OSDN Git Service

Updated x265 and NVEncC to latest versions.
[x264-launcher/x264-launcher.git] / src / model_preferences.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "model_preferences.h"
23
24 #include "global.h"
25
26 #include <QSettings>
27 #include <QDesktopServices>
28 #include <QMouseEvent>
29 #include <QMessageBox>
30
31 ///////////////////////////////////////////////////////////////////////////////
32
33 #define INIT_VALUE(NAME, VAL) do \
34 { \
35         preferences->set##NAME(VAL); \
36 } \
37 while(0)
38
39 #define STORE_VALUE(NAME) do \
40 { \
41         settings.setValue(#NAME, (preferences->get##NAME())); \
42 } \
43 while(0)
44
45 #define LOAD_VALUE_B(NAME) do \
46 { \
47         preferences->set##NAME(settings.value(#NAME, QVariant(defaults.get##NAME())).toBool()); \
48 } \
49 while(0)
50
51 #define LOAD_VALUE_I(NAME) do \
52 { \
53         preferences->set##NAME(settings.value(#NAME, QVariant(defaults.get##NAME())).toInt()); \
54 } \
55 while(0)
56
57 #define LOAD_VALUE_U(NAME) do \
58 { \
59         preferences->set##NAME(settings.value(#NAME, QVariant(defaults.get##NAME())).toUInt()); \
60 } \
61 while(0)
62
63 ///////////////////////////////////////////////////////////////////////////////
64
65 PreferencesModel::PreferencesModel(void)
66 {
67         initPreferences(this);
68 }
69
70 void PreferencesModel::initPreferences(PreferencesModel *preferences)
71 {
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);
85 }
86
87 void PreferencesModel::loadPreferences(PreferencesModel *preferences)
88 {
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");
93
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);
105
106         //Validation
107         preferences->setProcessPriority(qBound(-2, preferences->getProcessPriority(), 2));
108         preferences->setMaxRunningJobCount(qBound(1U, preferences->getMaxRunningJobCount(), 16U));
109 }
110
111 void PreferencesModel::savePreferences(PreferencesModel *preferences)
112 {
113         const QString appDir = x264_data_path();
114         QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
115         settings.beginGroup("preferences");
116
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);
128         
129         settings.sync();
130 }