Commit 8f174824 authored by Igor Poboiko's avatar Igor Poboiko
Browse files

[Akonadi/PasteHelper] Add support for items linking

Summary:
When linking an item to a virtual collection via KAddressBook, `canPaste` check
fails because it's not aware of the context (i.e. action is `Link`, not `Copy`)
and checks only for `CanCreateItem` (which is not correct if we're linking).

This patch provides `Qt::DropAction action` parameter to `canPaste` method so
it is aware of action, and check for correct permissions based on that

Test Plan:
1) Link an item via KAddressBook using Drag'n'Drop to some virtual collection
(e.g. Google Contacts Resource)
2) The item gets actually linked, instead of silently ignoring

Reviewers: dvratil

Reviewed By: dvratil

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D28432
parent c4cbd336
......@@ -216,7 +216,7 @@ void PasteHelperJob::runCollectionsActions()
}
}
bool PasteHelper::canPaste(const QMimeData *mimeData, const Collection &collection)
bool PasteHelper::canPaste(const QMimeData *mimeData, const Collection &collection, Qt::DropAction action)
{
if (!mimeData || !collection.isValid()) {
return false;
......@@ -230,7 +230,11 @@ bool PasteHelper::canPaste(const QMimeData *mimeData, const Collection &collecti
for (const QUrl &url : urls) {
const QUrlQuery query(url);
if (query.hasQueryItem(QStringLiteral("item"))) {
neededRights |= Collection::CanCreateItem;
if (action == Qt::LinkAction) {
neededRights |= Collection::CanLinkItem;
} else {
neededRights |= Collection::CanCreateItem;
}
} else if (query.hasQueryItem(QStringLiteral("collection"))) {
neededRights |= Collection::CanCreateCollection;
}
......@@ -267,9 +271,9 @@ bool PasteHelper::canPaste(const QMimeData *mimeData, const Collection &collecti
return false;
}
KJob *PasteHelper::paste(const QMimeData *mimeData, const Collection &collection, bool copy, Session *session)
KJob *PasteHelper::paste(const QMimeData *mimeData, const Collection &collection, Qt::DropAction action, Session *session)
{
if (!canPaste(mimeData, collection)) {
if (!canPaste(mimeData, collection, action)) {
return nullptr;
}
......@@ -300,7 +304,7 @@ KJob *PasteHelper::paste(const QMimeData *mimeData, const Collection &collection
}
// data contains an url list
return pasteUriList(mimeData, collection, copy ? Qt::CopyAction : Qt::MoveAction, session);
return pasteUriList(mimeData, collection, action, session);
}
KJob *PasteHelper::pasteUriList(const QMimeData *mimeData, const Collection &destination, Qt::DropAction action, Session *session)
......@@ -309,7 +313,7 @@ KJob *PasteHelper::pasteUriList(const QMimeData *mimeData, const Collection &des
return nullptr;
}
if (!canPaste(mimeData, destination)) {
if (!canPaste(mimeData, destination, action)) {
return nullptr;
}
......
......@@ -45,17 +45,18 @@ namespace PasteHelper
Check whether the given mime data can be pasted into the given collection.
@param mimeData The pasted/dropped data.
@param collection The collection to paste/drop into.
@param action Indicate whether this is a copy, a move or link.
*/
AKONADICORE_EXPORT bool canPaste(const QMimeData *mimeData, const Collection &collection);
AKONADICORE_EXPORT bool canPaste(const QMimeData *mimeData, const Collection &collection, Qt::DropAction action);
/**
Paste/drop the given mime data into the given collection.
@param mimeData The pasted/dropped data.
@param collection The target collection.
@param copy Indicate whether this is a copy or a move.
@param action Indicate whether this is a copy, a move or link.
@returns The job performing the paste, 0 if there is nothing to paste.
*/
AKONADICORE_EXPORT KJob *paste(const QMimeData *mimeData, const Collection &collection, bool copy = true, Session *session = nullptr);
AKONADICORE_EXPORT KJob *paste(const QMimeData *mimeData, const Collection &collection, Qt::DropAction action, Session *session = nullptr);
/**
URI list paste/drop.
......
......@@ -226,7 +226,7 @@ void ActionStateManager::updateState(const Collection::List &collections, const
collectionsAreFolders); // it must be a valid folder collection
#ifndef QT_NO_CLIPBOARD
enableAction(StandardActionManager::Paste, singleCollectionSelected && // we can paste only into a single collection
PasteHelper::canPaste(QApplication::clipboard()->mimeData(), collection)); // there must be data on the clipboard
PasteHelper::canPaste(QApplication::clipboard()->mimeData(), collection, Qt::CopyAction)); // there must be data on the clipboard
#else
enableAction(StandardActionManager::Paste, false); // no support for clipboard -> no paste
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment