[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:08:05 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=77edce6
The following commit has been merged in the master branch:
commit 77edce62b7ad3a6548c8320b9ae7878c92679325
Author: Siddhartha Sahu <sh.siddhartha at gmail.com>
Date: Wed Mar 19 00:13:42 2014 +0530
Move PresenceModel to K-C-I
REVIEW: 116882
---
KTp/Models/CMakeLists.txt | 2 +
KTp/Models/presence-model.cpp | 200 ++++++++++++++++++++++++++++++++++++++++++
KTp/Models/presence-model.h | 85 ++++++++++++++++++
3 files changed, 287 insertions(+)
diff --git a/KTp/Models/CMakeLists.txt b/KTp/Models/CMakeLists.txt
index f5c18b5..e89c7d7 100644
--- a/KTp/Models/CMakeLists.txt
+++ b/KTp/Models/CMakeLists.txt
@@ -11,6 +11,7 @@ set (ktp_models_private_SRCS
contacts-list-model.cpp
contacts-model.cpp
groups-tree-proxy-model.cpp
+ presence-model.cpp
text-channel-watcher-proxy-model.cpp
rooms-model.cpp
)
@@ -23,6 +24,7 @@ set (ktp_models_private_HDRS
contacts-list-model.h
contacts-model.h
groups-tree-proxy-model.h
+ presence-model.h
text-channel-watcher-proxy-model.h
rooms-model.h
)
diff --git a/KTp/Models/presence-model.cpp b/KTp/Models/presence-model.cpp
new file mode 100644
index 0000000..4bce22b
--- /dev/null
+++ b/KTp/Models/presence-model.cpp
@@ -0,0 +1,200 @@
+/*
+ * Presence Model - A model of settable presences.
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "presence-model.h"
+
+#include <QString>
+#include <QtGui/QFont>
+#include <QtDBus/QtDBus>
+
+#include <KDE/KIcon>
+#include <KDE/KLocalizedString>
+#include <KDE/KConfig>
+#include <KDE/KConfigGroup>
+#include <KDE/KGlobalSettings>
+#include <KDE/KDebug>
+
+namespace KTp
+{
+
+PresenceModel::PresenceModel(QObject *parent) :
+ QAbstractListModel(parent)
+{
+ loadPresences();
+}
+
+PresenceModel::~PresenceModel()
+{
+ syncCustomPresencesToDisk();
+}
+
+void PresenceModel::syncCustomPresencesToDisk()
+{
+ m_presenceGroup.deleteGroup();
+
+ Q_FOREACH (const KTp::Presence &presence, m_presences) {
+ if (!presence.statusMessage().isEmpty()) {
+ QVariantList presenceVariant;
+ presenceVariant.append(presence.type());
+ presenceVariant.append(presence.statusMessage());
+ QString id = QString::number(presence.type()).append(presence.statusMessage());
+ m_presenceGroup.writeEntry(id, presenceVariant);
+ }
+ }
+ m_presenceGroup.sync();
+}
+
+QVariant PresenceModel::data(int index) const
+{
+ if (index < 0 || index >= m_presences.size()) {
+ kDebug() << "invalid index data requested" << index;
+ return QVariant();
+ }
+
+ return QVariant::fromValue<KTp::Presence>(m_presences[index]);
+}
+
+QVariant PresenceModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid()) {
+ kDebug() << "invalid index data requested" << index;
+ return QVariant();
+ }
+
+ KTp::Presence presence = m_presences[index.row()];
+ switch (role) {
+ case Qt::DisplayRole:
+ if (presence.statusMessage().isEmpty()) {
+ return presence.displayString();
+ } else {
+ return presence.statusMessage();
+ }
+
+ case Qt::DecorationRole:
+ return presence.icon();
+
+ case Qt::FontRole:
+ if (presence.statusMessage().isEmpty()) {
+ QFont font = KGlobalSettings::generalFont();
+ font.setBold(true);
+ return font;
+ } else {
+ return QVariant();
+ }
+
+ case PresenceModel::PresenceRole:
+ return QVariant::fromValue<KTp::Presence>(presence);
+
+ }
+
+ return QVariant();
+}
+
+int PresenceModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent)
+ return m_presences.size();
+}
+
+void PresenceModel::loadPresences()
+{
+ KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+ config->reparseConfiguration();
+ m_presenceGroup = config->group("Custom Presence List");
+ m_presences.clear();
+ loadDefaultPresences();
+ loadCustomPresences();
+}
+
+void PresenceModel::loadDefaultPresences()
+{
+ addPresence(Tp::Presence::available());
+ addPresence(Tp::Presence::busy());
+ addPresence(Tp::Presence::away());
+ addPresence(Tp::Presence::xa());
+ addPresence(Tp::Presence::hidden());
+ addPresence(Tp::Presence::offline());
+}
+
+void PresenceModel::loadCustomPresences()
+{
+ Q_FOREACH (const QString &key, m_presenceGroup.keyList()) {
+ QVariantList entry = m_presenceGroup.readEntry(key, QVariantList());
+
+ QString statusMessage = entry.last().toString();
+
+ switch (entry.first().toInt()) {
+ case Tp::ConnectionPresenceTypeAvailable:
+ addPresence(Tp::Presence::available(statusMessage));
+ break;
+ case Tp::ConnectionPresenceTypeAway:
+ addPresence(Tp::Presence::away(statusMessage));
+ break;
+ case Tp::ConnectionPresenceTypeBusy:
+ addPresence(Tp::Presence::busy(statusMessage));
+ break;
+ case Tp::ConnectionPresenceTypeExtendedAway:
+ addPresence(Tp::Presence::xa(statusMessage));
+ }
+ }
+}
+
+QModelIndex PresenceModel::addPresence(const KTp::Presence &presence)
+{
+ if (m_presences.contains(presence)) {
+ return createIndex(m_presences.indexOf(presence), 0);
+ }
+
+ QList<KTp::Presence>::iterator i = qLowerBound(m_presences.begin(), m_presences.end(), KTp::Presence(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(index, 0);
+}
+
+void PresenceModel::removePresence(const KTp::Presence &presence)
+{
+ int row = m_presences.indexOf(presence);
+ beginRemoveRows(QModelIndex(), row, row);
+ m_presences.removeOne(presence);
+ endRemoveRows();
+ QString id = QString::number(presence.type()).append(presence.statusMessage());
+}
+
+int PresenceModel::updatePresenceApplet()
+{
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ return 1;
+ }
+
+ QDBusInterface callApplet(QLatin1String("org.kde.Telepathy.PresenceAppletActive"),
+ QLatin1String("/"), QLatin1String(""), QDBusConnection::sessionBus());
+ if (callApplet.isValid()) {
+ callApplet.asyncCall(QLatin1String("handleCustomPresenceChange"));
+ return 0;
+ }
+ return 1;
+}
+
+}
diff --git a/KTp/Models/presence-model.h b/KTp/Models/presence-model.h
new file mode 100644
index 0000000..666dbc4
--- /dev/null
+++ b/KTp/Models/presence-model.h
@@ -0,0 +1,85 @@
+/*
+ * Presence Model - A model of settable presences.
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PRESENCEMODEL_H
+#define PRESENCEMODEL_H
+
+#include <QAbstractListModel>
+
+#include <KConfigGroup>
+
+#include <KTp/presence.h>
+
+namespace KTp
+{
+
+class KTP_EXPORT PresenceModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ explicit PresenceModel(QObject *parent = 0);
+ ~PresenceModel();
+
+ enum Roles {
+ //Also supplies Qt::DisplayRole and Qt::DecorationRole
+ PresenceRole = Qt::UserRole
+ };
+
+ /** Adds a custom presence to the model, and write value to config file.
+ @return the newly added item
+ */
+ QModelIndex addPresence(const KTp::Presence &presence);
+
+ void removePresence(const KTp::Presence &presence);
+
+ /** Load all presences from disk */
+ void loadPresences();
+
+ /** Write all presences to disk */
+ void syncCustomPresencesToDisk();
+
+ /** Updates context menu of presence applet */
+ int updatePresenceApplet();
+
+ /** Returns the index of a given presence, adding it if needed */
+ QModelIndex indexOf(const KTp::Presence &presence);
+
+ //protected:
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual QVariant data(int index) const;
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+
+private:
+
+ /** Loads standard presences (online, away etc) into */
+ void loadDefaultPresences();
+
+ /** Loads any user custom presences into the model */
+ void loadCustomPresences();
+
+ QList<KTp::Presence> m_presences;
+
+ //this is wrong, KConfigGroup is a sharedptr..
+ KConfigGroup m_presenceGroup;
+};
+
+}
+
+#endif // PRESENCEMODEL_H
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list