• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

plasma-desktop-runner.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2009 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program is distributed in the hope that it will be useful,
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 #include "plasma-desktop-runner.h"
00020 
00021 #include <QDBusConnection>
00022 #include <QDBusConnectionInterface>
00023 #include <QDBusInterface>
00024 
00025 #include <KDebug>
00026 #include <KIcon>
00027 #include <KLocale>
00028 #include <KRun>
00029 #include <KToolInvocation>
00030 
00031 #include <plasma/theme.h>
00032 
00033 static const QString s_plasmaService = "org.kde.plasma-desktop";
00034 
00035 PlasmaDesktopRunner::PlasmaDesktopRunner(QObject *parent, const QVariantList &args)
00036     : Plasma::AbstractRunner(parent, args),
00037       m_desktopConsoleKeyword(i18nc("Note this is a KRunner keyword", "desktop console")),
00038       m_enabled(false)
00039 {
00040     setObjectName("Plasma-Desktop");
00041     setIgnoredTypes(Plasma::RunnerContext::FileSystem |
00042                     Plasma::RunnerContext::NetworkLocation |
00043                     Plasma::RunnerContext::Help);
00044 
00045     QObject::connect(QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
00046                      this, SLOT(checkAvailability(QString,QString,QString)));
00047     checkAvailability(QString(), QString(), QString());
00048 }
00049 
00050 PlasmaDesktopRunner::~PlasmaDesktopRunner()
00051 {
00052 }
00053 
00054 void PlasmaDesktopRunner::match(Plasma::RunnerContext &context)
00055 {
00056     if (m_enabled && context.query().startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive)) {
00057         Plasma::QueryMatch match(this);
00058         match.setId("plasma-desktop-console");
00059         match.setType(Plasma::QueryMatch::ExactMatch);
00060         match.setIcon(KIcon("plasma"));
00061         match.setText(i18n("Open Plasma desktop interactive console"));
00062         match.setRelevance(1.0);
00063         context.addMatch(context.query(), match);
00064     }
00065 }
00066 
00067 void PlasmaDesktopRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
00068 {
00069     Q_UNUSED(match)
00070 
00071     if (m_enabled) {
00072         QDBusMessage message;
00073 
00074         QString query = context.query();
00075         if (query.compare(m_desktopConsoleKeyword, Qt::CaseInsensitive) == 0) {
00076             message = QDBusMessage::createMethodCall(s_plasmaService, "/MainApplication",
00077                                                      QString(), "showInteractiveConsole");
00078         } else {
00079             message = QDBusMessage::createMethodCall(s_plasmaService, "/MainApplication",
00080                                                      QString(), "loadScriptInInteractiveConsole");
00081             query.replace(m_desktopConsoleKeyword, QString(), Qt::CaseInsensitive);
00082             QList<QVariant> args;
00083             args << query;
00084             message.setArguments(args);
00085         }
00086 
00087         QDBusConnection::sessionBus().asyncCall(message);
00088     }
00089 }
00090 
00091 void PlasmaDesktopRunner::checkAvailability(const QString &name, const QString &oldOwner, const QString &newOwner)
00092 {
00093     Q_UNUSED(oldOwner)
00094 
00095     bool enabled = false;
00096     if (name.isEmpty()) {
00097         enabled = QDBusConnection::sessionBus().interface()->isServiceRegistered(s_plasmaService).value();
00098     } else if (name == s_plasmaService) {
00099         enabled = !newOwner.isNull();
00100     } else {
00101         // it's not something we're interested in
00102         return;
00103     }
00104 
00105     if (m_enabled != enabled) {
00106         m_enabled = enabled;
00107 
00108         if (m_enabled) {
00109             addSyntax(Plasma::RunnerSyntax(m_desktopConsoleKeyword,
00110                                            i18n("Opens the Plasma desktop interactive console "
00111                                                 "with a file path to a script on disk.")));
00112             addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "desktop console :q:"),
00113                                            i18n("Opens the Plasma desktop interactive console "
00114                                                 "with a file path to a script on disk.")));
00115         } else {
00116             setSyntaxes(QList<Plasma::RunnerSyntax>());
00117         }
00118     }
00119 }
00120 
00121 
00122 #include "plasma-desktop-runner.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KStyles
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •     Animators
  •     Applets
  •     Engines
  • Solid Modules
  • System Settings
  •   SystemSettingsView
Generated for API Reference by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal