• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Utility Library
 

KDevelop Utility Library

  • lib
  • util
execcommand.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2002 Harald Fernengel <harry@kdevelop.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 as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "execcommand.h"
21 
22 #include <kprocess.h>
23 #include <kprogress.h>
24 #include <tdelocale.h>
25 #include <tdemessagebox.h>
26 
27 ExecCommand::ExecCommand( const TQString& executable, const TQStringList& args,
28  const TQString& workingDir, const TQStringList& env,
29  TQObject* parent, const char* name ):
30  TQObject( parent, name ), out( "" ) /* make sure out is not TQString() since that would mean "error" */
31 
32 {
33  progressDlg = 0;
34 
35  proc = new TDEProcess();
36  proc->setWorkingDirectory( workingDir );
37  for ( TQStringList::ConstIterator it = env.begin(); it != env.end(); ++it )
38  proc->setEnvironment( (*it).section( '=', 0, 0 ), (*it).section( '=', 1, 1 ) );
39  *proc << executable;
40  *proc << args;
41 
42  connect( proc, TQT_SIGNAL(processExited(TDEProcess*)),
43  this, TQT_SLOT(processExited()) );
44  connect( proc, TQT_SIGNAL(receivedStdout(TDEProcess*,char*,int)),
45  this, TQT_SLOT(receivedStdout(TDEProcess*,char*,int)) );
46  connect( proc, TQT_SIGNAL(receivedStderr(TDEProcess*,char*,int)),
47  this, TQT_SLOT(receivedStderr(TDEProcess*,char*,int)) );
48 
49  bool ok = proc->start( TDEProcess::NotifyOnExit, TDEProcess::AllOutput );
50 
51  if ( !ok ) {
52  KMessageBox::error( 0, i18n("Could not invoke \"%1\". Please make sure it is installed correctly").arg( executable ),
53  i18n("Error Invoking Command") );
54 
55  emit finished( TQString(), TQString() );
56  deleteLater();
57 
58  } else {
59  progressDlg = new KProgressDialog( 0, 0, i18n("Command running..."),
60  i18n("Please wait until the \"%1\" command finishes.").arg( executable ), false );
61  connect( progressDlg, TQT_SIGNAL(cancelClicked()),
62  this, TQT_SLOT(cancelClicked()) );
63  }
64 }
65 
66 void ExecCommand::receivedStdout (TDEProcess*, char *buffer, int buflen)
67 {
68  out += TQString::fromUtf8( buffer, buflen );
69 }
70 
71 void ExecCommand::receivedStderr (TDEProcess*, char *buffer, int buflen)
72 {
73  err += TQString::fromUtf8( buffer, buflen );
74 }
75 
76 void ExecCommand::processExited()
77 {
78  delete progressDlg;
79  progressDlg = 0;
80 
81  emit finished( out, err );
82  deleteLater();
83 }
84 
85 void ExecCommand::cancelClicked()
86 {
87  delete progressDlg;
88  progressDlg = 0;
89  proc->kill();
90 
91  emit finished( TQString(), TQString() );
92  deleteLater();
93 }
94 
95 ExecCommand::~ExecCommand()
96 {
97  delete proc;
98  delete progressDlg;
99 }
100 
101 #include "execcommand.moc"
execcommand.h
Command execution facilities.

KDevelop Utility Library

Skip menu "KDevelop Utility Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDevelop Utility Library

Skip menu "KDevelop Utility Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Utility Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.