~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to konqueror/shellcmdplugin/kshellcmdplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-04-05 05:22:13 UTC
  • mfrom: (0.4.2 experimental) (0.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20090405052213-39thr4l6p2ss07uj
Tags: 4:4.2.2-1
* New upstream release:
  - khtml fixes. (Closes: #290285, #359680)
  - Default konsole sessions can be deleted. (Closes: #286342)
  - Tag widget uses standard application palette. (Closes: #444800)
  - ... and surely many more but we have lost track...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2000 David Faure <faure@kde.org>
3
 
 
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.
7
 
 
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.
12
 
 
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.
17
 
*/
18
 
 
19
 
#include "kshellcmdplugin.h"
20
 
#include <kinputdialog.h>
21
 
#include <kmessagebox.h>
22
 
#include <konq_dirpart.h>
23
 
#include <kprocess.h>
24
 
#include <kapplication.h>
25
 
#include "kshellcmddialog.h"
26
 
#include <kgenericfactory.h>
27
 
#include <kio/netaccess.h>
28
 
 
29
 
KShellCmdPlugin::KShellCmdPlugin( QObject* parent, const char* name,
30
 
                                  const QStringList & )
31
 
    : KParts::Plugin( parent, name )
32
 
{
33
 
    if (!kapp->authorize("shell_access"))
34
 
       return;
35
 
 
36
 
    new KAction( i18n( "&Execute Shell Command..." ), "run", CTRL+Key_E, this,
37
 
                 SLOT( slotExecuteShellCommand() ), actionCollection(), "executeshellcommand" );
38
 
}
39
 
 
40
 
void KShellCmdPlugin::slotExecuteShellCommand()
41
 
{
42
 
   KonqDirPart * part = dynamic_cast<KonqDirPart *>(parent());
43
 
   if ( !part )
44
 
   {
45
 
      KMessageBox::sorry(0L, "KShellCmdPlugin::slotExecuteShellCommand: Program error, please report a bug.");
46
 
      return;
47
 
   }
48
 
   KURL url = KIO::NetAccess::mostLocalURL(part->url(),NULL);
49
 
   if ( !url.isLocalFile() )
50
 
   {
51
 
      KMessageBox::sorry(part->widget(),i18n("Executing shell commands works only on local directories."));
52
 
      return;
53
 
   }
54
 
   QString path;
55
 
   if ( part->currentItem() )
56
 
   {
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() );
62
 
   }
63
 
   else
64
 
   {
65
 
      path = url.path();
66
 
   }
67
 
   bool ok;
68
 
   QString cmd = KInputDialog::getText( i18n("Execute Shell Command"),
69
 
      i18n( "Execute shell command in current directory:" ),
70
 
      KProcess::quote( path ), &ok, part->widget() );
71
 
   if ( ok )
72
 
   {
73
 
      QString chDir;
74
 
      chDir="cd ";
75
 
      chDir+=KProcess::quote(part->url().path());
76
 
      chDir+="; ";
77
 
      chDir+=cmd;
78
 
 
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;
83
 
   }
84
 
}
85
 
 
86
 
typedef KGenericFactory<KShellCmdPlugin> KonqShellCmdPluginFactory;
87
 
K_EXPORT_COMPONENT_FACTORY( konq_shellcmdplugin, KonqShellCmdPluginFactory( "kshellcmdplugin" ) )
88
 
 
89
 
#include "kshellcmdplugin.moc"
90