1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2018 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"
23 #include "UIC_win_preferences.h"
27 #include "model_preferences.h"
28 #include "model_sysinfo.h"
31 #include <MUtils/GUI.h>
35 #include <QDesktopServices>
36 #include <QMouseEvent>
37 #include <QMessageBox>
39 static inline void UPDATE_CHECKBOX(QCheckBox *const chkbox, const bool value, const bool block = false)
41 if(block) { chkbox->blockSignals(true); }
42 if(chkbox->isChecked() != value) chkbox->click();
43 if(chkbox->isChecked() != value) chkbox->setChecked(value);
44 if(block) { chkbox->blockSignals(false); }
47 static inline void UPDATE_COMBOBOX(QComboBox *const cobox, const int value, const int defVal)
49 const int count = cobox->count();
50 for(int i = 0; i < count; i++)
52 const int current = cobox->itemData(i).toInt();
53 if((current == value) || (current == defVal))
55 cobox->setCurrentIndex(i);
56 if((current == value)) break;
61 PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, const SysinfoModel *sysinfo)
65 ui(new Ui::PreferencesDialog())
68 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
69 setFixedSize(minimumSize());
70 MUtils::GUI::enable_close_button(this, false);
72 ui->comboBoxPriority->setItemData(0, QVariant::fromValue( 1)); //Above Normal
73 ui->comboBoxPriority->setItemData(1, QVariant::fromValue( 0)); //Normal
74 ui->comboBoxPriority->setItemData(2, QVariant::fromValue(-1)); //Below Normal
75 ui->comboBoxPriority->setItemData(3, QVariant::fromValue(-2)); //Idle
77 ui->labelRunNextJob ->installEventFilter(this);
78 ui->labelUse64BitAvs2YUV ->installEventFilter(this);
79 ui->labelShutdownComputer ->installEventFilter(this);
80 ui->labelSaveLogFiles ->installEventFilter(this);
81 ui->labelSaveToSourceFolder->installEventFilter(this);
82 ui->labelEnableSounds ->installEventFilter(this);
83 ui->labelDisableWarnings ->installEventFilter(this);
84 ui->labelNoUpdateReminder ->installEventFilter(this);
85 ui->labelSaveQueueNoConfirm->installEventFilter(this);
87 ui->checkBoxDummy1->installEventFilter(this);
88 ui->checkBoxDummy2->installEventFilter(this);
90 connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
91 connect(ui->checkDisableWarnings, SIGNAL(toggled(bool)), this, SLOT(disableWarningsToggled(bool)));
93 m_preferences = preferences;
96 PreferencesDialog::~PreferencesDialog(void)
101 void PreferencesDialog::showEvent(QShowEvent *event)
103 if(event) QDialog::showEvent(event);
105 UPDATE_CHECKBOX(ui->checkRunNextJob, m_preferences->getAutoRunNextJob());
106 UPDATE_CHECKBOX(ui->checkShutdownComputer, m_preferences->getShutdownComputer());
107 UPDATE_CHECKBOX(ui->checkUse64BitAvs2YUV, m_preferences->getPrefer64BitSource() && m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64));
108 UPDATE_CHECKBOX(ui->checkSaveLogFiles, m_preferences->getSaveLogFiles());
109 UPDATE_CHECKBOX(ui->checkSaveToSourceFolder, m_preferences->getSaveToSourcePath());
110 UPDATE_CHECKBOX(ui->checkEnableSounds, m_preferences->getEnableSounds());
111 UPDATE_CHECKBOX(ui->checkNoUpdateReminder, m_preferences->getNoUpdateReminder());
112 UPDATE_CHECKBOX(ui->checkDisableWarnings, m_preferences->getDisableWarnings(), true);
113 UPDATE_CHECKBOX(ui->checkSaveQueueNoConfirm, m_preferences->getSaveQueueNoConfirm());
115 ui->spinBoxJobCount->setValue(m_preferences->getMaxRunningJobCount());
116 UPDATE_COMBOBOX(ui->comboBoxPriority, qBound(-2, m_preferences->getProcessPriority(), 1), 0);
118 const bool hasX64 = m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64);
119 ui->checkUse64BitAvs2YUV->setEnabled(hasX64);
120 ui->labelUse64BitAvs2YUV->setEnabled(hasX64);
123 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
125 if(e->type() == QEvent::Paint)
127 if(o == ui->checkBoxDummy1) return true;
128 if(o == ui->checkBoxDummy2) return true;
130 else if((e->type() == QEvent::MouseButtonPress) || (e->type() == QEvent::MouseButtonRelease))
132 emulateMouseEvent(o, e, ui->labelRunNextJob, ui->checkRunNextJob);
133 emulateMouseEvent(o, e, ui->labelShutdownComputer, ui->checkShutdownComputer);
134 emulateMouseEvent(o, e, ui->labelUse64BitAvs2YUV, ui->checkUse64BitAvs2YUV);
135 emulateMouseEvent(o, e, ui->labelSaveLogFiles, ui->checkSaveLogFiles);
136 emulateMouseEvent(o, e, ui->labelSaveToSourceFolder, ui->checkSaveToSourceFolder);
137 emulateMouseEvent(o, e, ui->labelEnableSounds, ui->checkEnableSounds);
138 emulateMouseEvent(o, e, ui->labelDisableWarnings, ui->checkDisableWarnings);
139 emulateMouseEvent(o, e, ui->labelNoUpdateReminder, ui->checkNoUpdateReminder);
140 emulateMouseEvent(o, e, ui->labelSaveQueueNoConfirm, ui->checkSaveQueueNoConfirm);
145 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
149 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
151 qApp->postEvent(target, new QMouseEvent
154 (qApp->widgetAt(mouseEvent->globalPos()) == source) ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
162 void PreferencesDialog::done(int n)
164 m_preferences->setAutoRunNextJob (ui->checkRunNextJob->isChecked());
165 m_preferences->setShutdownComputer (ui->checkShutdownComputer->isChecked());
166 m_preferences->setPrefer64BitSource (ui->checkUse64BitAvs2YUV->isChecked());
167 m_preferences->setSaveLogFiles (ui->checkSaveLogFiles->isChecked());
168 m_preferences->setSaveToSourcePath (ui->checkSaveToSourceFolder->isChecked());
169 m_preferences->setMaxRunningJobCount(ui->spinBoxJobCount->value());
170 m_preferences->setProcessPriority (ui->comboBoxPriority->itemData(ui->comboBoxPriority->currentIndex()).toInt());
171 m_preferences->setEnableSounds (ui->checkEnableSounds->isChecked());
172 m_preferences->setDisableWarnings (ui->checkDisableWarnings->isChecked());
173 m_preferences->setNoUpdateReminder (ui->checkNoUpdateReminder->isChecked());
174 m_preferences->setSaveQueueNoConfirm(ui->checkSaveQueueNoConfirm->isChecked());
176 PreferencesModel::savePreferences(m_preferences);
180 void PreferencesDialog::resetButtonPressed(void)
182 PreferencesModel::initPreferences(m_preferences);
186 void PreferencesDialog::disableWarningsToggled(bool checked)
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."));
194 if(QMessageBox::warning(this, tr("Avisynth/VapourSynth Warnings"), text.replace("-", "−"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
196 UPDATE_CHECKBOX(ui->checkDisableWarnings, false, true);