From: Peter Penz Date: Tue, 20 Dec 2011 07:56:32 +0000 (+0100) Subject: Show an error when dragging above a folder without write access X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/090393599c80d29439a7e5f63e7bba471f52639d Show an error when dragging above a folder without write access Got OK from the translator team to add this new string. --- diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 275cd7772..bb2198d48 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -259,7 +259,15 @@ void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos) void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event) { if (index >= 0) { - const KFileItem destItem = fileItemModel()->fileItem(index); + KFileItemModel* model = fileItemModel(); + KFileItem destItem = model->fileItem(index); + if (destItem.isNull()) { + destItem = model->rootItem(); + if (destItem.isNull()) { + kWarning() << "No destination item available for drop operation."; + return; + } + } QDropEvent dropEvent(event->pos().toPoint(), event->possibleActions(), @@ -267,7 +275,7 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve event->buttons(), event->modifiers()); - DragAndDropHelper::dropUrls(destItem, url(), &dropEvent); + DragAndDropHelper::dropUrls(destItem, &dropEvent); } } diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index 902c436cf..6f522fad2 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -48,7 +48,8 @@ void PlacesPanel::mousePressEvent(QMouseEvent* event) void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) { Q_UNUSED(parent); - DragAndDropHelper::dropUrls(KFileItem(), dest, event); + const KFileItem destItem(KFileItem::Unknown, KFileItem::Unknown, dest); + DragAndDropHelper::dropUrls(destItem, event); } void PlacesPanel::emitExtendedUrlChangedSignal(const KUrl& url) diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 0edcb2894..f17749b83 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -815,7 +815,14 @@ void DolphinView::slotItemUnhovered(int index) void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event) { - const KFileItem destItem = fileItemModel()->fileItem(index); + KFileItem destItem = fileItemModel()->fileItem(index); + if (destItem.isNull()) { + destItem = fileItemModel()->rootItem(); + if (destItem.isNull()) { + kWarning() << "No destination item available for drop operation."; + return; + } + } QDropEvent dropEvent(event->pos().toPoint(), event->possibleActions(), @@ -823,7 +830,7 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even event->buttons(), event->modifiers()); - const QString error = DragAndDropHelper::dropUrls(destItem, url(), &dropEvent); + const QString error = DragAndDropHelper::dropUrls(destItem, &dropEvent); if (!error.isEmpty()) { emit errorMessage(error); } diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index ea92787ab..91eb4267d 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -28,12 +28,14 @@ #include #include -QString DragAndDropHelper::dropUrls(const KFileItem& destItem, - const KUrl& destPath, - QDropEvent* event) +QString DragAndDropHelper::dropUrls(const KFileItem& destItem, QDropEvent* event) { - const bool dropToItem = !destItem.isNull() && (destItem.isDir() || destItem.isDesktopFile()); - const KUrl destination = dropToItem ? destItem.url() : destPath; + Q_ASSERT(!destItem.isNull()); + + const KUrl destination = destItem.url(); + if (!destItem.isWritable()) { + return i18nc("@info:status", "Access denied. Could not write to %1", destination.pathOrUrl()); + } const QMimeData* mimeData = event->mimeData(); if (mimeData->hasFormat("application/x-kde-dndextract")) { @@ -50,11 +52,7 @@ QString DragAndDropHelper::dropUrls(const KFileItem& destItem, } } - if (dropToItem) { - KonqOperations::doDrop(destItem, destination, event, QApplication::activeWindow()); - } else { - KonqOperations::doDrop(KFileItem(), destination, event, QApplication::activeWindow()); - } + KonqOperations::doDrop(destItem, destination, event, QApplication::activeWindow()); } return QString(); diff --git a/src/views/draganddrophelper.h b/src/views/draganddrophelper.h index d00e11157..1998a85a0 100644 --- a/src/views/draganddrophelper.h +++ b/src/views/draganddrophelper.h @@ -38,15 +38,12 @@ public: * destination. A context menu with the options * 'Move Here', 'Copy Here', 'Link Here' and * 'Cancel' is offered to the user. - * @param destItem Item of the destination (can be null, see KFileItem::isNull()). - * @param destPath Path of the destination. + * @param destItem Item of the destination. * @param event Drop event. * @return Error message if dropping is not possible. If an empty string * is returned, the dropping has been successful. */ - static QString dropUrls(const KFileItem& destItem, - const KUrl& destPath, - QDropEvent* event); + static QString dropUrls(const KFileItem& destItem, QDropEvent* event); }; #endif