AstRawDark
Manage your astrophoto dark frames
 All Classes Functions Variables Enumerations Enumerator Pages
abstractCommand.cpp
1 /*
2  * AstRawDark
3  *
4  * Copyright (C) 2015 - Frédéric CORNU
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "abstractCommand.h"
21 #include "signalDispatcher.h"
22 
23 #ifndef QT_NO_DEBUG
24 #include <QDebug>
25 #endif
26 
27 int AbstractCommand::SERIAL = 0;
28 
30  : _status(SCHEDULED),
31  _elapsed(0),
32  _serial(SERIAL++),
33  _error(false),
34  _warning(false) {
35 
36  connect(this,
40 
41  #ifndef QT_NO_DEBUG
42  qDebug() << "Command" << _serial << "created";
43  #endif
44 
45 }
46 
48 {
49 
50 }
51 
53 {
54 
55  #ifndef QT_NO_DEBUG
56  qDebug() << "Command" << getSerial() << "Starting";
57  #endif
58  /*
59  * this is a function template, all it does
60  * is calling redefined functions from subclasses
61  */
62 
63  // TODO this should be done in setup()
64  _timer.start();
65  _status = RUNNING;
66  emit statusChanged(this);
67 
68  setup();
69  do_processing();
70  cleanup();
71 
72  // TODO this should be done in cleanup()
73  _elapsed = _timer.elapsed();
74  _status = COMPLETE;
75  emit progressMax(1);
76  emit progress(1);
77  emit statusChanged(this);
78 
79  #ifndef QT_NO_DEBUG
80  qDebug() << "Command" << getSerial() << "Done";
81  #endif
82 }
83 
84 const QString AbstractCommand::getStatusString() const
85 {
86  QString sRet;
87 
88  switch ( _status ) {
89 
91  sRet = tr("Scheduled");
92  break;
93 
95  sRet = tr("Running");
96  break;
98  sRet = tr("Finished (%1 ms)").arg(getElapsed());
99  break;
100 
101  default:
102  sRet = tr("Undefined");
103  break;
104  }
105 
106  return sRet;
107 }
108