From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- konqueror/shellcmdplugin/kshellcmdplugin.cpp | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 konqueror/shellcmdplugin/kshellcmdplugin.cpp (limited to 'konqueror/shellcmdplugin/kshellcmdplugin.cpp') diff --git a/konqueror/shellcmdplugin/kshellcmdplugin.cpp b/konqueror/shellcmdplugin/kshellcmdplugin.cpp new file mode 100644 index 000000000..b7f07ec81 --- /dev/null +++ b/konqueror/shellcmdplugin/kshellcmdplugin.cpp @@ -0,0 +1,90 @@ +/* This file is part of the KDE project + Copyright (C) 2000 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kshellcmdplugin.h" +#include +#include +#include +#include +#include +#include "kshellcmddialog.h" +#include +#include + +KShellCmdPlugin::KShellCmdPlugin( QObject* parent, const char* name, + const QStringList & ) + : KParts::Plugin( parent, name ) +{ + if (!kapp->authorize("shell_access")) + return; + + new KAction( i18n( "&Execute Shell Command..." ), "run", CTRL+Key_E, this, + SLOT( slotExecuteShellCommand() ), actionCollection(), "executeshellcommand" ); +} + +void KShellCmdPlugin::slotExecuteShellCommand() +{ + KonqDirPart * part = dynamic_cast(parent()); + if ( !part ) + { + KMessageBox::sorry(0L, "KShellCmdPlugin::slotExecuteShellCommand: Program error, please report a bug."); + return; + } + KURL url = KIO::NetAccess::mostLocalURL(part->url(),NULL); + if ( !url.isLocalFile() ) + { + KMessageBox::sorry(part->widget(),i18n("Executing shell commands works only on local directories.")); + return; + } + QString path; + if ( part->currentItem() ) + { + // Putting the complete path to the selected file isn't really necessary, + // since we'll cd to the directory first. But we do need to get the + // complete relative path. + path = KURL::relativePath( url.path(), + part->currentItem()->url().path() ); + } + else + { + path = url.path(); + } + bool ok; + QString cmd = KInputDialog::getText( i18n("Execute Shell Command"), + i18n( "Execute shell command in current directory:" ), + KProcess::quote( path ), &ok, part->widget() ); + if ( ok ) + { + QString chDir; + chDir="cd "; + chDir+=KProcess::quote(part->url().path()); + chDir+="; "; + chDir+=cmd; + + KShellCommandDialog *shellCmdDialog=new KShellCommandDialog(i18n("Output from command: \"%1\"").arg(cmd),chDir,part->widget(),true); + shellCmdDialog->resize(500,300); + shellCmdDialog->executeCommand(); + delete shellCmdDialog; + } +} + +typedef KGenericFactory KonqShellCmdPluginFactory; +K_EXPORT_COMPONENT_FACTORY( konq_shellcmdplugin, KonqShellCmdPluginFactory( "kshellcmdplugin" ) ) + +#include "kshellcmdplugin.moc" + -- cgit v1.2.1