← Back to team overview

ayatana-commits team mailing list archive

[Branch ~agateau/libindicate-qt/trunk] Rev 96: Merged setservercount branch

 

Merge authors:
  Aurélien Gâteau (agateau)
------------------------------------------------------------
revno: 96 [merge]
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: libindicate-qt
timestamp: Thu 2009-09-17 17:12:41 +0200
message:
  Merged setservercount branch
added:
  examples/qservercount.cpp
  examples/qservercount.h
modified:
  CMakeLists.txt
  examples/CMakeLists.txt
  src/qindicateindicator.cpp
  src/qindicatelistener.cpp
  src/qindicatelistener.h
  src/qindicateserver.cpp
  tests/communicationtest.cpp


--
lp:libindicate-qt
https://code.launchpad.net/~agateau/libindicate-qt/trunk

Your team ayatana-commits is subscribed to branch lp:libindicate-qt.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/libindicate-qt/trunk/+edit-subscription.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt	2009-09-14 12:10:15 +0000
+++ CMakeLists.txt	2009-09-17 13:34:58 +0000
@@ -1,6 +1,6 @@
 project(libindicate_qt)
 cmake_minimum_required(VERSION 2.6)
-set(indicate_qt_VERSION 0.2.1)
+set(indicate_qt_VERSION 0.2.2)
 
 # Packaging
 set(ARCHIVE_NAME libindicate-qt-${indicate_qt_VERSION})
@@ -9,14 +9,14 @@
     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
 
 set(indicate_qt_lib_SOVERSION 1)
-set(indicate_qt_lib_VERSION ${indicate_qt_lib_SOVERSION}.0.0)
+set(indicate_qt_lib_VERSION ${indicate_qt_lib_SOVERSION}.1.0)
 
 find_package(Qt4 REQUIRED)
 find_package(PkgConfig REQUIRED)
 
 add_definitions(-Wall)
 
-pkg_check_modules(INDICATE REQUIRED indicate>=0.2.0)
+pkg_check_modules(INDICATE REQUIRED indicate>=0.2.1)
 
 include_directories(
     ${QT_INCLUDE_DIR}

=== modified file 'examples/CMakeLists.txt'
--- examples/CMakeLists.txt	2009-07-28 14:19:18 +0000
+++ examples/CMakeLists.txt	2009-09-17 13:36:42 +0000
@@ -31,3 +31,13 @@
 target_link_libraries(qlisten-and-print
     ${example_LIBRARIES}
     )
+
+# qservercount
+set(qservercount_SRCS qservercount.cpp)
+qt4_automoc(${qservercount_SRCS})
+
+add_executable(qservercount ${qservercount_SRCS})
+
+target_link_libraries(qservercount
+    ${example_LIBRARIES}
+    )

=== added file 'examples/qservercount.cpp'
--- examples/qservercount.cpp	1970-01-01 00:00:00 +0000
+++ examples/qservercount.cpp	2009-09-17 13:36:42 +0000
@@ -0,0 +1,63 @@
+/*
+ * Example of an application which only defines a server count
+ *
+ * Copyright 2009 Canonical Ltd.
+ *
+ * Authors:
+ * - Aurélien Gâteau <aurelien.gateau@xxxxxxxxxxxxx>
+ *
+ * License: LGPL v2.1 or LGPL v3
+ */
+#include "qservercount.h"
+
+#include <QDebug>
+#include <QTimer>
+
+Controller::Controller(QIndicate::Server* server)
+: mServer(server)
+, mCount(0)
+{
+    connect(mServer, SIGNAL(serverDisplay()), SLOT(slotServerDisplay()));
+
+    QTimer* timer = new QTimer(this);
+    timer->setInterval(2000);
+    connect(timer, SIGNAL(timeout()), SLOT(increaseCount()));
+    timer->start();
+}
+
+void Controller::slotServerDisplay()
+{
+    qDebug() << "A listener wants us to display the server";
+    mCount = 0;
+    mServer->setCount(mCount);
+}
+
+void Controller::increaseCount()
+{
+    mCount++;
+    mServer->setCount(mCount);
+}
+
+int main (int argc, char ** argv)
+{
+    QApplication app(argc, argv);
+
+    if (argc != 3) {
+        qCritical("Syntax: %s <desktop/file> <serverType>", argv[0]);
+        return 1;
+    }
+
+    QString desktopFile = QString::fromLocal8Bit(argv[1]);
+    QString serverType = QString::fromLocal8Bit(argv[2]);
+
+    QIndicate::Server* server = QIndicate::Server::defaultInstance();
+    server->setType(serverType);
+    server->setDesktopFile(desktopFile);
+    server->show();
+
+    Controller controller(server);
+
+    return app.exec();
+}
+
+#include "qservercount.moc"

=== added file 'examples/qservercount.h'
--- examples/qservercount.h	1970-01-01 00:00:00 +0000
+++ examples/qservercount.h	2009-09-17 13:36:42 +0000
@@ -0,0 +1,34 @@
+/*
+ * Example of an application which only defines a server count
+ *
+ * Copyright 2009 Canonical Ltd.
+ *
+ * Authors:
+ * - Aurélien Gâteau <aurelien.gateau@xxxxxxxxxxxxx>
+ *
+ * License: LGPL v2.1 or LGPL v3
+ */
+#ifndef QSERVERCOUNT_H
+#define QSERVERCOUNT_H
+
+#include <QApplication>
+#include <QObject>
+
+#include <qindicateserver.h>
+
+class Controller : public QObject
+{
+Q_OBJECT
+public:
+    Controller(QIndicate::Server*);
+
+public Q_SLOTS:
+    void slotServerDisplay();
+    void increaseCount();
+
+private:
+    QIndicate::Server* mServer;
+    int mCount;
+};
+
+#endif /* QSERVERCOUNT_H */

=== modified file 'src/qindicateindicator.cpp'
--- src/qindicateindicator.cpp	2009-09-16 08:38:45 +0000
+++ src/qindicateindicator.cpp	2009-09-17 14:57:52 +0000
@@ -123,6 +123,7 @@
 static void propertyList_helper(gchar* _item, QStringList* list)
 {
     *list << QString::fromUtf8(_item);
+    g_free(_item);
 }
 
 QStringList Indicator::propertyList() const

=== modified file 'src/qindicatelistener.cpp'
--- src/qindicatelistener.cpp	2009-09-14 15:10:58 +0000
+++ src/qindicatelistener.cpp	2009-09-17 14:57:52 +0000
@@ -71,6 +71,13 @@
     QMetaObject::invokeMethod(listener, "serverRemoved", Q_ARG(QIndicate::Listener::Server*, server), Q_ARG(QString, type));
 }
 
