summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2016-09-25 21:53:51 +0200
committerDavid Faure <[email protected]>2016-09-25 21:54:03 +0200
commitb6e3c572bbc84bca53bc4551f6b1a0ca6b0f3db6 (patch)
tree1291bb01ea8ee35ef5bfafb03d976ef2bdee4d79
parent47396ea25e9f99009e9fd10cd52a0ea6468c7192 (diff)
Kill KonqCopyToMenu and port to kio's KFileCopyToMenu instead.
(like in libkonq)
-rw-r--r--containments/desktop/plugins/folder/CMakeLists.txt1
-rw-r--r--containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.cpp266
-rw-r--r--containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.h80
-rw-r--r--containments/desktop/plugins/folder/internallibkonq/konq_copytomenu_p.h85
-rw-r--r--containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp15
5 files changed, 8 insertions, 439 deletions
diff --git a/containments/desktop/plugins/folder/CMakeLists.txt b/containments/desktop/plugins/folder/CMakeLists.txt
index 7800424..55d3119 100644
--- a/containments/desktop/plugins/folder/CMakeLists.txt
+++ b/containments/desktop/plugins/folder/CMakeLists.txt
@@ -17,7 +17,6 @@ set(folderplugin_SRCS
textfix.cpp
viewpropertiesmenu.cpp
wheelinterceptor.cpp
- internallibkonq/konq_copytomenu.cpp
internallibkonq/konq_popupmenu.cpp
shortcut.cpp
)
diff --git a/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.cpp b/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.cpp
deleted file mode 100644
index ca26914..0000000
--- a/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/* This file is part of the KDE project
-
- Copyright 2008, 2009 David Faure <[email protected]>
-
- 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 ) version 3 or, at the discretion of KDE e.V.
- ( which shall act as a proxy as in section 14 of the GPLv3 ), 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_copytomenu.h"
-#include "konq_copytomenu_p.h"
-#include <QAction>
-#include <QDebug>
-#include <QDir>
-#include <QIcon>
-#include <QFileDialog>
-#include <QMimeDatabase>
-#include <QMimeType>
-
-#include <KIO/FileUndoManager>
-#include <KIO/CopyJob>
-#include <KIO/JobUiDelegate>
-#include <KLocalizedString>
-#include <KSharedConfig>
-#include <KStringHandler>
-#include <KJobWidgets>
-
-#ifdef Q_OS_WIN
-#include "Windows.h"
-#endif
-
-KonqCopyToMenuPrivate::KonqCopyToMenuPrivate(QWidget *parentWidget)
- : m_urls(), m_readOnly(false), m_parentWidget(parentWidget)
-{
-}
-
-////
-
-KonqCopyToMenu::KonqCopyToMenu(QWidget *parentWidget)
- : d(new KonqCopyToMenuPrivate(parentWidget))
-{
-}
-
-KonqCopyToMenu::~KonqCopyToMenu()
-{
- delete d;
-}
-
-void KonqCopyToMenu::setItems(const KFileItemList &items)
-{
- // For now we lose all the information except for the urls
- // But this API is useful in case KIO can make use of this information later
- // (e.g. to avoid stat'ing the source urls)
- Q_FOREACH (const KFileItem &item, items) {
- d->m_urls.append(item.url());
- }
-}
-
-void KonqCopyToMenu::setUrls(const QList<QUrl> &urls)
-{
- d->m_urls = urls;
-}
-
-void KonqCopyToMenu::setReadOnly(bool ro)
-{
- d->m_readOnly = ro;
-}
-
-void KonqCopyToMenu::addActionsTo(QMenu *menu)
-{
- QMenu *mainCopyMenu = new KonqCopyToMainMenu(menu, d, Copy);
- mainCopyMenu->setTitle(i18nc("@title:menu", "Copy To"));
- mainCopyMenu->menuAction()->setObjectName(QLatin1String("copyTo_submenu")); // for the unittest
- menu->addMenu(mainCopyMenu);
-
- if (!d->m_readOnly) {
- QMenu *mainMoveMenu = new KonqCopyToMainMenu(menu, d, Move);
- mainMoveMenu->setTitle(i18nc("@title:menu", "Move To"));
- mainMoveMenu->menuAction()->setObjectName(QLatin1String("moveTo_submenu")); // for the unittest
- menu->addMenu(mainMoveMenu);
- }
-}
-
-////
-
-KonqCopyToMainMenu::KonqCopyToMainMenu(QMenu *parent, KonqCopyToMenuPrivate *_d, MenuType menuType)
- : QMenu(parent), m_menuType(menuType),
- m_actionGroup(static_cast<QWidget *>(0)),
- d(_d),
- m_recentDirsGroup(KSharedConfig::openConfig(), m_menuType == Copy ? "kuick-copy" : "kuick-move")
-{
- connect(this, &KonqCopyToMainMenu::aboutToShow, this, &KonqCopyToMainMenu::slotAboutToShow);
- connect(&m_actionGroup, &QActionGroup::triggered, this, &KonqCopyToMainMenu::slotTriggered);
-}
-
-void KonqCopyToMainMenu::slotAboutToShow()
-{
- clear();
- KonqCopyToDirectoryMenu *subMenu;
- // Home Folder
- subMenu = new KonqCopyToDirectoryMenu(this, this, QDir::homePath());
- subMenu->setTitle(i18nc("@title:menu", "Home Folder"));
- subMenu->setIcon(QIcon::fromTheme(QStringLiteral("go-home")));
- addMenu(subMenu);
-
- // Root Folder
-#ifndef Q_OS_WIN
- subMenu = new KonqCopyToDirectoryMenu(this, this, QDir::rootPath());
- subMenu->setTitle(i18nc("@title:menu", "Root Folder"));
- subMenu->setIcon(QIcon::fromTheme(QStringLiteral("folder-red")));
- addMenu(subMenu);
-#else
- foreach (const QFileInfo &info, QDir::drives()) {
- uint type = DRIVE_UNKNOWN;
- QString driveIcon = "drive-harddisk";
- type = GetDriveTypeW((wchar_t *)info.absoluteFilePath().utf16());
- switch (type) {
- case DRIVE_REMOVABLE:
- driveIcon = "drive-removable-media";
- break;
- case DRIVE_FIXED:
- driveIcon = "drive-harddisk";
- break;
- case DRIVE_REMOTE:
- driveIcon = "network-server";
- break;
- case DRIVE_CDROM:
- driveIcon = "drive-optical";
- break;
- case DRIVE_RAMDISK:
- case DRIVE_UNKNOWN:
- case DRIVE_NO_ROOT_DIR:
- default:
- driveIcon = "drive-harddisk";
- }
- subMenu = new KonqCopyToDirectoryMenu(this, this, info.absoluteFilePath());
- subMenu->setTitle(info.absoluteFilePath());
- subMenu->setIcon(QIcon::fromTheme(driveIcon));
- addMenu(subMenu);
- }
-#endif
-
- // Browse... action, shows a file dialog
- QAction *browseAction = new QAction(i18nc("@title:menu in Copy To or Move To submenu", "Browse..."), this);
- connect(browseAction, &QAction::triggered, this, &KonqCopyToMainMenu::slotBrowse);
- addAction(browseAction);
-
- addSeparator(); // looks like Qt4 handles removing it automatically if it's last in the menu, nice.
-
- // Recent Destinations
- const QStringList recentDirs = m_recentDirsGroup.readPathEntry("Paths", QStringList());
- Q_FOREACH (const QString &recentDir, recentDirs) {
- const QUrl url(recentDir);
- const QString text = KStringHandler::csqueeze(url.toDisplayString(), 60); // shorten very long paths (#61386)
- QAction *act = new QAction(text, this);
- act->setData(url);
- m_actionGroup.addAction(act);
- addAction(act);
- }
-}
-
-void KonqCopyToMainMenu::slotBrowse()
-{
- const QUrl dest = QFileDialog::getExistingDirectoryUrl(d->m_parentWidget ? d->m_parentWidget : this);
- if (!dest.isEmpty()) {
- copyOrMoveTo(dest);
- }
-}
-
-void KonqCopyToMainMenu::slotTriggered(QAction *action)
-{
- const QUrl url = action->data().value<QUrl>();
- Q_ASSERT(!url.isEmpty());
- copyOrMoveTo(url);
-}
-
-void KonqCopyToMainMenu::copyOrMoveTo(const QUrl &dest)
-{
- // Insert into the recent destinations list
- QStringList recentDirs = m_recentDirsGroup.readPathEntry("Paths", QStringList());
- const QString niceDest = dest.toDisplayString();
- if (!recentDirs.contains(niceDest)) { // don't change position if already there, moving stuff is bad usability
- recentDirs.prepend(niceDest);
- while (recentDirs.size() > 10) { // hardcoded max size
- recentDirs.removeLast();
- }
- m_recentDirsGroup.writePathEntry("Paths", recentDirs);
- }
-
- // #199549: add a trailing slash to avoid unexpected results when the
- // dest doesn't exist anymore: it was creating a file with the name of
- // the now non-existing dest.
- QUrl dirDest = dest;
- if (!dirDest.path().endsWith(QLatin1Char('/'))) {
- dirDest.setPath(dirDest.path() + QLatin1Char('/'));
- }
-
- // And now let's do the copy or move -- with undo/redo support.
- KIO::CopyJob *job = m_menuType == Copy ? KIO::copy(d->m_urls, dirDest) : KIO::move(d->m_urls, dirDest);
- KIO::FileUndoManager::self()->recordCopyJob(job);
- KJobWidgets::setWindow(job, d->m_parentWidget ? d->m_parentWidget : this);
- job->ui()->setAutoErrorHandlingEnabled(true); // or connect to the result signal
-}
-
-////
-
-KonqCopyToDirectoryMenu::KonqCopyToDirectoryMenu(QMenu *parent, KonqCopyToMainMenu *mainMenu, const QString &path)
- : QMenu(parent), m_mainMenu(mainMenu), m_path(path)
-{
- connect(this, &KonqCopyToDirectoryMenu::aboutToShow, this, &KonqCopyToDirectoryMenu::slotAboutToShow);
-}
-
-void KonqCopyToDirectoryMenu::slotAboutToShow()
-{
- clear();
- QAction *act = new QAction(m_mainMenu->menuType() == Copy
- ? i18nc("@title:menu", "Copy Here")
- : i18nc("@title:menu", "Move Here"), this);
- act->setData(QUrl::fromLocalFile(m_path));
- act->setEnabled(QFileInfo(m_path).isWritable());
- m_mainMenu->actionGroup().addAction(act);
- addAction(act);
-
- addSeparator(); // looks like Qt4 handles removing it automatically if it's last in the menu, nice.
-
- // List directory
- // All we need is sub folder names, their permissions, their icon.
- // KDirLister or KIO::listDir would fetch much more info, and would be async,
- // and we only care about local directories so we use QDir directly.
- QDir dir(m_path);
- const QStringList entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::LocaleAware);
- const QMimeDatabase db;
- const QMimeType dirMime = db.mimeTypeForName(QStringLiteral("inode/directory"));
- Q_FOREACH (const QString &subDir, entries) {
- QString subPath = m_path;
- if (!subPath.endsWith(QLatin1Char('/'))) {
- subPath.append(QLatin1Char('/'));
- }
- subPath += subDir;
- KonqCopyToDirectoryMenu *subMenu = new KonqCopyToDirectoryMenu(this, m_mainMenu, subPath);
- QString menuTitle(subDir);
- // Replace '&' by "&&" to make sure that '&' inside the directory name is displayed
- // correctly and not misinterpreted as an indicator for a keyboard shortcut
- subMenu->setTitle(menuTitle.replace(QLatin1Char('&'), QStringLiteral("&&")));
- const QString iconName = dirMime.iconName();
- subMenu->setIcon(QIcon::fromTheme(iconName));
- if (QFileInfo(subPath).isSymLink()) { // I hope this isn't too slow...
- QFont font = subMenu->menuAction()->font();
- font.setItalic(true);
- subMenu->menuAction()->setFont(font);
- }
- addMenu(subMenu);
- }
-}
diff --git a/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.h b/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.h
deleted file mode 100644
index 21ae6a8..0000000
--- a/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* This file is part of the KDE project
- Copyright 2008 David Faure <[email protected]>
-
- 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 ) version 3 or, at the discretion of KDE e.V.
- ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 KONQ_COPYTOMENU_H
-#define KONQ_COPYTOMENU_H
-
-#include <QUrl>
-
-#include <kfileitem.h>
-#include <libkonq_export.h>
-
-class QMenu;
-class KonqCopyToMenuPrivate;
-
-/**
- * This class adds "Copy To" and "Move To" submenus to a popupmenu.
- */
-class LIBKONQ_EXPORT KonqCopyToMenu
-{
-public:
- /**
- * Creates a KonqCopyToMenu instance, with a parent widget for the file dialog
- * and message boxes.
- * Note that this instance (and the widget) must stay alive for at least as
- * long as the popupmenu; it has the slots for the actions created by addActionsTo.
- * @param widget note that this is not the parent of KonqCopyToMenu itself.
- * @since 4.2
- */
- KonqCopyToMenu(QWidget *parentWidget);
-
- /**
- * Destructor
- */
- ~KonqCopyToMenu();
-
- /**
- * Sets the list of fileitems which the actions apply to.
- * Either call this or setUrls.
- */
- void setItems(const KFileItemList &items);
-
- /**
- * Sets the URLs which the actions apply to.
- * Either call this or setItems.
- */
- void setUrls(const QList<QUrl> &urls);
-
- /**
- * If setReadOnly(true) is called, the "Move To" submenu will not appear.
- */
- void setReadOnly(bool ro);
-
- /**
- * Generate the actions and submenus, and adds them to the @p menu.
- * All actions are created as children of the menu.
- */
- void addActionsTo(QMenu *menu);
-
-private:
- KonqCopyToMenuPrivate *const d;
-};
-
-#endif /* KONQ_COPYTOMENU_H */
diff --git a/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu_p.h b/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu_p.h
deleted file mode 100644
index 46c3b8e..0000000
--- a/containments/desktop/plugins/folder/internallibkonq/konq_copytomenu_p.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* This file is part of the KDE project
-
- Copyright 2008 David Faure <[email protected]>
-
- 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 ) version 3 or, at the discretion of KDE e.V.
- ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 <kconfiggroup.h>
-#include <QMenu>
-#include <QActionGroup>
-#include <QObject>
-#include <QUrl>
-
-class KonqCopyToMenuPrivate
-{
-public:
- KonqCopyToMenuPrivate(QWidget *parentWidget);
-
- QList<QUrl> m_urls;
- bool m_readOnly;
- QWidget *m_parentWidget;
-};
-
-enum MenuType { Copy, Move };
-
-// The main menu, shown when opening "Copy To" or "Move To"
-// It contains Home Folder, Root Folder, Browse, and recent destinations
-class KonqCopyToMainMenu : public QMenu
-{
- Q_OBJECT
-public:
- KonqCopyToMainMenu(QMenu *parent, KonqCopyToMenuPrivate *d, MenuType menuType);
-
- QActionGroup &actionGroup()
- {
- return m_actionGroup; // used by submenus
- }
- MenuType menuType() const
- {
- return m_menuType; // used by submenus
- }
-
-private Q_SLOTS:
- void slotAboutToShow();
- void slotBrowse();
- void slotTriggered(QAction *action);
-
-private:
- void copyOrMoveTo(const QUrl &dest);
-
-private:
- MenuType m_menuType;
- QActionGroup m_actionGroup;
- KonqCopyToMenuPrivate *d; // this isn't our own d pointer, it's the one for the public class
- KConfigGroup m_recentDirsGroup;
-};
-
-// The menu that lists a directory
-class KonqCopyToDirectoryMenu : public QMenu
-{
- Q_OBJECT
-public:
- KonqCopyToDirectoryMenu(QMenu *parent, KonqCopyToMainMenu *mainMenu, const QString &path);
-
-private Q_SLOTS:
- void slotAboutToShow();
-
-private:
- KonqCopyToMainMenu *m_mainMenu;
- QString m_path;
-};
diff --git a/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp b/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp
index 8ac077b..b15f6e9 100644
--- a/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp
+++ b/containments/desktop/plugins/folder/internallibkonq/konq_popupmenu.cpp
@@ -23,11 +23,11 @@
#include <KActionCollection>
#include <kfileitemlistproperties.h>
-#include "konq_copytomenu.h"
#include "kfileitemactions.h"
#include "kabstractfileitemactionplugin.h"
#include "kpropertiesdialog.h"
+#include <KFileCopyToMenu>
#include <klocalizedstring.h>
#include <kbookmarkmanager.h>
#include <kbookmarkdialog.h>
@@ -116,7 +116,7 @@ public:
QUrl m_sViewURL;
KFileItemListProperties m_popupItemProperties;
KFileItemActions m_menuActions;
- KonqCopyToMenu m_copyToMenu;
+ KFileCopyToMenu m_copyToMenu;
KBookmarkManager *m_bookmarkManager;
KActionCollection &m_actions;
QList<QAction *> m_ownActions;
@@ -162,10 +162,11 @@ void KonqPopupMenuPrivate::populate()
bool bTrashIncluded = false;
const KFileItemList lstItems = m_popupItemProperties.items();
- KFileItemList::const_iterator it = lstItems.constBegin();
- const KFileItemList::const_iterator kend = lstItems.constEnd();
- for (; it != kend; ++it) {
- const QUrl url = (*it).url();
+ QList<QUrl> 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;
}
@@ -430,7 +431,7 @@ void KonqPopupMenuPrivate::populate()
if (m_popupFlags & KonqPopupMenu::ShowUrlOperations &&
KConfigGroup(dolphin, "General").readEntry("ShowCopyMoveMenu", false)) {
- m_copyToMenu.setItems(lstItems);
+ m_copyToMenu.setUrls(lstUrls);
m_copyToMenu.setReadOnly(sMoving == false);
m_copyToMenu.addActionsTo(q);
q->addSeparator();