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>
30 #define UPDATE_CHECKBOX(CHKBOX, VALUE) \
32 if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->click(); \
33 if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->setChecked(VALUE); \
36 PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences, bool x64)
42 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
43 setFixedSize(minimumSize());
45 labelRunNextJob->installEventFilter(this);
46 labelUse64BitAvs2YUV->installEventFilter(this);
47 labelShutdownComputer->installEventFilter(this);
49 connect(resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
51 m_preferences = preferences;
54 PreferencesDialog::~PreferencesDialog(void)
58 void PreferencesDialog::showEvent(QShowEvent *event)
60 if(event) QDialog::showEvent(event);
62 UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob);
63 UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer);
64 UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit);
66 spinBoxJobCount->setValue(m_preferences->maxRunningJobCount);
68 checkUse64BitAvs2YUV->setEnabled(m_x64);
69 labelUse64BitAvs2YUV->setEnabled(m_x64);
72 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
74 emulateMouseEvent(o, e, labelRunNextJob, checkRunNextJob);
75 emulateMouseEvent(o, e, labelShutdownComputer, checkShutdownComputer);
76 emulateMouseEvent(o, e, labelUse64BitAvs2YUV, checkUse64BitAvs2YUV);
80 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
84 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
86 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
88 qApp->postEvent(target, new QMouseEvent
91 qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
100 void PreferencesDialog::done(int n)
102 m_preferences->autoRunNextJob = checkRunNextJob->isChecked();
103 m_preferences->shutdownComputer = checkShutdownComputer->isChecked();
104 m_preferences->useAvisyth64Bit = checkUse64BitAvs2YUV->isChecked();
105 m_preferences->maxRunningJobCount = spinBoxJobCount->value();
107 savePreferences(m_preferences);
111 void PreferencesDialog::resetButtonPressed(void)
113 initPreferences(m_preferences);
117 ///////////////////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////////////////
121 void PreferencesDialog::initPreferences(Preferences *preferences)
123 memset(preferences, 0, sizeof(Preferences));
125 preferences->autoRunNextJob = true;
126 preferences->maxRunningJobCount = 1;
127 preferences->shutdownComputer = false;
128 preferences->useAvisyth64Bit = false;
131 void PreferencesDialog::loadPreferences(Preferences *preferences)
133 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
134 QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
136 Preferences defaults;
137 initPreferences(&defaults);
139 settings.beginGroup("preferences");
140 preferences->autoRunNextJob = settings.value("auto_run_next_job", QVariant(defaults.autoRunNextJob)).toBool();
141 preferences->maxRunningJobCount = qBound(1U, settings.value("max_running_job_count", QVariant(defaults.maxRunningJobCount)).toUInt(), 16U);
142 preferences->shutdownComputer = settings.value("shutdown_computer_on_completion", QVariant(defaults.shutdownComputer)).toBool();
143 preferences->useAvisyth64Bit = settings.value("use_64bit_avisynth", QVariant(defaults.useAvisyth64Bit)).toBool();
146 void PreferencesDialog::savePreferences(Preferences *preferences)
148 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
149 QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
151 settings.beginGroup("preferences");
152 settings.setValue("auto_run_next_job", preferences->autoRunNextJob);
153 settings.setValue("shutdown_computer_on_completion", preferences->shutdownComputer);
154 settings.setValue("max_running_job_count", preferences->maxRunningJobCount);
155 settings.setValue("use_64bit_avisynth", preferences->useAvisyth64Bit);