diff --git a/containments/desktop/plugins/folder/CMakeLists.txt b/containments/desktop/plugins/folder/CMakeLists.txt --- a/containments/desktop/plugins/folder/CMakeLists.txt +++ b/containments/desktop/plugins/folder/CMakeLists.txt @@ -1,5 +1,4 @@ include_directories(plasmaquick) -include_directories(internallibkonq) set(folderplugin_SRCS directorypicker.cpp @@ -17,7 +16,6 @@ textfix.cpp viewpropertiesmenu.cpp wheelinterceptor.cpp - internallibkonq/konq_popupmenu.cpp shortcut.cpp ) diff --git a/containments/desktop/plugins/folder/foldermodel.h b/containments/desktop/plugins/folder/foldermodel.h --- a/containments/desktop/plugins/folder/foldermodel.h +++ b/containments/desktop/plugins/folder/foldermodel.h @@ -41,6 +41,7 @@ class QItemSelectionModel; class QQuickItem; +class KFileCopyToMenu; class KActionCollection; class KDirModel; class KDirWatch; @@ -201,6 +202,7 @@ Q_INVOKABLE void copy(); Q_INVOKABLE void cut(); Q_INVOKABLE void deleteSelected(); + Q_INVOKABLE void openSelected(); Q_SIGNALS: void urlChanged() const; @@ -267,6 +269,7 @@ KActionCollection m_actionCollection; KNewFileMenu *m_newMenu; KFileItemActions *m_fileItemActions; + KFileCopyToMenu *m_copyToMenu; QString m_errorString; bool m_usedByContainment; bool m_locked; diff --git a/containments/desktop/plugins/folder/foldermodel.cpp b/containments/desktop/plugins/folder/foldermodel.cpp --- a/containments/desktop/plugins/folder/foldermodel.cpp +++ b/containments/desktop/plugins/folder/foldermodel.cpp @@ -32,20 +32,20 @@ #include #include #include +#include #include #include #include #include #include #include #include -#include "internallibkonq/konq_popupmenu.h" #include #include #include -#include #include +#include #include #include #include @@ -56,8 +56,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -1196,6 +1198,10 @@ QAction *del = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("&Delete"), this); connect(del, &QAction::triggered, this, &FolderModel::deleteSelected); + QAction *actOpen = new QAction(QIcon::fromTheme(QStringLiteral("window-new")), i18n("&Open"), this); + connect(actOpen, &QAction::triggered, this, &FolderModel::openSelected); + + m_actionCollection.addAction(QStringLiteral("open"), actOpen); m_actionCollection.addAction(QStringLiteral("cut"), cut); m_actionCollection.addAction(QStringLiteral("undo"), undo); m_actionCollection.addAction(QStringLiteral("copy"), copy); @@ -1210,6 +1216,8 @@ m_newMenu = new KNewFileMenu(&m_actionCollection, QStringLiteral("newMenu"), QApplication::desktop()); m_newMenu->setModal(false); + + m_copyToMenu = new KFileCopyToMenu(Q_NULLPTR); } QAction* FolderModel::action(const QString &name) const @@ -1276,38 +1284,42 @@ updateActions(); - QMenu *menu = 0; + QMenu *menu = new QMenu(); + if (!m_fileItemActions) { + m_fileItemActions = new KFileItemActions(this); + m_fileItemActions->setParentWidget(QApplication::desktop()); + } if (indexes.isEmpty()) { - menu = new QMenu(); menu->addAction(m_actionCollection.action(QStringLiteral("newMenu"))); menu->addSeparator(); menu->addAction(m_actionCollection.action(QStringLiteral("paste"))); menu->addAction(m_actionCollection.action(QStringLiteral("undo"))); menu->addAction(m_actionCollection.action(QStringLiteral("refresh"))); menu->addAction(m_actionCollection.action(QStringLiteral("emptyTrash"))); menu->addSeparator(); - if (!m_fileItemActions) { - m_fileItemActions = new KFileItemActions(this); - } - - KFileItemListProperties itemList(KFileItemList() << m_dirModel->dirLister()->rootItem()); - m_fileItemActions->setItemListProperties(itemList); + KFileItemListProperties itemProperties(KFileItemList() << m_dirModel->dirLister()->rootItem()); + m_fileItemActions->setItemListProperties(itemProperties); menu->addAction(m_fileItemActions->preferredOpenWithAction(QString())); } else { KFileItemList items; + QList urls; bool hasRemoteFiles = false; bool isTrashLink = false; + items.reserve(indexes.count()); + urls.reserve(indexes.count()); foreach (const QModelIndex &index, indexes) { KFileItem item = itemForIndex(index); if (!item.isNull()) { hasRemoteFiles |= item.localPath().isEmpty(); items.append(item); + urls.append(item.url()); } } + KFileItemListProperties itemProperties(items); // Check if we're showing the menu for the trash link if (items.count() == 1 && items.at(0).isDesktopFile()) { @@ -1317,41 +1329,70 @@ } } - QList editActions; - editActions.append(m_actionCollection.action(QStringLiteral("rename"))); + // Start adding the actions: + menu->addAction(m_actionCollection.action(QStringLiteral("open"))); + menu->addSeparator(); + if (itemProperties.supportsDeleting()) { + menu->addAction(m_actionCollection.action(QStringLiteral("cut"))); + } + menu->addAction(m_actionCollection.action(QStringLiteral("copy"))); + + if (itemProperties.isDirectory() && itemProperties.supportsWriting()) { + menu->addAction(m_actionCollection.action(QStringLiteral("pasteto"))); + } + + menu->addAction(m_actionCollection.action(QStringLiteral("rename"))); KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals); KConfigGroup cg(globalConfig, "KDE"); bool showDeleteCommand = cg.readEntry("ShowDeleteCommand", false); // Don't add the "Move to Trash" action if we're showing the menu for the trash link if (!isTrashLink) { if (!hasRemoteFiles) { - editActions.append(m_actionCollection.action(QStringLiteral("trash"))); + menu->addAction(m_actionCollection.action(QStringLiteral("trash"))); } else { showDeleteCommand = true; } } if (showDeleteCommand) { - editActions.append(m_actionCollection.action(QStringLiteral("del"))); + menu->addAction(m_actionCollection.action(QStringLiteral("del"))); } - KonqPopupMenu::ActionGroupMap actionGroups; - actionGroups.insert(KonqPopupMenu::EditActions, editActions); + // "Open with" actions + m_fileItemActions->setItemListProperties(itemProperties); + m_fileItemActions->addOpenWithActionsTo(menu); + // Service actions + m_fileItemActions->addServiceActionsTo(menu); + menu->addSeparator(); + // Plugin actions +#if KIO_VERSION >= QT_VERSION_CHECK(5, 27, 0) + m_fileItemActions->addPluginActionsTo(menu); +#endif + + // Copy To, Move To + KSharedConfig::Ptr dolphin = KSharedConfig::openConfig(QStringLiteral("dolphinrc")); + if (KConfigGroup(dolphin, "General").readEntry("ShowCopyMoveMenu", false)) { + m_copyToMenu->setUrls(urls); + m_copyToMenu->setReadOnly(!itemProperties.supportsMoving()); + m_copyToMenu->addActionsTo(menu); + menu->addSeparator(); + } - KonqPopupMenu::Flags flags = KonqPopupMenu::ShowProperties; - flags |= KonqPopupMenu::ShowUrlOperations; - flags |= KonqPopupMenu::ShowNewWindow; + // Properties + if (KPropertiesDialog::canDisplay(items)) { + QAction *act = new QAction(menu); + act->setText(i18n("&Properties")); + QObject::connect(act, &QAction::triggered, [this, items]() { + KPropertiesDialog::showDialog(items, Q_NULLPTR, false /*non modal*/); + }); + menu->addAction(act); + } - KonqPopupMenu *popupMenu = new KonqPopupMenu(items, m_dirModel->dirLister()->url(), m_actionCollection, flags, QApplication::desktop()); - popupMenu->setNewFileMenu(m_newMenu); - popupMenu->setBookmarkManager(KBookmarkManager::userBookmarksManager()); - popupMenu->setActionGroups(actionGroups); - connect(popupMenu, &QMenu::aboutToHide, [popupMenu]() { popupMenu->deleteLater(); }); - menu = popupMenu; } menu->popup(QCursor::pos()); + connect(menu, &QMenu::aboutToHide, [menu]() { menu->deleteLater(); }); } void FolderModel::linkHere(const QUrl &sourceUrl) @@ -1448,6 +1489,18 @@ } } +void FolderModel::openSelected() +{ + if (!m_selectionModel->hasSelection()) { + return; + } + + const QList urls = selectedUrls(false); + for (const QUrl &url : urls) { + (void) new KRun(url, Q_NULLPTR); + } +} + void FolderModel::emptyTrashBin() { KIO::JobUiDelegate uiDelegate; diff --git a/containments/desktop/plugins/folder/internallibkonq/README_internallibkonq.txt b/containments/desktop/plugins/folder/internallibkonq/README_internallibkonq.txt deleted file mode 100644 --- a/containments/desktop/plugins/folder/internallibkonq/README_internallibkonq.txt +++ /dev/null @@ -1,16 +0,0 @@ -The internallibkonq/ folder contains a subset of the libkonq -library originally from kde-baseapps.git. - -This was added here temporarily to avoid a dependency of -plasma-desktop on kde-baseapps. - -The long-term plan is to split up libkonq and distribute its -useful parts over various parts of KDE Frameworks 5, and then -eliminate this duplication. - -DO NOT MODIFY this copy of the library to avoid divergence -from the upstream source. Any patches need to be applied to -kde-baseapps first. - -Signed of by: David Faure , library maintainer - Kevin Ottens , KF5 coordinator \ No newline at end of file diff --git a/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.h b/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.h deleted file mode 100644 --- a/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.h +++ /dev/null @@ -1,149 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1998-2016 David Faure - Copyright (C) 2001 Holger Freyther - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __konqpopupmenu_h -#define __konqpopupmenu_h - -#include - -#include - -class KFileItemList; -class KNewFileMenu; -class KFileItemActions; - -class KActionCollection; -class KBookmarkManager; -class KonqPopupMenuPrivate; -class QUrl; - -/** - * This class implements the popup menu for URLs in file managers. - * - * The recommended usage is to use QMenu::popup() to avoid modal popupmenus. - * - * Either reuse the instance, or delete it after use with - * connect(menu, &QMenu::aboutToHide, [menu]() { menu->deleteLater(); }); - * - * Users of KonqPopupMenu include: konqueror, kfind, the folderview desktop plasmoid. - */ -class LIBKONQ_EXPORT KonqPopupMenu : public QMenu -{ - Q_OBJECT -public: - - /** - * Each action group is inserted into the context menu at a specific position. - * "editactions" for actions related text editing, - * "linkactions" for actions related to hyperlinks, - * "partactions" for any other actions provided by the part - */ - enum ActionGroup { - TopActions, ///< actions to be shown at the top of the context menu, like "show menu bar" - TabHandlingActions, ///< actions for tab handling, like "open in new tab" - EditActions, ///< move to trash, delete, etc. - PreviewActions, ///< actions related to viewing the selected file with an embedded viewer - CustomActions, ///< group for more custom actions, such as those provided by KParts components - LinkActions ///< actions related to handling of hyperlinks, only shown if the IsLink flag is set - }; - - typedef QMap > ActionGroupMap; - - /** - * Set of flags to ask for some items in the popup menu. - */ - enum Flag { - DefaultPopupItems = 0x0000, ///< default value, no additional menu item - ShowNavigationItems = 0x0001, ///< show "back" and "forward" (usually done when clicking the background of the view, but not an item) - ShowUp = 0x0002, ///< show "up" (same thing, but not over e.g. HTTP). Requires ShowNavigationItems. - ShowReload = 0x0004, ///< show "reload" (usually done when clicking the background of the view, but not an item) - ShowBookmark = 0x0008, ///< show "add to bookmarks" (usually not done on the local filesystem) - ShowCreateDirectory = 0x0010, ///< show "create directory" (usually only done on the background of the view, or - /// in hierarchical views like directory trees, where the new dir would be visible) - ShowTextSelectionItems = 0x0020, ///< set when selecting text, for a popup that only contains text-related items. - NoDeletion = 0x0040, ///< "cut" not allowed (e.g. parent dir not writeable). - /// (this is only needed if the protocol itself supports deletion, unlike e.g. HTTP) - IsLink = 0x0080, ///< show "Bookmark This Link" and other link-related actions (LinkActions group) - ShowUrlOperations = 0x0100, ///< show copy, paste, as well as cut if NoDeletion is not set. - ShowProperties = 0x0200, ///< show "Properties" action (usually done by directory views) - ShowNewWindow = 0x0400, ///< Show "Open in new window" action - NoPlugins = 0x0800 ///< Disable plugins - mostly for the unittest - }; - Q_DECLARE_FLAGS(Flags, Flag) - - /** - * Constructor - * @param items the list of file items the popupmenu should be shown for - * @param viewURL the URL shown in the view, to test for RMB click on view background - * @param actions list of actions the caller wants to see in the menu - * @param newMenu "New" menu, shared with the File menu, in konqueror - * @param flags flags which control which items to show in the popupmenu - * @param parentWidget the widget we're showing this popup for. Helps destroying - * the popup if the widget is destroyed before the popup. - * - * The actions to pass in the action collection are : - * go_back, go_forward, go_up, reload, cut, copy, paste, pasteto - * The others items are automatically inserted. - */ - KonqPopupMenu(const KFileItemList &items, - const QUrl &viewURL, - KActionCollection &actions, - Flags flags, - QWidget *parentWidget = 0); - - /** - * Don't forget to destroy the object - */ - ~KonqPopupMenu(); - - /** - * Sets the "New file" menu instance. This allows to share it with the menubar. - */ - void setNewFileMenu(KNewFileMenu *newMenu); - - /** - * Sets the bookmark manager for the "add to bookmark" action. - * Only used if ShowBookmark is set - */ - void setBookmarkManager(KBookmarkManager *manager); - - /** - * Sets the additional actions to show in the context menu - */ - void setActionGroups(const ActionGroupMap &actionGroups); - - /** - * Set the title of the URL, when the popupmenu is opened for a single URL. - * This is used if the user chooses to add a bookmark for this URL. - */ - void setURLTitle(const QString &urlTitle); - -Q_SIGNALS: - /** - * Emitted before the "Open With" dialog is shown - * This is used e.g in folderview to close the folder peek popups on invoking the "Open With" menu action - */ - void openWithDialogAboutToBeShown(); - -private: - KonqPopupMenuPrivate *d; -}; - -#endif diff --git a/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp b/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp deleted file mode 100644 --- a/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1998-2008 David Faure - Copyright (C) 2001 Holger Freyther - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "konq_popupmenu.h" - -#include - -#include -#include "kfileitemactions.h" -#include "kabstractfileitemactionplugin.h" -#include "kpropertiesdialog.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/* - Test cases: - iconview file: background - iconview file: file (with and without servicemenus) - iconview file: directory - iconview remote protocol (e.g. ftp: or fish:) - iconview trash:/ - sidebar directory tree - sidebar Devices / Hard Disc - khtml background - khtml link - khtml image (www.kde.org RMB on K logo) - khtmlimage (same as above, then choose View image, then RMB) - selected text in khtml - embedded katepart - folder on the desktop - trash link on the desktop - trashed file or directory - application .desktop file - Then the same after uninstalling kdeaddons/konq-plugins (arkplugin in particular) -*/ - -class KonqPopupMenuPrivate -{ -public: - KonqPopupMenuPrivate(KonqPopupMenu *qq, KActionCollection &actions, QWidget *parentWidget) - : q(qq), - m_parentWidget(parentWidget), - m_popupFlags(KonqPopupMenu::DefaultPopupItems), - m_pMenuNew(0), - m_copyToMenu(parentWidget), - m_bookmarkManager(0), - m_actions(actions) - { - } - - ~KonqPopupMenuPrivate() - { - qDeleteAll(m_ownActions); - } - - void addNamedAction(const char *name); - void addGroup(KonqPopupMenu::ActionGroup group); - void addPlugins(); - void populate(); - void aboutToShow(); - - void slotPopupNewDir(); - void slotPopupNewView(); - void slotPopupEmptyTrashBin(); - void slotConfigTrashBin(); - void slotPopupRestoreTrashedItems(); - void slotPopupAddToBookmark(); - void slotPopupMimeType(); - void slotPopupProperties(); - void slotShowOriginalFile(); - - KonqPopupMenu *q; - QWidget *m_parentWidget; - QString m_urlTitle; - KonqPopupMenu::Flags m_popupFlags; - KNewFileMenu *m_pMenuNew; - QUrl m_sViewURL; - KFileItemListProperties m_popupItemProperties; - KFileItemActions m_menuActions; - KFileCopyToMenu m_copyToMenu; - KBookmarkManager *m_bookmarkManager; - KActionCollection &m_actions; - QList m_ownActions; - KonqPopupMenu::ActionGroupMap m_actionGroups; -}; - -////////////////// - -KonqPopupMenu::KonqPopupMenu(const KFileItemList &items, - const QUrl &viewURL, - KActionCollection &actions, - Flags popupFlags, - QWidget *parentWidget) - : QMenu(parentWidget), - d(new KonqPopupMenuPrivate(this, actions, parentWidget)) -{ - d->m_sViewURL = viewURL; - d->m_popupItemProperties.setItems(items); - d->m_menuActions.setParentWidget(parentWidget); - d->m_popupFlags = popupFlags; - - connect(this, &QMenu::aboutToShow, this, [this]() { d->aboutToShow(); }); -} - -void KonqPopupMenuPrivate::addNamedAction(const char *name) -{ - QAction *act = m_actions.action(QString::fromLatin1(name)); - if (act) { - q->addAction(act); - } -} - -void KonqPopupMenuPrivate::aboutToShow() -{ - populate(); - KAcceleratorManager::manage(q); -} - -void KonqPopupMenuPrivate::populate() -{ - Q_ASSERT(m_popupItemProperties.items().count() >= 1); - - bool bTrashIncluded = false; - - const KFileItemList lstItems = m_popupItemProperties.items(); - QList lstUrls; - lstUrls.reserve(lstItems.count()); - for (const KFileItem &item : lstItems) { - const QUrl url = item.url(); - lstUrls.append(url); - if (!bTrashIncluded && ((url.scheme() == QLatin1String("trash") && url.path().length() <= 1))) { - bTrashIncluded = true; - } - } - - const bool isDirectory = m_popupItemProperties.isDirectory(); - const bool sReading = m_popupItemProperties.supportsReading(); - bool sDeleting = (m_popupFlags & KonqPopupMenu::NoDeletion) == 0 - && m_popupItemProperties.supportsDeleting(); - const bool sWriting = m_popupItemProperties.supportsWriting(); - const bool sMoving = sDeleting && m_popupItemProperties.supportsMoving(); - - QUrl url = m_sViewURL.adjusted(QUrl::NormalizePathSegments); - - bool isTrashLink = false; - bool isCurrentTrash = false; - bool currentDir = false; - bool isSymLink = false; - bool isSymLinkInSameDir = false; // true for "ln -s foo bar", false for links to foo/sub or /foo - - //check if url is current directory - if (lstItems.count() == 1) { - KFileItem firstPopupItem(lstItems.first()); - if (firstPopupItem.isLink()) { - isSymLink = true; - isSymLinkInSameDir = !firstPopupItem.linkDest().contains(QLatin1Char('/')); - } - QUrl firstPopupURL(firstPopupItem.url().adjusted(QUrl::NormalizePathSegments)); - //kDebug(1203) << "View path is " << url.url(); - //kDebug(1203) << "First popup path is " << firstPopupURL.url(); - currentDir = (firstPopupURL.matches(url, QUrl::StripTrailingSlash)); - if (firstPopupItem.isDesktopFile()) { - KDesktopFile desktopFile(firstPopupItem.localPath()); - const KConfigGroup cfg = desktopFile.desktopGroup(); - isTrashLink = cfg.readEntry("Type") == QLatin1String("Link") - && cfg.readEntry("URL") == QLatin1String("trash:/"); - } - - if (isTrashLink) { - sDeleting = false; - } - - // isCurrentTrash: popup on trash:/ itself, or on the trash.desktop link - isCurrentTrash = (firstPopupURL.scheme() == QLatin1String("trash") && firstPopupURL.path().length() <= 1) - || isTrashLink; - } - - const bool isIntoTrash = (url.scheme() == QLatin1String("trash")) && !isCurrentTrash; // trashed file, not trash:/ itself - - const bool bIsLink = (m_popupFlags & KonqPopupMenu::IsLink); - - //kDebug() << "isLocal=" << isLocal << " url=" << url << " isCurrentTrash=" << isCurrentTrash << " isIntoTrash=" << isIntoTrash << " bTrashIncluded=" << bTrashIncluded; - - ////////////////////////////////////////////////////////////////////////// - - addGroup(KonqPopupMenu::TopActions); // used e.g. for ShowMenuBar. includes a separator at the end - - QAction *act; - - QAction *actNewWindow = 0; - -#if 0 // TODO in the desktop code itself. - if ((flags & KonqPopupMenu::ShowProperties) && isOnDesktop && - !KAuthorized::authorizeKAction("editable_desktop_icons")) { - flags &= ~KonqPopupMenu::ShowProperties; // remove flag - } -#endif - - // Either 'newview' is in the actions we're given (probably in the tabhandling group) - // or we need to insert it ourselves (e.g. for the desktop). - // In the first case, actNewWindow must remain 0. - if (((m_popupFlags & KonqPopupMenu::ShowNewWindow) != 0) && sReading) { - const QString openStr = i18n("&Open"); - actNewWindow = new QAction(m_parentWidget /*for status tips*/); - m_ownActions.append(actNewWindow); - actNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); - actNewWindow->setText(openStr); - QObject::connect(actNewWindow, &QAction::triggered, [this]() { - slotPopupNewView(); - }); - } - - if (isDirectory && sWriting && !isCurrentTrash) { // A dir, and we can create things into it - const bool mkdirRequested = m_popupFlags & KonqPopupMenu::ShowCreateDirectory; - if ((currentDir || mkdirRequested) && m_pMenuNew) { // Current dir -> add the "new" menu - // As requested by KNewFileMenu : - m_pMenuNew->checkUpToDate(); - m_pMenuNew->setPopupFiles(m_popupItemProperties.urlList()); - - q->addAction(m_pMenuNew); - q->addSeparator(); - } else if (mkdirRequested) { - QAction *actNewDir = new QAction(m_parentWidget); - m_ownActions.append(actNewDir); - actNewDir->setIcon(QIcon::fromTheme(QStringLiteral("folder-new"))); - actNewDir->setText(i18n("Create &Folder...")); - QObject::connect(actNewDir, &QAction::triggered, [this]() { - slotPopupNewDir(); - }); - q->addAction(actNewDir); - q->addSeparator(); - } - } else if (isIntoTrash) { - // Trashed item, offer restoring - act = new QAction(m_parentWidget /*for status tips*/); - m_ownActions.append(act); - act->setText(i18n("&Restore")); - //PORT QT5 act->setHelpText(i18n("Restores this file or directory, back to the location where it was deleted from initially")); - QObject::connect(act, &QAction::triggered, [this]() { - slotPopupRestoreTrashedItems(); - }); - q->addAction(act); - } - - if (m_popupFlags & KonqPopupMenu::ShowNavigationItems) { - if (m_popupFlags & KonqPopupMenu::ShowUp) { - addNamedAction("go_up"); - } - addNamedAction("go_back"); - addNamedAction("go_forward"); - if (m_popupFlags & KonqPopupMenu::ShowReload) { - addNamedAction("reload"); - } - q->addSeparator(); - } - - if (!currentDir && isSymLink && !isSymLinkInSameDir) { - // #65151: offer to open the target's parent dir - act = new QAction(m_parentWidget); - m_ownActions.append(act); - act->setText(isDirectory ? i18n("Show Original Directory") : i18n("Show Original File")); - //PORT TO QT5 act->setHelpText(i18n("Opens a new file manager window showing the target of this link, in its parent directory.")); - QObject::connect(act, &QAction::triggered, [this]() { - slotShowOriginalFile(); - }); - q->addAction(act); - } - - // "open in new window" is either provided by us, or by the tabhandling group - if (actNewWindow) { - q->addAction(actNewWindow); - q->addSeparator(); - } - addGroup(KonqPopupMenu::TabHandlingActions); // includes a separator at the end - - if (m_popupFlags & KonqPopupMenu::ShowUrlOperations) { - if (!currentDir && sReading) { - if (sDeleting) { - addNamedAction("cut"); - } - addNamedAction("copy"); - } - - if (isDirectory && sWriting) { - if (currentDir) { - addNamedAction("paste"); - } else { - addNamedAction("pasteto"); - } - } - } - if (isCurrentTrash) { - act = new QAction(m_parentWidget); - m_ownActions.append(act); - act->setIcon(QIcon::fromTheme(QStringLiteral("trash-empty"))); - act->setText(i18n("&Empty Trash Bin")); - KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); - act->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); - QObject::connect(act, &QAction::triggered, [this]() { - slotPopupEmptyTrashBin(); - }); - q->addAction(act); - } - if (isCurrentTrash) { - act = new QAction(m_parentWidget); - m_ownActions.append(act); - act->setIcon(QIcon::fromTheme(QStringLiteral("trash-empty"))); - act->setText(i18n("&Configure Trash Bin")); - QObject::connect(act, &QAction::triggered, [this]() { - slotConfigTrashBin(); - }); - q->addAction(act); - } - - // This is used by KHTML, see khtml_popupmenu.rc (copy, selectAll, searchProvider etc.) - // and by DolphinPart (rename, trash, delete) - addGroup(KonqPopupMenu::EditActions); - - if (m_popupFlags & KonqPopupMenu::ShowTextSelectionItems) { - // OK, we have to stop here. - - // Anything else that is provided by the part - addGroup(KonqPopupMenu::CustomActions); - return; - } - - if (!isCurrentTrash && !isIntoTrash && (m_popupFlags & KonqPopupMenu::ShowBookmark)) { - QString caption; - if (currentDir) { - const bool httpPage = m_sViewURL.scheme().startsWith(QLatin1String("http"), Qt::CaseInsensitive); - if (httpPage) { - caption = i18n("&Bookmark This Page"); - } else { - caption = i18n("&Bookmark This Location"); - } - } else if (isDirectory) { - caption = i18n("&Bookmark This Folder"); - } else if (bIsLink) { - caption = i18n("&Bookmark This Link"); - } else { - caption = i18n("&Bookmark This File"); - } - - act = new QAction(m_parentWidget); - m_ownActions.append(act); - act->setObjectName(QLatin1String("bookmark_add")); // for unittest - act->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new"))); - act->setText(caption); - QObject::connect(act, &QAction::triggered, [this]() { - slotPopupAddToBookmark(); - }); - if (lstItems.count() > 1) { - act->setEnabled(false); - } - if (KAuthorized::authorizeKAction(QStringLiteral("bookmarks"))) { - q->addAction(act); - } - if (bIsLink) { - addGroup(KonqPopupMenu::LinkActions); // see khtml - } - } - - // "Open With" actions - - m_menuActions.setItemListProperties(m_popupItemProperties); - - if (sReading) { - m_menuActions.addOpenWithActionsTo(q, QStringLiteral("DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'")); - - QList previewActions = m_actionGroups.value(KonqPopupMenu::PreviewActions); - if (!previewActions.isEmpty()) { - if (previewActions.count() == 1) { - q->addAction(previewActions.first()); - } else { - QMenu *subMenu = new QMenu(i18n("Preview In"), q); - subMenu->menuAction()->setObjectName(QLatin1String("preview_submenu")); // for the unittest - q->addMenu(subMenu); - subMenu->addActions(previewActions); - } - } - } - - // Second block, builtin + user - m_menuActions.addServiceActionsTo(q); - - q->addSeparator(); - - // Use the Dolphin setting for showing the "Copy To" and "Move To" actions - KSharedConfig::Ptr dolphin = KSharedConfig::openConfig(QStringLiteral("dolphinrc")); - - // CopyTo/MoveTo menus - if (m_popupFlags & KonqPopupMenu::ShowUrlOperations && - KConfigGroup(dolphin, "General").readEntry("ShowCopyMoveMenu", false)) { - - m_copyToMenu.setUrls(lstUrls); - m_copyToMenu.setReadOnly(sMoving == false); - m_copyToMenu.addActionsTo(q); - q->addSeparator(); - } - - if (!isCurrentTrash && !isIntoTrash && sReading && - (m_popupFlags & KonqPopupMenu::NoPlugins) == 0) { - addPlugins(); // now it's time to add plugins - } - - if ((m_popupFlags & KonqPopupMenu::ShowProperties) && KPropertiesDialog::canDisplay(lstItems)) { - act = new QAction(m_parentWidget); - m_ownActions.append(act); - act->setObjectName(QLatin1String("properties")); // for unittest - act->setText(i18n("&Properties")); - QObject::connect(act, &QAction::triggered, [this]() { - slotPopupProperties(); - }); - q->addAction(act); - } - - while (!q->actions().isEmpty() && - q->actions().last()->isSeparator()) { - delete q->actions().last(); - } - - // Anything else that is provided by the part - addGroup(KonqPopupMenu::CustomActions); - - QObject::connect(&m_menuActions, &KFileItemActions::openWithDialogAboutToBeShown, q, &KonqPopupMenu::openWithDialogAboutToBeShown); -} - -KonqPopupMenu::~KonqPopupMenu() -{ - delete d; - //kDebug(1203) << "~KonqPopupMenu leave"; -} - -void KonqPopupMenu::setNewFileMenu(KNewFileMenu *newMenu) -{ - d->m_pMenuNew = newMenu; -} - -void KonqPopupMenu::setBookmarkManager(KBookmarkManager *manager) -{ - d->m_bookmarkManager = manager; -} - -void KonqPopupMenu::setActionGroups(const KonqPopupMenu::ActionGroupMap &actionGroups) -{ - d->m_actionGroups = actionGroups; -} - -void KonqPopupMenu::setURLTitle(const QString &urlTitle) -{ - d->m_urlTitle = urlTitle; -} - -void KonqPopupMenuPrivate::slotPopupNewView() -{ - Q_FOREACH (const QUrl &url, m_popupItemProperties.urlList()) { - (void) new KRun(url, m_parentWidget); - } -} - -void KonqPopupMenuPrivate::slotPopupNewDir() -{ - m_pMenuNew->createDirectory(); -} - -void KonqPopupMenuPrivate::slotPopupEmptyTrashBin() -{ - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(m_parentWidget); - if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::emptyTrash(); - KJobWidgets::setWindow(job, m_parentWidget); - job->ui()->setAutoErrorHandlingEnabled(true); // or connect to the result signal - } -} - -void KonqPopupMenuPrivate::slotConfigTrashBin() -{ - KRun::run(QStringLiteral("kcmshell5 kcmtrash"), QList(), m_parentWidget); -} - -void KonqPopupMenuPrivate::slotPopupRestoreTrashedItems() -{ - KIO::RestoreJob *job = KIO::restoreFromTrash(m_popupItemProperties.urlList()); - KJobWidgets::setWindow(job, m_parentWidget); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); -} - -void KonqPopupMenuPrivate::slotPopupAddToBookmark() -{ - KBookmarkGroup root; - if (m_popupItemProperties.urlList().count() == 1) { - const QUrl url = m_popupItemProperties.urlList().first(); - const QString title = m_urlTitle.isEmpty() ? url.toDisplayString() : m_urlTitle; - KBookmarkDialog dlg(m_bookmarkManager, m_parentWidget); - dlg.addBookmark(title, url, QString()); - } else { - root = m_bookmarkManager->root(); - Q_FOREACH (const QUrl &url, m_popupItemProperties.urlList()) { - root.addBookmark(url.toDisplayString(), url, QString()); - } - m_bookmarkManager->emitChanged(root); - } -} - -void KonqPopupMenuPrivate::slotPopupMimeType() -{ - KMimeTypeEditor::editMimeType(m_popupItemProperties.mimeType(), m_parentWidget); -} - -void KonqPopupMenuPrivate::slotPopupProperties() -{ - KPropertiesDialog::showDialog(m_popupItemProperties.items(), m_parentWidget, false); -} - -void KonqPopupMenuPrivate::addGroup(KonqPopupMenu::ActionGroup group) -{ - q->addActions(m_actionGroups.value(group)); -} - -void KonqPopupMenuPrivate::addPlugins() -{ - QString commonMimeType = m_popupItemProperties.mimeType(); - if (commonMimeType.isEmpty()) { - commonMimeType = QLatin1String("application/octet-stream"); - } - - const KService::List fileItemPlugins = KMimeTypeTrader::self()->query(commonMimeType, QStringLiteral("KFileItemAction/Plugin"), QStringLiteral("exist Library")); - if (!fileItemPlugins.isEmpty()) { - const KConfig config(QStringLiteral("kservicemenurc"), KConfig::NoGlobals); - const KConfigGroup showGroup = config.group("Show"); - - foreach (const auto &service, fileItemPlugins) { - if (!showGroup.readEntry(service->desktopEntryName(), true)) { - // The plugin has been disabled - continue; - } - - KAbstractFileItemActionPlugin *abstractPlugin = service->createInstance(); - if (abstractPlugin) { - abstractPlugin->setParent(q); - q->addActions(abstractPlugin->actions(m_popupItemProperties, m_parentWidget)); - } - } - } -} - -void KonqPopupMenuPrivate::slotShowOriginalFile() -{ - const KFileItem item = m_popupItemProperties.items().first(); - QUrl destUrl = QUrl::fromLocalFile(item.linkDest()); - - if (!destUrl.isValid()) { - return; - } - - KIO::highlightInFileManager({destUrl}); -} diff --git a/containments/desktop/plugins/folder/internallibkonq/libkonq_export.h b/containments/desktop/plugins/folder/internallibkonq/libkonq_export.h deleted file mode 100644 --- a/containments/desktop/plugins/folder/internallibkonq/libkonq_export.h +++ /dev/null @@ -1,2 +0,0 @@ -#define LIBKONQ_EXPORT -