]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Use KonqMenuActions to add the "open with" actions to the popupmenu, to avoid this...
authorDavid Faure <faure@kde.org>
Mon, 2 Jun 2008 16:36:29 +0000 (16:36 +0000)
committerDavid Faure <faure@kde.org>
Mon, 2 Jun 2008 16:36:29 +0000 (16:36 +0000)
which brought back bug 121728 ('&' in application name treated as accelerator)

svn path=/trunk/KDE/kdebase/apps/; revision=815838

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h

index a9a5ffefe34af5b8be6a56532185ac7b1a706843..cf71bc26f6ab285dc99ee97dd218f8f62620e2cc 100644 (file)
@@ -184,18 +184,16 @@ void DolphinContextMenu::openItemContextMenu()
                                              i18nc("@action:inmenu Add selected folder to places", "Add to Places"));
     }
 
-    // Insert 'Open With...' sub menu
-    // TODO: port to menuActions.addOpenWithActionsTo(popup);
-    QVector<KService::Ptr> openWithVector;
-    const QList<QAction*> openWithActions = insertOpenWithItems(popup, openWithVector);
-
     KonqPopupMenuInformation popupInfo;
     popupInfo.setItems(m_selectedItems);
     popupInfo.setParentWidget(m_mainWindow);
-
-    // Insert 'Actions' sub menu
     KonqMenuActions menuActions;
     menuActions.setPopupMenuInfo(popupInfo);
+
+    // Insert 'Open With...' action or sub menu
+    menuActions.addOpenWithActionsTo(popup, "DesktopEntryName != 'dolphin'");
+
+    // Insert 'Actions' sub menu
     if (menuActions.addActionsTo(popup)) {
         popup->addSeparator();
     }
@@ -220,19 +218,8 @@ void DolphinContextMenu::openItemContextMenu()
             DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
                                                                 selectedUrl);
         }
-    } else if (openWithActions.contains(activatedAction)) {
-        // one of the 'Open With' items has been selected
-        if (openWithActions.last() == activatedAction) {
-            // the item 'Other...' has been selected
-            KRun::displayOpenWithDialog(m_selectedUrls, m_mainWindow);
-        } else {
-            int id = openWithActions.indexOf(activatedAction);
-            KService::Ptr servicePtr = openWithVector[id];
-            KRun::run(*servicePtr, m_selectedUrls, m_mainWindow);
-        }
     }
 
-    openWithVector.clear();
     popup->deleteLater();
 }
 
@@ -328,90 +315,6 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
     }
 }
 
-QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
-        QVector<KService::Ptr>& openWithVector)
-{
-    // 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>)
-
-    // 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.
-    bool insertOpenWithItems = true;
-    const QString contextMimeType(m_fileInfo.mimetype());
-
-    QListIterator<KFileItem> mimeIt(m_selectedItems);
-    while (insertOpenWithItems && mimeIt.hasNext()) {
-        KFileItem item = mimeIt.next();
-        insertOpenWithItems = (contextMimeType == item.mimetype());
-    }
-
-    QList<QAction*> openWithActions;
-    if (insertOpenWithItems) {
-        // fill the 'Open with' sub menu with application types
-        const KMimeType::Ptr mimePtr = KMimeType::findByUrl(m_fileInfo.url());
-        KService::List offers = KMimeTypeTrader::self()->query(mimePtr->name(),
-                                "Application",
-                                "Type == 'Application'");
-        if (offers.count() > 0) {
-            KService::List::Iterator it;
-            KMenu* openWithMenu = new KMenu(i18nc("@title:menu", "Open With"));
-            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)) {
-                    const KIcon icon((*it)->icon());
-                    QAction* action = openWithMenu->addAction(icon, appName);
-                    openWithVector.append(*it);
-                    openWithActions << action;
-                }
-            }
-
-            openWithMenu->addSeparator();
-            QAction* action = openWithMenu->addAction(i18nc("@action:inmenu Open With", "&Other..."));
-
-            openWithActions << action;
-            popup->addMenu(openWithMenu);
-        } else {
-            // No applications are registered, hence just offer
-            // a "Open With..." item instead of a sub menu containing
-            // only one entry.
-            QAction* action = popup->addAction(i18nc("@title:menu", "Open With..."));
-            openWithActions << action;
-        }
-    } else {
-        // At least one of the selected items has a different MIME type. In this case
-        // just show a disabled "Open With..." entry.
-        QAction* action = popup->addAction(i18nc("@title:menu", "Open With..."));
-        action->setEnabled(false);
-    }
-
-    return openWithActions;
-}
-
-bool DolphinContextMenu::containsEntry(const KMenu* menu,
-                                       const QString& entryName) const
-{
-    Q_ASSERT(menu != 0);
-
-    const QList<QAction*> list = menu->actions();
-    const uint count = list.count();
-    for (uint i = 0; i < count; ++i) {
-        const QAction* action = list.at(i);
-        if (action->text() == entryName) {
-            return true;
-        }
-    }
-
-    return false;
-}
-
 void DolphinContextMenu::addShowMenubarAction(KMenu* menu)
 {
     KAction* showMenuBar = m_mainWindow->showMenuBarAction();
index b3779c9ab71bed32aae26d4e4c270f5024d5ce47..4d8fe0c4379b01053f2e7d2c778bbc0e29278ff8 100644 (file)
@@ -79,26 +79,6 @@ private:
 
     void insertDefaultItemActions(KMenu* popup);
 
-    /**
-     * Inserts the 'Open With...' submenu to \a popup.
-     * @param popup          Menu where the 'Open With...' sub menu should
-     *                       be added.
-     * @param openWithVector Output parameter which contains all 'Open with...'
-     *                       services.
-     * @return               Identifier of the first 'Open With...' entry.
-     *                       All succeeding identifiers have an increased value of 1
-     *                       to the predecessor.
-     */
-    QList<QAction*> insertOpenWithItems(KMenu* popup,
-                                        QVector<KService::Ptr>& openWithVector);
-
-    /**
-     * Returns true, if 'menu' contains already
-     * an entry with the name 'entryName'.
-     */
-    bool containsEntry(const KMenu* menu,
-                       const QString& entryName) const;
-
     /**
      * Adds the "Show menubar" action to the menu if the
      * menubar is hidden.