[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:46 UTC 2016


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

The following commit has been merged in the master branch:
commit 6bbdd85d244be63a23eaa7297db252e51daefca4
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Thu Oct 6 23:41:39 2011 +0100

    Better presence model. Supports adding/deletion from the custom dialog.
---
 dialogs/custom-presence-dialog.cpp | 119 ++++++++++++++++++-------------------
 dialogs/custom-presence-dialog.h   |  23 +++----
 global-presence-chooser.cpp        |  12 +++-
 kpresence.cpp                      |  28 ++++++++-
 kpresence.h                        |   5 +-
 presence-model.cpp                 |  47 ++++++++++++---
 presence-model.h                   |  11 +++-
 7 files changed, 155 insertions(+), 90 deletions(-)

diff --git a/dialogs/custom-presence-dialog.cpp b/dialogs/custom-presence-dialog.cpp
index 238eef0..9459087 100644
--- a/dialogs/custom-presence-dialog.cpp
+++ b/dialogs/custom-presence-dialog.cpp
@@ -21,20 +21,46 @@
 
 #include "custom-presence-dialog.h"
 
-#include <QListWidget>
+#include "presence-model.h"
+
+#include <QListView>
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QPushButton>
+#include <QSortFilterProxyModel>
+#include <QModelIndex>
+
+
 
 #include <KDialog>
 #include <KLocalizedString>
 #include <KConfig>
 #include <KSharedConfigPtr>
 
-#include <TelepathyQt4/Presence>	
+#include <TelepathyQt4/Presence>
+
+
+class FilteredModel : public QSortFilterProxyModel {
+public:
+    FilteredModel(QObject *parent);
+    bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+};
+
+FilteredModel::FilteredModel(QObject *parent)
+    : QSortFilterProxyModel(parent)
+{
+}
+
+bool FilteredModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+    QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+    Tp::Presence presence = index.data(PresenceModel::PresenceRole).value<Tp::Presence>();
+    return ! presence.statusMessage().isEmpty();
+}
 
-CustomPresenceDialog::CustomPresenceDialog(QWidget* parent)
-  : KDialog(parent)
+CustomPresenceDialog::CustomPresenceDialog(PresenceModel *model, QWidget *parent)
+  : KDialog(parent),
+    m_model(model)
 {
     setupDialog();
 }
@@ -45,13 +71,19 @@ void CustomPresenceDialog::setupDialog()
     setButtons(KDialog::Close);
  
     QWidget *mainDialogWidget = new QWidget(this);
-    m_listWidget = new QListWidget(mainDialogWidget);
+
+    FilteredModel *filteredModel = new FilteredModel(this);
+    filteredModel->setSourceModel(m_model);
+
+    m_listView = new QListView(mainDialogWidget);
+    m_listView->setModel(filteredModel);
+
     m_statusMessage = new KComboBox(true, mainDialogWidget);
     m_statusMessage->setTrapReturnKey(false);
  
-    m_statusMessage->addItem(KIcon("user-online"), QString("Set custom available message ..."),qVariantFromValue(Tp::Presence::available()));
-    m_statusMessage->addItem(KIcon("user-busy"), QString("Set custom busy message ..."), qVariantFromValue(Tp::Presence::busy()));
-    m_statusMessage->addItem(KIcon("user-away"), QString("Set custom away message ..."), qVariantFromValue(Tp::Presence::away()));
+    m_statusMessage->addItem(KIcon("user-online"), i18n("Set custom available message ..."),qVariantFromValue(Tp::Presence::available()));
+    m_statusMessage->addItem(KIcon("user-busy"), i18n("Set custom busy message ..."), qVariantFromValue(Tp::Presence::busy()));
+    m_statusMessage->addItem(KIcon("user-away"), i18n("Set custom away message ..."), qVariantFromValue(Tp::Presence::away()));
  
     m_statusMessage->setAutoCompletion(false);
     m_statusMessage->show();
@@ -63,7 +95,7 @@ void CustomPresenceDialog::setupDialog()
     vLayout->addWidget(m_statusMessage);
  
     QHBoxLayout *hLayout = new QHBoxLayout();
-    hLayout->addWidget(m_listWidget);
+    hLayout->addWidget(m_listView);
  
     QVBoxLayout *vLayout2 = new QVBoxLayout();
     vLayout2->addWidget(addStatus);
@@ -75,13 +107,12 @@ void CustomPresenceDialog::setupDialog()
 
     setMainWidget(mainDialogWidget);
 
