[SCM] ktp-contact-applet packaging branch, master, updated. debian/15.12.1-1-966-gde83ac5

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:11:27 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-desktop-applets.git;a=commitdiff;h=28d4c1e

The following commit has been merged in the master branch:
commit 28d4c1e70b88e9e0bf6e180dd3bc5e00aae23fef
Author: Francesco Nwokeka <francesco.nwokeka at gmail.com>
Date:   Fri Aug 19 16:05:17 2011 +0200

    Made QML comunicate with C++
    
    now avatars are updated and can read contact info
---
 CMakeLists.txt                                     |  7 ++-
 src/config.ui                                      |  4 +-
 .../contents/ui/Contact.qml => contactWrapper.cpp} | 68 +++++++++++++++++-----
 src/{telepathyContact.h => contactWrapper.h}       | 47 ++++++++-------
 src/declarative/contents/ui/Avatar.qml             | 15 ++++-
 src/declarative/contents/ui/Contact.qml            |  9 +++
 src/declarative/contents/ui/main.qml               |  5 ++
 src/telepathyContact.cpp                           | 24 ++++++--
 src/telepathyContact.h                             |  4 +-
 9 files changed, 136 insertions(+), 47 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index db35edb..ce1ccdb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,7 @@ set(telepathy_contact_applet_SRCS
     src/abstractContactDelegate.cpp
     src/config.cpp
     src/contactDelegate.cpp
+    src/contactWrapper.cpp
     src/telepathyContact.cpp
     src/models/accounts-filter-model.cpp
     src/models/accounts-model-item.cpp
@@ -45,7 +46,11 @@ kde4_add_ui_files(telepathy_contact_applet_SRCS
 )
 
 kde4_add_plugin(plasma_applet_telepathy_contact ${telepathy_contact_applet_SRCS})
-target_link_libraries(plasma_applet_telepathy_contact ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${TELEPATHY_QT4_LIBRARIES})
+target_link_libraries(plasma_applet_telepathy_contact
+                        ${KDE4_PLASMA_LIBS}
+                        ${KDE4_KDEUI_LIBS}
+                        ${TELEPATHY_QT4_LIBRARIES}
+                        ${QT_QTDECLARATIVE_LIBRARY})
 
 install(DIRECTORY src/declarative/ DESTINATION ${DATA_INSTALL_DIR}/plasma/plasmoids/org.kde.telepathy-contact)
 install(TARGETS plasma_applet_telepathy_contact DESTINATION ${PLUGIN_INSTALL_DIR})
diff --git a/src/config.ui b/src/config.ui
index 6e9c147..967606c 100644
--- a/src/config.ui
+++ b/src/config.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>517</width>
-    <height>371</height>
+    <width>552</width>
+    <height>426</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
diff --git a/src/declarative/contents/ui/Contact.qml b/src/contactWrapper.cpp
similarity index 54%
copy from src/declarative/contents/ui/Contact.qml
copy to src/contactWrapper.cpp
index 686cb23..f629d3a 100644
--- a/src/declarative/contents/ui/Contact.qml
+++ b/src/contactWrapper.cpp
@@ -17,24 +17,64 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
-import Qt 4.7
+#include "contactWrapper.h"
 
-Item {
-    id: wrapper;
+#include <TelepathyQt4/AvatarData>
+#include <TelepathyQt4/Presence>
 
-    // contact/person presence status
-    property string status: "offline";
-
-    anchors.fill: parent;
+ContactWrapper::ContactWrapper(QObject* parent)
+    : QObject(parent)
+    , m_contact(0)
+{
+}
 
-    Avatar{
-        id: avatar;
-        avatarPresenceStatus: wrapper.status;
+ContactWrapper::~ContactWrapper()
+{
+}
 
-        anchors {
-            top: parent.top;
-            left: parent.left;
-            right: parent.right;
+QString ContactWrapper::avatar() const
+{
+    if (m_contact) {
+        if (!m_contact->avatarData().fileName.isEmpty()) {
+            return m_contact->avatarData().fileName;
+        } else {
+            return QString("im-user");
         }
+    } else {
+        // return default icon
+        return QString("im-user");
+    }
+}
+
+Tp::ContactPtr ContactWrapper::contact() const
+{
+    return m_contact;
+}
+
+QString ContactWrapper::displayName() const
+{
+    if (m_contact) {
+        return m_contact->alias();
+    } else {
+        return QString();
     }
 }
+
+QString ContactWrapper::presenceStatus() const
+{
+    if (m_contact) {
+        return m_contact->presence().status();
+    } else {
+        return QString("");
+    }
+}
+
+void ContactWrapper::setContact(const Tp::ContactPtr& newContact)
+{
+    qDebug() << "setting new contact to: " << newContact->id();
+    m_contact = newContact;
+
+    // tell QML we have a new contact
+    emit(newContactSet());
+}
+
diff --git a/src/telepathyContact.h b/src/contactWrapper.h
similarity index 64%
copy from src/telepathyContact.h
copy to src/contactWrapper.h
index 5631d44..aeafa25 100644
--- a/src/telepathyContact.h
+++ b/src/contactWrapper.h
@@ -17,41 +17,46 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
-#ifndef TELEPATHY_CONTACT_H
-#define TELEPATHY_CONTACT_H
+#ifndef CONTACT_WRAPER_H
+#define CONTACT_WRAPER_H
 
-#include <KIcon>
-
-#include <Plasma/Applet>
-#include <Plasma/DeclarativeWidget>
+#include <QtCore/QObject>
 
 #include <TelepathyQt4/Contact>
 
-class Config;
-
-class TelepathyContact: public Plasma::Applet
+class ContactWrapper : public QObject
 {
     Q_OBJECT
 public:
-    TelepathyContact(QObject *parent, const QVariantList &args);
-    ~TelepathyContact();
+    ContactWrapper(QObject *parent = 0);
+    virtual ~ContactWrapper();
+
+    Q_PROPERTY(QString avatar READ avatar);
+    Q_PROPERTY(QString displayName READ displayName);
+    Q_PROPERTY(QString presenceStatus READ presenceStatus);
 
-    void init();
-    void paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect& contentsRect);
+    /** returns the avatar location for the contact */
+    QString avatar() const;
 
-    /** overide of config signal */
-    void showConfigurationInterface();
+    /** returns current contact being rappresented */
+    Tp::ContactPtr contact() const;
 
-public slots:
-    /** called from config dialog to set new contact
-     * @param newContact Tp::ContactPtr to the new contact to use
+    /** returns the display name of the contact */
+    QString displayName() const;
+
+    /** returns the contact presence status (online, offlince ... ) */
+    QString presenceStatus() const;
+
+    /** set new contact to rappresent
+     * @param newContact the contact to rappresent
      */
     void setContact(const Tp::ContactPtr &newContact);
 
+signals:
+    void newContactSet();
+
 private:
-    Config *m_config;
-    Plasma::DeclarativeWidget *m_declarative;
     Tp::ContactPtr m_contact;
 };
 
-#endif  // TELEPATHY_CONTACT_H
\ No newline at end of file
+#endif  // CONTACT_WRAPER_H
diff --git a/src/declarative/contents/ui/Avatar.qml b/src/declarative/contents/ui/Avatar.qml
index 8e83b3b..a6713ed 100644
--- a/src/declarative/contents/ui/Avatar.qml
+++ b/src/declarative/contents/ui/Avatar.qml
@@ -65,31 +65,42 @@ Item {
     function setAvatarPresenceStatus(presenceStatus)
     {
         switch (presenceStatus) {
-            case "online":
+            case "available":
                 avatarFrame.source = "../frames/online.png";
                 if (!avatar.enabled) {
                     avatar.enabled = true;
                 }
-            case "busy":
+                break;
+            case "dnd":
                 avatarFrame.source = "../frames/busy.png";
                 if (!avatar.enabled) {
                     avatar.enabled = true;
                 }
+                break;
             case "away":
                 avatarFrame.source = "../frames/away.png";
                 if (!avatar.enabled) {
                     avatar.enabled = true;
                 }
+                break;
             case "offline":
                 avatarFrame.source = "../frames/offline.png";
                 if (avatar.enabled) {
                     avatar.enabled = false;
                 }
+                break;
             default:
                 avatarFrame.source = "../frames/offline.png";
                 if (avatar.enabled) {
                     avatar.enabled = false;
                 }
+                break;
         }
     }
+
+    // updates avatar info with info from contact currently set
+    function update()
+    {
+        avatar.icon = QIcon(TelepathyContact.avatar);
+    }
 }
diff --git a/src/declarative/contents/ui/Contact.qml b/src/declarative/contents/ui/Contact.qml
index 686cb23..f291c8c 100644
--- a/src/declarative/contents/ui/Contact.qml
+++ b/src/declarative/contents/ui/Contact.qml
@@ -37,4 +37,13 @@ Item {
             right: parent.right;
         }
     }
+
+    function update()
+    {
+        wrapper.status = TelepathyContact.presenceStatus;
+
+        // update avatar
+        avatar.update();
+        avatar.setAvatarPresenceStatus(wrapper.status);
+    }
 }
diff --git a/src/declarative/contents/ui/main.qml b/src/declarative/contents/ui/main.qml
index 45a0828..da2b63e 100644
--- a/src/declarative/contents/ui/main.qml
+++ b/src/declarative/contents/ui/main.qml
@@ -30,4 +30,9 @@ Item {
         id: contact;
         anchors.centerIn: parent;
     }
+
+    function onNewContactSet()
+    {
+        contact.update();
+    }
 }
