[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:04:33 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=57678f6
The following commit has been merged in the master branch:
commit 57678f683077023840515975cd2737c0022a0de7
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date: Mon Sep 12 15:25:43 2011 +0200
Add basic drag&drop support for contact list
Currently only dragging between groups is supported, but much more is planned (and in the works already).
Reviewed-by: David Edmundson
REVIEW: 102543
FEATURE: 279657
DIGEST
---
models/accounts-model.cpp | 7 +++-
models/groups-model-item.cpp | 3 +-
models/groups-model.cpp | 95 +++++++++++++++++++++++++++++++++++++++++---
models/groups-model.h | 11 +++--
models/proxy-tree-node.cpp | 3 +-
5 files changed, 107 insertions(+), 12 deletions(-)
diff --git a/models/accounts-model.cpp b/models/accounts-model.cpp
index 17846bf..d430e44 100644
--- a/models/accounts-model.cpp
+++ b/models/accounts-model.cpp
@@ -247,7 +247,12 @@ Tp::AccountPtr AccountsModel::accountForContactItem(ContactModelItem *contactIte
Qt::ItemFlags AccountsModel::flags(const QModelIndex &index) const
{
if (index.isValid()) {
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+ bool isContact = index.data(AccountsModel::ItemRole).userType() == qMetaTypeId<ContactModelItem*>();
+ if (isContact) {
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
+ } else {
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
+ }
}
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
diff --git a/models/groups-model-item.cpp b/models/groups-model-item.cpp
index 12acbaa..d441e9c 100644
--- a/models/groups-model-item.cpp
+++ b/models/groups-model-item.cpp
@@ -20,10 +20,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "groups-model-item.h"
+
#include <TelepathyQt4/Account>
#include <TelepathyQt4/ContactManager>
-#include "groups-model-item.h"
#include "groups-model.h"
#include "accounts-model.h"
#include "proxy-tree-node.h"
diff --git a/models/groups-model.cpp b/models/groups-model.cpp
index 1ee874a..b692ff5 100644
--- a/models/groups-model.cpp
+++ b/models/groups-model.cpp
@@ -20,11 +20,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "groups-model.h"
+
#include <TelepathyQt4/ContactManager>
#include <TelepathyQt4/Contact>
#include <TelepathyQt4/PendingReady>
-#include "groups-model.h"
#include "groups-model-item.h"
#include "proxy-tree-node.h"
#include "accounts-model.h"
@@ -103,12 +104,94 @@ QVariant GroupsModel::data(const QModelIndex &index, int role) const
Qt::ItemFlags GroupsModel::flags(const QModelIndex &index) const
{
if (index.isValid()) {
- return Qt::ItemIsEnabled;
+ bool isGroup = index.data(AccountsModel::ItemRole).userType() == qMetaTypeId<GroupsModelItem*>();
+ if (isGroup) {
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
+ } else {
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
+ }
}
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}
+Qt::DropActions GroupsModel::supportedDropActions() const
+{
+ return Qt::CopyAction | Qt::MoveAction;
+}
+
+QStringList GroupsModel::mimeTypes() const
+{
+ QStringList types;
+ types << "application/vnd.telepathy.contact";
+ return types;
+}
+
+QMimeData* GroupsModel::mimeData(const QModelIndexList& indexes) const
+{
+ QMimeData *mimeData = new QMimeData();
+ QByteArray encodedData;
+
+ QDataStream stream(&encodedData, QIODevice::WriteOnly);
+
+ foreach (const QModelIndex &index, indexes) {
+ if (index.isValid()) {
+ ContactModelItem *c = data(index, AccountsModel::ItemRole).value<ContactModelItem*>();
+ //We put a contact ID and its account ID to the stream, so we can later recreate the contact using AccountsModel
+ stream << c->contact().data()->id() << mPriv->mAM->accountForContactItem(c).data()->uniqueIdentifier();
+ }
+ }
+
+ mimeData->setData("application/vnd.telepathy.contact", encodedData);
+ return mimeData;
+}
+
+bool GroupsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
+{
+ if (action == Qt::IgnoreAction) {
+ return true;
+ }
+
+ if (!data->hasFormat("application/vnd.telepathy.contact")) {
+ return false;
+ }
+
+ if (column > 0) {
+ return false;
+ }
+
+ QByteArray encodedData = data->data("application/vnd.telepathy.contact");
+ QDataStream stream(&encodedData, QIODevice::ReadOnly);
+ QList<ContactModelItem*> contacts;
+
+ while (!stream.atEnd()) {
+ QString contact;
+ QString account;
+ //get contact and account out of the stream
+ stream >> contact >> account;
+ //casted pointer is checked below, before first use
+ contacts.append(qobject_cast<ContactModelItem*>(mPriv->mAM->contactItemForId(account, contact)));
+ }
+
+ foreach (ContactModelItem *contact, contacts) {
+ Q_ASSERT(contact);
+ QString group = parent.data(GroupsModel::GroupNameRole).toString();
+
+ kDebug() << contact->contact().data()->alias() << "added to group" << group;
+
+ if (group != QLatin1String("Ungrouped")) { //FIXME: consider i18n
+ //FIXME: Should we connect this somewhere?
+ Tp::PendingOperation *op = contact->contact().data()->manager().data()->addContactsToGroup(group,
+ QList<Tp::ContactPtr>() << contact->contact());
+
+ connect(op, SIGNAL(finished(Tp::PendingOperation*)),
+ this, SIGNAL(operationFinished(Tp::PendingOperation*)));
+ }
+ }
+
+ return true;
+}
+
bool GroupsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid()) {
@@ -272,9 +355,10 @@ void GroupsModel::removeContactFromGroup(ProxyTreeNode* proxyNode, const QString
addContactToGroups(proxyNode->data(AccountsModel::ItemRole).value<ContactModelItem*>(), contactGroups);
}
-// beginRemoveRows(index(proxyNode->parent()), proxyNode->parent()->indexOf(proxyNode), proxyNode->parent()->indexOf(proxyNode));
qobject_cast<GroupsModelItem*>(proxyNode->parent())->removeProxyContact(proxyNode);
-// endRemoveRows();
+ ContactModelItem *contactItem = proxyNode->data(AccountsModel::ItemRole).value<ContactModelItem*>();
+ Q_ASSERT(contactItem);
+ contactItem->contact().data()->manager().data()->removeContactsFromGroup(group, QList<Tp::ContactPtr>() << contactItem->contact());
}
}
@@ -301,7 +385,7 @@ void GroupsModel::addContactToGroups(ContactModelItem* contactItem, QStringList
groups.removeDuplicates();
- foreach (QString group, groups) {
+ foreach (const QString &group, groups) {
bool groupExists = false;
GroupsModelItem *groupItem;
@@ -347,4 +431,3 @@ void GroupsModel::addContactToGroups(ContactModelItem* contactItem, QStringList
}
}
-
diff --git a/models/groups-model.h b/models/groups-model.h
index f838897..ef9b28e 100644
--- a/models/groups-model.h
+++ b/models/groups-model.h
@@ -57,6 +57,7 @@ public:
virtual QVariant data(const QModelIndex &index, int role) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual Qt::DropActions supportedDropActions() const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
virtual QModelIndex index(TreeNode *node) const;
@@ -69,9 +70,13 @@ public:
void removeContactFromGroup(ProxyTreeNode* proxyNode, const QString& group);
-// Q_SIGNALS:
-// void accountCountChanged();
-// void accountConnectionStatusChanged(const QString &accountId, int status);
+ virtual QStringList mimeTypes() const;
+ virtual QMimeData* mimeData(const QModelIndexList &indexes) const;
+ virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
+
+Q_SIGNALS:
+ //a signal for reemitting the operation status, used for displaying errors in GUI
+ void operationFinished(Tp::PendingOperation *op);
private Q_SLOTS:
// void onNewAccount(const Tp::AccountPtr &account);
diff --git a/models/proxy-tree-node.cpp b/models/proxy-tree-node.cpp
index 7d8c8e4..e413509 100644
--- a/models/proxy-tree-node.cpp
+++ b/models/proxy-tree-node.cpp
@@ -18,9 +18,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "proxy-tree-node.h"
+
#include <TelepathyQt4/Contact>
-#include "proxy-tree-node.h"
#include "tree-node.h"
#include "contact-model-item.h"
#include "accounts-model.h"
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list