1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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_Settings.h"
27 #include <QDesktopServices>
28 #include <QApplication>
32 #include <QStringList>
37 ////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////
41 #define LAMEXP_MAKE_OPTION_I(OPT,DEF) \
42 int SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toInt(); } \
43 void SettingsModel::OPT(int value) { m_settings->setValue(g_settingsId_##OPT, value); } \
44 int SettingsModel::OPT##Default(void) { return DEF; }
46 #define LAMEXP_MAKE_OPTION_S(OPT,DEF) \
47 QString SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toString().trimmed(); } \
48 void SettingsModel::OPT(const QString &value) { m_settings->setValue(g_settingsId_##OPT, value); } \
49 QString SettingsModel::OPT##Default(void) { return DEF; }
51 #define LAMEXP_MAKE_OPTION_B(OPT,DEF) \
52 bool SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toBool(); } \
53 void SettingsModel::OPT(bool value) { m_settings->setValue(g_settingsId_##OPT, value); } \
54 bool SettingsModel::OPT##Default(void) { return DEF; }
56 #define LAMEXP_MAKE_OPTION_U(OPT,DEF) \
57 unsigned int SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toUInt(); } \
58 void SettingsModel::OPT(unsigned int value) { m_settings->setValue(g_settingsId_##OPT, value); } \
59 unsigned int SettingsModel::OPT##Default(void) { return DEF; }
61 #define LAMEXP_MAKE_ID(DEC,STR) static const char *g_settingsId_##DEC = STR
62 #define REMOVE_GROUP(OBJ,ID) OBJ->beginGroup(ID); OBJ->remove(""); OBJ->endGroup();
64 ////////////////////////////////////////////////////////////
66 ////////////////////////////////////////////////////////////
69 LAMEXP_MAKE_ID(versionNumber
, "VersionNumber");
70 LAMEXP_MAKE_ID(licenseAccepted
, "LicenseAccepted");
71 LAMEXP_MAKE_ID(interfaceStyle
, "InterfaceStyle");
72 LAMEXP_MAKE_ID(compressionEncoder
, "Compression/Encoder");
73 LAMEXP_MAKE_ID(compressionRCMode
, "Compression/RCMode");
74 LAMEXP_MAKE_ID(compressionBitrate
, "Compression/Bitrate");
75 LAMEXP_MAKE_ID(outputDir
, "OutputDirectory/SelectedPath");
76 LAMEXP_MAKE_ID(outputToSourceDir
, "OutputDirectory/OutputToSourceFolder");
77 LAMEXP_MAKE_ID(prependRelativeSourcePath
, "OutputDirectory/PrependRelativeSourcePath");
78 LAMEXP_MAKE_ID(writeMetaTags
, "Flags/WriteMetaTags");
79 LAMEXP_MAKE_ID(createPlaylist
, "Flags/AutoCreatePlaylist");
80 LAMEXP_MAKE_ID(autoUpdateLastCheck
, "AutoUpdate/LastCheck");
81 LAMEXP_MAKE_ID(autoUpdateEnabled
, "AutoUpdate/Enabled");
82 LAMEXP_MAKE_ID(autoUpdateCheckBeta
, "AutoUpdate/CheckForBetaVersions");
83 LAMEXP_MAKE_ID(soundsEnabled
, "Flags/EnableSounds");
84 LAMEXP_MAKE_ID(neroAacNotificationsEnabled
, "Flags/EnableNeroAacNotifications");
85 LAMEXP_MAKE_ID(wmaDecoderNotificationsEnabled
, "Flags/EnableWmaDecoderNotifications");
86 LAMEXP_MAKE_ID(dropBoxWidgetEnabled
, "Flags/EnableDropBoxWidget");
87 LAMEXP_MAKE_ID(shellIntegrationEnabled
, "Flags/EnableShellIntegration");
88 LAMEXP_MAKE_ID(currentLanguage
, "Localization/Language");
89 LAMEXP_MAKE_ID(lameAlgoQuality
, "AdvancedOptions/LAME/AlgorithmQuality");
90 LAMEXP_MAKE_ID(lameChannelMode
, "AdvancedOptions/LAME/ChannelMode");
91 LAMEXP_MAKE_ID(bitrateManagementEnabled
, "AdvancedOptions/BitrateManagement/Enabled");
92 LAMEXP_MAKE_ID(bitrateManagementMinRate
, "AdvancedOptions/BitrateManagement/MinRate");
93 LAMEXP_MAKE_ID(bitrateManagementMaxRate
, "AdvancedOptions/BitrateManagement/MaxRate");
94 LAMEXP_MAKE_ID(aftenAudioCodingMode
, "AdvancedOptions/Aften/AudioCodingMode");
95 LAMEXP_MAKE_ID(aftenDynamicRangeCompression
, "AdvancedOptions/Aften/DynamicRangeCompression");
96 LAMEXP_MAKE_ID(aftenFastBitAllocation
, "AdvancedOptions/Aften/FastBitAllocation");
97 LAMEXP_MAKE_ID(aftenExponentSearchSize
, "AdvancedOptions/Aften/ExponentSearchSize");
98 LAMEXP_MAKE_ID(samplingRate
, "AdvancedOptions/Common/Resampling");
99 LAMEXP_MAKE_ID(neroAACEnable2Pass
, "AdvancedOptions/NeroAAC/Enable2Pass");
100 LAMEXP_MAKE_ID(neroAACProfile
, "AdvancedOptions/NeroAAC/ForceProfile");
101 LAMEXP_MAKE_ID(normalizationFilterEnabled
, "AdvancedOptions/VolumeNormalization/Enabled");
102 LAMEXP_MAKE_ID(normalizationFilterMaxVolume
, "AdvancedOptions/VolumeNormalization/MaxVolume");
103 LAMEXP_MAKE_ID(toneAdjustBass
, "AdvancedOptions/ToneAdjustment/Bass");
104 LAMEXP_MAKE_ID(toneAdjustTreble
, "AdvancedOptions/ToneAdjustment/Treble");
105 LAMEXP_MAKE_ID(customParametersLAME
, "AdvancedOptions/CustomParameters/LAME");
106 LAMEXP_MAKE_ID(customParametersOggEnc
, "AdvancedOptions/CustomParameters/OggEnc");
107 LAMEXP_MAKE_ID(customParametersNeroAAC
, "AdvancedOptions/CustomParameters/NeroAAC");
108 LAMEXP_MAKE_ID(customParametersAften
, "AdvancedOptions/CustomParameters/Aften");
109 LAMEXP_MAKE_ID(customParametersFLAC
, "AdvancedOptions/CustomParameters/FLAC");
110 LAMEXP_MAKE_ID(metaInfoPosition
, "MetaInformation/PlaylistPosition");
111 LAMEXP_MAKE_ID(maximumInstances
, "AdvancedOptions/Threading/MaximumInstances");
112 LAMEXP_MAKE_ID(customTempPath
, "AdvancedOptions/TempDirectory/CustomPath");
113 LAMEXP_MAKE_ID(customTempPathEnabled
, "AdvancedOptions/TempDirectory/UseCustomPath");
116 const int SettingsModel::mp3Bitrates
[15] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1};
117 const int SettingsModel::ac3Bitrates
[20] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 512, 576, 640, -1};
118 const int SettingsModel::samplingRates
[8] = {0, 16000, 22050, 24000, 32000, 44100, 48000, -1};
120 ////////////////////////////////////////////////////////////
122 ////////////////////////////////////////////////////////////
124 SettingsModel::SettingsModel(void)
126 m_defaultLanguage(NULL
)
130 if(!lamexp_portable_mode())
132 QString dataPath
= QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation
)).canonicalPath();
133 if(dataPath
.isEmpty()) dataPath
= QDesktopServices::storageLocation(QDesktopServices::DataLocation
);
134 QDir(dataPath
).mkpath(".");
135 configPath
= QString("%1/config.ini").arg(dataPath
);
139 qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n");
140 QString appPath
= QFileInfo(QApplication::applicationFilePath()).canonicalFilePath();
141 if(appPath
.isEmpty()) appPath
= QApplication::applicationFilePath();
142 configPath
= QString("%1/%2.ini").arg(QFileInfo(appPath
).absolutePath(), QFileInfo(appPath
).completeBaseName());
145 m_settings
= new QSettings(configPath
, QSettings::IniFormat
);
146 const QString groupKey
= QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build());
147 QStringList childGroups
= m_settings
->childGroups();
149 while(!childGroups
.isEmpty())
151 QString current
= childGroups
.takeFirst();
152 QRegExp
filter("^LameXP_(\\d+)(\\d\\d)(\\d\\d\\d\\d\\d)$");
153 if(filter
.indexIn(current
) >= 0)
156 unsigned int temp
= filter
.cap(3).toUInt(&ok
) + 10;
157 if(ok
&& (temp
>= lamexp_version_build()))
162 qWarning("Deleting obsolete group from config: %s", current
.toUtf8().constData());
163 REMOVE_GROUP(m_settings
, current
);
166 m_settings
->beginGroup(groupKey
);
167 m_settings
->setValue(g_settingsId_versionNumber
, QApplication::applicationVersion());
171 ////////////////////////////////////////////////////////////
173 ////////////////////////////////////////////////////////////
175 SettingsModel::~SettingsModel(void)
177 LAMEXP_DELETE(m_settings
);
178 LAMEXP_DELETE(m_defaultLanguage
);
181 ////////////////////////////////////////////////////////////
183 ////////////////////////////////////////////////////////////
185 void SettingsModel::validate(void)
187 if(this->compressionEncoder() < SettingsModel::MP3Encoder
|| this->compressionEncoder() > SettingsModel::PCMEncoder
)
189 this->compressionEncoder(SettingsModel::MP3Encoder
);
192 if(this->compressionRCMode() < SettingsModel::VBRMode
|| this->compressionRCMode() > SettingsModel::CBRMode
)
194 this->compressionEncoder(SettingsModel::VBRMode
);
197 if(!(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")))
199 if(this->compressionEncoder() == SettingsModel::AACEncoder
)
201 qWarning("Nero encoder selected, but not available any more. Reverting to MP3!");
202 this->compressionEncoder(SettingsModel::MP3Encoder
);
206 if(this->outputDir().isEmpty() || !QFileInfo(this->outputDir()).isDir())
208 this->outputDir(QDesktopServices::storageLocation(QDesktopServices::MusicLocation
));
211 if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive
))
213 qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
214 this->currentLanguage(defaultLanguage());
218 ////////////////////////////////////////////////////////////
220 ////////////////////////////////////////////////////////////
222 QString
SettingsModel::defaultLanguage(void)
224 if(m_defaultLanguage
)
226 return *m_defaultLanguage
;
229 //Check if we can use the default translation
230 QLocale systemLanguage
= QLocale::system();
231 if(systemLanguage
.language() == QLocale::English
|| systemLanguage
.language() == QLocale::C
)
233 m_defaultLanguage
= new QString(LAMEXP_DEFAULT_LANGID
);
234 return LAMEXP_DEFAULT_LANGID
;
237 //Try to find a suitable translation for the user's system language
238 QStringList languages
= lamexp_query_translations();
239 while(!languages
.isEmpty())
241 QString currentLangId
= languages
.takeFirst();
242 if(lamexp_translation_sysid(currentLangId
) == systemLanguage
.language())
244 m_defaultLanguage
= new QString(currentLangId
);
245 return currentLangId
;
249 //Fall back to the default translation
250 m_defaultLanguage
= new QString(LAMEXP_DEFAULT_LANGID
);
251 return LAMEXP_DEFAULT_LANGID
;
254 ////////////////////////////////////////////////////////////
256 ////////////////////////////////////////////////////////////
258 LAMEXP_MAKE_OPTION_I(licenseAccepted
, 0)
259 LAMEXP_MAKE_OPTION_I(interfaceStyle
, 0)
260 LAMEXP_MAKE_OPTION_I(compressionEncoder
, 0)
261 LAMEXP_MAKE_OPTION_I(compressionRCMode
, 0)
262 LAMEXP_MAKE_OPTION_I(compressionBitrate
, 7)
263 LAMEXP_MAKE_OPTION_S(outputDir
, QString())
264 LAMEXP_MAKE_OPTION_B(outputToSourceDir
, false)
265 LAMEXP_MAKE_OPTION_B(prependRelativeSourcePath
, false)
266 LAMEXP_MAKE_OPTION_B(writeMetaTags
, true)
267 LAMEXP_MAKE_OPTION_B(createPlaylist
, true)
268 LAMEXP_MAKE_OPTION_S(autoUpdateLastCheck
, "Never")
269 LAMEXP_MAKE_OPTION_B(autoUpdateEnabled
, true)
270 LAMEXP_MAKE_OPTION_B(autoUpdateCheckBeta
, false)
271 LAMEXP_MAKE_OPTION_B(soundsEnabled
, true)
272 LAMEXP_MAKE_OPTION_B(neroAacNotificationsEnabled
, true)
273 LAMEXP_MAKE_OPTION_B(wmaDecoderNotificationsEnabled
, true)
274 LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled
, true)
275 LAMEXP_MAKE_OPTION_B(shellIntegrationEnabled
, !lamexp_portable_mode())
276 LAMEXP_MAKE_OPTION_S(currentLanguage
, defaultLanguage())
277 LAMEXP_MAKE_OPTION_I(lameAlgoQuality
, 3)
278 LAMEXP_MAKE_OPTION_I(lameChannelMode
, 0);
279 LAMEXP_MAKE_OPTION_B(bitrateManagementEnabled
, false)
280 LAMEXP_MAKE_OPTION_I(bitrateManagementMinRate
, 32)
281 LAMEXP_MAKE_OPTION_I(bitrateManagementMaxRate
, 500)
282 LAMEXP_MAKE_OPTION_I(samplingRate
, 0)
283 LAMEXP_MAKE_OPTION_B(neroAACEnable2Pass
, true)
284 LAMEXP_MAKE_OPTION_I(neroAACProfile
, 0)
285 LAMEXP_MAKE_OPTION_I(aftenAudioCodingMode
, 0);
286 LAMEXP_MAKE_OPTION_I(aftenDynamicRangeCompression
, 5);
287 LAMEXP_MAKE_OPTION_B(aftenFastBitAllocation
, false);
288 LAMEXP_MAKE_OPTION_I(aftenExponentSearchSize
, 8);
289 LAMEXP_MAKE_OPTION_B(normalizationFilterEnabled
, false)
290 LAMEXP_MAKE_OPTION_I(normalizationFilterMaxVolume
, -50)
291 LAMEXP_MAKE_OPTION_I(toneAdjustBass
, 0)
292 LAMEXP_MAKE_OPTION_I(toneAdjustTreble
, 0)
293 LAMEXP_MAKE_OPTION_S(customParametersLAME
, QString());
294 LAMEXP_MAKE_OPTION_S(customParametersOggEnc
, QString());
295 LAMEXP_MAKE_OPTION_S(customParametersNeroAAC
, QString());
296 LAMEXP_MAKE_OPTION_S(customParametersAften
, QString());
297 LAMEXP_MAKE_OPTION_S(customParametersFLAC
, QString());
298 LAMEXP_MAKE_OPTION_U(metaInfoPosition
, UINT_MAX
);
299 LAMEXP_MAKE_OPTION_U(maximumInstances
, 0);
300 LAMEXP_MAKE_OPTION_S(customTempPath
, QDesktopServices::storageLocation(QDesktopServices::TempLocation
));
301 LAMEXP_MAKE_OPTION_B(customTempPathEnabled
, false);