2
* Copyright (C) 2009 Aaron Seigo <aseigo@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 version 2 as
6
* published by the Free Software Foundation
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details
13
* You should have received a copy of the GNU Library General Public
14
* License along with this program; if not, write to the
15
* Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "plasma-desktop-runner.h"
21
#include <QDBusConnection>
22
#include <QDBusServiceWatcher>
23
#include <QDBusConnectionInterface>
30
#include <plasma/theme.h>
32
static const QString s_plasmaService = "org.kde.plasma-desktop";
34
PlasmaDesktopRunner::PlasmaDesktopRunner(QObject *parent, const QVariantList &args)
35
: Plasma::AbstractRunner(parent, args),
36
m_desktopConsoleKeyword(i18nc("Note this is a KRunner keyword", "desktop console")),
39
setObjectName( QLatin1String("Plasma-Desktop" ));
40
setIgnoredTypes(Plasma::RunnerContext::FileSystem |
41
Plasma::RunnerContext::NetworkLocation |
42
Plasma::RunnerContext::Help);
43
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(s_plasmaService, QDBusConnection::sessionBus(),
44
QDBusServiceWatcher::WatchForOwnerChange, this);
45
connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
46
this, SLOT(checkAvailability(QString,QString,QString)));
47
checkAvailability(QString(), QString(), QString());
50
PlasmaDesktopRunner::~PlasmaDesktopRunner()
54
void PlasmaDesktopRunner::match(Plasma::RunnerContext &context)
56
if (m_enabled && context.query().startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive)) {
57
Plasma::QueryMatch match(this);
58
match.setId("plasma-desktop-console");
59
match.setType(Plasma::QueryMatch::ExactMatch);
60
match.setIcon(KIcon("plasma"));
61
match.setText(i18n("Open Plasma desktop interactive console"));
62
match.setRelevance(1.0);
63
context.addMatch(context.query(), match);
67
void PlasmaDesktopRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
74
QString query = context.query();
75
if (query.compare(m_desktopConsoleKeyword, Qt::CaseInsensitive) == 0) {
76
message = QDBusMessage::createMethodCall(s_plasmaService, "/MainApplication",
77
QString(), "showInteractiveConsole");
79
message = QDBusMessage::createMethodCall(s_plasmaService, "/MainApplication",
80
QString(), "loadScriptInInteractiveConsole");
81
query.replace(m_desktopConsoleKeyword, QString(), Qt::CaseInsensitive);
84
message.setArguments(args);
87
QDBusConnection::sessionBus().asyncCall(message);
91
void PlasmaDesktopRunner::checkAvailability(const QString &name, const QString &oldOwner, const QString &newOwner)
97
enabled = QDBusConnection::sessionBus().interface()->isServiceRegistered(s_plasmaService).value();
99
enabled = !newOwner.isEmpty();
102
if (m_enabled != enabled) {
106
addSyntax(Plasma::RunnerSyntax(m_desktopConsoleKeyword,
107
i18n("Opens the Plasma desktop interactive console "
108
"with a file path to a script on disk.")));
109
addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "desktop console :q:"),
110
i18n("Opens the Plasma desktop interactive console "
111
"with a file path to a script on disk.")));
113
setSyntaxes(QList<Plasma::RunnerSyntax>());
119
#include "plasma-desktop-runner.moc"