+static void serverCountChangedCB(IndicateListener* _listener, void* _server, guint value)
+{
+    Listener* listener = sQListenerFromGListener.value(_listener);
+    Listener::Server* server = reinterpret_cast<Listener::Server*>(_server);
+    QMetaObject::invokeMethod(listener, "serverCountChanged", Q_ARG(QIndicate::Listener::Server*, server), Q_ARG(int, value));
+}
+
 static void indicatorAddedCB(IndicateListener* _listener, void* _server, void* _indicator)
 {
     Listener* listener = sQListenerFromGListener.value(_listener);
@@ -121,6 +128,7 @@
         g_signal_connect(G_OBJECT(d->mGListener), gsignal, G_CALLBACK(callback), NULL)
     gconnect(INDICATE_LISTENER_SIGNAL_SERVER_ADDED, serverAddedCB);
     gconnect(INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, serverRemovedCB);
+    gconnect(INDICATE_LISTENER_SIGNAL_SERVER_COUNT_CHANGED, serverCountChangedCB);
     gconnect(INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, indicatorAddedCB);
     gconnect(INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED, indicatorModifiedCB);
     gconnect(INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, indicatorRemovedCB);
@@ -162,6 +170,7 @@
             Listener::Indicator* indicator = reinterpret_cast<Listener::Indicator*>(_indicator);
             QString key = QString::fromUtf8(_key);
             QByteArray value(_value);
+            g_free(_value);
 
             QMetaObject::invokeMethod(helper->mReceiver, helper->mMethod.data(),
                 Q_ARG(QIndicate::Listener::Server*, server),
@@ -181,7 +190,7 @@
     static void serverGetUIntPropertyCB(IndicateListener* listener,
         IndicateListenerServer* server, guint value, gpointer data)
     {
-        serverGetPropertyCB(listener, server, Q_ARG(uint, value), data);
+        serverGetPropertyCB(listener, server, Q_ARG(int, value), data);
     }
 
 private:

=== modified file 'src/qindicatelistener.h'
--- src/qindicatelistener.h	2009-09-14 15:10:58 +0000
+++ src/qindicatelistener.h	2009-09-17 12:20:35 +0000
@@ -99,6 +99,7 @@
 Q_SIGNALS:
     void serverAdded(QIndicate::Listener::Server* server, const QString& type);
     void serverRemoved(QIndicate::Listener::Server* server, const QString& type);
+    void serverCountChanged(QIndicate::Listener::Server* server, int count);
 
     void indicatorAdded(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator);
     void indicatorModified(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator, const QString& property);

=== modified file 'src/qindicateserver.cpp'
--- src/qindicateserver.cpp	2009-09-14 09:27:22 +0000
+++ src/qindicateserver.cpp	2009-09-17 12:12:33 +0000
@@ -148,8 +148,7 @@
 
 void Server::setCount(int count)
 {
-    qDebug() << "FIXME: Waiting for indicate_server_set_count to be implemented in libindicate";
-    //indicate_server_set_count(d->mGServer, count);
+    indicate_server_set_count(d->mGServer, count);
 }
 
 void Server::show()

=== modified file 'tests/communicationtest.cpp'
--- tests/communicationtest.cpp	2009-09-14 15:10:58 +0000
+++ tests/communicationtest.cpp	2009-09-17 12:20:35 +0000
@@ -209,9 +209,11 @@
 
 void CommunicationTest::testGetServerCount()
 {
+    QSignalSpy spy(mListener, SIGNAL(serverCountChanged(QIndicate::Listener::Server*, int)));
+    QCOMPARE(spy.count(), 0);
+
     showIndicatorAndGetProxies();
-    QSKIP("FIXME: This test won't pass until indicate_server_set_count() is implemented", SkipAll);
-
+    QCOMPARE(spy.count(), 0);
     PropertyReceiver receiver;
 
     int count = 12;
@@ -229,6 +231,10 @@
 
     QCOMPARE(receiver.server, mListenerServer);
     QCOMPARE(receiver.value.toInt(), count);
+    QCOMPARE(spy.count(), 1);
+    QVariantList args = spy.takeFirst();
+    QCOMPARE(args[0].value<QIndicate::Listener::Server*>(), mListenerServer);
+    QCOMPARE(args[1].toInt(), count);
 }
 
 void CommunicationTest::testDisplay()