Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / plasma / runners / shell / shellrunner.cpp
blob83dde7dda013e452944a7ea11c9d520f3c3297e3
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 <KIcon>
27 #include <KLocale>
28 #include <KRun>
29 #include <KStandardDirs>
31 #include "ui_shellOptions.h"
33 ShellRunner::ShellRunner(QObject *parent, const QVariantList &args)
34 : Plasma::AbstractRunner(parent, args)
36 Q_UNUSED(args)
38 setObjectName(i18n("Command"));
39 setHasMatchOptions(true);
40 setPriority(AbstractRunner::HighestPriority);
41 m_enabled = KAuthorized::authorizeKAction("shell_access");
44 ShellRunner::~ShellRunner()
48 void ShellRunner::match(Plasma::SearchContext *search)
50 if (!m_enabled) {
51 return;
54 if (search->type() == Plasma::SearchContext::Executable ||
55 search->type() == Plasma::SearchContext::ShellCommand) {
56 const QString term = search->searchTerm();
57 Plasma::SearchMatch* match = new Plasma::SearchMatch(this);
58 match->setType(Plasma::SearchMatch::ExactMatch);
59 match->setIcon(KIcon("system-run"));
60 match->setText(i18n("Run %1", term));
61 match->setRelevance(1);
62 search->addMatch(term, match);
66 void ShellRunner::createMatchOptions(QWidget* parent)
68 Ui::shellOptions ui;
69 ui.setupUi(parent);
72 void ShellRunner::exec(const Plasma::SearchContext *search, const Plasma::SearchMatch *action)
74 Q_UNUSED(action);
75 if (!m_enabled) {
76 return;
79 KRun::runCommand(search->searchTerm(), NULL);
82 #include "shellrunner.moc"