1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "win_preferences.h"
27 #include <QDesktopServices>
28 #include <QMouseEvent>
29 #include <QMessageBox>
31 #define UPDATE_CHECKBOX(CHKBOX, VALUE) \
33 if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->click(); \
34 if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->setChecked(VALUE); \
37 PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences, bool x64)
43 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
44 setFixedSize(minimumSize());
46 labelRunNextJob->installEventFilter(this);
47 labelUse10BitEncoding->installEventFilter(this);
48 labelUse64BitAvs2YUV->installEventFilter(this);
49 labelShutdownComputer->installEventFilter(this);
50 labelSaveLogFiles->installEventFilter(this);
51 labelSaveToSourceFolder->installEventFilter(this);
52 labelEnableSounds->installEventFilter(this);
54 connect(resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
55 connect(checkUse10BitEncoding, SIGNAL(toggled(bool)), this, SLOT(use10BitEncodingToggled(bool)));
57 m_preferences = preferences;
60 PreferencesDialog::~PreferencesDialog(void)
64 void PreferencesDialog::showEvent(QShowEvent *event)
66 if(event) QDialog::showEvent(event);
68 UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob);
69 UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer);
70 UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit);
71 UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles);
72 UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath);
73 UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds);
75 checkUse10BitEncoding->blockSignals(true);
76 UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding);
77 checkUse10BitEncoding->blockSignals(false);
79 spinBoxJobCount->setValue(m_preferences->maxRunningJobCount);
80 comboBoxPriority->setCurrentIndex(qBound(0U, m_preferences->processPriority, 2U));
82 checkUse64BitAvs2YUV->setEnabled(m_x64);
83 labelUse64BitAvs2YUV->setEnabled(m_x64);
86 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
88 emulateMouseEvent(o, e, labelRunNextJob, checkRunNextJob);
89 emulateMouseEvent(o, e, labelShutdownComputer, checkShutdownComputer);
90 emulateMouseEvent(o, e, labelUse10BitEncoding, checkUse10BitEncoding);
91 emulateMouseEvent(o, e, labelUse64BitAvs2YUV, checkUse64BitAvs2YUV);
92 emulateMouseEvent(o, e, labelSaveLogFiles, checkSaveLogFiles);
93 emulateMouseEvent(o, e, labelSaveToSourceFolder, checkSaveToSourceFolder);
94 emulateMouseEvent(o, e, labelEnableSounds, checkEnableSounds);
98 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
102 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
104 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
106 qApp->postEvent(target, new QMouseEvent
109 qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
118 void PreferencesDialog::done(int n)
120 m_preferences->autoRunNextJob = checkRunNextJob->isChecked();
121 m_preferences->shutdownComputer = checkShutdownComputer->isChecked();
122 m_preferences->use10BitEncoding = checkUse10BitEncoding->isChecked();
123 m_preferences->useAvisyth64Bit = checkUse64BitAvs2YUV->isChecked();
124 m_preferences->saveLogFiles = checkSaveLogFiles->isChecked();
125 m_preferences->saveToSourcePath = checkSaveToSourceFolder->isChecked();
126 m_preferences->maxRunningJobCount = spinBoxJobCount->value();
127 m_preferences->processPriority = comboBoxPriority->currentIndex();
128 m_preferences->enableSounds = checkEnableSounds->isChecked();
130 savePreferences(m_preferences);
134 void PreferencesDialog::resetButtonPressed(void)
136 initPreferences(m_preferences);
140 void PreferencesDialog::use10BitEncodingToggled(bool checked)
145 text += tr("<nobr>Please note that 10−Bit H.264 streams are <b>not</b> currently supported by hardware (standalone) players!</nobr><br>");
146 text += tr("<nobr>To play such streams, you will need an <i>up−to−date</i> ffdshow−tryouts, CoreAVC 3.x or another supported s/w decoder.</nobr><br>");
147 text += tr("<nobr>Also be aware that hardware−acceleration (CUDA, DXVA, etc) usually will <b>not</b> work with 10−Bit H.264 streams.</nobr><br>");
149 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text, tr("Continue"), tr("Revert"), QString(), 1) != 0)
151 UPDATE_CHECKBOX(checkUse10BitEncoding, false);
156 ///////////////////////////////////////////////////////////////////////////////
158 ///////////////////////////////////////////////////////////////////////////////
160 void PreferencesDialog::initPreferences(Preferences *preferences)
162 memset(preferences, 0, sizeof(Preferences));
164 preferences->autoRunNextJob = true;
165 preferences->maxRunningJobCount = 1;
166 preferences->shutdownComputer = false;
167 preferences->use10BitEncoding = false;
168 preferences->useAvisyth64Bit = false;
169 preferences->saveLogFiles = false;
170 preferences->saveToSourcePath = false;
171 preferences->processPriority = X264_PRIORITY_BELOWNORMAL;
172 preferences->enableSounds = false;
175 void PreferencesDialog::loadPreferences(Preferences *preferences)
177 const QString appDir = x264_data_path();
178 QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
180 Preferences defaults;
181 initPreferences(&defaults);
183 settings.beginGroup("preferences");
184 preferences->autoRunNextJob = settings.value("auto_run_next_job", QVariant(defaults.autoRunNextJob)).toBool();
185 preferences->maxRunningJobCount = qBound(1U, settings.value("max_running_job_count", QVariant(defaults.maxRunningJobCount)).toUInt(), 16U);
186 preferences->shutdownComputer = settings.value("shutdown_computer_on_completion", QVariant(defaults.shutdownComputer)).toBool();
187 preferences->use10BitEncoding = settings.value("use_10bit_encoding", QVariant(defaults.use10BitEncoding)).toBool();
188 preferences->useAvisyth64Bit = settings.value("use_64bit_avisynth", QVariant(defaults.useAvisyth64Bit)).toBool();
189 preferences->saveLogFiles = settings.value("save_log_files", QVariant(defaults.saveLogFiles)).toBool();
190 preferences->saveToSourcePath = settings.value("save_to_source_path", QVariant(defaults.saveToSourcePath)).toBool();
191 preferences->processPriority = settings.value("process_priority", QVariant(defaults.processPriority)).toUInt();
192 preferences->enableSounds = settings.value("enable_sounds", QVariant(defaults.enableSounds)).toBool();
195 void PreferencesDialog::savePreferences(Preferences *preferences)
197 const QString appDir = x264_data_path();
198 QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
200 settings.beginGroup("preferences");
201 settings.setValue("auto_run_next_job", preferences->autoRunNextJob);
202 settings.setValue("shutdown_computer_on_completion", preferences->shutdownComputer);
203 settings.setValue("max_running_job_count", preferences->maxRunningJobCount);
204 settings.setValue("use_10bit_encoding", preferences->use10BitEncoding);
205 settings.setValue("use_64bit_avisynth", preferences->useAvisyth64Bit);
206 settings.setValue("save_log_files", preferences->saveLogFiles);
207 settings.setValue("save_to_source_path", preferences->saveToSourcePath);
208 settings.setValue("process_priority", preferences->processPriority);
209 settings.setValue("enable_sounds", preferences->enableSounds);