add more spacing
[personal-kdebase.git] / workspace / plasma / runners / shell / shellrunner.cpp
blob65f367324ee547ba6e3b2fd394efeb436d9633ac
1 /*
2 * Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "shellrunner.h"
21 #include <QWidget>
22 #include <QAction>
23 #include <QPushButton>
25 #include <KAuthorized>
26 #include <KDebug>
27 #include <KIcon>
28 #include <KLocale>
29 #include <KRun>
30 #include <KStandardDirs>
31 #include <KToolInvocation>
33 ShellRunner::ShellRunner(QObject *parent, const QVariantList &args)
34 : Plasma::AbstractRunner(parent, args),
35 m_inTerminal(false)
37 Q_UNUSED(args)
38 KGlobal::locale()->insertCatalog("krunner_shellrunner");
40 setObjectName("Command");
41 setPriority(AbstractRunner::HighestPriority);
42 m_enabled = KAuthorized::authorizeKAction("shell_access");
43 setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File |
44 Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::UnknownType |
45 Plasma::RunnerContext::Help);
46 reloadConfig();
49 ShellRunner::~ShellRunner()
53 void ShellRunner::reloadConfig()
55 //TODO
58 void ShellRunner::match(Plasma::RunnerContext &context)
60 if (!m_enabled) {
61 return;
64 if (context.type() == Plasma::RunnerContext::Executable ||
65 context.type() == Plasma::RunnerContext::ShellCommand) {
66 const QString term = context.query();
67 Plasma::QueryMatch match(this);
68 match.setType(Plasma::QueryMatch::ExactMatch);
69 match.setIcon(KIcon("system-run"));
70 match.setText(i18n("Run %1", term));
71 match.setRelevance(0.7);
72 context.addMatch(term, match);
76 void ShellRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
78 QMutexLocker lock(bigLock());
79 Q_UNUSED(match);
80 if (!m_enabled) {
81 return;
84 if (m_inTerminal) {
85 KToolInvocation::invokeTerminal(context.query());
87 // reset for the next run!
88 m_inTerminal = false;
89 } else {
90 KRun::runCommand(context.query(), NULL);
94 #include "shellrunner.moc"