OSDN Git Service

Fixed a small bug: When adding multiple files and enabling the "Apply To All Files...
[x264-launcher/x264-launcher.git] / src / win_help.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 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 "global.h"
24
25 #include <QProcess>
26 #include <QScrollBar>
27 #include <QTimer>
28
29 #define X264_BINARY(BIN_DIR, IS_10BIT, IS_X64) QString("%1/x264_%2_%3.exe").arg((BIN_DIR), ((IS_10BIT) ? "10bit" : "8bit"), ((IS_X64) ? "x64" : "x86"))
30
31 ///////////////////////////////////////////////////////////////////////////////
32 // Constructor & Destructor
33 ///////////////////////////////////////////////////////////////////////////////
34
35 HelpDialog::HelpDialog(QWidget *parent, bool avs2yuv, bool x64supported, bool use10BitEncoding)
36 :
37         QDialog(parent),
38         m_appDir(QApplication::applicationDirPath() + "/toolset"),
39         m_avs2yuv(avs2yuv),
40         m_x64supported(x64supported),
41         m_use10BitEncoding(use10BitEncoding),
42         m_process(new QProcess())
43 {
44         //Init the dialog, from the .ui file
45         setupUi(this);
46         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
47
48         //Fix size
49         setMinimumSize(size());
50
51         //Prepare process
52         m_process->setReadChannelMode(QProcess::MergedChannels);
53         m_process->setReadChannel(QProcess::StandardOutput);
54         connect(m_process, SIGNAL(readyRead()), this, SLOT(readyRead()));
55         connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished()));
56
57         m_startAgain = true;
58 }
59
60 HelpDialog::~HelpDialog(void)
61 {
62         delete m_process;
63 }
64
65 ///////////////////////////////////////////////////////////////////////////////
66 // Events
67 ///////////////////////////////////////////////////////////////////////////////
68
69 void HelpDialog::showEvent(QShowEvent *event)
70 {
71         logo_x264->setHidden(m_avs2yuv);
72         logo_avisynth->setVisible(m_avs2yuv);
73         
74         QDialog::showEvent(event);
75         
76         m_startAgain = true;
77
78         if(!m_avs2yuv)
79         {
80                 m_process->start(X264_BINARY(m_appDir, m_use10BitEncoding, m_x64supported), QStringList() << "--version");
81         }
82         else
83         {
84                 m_process->start(QString("%1/%2.exe").arg(m_appDir, m_x64supported ? "avs2yuv_x64" : "avs2yuv_x86"), QStringList());
85         }
86
87         if(!m_process->waitForStarted())
88         {
89                 plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
90         }
91 }
92
93 void HelpDialog::closeEvent(QCloseEvent *e)
94 {
95         if(m_process->state() != QProcess::NotRunning)
96         {
97                 e->ignore();
98                 MessageBeep(MB_ICONWARNING);
99                 return;
100         }
101
102         QDialog::closeEvent(e);
103 }
104
105 ///////////////////////////////////////////////////////////////////////////////
106 // Slots
107 ///////////////////////////////////////////////////////////////////////////////
108
109 void HelpDialog::readyRead(void)
110 {
111         while(m_process->canReadLine())
112         {
113                 QString line = QString::fromLatin1(m_process->readLine());
114                 while(line.endsWith('\r') || line.endsWith('\n'))
115                 {
116                         line = line.left(line.length() - 1);
117                 }
118                 plainTextEdit->appendPlainText(line);
119         }
120 }
121
122 void HelpDialog::finished(void)
123 {
124         if(m_startAgain)
125         {
126                 m_startAgain = false;
127                 if(!m_avs2yuv)
128                 {
129                         m_process->start(X264_BINARY(m_appDir, m_use10BitEncoding, m_x64supported), QStringList() << "--fullhelp");
130                         plainTextEdit->appendPlainText("\n--------\n");
131
132                         if(!m_process->waitForStarted())
133                         {
134                                 plainTextEdit->appendPlainText(tr("Failed to create x264 process :-("));
135                         }
136                 }
137         }
138         else
139         {
140                 plainTextEdit->verticalScrollBar()->setSliderPosition(0);
141         }
142 }