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
This commit is contained in:
Peter Penz 2008-04-18 19:43:16 +00:00
parent 01f53f01b4
commit 7d0080868b
5 changed files with 149 additions and 1 deletions

View file

@ -98,6 +98,7 @@ set(dolphin_SRCS
dolphinfileplacesview.cpp
dolphinsettingsdialog.cpp
draganddrophelper.cpp
fileitemcapabilities.cpp
filterbar.cpp
generalsettingspage.cpp
generalviewsettingspage.cpp

View file

@ -25,6 +25,7 @@
#include "dolphinview.h"
#include "dolphinviewcontainer.h"
#include "dolphin_generalsettings.h"
#include "fileitemcapabilities.h"
#include <kactioncollection.h>
#include <kfileplacesmodel.h>
@ -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"

View file

@ -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;

View file

@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
* *
* 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 <kfileitem.h>
#include <kprotocolmanager.h>
#include <QFileInfo>
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()
{
}

View file

@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
* *
* 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