X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/832e157ecd1a1640b82425358b20fff416a2f8b7..8d7e600f63a1961294dfe2c278a710b4ce0716e9:/src/panels/folders/treeviewcontextmenu.cpp diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index e45fcd67e..df96b9f25 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -1,46 +1,32 @@ -/*************************************************************************** - * 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 "folderspanel.h" +#include "global.h" + +#include +#include #include #include +#include #include -#include -#include +#include +#include #include -#include -#include -#include -#include #include -#include -#include -#include #include - -#include "folderspanel.h" +#include +#include #include #include +#include #include #include @@ -56,7 +42,7 @@ TreeViewContextMenu::~TreeViewContextMenu() { } -void TreeViewContextMenu::open() +void TreeViewContextMenu::open(const QPoint& pos) { QMenu* popup = new QMenu(m_parent); @@ -64,17 +50,17 @@ void TreeViewContextMenu::open() KFileItemListProperties capabilities(KFileItemList() << m_fileItem); // insert 'Cut', 'Copy' and 'Paste' - QAction* cutAction = new QAction(QIcon::fromTheme("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, &QAction::triggered, this, &TreeViewContextMenu::cut); - QAction* copyAction = new QAction(QIcon::fromTheme("edit-copy"), i18nc("@action:inmenu", "Copy"), this); + QAction* copyAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18nc("@action:inmenu", "Copy"), this); connect(copyAction, &QAction::triggered, this, &TreeViewContextMenu::copy); const QMimeData *mimeData = QApplication::clipboard()->mimeData(); bool canPaste; const QString text = KIO::pasteActionText(mimeData, &canPaste, m_fileItem); - QAction* pasteAction = new QAction(QIcon::fromTheme("edit-paste"), text, this); + QAction* pasteAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), text, this); connect(pasteAction, &QAction::triggered, this, &TreeViewContextMenu::paste); pasteAction->setEnabled(canPaste); @@ -86,18 +72,18 @@ void TreeViewContextMenu::open() // insert 'Rename' QAction* renameAction = new QAction(i18nc("@action:inmenu", "Rename..."), this); renameAction->setEnabled(capabilities.supportsMoving()); - renameAction->setIcon(QIcon::fromTheme("edit-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 QUrl url = m_fileItem.url(); if (url.isLocalFile()) { - QAction* moveToTrashAction = new QAction(QIcon::fromTheme("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); @@ -108,7 +94,7 @@ void TreeViewContextMenu::open() } if (showDeleteCommand) { - QAction* deleteAction = new QAction(QIcon::fromTheme("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, &QAction::triggered, this, &TreeViewContextMenu::deleteItem); popup->addAction(deleteAction); @@ -124,6 +110,18 @@ void TreeViewContextMenu::open() popup->addAction(showHiddenFilesAction); 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); autoScrollingAction->setCheckable(true); @@ -136,21 +134,21 @@ void TreeViewContextMenu::open() if (!m_fileItem.isNull()) { // insert 'Properties' entry QAction* propertiesAction = new QAction(i18nc("@action:inmenu", "Properties"), this); - propertiesAction->setIcon(QIcon::fromTheme("document-properties")); + 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); } } QPointer popupPtr = popup; - popup->exec(QCursor::pos()); + popup->exec(pos); if (popupPtr.data()) { popupPtr.data()->deleteLater(); } @@ -162,8 +160,9 @@ void TreeViewContextMenu::populateMimeData(QMimeData* mimeData, bool cut) kdeUrls.append(m_fileItem.url()); QList mostLocalUrls; bool dummy; - mostLocalUrls.append(m_fileItem.mostLocalUrl(dummy)); + mostLocalUrls.append(m_fileItem.mostLocalUrl(&dummy)); KIO::setClipboardDataCut(mimeData, cut); + KUrlMimeData::exportUrlsToPortal(mimeData); KUrlMimeData::setUrls(kdeUrls, mostLocalUrls, mimeData); } @@ -199,9 +198,9 @@ void TreeViewContextMenu::moveToTrash() 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("trash:/"), job); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl(QStringLiteral("trash:/")), job); KJobWidgets::setWindow(job, m_parent); - job->ui()->setAutoErrorHandlingEnabled(true); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); } } @@ -213,7 +212,7 @@ void TreeViewContextMenu::deleteItem() if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { KIO::Job* job = KIO::del(list); KJobWidgets::setWindow(job, m_parent); - job->ui()->setAutoErrorHandlingEnabled(true); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); } } @@ -229,6 +228,11 @@ 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);