Added ability to add widgets from command-line.
[quick-widgets] / ProcessObject.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef EXAMPLEITEM_H
31 #define EXAMPLEITEM_H
32
33 #include <QtCore/QObject>
34 #include <QtCore/QString>
35 #include <QtCore/QProcess>
36
37 class ProcessObject : public QObject
38 {
39     Q_OBJECT
40
41     Q_PROPERTY(QString command READ command WRITE setCommand)
42     Q_PROPERTY(bool suspend READ isSuspended WRITE setSuspend NOTIFY suspendChanged)
43
44 public:
45     ProcessObject(QObject *parent = 0);
46     ~ProcessObject();
47
48     Q_INVOKABLE void run();
49     Q_INVOKABLE void terminate();
50
51     QString command() const;
52     void setCommand(const QString &command);
53     bool isSuspended() const;
54     void setSuspend(bool suspend);
55
56 signals:
57     void completed(const QString& stdout);
58     void failed(int exitCode, const QString& stderr,
59                 QProcess::ProcessError error);
60     void suspendChanged(bool);
61
62 private slots:
63     void processFinished(int exitCode,
64                          QProcess::ExitStatus exitStatus);
65     void processErrored(QProcess::ProcessError error);
66
67 private:
68
69     QString m_command;
70     QProcess* m_process;
71     bool m_suspend;
72     bool m_started;
73
74     Q_DISABLE_COPY(ProcessObject)
75 };
76
77 #endif // EXAMPLEITEM_H