OSDN Git Service

Each encoder now can return an AbstractEncoderInfo object, which contains the support...
[x264-launcher/x264-launcher.git] / src / model_preferences.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 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(ShutdownComputer,   false);
75         INIT_VALUE(UseAvisyth64Bit,    false);
76         INIT_VALUE(SaveLogFiles,       false);
77         INIT_VALUE(SaveToSourcePath,   false);
78         INIT_VALUE(ProcessPriority,    -1   );
79         INIT_VALUE(EnableSounds,       false);
80         INIT_VALUE(DisableWarnings,    false);
81         INIT_VALUE(NoUpdateReminder,   false);
82         INIT_VALUE(AbortOnTimeout,     true );
83         INIT_VALUE(SkipVersionTest,    false);
84
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(ShutdownComputer  );
97         LOAD_VALUE_B(UseAvisyth64Bit   );
98         LOAD_VALUE_B(SaveLogFiles      );
99         LOAD_VALUE_B(SaveToSourcePath  );
100         LOAD_VALUE_I(ProcessPriority   );
101         LOAD_VALUE_B(EnableSounds      );
102         LOAD_VALUE_B(DisableWarnings   );
103         LOAD_VALUE_B(NoUpdateReminder  );
104
105         //Validation
106         preferences->setProcessPriority(qBound(-2, preferences->getProcessPriority(), 2));
107         preferences->setMaxRunningJobCount(qBound(1U, preferences->getMaxRunningJobCount(), 16U));
108 }
109
110 void PreferencesModel::savePreferences(PreferencesModel *preferences)
111 {
112         const QString appDir = x264_data_path();
113         QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
114         settings.beginGroup("preferences");
115
116         STORE_VALUE(AutoRunNextJob    );
117         STORE_VALUE(MaxRunningJobCount);
118         STORE_VALUE(ShutdownComputer  );
119         STORE_VALUE(UseAvisyth64Bit   );
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         
127         settings.sync();
128 }