OSDN Git Service

25641e112df65d22cd124d75c618dc3395c46930
[x264-launcher/x264-launcher.git] / src / tool_abstract.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
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 2 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 along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 #include <QObject>
25 #include <QUuid>
26 #include <QMutex>
27
28 class OptionsModel;
29 class SysinfoModel;
30 class PreferencesModel;
31 class JobObject;
32 class QProcess;
33 class QSemaphore;
34 enum JobStatus;
35
36 class AbstractTool : public QObject
37 {
38         Q_OBJECT
39
40 public:
41         AbstractTool(JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobStatus &jobStatus, volatile bool *abort, volatile bool *pause, QSemaphore *semaphorePause);
42         virtual ~AbstractTool(void) {/*NOP*/}
43         
44 signals:
45         void statusChanged(const JobStatus &newStatus);
46         void progressChanged(unsigned int newProgress);
47         void messageLogged(const QString &text);
48         void detailsChanged(const QString &details);
49
50 protected:
51         static const unsigned int m_processTimeoutInterval = 2500;
52         static const unsigned int m_processTimeoutMaxCounter = 120;
53         static const unsigned int m_processTimeoutWarning = 24;
54
55         void log(const QString &text) { emit messageLogged(text); }
56         void setStatus(const JobStatus &newStatus) { emit statusChanged(newStatus); } 
57         void setProgress(unsigned int newProgress) { emit progressChanged(newProgress); }
58         void setDetails(const QString &text) { emit detailsChanged(text); }
59
60         bool startProcess(QProcess &process, const QString &program, const QStringList &args, bool mergeChannels = true);
61
62         JobObject *const m_jobObject;
63         const OptionsModel *const m_options;
64         const SysinfoModel *const m_sysinfo;
65         const PreferencesModel *const m_preferences;
66         JobStatus &m_jobStatus;
67         volatile bool *const m_abort;
68         volatile bool *const m_pause;
69         QSemaphore *const m_semaphorePause;
70
71         static QString commandline2string(const QString &program, const QStringList &arguments);
72         static QString stringToHash(const QString &string);
73         
74         static QMutex s_mutexStartProcess;
75 };