Plasma
shellrunner.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00100 m_inTerminal = false;
00101 } else {
00102 KRun::runCommand(context.query(), NULL);
00103 }
00104 }
00105
00106 #include "shellrunner.moc"