X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e8c3df5f60aae3c34545c4112b9ec1c323ee66fd..7bd5bec21977c733dd3e1fc70f5afd66dda3ab97:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index f66847334..fccd6059f 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -27,34 +27,30 @@ #include "dolphinremoveaction.h" #include -#include -#include -#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include +#include #include -#include #include +#include +#include +#include +#include +#include + #include #include -#include -#include -#include #include "views/dolphinview.h" #include "views/viewmodecontroller.h" @@ -62,8 +58,8 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const QPoint& pos, const KFileItem& fileInfo, - const KUrl& baseUrl) : - KMenu(parent), + const QUrl& baseUrl) : + QMenu(parent), m_pos(pos), m_mainWindow(parent), m_fileInfo(fileInfo), @@ -74,14 +70,13 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_context(NoContext), m_copyToMenu(parent), m_customActions(), - m_command(None) + m_command(None), + m_removeAction(0) { // The context menu either accesses the URLs of the selected items // or the items itself. To increase the performance both lists are cached. const DolphinView* view = m_mainWindow->activeViewContainer()->view(); m_selectedItems = view->selectedItems(); - - m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection()); } DolphinContextMenu::~DolphinContextMenu() @@ -98,7 +93,7 @@ void DolphinContextMenu::setCustomActions(const QList& actions) DolphinContextMenu::Command DolphinContextMenu::open() { // get the context information - if (m_baseUrl.protocol() == QLatin1String("trash")) { + if (m_baseUrl.scheme() == QLatin1String("trash")) { m_context |= TrashContext; } @@ -126,25 +121,25 @@ DolphinContextMenu::Command DolphinContextMenu::open() void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) { - if (ev->key() == Qt::Key_Shift) { + if (m_removeAction && ev->key() == Qt::Key_Shift) { m_removeAction->update(); } - KMenu::keyPressEvent(ev); + QMenu::keyPressEvent(ev); } void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) { - if (ev->key() == Qt::Key_Shift) { + if (m_removeAction && ev->key() == Qt::Key_Shift) { m_removeAction->update(); } - KMenu::keyReleaseEvent(ev); + QMenu::keyReleaseEvent(ev); } void DolphinContextMenu::openTrashContextMenu() { Q_ASSERT(m_context & TrashContext); - QAction* emptyTrashAction = new QAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), this); + QAction* emptyTrashAction = new QAction(QIcon::fromTheme("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), this); KConfig trashConfig("trashrc", KConfig::SimpleConfig); emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); addAction(emptyTrashAction); @@ -157,7 +152,13 @@ void DolphinContextMenu::openTrashContextMenu() addShowMenuBarAction(); if (exec(m_pos) == emptyTrashAction) { - KonqOperations::emptyTrash(m_mainWindow); + KIO::JobUiDelegate uiDelegate; + uiDelegate.setWindow(m_mainWindow); + if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { + KIO::Job* job = KIO::emptyTrash(); + KJobWidgets::setWindow(job, m_mainWindow); + job->ui()->setAutoErrorHandlingEnabled(true); + } } } @@ -176,12 +177,14 @@ void DolphinContextMenu::openTrashItemContextMenu() addAction(propertiesAction); if (exec(m_pos) == restoreAction) { - KUrl::List selectedUrls; + QList selectedUrls; foreach (const KFileItem &item, m_selectedItems) { selectedUrls.append(item.url()); } - KonqOperations::restoreTrashedItems(selectedUrls, m_mainWindow); + KIO::RestoreJob *job = KIO::restoreFromTrash(selectedUrls); + KJobWidgets::setWindow(job, m_mainWindow); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); } } @@ -189,24 +192,27 @@ void DolphinContextMenu::openItemContextMenu() { Q_ASSERT(!m_fileInfo.isNull()); + QAction* openParentAction = 0; QAction* openParentInNewWindowAction = 0; QAction* openParentInNewTabAction = 0; QAction* addToPlacesAction = 0; + const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); + if (m_selectedItems.count() == 1) { if (m_fileInfo.isDir()) { // setup 'Create New' menu - DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow); + DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); const DolphinView* view = m_mainWindow->activeViewContainer()->view(); newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); newFileMenu->checkUpToDate(); newFileMenu->setPopupFiles(m_fileInfo.url()); - newFileMenu->setEnabled(selectedItemsProperties().supportsWriting()); - connect(newFileMenu, SIGNAL(fileCreated(KUrl)), newFileMenu, SLOT(deleteLater())); - connect(newFileMenu, SIGNAL(directoryCreated(KUrl)), newFileMenu, SLOT(deleteLater())); + newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); + connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); + connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); - KMenu* menu = newFileMenu->menu(); + QMenu* menu = newFileMenu->menu(); menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); - menu->setIcon(KIcon("document-new")); + menu->setIcon(QIcon::fromTheme("document-new")); addMenu(menu); addSeparator(); @@ -216,20 +222,26 @@ void DolphinContextMenu::openItemContextMenu() // insert 'Add to Places' entry if (!placeExists(m_fileInfo.url())) { - addToPlacesAction = addAction(KIcon("bookmark-new"), + addToPlacesAction = addAction(QIcon::fromTheme("bookmark-new"), i18nc("@action:inmenu Add selected folder to places", "Add to Places")); } addSeparator(); - } else if (m_baseUrl.protocol().contains("search")) { - openParentInNewWindowAction = new QAction(KIcon("window-new"), + } else if (m_baseUrl.scheme().contains("search") || m_baseUrl.scheme().contains("timeline")) { + openParentAction = new QAction(QIcon::fromTheme("document-open-folder"), + i18nc("@action:inmenu", + "Open Path"), + this); + addAction(openParentAction); + + openParentInNewWindowAction = new QAction(QIcon::fromTheme("window-new"), i18nc("@action:inmenu", "Open Path in New Window"), this); addAction(openParentInNewWindowAction); - openParentInNewTabAction = new QAction(KIcon("tab-new"), + openParentInNewTabAction = new QAction(QIcon::fromTheme("tab-new"), i18nc("@action:inmenu", "Open Path in New Tab"), this); @@ -246,7 +258,7 @@ void DolphinContextMenu::openItemContextMenu() } else { bool selectionHasOnlyDirs = true; foreach (const KFileItem& item, m_selectedItems) { - const KUrl& url = DolphinView::openItemAsFolderUrl(item); + const QUrl& url = DolphinView::openItemAsFolderUrl(item); if (url.isEmpty()) { selectionHasOnlyDirs = false; break; @@ -260,12 +272,12 @@ void DolphinContextMenu::openItemContextMenu() } } - insertDefaultItemActions(); + insertDefaultItemActions(selectedItemsProps); addSeparator(); KFileItemActions fileItemActions; - fileItemActions.setItemListProperties(selectedItemsProperties()); + fileItemActions.setItemListProperties(selectedItemsProps); addServiceActions(fileItemActions); addFileItemPluginActions(); @@ -275,7 +287,7 @@ void DolphinContextMenu::openItemContextMenu() // insert 'Copy To' and 'Move To' sub menus if (GeneralSettings::showCopyMoveMenu()) { m_copyToMenu.setItems(m_selectedItems); - m_copyToMenu.setReadOnly(!selectedItemsProperties().supportsWriting()); + m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting()); m_copyToMenu.addActionsTo(this); } @@ -286,13 +298,15 @@ void DolphinContextMenu::openItemContextMenu() QAction* activatedAction = exec(m_pos); if (activatedAction) { if (activatedAction == addToPlacesAction) { - const KUrl selectedUrl(m_fileInfo.url()); + const QUrl selectedUrl(m_fileInfo.url()); if (selectedUrl.isValid()) { PlacesItemModel model; const QString text = selectedUrl.fileName(); PlacesItem* item = model.createPlacesItem(text, selectedUrl); model.appendItemToGroup(item); } + } else if (activatedAction == openParentAction) { + m_command = OpenParentFolder; } else if (activatedAction == openParentInNewWindowAction) { m_command = OpenParentFolderInNewWindow; } else if (activatedAction == openParentInNewTabAction) { @@ -320,7 +334,7 @@ void DolphinContextMenu::openViewportContextMenu() // Insert 'Add to Places' entry if exactly one item is selected QAction* addToPlacesAction = 0; if (!placeExists(m_mainWindow->activeViewContainer()->url())) { - addToPlacesAction = addAction(KIcon("bookmark-new"), + addToPlacesAction = addAction(QIcon::fromTheme("bookmark-new"), i18nc("@action:inmenu Add current folder to places", "Add to Places")); } @@ -359,7 +373,7 @@ void DolphinContextMenu::openViewportContextMenu() } } -void DolphinContextMenu::insertDefaultItemActions() +void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties) { const KActionCollection* collection = m_mainWindow->actionCollection(); @@ -375,12 +389,26 @@ void DolphinContextMenu::insertDefaultItemActions() addAction(renameAction); // Insert 'Move to Trash' and/or 'Delete' - if (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false)) { - addAction(collection->action("move_to_trash")); - addAction(collection->action("delete")); - } else { - addAction(m_removeAction); - m_removeAction->update(); + if (properties.supportsDeleting()) { + const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) || + !properties.isLocal()); + const bool showMoveToTrashAction = (properties.isLocal() && + properties.supportsMoving()); + + if (showDeleteAction && showMoveToTrashAction) { + delete m_removeAction; + m_removeAction = 0; + addAction(m_mainWindow->actionCollection()->action("move_to_trash")); + addAction(m_mainWindow->actionCollection()->action("delete")); + } else if (showDeleteAction && !showMoveToTrashAction) { + addAction(m_mainWindow->actionCollection()->action("delete")); + } else { + if (!m_removeAction) { + m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection()); + } + addAction(m_removeAction); + m_removeAction->update(); + } } } @@ -394,14 +422,14 @@ void DolphinContextMenu::addShowMenuBarAction() } } -bool DolphinContextMenu::placeExists(const KUrl& url) const +bool DolphinContextMenu::placeExists(const QUrl& url) const { PlacesItemModel model; const int count = model.count(); for (int i = 0; i < count; ++i) { - const KUrl placeUrl = model.placesItem(i)->url(); - if (placeUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) { + const QUrl placeUrl = model.placesItem(i)->url(); + if (placeUrl.matches(url, QUrl::StripTrailingSlash)) { return true; } } @@ -414,11 +442,12 @@ QAction* DolphinContextMenu::createPasteAction() QAction* action = 0; const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir(); if (isDir && (m_selectedItems.count() == 1)) { - action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this); - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); - const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData); - action->setEnabled(!pasteData.isEmpty() && selectedItemsProperties().supportsWriting()); - connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(pasteIntoFolder())); + const QMimeData *mimeData = QApplication::clipboard()->mimeData(); + bool canPaste; + const QString text = KIO::pasteActionText(mimeData, &canPaste, m_fileInfo); + action = new QAction(QIcon::fromTheme("edit-paste"), text, this); + action->setEnabled(canPaste); + connect(action, &QAction::triggered, m_mainWindow, &DolphinMainWindow::pasteIntoFolder); } else { action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); } @@ -437,7 +466,7 @@ KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() const KFileItem DolphinContextMenu::baseFileItem() { if (!m_baseFileItem) { - m_baseFileItem = new KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_baseUrl); + m_baseFileItem = new KFileItem(m_baseUrl); } return *m_baseFileItem; } @@ -475,26 +504,14 @@ void DolphinContextMenu::addFileItemPluginActions() const KConfig config("kservicemenurc", KConfig::NoGlobals); const KConfigGroup showGroup = config.group("Show"); - foreach (const KSharedPtr& service, pluginServices) { - // Old API (kdelibs-4.6.0 only) - KFileItemActionPlugin* plugin = service->createInstance(); - if (plugin) { - if (!showGroup.readEntry(service->desktopEntryName(), true)) { - // The plugin has been disabled - continue; - } - - plugin->setParent(this); - addActions(plugin->actions(props, m_mainWindow)); + foreach (const KService::Ptr& service, pluginServices) { + if (!showGroup.readEntry(service->desktopEntryName(), true)) { + // The plugin has been disabled + continue; } - // New API (kdelibs >= 4.6.1) + KAbstractFileItemActionPlugin* abstractPlugin = service->createInstance(); if (abstractPlugin) { - if (!showGroup.readEntry(service->desktopEntryName(), abstractPlugin->enabledByDefault())) { - // The plugin has been disabled - continue; - } - abstractPlugin->setParent(this); addActions(abstractPlugin->actions(props, m_mainWindow)); } @@ -520,4 +537,3 @@ void DolphinContextMenu::addCustomActions() } } -#include "dolphincontextmenu.moc"