OSDN Git Service

Implement update reminder + added options to disable the update reminder and/or the...
[lamexp/LameXP.git] / src / Model_Settings.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2010 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_Settings.h"
23
24 #include "Global.h"
25
26 #include <QSettings>
27 #include <QDesktopServices>
28 #include <QApplication>
29 #include <QString>
30 #include <QFileInfo>
31
32 //Constants
33 static const char *g_settingsId_versionNumber = "VersionNumber";
34 static const char *g_settingsId_licenseAccepted = "LicenseAccepted";
35 static const char *g_settingsId_interfaceStyle = "InterfaceStyle";
36 static const char *g_settingsId_compressionEncoder = "Compression/Encoder";
37 static const char *g_settingsId_compressionRCMode = "Compression/RCMode";
38 static const char *g_settingsId_compressionBitrate = "Compression/Bitrate";
39 static const char *g_settingsId_outputDir = "OutputDirectory/SelectedPath";
40 static const char *g_settingsId_outputToSourceDir = "OutputDirectory/OutputToSourceFolder";
41 static const char *g_settingsId_writeMetaTags = "Flags/WriteMetaTags";
42 static const char *g_settingsId_createPlaylist = "Flags/AutoCreatePlaylist";
43 static const char *g_settingsId_autoUpdateLastCheck = "AutoUpdate/LastCheck";
44 static const char *g_settingsId_autoUpdateEnabled = "AutoUpdate/Enabled";
45 static const char *g_settingsId_soundsEnabled = "Flags/EnableSounds";
46
47 //Macros
48 #define MAKE_OPTION1(OPT,DEF) \
49 int SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toInt(); } \
50 void SettingsModel::OPT(int value) { m_settings->setValue(g_settingsId_##OPT, value); }
51
52 #define MAKE_OPTION2(OPT,DEF) \
53 QString SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toString().trimmed(); } \
54 void SettingsModel::OPT(const QString &value) { m_settings->setValue(g_settingsId_##OPT, value); }
55
56 #define MAKE_OPTION3(OPT,DEF) \
57 bool SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toBool(); } \
58 void SettingsModel::OPT(bool value) { m_settings->setValue(g_settingsId_##OPT, value); }
59
60 //LUT
61 const int SettingsModel::mp3Bitrates[15] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1};
62
63 ////////////////////////////////////////////////////////////
64 // Constructor
65 ////////////////////////////////////////////////////////////
66
67 SettingsModel::SettingsModel(void)
68 {
69         QString appPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
70         m_settings = new QSettings(appPath.append("/config.ini"), QSettings::IniFormat);
71         m_settings->beginGroup(QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()));
72         m_settings->setValue(g_settingsId_versionNumber, QApplication::applicationVersion());
73         m_settings->sync();
74 }
75
76 ////////////////////////////////////////////////////////////
77 // Destructor
78 ////////////////////////////////////////////////////////////
79
80 SettingsModel::~SettingsModel(void)
81 {
82         LAMEXP_DELETE(m_settings);
83 }
84
85 ////////////////////////////////////////////////////////////
86 // Public Functions
87 ////////////////////////////////////////////////////////////
88
89 void SettingsModel::validate(void)
90 {
91         if(this->compressionEncoder() < SettingsModel::MP3Encoder || this->compressionEncoder() > SettingsModel::PCMEncoder)
92         {
93                 this->compressionEncoder(SettingsModel::MP3Encoder);
94         }
95         if(this->compressionRCMode() < SettingsModel::VBRMode || this->compressionRCMode() > SettingsModel::CBRMode)
96         {
97                 this->compressionEncoder(SettingsModel::VBRMode);
98         }
99         if(!(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")))
100         {
101                 if(this->compressionEncoder() == SettingsModel::AACEncoder) this->compressionEncoder(SettingsModel::MP3Encoder);
102         }
103         if(this->outputDir().isEmpty() || !QFileInfo(this->outputDir()).isDir())
104         {
105                 this->outputDir(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
106         }
107 }
108
109 ////////////////////////////////////////////////////////////
110 // Getter and Setter
111 ////////////////////////////////////////////////////////////
112
113 MAKE_OPTION1(licenseAccepted, 0)
114 MAKE_OPTION1(interfaceStyle, 0)
115 MAKE_OPTION1(compressionEncoder, 0)
116 MAKE_OPTION1(compressionRCMode, 0)
117 MAKE_OPTION1(compressionBitrate, 7)
118 MAKE_OPTION2(outputDir, QString())
119 MAKE_OPTION3(outputToSourceDir, false)
120 MAKE_OPTION3(writeMetaTags, true)
121 MAKE_OPTION3(createPlaylist, true)
122 MAKE_OPTION2(autoUpdateLastCheck, "Never")
123 MAKE_OPTION3(autoUpdateEnabled, true)
124 MAKE_OPTION3(soundsEnabled, true)