OSDN Git Service

1fbe89a83b957883a13a550aa16187bb94a79a4f
[x264-launcher/x264-launcher.git] / src / win_preferences.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_preferences.h"
23
24 #include "global.h"
25 #include "model_preferences.h"
26
27 #include <QSettings>
28 #include <QDesktopServices>
29 #include <QMouseEvent>
30 #include <QMessageBox>
31
32 #define UPDATE_CHECKBOX(CHKBOX, VALUE, BLOCK) do \
33 { \
34         if((BLOCK)) { (CHKBOX)->blockSignals(true); } \
35         if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->click(); \
36         if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->setChecked(VALUE); \
37         if((BLOCK)) { (CHKBOX)->blockSignals(false); } \
38 } \
39 while(0)
40
41 #define UPDATE_COMBOBOX(COBOX, VALUE, DEFAULT) do \
42 { \
43         const int _cnt = (COBOX)->count(); \
44         const int _val = (VALUE); \
45         const int _def = (DEFAULT); \
46         for(int _i = 0; _i < _cnt; _i++) \
47         { \
48                 const int _current = (COBOX)->itemData(_i).toInt(); \
49                 if((_current == _val) || (_current == _def)) \
50                 { \
51                         (COBOX)->setCurrentIndex(_i); \
52                         if((_current == _val)) break; \
53                 } \
54         } \
55 } \
56 while(0)
57
58 PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64)
59 :
60         QDialog(parent),
61         m_x64(x64)
62 {
63         setupUi(this);
64         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
65         setFixedSize(minimumSize());
66         x264_enable_close_button(this, false);
67         
68         comboBoxPriority->setItemData(0, QVariant::fromValue( 1)); //Above Normal
69         comboBoxPriority->setItemData(1, QVariant::fromValue( 0)); //Normal
70         comboBoxPriority->setItemData(2, QVariant::fromValue(-1)); //Below Normal
71         comboBoxPriority->setItemData(3, QVariant::fromValue(-2)); //Idle
72
73         labelRunNextJob->installEventFilter(this);
74         labelUse10BitEncoding->installEventFilter(this);
75         labelUse64BitAvs2YUV->installEventFilter(this);
76         labelShutdownComputer->installEventFilter(this);
77         labelSaveLogFiles->installEventFilter(this);
78         labelSaveToSourceFolder->installEventFilter(this);
79         labelEnableSounds->installEventFilter(this);
80         labelDisableWarnings->installEventFilter(this);
81
82         connect(resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
83         connect(checkUse10BitEncoding, SIGNAL(toggled(bool)), this, SLOT(use10BitEncodingToggled(bool)));
84         connect(checkDisableWarnings, SIGNAL(toggled(bool)), this, SLOT(disableWarningsToggled(bool)));
85         
86         m_preferences = preferences;
87 }
88
89 PreferencesDialog::~PreferencesDialog(void)
90 {
91 }
92
93 void PreferencesDialog::showEvent(QShowEvent *event)
94 {
95         if(event) QDialog::showEvent(event);
96         
97         UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob(), false);
98         UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer(), false);
99         UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit(), false);
100         UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles(), false);
101         UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath(), false);
102         UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds(), false);
103         UPDATE_CHECKBOX(checkDisableWarnings, m_preferences->disableWarnings(), true);
104         UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding(), true);
105
106         spinBoxJobCount->setValue(m_preferences->maxRunningJobCount());
107         
108         UPDATE_COMBOBOX(comboBoxPriority, qBound(-2, m_preferences->processPriority(), 1), 0);
109         
110         checkUse64BitAvs2YUV->setEnabled(m_x64);
111         labelUse64BitAvs2YUV->setEnabled(m_x64);
112 }
113
114 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
115 {
116         emulateMouseEvent(o, e, labelRunNextJob, checkRunNextJob);
117         emulateMouseEvent(o, e, labelShutdownComputer, checkShutdownComputer);
118         emulateMouseEvent(o, e, labelUse10BitEncoding, checkUse10BitEncoding);
119         emulateMouseEvent(o, e, labelUse64BitAvs2YUV, checkUse64BitAvs2YUV);
120         emulateMouseEvent(o, e, labelSaveLogFiles, checkSaveLogFiles);
121         emulateMouseEvent(o, e, labelSaveToSourceFolder, checkSaveToSourceFolder);
122         emulateMouseEvent(o, e, labelEnableSounds, checkEnableSounds);
123         emulateMouseEvent(o, e, labelDisableWarnings, checkDisableWarnings);
124         return false;
125 }
126
127 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
128 {
129         if(object == source)
130         {
131                 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
132                 {
133                         if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
134                         {
135                                 qApp->postEvent(target, new QMouseEvent
136                                 (
137                                         event->type(),
138                                         qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
139                                         Qt::LeftButton,
140                                         0, 0
141                                 ));
142                         }
143                 }
144         }
145 }
146
147 void PreferencesDialog::done(int n)
148 {
149         m_preferences->setAutoRunNextJob(checkRunNextJob->isChecked());
150         m_preferences->setShutdownComputer(checkShutdownComputer->isChecked());
151         m_preferences->setUse10BitEncoding(checkUse10BitEncoding->isChecked());
152         m_preferences->setUseAvisyth64Bit(checkUse64BitAvs2YUV->isChecked());
153         m_preferences->setSaveLogFiles(checkSaveLogFiles->isChecked());
154         m_preferences->setSaveToSourcePath(checkSaveToSourceFolder->isChecked());
155         m_preferences->setMaxRunningJobCount(spinBoxJobCount->value());
156         m_preferences->setProcessPriority(comboBoxPriority->itemData(comboBoxPriority->currentIndex()).toInt());
157         m_preferences->setEnableSounds(checkEnableSounds->isChecked());
158         m_preferences->setDisableWarnings(checkDisableWarnings->isChecked());
159
160         PreferencesModel::savePreferences(m_preferences);
161         QDialog::done(n);
162 }
163
164 void PreferencesDialog::resetButtonPressed(void)
165 {
166         PreferencesModel::initPreferences(m_preferences);
167         showEvent(NULL);
168 }
169
170 void PreferencesDialog::use10BitEncodingToggled(bool checked)
171 {
172         if(checked)
173         {
174                 QString text;
175                 text += QString("<nobr>%1</nobr><br>").arg(tr("Please note that 10&minus;Bit H.264 streams are <b>not</b> currently supported by hardware (standalone) players!"));
176                 text += QString("<nobr>%1</nobr><br>").arg(tr("To play such streams, you will need an <i>up&minus;to&minus;date</i> ffdshow&minus;tryouts, CoreAVC 3.x or another supported s/w decoder."));
177                 text += QString("<nobr>%1</nobr><br>").arg(tr("Also be aware that hardware&minus;acceleration (CUDA, DXVA, etc) usually will <b>not</b> work with 10&minus;Bit H.264 streams."));
178                 
179                 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text.replace("-", "&minus;"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
180                 {
181                         UPDATE_CHECKBOX(checkUse10BitEncoding, false, true);
182                 }
183         }
184 }
185
186 void PreferencesDialog::disableWarningsToggled(bool checked)
187 {
188         if(checked)
189         {
190                 QString text;
191                 text += QString("<nobr>%1</nobr><br>").arg(tr("Please note that Avisynth and/or VapourSynth support might be unavailable <b>without</b> any notice!"));
192                 text += QString("<nobr>%1</nobr><br>").arg(tr("Also note that the CLI option <tt>--console</tt> may be used to get more diagnostic infomation."));
193
194                 if(QMessageBox::warning(this, tr("Avisynth/VapourSynth Warnings"), text.replace("-", "&minus;"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
195                 {
196                         UPDATE_CHECKBOX(checkDisableWarnings, false, true);
197                 }
198         }
199 }