1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Model_Settings.h"
28 #include <QDesktopServices>
29 #include <QApplication>
33 #include <QStringList>
36 #include <QReadWriteLock>
37 #include <QReadLocker>
38 #include <QWriteLocker>
43 ////////////////////////////////////////////////////////////
44 // SettingsCache Class
45 ////////////////////////////////////////////////////////////
50 SettingsCache(QSettings *configFile) : m_configFile(configFile)
52 m_cache = new QHash<QString, QVariant>();
53 m_cacheLock = new QMutex();
54 m_cacheDirty = new QSet<QString>();
61 LAMEXP_DELETE(m_cache);
62 LAMEXP_DELETE(m_cacheDirty);
63 LAMEXP_DELETE(m_cacheLock);
64 LAMEXP_DELETE(m_configFile);
67 inline void storeValue(const QString &key, const QVariant &value)
69 QMutexLocker lock(m_cacheLock);
71 if(!m_cache->contains(key))
73 m_cache->insert(key, value);
74 m_cacheDirty->insert(key);
78 if(m_cache->value(key) != value)
80 m_cache->insert(key, value);
81 m_cacheDirty->insert(key);
86 inline QVariant loadValue(const QString &key, const QVariant &defaultValue) const
88 QMutexLocker lock(m_cacheLock);
90 if(!m_cache->contains(key))
92 const QVariant storedValue = m_configFile->value(key, defaultValue);
93 m_cache->insert(key, storedValue);
96 return m_cache->value(key, defaultValue);
99 inline void flushValues(void)
101 QMutexLocker lock(m_cacheLock);
103 if(!m_cacheDirty->isEmpty())
105 QSet<QString>::ConstIterator iter;
106 for(iter = m_cacheDirty->constBegin(); iter != m_cacheDirty->constEnd(); iter++)
108 if(m_cache->contains(*iter))
110 m_configFile->setValue((*iter), m_cache->value(*iter));
114 qWarning("Could not find '%s' in cache, but it has been marked as dirty!", QUTF8(*iter));
117 m_configFile->sync();
118 m_cacheDirty->clear();
123 QSettings *m_configFile;
124 QHash<QString, QVariant> *m_cache;
125 QSet<QString> *m_cacheDirty;
129 ////////////////////////////////////////////////////////////
131 ////////////////////////////////////////////////////////////
133 #define LAMEXP_MAKE_OPTION_I(OPT,DEF) \
134 int SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toInt(); } \
135 void SettingsModel::OPT(int value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
136 int SettingsModel::OPT##Default(void) { return (DEF); }
138 #define LAMEXP_MAKE_OPTION_S(OPT,DEF) \
139 QString SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toString().trimmed(); } \
140 void SettingsModel::OPT(const QString &value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
141 QString SettingsModel::OPT##Default(void) { return (DEF); }
143 #define LAMEXP_MAKE_OPTION_B(OPT,DEF) \
144 bool SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toBool(); } \
145 void SettingsModel::OPT(bool value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
146 bool SettingsModel::OPT##Default(void) { return (DEF); }
148 #define LAMEXP_MAKE_OPTION_U(OPT,DEF) \
149 unsigned int SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toUInt(); } \
150 void SettingsModel::OPT(unsigned int value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
151 unsigned int SettingsModel::OPT##Default(void) { return (DEF); }
153 #define LAMEXP_MAKE_ID(DEC,STR) static const char *g_settingsId_##DEC = STR
155 #define REMOVE_GROUP(OBJ,ID) do \
157 OBJ->beginGroup(ID); \
163 #define DIR_EXISTS(PATH) (QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
165 ////////////////////////////////////////////////////////////
167 ////////////////////////////////////////////////////////////
170 LAMEXP_MAKE_ID(aacEncProfile, "AdvancedOptions/AACEnc/ForceProfile");
171 LAMEXP_MAKE_ID(aftenAudioCodingMode, "AdvancedOptions/Aften/AudioCodingMode");
172 LAMEXP_MAKE_ID(aftenDynamicRangeCompression, "AdvancedOptions/Aften/DynamicRangeCompression");
173 LAMEXP_MAKE_ID(aftenExponentSearchSize, "AdvancedOptions/Aften/ExponentSearchSize");
174 LAMEXP_MAKE_ID(aftenFastBitAllocation, "AdvancedOptions/Aften/FastBitAllocation");
175 LAMEXP_MAKE_ID(antivirNotificationsEnabled, "Flags/EnableAntivirusNotifications");
176 LAMEXP_MAKE_ID(autoUpdateCheckBeta, "AutoUpdate/CheckForBetaVersions");
177 LAMEXP_MAKE_ID(autoUpdateEnabled, "AutoUpdate/Enabled");
178 LAMEXP_MAKE_ID(autoUpdateLastCheck, "AutoUpdate/LastCheck");
179 LAMEXP_MAKE_ID(bitrateManagementEnabled, "AdvancedOptions/BitrateManagement/Enabled");
180 LAMEXP_MAKE_ID(bitrateManagementMaxRate, "AdvancedOptions/BitrateManagement/MaxRate");
181 LAMEXP_MAKE_ID(bitrateManagementMinRate, "AdvancedOptions/BitrateManagement/MinRate");
182 LAMEXP_MAKE_ID(compressionAbrBitrateAacEnc, "Compression/AbrTaretBitrate/AacEnc");
183 LAMEXP_MAKE_ID(compressionAbrBitrateAften, "Compression/AbrTaretBitrate/Aften");
184 LAMEXP_MAKE_ID(compressionAbrBitrateDcaEnc, "Compression/AbrTaretBitrate/DcaEnc");
185 LAMEXP_MAKE_ID(compressionAbrBitrateFLAC, "Compression/AbrTaretBitrate/FLAC");
186 LAMEXP_MAKE_ID(compressionAbrBitrateLAME, "Compression/AbrTaretBitrate/LAME");
187 LAMEXP_MAKE_ID(compressionAbrBitrateMacEnc, "Compression/AbrTaretBitrate/MacEnc");
188 LAMEXP_MAKE_ID(compressionAbrBitrateOggEnc, "Compression/AbrTaretBitrate/OggEnc");
189 LAMEXP_MAKE_ID(compressionAbrBitrateOpusEnc, "Compression/AbrTaretBitrate/OpusEnc");
190 LAMEXP_MAKE_ID(compressionAbrBitrateWave, "Compression/AbrTaretBitrate/Wave");
191 LAMEXP_MAKE_ID(compressionCbrBitrateAacEnc, "Compression/CbrTaretBitrate/AacEnc");
192 LAMEXP_MAKE_ID(compressionCbrBitrateAften, "Compression/CbrTaretBitrate/Aften");
193 LAMEXP_MAKE_ID(compressionCbrBitrateDcaEnc, "Compression/CbrTaretBitrate/DcaEnc");
194 LAMEXP_MAKE_ID(compressionCbrBitrateFLAC, "Compression/CbrTaretBitrate/FLAC");
195 LAMEXP_MAKE_ID(compressionCbrBitrateLAME, "Compression/CbrTaretBitrate/LAME");
196 LAMEXP_MAKE_ID(compressionCbrBitrateMacEnc, "Compression/CbrTaretBitrate/MacEnc");
197 LAMEXP_MAKE_ID(compressionCbrBitrateOggEnc, "Compression/CbrTaretBitrate/OggEnc");
198 LAMEXP_MAKE_ID(compressionCbrBitrateOpusEnc, "Compression/CbrTaretBitrate/OpusEnc");
199 LAMEXP_MAKE_ID(compressionCbrBitrateWave, "Compression/CbrTaretBitrate/Wave");
200 LAMEXP_MAKE_ID(compressionEncoder, "Compression/Encoder");
201 LAMEXP_MAKE_ID(compressionRCModeAacEnc, "Compression/RCMode/AacEnc");
202 LAMEXP_MAKE_ID(compressionRCModeAften, "Compression/RCMode/Aften");
203 LAMEXP_MAKE_ID(compressionRCModeDcaEnc, "Compression/RCMode/DcaEnc");
204 LAMEXP_MAKE_ID(compressionRCModeFLAC, "Compression/RCMode/FLAC");
205 LAMEXP_MAKE_ID(compressionRCModeLAME, "Compression/RCMode/LAME");
206 LAMEXP_MAKE_ID(compressionRCModeMacEnc, "Compression/RCMode/MacEnc");
207 LAMEXP_MAKE_ID(compressionRCModeOggEnc, "Compression/RCMode/OggEnc");
208 LAMEXP_MAKE_ID(compressionRCModeOpusEnc, "Compression/RCMode/OpusEnc");
209 LAMEXP_MAKE_ID(compressionRCModeWave, "Compression/RCMode/Wave");
210 LAMEXP_MAKE_ID(compressionVbrQualityAacEnc, "Compression/VbrQualityLevel/AacEnc");
211 LAMEXP_MAKE_ID(compressionVbrQualityAften, "Compression/VbrQualityLevel/Aften");
212 LAMEXP_MAKE_ID(compressionVbrQualityDcaEnc, "Compression/VbrQualityLevel/DcaEnc");
213 LAMEXP_MAKE_ID(compressionVbrQualityFLAC, "Compression/VbrQualityLevel/FLAC");
214 LAMEXP_MAKE_ID(compressionVbrQualityLAME, "Compression/VbrQualityLevel/LAME");
215 LAMEXP_MAKE_ID(compressionVbrQualityMacEnc, "Compression/VbrQualityLevel/MacEnc");
216 LAMEXP_MAKE_ID(compressionVbrQualityOggEnc, "Compression/VbrQualityLevel/OggEnc");
217 LAMEXP_MAKE_ID(compressionVbrQualityOpusEnc, "Compression/VbrQualityLevel/OpusEnc");
218 LAMEXP_MAKE_ID(compressionVbrQualityWave, "Compression/VbrQualityLevel/Wave");
219 LAMEXP_MAKE_ID(createPlaylist, "Flags/AutoCreatePlaylist");
220 LAMEXP_MAKE_ID(currentLanguage, "Localization/Language");
221 LAMEXP_MAKE_ID(currentLanguageFile, "Localization/UseQMFile");
222 LAMEXP_MAKE_ID(customParametersAacEnc, "AdvancedOptions/CustomParameters/AacEnc");
223 LAMEXP_MAKE_ID(customParametersAften, "AdvancedOptions/CustomParameters/Aften");
224 LAMEXP_MAKE_ID(customParametersDcaEnc, "AdvancedOptions/CustomParameters/DcaEnc");
225 LAMEXP_MAKE_ID(customParametersFLAC, "AdvancedOptions/CustomParameters/FLAC");
226 LAMEXP_MAKE_ID(customParametersLAME, "AdvancedOptions/CustomParameters/LAME");
227 LAMEXP_MAKE_ID(customParametersMacEnc, "AdvancedOptions/CustomParameters/MacEnc");
228 LAMEXP_MAKE_ID(customParametersOggEnc, "AdvancedOptions/CustomParameters/OggEnc");
229 LAMEXP_MAKE_ID(customParametersOpusEnc, "AdvancedOptions/CustomParameters/OpusEnc");
230 LAMEXP_MAKE_ID(customParametersWave, "AdvancedOptions/CustomParameters/Wave");
231 LAMEXP_MAKE_ID(customTempPath, "AdvancedOptions/TempDirectory/CustomPath");
232 LAMEXP_MAKE_ID(customTempPathEnabled, "AdvancedOptions/TempDirectory/UseCustomPath");
233 LAMEXP_MAKE_ID(dropBoxWidgetEnabled, "DropBoxWidget/Enabled");
234 LAMEXP_MAKE_ID(dropBoxWidgetPositionX, "DropBoxWidget/Position/X");
235 LAMEXP_MAKE_ID(dropBoxWidgetPositionY, "DropBoxWidget/Position/Y");
236 LAMEXP_MAKE_ID(favoriteOutputFolders, "OutputDirectory/Favorites");
237 LAMEXP_MAKE_ID(forceStereoDownmix, "AdvancedOptions/StereoDownmix/Force");
238 LAMEXP_MAKE_ID(hibernateComputer, "AdvancedOptions/HibernateComputerOnShutdown");
239 LAMEXP_MAKE_ID(interfaceStyle, "InterfaceStyle");
240 LAMEXP_MAKE_ID(lameAlgoQuality, "AdvancedOptions/LAME/AlgorithmQuality");
241 LAMEXP_MAKE_ID(lameChannelMode, "AdvancedOptions/LAME/ChannelMode");
242 LAMEXP_MAKE_ID(licenseAccepted, "LicenseAccepted");
243 LAMEXP_MAKE_ID(maximumInstances, "AdvancedOptions/Threading/MaximumInstances");
244 LAMEXP_MAKE_ID(metaInfoPosition, "MetaInformation/PlaylistPosition");
245 LAMEXP_MAKE_ID(mostRecentInputPath, "InputDirectory/MostRecentPath");
246 LAMEXP_MAKE_ID(neroAACEnable2Pass, "AdvancedOptions/AACEnc/Enable2Pass");
247 LAMEXP_MAKE_ID(neroAacNotificationsEnabled, "Flags/EnableNeroAacNotifications");
248 LAMEXP_MAKE_ID(normalizationFilterEnabled, "AdvancedOptions/VolumeNormalization/Enabled");
249 LAMEXP_MAKE_ID(normalizationFilterEQMode, "AdvancedOptions/VolumeNormalization/EqualizationMode");
250 LAMEXP_MAKE_ID(normalizationFilterMaxVolume, "AdvancedOptions/VolumeNormalization/MaxVolume");
251 LAMEXP_MAKE_ID(opusComplexity, "AdvancedOptions/Opus/EncodingComplexity");
252 LAMEXP_MAKE_ID(opusDisableResample, "AdvancedOptions/Opus/DisableResample");
253 LAMEXP_MAKE_ID(opusFramesize, "AdvancedOptions/Opus/FrameSize");
254 LAMEXP_MAKE_ID(opusOptimizeFor, "AdvancedOptions/Opus/OptimizeForSignalType");
255 LAMEXP_MAKE_ID(outputDir, "OutputDirectory/SelectedPath");
256 LAMEXP_MAKE_ID(outputToSourceDir, "OutputDirectory/OutputToSourceFolder");
257 LAMEXP_MAKE_ID(overwriteMode, "AdvancedOptions/OverwriteMode");
258 LAMEXP_MAKE_ID(prependRelativeSourcePath, "OutputDirectory/PrependRelativeSourcePath");
259 LAMEXP_MAKE_ID(renameOutputFilesEnabled, "AdvancedOptions/RenameOutputFiles/Enabled");
260 LAMEXP_MAKE_ID(renameOutputFilesPattern, "AdvancedOptions/RenameOutputFiles/Pattern");
261 LAMEXP_MAKE_ID(samplingRate, "AdvancedOptions/Common/Resampling");
262 LAMEXP_MAKE_ID(shellIntegrationEnabled, "Flags/EnableShellIntegration");
263 LAMEXP_MAKE_ID(slowStartup, "Flags/SlowStartupDetected");
264 LAMEXP_MAKE_ID(soundsEnabled, "Flags/EnableSounds");
265 LAMEXP_MAKE_ID(toneAdjustBass, "AdvancedOptions/ToneAdjustment/Bass");
266 LAMEXP_MAKE_ID(toneAdjustTreble, "AdvancedOptions/ToneAdjustment/Treble");
267 LAMEXP_MAKE_ID(versionNumber, "VersionNumber");
268 LAMEXP_MAKE_ID(writeMetaTags, "Flags/WriteMetaTags");
271 const int SettingsModel::samplingRates[8] = {0, 16000, 22050, 24000, 32000, 44100, 48000, -1};
273 static QReadWriteLock s_lock;
275 ////////////////////////////////////////////////////////////
277 ////////////////////////////////////////////////////////////
279 SettingsModel::SettingsModel(void)
281 QString configPath = "LameXP.ini";
283 if(!lamexp_portable_mode())
285 QString dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
286 if(!dataPath.isEmpty())
288 configPath = QString("%1/config.ini").arg(QDir(dataPath).canonicalPath());
292 qWarning("SettingsModel: DataLocation could not be initialized!");
293 dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
294 if(!dataPath.isEmpty())
296 configPath = QString("%1/LameXP.ini").arg(QDir(dataPath).canonicalPath());
302 qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n");
303 QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath();
304 if(appPath.isEmpty())
306 appPath = QFileInfo(QApplication::applicationFilePath()).absoluteFilePath();
308 if(QFileInfo(appPath).exists() && QFileInfo(appPath).isFile())
310 configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName());
315 QSettings *configFile = new QSettings(configPath, QSettings::IniFormat);
316 const QString groupKey = QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_confg());
317 QStringList childGroups =configFile->childGroups();
320 while(!childGroups.isEmpty())
322 QString current = childGroups.takeFirst();
323 QRegExp filter("^LameXP_(\\d+)(\\d\\d)(\\d\\d\\d\\d\\d)$");
324 if(filter.indexIn(current) >= 0)
327 unsigned int temp = filter.cap(3).toUInt(&ok) + 10;
328 if(ok && (temp >= lamexp_version_confg()))
333 qWarning("Deleting obsolete group from config: %s", QUTF8(current));
334 REMOVE_GROUP(configFile, current);
338 configFile->beginGroup(groupKey);
339 configFile->setValue(g_settingsId_versionNumber, QApplication::applicationVersion());
343 m_configCache = new SettingsCache(configFile);
346 ////////////////////////////////////////////////////////////
348 ////////////////////////////////////////////////////////////
350 SettingsModel::~SettingsModel(void)
352 LAMEXP_DELETE(m_configCache);
353 LAMEXP_DELETE(m_defaultLanguage);
356 ////////////////////////////////////////////////////////////
358 ////////////////////////////////////////////////////////////
360 #define CHECK_RCMODE(NAME) do\
362 if(this->compressionRCMode##NAME() < SettingsModel::VBRMode || this->compressionRCMode##NAME() >= SettingsModel::RCMODE_COUNT) \
364 this->compressionRCMode##NAME(SettingsModel::VBRMode); \
369 void SettingsModel::validate(void)
371 if(this->compressionEncoder() < SettingsModel::MP3Encoder || this->compressionEncoder() >= SettingsModel::ENCODER_COUNT)
373 this->compressionEncoder(SettingsModel::MP3Encoder);
377 CHECK_RCMODE(OggEnc);
378 CHECK_RCMODE(AacEnc);
380 CHECK_RCMODE(OpusEnc);
382 if(!(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")))
384 if(!(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll")))
386 if(!(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")))
388 if(this->compressionEncoder() == SettingsModel::AACEncoder)
390 qWarning("AAC encoder selected, but not available any more. Reverting to MP3!");
391 this->compressionEncoder(SettingsModel::MP3Encoder);
397 if(this->outputDir().isEmpty() || (!DIR_EXISTS(this->outputDir())))
399 qWarning("Output directory not set yet or does NOT exist anymore -> Resetting");
400 this->outputDir(defaultDirectory());
403 if(this->mostRecentInputPath().isEmpty() || (!DIR_EXISTS(this->mostRecentInputPath())))
405 qWarning("Most recent input directory not set yet or does NOT exist anymore -> Resetting");
406 this->mostRecentInputPath(defaultDirectory());
409 if(!this->currentLanguageFile().isEmpty())
411 const QString qmPath = QFileInfo(this->currentLanguageFile()).canonicalFilePath();
412 if(qmPath.isEmpty() || (!(QFileInfo(qmPath).exists() && QFileInfo(qmPath).isFile() && (QFileInfo(qmPath).suffix().compare("qm", Qt::CaseInsensitive) == 0))))
414 qWarning("Current language file missing, reverting to built-in translator!");
415 this->currentLanguageFile(QString());
419 if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive))
421 qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
422 this->currentLanguage(defaultLanguage());
425 if(this->hibernateComputer())
427 if(!lamexp_is_hibernation_supported())
429 this->hibernateComputer(false);
433 if(this->overwriteMode() < SettingsModel::Overwrite_KeepBoth || this->overwriteMode() > SettingsModel::Overwrite_Replaces)
435 this->overwriteMode(SettingsModel::Overwrite_KeepBoth);
440 void SettingsModel::syncNow(void)
442 m_configCache->flushValues();
445 ////////////////////////////////////////////////////////////
447 ////////////////////////////////////////////////////////////
449 QString *SettingsModel::m_defaultLanguage = NULL;
451 QString SettingsModel::defaultLanguage(void) const
453 QReadLocker readLock(&s_lock);
455 //Default already initialized?
456 if(m_defaultLanguage)
458 return *m_defaultLanguage;
461 //Acquire write lock now
463 QWriteLocker writeLock(&s_lock);
465 //Default still not initialized?
466 if(m_defaultLanguage)
468 return *m_defaultLanguage;
471 //Detect system langauge
472 QLocale systemLanguage= QLocale::system();
474 qDebug("Language: %s (%d)", QUTF8(QLocale::languageToString(systemLanguage.language())), systemLanguage.language());
475 qDebug("Country is: %s (%d)", QUTF8(QLocale::countryToString(systemLanguage.country())), systemLanguage.country());
476 qDebug("Script is: %s (%d)\n", QUTF8(QLocale::scriptToString(systemLanguage.script())), systemLanguage.script());
478 //Check if we can use the default translation
479 if(systemLanguage.language() == QLocale::English /*|| systemLanguage.language() == QLocale::C*/)
481 m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
482 return LAMEXP_DEFAULT_LANGID;
485 //Try to find a suitable translation for the user's system language *and* country
486 QStringList languages = lamexp_query_translations();
487 while(!languages.isEmpty())
489 QString currentLangId = languages.takeFirst();
490 if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
492 if(lamexp_translation_country(currentLangId) == systemLanguage.country())
494 m_defaultLanguage = new QString(currentLangId);
495 return currentLangId;
500 //Try to find a suitable translation for the user's system language
501 languages = lamexp_query_translations();
502 while(!languages.isEmpty())
504 QString currentLangId = languages.takeFirst();
505 if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
507 m_defaultLanguage = new QString(currentLangId);
508 return currentLangId;
512 //Fall back to the default translation
513 m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
514 return LAMEXP_DEFAULT_LANGID;
517 QString SettingsModel::defaultDirectory(void) const
519 QString defaultLocation = initDirectory(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
521 if(defaultLocation.isEmpty())
523 defaultLocation = initDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
525 if(defaultLocation.isEmpty())
527 defaultLocation = initDirectory(QDir::currentPath());
531 return defaultLocation;
534 QString SettingsModel::initDirectory(const QString &path) const
541 if(!QDir(path).exists())
543 for(int i = 0; i < 32; i++)
545 if(QDir(path).mkpath(".")) break;
550 if(!QDir(path).exists())
555 return QDir(path).canonicalPath();
558 ////////////////////////////////////////////////////////////
560 ////////////////////////////////////////////////////////////
562 LAMEXP_MAKE_OPTION_I(aacEncProfile, 0)
563 LAMEXP_MAKE_OPTION_I(aftenAudioCodingMode, 0)
564 LAMEXP_MAKE_OPTION_I(aftenDynamicRangeCompression, 5)
565 LAMEXP_MAKE_OPTION_I(aftenExponentSearchSize, 8)
566 LAMEXP_MAKE_OPTION_B(aftenFastBitAllocation, false)
567 LAMEXP_MAKE_OPTION_B(antivirNotificationsEnabled, true)
568 LAMEXP_MAKE_OPTION_B(autoUpdateCheckBeta, false)
569 LAMEXP_MAKE_OPTION_B(autoUpdateEnabled, true)
570 LAMEXP_MAKE_OPTION_S(autoUpdateLastCheck, "Never")
571 LAMEXP_MAKE_OPTION_B(bitrateManagementEnabled, false)
572 LAMEXP_MAKE_OPTION_I(bitrateManagementMaxRate, 500)
573 LAMEXP_MAKE_OPTION_I(bitrateManagementMinRate, 32)
574 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateAacEnc, 19)
575 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateAften, 17)
576 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateDcaEnc, 13)
577 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateFLAC, 5)
578 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateLAME, 10)
579 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateMacEnc, 2)
580 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateOggEnc, 16)
581 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateOpusEnc, 11)
582 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateWave, 0)
583 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateAacEnc, 19)
584 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateAften, 17)
585 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateDcaEnc, 13)
586 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateFLAC, 5)
587 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateLAME, 10)
588 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateMacEnc, 2)
589 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateOggEnc, 16)
590 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateOpusEnc, 11)
591 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateWave, 0)
592 LAMEXP_MAKE_OPTION_I(compressionEncoder, 0)
593 LAMEXP_MAKE_OPTION_I(compressionRCModeAacEnc, 0)
594 LAMEXP_MAKE_OPTION_I(compressionRCModeAften, 0)
595 LAMEXP_MAKE_OPTION_I(compressionRCModeDcaEnc, 2)
596 LAMEXP_MAKE_OPTION_I(compressionRCModeFLAC, 0)
597 LAMEXP_MAKE_OPTION_I(compressionRCModeLAME, 0)
598 LAMEXP_MAKE_OPTION_I(compressionRCModeMacEnc, 0)
599 LAMEXP_MAKE_OPTION_I(compressionRCModeOggEnc, 0)
600 LAMEXP_MAKE_OPTION_I(compressionRCModeOpusEnc, 0)
601 LAMEXP_MAKE_OPTION_I(compressionRCModeWave, 2)
602 LAMEXP_MAKE_OPTION_I(compressionVbrQualityAacEnc, 10)
603 LAMEXP_MAKE_OPTION_I(compressionVbrQualityAften, 15)
604 LAMEXP_MAKE_OPTION_I(compressionVbrQualityDcaEnc, 13)
605 LAMEXP_MAKE_OPTION_I(compressionVbrQualityFLAC, 5)
606 LAMEXP_MAKE_OPTION_I(compressionVbrQualityLAME, 7)
607 LAMEXP_MAKE_OPTION_I(compressionVbrQualityMacEnc, 2)
608 LAMEXP_MAKE_OPTION_I(compressionVbrQualityOggEnc, 7)
609 LAMEXP_MAKE_OPTION_I(compressionVbrQualityOpusEnc, 11)
610 LAMEXP_MAKE_OPTION_I(compressionVbrQualityWave, 0)
611 LAMEXP_MAKE_OPTION_B(createPlaylist, true)
612 LAMEXP_MAKE_OPTION_S(currentLanguage, defaultLanguage())
613 LAMEXP_MAKE_OPTION_S(currentLanguageFile, QString())
614 LAMEXP_MAKE_OPTION_S(customParametersAacEnc, QString())
615 LAMEXP_MAKE_OPTION_S(customParametersAften, QString())
616 LAMEXP_MAKE_OPTION_S(customParametersDcaEnc, QString())
617 LAMEXP_MAKE_OPTION_S(customParametersFLAC, QString())
618 LAMEXP_MAKE_OPTION_S(customParametersLAME, QString())
619 LAMEXP_MAKE_OPTION_S(customParametersMacEnc, QString())
620 LAMEXP_MAKE_OPTION_S(customParametersOggEnc, QString())
621 LAMEXP_MAKE_OPTION_S(customParametersOpusEnc, QString())
622 LAMEXP_MAKE_OPTION_S(customParametersWave, QString())
623 LAMEXP_MAKE_OPTION_S(customTempPath, QDesktopServices::storageLocation(QDesktopServices::TempLocation))
624 LAMEXP_MAKE_OPTION_B(customTempPathEnabled, false)
625 LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled, true)
626 LAMEXP_MAKE_OPTION_I(dropBoxWidgetPositionX, -1)
627 LAMEXP_MAKE_OPTION_I(dropBoxWidgetPositionY, -1)
628 LAMEXP_MAKE_OPTION_S(favoriteOutputFolders, QString())
629 LAMEXP_MAKE_OPTION_B(forceStereoDownmix, false)
630 LAMEXP_MAKE_OPTION_B(hibernateComputer, false)
631 LAMEXP_MAKE_OPTION_I(interfaceStyle, 0)
632 LAMEXP_MAKE_OPTION_I(lameAlgoQuality, 2)
633 LAMEXP_MAKE_OPTION_I(lameChannelMode, 0)
634 LAMEXP_MAKE_OPTION_I(licenseAccepted, 0)
635 LAMEXP_MAKE_OPTION_U(maximumInstances, 0)
636 LAMEXP_MAKE_OPTION_U(metaInfoPosition, UINT_MAX)
637 LAMEXP_MAKE_OPTION_S(mostRecentInputPath, defaultDirectory())
638 LAMEXP_MAKE_OPTION_B(neroAACEnable2Pass, true)
639 LAMEXP_MAKE_OPTION_B(neroAacNotificationsEnabled, true)
640 LAMEXP_MAKE_OPTION_B(normalizationFilterEnabled, false)
641 LAMEXP_MAKE_OPTION_I(normalizationFilterEQMode, 0)
642 LAMEXP_MAKE_OPTION_I(normalizationFilterMaxVolume, -50)
643 LAMEXP_MAKE_OPTION_I(opusComplexity, 10)
644 LAMEXP_MAKE_OPTION_B(opusDisableResample, false)
645 LAMEXP_MAKE_OPTION_I(opusFramesize, 3)
646 LAMEXP_MAKE_OPTION_I(opusOptimizeFor, 0)
647 LAMEXP_MAKE_OPTION_S(outputDir, defaultDirectory())
648 LAMEXP_MAKE_OPTION_B(outputToSourceDir, false)
649 LAMEXP_MAKE_OPTION_I(overwriteMode, Overwrite_KeepBoth)
650 LAMEXP_MAKE_OPTION_B(prependRelativeSourcePath, false)
651 LAMEXP_MAKE_OPTION_B(renameOutputFilesEnabled, false)
652 LAMEXP_MAKE_OPTION_S(renameOutputFilesPattern, "[<TrackNo>] <Artist> - <Title>")
653 LAMEXP_MAKE_OPTION_I(samplingRate, 0)
654 LAMEXP_MAKE_OPTION_B(shellIntegrationEnabled, !lamexp_portable_mode())
655 LAMEXP_MAKE_OPTION_B(slowStartup, false)
656 LAMEXP_MAKE_OPTION_B(soundsEnabled, true)
657 LAMEXP_MAKE_OPTION_I(toneAdjustBass, 0)
658 LAMEXP_MAKE_OPTION_I(toneAdjustTreble, 0)
659 LAMEXP_MAKE_OPTION_B(writeMetaTags, true)