- KPopupMenu* actionsMenu = new KPopupMenu();
-
- int actionsIndex = 0;
-
- QStringList dirs = KGlobal::dirs()->findDirs("data", "dolphin/servicemenus/");
-
- KPopupMenu* menu = 0;
- 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...
- const KFileItemList* list = m_dolphinView->selectedItems();
- assert(list != 0);
-
- KFileItemListIterator mimeIt(*list);
- KFileItem* item = 0;
- insert = true;
- while (insert && ((item = mimeIt.current()) != 0)) {
- insert = !item->isDir();
- ++mimeIt;
- }
- }
-
- 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.
- const KFileItemList* list = m_dolphinView->selectedItems();
- assert(list != 0);
-
- KFileItemListIterator mimeIt(*list);
- KFileItem* item = 0;
- insert = true;
- while (insert && ((item = mimeIt.current()) != 0)) {
- const QString mimeType((*mimeIt)->mimetype());
- const QString mimeGroup(mimeType.left(mimeType.find('/')));
-
- insert = (*it == mimeType) ||
- ((*it).right(1) == "*") &&
- ((*it).left((*it).find('/')) == mimeGroup);
- ++mimeIt;
- }
- }
-
- if (insert) {
- menu = actionsMenu;
-
- const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
- if (!submenuName.isEmpty()) {
- menu = new KPopupMenu();
- 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()) {
- menu->insertItem(SmallIcon(service.m_strIcon),
- service.m_strName,
- actionsIDStart + actionsIndex);
- }
- else {
- menu->insertItem(service.m_strName,
- actionsIDStart + actionsIndex);
- }
- actionsVector.append(service);
- ++actionsIndex;
- }
- }
- }
- }
- }
+ Q_ASSERT(popup != 0);
+ const KActionCollection* collection = m_mainWindow->actionCollection();
+
+ // insert 'Cut', 'Copy' and 'Paste'
+ QAction* cutAction = collection->action(KStandardAction::name(KStandardAction::Cut));
+ QAction* copyAction = collection->action(KStandardAction::name(KStandardAction::Copy));
+ QAction* pasteAction = createPasteAction();
+
+ popup->addAction(cutAction);
+ popup->addAction(copyAction);
+ popup->addAction(pasteAction);
+ popup->addSeparator();
+
+ // insert 'Rename'
+ QAction* renameAction = collection->action("rename");
+ popup->addAction(renameAction);
+
+ // insert 'Move to Trash' and (optionally) 'Delete'
+ KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
+ KConfigGroup configGroup(globalConfig, "KDE");
+ bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false);
+
+ const KUrl& url = m_mainWindow->activeViewContainer()->url();
+ if (url.isLocalFile()) {
+ QAction* moveToTrashAction = collection->action("move_to_trash");
+ popup->addAction(moveToTrashAction);
+ } else {
+ showDeleteCommand = true;