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

Plasma

shellrunner.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2006 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 "shellrunner.h"
00020 
00021 #include <QWidget>
00022 #include <QAction>
00023 #include <QPushButton>
00024 
00025 #include <KAuthorized>
00026 #include <KDebug>
00027 #include <KIcon>
00028 #include <KLocale>
00029 #include <KRun>
00030 #include <KStandardDirs>
00031 #include <KToolInvocation>
00032 
00033 ShellRunner::ShellRunner(QObject *parent, const QVariantList &args)
00034     : Plasma::AbstractRunner(parent, args),
00035       m_inTerminal(false)
00036 {
00037     Q_UNUSED(args)
00038     KGlobal::locale()->insertCatalog("krunner_shellrunner");
00039 
00040     setObjectName("Command");
00041     setPriority(AbstractRunner::HighestPriority);
00042     m_enabled = KAuthorized::authorizeKAction("shell_access");
00043     setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File |
00044                     Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::UnknownType |
00045                     Plasma::RunnerContext::Help);
00046     reloadConfig();
00047 }
00048 
00049 ShellRunner::~ShellRunner()
00050 {
00051 }
00052 
00053 void ShellRunner::reloadConfig()
00054 {
00055     //TODO
00056 }
00057 
00058 void ShellRunner::match(Plasma::RunnerContext &context)
00059 {
00060     if (!m_enabled) {
00061         return;
00062     }
00063 
00064     if (context.type() == Plasma::RunnerContext::Executable ||
00065         context.type() == Plasma::RunnerContext::ShellCommand)  {
00066         const QString term = context.query();
00067         Plasma::QueryMatch match(this);
00068         match.setType(Plasma::QueryMatch::ExactMatch);
00069         match.setIcon(KIcon("system-run"));
00070         match.setText(i18n("Run %1", term));
00071         match.setRelevance(0.7);
00072         context.addMatch(term, match);
00073     }
00074 }
00075 
00076 void ShellRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
00077 {
00078     QMutexLocker lock(bigLock());
00079     Q_UNUSED(match);
00080     if (!m_enabled) {
00081         return;
00082     }
00083 
00084     if (m_inTerminal) {
00085         KToolInvocation::invokeTerminal(context.query());
00086 
00087         // reset for the next run!
00088         m_inTerminal = false;
00089     } else {
00090         KRun::runCommand(context.query(), NULL);
00091     }
00092 }
00093 
00094 #include "shellrunner.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"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
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