~ubuntu-branches/ubuntu/oneiric/partitionmanager/oneiric

« back to all changes in this revision

Viewing changes to src/util/externalcommand.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-01-23 17:57:36 UTC
  • Revision ID: james.westby@ubuntu.com-20090123175736-2ltrhgg3m55dokbm
Tags: upstream-1.0.0~beta1a
ImportĀ upstreamĀ versionĀ 1.0.0~beta1a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Volker Lanz <vl@fidra.de>                       *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program 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         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 
18
 ***************************************************************************/
 
19
 
 
20
#if !defined(EXTERNALCOMMAND__H)
 
21
 
 
22
#define EXTERNALCOMMAND__H
 
23
 
 
24
#include <QProcess>
 
25
#include <QStringList>
 
26
#include <QString>
 
27
#include <qglobal.h>
 
28
 
 
29
class Report;
 
30
 
 
31
/** @brief An external command.
 
32
 
 
33
        Runs an external command as a child process.
 
34
 
 
35
        @author vl@fidra.de
 
36
*/
 
37
class ExternalCommand : public QProcess
 
38
{
 
39
        Q_OBJECT
 
40
        Q_DISABLE_COPY(ExternalCommand)
 
41
 
 
42
        public:
 
43
                explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList());
 
44
                explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList());
 
45
 
 
46
        public:
 
47
                void setCommand(const QString& cmd) { m_Command = cmd; } /**< @param cmd the command to run */
 
48
                const QString& command() const { return m_Command; } /**< @return the command to run */
 
49
                
 
50
                void addArg(const QString& s) { m_Args << s; } /**< @param s the argument to add */
 
51
                const QStringList& args() const { return m_Args; } /**< @return the arguments */
 
52
                void setArgs(const QStringList& args) { m_Args = args; } /**< @param args the new arguments */
 
53
 
 
54
                bool start(int timeout = 30000);
 
55
                bool waitFor(int timeout = 30000);
 
56
                bool run(int timeout = 30000);
 
57
 
 
58
                int exitCode() const { return m_ExitCode; } /**< @return the exit code */
 
59
 
 
60
                const QString& output() const { return m_Output; } /**< @return the command output */
 
61
 
 
62
                Report* report() { return m_Report; } /**< @return pointer to the Report or NULL */
 
63
 
 
64
        protected:
 
65
                void setExitCode(int i) { m_ExitCode = i; }
 
66
                void setup();
 
67
                
 
68
        protected slots:
 
69
                void onFinished(int exitCode);
 
70
                void onReadOutput();
 
71
 
 
72
        private:
 
73
                Report* m_Report;
 
74
                QString m_Command;
 
75
                QStringList m_Args;
 
76
                int m_ExitCode;
 
77
                QString m_Output;
 
78
};
 
79
 
 
80
#endif