1
/* This file is part of the KDE project
2
Copyright (C) 2000 David Faure <faure@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library 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 GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#include "kshellcmdplugin.h"
20
#include <kinputdialog.h>
21
#include <kmessagebox.h>
22
#include <konq_dirpart.h>
24
#include <kapplication.h>
25
#include "kshellcmddialog.h"
26
#include <kgenericfactory.h>
27
#include <kio/netaccess.h>
29
KShellCmdPlugin::KShellCmdPlugin( QObject* parent, const char* name,
31
: KParts::Plugin( parent, name )
33
if (!kapp->authorize("shell_access"))
36
new KAction( i18n( "&Execute Shell Command..." ), "run", CTRL+Key_E, this,
37
SLOT( slotExecuteShellCommand() ), actionCollection(), "executeshellcommand" );
40
void KShellCmdPlugin::slotExecuteShellCommand()
42
KonqDirPart * part = dynamic_cast<KonqDirPart *>(parent());
45
KMessageBox::sorry(0L, "KShellCmdPlugin::slotExecuteShellCommand: Program error, please report a bug.");
48
KURL url = KIO::NetAccess::mostLocalURL(part->url(),NULL);
49
if ( !url.isLocalFile() )
51
KMessageBox::sorry(part->widget(),i18n("Executing shell commands works only on local directories."));
55
if ( part->currentItem() )
57
// Putting the complete path to the selected file isn't really necessary,
58
// since we'll cd to the directory first. But we do need to get the
59
// complete relative path.
60
path = KURL::relativePath( url.path(),
61
part->currentItem()->url().path() );
68
QString cmd = KInputDialog::getText( i18n("Execute Shell Command"),
69
i18n( "Execute shell command in current directory:" ),
70
KProcess::quote( path ), &ok, part->widget() );
75
chDir+=KProcess::quote(part->url().path());
79
KShellCommandDialog *shellCmdDialog=new KShellCommandDialog(i18n("Output from command: \"%1\"").arg(cmd),chDir,part->widget(),true);
80
shellCmdDialog->resize(500,300);
81
shellCmdDialog->executeCommand();
82
delete shellCmdDialog;
86
typedef KGenericFactory<KShellCmdPlugin> KonqShellCmdPluginFactory;
87
K_EXPORT_COMPONENT_FACTORY( konq_shellcmdplugin, KonqShellCmdPluginFactory( "kshellcmdplugin" ) )
89
#include "kshellcmdplugin.moc"