Use KonqMenuActions to add the "open with" actions to the popupmenu, to avoid this independent reimplementation,

which brought back bug 121728 ('&' in application name treated as accelerator)

svn path=/trunk/KDE/kdebase/apps/; revision=815838
This commit is contained in:
David Faure 2008-06-02 16:36:29 +00:00
parent 927a621f0e
commit d6e0d332e1
2 changed files with 5 additions and 122 deletions

View 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();

View 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.