X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/2f045c60109e0a5811f68bcce617236e3478e402..8d7e600f63a1961294dfe2c278a710b4ce0716e9:/src/panels/folders/treeviewcontextmenu.cpp diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index b15badde1..df96b9f25 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -1,43 +1,34 @@ -/*************************************************************************** - * Copyright (C) 2006-2010 by Peter Penz * - * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2006-2010 Peter Penz + * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "treeviewcontextmenu.h" -#include -#include -#include -#include -#include -#include +#include "folderspanel.h" +#include "global.h" + #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include - -#include "folderspanel.h" +#include +#include #include #include +#include #include +#include TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo) : @@ -51,26 +42,27 @@ TreeViewContextMenu::~TreeViewContextMenu() { } -void TreeViewContextMenu::open() +void TreeViewContextMenu::open(const QPoint& pos) { - KMenu* popup = new KMenu(m_parent); + QMenu* popup = new QMenu(m_parent); if (!m_fileItem.isNull()) { KFileItemListProperties capabilities(KFileItemList() << m_fileItem); // insert 'Cut', 'Copy' and 'Paste' - QAction* cutAction = new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this); + QAction* cutAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-cut")), i18nc("@action:inmenu", "Cut"), this); cutAction->setEnabled(capabilities.supportsMoving()); - connect(cutAction, SIGNAL(triggered()), this, SLOT(cut())); + connect(cutAction, &QAction::triggered, this, &TreeViewContextMenu::cut); - QAction* copyAction = new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this); - connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())); + QAction* copyAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18nc("@action:inmenu", "Copy"), this); + connect(copyAction, &QAction::triggered, this, &TreeViewContextMenu::copy); - QAction* pasteAction = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this); - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); - const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData); - connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste())); - pasteAction->setEnabled(!pasteData.isEmpty() && capabilities.supportsWriting()); + const QMimeData *mimeData = QApplication::clipboard()->mimeData(); + bool canPaste; + const QString text = KIO::pasteActionText(mimeData, &canPaste, m_fileItem); + QAction* pasteAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), text, this); + connect(pasteAction, &QAction::triggered, this, &TreeViewContextMenu::paste); + pasteAction->setEnabled(canPaste); popup->addAction(cutAction); popup->addAction(copyAction); @@ -80,31 +72,31 @@ void TreeViewContextMenu::open() // insert 'Rename' QAction* renameAction = new QAction(i18nc("@action:inmenu", "Rename..."), this); renameAction->setEnabled(capabilities.supportsMoving()); - renameAction->setIcon(KIcon("edit-rename")); - connect(renameAction, SIGNAL(triggered()), this, SLOT(rename())); + renameAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); + connect(renameAction, &QAction::triggered, this, &TreeViewContextMenu::rename); popup->addAction(renameAction); // insert 'Move to Trash' and (optionally) 'Delete' - KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals); + KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::IncludeGlobals); KConfigGroup configGroup(globalConfig, "KDE"); bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false); - const KUrl url = m_fileItem.url(); + const QUrl url = m_fileItem.url(); if (url.isLocalFile()) { - QAction* moveToTrashAction = new QAction(KIcon("user-trash"), + QAction* moveToTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:inmenu", "Move to Trash"), this); const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); moveToTrashAction->setEnabled(enableMoveToTrash); - connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash())); + connect(moveToTrashAction, &QAction::triggered, this, &TreeViewContextMenu::moveToTrash); popup->addAction(moveToTrashAction); } else { showDeleteCommand = true; } if (showDeleteCommand) { - QAction* deleteAction = new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this); + QAction* deleteAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@action:inmenu", "Delete"), this); deleteAction->setEnabled(capabilities.supportsDeleting()); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); + connect(deleteAction, &QAction::triggered, this, &TreeViewContextMenu::deleteItem); popup->addAction(deleteAction); } @@ -116,7 +108,19 @@ void TreeViewContextMenu::open() showHiddenFilesAction->setCheckable(true); showHiddenFilesAction->setChecked(m_parent->showHiddenFiles()); popup->addAction(showHiddenFilesAction); - connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool))); + connect(showHiddenFilesAction, &QAction::toggled, this, &TreeViewContextMenu::setShowHiddenFiles); + + if (!m_fileItem.isNull()) { + // insert 'Limit to Home Directory' + const QUrl url = m_fileItem.url(); + const bool enableLimitToHomeDirectory = url.isLocalFile(); + QAction* limitFoldersPanelToHomeAction = new QAction(i18nc("@action:inmenu", "Limit to Home Directory"), this); + limitFoldersPanelToHomeAction->setCheckable(true); + limitFoldersPanelToHomeAction->setEnabled(enableLimitToHomeDirectory); + limitFoldersPanelToHomeAction->setChecked(m_parent->limitFoldersPanelToHome()); + popup->addAction(limitFoldersPanelToHomeAction); + connect(limitFoldersPanelToHomeAction, &QAction::toggled, this, &TreeViewContextMenu::setLimitFoldersPanelToHome); + } // insert 'Automatic Scrolling' QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this); @@ -125,26 +129,26 @@ void TreeViewContextMenu::open() // TODO: Temporary disabled. Horizontal autoscrolling will be implemented later either // in KItemViews or manually as part of the FoldersPanel //popup->addAction(autoScrollingAction); - connect(autoScrollingAction, SIGNAL(toggled(bool)), this, SLOT(setAutoScrolling(bool))); + connect(autoScrollingAction, &QAction::toggled, this, &TreeViewContextMenu::setAutoScrolling); if (!m_fileItem.isNull()) { // insert 'Properties' entry QAction* propertiesAction = new QAction(i18nc("@action:inmenu", "Properties"), this); - propertiesAction->setIcon(KIcon("document-properties")); - connect(propertiesAction, SIGNAL(triggered()), this, SLOT(showProperties())); + propertiesAction->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); + connect(propertiesAction, &QAction::triggered, this, &TreeViewContextMenu::showProperties); popup->addAction(propertiesAction); } - QList customActions = m_parent->customContextMenuActions(); + const QList customActions = m_parent->customContextMenuActions(); if (!customActions.isEmpty()) { popup->addSeparator(); - foreach (QAction* action, customActions) { + for (QAction* action : customActions) { popup->addAction(action); } } - QWeakPointer popupPtr = popup; - popup->exec(QCursor::pos()); + QPointer popupPtr = popup; + popup->exec(pos); if (popupPtr.data()) { popupPtr.data()->deleteLater(); } @@ -152,12 +156,14 @@ void TreeViewContextMenu::open() void TreeViewContextMenu::populateMimeData(QMimeData* mimeData, bool cut) { - KUrl::List kdeUrls; + QList kdeUrls; kdeUrls.append(m_fileItem.url()); - KUrl::List mostLocalUrls; + QList mostLocalUrls; bool dummy; - mostLocalUrls.append(m_fileItem.mostLocalUrl(dummy)); - KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, cut); + mostLocalUrls.append(m_fileItem.mostLocalUrl(&dummy)); + KIO::setClipboardDataCut(mimeData, cut); + KUrlMimeData::exportUrlsToPortal(mimeData); + KUrlMimeData::setUrls(kdeUrls, mostLocalUrls, mimeData); } void TreeViewContextMenu::cut() @@ -176,17 +182,8 @@ void TreeViewContextMenu::copy() void TreeViewContextMenu::paste() { - QClipboard* clipboard = QApplication::clipboard(); - const QMimeData* mimeData = clipboard->mimeData(); - - const KUrl::List source = KUrl::List::fromMimeData(mimeData); - const KUrl& dest = m_fileItem.url(); - if (KonqMimeData::decodeIsCutSelection(mimeData)) { - KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest); - clipboard->clear(); - } else { - KonqOperations::copy(m_parent, KonqOperations::COPY, source, dest); - } + KIO::PasteJob *job = KIO::paste(QApplication::clipboard()->mimeData(), m_fileItem.url()); + KJobWidgets::setWindow(job, m_parent); } void TreeViewContextMenu::rename() @@ -196,12 +193,27 @@ void TreeViewContextMenu::rename() void TreeViewContextMenu::moveToTrash() { - KonqOperations::del(m_parent, KonqOperations::TRASH, KUrl::List() << m_fileItem.url()); + const QList list{m_fileItem.url()}; + KIO::JobUiDelegate uiDelegate; + uiDelegate.setWindow(m_parent); + if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { + KIO::Job* job = KIO::trash(list); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl(QStringLiteral("trash:/")), job); + KJobWidgets::setWindow(job, m_parent); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); + } } void TreeViewContextMenu::deleteItem() { - KonqOperations::del(m_parent, KonqOperations::DEL, KUrl::List() << m_fileItem.url()); + const QList list{m_fileItem.url()}; + KIO::JobUiDelegate uiDelegate; + uiDelegate.setWindow(m_parent); + if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { + KIO::Job* job = KIO::del(list); + KJobWidgets::setWindow(job, m_parent); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); + } } void TreeViewContextMenu::showProperties() @@ -216,9 +228,13 @@ void TreeViewContextMenu::setShowHiddenFiles(bool show) m_parent->setShowHiddenFiles(show); } +void TreeViewContextMenu::setLimitFoldersPanelToHome(bool enable) +{ + m_parent->setLimitFoldersPanelToHome(enable); +} + void TreeViewContextMenu::setAutoScrolling(bool enable) { m_parent->setAutoScrolling(enable); } -#include "treeviewcontextmenu.moc"