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 "postjobaction.h"
23 #include <QProcess>
24 #include <QModelIndex>
25 #include <QList>
26 #include <QTime>
27 
28 class QAction;
29 class QStandardItem;
30 
31 class AbstractJob : public QProcess
32 {
33  Q_OBJECT
34 public:
35  explicit AbstractJob(const QString& name);
36  virtual ~AbstractJob() {}
37 
38  void setStandardItem(QStandardItem* item);
39  QStandardItem* standardItem();
40  bool ran() const;
41  bool stopped() const;
42  void appendToLog(const QString&);
43  QString log() const;
44  QString label() const { return m_label; }
45  void setLabel(const QString& label);
46  QList<QAction*> standardActions() const { return m_standardActions; }
47  QList<QAction*> successActions() const { return m_successActions; }
48  QTime estimateRemaining(int percent);
49  QTime time() const { return m_time; }
50  void setPostJobAction(PostJobAction* action);
51 
52 public slots:
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);
67  virtual void onReadyRead();
68  virtual void onStarted();
69 
70 private:
71  bool m_ran;
72  bool m_killed;
73  QString m_log;
74  QString m_label;
75  QTime m_time;
76  QScopedPointer<PostJobAction> m_postJobAction;
77 };
78 
79 #endif // ABSTRACTJOB_H