CuteLogger
Fast and simple logging solution for Qt based applications
abstractjob.h
1 /*
2  * Copyright (c) 2012-2018 Meltytech, LLC
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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ABSTRACTJOB_H
19 #define ABSTRACTJOB_H
20 
21 #include "postjobaction.h"
22 #include <QProcess>
23 #include <QModelIndex>
24 #include <QList>
25 #include <QTime>
26 
27 class QAction;
28 class QStandardItem;
29 
30 class AbstractJob : public QProcess
31 {
32  Q_OBJECT
33 public:
34  explicit AbstractJob(const QString& name);
35  virtual ~AbstractJob() {}
36 
37  void setStandardItem(QStandardItem* item);
38  QStandardItem* standardItem();
39  bool ran() const;
40  bool stopped() const;
41  void appendToLog(const QString&);
42  QString log() const;
43  QString label() const { return m_label; }
44  void setLabel(const QString& label);
45  QList<QAction*> standardActions() const { return m_standardActions; }
46  QList<QAction*> successActions() const { return m_successActions; }
47  QTime estimateRemaining(int percent);
48  QTime time() const { return m_totalTime; }
49  void setPostJobAction(PostJobAction* action);
50 
51 public slots:
52  void start(const QString &program, const QStringList &arguments);
53  virtual void start();
54  virtual void stop();
55 
56 signals:
57  void progressUpdated(QStandardItem* item, int percent);
58  void finished(AbstractJob* job, bool isSuccess, QString failureTime = QString());
59 
60 protected:
61  QList<QAction*> m_standardActions;
62  QList<QAction*> m_successActions;
63  QStandardItem* m_item;
64 
65 protected slots:
66  virtual void onFinished(int exitCode, QProcess::ExitStatus exitStatus = QProcess::NormalExit);
67  virtual void onReadyRead();
68  virtual void onStarted();
69 
70 private slots:
71  void onProgressUpdated(QStandardItem*, int percent);
72 
73 private:
74  bool m_ran;
75  bool m_killed;
76  QString m_log;
77  QString m_label;
78  QTime m_estimateTime;
79  int m_startingPercent;
80  QTime m_totalTime;
81  QScopedPointer<PostJobAction> m_postJobAction;
82 };
83 
84 #endif // ABSTRACTJOB_H