Merge branch 'central-widget'
[krunner.git] / runners / shell / shellrunner.cpp
blob1838b4a9d83fd95474d89ce7f380320d63495ced
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 <QWidget>
20 #include <QAction>
21 #include <QPushButton>
23 #include <KAuthorized>
24 #include <KIcon>
25 #include <KLocale>
26 #include <KRun>
27 #include <KStandardDirs>
29 #include "shellrunner.h"
30 #include "ui_shellOptions.h"
32 ShellRunner::ShellRunner( QObject* parent )
33 : Plasma::AbstractRunner( parent ),
34 m_options( 0 )
36 setObjectName( i18n( "Command" ) );
37 m_enabled = KAuthorized::authorizeKAction( "shell_access" );
40 ShellRunner::~ShellRunner()
42 delete m_options;
45 QAction* ShellRunner::accepts(const QString& term)
47 if ( !m_enabled ) {
48 return 0;
51 QString executable = term;
52 int space = executable.indexOf( " " );
54 if ( space > 0 ) {
55 executable = executable.left( space );
58 executable = KStandardDirs::findExe( executable );
60 if ( !executable.isEmpty() ) {
61 QAction* action = new QAction( KIcon( "exec" ), executable, this );
62 return action;
63 } else {
64 return 0;
68 bool ShellRunner::hasOptions()
70 return true;
73 QWidget* ShellRunner::options()
75 if ( !m_options ) {
76 Ui::shellOptions ui;
77 m_options = new QWidget;
78 ui.setupUi( m_options );
81 return m_options;
84 bool ShellRunner::exec(QAction* action, const QString& command)
86 if (!m_enabled) {
87 return false;
90 return (KRun::runCommand(command, NULL) != 0);
93 #include "shellrunner.moc"