Updated copyright year.
[simple-x264-launcher.git] / src / win_help.cpp
blob0f8a920208ba9fe72aa73414e83ea00c130a6c48
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2024 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.
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 "win_help.h"
23 #include "UIC_win_help.h"
25 //Internal
26 #include "global.h"
27 #include "model_options.h"
28 #include "model_sysinfo.h"
29 #include "model_preferences.h"
30 #include "encoder_factory.h"
31 #include "source_factory.h"
33 //MUtils
34 #include <MUtils/Sound.h>
36 //Qt
37 #include <QProcess>
38 #include <QScrollBar>
39 #include <QTimer>
41 ///////////////////////////////////////////////////////////////////////////////
42 // Constructor & Destructor
43 ///////////////////////////////////////////////////////////////////////////////
45 HelpDialog::HelpDialog(QWidget *parent, bool avs2yuv, const SysinfoModel *const sysinfo, const OptionsModel *const options, const PreferencesModel *const preferences)
47 QDialog(parent),
48 m_avs2yuv(avs2yuv),
49 m_sysinfo(sysinfo),
50 m_preferences(preferences),
51 m_options(options),
52 m_process(new QProcess()),
53 ui(new Ui::HelpDialog())
55 //Init the dialog, from the .ui file
56 ui->setupUi(this);
57 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
59 //Fix size
60 setMinimumSize(size());
62 //Prepare process
63 m_process->setReadChannelMode(QProcess::MergedChannels);
64 m_process->setReadChannel(QProcess::StandardOutput);
65 connect(m_process, SIGNAL(readyRead()), this, SLOT(readyRead()));
66 connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished()));
68 m_startAgain = true;
71 HelpDialog::~HelpDialog(void)
73 delete m_process;
74 delete ui;
77 ///////////////////////////////////////////////////////////////////////////////
78 // Events
79 ///////////////////////////////////////////////////////////////////////////////
81 void HelpDialog::showEvent(QShowEvent *event)
83 ui->logo_x264->setHidden(m_avs2yuv);
84 ui->logo_avisynth->setVisible(m_avs2yuv);
86 QDialog::showEvent(event);
88 m_startAgain = true;
90 if(!m_avs2yuv)
92 m_process->start(EncoderFactory::getEncoderInfo(m_options->encType()).getBinaryPath(m_sysinfo, m_options->encArch(), m_options->encVariant()), QStringList() << "--version");
94 else
96 m_process->start(SourceFactory::getSourceInfo(SourceFactory::SourceType_AVS).getBinaryPath(m_sysinfo, m_preferences->getPrefer64BitSource() && m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64)), QStringList());
99 if(!m_process->waitForStarted())
101 ui->plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
105 void HelpDialog::closeEvent(QCloseEvent *e)
107 if(m_process->state() != QProcess::NotRunning)
109 e->ignore();
110 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
111 return;
114 QDialog::closeEvent(e);
117 ///////////////////////////////////////////////////////////////////////////////
118 // Slots
119 ///////////////////////////////////////////////////////////////////////////////
121 void HelpDialog::readyRead(void)
123 while(m_process->canReadLine())
125 QString line = QString::fromLatin1(m_process->readLine());
126 while(line.endsWith('\r') || line.endsWith('\n'))
128 line = line.left(line.length() - 1);
130 ui->plainTextEdit->appendPlainText(line);
134 void HelpDialog::finished(void)
136 if(m_startAgain)
138 m_startAgain = false;
139 if(!m_avs2yuv)
141 const AbstractEncoderInfo &encInfo = EncoderFactory::getEncoderInfo(m_options->encType());
142 m_process->start(encInfo.getBinaryPath(m_sysinfo, m_options->encArch(), m_options->encVariant()), QStringList() << encInfo.getHelpCommand());
143 ui->plainTextEdit->appendPlainText("\n--------\n");
145 if(!m_process->waitForStarted())
147 ui->plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
151 else
153 ui->plainTextEdit->verticalScrollBar()->setSliderPosition(0);