-    KSharedConfigPtr config = KSharedConfig::openConfig("telepathy-kde-contactlistrc");
-    m_presenceGroup = new KConfigGroup( config, "Custom Presence List" );
-    int presenceIcon;
-    foreach(const QString& presenceString, m_presenceGroup->keyList()) {
-       presenceIcon = m_presenceGroup->readEntry<int>(presenceString, 0);
-       new QListWidgetItem(iconForIndex(presenceIcon), presenceString.left(presenceString.size() - 2), m_listWidget);
-    }
+
+//    int presenceIcon;
+//    foreach(const QString& presenceString, m_presenceGroup->keyList()) {
+//       presenceIcon = m_presenceGroup->readEntry<int>(presenceString, 0);
+//       new QListWidgetItem(iconForIndex(presenceIcon), presenceString.left(presenceString.size() - 2), m_listView);
+//    }
     
     connect(addStatus, SIGNAL(clicked()), SLOT(addCustomPresence()));
     connect(removeStatus, SIGNAL(clicked()), SLOT(removeCustomPresence()));
@@ -91,57 +122,25 @@ void CustomPresenceDialog::setupDialog()
 void CustomPresenceDialog::addCustomPresence()
 {
     int presenceIndex = m_statusMessage->currentIndex();
-    QString uniquePresenceString = m_statusMessage->currentText() + "_" + QString::number(m_statusMessage->currentIndex());
-    new QListWidgetItem(iconForIndex(presenceIndex), m_statusMessage->currentText(), m_listWidget);
-    m_presenceGroup->writeEntry(uniquePresenceString, m_statusMessage->currentIndex());
-    m_presenceGroup->sync();
-    emit configChanged();
+    Tp::Presence presence = m_statusMessage->itemData(presenceIndex).value<Tp::Presence>();
+    presence.setStatus(presence.type(), QString(), m_statusMessage->currentText());
+
+    m_model->addPresence(presence);
+
+//    QString uniquePresenceString = m_statusMessage->currentText() + "_" + QString::number(m_statusMessage->currentIndex());
+//    m_presenceGroup->writeEntry(uniquePresenceString, m_statusMessage->currentIndex());
+//    m_presenceGroup->sync();
 }
 
 void CustomPresenceDialog::removeCustomPresence()
 {
-   int index = indexForIcon(KIcon(m_listWidget->currentItem()->icon()));
-   if(index == -1) {
-     return;
-   } else { 
-      m_presenceGroup->deleteEntry(m_listWidget->currentItem()->text() + "_" + QString::number(index));
-      m_presenceGroup->sync();
-      emit configChanged();;
-      delete m_listWidget->currentItem();
+   if (! m_listView->currentIndex().isValid()) {
+       return;
    }
-}
 
-KIcon CustomPresenceDialog::iconForIndex(int index)
-{
-    QString iconName;
-
-    switch (index) {
-        case 0:
-            iconName = QLatin1String("user-online");
-            break;
-        case 1:
-            iconName = QLatin1String("user-busy");
-            break;
-        case 2:
-            iconName = QLatin1String("user-away");
-            break;
-    }
-
-    return KIcon(iconName);
+   Tp::Presence presence = m_listView->currentIndex().data(PresenceModel::PresenceRole).value<Tp::Presence>();
+   m_model->removePresence(presence);
 }
 
-int CustomPresenceDialog::indexForIcon(KIcon icon)
-{
-    if (icon.name() == QLatin1String("user-online")) {
-      return 0;
-    }
-    else if (icon.name() == QLatin1String("user-busy")) {
-      return 1;
-    }
-    else if (icon.name() == QLatin1String("user-away")) {
-      return 2;
-    }
-    return -1;
-}
 
 #include "custom-presence-dialog.moc"
diff --git a/dialogs/custom-presence-dialog.h b/dialogs/custom-presence-dialog.h
index df7e5fe..b694130 100644
--- a/dialogs/custom-presence-dialog.h
+++ b/dialogs/custom-presence-dialog.h
@@ -27,27 +27,23 @@
 
 //Forward declrare classes
 class KIcon;
-class QListWidget;
-class KConfig;
-class KConfigGroup;
+class QListView;
+class PresenceModel;
 
 class CustomPresenceDialog : public KDialog
 {
   Q_OBJECT
 
 public:
-    explicit CustomPresenceDialog(QWidget *parent = 0);
+    explicit CustomPresenceDialog(PresenceModel *model, QWidget *parent = 0);
 
-public Q_SLOTS:
+private Q_SLOTS:
     ///Adds a custom presence to the config file
     void addCustomPresence();
 
     ///Removes a custom presence from the config file
     void removeCustomPresence();
 
-Q_SIGNALS:
-  void configChanged();
-
 private:
     ///Setup the initial dialog
     void setupDialog();
@@ -55,20 +51,15 @@ private:
     ///Returns corresponding icon for index read from the config file
     static KIcon iconForIndex(int index);
 
-    ///Retruns corresponding index for icon
-    static int indexForIcon(KIcon icon);
-
     ///ListWidget to display custom presence's
-    QListWidget  *m_listWidget;
+    QListView  *m_listView;
 
     ///Combobox to type custom presence's
     KComboBox    *m_statusMessage;
 
-    ///KConfig variable to read/write/sync changes to disk
-    KConfig      *m_config;
 
-    ///KConfigGroup variable to read/write/sync changes to disk
-    KConfigGroup *m_presenceGroup;
+
+    PresenceModel *m_model;
   
 };
 
diff --git a/global-presence-chooser.cpp b/global-presence-chooser.cpp
index caf332c..e74d95e 100644
--- a/global-presence-chooser.cpp
+++ b/global-presence-chooser.cpp
@@ -2,6 +2,7 @@
 
 #include "global-presence.h"
 #include "presence-model.h"
+#include "dialogs/custom-presence-dialog.h"
 
 #include <KIcon>
 #include <KLocale>
@@ -32,8 +33,15 @@ void GlobalPresenceChooser::setAccountManager(const Tp::AccountManagerPtr &accou
 
 void GlobalPresenceChooser::onCurrentIndexChanged(int index)
 {
-    Tp::Presence presence = itemData(index, PresenceModel::PresenceRole).value<Tp::Presence>();
-    m_globalPresence->setPresence(presence);
+    //FIXME hack - if they select the "configure item"
+    if (index == count()-1) {
+        CustomPresenceDialog dialog(m_model, this);
+        dialog.exec();
+        onPresenceChanged(m_globalPresence->currentPresence());
+    } else {
+        Tp::Presence presence = itemData(index, PresenceModel::PresenceRole).value<Tp::Presence>();
+        m_globalPresence->setPresence(presence);
+    }
 }
 
 void GlobalPresenceChooser::onPresenceChanged(const Tp::Presence &presence)
diff --git a/kpresence.cpp b/kpresence.cpp
index 8de6e5a..698812d 100644
--- a/kpresence.cpp
+++ b/kpresence.cpp
@@ -11,7 +11,7 @@ KPresence::KPresence(const Tp::Presence &presence) :
 {
 }
 
-KIcon KPresence::icon()
+KIcon KPresence::icon() const
 {
     switch (type()) {
     case Tp::ConnectionPresenceTypeAvailable:
@@ -31,3 +31,29 @@ KIcon KPresence::icon()
     }
 }
 
+bool KPresence::operator <(const KPresence &other) const
+{
+    /// Sets the sorting order of presences
+    QHash<uint, int> m_presenceSorting;
+
+    m_presenceSorting[Tp::ConnectionPresenceTypeAvailable] = 0;
+    m_presenceSorting[Tp::ConnectionPresenceTypeBusy] = 1;
+    m_presenceSorting[Tp::ConnectionPresenceTypeHidden] = 2;
+    m_presenceSorting[Tp::ConnectionPresenceTypeAway] = 3;
+    m_presenceSorting[Tp::ConnectionPresenceTypeExtendedAway] = 4;
+    m_presenceSorting[Tp::ConnectionPresenceTypeHidden] = 5;
+    //don't distinguish between the following three presences
+    m_presenceSorting[Tp::ConnectionPresenceTypeError] = 6;
+    m_presenceSorting[Tp::ConnectionPresenceTypeUnknown] = 6;
+    m_presenceSorting[Tp::ConnectionPresenceTypeUnset] = 6;
+    m_presenceSorting[Tp::ConnectionPresenceTypeOffline] = 7;
+
+    if (m_presenceSorting[type()] < m_presenceSorting[other.type()]) {
+        return true;
+    } else if (m_presenceSorting[type()] == m_presenceSorting[other.type()]) {
+        return (statusMessage() < other.statusMessage());
+    } else {
+        return false;
+    }
+}
+
diff --git a/kpresence.h b/kpresence.h
index 124e32f..59d4fc1 100644
--- a/kpresence.h
+++ b/kpresence.h
@@ -11,7 +11,10 @@ class KPresence : public Tp::Presence
 public:
     KPresence();
     KPresence(const Tp::Presence &presence);
-    KIcon icon();
+    KIcon icon() const;
+
+
+    bool operator <(const KPresence &other) const;
 };
 
 #endif // KPRESENCE_H
diff --git a/presence-model.cpp b/presence-model.cpp
index 7b109b2..23a7947 100644
--- a/presence-model.cpp
+++ b/presence-model.cpp
@@ -5,10 +5,18 @@
 #include <KIcon>
 #include <KLocalizedString>
 
+#include <KConfig>
+#include <KConfigGroup>
+
+
+
 PresenceModel::PresenceModel(QObject *parent) :
     QAbstractListModel(parent)
 {
     loadDefaultPresences();
+
+    KSharedConfigPtr config = KSharedConfig::openConfig("telepathy-kde-contactlistrc");
+    m_presenceGroup = new KConfigGroup( config, "Custom Presence List" );
 }
 
 QVariant PresenceModel::data(const QModelIndex &index, int role) const
@@ -63,27 +71,48 @@ int PresenceModel::rowCount(const QModelIndex &parent) const
 void PresenceModel::loadDefaultPresences()
 {
     addPresence(Tp::Presence::available());
+
     addPresence(Tp::Presence::busy());
+
+    addPresence(Tp::Presence::xa());
+    addPresence(Tp::Presence::xa("Abducted by aliens, back later"));
+
+
     addPresence(Tp::Presence::away());
     addPresence(Tp::Presence::away("Back Soon!"));
     addPresence(Tp::Presence::away("Off to eat some cheese"));
-    addPresence(Tp::Presence::xa());
-    addPresence(Tp::Presence::xa("Abducted by aliens, back later"));
+
+
     addPresence(Tp::Presence::hidden());
     addPresence(Tp::Presence::offline());
 
-    addPresence(Tp::Presence::available("Configure Custom Messages..."));
+
+    //FIXME FIXME FIXIME this is just a hack!
+    addPresence(Tp::Presence::offline("Configure Custom Messages..."));
 }
 
 QModelIndex PresenceModel::addPresence(const Tp::Presence &presence)
 {
-    qDebug() << presence.status();
-    qDebug() << presence.statusMessage();
-
+    QList<KPresence>::iterator i = qLowerBound(m_presences.begin(), m_presences.end(), KPresence(presence));
 
-    beginInsertRows(QModelIndex(), m_presences.size(), m_presences.size());
-    m_presences.append(presence);
+    m_presences.insert(i, presence);
+    int index = m_presences.indexOf(presence);
+    //this is technically a backwards and wrong, but I can't get a row from a const iterator, and using qLowerBound does seem a good approach
+    beginInsertRows(QModelIndex(), index, index);
     endInsertRows();
 
-    return createIndex(m_presences.size(), 0);
+    //save changes
+    m_presenceGroup->writeEntry("presences", presence);
+
+    return createIndex(index, 0);
+}
+
+void PresenceModel::removePresence(const Tp::Presence &presence)
+{
+    int row = m_presences.indexOf(presence);
+    beginRemoveRows(QModelIndex(), row, row);
+    m_presences.removeOne(presence);
+    endRemoveRows();
+
+    //FIXME edit the config file too
 }
diff --git a/presence-model.h b/presence-model.h
index 5f3152e..9138b6c 100644
--- a/presence-model.h
+++ b/presence-model.h
@@ -5,6 +5,8 @@
 
 #include <QAbstractListModel>
 
+class KConfigGroup;
+
 class PresenceModel : public QAbstractListModel
 {
     Q_OBJECT
@@ -21,6 +23,8 @@ public:
     */
     QModelIndex addPresence(const Tp::Presence &presence);
 
+    void removePresence(const Tp::Presence &presence);
+
     /** Returns the index of a given presence, adding it if needed*/
     QModelIndex indexOf(const Tp::Presence &presence);
 
@@ -33,13 +37,18 @@ signals:
 public slots:
 
 private:
-    QList<KPresence> m_presences;
 
     /** Loads standard presences (online, away etc) into */
     void loadDefaultPresences();
 
     /** Loads any user custom presences into the model*/
     void loadCustomPresences();
+
+
+    QList<KPresence> m_presences;
+
+    //this is wrong, KConfigGroup is a sharedptr..
+    KConfigGroup *m_presenceGroup;
 };
 
 #endif // PRESENCEMODEL_H

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list