X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/9ed13b31b458bc4d41c7b1c5bbc472fce3554d8d..4eec2a77cfa8719f0cf7f6741c8cfa11b23ebf5b:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 2475c68bc..e825a5a61 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -43,29 +44,28 @@ #include #include +#include +#include #include +#include DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, KFileItem* fileInfo, - const KUrl& baseUrl, - ViewType viewType) : + const KUrl& baseUrl) : m_mainWindow(parent), m_fileInfo(fileInfo), m_baseUrl(baseUrl), - m_viewType(viewType), m_context(NoContext) { - if (viewType == ItemsView) { - // The context menu either accesses the URLs of the selected items - // or the items itself. To increase the performance both lists are cached. - DolphinView* view = m_mainWindow->activeView(); - m_selectedUrls = view->selectedUrls(); - m_selectedItems = view->selectedItems(); - } - else if (fileInfo != 0) { - m_selectedUrls.append(fileInfo->url()); - m_selectedItems.append(fileInfo); - } + // The context menu either accesses the URLs of the selected items + // or the items itself. To increase the performance both lists are cached. + DolphinView* view = m_mainWindow->activeView(); + m_selectedUrls = view->selectedUrls(); + m_selectedItems = view->selectedItems(); +} + +DolphinContextMenu::~DolphinContextMenu() +{ } void DolphinContextMenu::open() @@ -98,9 +98,6 @@ void DolphinContextMenu::open() } } -DolphinContextMenu::~DolphinContextMenu() -{ -} void DolphinContextMenu::openTrashContextMenu() { @@ -108,7 +105,7 @@ void DolphinContextMenu::openTrashContextMenu() KMenu* popup = new KMenu(m_mainWindow); - QAction* emptyTrashAction = new QAction(KIcon("user-trash"), i18n("Emtpy Trash"), popup); + QAction* emptyTrashAction = new QAction(KIcon("emptytrash"), i18n("Emtpy Trash"), popup); KConfig trashConfig("trashrc", KConfig::OnlyLocal); emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); popup->addAction(emptyTrashAction); @@ -159,9 +156,7 @@ void DolphinContextMenu::openItemContextMenu() Q_ASSERT(m_fileInfo != 0); KMenu* popup = new KMenu(m_mainWindow); - if (m_viewType == ItemsView) { - insertDefaultItemActions(popup); - } + insertDefaultItemActions(popup); popup->addSeparator(); @@ -176,15 +171,13 @@ void DolphinContextMenu::openItemContextMenu() const QList openWithActions = insertOpenWithItems(popup, openWithVector); // Insert 'Actions' sub menu - QVector actionsVector; + QVector actionsVector; const QList serviceActions = insertActionItems(popup, actionsVector); popup->addSeparator(); - if (m_viewType == ItemsView) { - // insert 'Properties...' entry - QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); - popup->addAction(propertiesAction); - } + // insert 'Properties...' entry + QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); + popup->addAction(propertiesAction); QAction* activatedAction = popup->exec(QCursor::pos()); @@ -204,7 +197,7 @@ void DolphinContextMenu::openItemContextMenu() else if (serviceActions.contains(activatedAction)) { // one of the 'Actions' items has been selected int id = serviceActions.indexOf(activatedAction); - KDEDesktopMimeType::executeService(m_selectedUrls, actionsVector[id]); + KDesktopFileActions::executeService(m_selectedUrls, actionsVector[id]); } else if (openWithActions.contains(activatedAction)) { // one of the 'Open With' items has been selected @@ -283,18 +276,20 @@ void DolphinContextMenu::openViewportContextMenu() void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) { Q_ASSERT(popup != 0); + const KActionCollection* collection = m_mainWindow->actionCollection(); // insert 'Cut', 'Copy' and 'Paste' - QAction* cutAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Cut)); - QAction* copyAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Copy)); - QAction* pasteAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste)); + QAction* cutAction = collection->action(KStandardAction::stdName(KStandardAction::Cut)); + QAction* copyAction = collection->action(KStandardAction::stdName(KStandardAction::Copy)); + QAction* pasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste)); + popup->addAction(cutAction); popup->addAction(copyAction); popup->addAction(pasteAction); popup->addSeparator(); // insert 'Rename' - QAction* renameAction = m_mainWindow->actionCollection()->action("rename"); + QAction* renameAction = collection->action("rename"); popup->addAction(renameAction); // insert 'Move to Trash' and (optionally) 'Delete' @@ -303,7 +298,7 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false); const KUrl& url = m_mainWindow->activeView()->url(); if (url.isLocalFile()) { - QAction* moveToTrashAction = m_mainWindow->actionCollection()->action("move_to_trash"); + QAction* moveToTrashAction = collection->action("move_to_trash"); popup->addAction(moveToTrashAction); } else { @@ -311,7 +306,7 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) } if (showDeleteCommand) { - QAction* deleteAction = m_mainWindow->actionCollection()->action("delete"); + QAction* deleteAction = collection->action("delete"); popup->addAction(deleteAction); } } @@ -386,7 +381,7 @@ QList DolphinContextMenu::insertOpenWithItems(KMenu* popup, } QList DolphinContextMenu::insertActionItems(KMenu* popup, - QVector& actionsVector) + QVector& actionsVector) { // Parts of the following code have been taken // from the class KonqOperations located in @@ -455,14 +450,14 @@ QList DolphinContextMenu::insertActionItems(KMenu* popup, actionsMenu->addMenu(menu); } - Q3ValueList userServices = - KDEDesktopMimeType::userDefinedServices(*dirIt + *entryIt, true); + Q3ValueList userServices = + KDesktopFileActions::userDefinedServices(*dirIt + *entryIt, true); - Q3ValueList::Iterator serviceIt; + Q3ValueList::Iterator serviceIt; for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) { - KDEDesktopMimeType::Service service = (*serviceIt); + KDesktopFileActions::Service service = (*serviceIt); if (!service.m_strIcon.isEmpty()) { - QAction* action = menu->addAction(SmallIcon(service.m_strIcon), + QAction* action = menu->addAction(KIcon(service.m_strIcon), service.m_strName); serviceActions << action; } @@ -536,3 +531,5 @@ bool DolphinContextMenu::containsEntry(const KMenu* menu, return false; } + +#include "dolphincontextmenu.moc"