1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 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);
52 connect(resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
53 connect(checkUse10BitEncoding, SIGNAL(toggled(bool)), this, SLOT(use10BitEncodingToggled(bool)));
55 m_preferences = preferences;
58 PreferencesDialog::~PreferencesDialog(void)
62 void PreferencesDialog::showEvent(QShowEvent *event)
64 if(event) QDialog::showEvent(event);
66 UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob);
67 UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer);
68 UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit);
69 UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles);
71 checkUse10BitEncoding->blockSignals(true);
72 UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding);
73 checkUse10BitEncoding->blockSignals(false);
75 spinBoxJobCount->setValue(m_preferences->maxRunningJobCount);
77 checkUse64BitAvs2YUV->setEnabled(m_x64);
78 labelUse64BitAvs2YUV->setEnabled(m_x64);
81 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
83 emulateMouseEvent(o, e, labelRunNextJob, checkRunNextJob);
84 emulateMouseEvent(o, e, labelShutdownComputer, checkShutdownComputer);
85 emulateMouseEvent(o, e, labelUse10BitEncoding, checkUse10BitEncoding);
86 emulateMouseEvent(o, e, labelUse64BitAvs2YUV, checkUse64BitAvs2YUV);
87 emulateMouseEvent(o, e, labelSaveLogFiles, checkSaveLogFiles);
91 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
95 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
97 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
99 qApp->postEvent(target, new QMouseEvent
102 qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
111 void PreferencesDialog::done(int n)
113 m_preferences->autoRunNextJob = checkRunNextJob->isChecked();
114 m_preferences->shutdownComputer = checkShutdownComputer->isChecked();
115 m_preferences->use10BitEncoding = checkUse10BitEncoding->isChecked();
116 m_preferences->useAvisyth64Bit = checkUse64BitAvs2YUV->isChecked();
117 m_preferences->saveLogFiles = checkSaveLogFiles->isChecked();
118 m_preferences->maxRunningJobCount = spinBoxJobCount->value();
120 savePreferences(m_preferences);
124 void PreferencesDialog::resetButtonPressed(void)
126 initPreferences(m_preferences);
130 void PreferencesDialog::use10BitEncodingToggled(bool checked)
135 text += tr("<nobr>Please note that 10−Bit H.264 streams are <b>not</b> currently supported by hardware (standalone) players!</nobr><br>");
136 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>");
137 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>");
139 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text, tr("Continue"), tr("Revert"), QString(), 1) != 0)
141 UPDATE_CHECKBOX(checkUse10BitEncoding, false);
146 ///////////////////////////////////////////////////////////////////////////////
148 ///////////////////////////////////////////////////////////////////////////////
150 void PreferencesDialog::initPreferences(Preferences *preferences)
152 memset(preferences, 0, sizeof(Preferences));
154 preferences->autoRunNextJob = true;
155 preferences->maxRunningJobCount = 1;
156 preferences->shutdownComputer = false;
157 preferences->use10BitEncoding = false;
158 preferences->useAvisyth64Bit = false;
159 preferences->saveLogFiles = false;
162 void PreferencesDialog::loadPreferences(Preferences *preferences)
164 const QString appDir = x264_data_path();
165 QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
167 Preferences defaults;
168 initPreferences(&defaults);
170 settings.beginGroup("preferences");
171 preferences->autoRunNextJob = settings.value("auto_run_next_job", QVariant(defaults.autoRunNextJob)).toBool();
172 preferences->maxRunningJobCount = qBound(1U, settings.value("max_running_job_count", QVariant(defaults.maxRunningJobCount)).toUInt(), 16U);
173 preferences->shutdownComputer = settings.value("shutdown_computer_on_completion", QVariant(defaults.shutdownComputer)).toBool();
174 preferences->use10BitEncoding = settings.value("use_10bit_encoding", QVariant(defaults.use10BitEncoding)).toBool();
175 preferences->useAvisyth64Bit = settings.value("use_64bit_avisynth", QVariant(defaults.useAvisyth64Bit)).toBool();
176 preferences->saveLogFiles = settings.value("save_log_files", QVariant(defaults.saveLogFiles)).toBool();
179 void PreferencesDialog::savePreferences(Preferences *preferences)
181 const QString appDir = x264_data_path();
182 QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
184 settings.beginGroup("preferences");
185 settings.setValue("auto_run_next_job", preferences->autoRunNextJob);
186 settings.setValue("shutdown_computer_on_completion", preferences->shutdownComputer);
187 settings.setValue("max_running_job_count", preferences->maxRunningJobCount);
188 settings.setValue("use_10bit_encoding", preferences->use10BitEncoding);
189 settings.setValue("use_64bit_avisynth", preferences->useAvisyth64Bit);
190 settings.setValue("save_log_files", preferences->saveLogFiles);