diff --git a/src/telepathyContact.cpp b/src/telepathyContact.cpp
index 5f3c87b..b60c3e9 100644
--- a/src/telepathyContact.cpp
+++ b/src/telepathyContact.cpp
@@ -18,11 +18,14 @@
  ***************************************************************************/
 
 #include "config.h"
+#include "contactWrapper.h"
 #include "telepathyContact.h"
 
 #include <KStandardDirs>
-
-#include <Plasma/PackageStructure>
+#include <QObject>
+#include <QDeclarativeEngine>
+#include <QDeclarativeContext>
+// #include <Plasma/PackageStructure>
 
 #include <QtGui/QPainter>
 
@@ -31,7 +34,8 @@ TelepathyContact::TelepathyContact(QObject* parent, const QVariantList& args)
     : Plasma::Applet(parent, args)
     , m_config(new Config())
     , m_declarative(new Plasma::DeclarativeWidget(this))
-    , m_contact(0)
+    , m_contact(new ContactWrapper(parent))
+    , m_qmlObject(0)
 {
     // setup plasmoid
     resize(128, 128);
@@ -47,6 +51,8 @@ TelepathyContact::~TelepathyContact()
 {
     delete m_config;
     delete m_declarative;
+//     delete m_contact;
+//     delete m_qmlObject;
 }
 
 void TelepathyContact::init()
@@ -57,6 +63,13 @@ void TelepathyContact::init()
         QString qmlFile = KGlobal::dirs()->findResource("data", "plasma/plasmoids/org.kde.telepathy-contact/contents/ui/main.qml");
         qDebug() << "LOADING: " << qmlFile;
         m_declarative->setQmlPath(qmlFile);
+        m_declarative->engine()->rootContext()->setContextProperty("TelepathyContact", m_contact);
+
+        // setup qml object so that we can talk to the declarative part
+        m_qmlObject = dynamic_cast<QObject*>(m_declarative->rootObject());
+
+        // connect the qml object to recieve signals from C++ end
+        connect(m_contact, SIGNAL(newContactSet()), m_qmlObject, SLOT(onNewContactSet()));
     }
 }
 
