CuteLogger
Fast and simple logging solution for Qt based applications
abstractjob.h
1 /*
2  * Copyright (c) 2012-2017 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef ABSTRACTJOB_H
20 #define ABSTRACTJOB_H
21 
22 #include <QProcess>
23 #include <QModelIndex>
24 #include <QList>
25 
26 class QAction;
27 
28 class AbstractJob : public QProcess
29 {
30  Q_OBJECT
31 public:
32  explicit AbstractJob(const QString& name);
33  virtual ~AbstractJob() {}
34 
35  void setModelIndex(const QModelIndex& index);
36  QModelIndex modelIndex() const;
37  bool ran() const;
38  bool stopped() const;
39  void appendToLog(const QString&);
40  QString log() const;
41  QString label() const { return m_label; }
42  void setLabel(const QString& label);
43  QList<QAction*> standardActions() const { return m_standardActions; }
44  QList<QAction*> successActions() const { return m_successActions; }
45 
46 public slots:
47  virtual void start();
48  virtual void stop();
49 
50 signals:
51  void progressUpdated(QModelIndex index, uint percent);
52  void finished(AbstractJob* job, bool isSuccess);
53 
54 protected:
55  QList<QAction*> m_standardActions;
56  QList<QAction*> m_successActions;
57  QModelIndex m_index;
58 
59 protected slots:
60  virtual void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
61  virtual void onReadyRead();
62 
63 private:
64  bool m_ran;
65  bool m_killed;
66  QString m_log;
67  QString m_label;
68 };
69 
70 #endif // ABSTRACTJOB_H