OSDN Git Service

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