@@ -69,9 +82,8 @@ void TelepathyContact::setContact(const Tp::ContactPtr& newContact)
 {
     Q_ASSERT(newContact);
 
-    if (!m_contact || m_contact->id() != newContact->id()) {
-        m_contact = newContact;
-        /// TODO update contact info for QML to read from
+    if (!m_contact->contact() || m_contact->contact()->id() != newContact->id()) {
+        m_contact->setContact(newContact);
     }
 }
 
diff --git a/src/telepathyContact.h b/src/telepathyContact.h
index 5631d44..354dae2 100644
--- a/src/telepathyContact.h
+++ b/src/telepathyContact.h
@@ -28,6 +28,7 @@
 #include <TelepathyQt4/Contact>
 
 class Config;
+class ContactWrapper;
 
 class TelepathyContact: public Plasma::Applet
 {
@@ -51,7 +52,8 @@ public slots:
 private:
     Config *m_config;
     Plasma::DeclarativeWidget *m_declarative;
-    Tp::ContactPtr m_contact;
+    ContactWrapper *m_contact;
+    QObject *m_qmlObject;
 };
 
 #endif  // TELEPATHY_CONTACT_H
\ No newline at end of file

-- 
ktp-contact-applet packaging



More information about the pkg-kde-commits mailing list