← Back to team overview

ayatana-commits team mailing list archive

[Branch ~agateau/plasma-indicatordisplay/trunk] Rev 76: Ported to latest changes in libindicate-qt

 

------------------------------------------------------------
revno: 76
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-indicatordisplay
timestamp: Mon 2009-09-14 18:23:19 +0200
message:
  Ported to latest changes in libindicate-qt
  Added support for draw_attention and count to ListenerModel
modified:
  src/listenermodel.cpp
  src/listenermodel.h
  tests/filtermodeltest.cpp
  tests/listenermodeltest.cpp


--
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/listenermodel.cpp'
--- src/listenermodel.cpp	2009-09-11 15:10:09 +0000
+++ src/listenermodel.cpp	2009-09-14 16:23:19 +0000
@@ -20,6 +20,9 @@
 #include <KIcon>
 #include <KIconLoader>
 
+// libindicate-qt
+#include <qindicatedecode.h>
+
 // Local
 
 #define USE_ICONS_FOR_SERVERS
@@ -141,7 +144,7 @@
 
 void ListenerModel::slotDesktopFileReceived(QIndicate::Listener::Server* server, const QByteArray& _fileName)
 {
-    QString fileName = QIndicate::Listener::stringFromValue(_fileName);
+    QString fileName = QIndicate::Decode::stringFromValue(_fileName);
     KDesktopFile desktopFile(fileName);
     QString name = desktopFile.readName();
     if (name.isEmpty()) {
@@ -179,7 +182,7 @@
 
 void ListenerModel::slotServerTypeReceived(QIndicate::Listener::Server* server, const QByteArray& _type)
 {
-    QString type = QIndicate::Listener::stringFromValue(_type);
+    QString type = QIndicate::Decode::stringFromValue(_type);
     QStandardItem* item = d->mItemForServer.value(server);
     if (!item) {
         kError() << "No item for server" << server;
@@ -209,7 +212,7 @@
 void ListenerModel::slotIndicatorAdded(QIndicate::Listener::Server* server,
                                        QIndicate::Listener::Indicator* indicator)
 {
-    static QVariant outdatedKeyList = QStringList() << "name" << "icon" << "time";
+    static QVariant outdatedKeyList = QStringList() << "name" << "icon" << "time" << "draw_attention" << "count";
 
     QStandardItem* serverItem = d->mItemForServer.value(server);
     if (!serverItem) {
@@ -296,14 +299,20 @@
     }
 
     if (key == "name") {
-        item->setText(QIndicate::Listener::stringFromValue(value));
+        item->setText(QIndicate::Decode::stringFromValue(value));
     } else if (key == "icon") {
-        QImage image = QIndicate::Listener::imageFromValue(value);
+        QImage image = QIndicate::Decode::imageFromValue(value);
         QPixmap pix = QPixmap::fromImage(image);
         item->setData(KIcon(pix), Qt::DecorationRole);
     } else if (key == "time") {
-        QDateTime dateTime = QIndicate::Listener::dateTimeFromValue(value);
+        QDateTime dateTime = QIndicate::Decode::dateTimeFromValue(value);
         item->setData(QVariant(dateTime), IndicatorDateTimeRole);
+    } else if (key == "draw_attention") {
+        bool attention = QIndicate::Decode::boolFromValue(value);
+        item->setData(QVariant(attention), IndicatorDrawAttentionRole);
+    } else if (key == "count") {
+        int count = QIndicate::Decode::intFromValue(value);
+        item->setData(QVariant(count), IndicatorCountRole);
     } else {
         kWarning() << "Unhandled key" << key;
     }

=== modified file 'src/listenermodel.h'
--- src/listenermodel.h	2009-09-11 15:10:09 +0000
+++ src/listenermodel.h	2009-09-14 16:23:19 +0000
@@ -29,7 +29,8 @@
     {
         ServerTypeRole = 0x0F3B4320,
         IndicatorCountRole = 0x2CFC6823,
-        IndicatorDateTimeRole = 0x215B03CC
+        IndicatorDateTimeRole = 0x215B03CC,
+        IndicatorDrawAttentionRole = 0x28304470
     };
 
     /**

=== modified file 'tests/filtermodeltest.cpp'
--- tests/filtermodeltest.cpp	2009-09-11 15:10:09 +0000
+++ tests/filtermodeltest.cpp	2009-09-14 16:23:19 +0000
@@ -62,7 +62,7 @@
 
     // Show an indicator
     QIndicate::Indicator indicator;
-    indicator.setProperty("name", "John Doe");
+    indicator.setIndicatorProperty("name", "John Doe");
     indicator.show();
     QTest::qWait(500);
 
@@ -80,7 +80,7 @@
 
     QCOMPARE(indicatorIndex.data().toString(), QString("John Doe"));
 
-    indicator.setProperty("name", "Bruce Wayne");
+    indicator.setIndicatorProperty("name", "Bruce Wayne");
     QTest::qWait(500);
 
     QCOMPARE(indicatorIndex.data().toString(), QString("Bruce Wayne"));

=== modified file 'tests/listenermodeltest.cpp'
--- tests/listenermodeltest.cpp	2009-09-11 15:10:09 +0000
+++ tests/listenermodeltest.cpp	2009-09-14 16:23:19 +0000
@@ -96,8 +96,8 @@
 
     // Show an indicator
     QIndicate::Indicator indicator;
-    indicator.setProperty("name", "John Doe");
-    indicator.setProperty("icon", testImage);
+    indicator.setIndicatorProperty("name", "John Doe");
+    indicator.setIndicatorProperty("icon", testImage);
     indicator.show();
     QTest::qWait(500);
 
@@ -140,7 +140,7 @@
     mServer->show();
 
     QIndicate::Indicator indicator;
-    indicator.setProperty("name", "John Doe");
+    indicator.setIndicatorProperty("name", "John Doe");
     indicator.show();
 
     QTest::qWait(500);
@@ -179,7 +179,7 @@
 
     // Show an indicator
     QIndicate::Indicator indicator;
-    indicator.setProperty("name", "John Doe");
+    indicator.setIndicatorProperty("name", "John Doe");
     indicator.show();
     QTest::qWait(500);
 
@@ -219,6 +219,18 @@
     return value.toDateTime();
 }
 
+static bool indicatorDrawAttention(const QModelIndex& index)
+{
+    QVariant value = index.data(ListenerModel::IndicatorDrawAttentionRole);
+    return value.canConvert(QVariant::Bool) ? value.toBool() : false;
+}
+
+static int indicatorCount(const QModelIndex& index)
+{
+    QVariant value = index.data(ListenerModel::IndicatorCountRole);
+    return value.canConvert(QVariant::Int) ? value.toInt() : 0;
+}
+
 void ListenerModelTest::testUpdateIndicator()
 {
     QDate day = QDate(2006, 4, 1);
@@ -228,8 +240,8 @@
 
     // Show an indicator
     QIndicate::Indicator indicator;
-    indicator.setProperty("name", "John Doe");
-    indicator.setProperty("time", QDateTime(day, QTime(1, 23, 45)));
+    indicator.setIndicatorProperty("name", "John Doe");
+    indicator.setIndicatorProperty("time", QDateTime(day, QTime(1, 23, 45)));
     indicator.show();
     QTest::qWait(500);
 
@@ -239,16 +251,22 @@
 
     QCOMPARE(indicatorIndex.data().toString(), QString("John Doe"));
     QCOMPARE(indicatorDateTime(indicatorIndex), QDateTime(day, QTime(1, 23, 45)));
+    QCOMPARE(indicatorCount(indicatorIndex), 0);
+    QVERIFY(!indicatorDrawAttention(indicatorIndex));
 
-    indicator.setProperty("name", "Bruce Wayne");
-    indicator.setProperty("time", QDateTime(day, QTime(12, 34, 56)));
+    indicator.setIndicatorProperty("name", "Bruce Wayne");
+    indicator.setIndicatorProperty("time", QDateTime(day, QTime(12, 34, 56)));
+    indicator.setDrawAttentionProperty(true);
+    indicator.setCountProperty(5);
     QTest::qWait(500);
 
     QCOMPARE(indicatorIndex.data().toString(), QString("Bruce Wayne"));
     QCOMPARE(indicatorDateTime(indicatorIndex), QDateTime(day, QTime(12, 34, 56)));
+    QCOMPARE(indicatorCount(indicatorIndex), 5);
+    QVERIFY(indicatorDrawAttention(indicatorIndex));
 }
 
-static int indicatorCount(const QModelIndex& index)
+static int serverIndicatorCount(const QModelIndex& index)
 {
     QVariant value = index.data(ListenerModel::IndicatorCountRole);
     if (!value.canConvert(QVariant::Int)) {
@@ -264,27 +282,27 @@
     QTest::qWait(500);
     QModelIndex serverIndex = mModel->index(0, 0);
 
-    QCOMPARE(indicatorCount(serverIndex), 0);
+    QCOMPARE(serverIndicatorCount(serverIndex), 0);
 
     // Show an indicator
     QIndicate::Indicator indicator1;
     indicator1.show();
     QTest::qWait(500);
 
-    QCOMPARE(indicatorCount(serverIndex), 1);
+    QCOMPARE(serverIndicatorCount(serverIndex), 1);
 
     // Show another one
     QIndicate::Indicator indicator2;
     indicator2.show();
     QTest::qWait(500);
 
-    QCOMPARE(indicatorCount(serverIndex), 2);
+    QCOMPARE(serverIndicatorCount(serverIndex), 2);
 
     // Hide first one
     indicator1.hide();
     QTest::qWait(500);
 
-    QCOMPARE(indicatorCount(serverIndex), 1);
+    QCOMPARE(serverIndicatorCount(serverIndex), 1);
 }
 
 #include "listenermodeltest.moc"