• Skip to content
  • Skip to link menu
KDE 4.1 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 #include "ui_shellOptions.h"
00034 
00035 ShellRunner::ShellRunner(QObject *parent, const QVariantList &args)
00036     : Plasma::AbstractRunner(parent, args),
00037       m_inTerminal(false)
00038 {
00039     Q_UNUSED(args)
00040     KGlobal::locale()->insertCatalog("krunner_shellrunner");
00041 
00042     setObjectName(i18n("Command"));
00043     setHasRunOptions(true);
00044     setPriority(AbstractRunner::HighestPriority);
00045     m_enabled = KAuthorized::authorizeKAction("shell_access");
00046     setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File | 
00047                     Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::UnknownType | 
00048                     Plasma::RunnerContext::Help);
00049 }
00050 
00051 ShellRunner::~ShellRunner()
00052 {
00053 }
00054 
00055 void ShellRunner::match(Plasma::RunnerContext &context)
00056 {
00057     if (!m_enabled) {
00058         return;
00059     }
00060 
00061     if (context.type() == Plasma::RunnerContext::Executable ||
00062         context.type() == Plasma::RunnerContext::ShellCommand)  {
00063         const QString term = context.query();
00064         Plasma::QueryMatch match(this);
00065         match.setType(Plasma::QueryMatch::ExactMatch);
00066         match.setIcon(KIcon("system-run"));
00067         match.setText(i18n("Run %1", term));
00068         match.setRelevance(1);
00069         context.addMatch(term, match);
00070     }
00071 }
00072 
00073 void ShellRunner::createMatchOptions(QWidget* parent)
00074 {
00075     m_inTerminal = false;
00076     Ui::shellOptions ui;
00077     ui.setupUi(parent);
00078 
00079     //TODO: connect rest of UI up too!
00080     connect(ui.cbRunInTerminal, SIGNAL(toggled(bool)), this, SLOT(setRunInTerminal(bool)));
00081 }
00082 
00083 void ShellRunner::setRunInTerminal(bool inTerminal)
00084 {
00085     m_inTerminal = inTerminal;
00086 }
00087 
00088 void ShellRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
00089 {
00090     QMutexLocker lock(bigLock());
00091     Q_UNUSED(match);
00092     if (!m_enabled) {
00093         return;
00094     }
00095 
00096     if (m_inTerminal) {
00097         KToolInvocation::invokeTerminal(context.query());
00098 
00099         // reset for the next run!
00100         m_inTerminal = false;
00101     } else {
00102         KRun::runCommand(context.query(), NULL);
00103     }
00104 }
00105 
00106 #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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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