X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/848abc5922167a467bb73107ee6b72e9af3c8317..579eadeb6ddffb03e8043090a330c6dba0717299:/src/panels/folders/treeviewcontextmenu.cpp diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index 99802ed18..893a494fb 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -1,47 +1,40 @@ -/*************************************************************************** - * 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 "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 +#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) +#include +#else +#include +#include +#endif #include #include +#include #include #include -#include "global.h" TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo) : @@ -55,7 +48,7 @@ TreeViewContextMenu::~TreeViewContextMenu() { } -void TreeViewContextMenu::open() +void TreeViewContextMenu::open(const QPoint& pos) { QMenu* popup = new QMenu(m_parent); @@ -123,15 +116,17 @@ void TreeViewContextMenu::open() popup->addAction(showHiddenFilesAction); connect(showHiddenFilesAction, &QAction::toggled, this, &TreeViewContextMenu::setShowHiddenFiles); - // 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); + 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); @@ -150,16 +145,16 @@ void TreeViewContextMenu::open() 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(); } @@ -171,8 +166,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); } @@ -203,6 +199,11 @@ void TreeViewContextMenu::rename() void TreeViewContextMenu::moveToTrash() { +#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) + using Iface = KIO::AskUserActionInterface; + auto *deleteJob = new KIO::DeleteOrTrashJob(QList{m_fileItem.url()}, Iface::Trash, Iface::DefaultConfirmation, m_parent); + deleteJob->start(); +#else const QList list{m_fileItem.url()}; KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(m_parent); @@ -212,10 +213,16 @@ void TreeViewContextMenu::moveToTrash() KJobWidgets::setWindow(job, m_parent); job->uiDelegate()->setAutoErrorHandlingEnabled(true); } +#endif } void TreeViewContextMenu::deleteItem() { +#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) + using Iface = KIO::AskUserActionInterface; + auto *deleteJob = new KIO::DeleteOrTrashJob(QList{m_fileItem.url()}, Iface::Delete, Iface::DefaultConfirmation, m_parent); + deleteJob->start(); +#else const QList list{m_fileItem.url()}; KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(m_parent); @@ -224,6 +231,7 @@ void TreeViewContextMenu::deleteItem() KJobWidgets::setWindow(job, m_parent); job->uiDelegate()->setAutoErrorHandlingEnabled(true); } +#endif } void TreeViewContextMenu::showProperties()