OSDN Git Service

Removed "use 10-Bit encoding" from preferences. Also updated Help screen to show...
[x264-launcher/x264-launcher.git] / src / win_help.cpp
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 #include "win_help.h"
23 #include "uic_win_help.h"
24
25 #include "global.h"
26 #include "model_options.h"
27
28 #include <QProcess>
29 #include <QScrollBar>
30 #include <QTimer>
31
32 #define AVS2_BINARY(BIN_DIR) QString("%1/%2/avs2yuv_%2.exe").arg((BIN_DIR), "x86")
33
34 static QString X264_BINARY(const QString &binDir, const OptionsModel *options)
35 {
36         QString baseName, arch, variant;
37
38         switch(options->encType())
39         {
40                 case OptionsModel::EncType_X264: baseName = "x264"; break;
41                 case OptionsModel::EncType_X265: baseName = "x265"; break;
42         }
43         
44         switch(options->encArch())
45         {
46                 case OptionsModel::EncArch_x32: arch = "x86"; break;
47                 case OptionsModel::EncArch_x64: arch = "x64"; break;
48         }
49
50         switch(options->encVariant())
51         {
52                 case OptionsModel::EncVariant_LoBit: variant = "8bit"; break;
53                 case OptionsModel::EncVariant_HiBit: variant = (options->encType() == OptionsModel::EncType_X265) ? "16bit" : "10bit"; break;
54         }
55
56         return QString("%1/%2/x264_%3_%2.exe").arg((binDir), arch, variant);
57 }
58
59 ///////////////////////////////////////////////////////////////////////////////
60 // Constructor & Destructor
61 ///////////////////////////////////////////////////////////////////////////////
62
63 HelpDialog::HelpDialog(QWidget *parent, bool avs2yuv, const OptionsModel *options)
64 :
65         QDialog(parent),
66         m_appDir(QApplication::applicationDirPath() + "/toolset"),
67         m_avs2yuv(avs2yuv),
68         m_options(options),
69         m_process(new QProcess()),
70         ui(new Ui::HelpDialog())
71 {
72         //Init the dialog, from the .ui file
73         ui->setupUi(this);
74         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
75
76         //Fix size
77         setMinimumSize(size());
78
79         //Prepare process
80         m_process->setReadChannelMode(QProcess::MergedChannels);
81         m_process->setReadChannel(QProcess::StandardOutput);
82         connect(m_process, SIGNAL(readyRead()), this, SLOT(readyRead()));
83         connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished()));
84
85         m_startAgain = true;
86 }
87
88 HelpDialog::~HelpDialog(void)
89 {
90         delete m_process;
91         delete ui;
92 }
93
94 ///////////////////////////////////////////////////////////////////////////////
95 // Events
96 ///////////////////////////////////////////////////////////////////////////////
97
98 void HelpDialog::showEvent(QShowEvent *event)
99 {
100         ui->logo_x264->setHidden(m_avs2yuv);
101         ui->logo_avisynth->setVisible(m_avs2yuv);
102         
103         QDialog::showEvent(event);
104         
105         m_startAgain = true;
106
107         if(!m_avs2yuv)
108         {
109                 m_process->start(X264_BINARY(m_appDir, m_options), QStringList() << "--version");
110         }
111         else
112         {
113                 m_process->start(AVS2_BINARY(m_appDir), QStringList());
114         }
115
116         if(!m_process->waitForStarted())
117         {
118                 ui->plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
119         }
120 }
121
122 void HelpDialog::closeEvent(QCloseEvent *e)
123 {
124         if(m_process->state() != QProcess::NotRunning)
125         {
126                 e->ignore();
127                 x264_beep(x264_beep_warning);
128                 return;
129         }
130
131         QDialog::closeEvent(e);
132 }
133
134 ///////////////////////////////////////////////////////////////////////////////
135 // Slots
136 ///////////////////////////////////////////////////////////////////////////////
137
138 void HelpDialog::readyRead(void)
139 {
140         while(m_process->canReadLine())
141         {
142                 QString line = QString::fromLatin1(m_process->readLine());
143                 while(line.endsWith('\r') || line.endsWith('\n'))
144                 {
145                         line = line.left(line.length() - 1);
146                 }
147                 ui->plainTextEdit->appendPlainText(line);
148         }
149 }
150
151 void HelpDialog::finished(void)
152 {
153         if(m_startAgain)
154         {
155                 m_startAgain = false;
156                 if(!m_avs2yuv)
157                 {
158                         m_process->start(X264_BINARY(m_appDir, m_options), QStringList() << "--fullhelp");
159                         ui->plainTextEdit->appendPlainText("\n--------\n");
160
161                         if(!m_process->waitForStarted())
162                         {
163                                 ui->plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
164                         }
165                 }
166         }
167         else
168         {
169                 ui->plainTextEdit->verticalScrollBar()->setSliderPosition(0);
170         }
171 }