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 #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_time; }
49 
50 public slots:
51  virtual void start();
52  virtual void stop();
53 
54 signals:
55  void progressUpdated(QStandardItem* item, int percent);
56  void finished(AbstractJob* job, bool isSuccess);
57 
58 protected:
59  QList<QAction*> m_standardActions;
60  QList<QAction*> m_successActions;
61  QStandardItem* m_item;
62 
63 protected slots:
64  virtual void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
65  virtual void onReadyRead();
66 
67 private:
68  bool m_ran;
69  bool m_killed;
70  QString m_log;
71  QString m_label;
72  QTime m_time;
73 };
74 
75 #endif // ABSTRACTJOB_H