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


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

The following commit has been merged in the master branch:
commit dbb6f4cf87fffb221ac906151d412d946179d932
Author: Dan Vrátil <dvratil at redhat.com>
Date:   Wed Jan 16 01:58:40 2013 +0100

    Copy or move contacts between groups by dragging
    
    When user holds Shift on drag start, no popup menu appears and
    contact is moved from source to target group.
    When user holds Ctrl on drag start, no popup menu appears and
    contact is copied to target group.
    When user holds no modifier on drag start, a popup menu appears
    when contact is dropped, allowing user to choose whether to
    move or copy contact to target group.
    
    REVIEW: 108432
---
 contact-list-widget.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++-------
 contact-list-widget_p.h |  1 +
 2 files changed, 67 insertions(+), 11 deletions(-)

diff --git a/contact-list-widget.cpp b/contact-list-widget.cpp
index d60f1bb..032de48 100644
--- a/contact-list-widget.cpp
+++ b/contact-list-widget.cpp
@@ -45,6 +45,7 @@
 #include <KDialog>
 #include <KFileDialog>
 #include <KSettings/Dialog>
+#include <KMenu>
 
 #include <QHeaderView>
 #include <QLabel>
@@ -55,6 +56,7 @@
 #include <QDragLeaveEvent>
 #include <QPainter>
 #include <QPixmap>
+#include <QMenu>
 
 #include "contact-delegate.h"
 #include "contact-delegate-compact.h"
@@ -538,6 +540,7 @@ void ContactListWidget::mousePressEvent(QMouseEvent *event)
 
     QModelIndex index = indexAt(event->pos());
     d->shouldDrag = false;
+    d->dragSourceGroup.clear();
 
     // no drag when grouping by accounts
     if (d->modelFilter->groupMode() == ContactsModel2::AccountGrouping) {
@@ -585,6 +588,9 @@ void ContactListWidget::mouseMoveEvent(QMouseEvent *event)
 
         //We put a contact ID and its account ID to the stream, so we can later recreate the contact using ContactsModel
         stream << contact->id() << account->objectPath();
+
+        //Store source group name so that we can remove the contact from it on move-drop */
+        d->dragSourceGroup = index.parent().data(GroupsModel::GroupNameRole).toString();
     }
 
     mimeData->setData("application/vnd.telepathy.contact", encodedData);
@@ -594,7 +600,15 @@ void ContactListWidget::mouseMoveEvent(QMouseEvent *event)
     drag->setMimeData(mimeData);
     drag->setPixmap(dragIndicator);
 
-    drag->exec(Qt::CopyAction);
+    Qt::DropActions actions;
+    if (event->modifiers() & Qt::ShiftModifier) {
+        actions = Qt::MoveAction;
+    } else if (event->modifiers() & Qt::ControlModifier) {
+        actions = Qt::CopyAction;
+    } else {
+        actions = Qt::MoveAction | Qt::CopyAction;
+    }
+    drag->exec(actions);
 }
 
 void ContactListWidget::dropEvent(QDropEvent *event)
@@ -651,29 +665,70 @@ void ContactListWidget::dropEvent(QDropEvent *event)
             }
         }
 
-        Q_FOREACH (const Tp::ContactPtr &contact, contacts) {
-            Q_ASSERT(contact);
-            QString group;
+        Qt::DropAction action = Qt::IgnoreAction;
+        if ((event->possibleActions() & Qt::CopyAction) &&
+            (event->possibleActions() & Qt::MoveAction)) {
+
+            KMenu menu;
+            QString seq = QKeySequence(Qt::ShiftModifier).toString();
+            seq.chop(1);
+            QAction *move = menu.addAction(KIcon("go-jump"), i18n("&Move here") + QLatin1Char('	') + seq);
+
+            seq = QKeySequence(Qt::ControlModifier).toString();
+            seq.chop(1);
+            QAction *copy = menu.addAction(KIcon("edit-copy"), i18n("&Copy here") + QLatin1Char('	') + seq);
+
+            menu.addSeparator();
+            seq = QKeySequence(Qt::Key_Escape).toString();
+            menu.addAction(KIcon("process-stop"), i18n("C&ancel") + QLatin1Char('	') + seq);
+
+            QAction *result = menu.exec(mapToGlobal(event->pos()));
+
+            if (result == move) {
+                action = Qt::MoveAction;
+            } else if (result == copy) {
+                action = Qt::CopyAction;
+            }
+        } else if (event->possibleActions() & Qt::MoveAction) {
+            action = Qt::MoveAction;
+        } else if (event->possibleActions() & Qt::CopyAction) {
+            action = Qt::CopyAction;
+        }
+
+        Q_FOREACH(const Tp::ContactPtr &contact, contacts) {
+            QString targetGroup;
+
+            if (action == Qt::IgnoreAction) {
+                continue;
+            }
+
             if (index.data(ContactsModel::TypeRole).toInt() == ContactsModel::GroupRowType) {
                 // contact is dropped on a group, so take it's name
-                group = index.data(GroupsModel::GroupNameRole).toString();
+                targetGroup = index.data(GroupsModel::GroupNameRole).toString();
             } else if (index.data(ContactsModel::TypeRole).toInt() == ContactsModel::ContactRowType) {
                 // contact is dropped on another contact, so take it's parents (group) name
-                group = index.parent().data(GroupsModel::GroupNameRole).toString();
+                targetGroup = index.parent().data(GroupsModel::GroupNameRole).toString();
             }
 
-            if (group.isEmpty() || (group == QLatin1String("_unsorted")) ||
-                contact->groups().contains(group)) {
+            if (targetGroup.isEmpty() || (targetGroup == QLatin1String("_unsorted")) ||
+                contact->groups().contains(targetGroup)) {
                 continue;
             }
 
-            kDebug() << contact->alias() << "added to group" << group;
+            kDebug() << contact->alias() << "added to group" << targetGroup;
 
-            Tp::PendingOperation *op = contact->addToGroup(group);
+            if (action == Qt::MoveAction) {
+                Tp::PendingOperation *rmOp = contact->removeFromGroup(d->dragSourceGroup);
+                connect(rmOp, SIGNAL(finished(Tp::PendingOperation*)),
+                        this, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
+            }
 
-            connect(op, SIGNAL(finished(Tp::PendingOperation*)),
+            Tp::PendingOperation *addOp = contact->addToGroup(targetGroup);
+            connect(addOp, SIGNAL(finished(Tp::PendingOperation*)),
                     this, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
         }
+        d->dragSourceGroup.clear();
+
         event->acceptProposedAction();
 
     } else {
diff --git a/contact-list-widget_p.h b/contact-list-widget_p.h
index 68e0302..ecb70ec 100644
--- a/contact-list-widget_p.h
+++ b/contact-list-widget_p.h
@@ -45,6 +45,7 @@ public:
     ContactDelegateCompact *compactDelegate;
     QRect                   dropIndicatorRect;
     QPoint                  dragStartPosition;
+    QString                 dragSourceGroup;
     bool                    shouldDrag;
     bool                    showOffline;
     QHash<QString, bool>    groupStates;

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list