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 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
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
00088 m_inTerminal = false;
00089 } else {
00090 KRun::runCommand(context.query(), NULL);
00091 }
00092 }
00093
00094 #include "shellrunner.moc"