[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/apps/lib/konq
From: David Faure <faure () kde ! org>
Date: 2009-03-09 18:52:49
Message-ID: 1236624769.715185.1838.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 937490 by dfaure:
Refactor a bit in order to be able to provide fredrikh with KAction* preferredOpenWithAction().
M +35 -13 konq_menuactions.cpp
M +10 -0 konq_menuactions.h
M +5 -1 konq_menuactions_p.h
--- trunk/KDE/kdebase/apps/lib/konq/konq_menuactions.cpp #937489:937490
@@ -400,12 +400,13 @@
return userItemCount;
}
-void KonqMenuActions::addOpenWithActionsTo(QMenu* topMenu, const QString& traderConstraint)
+
+KService::List KonqMenuActionsPrivate::associatedApplications(const QString& traderConstraint)
{
if (!KAuthorized::authorizeKAction("openwith"))
- return;
+ return KService::List();
- const KFileItemList items = d->m_info.items();
+ const KFileItemList items = m_info.items();
QStringList mimeTypeList;
KFileItemList::const_iterator kit = items.constBegin();
const KFileItemList::const_iterator kend = items.constEnd();
@@ -467,10 +468,16 @@
++it;
}
}
+ return offers;
+}
+void KonqMenuActions::addOpenWithActionsTo(QMenu* topMenu, const QString& traderConstraint)
+{
+ const KService::List offers = d->associatedApplications(traderConstraint);
//// Ok, we have everything, now insert
+ const KFileItemList items = d->m_info.items();
const KFileItem firstItem = items.first();
const bool isLocal = firstItem.url().isLocalFile();
// "Open With..." for folders is really not very useful, especially for remote folders.
@@ -491,16 +498,9 @@
KService::List::ConstIterator it = offers.constBegin();
for( ; it != offers.constEnd(); it++ ) {
- KService::Ptr service = (*it);
- QString actionName(service->name().replace('&', "&&"));
- if (menu == topMenu) // no submenu -> prefix single offer
- actionName = i18n("Open &with %1", actionName);
-
- KAction* act = d->m_ownActions.addAction("openwith");
- act->setIcon(KIcon(service->icon()));
- act->setText(actionName);
- act->setData(QVariant::fromValue(service));
- d->m_runApplicationActionGroup.addAction(act);
+ KAction* act = d->createAppAction(*it,
+ // no submenu -> prefix single offer
+ menu == topMenu);
menu->addAction(act);
}
@@ -542,3 +542,25 @@
// The item 'Other...' or 'Open With...' has been selected
KRun::displayOpenWithDialog(m_info.urlList(), m_info.parentWidget());
}
+
+KAction* KonqMenuActionsPrivate::createAppAction(const KService::Ptr& service, bool singleOffer)
+{
+ QString actionName(service->name().replace('&', "&&"));
+ if (singleOffer)
+ actionName = i18n("Open &with %1", actionName);
+
+ KAction* act = m_ownActions.addAction("openwith");
+ act->setIcon(KIcon(service->icon()));
+ act->setText(actionName);
+ act->setData(QVariant::fromValue(service));
+ m_runApplicationActionGroup.addAction(act);
+ return act;
+}
+
+KAction* KonqMenuActions::preferredOpenWithAction(const QString& traderConstraint)
+{
+ const KService::List offers = d->associatedApplications(traderConstraint);
+ if (offers.isEmpty())
+ return 0;
+ return d->createAppAction(offers.first(), true);
+}
--- trunk/KDE/kdebase/apps/lib/konq/konq_menuactions.h #937489:937490
@@ -23,6 +23,7 @@
#include <kfileitem.h>
#include <libkonq_export.h>
+class KAction;
class KonqPopupMenuInformation;
class QMenu;
class KonqMenuActionsPrivate;
@@ -81,6 +82,15 @@
*/
void addOpenWithActionsTo(QMenu* menu, const QString& traderConstraint);
+ /**
+ * Returns an action for the preferred app only.
+ * @param traderConstraint this constraint allows to exclude the current application
+ * from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".
+ * @return the action - or 0 if no application was found.
+ * @since 4.3
+ */
+ KAction* preferredOpenWithAction(const QString& traderConstraint);
+
private:
KonqMenuActionsPrivate* const d;
};
--- trunk/KDE/kdebase/apps/lib/konq/konq_menuactions_p.h #937489:937490
@@ -1,5 +1,5 @@
/* This file is part of the KDE project
- Copyright (C) 1998-2007 David Faure <faure@kde.org>
+ Copyright (C) 1998-2009 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -39,6 +39,10 @@
int insertServicesSubmenus(const QMap<QString, ServiceList>& list, QMenu* menu, bool isBuiltin);
int insertServices(const ServiceList& list, QMenu* menu, bool isBuiltin);
+ // For "open with"
+ KService::List associatedApplications(const QString& traderConstraint);
+ KAction* createAppAction(const KService::Ptr& service, bool singleOffer);
+
private Q_SLOTS:
// For servicemenus
void slotExecuteService(QAction* act);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic