- 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;
- }
- }
- }
- }
- }
+ QAction* action = nullptr;
+ const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
+ if (isDir && (m_selectedItems.count() == 1)) {
+ const QMimeData *mimeData = QApplication::clipboard()->mimeData();
+ bool canPaste;
+ const QString text = KIO::pasteActionText(mimeData, &canPaste, m_fileInfo);
+ action = new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), text, this);
+ action->setEnabled(canPaste);
+ connect(action, &QAction::triggered, m_mainWindow, &DolphinMainWindow::pasteIntoFolder);
+ } else {
+ action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));