From: Peter Penz Date: Fri, 18 Apr 2008 19:43:16 +0000 (+0000) Subject: Consider the protocol and directory capabilities for file actions like Move To/Copy... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/7d0080868bade4b476c824817b5ec9b5993a3b46 Consider the protocol and directory capabilities for file actions like Move To/Copy To (note that this is just an initial version; adjustments must also be done for the global actions like Delete, Rename etc.) svn path=/trunk/KDE/kdebase/apps/; revision=798658 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e85d4d5b4..80353a268 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,6 +98,7 @@ set(dolphin_SRCS dolphinfileplacesview.cpp dolphinsettingsdialog.cpp draganddrophelper.cpp + fileitemcapabilities.cpp filterbar.cpp generalsettingspage.cpp generalviewsettingspage.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 41673e182..81194e42b 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -25,6 +25,7 @@ #include "dolphinview.h" #include "dolphinviewcontainer.h" #include "dolphin_generalsettings.h" +#include "fileitemcapabilities.h" #include #include @@ -54,6 +55,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const KFileItem& fileInfo, const KUrl& baseUrl) : m_mainWindow(parent), + m_capabilities(0), m_fileInfo(fileInfo), m_baseUrl(baseUrl), m_context(NoContext) @@ -67,6 +69,8 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, DolphinContextMenu::~DolphinContextMenu() { + delete m_capabilities; + m_capabilities = 0; } void DolphinContextMenu::open() @@ -193,6 +197,7 @@ void DolphinContextMenu::openItemContextMenu() // Insert 'Copy To' and 'Move To' sub menus if (DolphinSettings::instance().generalSettings()->showCopyMoveMenu()) { m_copyToMenu.setItems(m_selectedItems); + m_copyToMenu.setReadOnly(!capabilities().supportsMoving()); m_copyToMenu.addActionsTo(popup); popup->addSeparator(); } @@ -430,7 +435,7 @@ QAction* DolphinContextMenu::createPasteAction() 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()); + action->setEnabled(!pasteData.isEmpty() && capabilities().supportsWriting()); connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(pasteIntoFolder())); } else { action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); @@ -439,4 +444,12 @@ QAction* DolphinContextMenu::createPasteAction() return action; } +FileItemCapabilities& DolphinContextMenu::capabilities() +{ + if (m_capabilities == 0) { + m_capabilities = new FileItemCapabilities(m_selectedItems); + } + return *m_capabilities; +} + #include "dolphincontextmenu.moc" diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h index 7eb542b6b..8b623114c 100644 --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -34,6 +34,7 @@ class KMenu; class KFileItem; class QAction; class DolphinMainWindow; +class FileItemCapabilities; /** * @brief Represents the context menu which appears when doing a right @@ -111,6 +112,9 @@ private: QAction* createPasteAction(); +private: + FileItemCapabilities& capabilities(); + private: struct Entry { @@ -130,6 +134,7 @@ private: }; DolphinMainWindow* m_mainWindow; + FileItemCapabilities* m_capabilities; KFileItem m_fileInfo; KUrl m_baseUrl; KFileItemList m_selectedItems; diff --git a/src/fileitemcapabilities.cpp b/src/fileitemcapabilities.cpp new file mode 100644 index 000000000..5ec0797d6 --- /dev/null +++ b/src/fileitemcapabilities.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 * + ***************************************************************************/ + +#include "fileitemcapabilities.h" + +#include +#include + +#include + +FileItemCapabilities::FileItemCapabilities(const KFileItemList& items) : + m_supportsReading(true), + m_supportsDeleting(true), + m_supportsWriting(true), + m_supportsMoving(true), + m_isLocal(true) +{ + QFileInfo parentDirInfo; + foreach (KFileItem item, items) { + const KUrl url = item.url(); + m_isLocal = m_isLocal && url.isLocalFile(); + m_supportsReading = m_supportsReading && KProtocolManager::supportsReading(url); + m_supportsDeleting = m_supportsDeleting && KProtocolManager::supportsReading(url); + m_supportsWriting = m_supportsWriting && KProtocolManager::supportsWriting(url); + m_supportsMoving = m_supportsMoving && KProtocolManager::supportsMoving(url); + + // The following code has been taken from kdebase/apps/lib/konq/konq_popupmenu.cpp: + // For local files we can do better: check if we have write permission in parent directory + if (m_isLocal && (m_supportsDeleting || m_supportsMoving)) { + const QString directory = url.directory(); + if (parentDirInfo.filePath() != directory) { + parentDirInfo.setFile(directory); + } + if (!parentDirInfo.isWritable()) { + m_supportsDeleting = false; + m_supportsMoving = false; + } + } + } +} + +FileItemCapabilities::~FileItemCapabilities() +{ +} diff --git a/src/fileitemcapabilities.h b/src/fileitemcapabilities.h new file mode 100644 index 000000000..15d8383e9 --- /dev/null +++ b/src/fileitemcapabilities.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 * + ***************************************************************************/ + +#ifndef FILEITEMCAPABILITIES_H +#define FILEITEMCAPABILITIES_H + +class KFileItemList; + +/** + * @brief Provides information about the access capabilities of file items. + * + * As soon as one file item does not support a specific capability, it is + * marked as unsupported for all items. + */ +class FileItemCapabilities +{ +public: + FileItemCapabilities(const KFileItemList& items); + virtual ~FileItemCapabilities(); + bool supportsReading() const; + bool supportsDeleting() const; + bool supportsWriting() const; + bool supportsMoving() const; + +private: + bool m_supportsReading : 1; + bool m_supportsDeleting : 1; + bool m_supportsWriting : 1; + bool m_supportsMoving : 1; + bool m_isLocal : 1; +}; + +inline bool FileItemCapabilities::supportsReading() const +{ + return m_supportsReading; +} + +inline bool FileItemCapabilities::supportsDeleting() const +{ + return m_supportsDeleting; +} + +inline bool FileItemCapabilities::supportsWriting() const +{ + return m_supportsWriting; +} + +inline bool FileItemCapabilities::supportsMoving() const +{ + return m_supportsMoving; +} + +#endif