OSDN Git Service

Removed a lot of old cruft and use MUtils functions where possible.
[x264-launcher/x264-launcher.git] / src / win_help.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2015 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 #include "win_help.h"
23 #include "UIC_win_help.h"
24
25 //Internal
26 #include "global.h"
27 #include "model_options.h"
28 #include "binaries.h"
29
30 //MUtils
31 #include <MUtils/Sound.h>
32
33 //Qt
34 #include <QProcess>
35 #include <QScrollBar>
36 #include <QTimer>
37
38 ///////////////////////////////////////////////////////////////////////////////
39 // Constructor & Destructor
40 ///////////////////////////////////////////////////////////////////////////////
41
42 HelpDialog::HelpDialog(QWidget *parent, bool avs2yuv, const SysinfoModel *const sysinfo, const OptionsModel *const options, const PreferencesModel *const preferences)
43 :
44         QDialog(parent),
45         m_avs2yuv(avs2yuv),
46         m_sysinfo(sysinfo),
47         m_preferences(preferences),
48         m_options(options),
49         m_process(new QProcess()),
50         ui(new Ui::HelpDialog())
51 {
52         //Init the dialog, from the .ui file
53         ui->setupUi(this);
54         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
55
56         //Fix size
57         setMinimumSize(size());
58
59         //Prepare process
60         m_process->setReadChannelMode(QProcess::MergedChannels);
61         m_process->setReadChannel(QProcess::StandardOutput);
62         connect(m_process, SIGNAL(readyRead()), this, SLOT(readyRead()));
63         connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished()));
64
65         m_startAgain = true;
66 }
67
68 HelpDialog::~HelpDialog(void)
69 {
70         delete m_process;
71         delete ui;
72 }
73
74 ///////////////////////////////////////////////////////////////////////////////
75 // Events
76 ///////////////////////////////////////////////////////////////////////////////
77
78 void HelpDialog::showEvent(QShowEvent *event)
79 {
80         ui->logo_x264->setHidden(m_avs2yuv);
81         ui->logo_avisynth->setVisible(m_avs2yuv);
82         
83         QDialog::showEvent(event);
84         
85         m_startAgain = true;
86
87         if(!m_avs2yuv)
88         {
89                 m_process->start(ENC_BINARY(m_sysinfo, m_options), QStringList() << "--version");
90         }
91         else
92         {
93                 m_process->start(AVS_BINARY(m_sysinfo, m_preferences), QStringList());
94         }
95
96         if(!m_process->waitForStarted())
97         {
98                 ui->plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
99         }
100 }
101
102 void HelpDialog::closeEvent(QCloseEvent *e)
103 {
104         if(m_process->state() != QProcess::NotRunning)
105         {
106                 e->ignore();
107                 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
108                 return;
109         }
110
111         QDialog::closeEvent(e);
112 }
113
114 ///////////////////////////////////////////////////////////////////////////////
115 // Slots
116 ///////////////////////////////////////////////////////////////////////////////
117
118 void HelpDialog::readyRead(void)
119 {
120         while(m_process->canReadLine())
121         {
122                 QString line = QString::fromLatin1(m_process->readLine());
123                 while(line.endsWith('\r') || line.endsWith('\n'))
124                 {
125                         line = line.left(line.length() - 1);
126                 }
127                 ui->plainTextEdit->appendPlainText(line);
128         }
129 }
130
131 void HelpDialog::finished(void)
132 {
133         if(m_startAgain)
134         {
135                 m_startAgain = false;
136                 if(!m_avs2yuv)
137                 {
138                         m_process->start(ENC_BINARY(m_sysinfo, m_options), QStringList() << "--fullhelp");
139                         ui->plainTextEdit->appendPlainText("\n--------\n");
140
141                         if(!m_process->waitForStarted())
142                         {
143                                 ui->plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
144                         }
145                 }
146         }
147         else
148         {
149                 ui->plainTextEdit->verticalScrollBar()->setSliderPosition(0);
150         }
151 }