[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/applets/presence
From:       Abner Silva <abner.silva () kdemail ! net>
Date:       2009-07-21 22:56:26
Message-ID: 1248216986.028896.18222.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1000751 by abnerf:

Implemented changing presence support.

 M  +23 -1     accountwidget.cpp  
 M  +7 -0      accountwidget.h  
 M  +30 -0     presence.cpp  
 M  +3 -1      presence.h  


--- trunk/playground/base/plasma/applets/presence/accountwidget.cpp #1000750:1000751
@@ -97,6 +97,9 @@
     m_presenceStatus->addItem("Busy - Sorry, I'm busy right now");
     m_presenceStatus->addItem("Invisible - Hidden");
     m_presenceStatus->addItem("Offline - Offline");
+    connect (m_presenceStatus->nativeWidget(),
+            SIGNAL(activated(const QString&)),
+            this, SLOT(onActivated(const QString&)));
     m_layout->addItem(m_presenceStatus, 2, 0, 1, 3, Qt::AlignTop);
 
     setLayout(m_layout);
@@ -148,4 +151,23 @@
 
     m_presenceStatus->nativeWidget()->setCurrentIndex(pos);
 }
-//#include "contactwidget.moc"
+
+void AccountWidget::onActivated(const QString &text)
+{
+    QString ret;
+
+    if (text.contains("Available"))
+        ret = "available";
+    else if (text.contains("Away"))
+        ret = "away";
+    else if (text.contains("Busy"))
+        ret = "busy";
+    else if (text.contains("Invisible"))
+        ret = "invisible";
+    else if (text.contains("Offline"))
+        ret = "offline";
+
+    // FIXME - Send the presence msg
+    emit presenceChanged(ret, "");
+}
+#include "accountwidget.moc"
--- trunk/playground/base/plasma/applets/presence/accountwidget.h #1000750:1000751
@@ -56,6 +56,13 @@
     void setImage(const QPixmap &image);
 
     void setPresence(const QString &presence, const QString &msg);
+
+Q_SIGNALS:
+    void presenceChanged(const QString &presence, const QString &msg);
+
+private Q_SLOTS:
+    void onActivated(const QString &text);
+
 private:
     QString m_id;
     AccountImage *m_image;
--- trunk/playground/base/plasma/applets/presence/presence.cpp #1000750:1000751
@@ -26,6 +26,7 @@
 
 // Plasma
 #include <Plasma/Theme>
+#include <Plasma/Service>
 
 // Kde
 #include <KColorScheme>
@@ -102,6 +103,8 @@
     if (!m_accounts.contains(source)) {
         AccountWidget *account = new AccountWidget();
         account->setId(source);
+        connect(account, SIGNAL(presenceChanged(const QString&, const QString&)),
+                this, SLOT(onPresenceChanged(const QString&, const QString&)));
         m_layout->addItem(account);
         m_accounts[source] = account;
         m_engine->connectSource(source, this);
@@ -286,5 +289,32 @@
     m_masterStatusMessage = message;*/
 }
 
+void PresenceApplet::onPresenceChanged(const QString &presence,
+        const QString &msg)
+{
+    Q_UNUSED(msg);
+
+    AccountWidget *account = static_cast<AccountWidget *>(sender());
+
+    Q_ASSERT(account);
+
+    Plasma::Service *service = m_engine->serviceForSource(account->id());
+
+    if (service != NULL) {
+        KConfigGroup op = service->operationDescription("setPresence");
+        op.writeEntry("status", presence);
+        connect(service, SIGNAL(finished(Plasma::ServiceJob *)),
+                this, SLOT(onJobCompleted()));
+        service->startOperationCall(op);
+    }
+}
+
+void PresenceApplet::onJobCompleted()
+{
+    Plasma::Service *service = static_cast<Plasma::Service *>(sender());
+
+    if (service)
+        service->deleteLater();
+}
 #include "presence.moc"
 
--- trunk/playground/base/plasma/applets/presence/presence.h #1000750:1000751
@@ -51,7 +51,9 @@
     void onSourceRemoved(const QString &source);
     void dataUpdated(const QString &source,
             const Plasma::DataEngine::Data &data);
-    // void onItemChanged(QStandardItem *item);
+    void onPresenceChanged(const QString &presence,
+            const QString &msg);
+    void onJobCompleted();
 
 private:
     void updateMasterIcon();
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic