ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00189
[Branch ~agateau/plasma-indicatordisplay/trunk] Rev 86: Properly represent draw_attention indicator property.
------------------------------------------------------------
revno: 86
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-indicatordisplay
timestamp: Tue 2009-09-15 17:33:21 +0200
message:
Properly represent draw_attention indicator property.
modified:
src/indicatordisplay.cpp
src/indicatordisplay.h
src/listenermodel.cpp
src/listenermodel.h
tests/listenermodeltest.cpp
tests/listenermodeltest.h
--
lp:plasma-indicatordisplay
https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk
Your team ayatana-commits is subscribed to branch lp:plasma-indicatordisplay.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk/+edit-subscription.
=== modified file 'src/indicatordisplay.cpp'
--- src/indicatordisplay.cpp 2009-09-15 14:42:06 +0000
+++ src/indicatordisplay.cpp 2009-09-15 15:33:21 +0000
@@ -89,6 +89,9 @@
connect(mSourceModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
SLOT(slotRowsChanged(const QModelIndex&))
);
+ connect(mSourceModel, SIGNAL(drawAttentionChanged(const QModelIndex&)),
+ SLOT(slotDrawAttentionChanged())
+ );
#ifdef DUMP_MODELS
connect(mSourceModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
SLOT(dumpModels())
@@ -190,17 +193,16 @@
return;
}
- // If one of the server has a child, then we have new stuff
- bool newStuff = false;
- for (int row = mSourceModel->rowCount() - 1; row >= 0; --row) {
- QModelIndex index = mSourceModel->index(row, 0);
- if (mSourceModel->hasChildren(index)) {
- newStuff = true;
- break;
- }
- }
-
- updateIcon(newStuff);
+ updateIconFromIndicators();
+
+ #ifdef DUMP_MODELS
+ dumpModels();
+ #endif
+}
+
+void IndicatorDisplay::slotDrawAttentionChanged()
+{
+ updateIconFromIndicators();
#ifdef DUMP_MODELS
dumpModels();
@@ -212,6 +214,18 @@
mIconWidget->setIcon(newStuff ? NEW_STUFF_ICON : NO_NEW_STUFF_ICON);
}
+void IndicatorDisplay::updateIconFromIndicators()
+{
+ // Check if one of the indicators want to draw attention
+ QModelIndexList lst = mSourceModel->match(mSourceModel->index(0, 0),
+ ListenerModel::IndicatorDrawAttentionRole,
+ QVariant(true),
+ 1 /* hits */,
+ Qt::MatchExactly | Qt::MatchRecursive);
+
+ updateIcon(!lst.isEmpty());
+}
+
void IndicatorDisplay::updateIconState()
{
if (mSourceModel->rowCount() == 0) {
=== modified file 'src/indicatordisplay.h'
--- src/indicatordisplay.h 2009-09-15 14:42:06 +0000
+++ src/indicatordisplay.h 2009-09-15 15:33:21 +0000
@@ -42,6 +42,7 @@
private Q_SLOTS:
void slotRowsChanged(const QModelIndex& parent);
+ void slotDrawAttentionChanged();
void slotClicked(const QModelIndex& index);
void slotServerAdded(QIndicate::Listener::Server* server);
void dumpModels();
@@ -59,6 +60,7 @@
void initView();
void updateIcon(bool newStuff);
void updateIconState();
+ void updateIconFromIndicators();
void removeInterestOnServers();
};
=== modified file 'src/listenermodel.cpp'
--- src/listenermodel.cpp 2009-09-15 13:56:48 +0000
+++ src/listenermodel.cpp 2009-09-15 15:33:21 +0000
@@ -343,8 +343,12 @@
QDateTime dateTime = QIndicate::Decode::dateTimeFromValue(value);
item->setData(QVariant(dateTime), IndicatorDateTimeRole);
} else if (key == "draw_attention") {
+ QVariant oldAttention = item->data(IndicatorDrawAttentionRole).toBool();
bool attention = QIndicate::Decode::boolFromValue(value);
item->setData(QVariant(attention), IndicatorDrawAttentionRole);
+ if (oldAttention != attention) {
+ emit drawAttentionChanged(indexFromItem(item));
+ }
} else if (key == "count") {
int count = QIndicate::Decode::intFromValue(value);
item->setData(QVariant(count), IndicatorCountRole);
=== modified file 'src/listenermodel.h'
--- src/listenermodel.h 2009-09-15 13:56:48 +0000
+++ src/listenermodel.h 2009-09-15 15:33:21 +0000
@@ -42,6 +42,9 @@
QIndicate::Listener::Server** server,
QIndicate::Listener::Indicator** indicator) const;
+Q_SIGNALS:
+ void drawAttentionChanged(const QModelIndex&);
+
private Q_SLOTS:
void slotServerAdded(QIndicate::Listener::Server* server);
void slotServerRemoved(QIndicate::Listener::Server* server);
=== modified file 'tests/listenermodeltest.cpp'
--- tests/listenermodeltest.cpp 2009-09-15 14:06:26 +0000
+++ tests/listenermodeltest.cpp 2009-09-15 15:33:21 +0000
@@ -30,6 +30,13 @@
QTEST_KDEMAIN(ListenerModelTest, GUI)
+Q_DECLARE_METATYPE(QModelIndex);
+
+void ListenerModelTest::initTestCase()
+{
+ qRegisterMetaType<QModelIndex>("QModelIndex");
+}
+
void ListenerModelTest::init()
{
mListener = new QIndicate::Listener();
@@ -234,6 +241,7 @@
void ListenerModelTest::testUpdateIndicator()
{
QDate day = QDate(2006, 4, 1);
+ QSignalSpy drawAttentionSpy(mModel, SIGNAL(drawAttentionChanged(const QModelIndex&)));
// Show server
mServer->show();
@@ -253,6 +261,7 @@
QCOMPARE(indicatorDateTime(indicatorIndex), QDateTime(day, QTime(1, 23, 45)));
QCOMPARE(indicatorCount(indicatorIndex), 0);
QVERIFY(!indicatorDrawAttention(indicatorIndex));
+ QCOMPARE(drawAttentionSpy.count(), 0);
indicator.setIndicatorProperty("name", "Bruce Wayne");
indicator.setIndicatorProperty("time", QDateTime(day, QTime(12, 34, 56)));
@@ -264,6 +273,10 @@
QCOMPARE(indicatorDateTime(indicatorIndex), QDateTime(day, QTime(12, 34, 56)));
QCOMPARE(indicatorCount(indicatorIndex), 5);
QVERIFY(indicatorDrawAttention(indicatorIndex));
+ QCOMPARE(drawAttentionSpy.count(), 1);
+ QVariantList args = drawAttentionSpy.takeFirst();
+ QCOMPARE(args.count(), 1);
+ QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), indicatorIndex);
}
#include "listenermodeltest.moc"
=== modified file 'tests/listenermodeltest.h'
--- tests/listenermodeltest.h 2009-09-15 13:38:04 +0000
+++ tests/listenermodeltest.h 2009-09-15 15:33:21 +0000
@@ -27,6 +27,7 @@
{
Q_OBJECT
private Q_SLOTS:
+ void initTestCase();
void init();
void cleanup();
void testAddServers();