1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "tool_abstract.h"
25 #include "model_options.h"
26 #include "model_preferences.h"
27 #include "model_sysinfo.h"
29 #include "job_object.h"
32 #include <QMutexLocker>
35 QMutex AbstractTool::s_mutexStartProcess;
37 AbstractTool::AbstractTool(volatile bool *abort, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobObject *jobObject)
42 m_preferences(preferences),
43 m_jobObject(jobObject)
45 /*nothing to do here*/
48 bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args, bool mergeChannels)
50 QMutexLocker lock(&s_mutexStartProcess);
51 log(commandline2string(program, args) + "\n");
53 process.setWorkingDirectory(QDir::tempPath());
57 process.setProcessChannelMode(QProcess::MergedChannels);
58 process.setReadChannel(QProcess::StandardOutput);
62 process.setProcessChannelMode(QProcess::SeparateChannels);
63 process.setReadChannel(QProcess::StandardError);
66 process.start(program, args);
68 if(process.waitForStarted())
70 m_jobObject->addProcessToJob(&process);
71 x264_change_process_priority(&process, m_preferences->getProcessPriority());
76 log("Process creation has failed :-(");
77 QString errorMsg= process.errorString().trimmed();
78 if(!errorMsg.isEmpty()) log(errorMsg);
81 process.waitForFinished(-1);
85 QString AbstractTool::commandline2string(const QString &program, const QStringList &arguments)
87 QString commandline = (program.contains(' ') ? QString("\"%1\"").arg(program) : program);
89 for(int i = 0; i < arguments.count(); i++)
91 commandline += (arguments.at(i).contains(' ') ? QString(" \"%1\"").arg(arguments.at(i)) : QString(" %1").arg(arguments.at(i)));