[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:07:45 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=863347d

The following commit has been merged in the master branch:
commit 863347d01ad29e03e8bfe95ffb7fc58479fdc992
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Thu Oct 6 20:50:34 2011 +0100

    Work new presence model into presence chooser
---
 global-presence-chooser.cpp | 84 +++++++++------------------------------------
 global-presence-chooser.h   |  7 ++--
 kpresence.cpp               |  6 ++++
 kpresence.h                 |  1 +
 presence-model.cpp          | 25 ++++----------
 presence-model.h            |  6 ++--
 6 files changed, 36 insertions(+), 93 deletions(-)

diff --git a/global-presence-chooser.cpp b/global-presence-chooser.cpp
index e2c880b..caf332c 100644
--- a/global-presence-chooser.cpp
+++ b/global-presence-chooser.cpp
@@ -1,35 +1,28 @@
 #include "global-presence-chooser.h"
 
 #include "global-presence.h"
+#include "presence-model.h"
 
 #include <KIcon>
 #include <KLocale>
 #include <KLineEdit>
+#include <KDebug>
 
 #include <TelepathyQt4/Presence>
+
 #include <QMouseEvent>
 
 GlobalPresenceChooser::GlobalPresenceChooser(QWidget *parent) :
     KComboBox(parent),
-    m_globalPresence(new GlobalPresence(this))
+    m_globalPresence(new GlobalPresence(this)),
+    m_model(new PresenceModel(this))
 {
-    setInsertPolicy(NoInsert);
-    //setTrapReturnKey(true);
-    addItem(KIcon("user-online"), i18n("Available"), qVariantFromValue(Tp::Presence::available()));
-    addItem(KIcon("user-away"), i18n("Away"), qVariantFromValue(Tp::Presence::away()));
-    addItem(KIcon("user-away"), i18n("Be Right Back"), qVariantFromValue(Tp::Presence::brb()));
-    addItem(KIcon("user-busy"), i18n("Busy"), qVariantFromValue(Tp::Presence::busy()));
-    addItem(KIcon("user-busy"), i18n("Do Not Disturb"), qVariantFromValue(Tp::Presence(
-                                                                            Tp::ConnectionPresenceTypeBusy,
-                                                                              QLatin1String("dnd"),
-                                                                              QLatin1String(""))));
-    addItem(KIcon("user-away-extended"), i18n("Extended Away"), qVariantFromValue(Tp::Presence::xa()));
-    addItem(KIcon("user-invisible"), i18n("Invisible"), qVariantFromValue(Tp::Presence::hidden()));
-    addItem(KIcon("user-offline"), i18n("Offline"), qVariantFromValue(Tp::Presence::offline()));
+    this->setModel(m_model);
 
     connect(this, SIGNAL(activated(int)), SLOT(onCurrentIndexChanged(int)));
     connect(m_globalPresence, SIGNAL(currentPresenceChanged(Tp::Presence)), SLOT(onPresenceChanged(Tp::Presence)));
-    connect(this, SIGNAL(returnPressed(QString)), SLOT(onPresenceMessageChanged(QString)));
+
+    onPresenceChanged(m_globalPresence->currentPresence());
 }
 
 void GlobalPresenceChooser::setAccountManager(const Tp::AccountManagerPtr &accountManager)
@@ -39,67 +32,24 @@ void GlobalPresenceChooser::setAccountManager(const Tp::AccountManagerPtr &accou
 
 void GlobalPresenceChooser::onCurrentIndexChanged(int index)
 {
-    Tp::Presence presence = itemData(index).value<Tp::Presence>();
+    Tp::Presence presence = itemData(index, PresenceModel::PresenceRole).value<Tp::Presence>();
     m_globalPresence->setPresence(presence);
-    setEditable(true);
-    lineEdit()->selectAll();
-    lineEdit()->setFocus();
 }
 
 void GlobalPresenceChooser::onPresenceChanged(const Tp::Presence &presence)
 {
-    qDebug() << "presence changing";
+    kDebug() << "presence changing";
     for (int i=0; i < count() ; i++) {
-        Tp::Presence itemPresence = itemData(i).value<Tp::Presence>();
-        if (itemPresence.type() == presence.type() && itemPresence.status() == presence.status()) {
+        Tp::Presence itemPresence = itemData(i, PresenceModel::PresenceRole).value<Tp::Presence>();
+        if (itemPresence.type() == presence.type() && itemPresence.statusMessage() == presence.statusMessage()) {
             setCurrentIndex(i);
-            qDebug() << "found item";
+            kDebug() << "found item";
+            return;
         }
     }
 
-    //FIXME if we can't find the correct value, create an entry.
+    //FIXME this needs to only be a temporary presence, which we delete afterwards
+    QModelIndex index = m_model->addPresence(presence);
+    setCurrentIndex(index.row());
 }
 
-void GlobalPresenceChooser::onPresenceMessageChanged(const QString &message)
-{
-    Tp::Presence presence = m_globalPresence->currentPresence();
-    presence.setStatus(presence.type(), presence.status(), message);
-
-    bool presenceExists = false;
-    int currentPresenceIndex;
-    for (int i=0; i < count() ; i++) {
-        Tp::Presence itemPresence = itemData(i).value<Tp::Presence>();
-        if (itemPresence.type() == presence.type()) {
-            currentPresenceIndex = i;
-        }
-        if (itemPresence.type() == presence.type() && itemPresence.status() == presence.status() && itemPresence.statusMessage() == presence.statusMessage()) {
-            qDebug() << "This presence already exists, setting this one instead";
-            setCurrentIndex(i);
-            presenceExists = true;
-            break;
-        }
-    }
-
-    if (!presenceExists) {
-        qDebug() << "Adding new presence";
-        insertItem(currentPresenceIndex, itemIcon(currentIndex()), message, qVariantFromValue(presence));
-        setCurrentIndex(currentPresenceIndex);
-        m_globalPresence->setPresence(presence);
-    }
-
-    setEditable(false);
-}
-
-void GlobalPresenceChooser::mousePressEvent(QMouseEvent *event)
-{
-    if (!isEditable()) {
-        setEditable(true);
-    }
-
-    KComboBox::mousePressEvent(event);
-}
-
-void GlobalPresenceChooser::focusOutEvent(QFocusEvent* event)
-{
-    setEditable(false);
-}
diff --git a/global-presence-chooser.h b/global-presence-chooser.h
index 248e73b..f558daa 100644
--- a/global-presence-chooser.h
+++ b/global-presence-chooser.h
@@ -8,6 +8,7 @@
 class QFocusEvent;
 class QMouseEvent;
 class GlobalPresence;
+class PresenceModel;
 
 class GlobalPresenceChooser : public KComboBox
 {
@@ -16,17 +17,13 @@ public:
     explicit GlobalPresenceChooser(QWidget *parent = 0);
     void setAccountManager(const Tp::AccountManagerPtr &accountManager);
 
-protected:
-    void mousePressEvent(QMouseEvent *event);
-    void focusOutEvent(QFocusEvent *event);
-
 private slots:
     void onCurrentIndexChanged(int index);
     void onPresenceChanged(const Tp::Presence &presence);
-    void onPresenceMessageChanged(const QString &message);
 
 private:
     GlobalPresence *m_globalPresence;
+    PresenceModel *m_model;
 };
 
 #endif // GLOBALPRESENCECHOOSER_H
diff --git a/kpresence.cpp b/kpresence.cpp
index ed2dd73..8de6e5a 100644
--- a/kpresence.cpp
+++ b/kpresence.cpp
@@ -1,5 +1,11 @@
 #include "kpresence.h"
 
+KPresence::KPresence() :
+    Tp::Presence()
+{
+
+}
+
 KPresence::KPresence(const Tp::Presence &presence) :
     Tp::Presence(presence)
 {
diff --git a/kpresence.h b/kpresence.h
index f047ebd..124e32f 100644
--- a/kpresence.h
+++ b/kpresence.h
@@ -9,6 +9,7 @@
 class KPresence : public Tp::Presence
 {
 public:
+    KPresence();
     KPresence(const Tp::Presence &presence);
     KIcon icon();
 };
diff --git a/presence-model.cpp b/presence-model.cpp
index a3b979e..7b109b2 100644
--- a/presence-model.cpp
+++ b/presence-model.cpp
@@ -13,7 +13,7 @@ PresenceModel::PresenceModel(QObject *parent) :
 
 QVariant PresenceModel::data(const QModelIndex &index, int role) const
 {
-    Tp::Presence presence = m_presences[index.row()];
+    KPresence presence = m_presences[index.row()];
     switch (role) {
     case Qt::DisplayRole:
         if (presence.statusMessage().isEmpty()) {
@@ -38,22 +38,7 @@ QVariant PresenceModel::data(const QModelIndex &index, int role) const
         }
 
     case Qt::DecorationRole:
-        switch (presence.type()) {
-        case Tp::ConnectionPresenceTypeAvailable:
-            return KIcon("user-online");
-        case Tp::ConnectionPresenceTypeBusy:
-            return KIcon("user-busy");
-        case Tp::ConnectionPresenceTypeAway:
-            return KIcon("user-away");
-        case Tp::ConnectionPresenceTypeExtendedAway:
-            return KIcon("user-away-extended");
-        case Tp::ConnectionPresenceTypeHidden:
-            return KIcon("user-invisible");
-        case Tp::ConnectionPresenceTypeOffline:
-            return KIcon("user-offline");
-        default:
-            return KIcon("");
-        }
+        return presence.icon();
 
     case Qt::FontRole:
         if (presence.statusMessage().isEmpty()) {
@@ -63,7 +48,7 @@ QVariant PresenceModel::data(const QModelIndex &index, int role) const
         }
 
     case PresenceModel::PresenceRole:
-        return QVariant::fromValue(presence);
+        return QVariant::fromValue<Tp::Presence>(presence);
 
     }
 
@@ -92,6 +77,10 @@ void PresenceModel::loadDefaultPresences()
 
 QModelIndex PresenceModel::addPresence(const Tp::Presence &presence)
 {
+    qDebug() << presence.status();
+    qDebug() << presence.statusMessage();
+
+
     beginInsertRows(QModelIndex(), m_presences.size(), m_presences.size());
     m_presences.append(presence);
     endInsertRows();
diff --git a/presence-model.h b/presence-model.h
index 5f6fc60..5f3152e 100644
--- a/presence-model.h
+++ b/presence-model.h
@@ -1,9 +1,9 @@
 #ifndef PRESENCEMODEL_H
 #define PRESENCEMODEL_H
 
-#include <QAbstractListModel>
+#include "kpresence.h"
 
-#include <TelepathyQt4/Presence>
+#include <QAbstractListModel>
 
 class PresenceModel : public QAbstractListModel
 {
@@ -33,7 +33,7 @@ signals:
 public slots:
 
 private:
-    QList<Tp::Presence> m_presences;
+    QList<KPresence> m_presences;
 
     /** Loads standard presences (online, away etc) into */
     void loadDefaultPresences();

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list