1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2020 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 "model_preferences.h"
27 #include <QDesktopServices>
28 #include <QMouseEvent>
29 #include <QMessageBox>
31 ///////////////////////////////////////////////////////////////////////////////
33 #define INIT_VALUE(NAME, VAL) do \
35 preferences->set##NAME(VAL); \
39 #define STORE_VALUE(NAME) do \
41 settings.setValue(#NAME, (preferences->get##NAME())); \
45 #define LOAD_VALUE_B(NAME) do \
47 preferences->set##NAME(settings.value(#NAME, QVariant(defaults.get##NAME())).toBool()); \
51 #define LOAD_VALUE_I(NAME) do \
53 preferences->set##NAME(settings.value(#NAME, QVariant(defaults.get##NAME())).toInt()); \
57 #define LOAD_VALUE_U(NAME) do \
59 preferences->set##NAME(settings.value(#NAME, QVariant(defaults.get##NAME())).toUInt()); \
63 ///////////////////////////////////////////////////////////////////////////////
65 PreferencesModel::PreferencesModel(void)
67 initPreferences(this);
70 void PreferencesModel::initPreferences(PreferencesModel
*preferences
)
72 INIT_VALUE(AutoRunNextJob
, true );
73 INIT_VALUE(MaxRunningJobCount
, 1 );
74 INIT_VALUE(Prefer64BitSource
, false);
75 INIT_VALUE(SaveLogFiles
, false);
76 INIT_VALUE(SaveToSourcePath
, false);
77 INIT_VALUE(ProcessPriority
, -1 );
78 INIT_VALUE(EnableSounds
, false);
79 INIT_VALUE(DisableWarnings
, false);
80 INIT_VALUE(NoUpdateReminder
, false);
81 INIT_VALUE(AbortOnTimeout
, true );
82 INIT_VALUE(SkipVersionTest
, false);
83 INIT_VALUE(NoSystrayWarning
, false);
84 INIT_VALUE(SaveQueueNoConfirm
, false);
87 void PreferencesModel::loadPreferences(PreferencesModel
*preferences
)
89 const QString appDir
= x264_data_path();
90 PreferencesModel defaults
;
91 QSettings
settings(QString("%1/preferences.ini").arg(appDir
), QSettings::IniFormat
);
92 settings
.beginGroup("preferences");
94 LOAD_VALUE_B(AutoRunNextJob
);
95 LOAD_VALUE_U(MaxRunningJobCount
);
96 LOAD_VALUE_B(Prefer64BitSource
);
97 LOAD_VALUE_B(SaveLogFiles
);
98 LOAD_VALUE_B(SaveToSourcePath
);
99 LOAD_VALUE_I(ProcessPriority
);
100 LOAD_VALUE_B(EnableSounds
);
101 LOAD_VALUE_B(DisableWarnings
);
102 LOAD_VALUE_B(NoUpdateReminder
);
103 LOAD_VALUE_B(NoSystrayWarning
);
104 LOAD_VALUE_B(SaveQueueNoConfirm
);
107 preferences
->setProcessPriority(qBound(-2, preferences
->getProcessPriority(), 2));
108 preferences
->setMaxRunningJobCount(qBound(1U, preferences
->getMaxRunningJobCount(), 16U));
111 void PreferencesModel::savePreferences(PreferencesModel
*preferences
)
113 const QString appDir
= x264_data_path();
114 QSettings
settings(QString("%1/preferences.ini").arg(appDir
), QSettings::IniFormat
);
115 settings
.beginGroup("preferences");
117 STORE_VALUE(AutoRunNextJob
);
118 STORE_VALUE(MaxRunningJobCount
);
119 STORE_VALUE(Prefer64BitSource
);
120 STORE_VALUE(SaveLogFiles
);
121 STORE_VALUE(SaveToSourcePath
);
122 STORE_VALUE(ProcessPriority
);
123 STORE_VALUE(EnableSounds
);
124 STORE_VALUE(DisableWarnings
);
125 STORE_VALUE(NoUpdateReminder
);
126 STORE_VALUE(NoSystrayWarning
);
127 STORE_VALUE(SaveQueueNoConfirm
);