2006-11-21 06:02:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
|
|
|
|
* Cvetoslav Ludmiloff *
|
|
|
|
* *
|
|
|
|
* 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., *
|
2006-12-08 21:24:08 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
2006-11-21 06:02:05 +00:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "dolphincontextmenu.h"
|
|
|
|
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <kbookmarkmanager.h>
|
|
|
|
#include <kbookmark.h>
|
2006-11-22 11:34:19 +00:00
|
|
|
#include <kmimetypetrader.h>
|
2006-11-21 06:02:05 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <krun.h>
|
|
|
|
#include <qdir.h>
|
|
|
|
//Added by qt3to4:
|
|
|
|
#include <Q3ValueList>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kaction.h>
|
|
|
|
#include <kpropertiesdialog.h>
|
|
|
|
#include <kdesktopfile.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <kio/netaccess.h>
|
2006-11-22 08:22:45 +00:00
|
|
|
#include <kmenu.h>
|
2006-12-19 02:26:06 +00:00
|
|
|
#include <kstandardaction.h>
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-11-29 00:02:19 +00:00
|
|
|
#include "dolphinmainwindow.h"
|
2006-11-21 06:02:05 +00:00
|
|
|
#include "dolphinview.h"
|
|
|
|
#include "editbookmarkdialog.h"
|
|
|
|
#include "dolphinsettings.h"
|
|
|
|
|
|
|
|
|
|
|
|
DolphinContextMenu::DolphinContextMenu(DolphinView* parent,
|
|
|
|
KFileItem* fileInfo,
|
|
|
|
const QPoint& pos) :
|
|
|
|
m_dolphinView(parent),
|
|
|
|
m_fileInfo(fileInfo),
|
|
|
|
m_pos(pos)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinContextMenu::open()
|
|
|
|
{
|
|
|
|
if (m_fileInfo == 0) {
|
|
|
|
openViewportContextMenu();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
openItemContextMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DolphinContextMenu::~DolphinContextMenu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinContextMenu::openViewportContextMenu()
|
|
|
|
{
|
|
|
|
// Parts of the following code have been taken
|
|
|
|
// from the class KonqOperations located in
|
|
|
|
// libqonq/konq_operations.h of Konqueror.
|
|
|
|
// (Copyright (C) 2000 David Faure <faure@kde.org>)
|
|
|
|
|
|
|
|
assert(m_fileInfo == 0);
|
|
|
|
|
2006-11-22 08:12:45 +00:00
|
|
|
KMenu* popup = new KMenu(m_dolphinView);
|
2006-11-29 00:02:19 +00:00
|
|
|
DolphinMainWindow *dolphin = m_dolphinView->mainWindow();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
// setup 'Create New' menu
|
2006-11-22 08:12:45 +00:00
|
|
|
KMenu* createNewMenu = new KMenu();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* createFolderAction = dolphin->actionCollection()->action("create_folder");
|
2006-11-21 06:02:05 +00:00
|
|
|
if (createFolderAction != 0) {
|
2006-12-04 21:51:17 +00:00
|
|
|
createNewMenu->addAction(createFolderAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createNewMenu->insertSeparator();
|
|
|
|
|
2006-12-10 21:01:38 +00:00
|
|
|
QLinkedListIterator<QAction*> fileGrouptIt(dolphin->fileGroupActions());
|
|
|
|
while (fileGrouptIt.hasNext()) {
|
|
|
|
createNewMenu->addAction(fileGrouptIt.next());
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: not used yet. See documentation of Dolphin::linkGroupActions()
|
|
|
|
// and Dolphin::linkToDeviceActions() in the header file for details.
|
|
|
|
//
|
|
|
|
//createNewMenu->insertSeparator();
|
|
|
|
//
|
2006-11-29 00:02:19 +00:00
|
|
|
//QPtrListIterator<KAction> linkGroupIt(dolphin->linkGroupActions());
|
2006-11-21 06:02:05 +00:00
|
|
|
//while ((action = linkGroupIt.current()) != 0) {
|
|
|
|
// action->plug(createNewMenu);
|
|
|
|
// ++linkGroupIt;
|
|
|
|
//}
|
|
|
|
//
|
2006-11-22 08:22:45 +00:00
|
|
|
//KMenu* linkToDeviceMenu = new KMenu();
|
2006-11-29 00:02:19 +00:00
|
|
|
//QPtrListIterator<KAction> linkToDeviceIt(dolphin->linkToDeviceActions());
|
2006-11-21 06:02:05 +00:00
|
|
|
//while ((action = linkToDeviceIt.current()) != 0) {
|
|
|
|
// action->plug(linkToDeviceMenu);
|
|
|
|
// ++linkToDeviceIt;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//createNewMenu->insertItem(i18n("Link to Device"), linkToDeviceMenu);
|
|
|
|
|
|
|
|
popup->insertItem(SmallIcon("filenew"), i18n("Create New"), createNewMenu);
|
|
|
|
popup->insertSeparator();
|
|
|
|
|
2006-12-19 02:26:06 +00:00
|
|
|
QAction* pasteAction = dolphin->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
|
2006-12-04 21:51:17 +00:00
|
|
|
popup->addAction(pasteAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
// setup 'View Mode' menu
|
2006-11-22 08:12:45 +00:00
|
|
|
KMenu* viewModeMenu = new KMenu();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* iconsMode = dolphin->actionCollection()->action("icons");
|
|
|
|
viewModeMenu->addAction(iconsMode);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* detailsMode = dolphin->actionCollection()->action("details");
|
|
|
|
viewModeMenu->addAction(detailsMode);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* previewsMode = dolphin->actionCollection()->action("previews");
|
|
|
|
viewModeMenu->addAction(previewsMode);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
popup->insertItem(i18n("View Mode"), viewModeMenu);
|
|
|
|
popup->insertSeparator();
|
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
|
2006-11-21 06:02:05 +00:00
|
|
|
popup->insertSeparator();
|
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *propertiesAction = popup->addAction(i18n("Properties..."));
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *activatedAction = popup->exec(m_pos);
|
|
|
|
if (activatedAction == propertiesAction) {
|
2006-11-29 00:02:19 +00:00
|
|
|
new KPropertiesDialog(dolphin->activeView()->url());
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
2006-11-22 11:34:19 +00:00
|
|
|
else if (activatedAction == bookmarkAction) {
|
2006-11-29 00:02:19 +00:00
|
|
|
const KUrl& url = dolphin->activeView()->url();
|
2006-11-21 06:02:05 +00:00
|
|
|
KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add folder as bookmark"),
|
2006-11-22 08:22:45 +00:00
|
|
|
url.fileName(),
|
2006-11-21 06:02:05 +00:00
|
|
|
url,
|
|
|
|
"bookmark");
|
|
|
|
if (!bookmark.isNull()) {
|
|
|
|
KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager();
|
|
|
|
KBookmarkGroup root = manager->root();
|
|
|
|
root.addBookmark(manager, bookmark);
|
|
|
|
manager->emitChanged(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
popup->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinContextMenu::openItemContextMenu()
|
|
|
|
{
|
|
|
|
// Parts of the following code have been taken
|
|
|
|
// from the class KonqOperations located in
|
|
|
|
// libqonq/konq_operations.h of Konqueror.
|
|
|
|
// (Copyright (C) 2000 David Faure <faure@kde.org>)
|
|
|
|
|
|
|
|
assert(m_fileInfo != 0);
|
|
|
|
|
2006-11-22 08:12:45 +00:00
|
|
|
KMenu* popup = new KMenu(m_dolphinView);
|
2006-11-29 00:02:19 +00:00
|
|
|
DolphinMainWindow* dolphin = m_dolphinView->mainWindow();
|
2006-11-22 17:13:11 +00:00
|
|
|
const KUrl::List urls = m_dolphinView->selectedUrls();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
// insert 'Cut', 'Copy' and 'Paste'
|
2006-12-19 02:56:16 +00:00
|
|
|
const KStandardAction::StandardAction actionNames[] = { KStandardAction::Cut, KStandardAction::Copy, KStandardAction::Paste };
|
|
|
|
const int count = sizeof(actionNames) / sizeof(KStandardAction::StandardAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
2006-12-19 02:26:06 +00:00
|
|
|
QAction* action = dolphin->actionCollection()->action(KStandardAction::stdName(actionNames[i]));
|
2006-12-04 21:51:17 +00:00
|
|
|
if (action)
|
|
|
|
popup->addAction(action);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
popup->insertSeparator();
|
|
|
|
|
|
|
|
// insert 'Rename'
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* renameAction = dolphin->actionCollection()->action("rename");
|
|
|
|
popup->addAction(renameAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-11-22 17:13:11 +00:00
|
|
|
// insert 'Move to Trash' for local Urls, otherwise insert 'Delete'
|
2006-11-29 00:02:19 +00:00
|
|
|
const KUrl& url = dolphin->activeView()->url();
|
2006-11-21 06:02:05 +00:00
|
|
|
if (url.isLocalFile()) {
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* moveToTrashAction = dolphin->actionCollection()->action("move_to_trash");
|
|
|
|
popup->addAction(moveToTrashAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* deleteAction = dolphin->actionCollection()->action("delete");
|
|
|
|
popup->addAction(deleteAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// insert 'Bookmark this folder...' entry
|
|
|
|
// urls is a list of selected items, so insert boolmark menu if
|
|
|
|
// urls contains only one item, i.e. no multiple selection made
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *bookmarkAction = 0;
|
2006-11-21 06:02:05 +00:00
|
|
|
if (m_fileInfo->isDir() && (urls.count() == 1)) {
|
2006-11-22 11:34:19 +00:00
|
|
|
bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
popup->insertSeparator();
|
|
|
|
|
|
|
|
// Insert 'Open With...' sub menu
|
|
|
|
Q3ValueVector<KService::Ptr> openWithVector;
|
2006-11-22 11:34:19 +00:00
|
|
|
const QList<QAction*> openWithActions = insertOpenWithItems(popup, openWithVector);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
// Insert 'Actions' sub menu
|
|
|
|
Q3ValueVector<KDEDesktopMimeType::Service> actionsVector;
|
2006-11-22 11:34:19 +00:00
|
|
|
const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
// insert 'Properties...' entry
|
|
|
|
popup->insertSeparator();
|
2006-12-04 21:51:17 +00:00
|
|
|
QAction* propertiesAction = dolphin->actionCollection()->action("properties");
|
|
|
|
popup->addAction(propertiesAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *activatedAction = popup->exec(m_pos);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-11-22 12:22:41 +00:00
|
|
|
if (bookmarkAction!=0 && activatedAction == bookmarkAction) {
|
2006-11-22 17:13:11 +00:00
|
|
|
const KUrl selectedUrl(m_fileInfo->url());
|
2006-11-21 06:02:05 +00:00
|
|
|
KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add folder as bookmark"),
|
2006-11-22 17:13:11 +00:00
|
|
|
selectedUrl.fileName(),
|
|
|
|
selectedUrl,
|
2006-11-21 06:02:05 +00:00
|
|
|
"bookmark");
|
|
|
|
if (!bookmark.isNull()) {
|
|
|
|
KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager();
|
|
|
|
KBookmarkGroup root = manager->root();
|
|
|
|
root.addBookmark(manager, bookmark);
|
|
|
|
manager->emitChanged(root);
|
|
|
|
}
|
|
|
|
}
|
2006-11-22 11:34:19 +00:00
|
|
|
else if (serviceActions.contains(activatedAction)) {
|
2006-11-21 06:02:05 +00:00
|
|
|
// one of the 'Actions' items has been selected
|
2006-11-22 11:34:19 +00:00
|
|
|
int id = serviceActions.indexOf(activatedAction);
|
|
|
|
KDEDesktopMimeType::executeService(urls, actionsVector[id]);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
2006-11-22 11:34:19 +00:00
|
|
|
else if (openWithActions.contains(activatedAction)) {
|
2006-11-21 06:02:05 +00:00
|
|
|
// one of the 'Open With' items has been selected
|
2006-11-22 11:34:19 +00:00
|
|
|
if (openWithActions.last()==activatedAction) {
|
2006-11-21 06:02:05 +00:00
|
|
|
// the item 'Other...' has been selected
|
2006-11-22 11:34:19 +00:00
|
|
|
KRun::displayOpenWithDialog(urls, m_dolphinView);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-11-22 11:34:19 +00:00
|
|
|
int id = openWithActions.indexOf(activatedAction);
|
|
|
|
KService::Ptr servicePtr = openWithVector[id];
|
|
|
|
KRun::run(*servicePtr, urls, m_dolphinView);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
openWithVector.clear();
|
|
|
|
actionsVector.clear();
|
|
|
|
popup->deleteLater();
|
|
|
|
}
|
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
|
|
|
|
Q3ValueVector<KService::Ptr>& openWithVector)
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
|
|
|
// Prepare 'Open With' sub menu. Usually a sub menu is created, where all applications
|
|
|
|
// are listed which are registered to open the item. As last entry "Other..." will be
|
|
|
|
// attached which allows to select a custom application. If no applications are registered
|
|
|
|
// no sub menu is created at all, only "Open With..." will be offered.
|
2006-12-02 21:51:36 +00:00
|
|
|
const KFileItemList list = m_dolphinView->selectedItems();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
bool insertOpenWithItems = true;
|
|
|
|
const QString contextMimeType(m_fileInfo->mimetype());
|
2006-12-02 21:51:36 +00:00
|
|
|
QListIterator<KFileItem*> mimeIt(list);
|
2006-11-22 11:34:19 +00:00
|
|
|
while (insertOpenWithItems && mimeIt.hasNext()) {
|
|
|
|
KFileItem* item = mimeIt.next();
|
2006-11-21 06:02:05 +00:00
|
|
|
insertOpenWithItems = (contextMimeType == item->mimetype());
|
|
|
|
}
|
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QList<QAction*> openWithActions;
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
if (insertOpenWithItems) {
|
|
|
|
// fill the 'Open with' sub menu with application types
|
2006-11-22 11:34:19 +00:00
|
|
|
const KMimeType::Ptr mimePtr = KMimeType::findByUrl(m_fileInfo->url());
|
|
|
|
KService::List offers = KMimeTypeTrader::self()->query(mimePtr->name(),
|
|
|
|
"Application",
|
|
|
|
"Type == 'Application'");
|
2006-11-21 06:02:05 +00:00
|
|
|
if (offers.count() > 0) {
|
2006-11-22 11:34:19 +00:00
|
|
|
KService::List::Iterator it;
|
2006-11-22 08:12:45 +00:00
|
|
|
KMenu* openWithMenu = new KMenu();
|
2006-11-21 06:02:05 +00:00
|
|
|
for(it = offers.begin(); it != offers.end(); ++it) {
|
|
|
|
// The offer list from the KTrader returns duplicate
|
|
|
|
// application entries. Although this seems to be a configuration
|
|
|
|
// problem outside the scope of Dolphin, duplicated entries just
|
|
|
|
// will be skipped here.
|
|
|
|
const QString appName((*it)->name());
|
|
|
|
if (!containsEntry(openWithMenu, appName)) {
|
2007-01-03 20:24:55 +00:00
|
|
|
const KIcon icon((*it)->icon());
|
|
|
|
QAction *action = openWithMenu->addAction(icon, appName);
|
2006-11-21 06:02:05 +00:00
|
|
|
openWithVector.append(*it);
|
2006-11-22 11:34:19 +00:00
|
|
|
openWithActions << action;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
openWithMenu->insertSeparator();
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *action = openWithMenu->addAction(i18n("&Other..."));
|
|
|
|
openWithActions << action;
|
2006-11-21 06:02:05 +00:00
|
|
|
popup->insertItem(i18n("Open With"), openWithMenu);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No applications are registered, hence just offer
|
|
|
|
// a "Open With..." item instead of a sub menu containing
|
|
|
|
// only one entry.
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *action = popup->addAction(i18n("Open With..."));
|
|
|
|
openWithActions << action;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// At least one of the selected items has a different MIME type. In this case
|
|
|
|
// just show a disabled "Open With..." entry.
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *action = popup->addAction(i18n("Open With..."));
|
|
|
|
action->setEnabled(false);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
return openWithActions;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QList<QAction*> DolphinContextMenu::insertActionItems(KMenu* popup,
|
|
|
|
Q3ValueVector<KDEDesktopMimeType::Service>& actionsVector)
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2006-11-22 08:12:45 +00:00
|
|
|
KMenu* actionsMenu = new KMenu();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-11-22 11:34:19 +00:00
|
|
|
QList<QAction*> serviceActions;
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
QStringList dirs = KGlobal::dirs()->findDirs("data", "dolphin/servicemenus/");
|
|
|
|
|
2006-11-22 08:12:45 +00:00
|
|
|
KMenu* menu = 0;
|
2006-11-21 06:02:05 +00:00
|
|
|
for (QStringList::ConstIterator dirIt = dirs.begin(); dirIt != dirs.end(); ++dirIt) {
|
|
|
|
QDir dir(*dirIt);
|
|
|
|
QStringList entries = dir.entryList("*.desktop", QDir::Files);
|
|
|
|
|
|
|
|
for (QStringList::ConstIterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt) {
|
|
|
|
KSimpleConfig cfg(*dirIt + *entryIt, true);
|
|
|
|
cfg.setDesktopGroup();
|
|
|
|
if ((cfg.hasKey("Actions") || cfg.hasKey("X-KDE-GetActionMenu")) && cfg.hasKey("ServiceTypes")) {
|
|
|
|
const QStringList types = cfg.readListEntry("ServiceTypes");
|
|
|
|
for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it) {
|
|
|
|
// check whether the mime type is equal or whether the
|
|
|
|
// mimegroup (e. g. image/*) is supported
|
|
|
|
|
|
|
|
bool insert = false;
|
|
|
|
if ((*it) == "all/allfiles") {
|
|
|
|
// The service type is valid for all files, but not for directories.
|
|
|
|
// Check whether the selected items only consist of files...
|
2006-12-02 21:51:36 +00:00
|
|
|
const KFileItemList list = m_dolphinView->selectedItems();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-02 21:51:36 +00:00
|
|
|
QListIterator<KFileItem*> mimeIt(list);
|
2006-11-21 06:02:05 +00:00
|
|
|
insert = true;
|
2006-11-22 11:34:19 +00:00
|
|
|
while (insert && mimeIt.hasNext()) {
|
|
|
|
KFileItem* item = mimeIt.next();
|
2006-11-21 06:02:05 +00:00
|
|
|
insert = !item->isDir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!insert) {
|
|
|
|
// Check whether the MIME types of all selected files match
|
|
|
|
// to the mimetype of the service action. As soon as one MIME
|
|
|
|
// type does not match, no service menu is shown at all.
|
2006-12-02 21:51:36 +00:00
|
|
|
const KFileItemList list = m_dolphinView->selectedItems();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-02 21:51:36 +00:00
|
|
|
QListIterator<KFileItem*> mimeIt(list);
|
2006-11-21 06:02:05 +00:00
|
|
|
insert = true;
|
2006-11-22 11:34:19 +00:00
|
|
|
while (insert && mimeIt.hasNext()) {
|
|
|
|
KFileItem* item = mimeIt.next();
|
|
|
|
const QString mimeType(item->mimetype());
|
2006-12-04 19:51:53 +00:00
|
|
|
const QString mimeGroup(mimeType.left(mimeType.indexOf('/')));
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
insert = (*it == mimeType) ||
|
|
|
|
((*it).right(1) == "*") &&
|
2006-12-04 19:51:53 +00:00
|
|
|
((*it).left((*it).indexOf('/')) == mimeGroup);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (insert) {
|
|
|
|
menu = actionsMenu;
|
|
|
|
|
|
|
|
const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
|
|
|
|
if (!submenuName.isEmpty()) {
|
2006-11-22 08:12:45 +00:00
|
|
|
menu = new KMenu();
|
2006-11-21 06:02:05 +00:00
|
|
|
actionsMenu->insertItem(submenuName, menu, submenuID);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q3ValueList<KDEDesktopMimeType::Service> userServices =
|
|
|
|
KDEDesktopMimeType::userDefinedServices(*dirIt + *entryIt, true);
|
|
|
|
|
|
|
|
Q3ValueList<KDEDesktopMimeType::Service>::Iterator serviceIt;
|
|
|
|
for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) {
|
|
|
|
KDEDesktopMimeType::Service service = (*serviceIt);
|
|
|
|
if (!service.m_strIcon.isEmpty()) {
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *action = menu->addAction(SmallIcon(service.m_strIcon),
|
|
|
|
service.m_strName);
|
|
|
|
serviceActions << action;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *action = menu->addAction(service.m_strName);
|
|
|
|
serviceActions << action;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
actionsVector.append(service);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const int itemsCount = actionsMenu->count();
|
|
|
|
if (itemsCount == 0) {
|
|
|
|
// no actions are available at all, hence show the "Actions"
|
|
|
|
// submenu disabled
|
|
|
|
actionsMenu->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemsCount == 1) {
|
|
|
|
// Exactly one item is available. Instead of showing a sub menu with
|
|
|
|
// only one item, show the item directly in the root menu.
|
|
|
|
if (menu == actionsMenu) {
|
|
|
|
// The item is an action, hence show the action in the root menu.
|
|
|
|
const int id = actionsMenu->idAt(0);
|
|
|
|
const QString text(actionsMenu->text(id));
|
2006-11-22 11:34:19 +00:00
|
|
|
QIcon iconSet = actionsMenu->iconSet(id);
|
|
|
|
if (iconSet.isNull()) {
|
|
|
|
QAction *action = popup->addAction(text);
|
|
|
|
serviceActions.clear();
|
|
|
|
serviceActions << action;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-11-22 11:34:19 +00:00
|
|
|
QAction *action = popup->addAction(iconSet, text);
|
|
|
|
serviceActions.clear();
|
|
|
|
serviceActions << action;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The item is a sub menu, hence show the sub menu in the root menu.
|
|
|
|
popup->insertItem(actionsMenu->text(submenuID), menu);
|
|
|
|
}
|
|
|
|
actionsMenu->deleteLater();
|
|
|
|
actionsMenu = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
popup->insertItem(i18n("Actions"), actionsMenu);
|
|
|
|
}
|
2006-11-22 11:34:19 +00:00
|
|
|
|
|
|
|
return serviceActions;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
2006-11-22 08:12:45 +00:00
|
|
|
bool DolphinContextMenu::containsEntry(const KMenu* menu,
|
2006-11-21 06:02:05 +00:00
|
|
|
const QString& entryName) const
|
|
|
|
{
|
|
|
|
assert(menu != 0);
|
|
|
|
|
|
|
|
const uint count = menu->count();
|
|
|
|
for (uint i = 0; i < count; ++i) {
|
|
|
|
const int id = menu->idAt(i);
|
|
|
|
if (menu->text(id) == entryName) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|