2
* Copyright 2009 by Chani Armitage <chani@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include <QGraphicsSceneMouseEvent>
23
#include <QGraphicsSceneWheelEvent>
29
#include <Plasma/DataEngine>
30
#include <Plasma/Containment>
31
#include <Plasma/ServiceJob>
33
AppLauncher::AppLauncher(QObject *parent, const QVariantList &args)
34
: Plasma::ContainmentActions(parent, args),
35
m_action(new QAction(this))
38
connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(switchTo(QAction*)));
40
m_action->setMenu(m_menu);
43
AppLauncher::~AppLauncher()
48
void AppLauncher::init(const KConfigGroup &)
52
void AppLauncher::contextEvent(QEvent *event)
56
m_menu->exec(popupPosition(m_menu->size(), event));
59
QList<QAction*> AppLauncher::contextualActions()
68
void AppLauncher::makeMenu()
70
Plasma::DataEngine *apps = dataEngine("apps");
71
if (!apps->isValid()) {
78
Plasma::DataEngine::Data app = dataEngine("apps")->query("/");
79
const QStringList sources = app.value("entries").toStringList();
80
foreach (const QString &source, sources) {
81
addApp(m_menu, source);
85
bool AppLauncher::addApp(QMenu *menu, const QString &source)
87
if (source == "---") {
92
Plasma::DataEngine::Data app = dataEngine("apps")->query(source);
94
if (!app.value("display").toBool()) {
95
kDebug() << "hidden entry" << source;
98
QString name = app.value("name").toString();
100
kDebug() << "failed source" << source;
104
name.replace("&", "&&"); //escaping
105
KIcon icon(app.value("iconName").toString());
107
if (app.value("isApp").toBool()) {
108
QAction *action = menu->addAction(icon, name);
109
action->setData(source);
110
} else { //ooh, it's actually a group!
111
QMenu *subMenu = menu->addMenu(icon, name);
112
bool hasEntries = false;
113
foreach (const QString &source, app.value("entries").toStringList()) {
114
hasEntries = addApp(subMenu, source) || hasEntries;
125
void AppLauncher::switchTo(QAction *action)
127
QString source = action->data().toString();
129
Plasma::Service *service = dataEngine("apps")->serviceForSource(source);
131
Plasma::ServiceJob *job = service->startOperationCall(service->operationDescription("launch"));
132
connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater()));
136
#include "launch.moc"