[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:06:54 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=97e4a2f
The following commit has been merged in the master branch:
commit 97e4a2fc555e71a9748c1aa1a39f99c9f2666a22
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Tue Jun 25 02:00:42 2013 +0100
Switch ContactsModel between legacy mode and KPeople powered
Include a proxy model that translates between KPeople and KTp roles
so that it can seemlessly port the two
---
KTp/Models/CMakeLists.txt | 30 +++-
KTp/Models/contacts-model.cpp | 23 ++-
KTp/Models/kpeopletranslationproxy.cpp | 159 +++++++++++++++++++++
.../kpeopletranslationproxy.h} | 31 ++--
4 files changed, 225 insertions(+), 18 deletions(-)
diff --git a/KTp/Models/CMakeLists.txt b/KTp/Models/CMakeLists.txt
index 720a5b0..263c630 100644
--- a/KTp/Models/CMakeLists.txt
+++ b/KTp/Models/CMakeLists.txt
@@ -3,6 +3,9 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
+
+
+
set (ktp_models_private_SRCS
${KTP_GLOBAL_SOURCES}
abstract-grouping-proxy-model.cpp
@@ -28,6 +31,26 @@ set (ktp_models_private_HDRS
rooms-model.h
)
+set (ktp_models_private_LIBS
+ ${KDE4_KDECORE_LIBS}
+ ${TELEPATHY_QT4_LIBRARIES}
+ ${KDE4_KDEUI_LIBS}
+ ktpcommoninternalsprivate
+)
+
+if (KPEOPLE_FOUND)
+ add_definitions(-DHAVE_KPEOPLE)
+ set (ktp_models_private_SRCS
+ ${ktp_models_private_SRCS}
+ kpeopletranslationproxy.cpp
+ )
+
+ set (ktp_models_private_LIBS
+ ${ktp_models_private_LIBS}
+ kpeople
+ )
+endif (KPEOPLE_FOUND)
+
kde4_add_library (ktpmodelsprivate SHARED
${ktp_models_private_SRCS}
)
@@ -39,12 +62,11 @@ set_target_properties(ktpmodelsprivate PROPERTIES
DEFINE_SYMBOL MAKE_KTP_LIB)
target_link_libraries (ktpmodelsprivate
- ${KDE4_KDECORE_LIBS}
- ${TELEPATHY_QT4_LIBRARIES}
- ${KDE4_KDEUI_LIBS}
- ktpcommoninternalsprivate
+ ${ktp_models_private_LIBS}
)
+
+
install (TARGETS ktpmodelsprivate
DESTINATION ${LIB_INSTALL_DIR}
)
diff --git a/KTp/Models/contacts-model.cpp b/KTp/Models/contacts-model.cpp
index 9506151..c719b6c 100644
--- a/KTp/Models/contacts-model.cpp
+++ b/KTp/Models/contacts-model.cpp
@@ -27,6 +27,11 @@
#include <TelepathyQt/ClientRegistrar>
+#ifdef HAVE_KPEOPLE
+#include <KPeople/PersonsModel>
+#include "kpeopletranslationproxy.h"
+#endif
+
namespace KTp
{
class ContactsModel::Private
@@ -35,7 +40,12 @@ public:
GroupMode groupMode;
bool trackUnread;
QWeakPointer<KTp::AbstractGroupingProxyModel> proxy;
- KTp::ContactsListModel *source;
+#ifdef HAVE_KPEOPLE
+ KPeopleTranslationProxy *source;
+#else
+ ContactsListModel *source;
+#endif
+
Tp::AccountManagerPtr accountManager;
Tp::ClientRegistrarPtr clientRegistrar;
Tp::SharedPtr<KTp::TextChannelWatcherProxyModel> channelWatcherProxy;
@@ -49,7 +59,16 @@ KTp::ContactsModel::ContactsModel(QObject *parent)
{
d->groupMode = NoGrouping;
d->trackUnread = false;
+#ifdef HAVE_KPEOPLE
+ KPeople::PersonsModel *personsModel = new KPeople::PersonsModel(KPeople::PersonsModel::FeatureIM,
+ KPeople::PersonsModel::FeatureAvatars |
+ KPeople::PersonsModel::FeatureGroups,
+ this);
+ d->source = new KPeopleTranslationProxy(this);
+ d->source->setSourceModel(personsModel);
+#else
d->source = new KTp::ContactsListModel(this);
+#endif
}
KTp::ContactsModel::~ContactsModel()
@@ -65,7 +84,9 @@ void KTp::ContactsModel::setAccountManager(const Tp::AccountManagerPtr &accountM
updateGroupProxyModels();
//set the account manager after we've reloaded the groups so that we don't send a list to the view, only to replace it with a grouped tree
+#ifndef HAVE_KPEOPLE
d->source->setAccountManager(accountManager);
+#endif
}
Tp::AccountManagerPtr KTp::ContactsModel::accountManager() const
diff --git a/KTp/Models/kpeopletranslationproxy.cpp b/KTp/Models/kpeopletranslationproxy.cpp
new file mode 100644
index 0000000..e231823
--- /dev/null
+++ b/KTp/Models/kpeopletranslationproxy.cpp
@@ -0,0 +1,159 @@
+/*
+ Copyright (C) 2013 Martin Klapetek <mklapetek at kde.org>
+
+ 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include "kpeopletranslationproxy.h"
+
+#include <KPeople/PersonsModel>
+
+//temporary hack until IM data source moves to KTp where it belongs
+#include <kpeople/personpluginmanager.h>
+#include <kpeople/impersonsdatasource.h>
+
+#include <KTp/types.h>
+#include <KDebug>
+
+using namespace KPeople;
+
+
+KPeopleTranslationProxy::KPeopleTranslationProxy(QObject *parent)
+ : QIdentityProxyModel(parent)
+{
+}
+
+KPeopleTranslationProxy::~KPeopleTranslationProxy()
+{
+}
+
+QVariant KPeopleTranslationProxy::data(const QModelIndex &proxyIndex, int role) const
+{
+ if (!proxyIndex.isValid()) {
+ return QVariant();
+ }
+
+ IMPersonsDataSource *imPlugin = qobject_cast<IMPersonsDataSource*>(PersonPluginManager::presencePlugin());
+
+ if (!imPlugin) {
+ kWarning() << "No imPlugin";
+ return QVariant();
+ }
+
+ switch (role) {
+ case KTp::ContactPresenceTypeRole:
+ return translatePresence(mapToSource(proxyIndex).data(PersonsModel::PresenceTypeRole));
+ case KTp::ContactPresenceIconRole:
+ return mapToSource(proxyIndex).data(PersonsModel::PresenceDecorationRole);
+ case KTp::ContactPresenceNameRole:
+ return mapToSource(proxyIndex).data(PersonsModel::PresenceDisplayRole);
+ case Qt::DisplayRole:
+ return mapToSource(proxyIndex).data(Qt::DisplayRole);
+ case KTp::RowTypeRole:
+ if (sourceModel()->rowCount(mapToSource(proxyIndex)) <= 1) {
+ return KTp::ContactRowType;
+ } else {
+ return KTp::PersonRowType;
+ }
+ case KTp::ContactAvatarPathRole:
+ return mapToSource(proxyIndex).data(PersonsModel::PhotosRole);
+ case KTp::IdRole:
+ return mapToSource(proxyIndex).data(PersonsModel::IMsRole);
+ case KTp::HeaderTotalUsersRole:
+ return sourceModel()->rowCount(mapToSource(proxyIndex));
+ case KTp::ContactGroupsRole:
+ return mapToSource(proxyIndex).data(PersonsModel::GroupsRole);
+ }
+
+ QVariantList ret;
+
+ int j = sourceModel()->rowCount(mapToSource(proxyIndex));
+ bool isChildContact = false;
+ if (j == 0) {
+ isChildContact = true;
+ j = 1;
+ }
+
+ for (int i = 0; i < j; i++) {
+ const QString contactId = isChildContact ? mapToSource(proxyIndex).data(PersonsModel::IMsRole).toString()
+ : mapToSource(proxyIndex).data(PersonsModel::IMsRole).toList().at(i).toString();
+ const KTp::ContactPtr contact = imPlugin->contactForContactId(contactId);
+
+ if (!contact.isNull()) {
+ switch (role) {
+ case KTp::ContactRole:
+ ret += QVariant::fromValue<KTp::ContactPtr>(contact);
+ break;
+ case KTp::AccountRole:
+ ret += QVariant::fromValue<Tp::AccountPtr>(imPlugin->accountForContact(contact));
+ break;
+ case KTp::ContactPresenceMessageRole:
+ ret += contact->presence().statusMessage();
+ break;
+ case KTp::ContactIsBlockedRole:
+ ret += contact->isBlocked();
+ break;
+ case KTp::ContactCanTextChatRole:
+ ret += true;
+ break;
+ case KTp::ContactCanAudioCallRole:
+ ret += contact->audioCallCapability();
+ break;
+ case KTp::ContactCanVideoCallRole:
+ ret += contact->videoCallCapability();
+ break;
+ case KTp::ContactCanFileTransferRole:
+ ret += contact->fileTransferCapability();
+ break;
+ case KTp::ContactClientTypesRole:
+ ret += contact->clientTypes();
+ break;
+ }
+ } else if (contact.isNull() && role == KTp::AccountRole) {
+ //if the KTp contact is null, we still need the Tp account for that contact
+ //so we can either group it properly or bring that account online if user
+ //starts a chat with a contact that belongs to offline account
+ ret += QVariant::fromValue<Tp::AccountPtr>(imPlugin->accountForContactId(contactId));
+ }
+ }
+
+ return ret;
+}
+
+QVariant KPeopleTranslationProxy::translatePresence(const QVariant &presenceName) const
+{
+ if (presenceName == QLatin1String("available")) {
+ return Tp::ConnectionPresenceTypeAvailable;
+ }
+
+ if (presenceName == QLatin1String("away")) {
+ return Tp::ConnectionPresenceTypeAway;
+ }
+
+ if (presenceName == QLatin1String("busy") || presenceName == QLatin1String("dnd")) {
+ return Tp::ConnectionPresenceTypeBusy;
+ }
+
+ if (presenceName == QLatin1String("xa")) {
+ return Tp::ConnectionPresenceTypeExtendedAway;
+ }
+
+ if (presenceName == QLatin1String("hidden")) {
+ return Tp::ConnectionPresenceTypeHidden;
+ }
+
+ return Tp::ConnectionPresenceTypeOffline;
+}
diff --git a/KTp/wallet-utils.h b/KTp/Models/kpeopletranslationproxy.h
similarity index 59%
copy from KTp/wallet-utils.h
copy to KTp/Models/kpeopletranslationproxy.h
index eeab936..a37e881 100644
--- a/KTp/wallet-utils.h
+++ b/KTp/Models/kpeopletranslationproxy.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012 David Edmundson <kde at davidedmundson.co.uk>
+ Copyright (C) 2013 Martin Klapetek <mklapetek at kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -16,21 +16,26 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef WALLETUTILS_H
-#define WALLETUTILS_H
-#include <TelepathyQt/PendingOperation>
-#include <TelepathyQt/Account>
+#ifndef KTP_TRANSLATION_PROXY_H
+#define KTP_TRANSLATION_PROXY_H
+
+#include <QIdentityProxyModel>
#include <KTp/ktp-export.h>
-namespace KTp
-{
-namespace WalletUtils
+class KTP_EXPORT KPeopleTranslationProxy : public QIdentityProxyModel
{
- KTP_EXPORT Tp::PendingOperation * setAccountPassword(const Tp::AccountPtr &account, const QString &password);
- KTP_EXPORT Tp::PendingOperation * removeAccountPassword(const Tp::AccountPtr &account);
-}
-}
+ Q_OBJECT
+
+public:
+ KPeopleTranslationProxy(QObject *parent = 0);
+ virtual ~KPeopleTranslationProxy();
+
+ virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const;
+
+private:
+ QVariant translatePresence(const QVariant &presenceName) const;
+};
-#endif //WALLETUTILS_H
+#endif // KTP_TRANSLATION_PROXY_H
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list