Small translation fix.
[LameXP.git] / src / Model_Settings.cpp
blob23cbd973f0d93f63f29e7ef86b9ff36ccbe3f19d
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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.
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"
24 #include "Global.h"
26 #include <QSettings>
27 #include <QDesktopServices>
28 #include <QApplication>
29 #include <QString>
30 #include <QFileInfo>
31 #include <QDir>
32 #include <QStringList>
33 #include <QLocale>
34 #include <QRegExp>
35 #include <QReadWriteLock>
36 #include <QReadLocker>
37 #include <QWriteLocker>
38 #include <QHash>
39 #include <QMutex>
40 #include <QSet>
42 ////////////////////////////////////////////////////////////
43 // SettingsCache Class
44 ////////////////////////////////////////////////////////////
46 class SettingsCache
48 public:
49 SettingsCache(QSettings *configFile) : m_configFile(configFile)
51 m_cache = new QHash<QString, QVariant>();
52 m_cacheLock = new QMutex();
53 m_cacheDirty = new QSet<QString>();
56 ~SettingsCache(void)
58 flushValues();
60 LAMEXP_DELETE(m_cache);
61 LAMEXP_DELETE(m_cacheDirty);
62 LAMEXP_DELETE(m_cacheLock);
63 LAMEXP_DELETE(m_configFile);
66 inline void storeValue(const QString &key, const QVariant &value)
68 QMutexLocker lock(m_cacheLock);
70 if(!m_cache->contains(key))
72 m_cache->insert(key, value);
73 m_cacheDirty->insert(key);
75 else
77 if(m_cache->value(key) != value)
79 m_cache->insert(key, value);
80 m_cacheDirty->insert(key);
85 inline QVariant loadValue(const QString &key, const QVariant &defaultValue) const
87 QMutexLocker lock(m_cacheLock);
89 if(!m_cache->contains(key))
91 const QVariant storedValue = m_configFile->value(key, defaultValue);
92 m_cache->insert(key, storedValue);
95 return m_cache->value(key, defaultValue);
98 inline void flushValues(void)
100 QMutexLocker lock(m_cacheLock);
102 if(!m_cacheDirty->isEmpty())
104 QSet<QString>::ConstIterator iter;
105 for(iter = m_cacheDirty->constBegin(); iter != m_cacheDirty->constEnd(); iter++)
107 if(m_cache->contains(*iter))
109 m_configFile->setValue((*iter), m_cache->value(*iter));
111 else
113 qWarning("Could not find '%s' in cache, but it has been marked as dirty!", (*iter).toUtf8().constData());
116 m_configFile->sync();
117 m_cacheDirty->clear();
121 private:
122 QSettings *m_configFile;
123 QHash<QString, QVariant> *m_cache;
124 QSet<QString> *m_cacheDirty;
125 QMutex *m_cacheLock;
128 ////////////////////////////////////////////////////////////
129 // Macros
130 ////////////////////////////////////////////////////////////
132 #define LAMEXP_MAKE_OPTION_I(OPT,DEF) \
133 int SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toInt(); } \
134 void SettingsModel::OPT(int value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
135 int SettingsModel::OPT##Default(void) { return (DEF); }
137 #define LAMEXP_MAKE_OPTION_S(OPT,DEF) \
138 QString SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toString().trimmed(); } \
139 void SettingsModel::OPT(const QString &value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
140 QString SettingsModel::OPT##Default(void) { return (DEF); }
142 #define LAMEXP_MAKE_OPTION_B(OPT,DEF) \
143 bool SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toBool(); } \
144 void SettingsModel::OPT(bool value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
145 bool SettingsModel::OPT##Default(void) { return (DEF); }
147 #define LAMEXP_MAKE_OPTION_U(OPT,DEF) \
148 unsigned int SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toUInt(); } \
149 void SettingsModel::OPT(unsigned int value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
150 unsigned int SettingsModel::OPT##Default(void) { return (DEF); }
152 #define LAMEXP_MAKE_ID(DEC,STR) static const char *g_settingsId_##DEC = STR
154 #define REMOVE_GROUP(OBJ,ID) do \
156 OBJ->beginGroup(ID); \
157 OBJ->remove(""); \
158 OBJ->endGroup(); \
160 while(0)
162 #define DIR_EXISTS(PATH) (QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
164 ////////////////////////////////////////////////////////////
165 // Constants
166 ////////////////////////////////////////////////////////////
168 //Setting ID's
169 LAMEXP_MAKE_ID(aacEncProfile, "AdvancedOptions/AACEnc/ForceProfile");
170 LAMEXP_MAKE_ID(aftenAudioCodingMode, "AdvancedOptions/Aften/AudioCodingMode");
171 LAMEXP_MAKE_ID(aftenDynamicRangeCompression, "AdvancedOptions/Aften/DynamicRangeCompression");
172 LAMEXP_MAKE_ID(aftenExponentSearchSize, "AdvancedOptions/Aften/ExponentSearchSize");
173 LAMEXP_MAKE_ID(aftenFastBitAllocation, "AdvancedOptions/Aften/FastBitAllocation");
174 LAMEXP_MAKE_ID(antivirNotificationsEnabled, "Flags/EnableAntivirusNotifications");
175 LAMEXP_MAKE_ID(autoUpdateCheckBeta, "AutoUpdate/CheckForBetaVersions");
176 LAMEXP_MAKE_ID(autoUpdateEnabled, "AutoUpdate/Enabled");
177 LAMEXP_MAKE_ID(autoUpdateLastCheck, "AutoUpdate/LastCheck");
178 LAMEXP_MAKE_ID(bitrateManagementEnabled, "AdvancedOptions/BitrateManagement/Enabled");
179 LAMEXP_MAKE_ID(bitrateManagementMaxRate, "AdvancedOptions/BitrateManagement/MaxRate");
180 LAMEXP_MAKE_ID(bitrateManagementMinRate, "AdvancedOptions/BitrateManagement/MinRate");
181 LAMEXP_MAKE_ID(compressionAbrBitrateAacEnc, "Compression/AbrTaretBitrate/AacEnc");
182 LAMEXP_MAKE_ID(compressionAbrBitrateAften, "Compression/AbrTaretBitrate/Aften");
183 LAMEXP_MAKE_ID(compressionAbrBitrateDcaEnc, "Compression/AbrTaretBitrate/DcaEnc");
184 LAMEXP_MAKE_ID(compressionAbrBitrateFLAC, "Compression/AbrTaretBitrate/FLAC");
185 LAMEXP_MAKE_ID(compressionAbrBitrateLAME, "Compression/AbrTaretBitrate/LAME");
186 LAMEXP_MAKE_ID(compressionAbrBitrateOggEnc, "Compression/AbrTaretBitrate/OggEnc");
187 LAMEXP_MAKE_ID(compressionAbrBitrateOpusEnc, "Compression/AbrTaretBitrate/OpusEnc");
188 LAMEXP_MAKE_ID(compressionAbrBitrateWave, "Compression/AbrTaretBitrate/Wave");
189 LAMEXP_MAKE_ID(compressionCbrBitrateAacEnc, "Compression/CbrTaretBitrate/AacEnc");
190 LAMEXP_MAKE_ID(compressionCbrBitrateAften, "Compression/CbrTaretBitrate/Aften");
191 LAMEXP_MAKE_ID(compressionCbrBitrateDcaEnc, "Compression/CbrTaretBitrate/DcaEnc");
192 LAMEXP_MAKE_ID(compressionCbrBitrateFLAC, "Compression/CbrTaretBitrate/FLAC");
193 LAMEXP_MAKE_ID(compressionCbrBitrateLAME, "Compression/CbrTaretBitrate/LAME");
194 LAMEXP_MAKE_ID(compressionCbrBitrateOggEnc, "Compression/CbrTaretBitrate/OggEnc");
195 LAMEXP_MAKE_ID(compressionCbrBitrateOpusEnc, "Compression/CbrTaretBitrate/OpusEnc");
196 LAMEXP_MAKE_ID(compressionCbrBitrateWave, "Compression/CbrTaretBitrate/Wave");
197 LAMEXP_MAKE_ID(compressionEncoder, "Compression/Encoder");
198 LAMEXP_MAKE_ID(compressionRCModeAacEnc, "Compression/RCMode/AacEnc");
199 LAMEXP_MAKE_ID(compressionRCModeAften, "Compression/RCMode/Aften");
200 LAMEXP_MAKE_ID(compressionRCModeDcaEnc, "Compression/RCMode/DcaEnc");
201 LAMEXP_MAKE_ID(compressionRCModeFLAC, "Compression/RCMode/FLAC");
202 LAMEXP_MAKE_ID(compressionRCModeLAME, "Compression/RCMode/LAME");
203 LAMEXP_MAKE_ID(compressionRCModeOggEnc, "Compression/RCMode/OggEnc");
204 LAMEXP_MAKE_ID(compressionRCModeOpusEnc, "Compression/RCMode/OpusEnc");
205 LAMEXP_MAKE_ID(compressionRCModeWave, "Compression/RCMode/Wave");
206 LAMEXP_MAKE_ID(compressionVbrQualityAacEnc, "Compression/VbrQualityLevel/AacEnc");
207 LAMEXP_MAKE_ID(compressionVbrQualityAften, "Compression/VbrQualityLevel/Aften");
208 LAMEXP_MAKE_ID(compressionVbrQualityDcaEnc, "Compression/VbrQualityLevel/DcaEnc");
209 LAMEXP_MAKE_ID(compressionVbrQualityFLAC, "Compression/VbrQualityLevel/FLAC");
210 LAMEXP_MAKE_ID(compressionVbrQualityLAME, "Compression/VbrQualityLevel/LAME");
211 LAMEXP_MAKE_ID(compressionVbrQualityOggEnc, "Compression/VbrQualityLevel/OggEnc");
212 LAMEXP_MAKE_ID(compressionVbrQualityOpusEnc, "Compression/VbrQualityLevel/OpusEnc");
213 LAMEXP_MAKE_ID(compressionVbrQualityWave, "Compression/VbrQualityLevel/Wave");
214 LAMEXP_MAKE_ID(createPlaylist, "Flags/AutoCreatePlaylist");
215 LAMEXP_MAKE_ID(currentLanguage, "Localization/Language");
216 LAMEXP_MAKE_ID(currentLanguageFile, "Localization/UseQMFile");
217 LAMEXP_MAKE_ID(customParametersAacEnc, "AdvancedOptions/CustomParameters/AacEnc");
218 LAMEXP_MAKE_ID(customParametersAften, "AdvancedOptions/CustomParameters/Aften");
219 LAMEXP_MAKE_ID(customParametersDcaEnc, "AdvancedOptions/CustomParameters/DcaEnc");
220 LAMEXP_MAKE_ID(customParametersFLAC, "AdvancedOptions/CustomParameters/FLAC");
221 LAMEXP_MAKE_ID(customParametersLAME, "AdvancedOptions/CustomParameters/LAME");
222 LAMEXP_MAKE_ID(customParametersOggEnc, "AdvancedOptions/CustomParameters/OggEnc");
223 LAMEXP_MAKE_ID(customParametersOpusEnc, "AdvancedOptions/CustomParameters/OpusEnc");
224 LAMEXP_MAKE_ID(customParametersWave, "AdvancedOptions/CustomParameters/Wave");
225 LAMEXP_MAKE_ID(customTempPath, "AdvancedOptions/TempDirectory/CustomPath");
226 LAMEXP_MAKE_ID(customTempPathEnabled, "AdvancedOptions/TempDirectory/UseCustomPath");
227 LAMEXP_MAKE_ID(dropBoxWidgetEnabled, "Flags/EnableDropBoxWidget");
228 LAMEXP_MAKE_ID(favoriteOutputFolders, "OutputDirectory/Favorites");
229 LAMEXP_MAKE_ID(forceStereoDownmix, "AdvancedOptions/StereoDownmix/Force");
230 LAMEXP_MAKE_ID(hibernateComputer, "AdvancedOptions/HibernateComputerOnShutdown");
231 LAMEXP_MAKE_ID(interfaceStyle, "InterfaceStyle");
232 LAMEXP_MAKE_ID(lameAlgoQuality, "AdvancedOptions/LAME/AlgorithmQuality");
233 LAMEXP_MAKE_ID(lameChannelMode, "AdvancedOptions/LAME/ChannelMode");
234 LAMEXP_MAKE_ID(licenseAccepted, "LicenseAccepted");
235 LAMEXP_MAKE_ID(maximumInstances, "AdvancedOptions/Threading/MaximumInstances");
236 LAMEXP_MAKE_ID(metaInfoPosition, "MetaInformation/PlaylistPosition");
237 LAMEXP_MAKE_ID(mostRecentInputPath, "InputDirectory/MostRecentPath");
238 LAMEXP_MAKE_ID(neroAACEnable2Pass, "AdvancedOptions/AACEnc/Enable2Pass");
239 LAMEXP_MAKE_ID(neroAacNotificationsEnabled, "Flags/EnableNeroAacNotifications");
240 LAMEXP_MAKE_ID(normalizationFilterEnabled, "AdvancedOptions/VolumeNormalization/Enabled");
241 LAMEXP_MAKE_ID(normalizationFilterEQMode, "AdvancedOptions/VolumeNormalization/EqualizationMode");
242 LAMEXP_MAKE_ID(normalizationFilterMaxVolume, "AdvancedOptions/VolumeNormalization/MaxVolume");
243 LAMEXP_MAKE_ID(opusComplexity, "AdvancedOptions/Opus/EncodingComplexity");
244 LAMEXP_MAKE_ID(opusDisableResample, "AdvancedOptions/Opus/DisableResample");
245 LAMEXP_MAKE_ID(opusFramesize, "AdvancedOptions/Opus/FrameSize");
246 LAMEXP_MAKE_ID(opusOptimizeFor, "AdvancedOptions/Opus/OptimizeForSignalType");
247 LAMEXP_MAKE_ID(outputDir, "OutputDirectory/SelectedPath");
248 LAMEXP_MAKE_ID(outputToSourceDir, "OutputDirectory/OutputToSourceFolder");
249 LAMEXP_MAKE_ID(overwriteMode, "AdvancedOptions/OverwriteMode");
250 LAMEXP_MAKE_ID(prependRelativeSourcePath, "OutputDirectory/PrependRelativeSourcePath");
251 LAMEXP_MAKE_ID(renameOutputFilesEnabled, "AdvancedOptions/RenameOutputFiles/Enabled");
252 LAMEXP_MAKE_ID(renameOutputFilesPattern, "AdvancedOptions/RenameOutputFiles/Pattern");
253 LAMEXP_MAKE_ID(samplingRate, "AdvancedOptions/Common/Resampling");
254 LAMEXP_MAKE_ID(shellIntegrationEnabled, "Flags/EnableShellIntegration");
255 LAMEXP_MAKE_ID(slowStartup, "Flags/SlowStartupDetected");
256 LAMEXP_MAKE_ID(soundsEnabled, "Flags/EnableSounds");
257 LAMEXP_MAKE_ID(toneAdjustBass, "AdvancedOptions/ToneAdjustment/Bass");
258 LAMEXP_MAKE_ID(toneAdjustTreble, "AdvancedOptions/ToneAdjustment/Treble");
259 LAMEXP_MAKE_ID(versionNumber, "VersionNumber");
260 LAMEXP_MAKE_ID(writeMetaTags, "Flags/WriteMetaTags");
262 //LUT
263 const int SettingsModel::samplingRates[8] = {0, 16000, 22050, 24000, 32000, 44100, 48000, -1};
265 static QReadWriteLock s_lock;
267 ////////////////////////////////////////////////////////////
268 // Constructor
269 ////////////////////////////////////////////////////////////
271 SettingsModel::SettingsModel(void)
273 QString configPath = "LameXP.ini";
275 if(!lamexp_portable_mode())
277 QString dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
278 if(!dataPath.isEmpty())
280 configPath = QString("%1/config.ini").arg(QDir(dataPath).canonicalPath());
282 else
284 qWarning("SettingsModel: DataLocation could not be initialized!");
285 dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
286 if(!dataPath.isEmpty())
288 configPath = QString("%1/LameXP.ini").arg(QDir(dataPath).canonicalPath());
292 else
294 qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n");
295 QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath();
296 if(appPath.isEmpty())
298 appPath = QFileInfo(QApplication::applicationFilePath()).absoluteFilePath();
300 if(QFileInfo(appPath).exists() && QFileInfo(appPath).isFile())
302 configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName());
306 //Create settings
307 QSettings *configFile = new QSettings(configPath, QSettings::IniFormat);
308 const QString groupKey = QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_confg());
309 QStringList childGroups =configFile->childGroups();
311 //Clean-up settings
312 while(!childGroups.isEmpty())
314 QString current = childGroups.takeFirst();
315 QRegExp filter("^LameXP_(\\d+)(\\d\\d)(\\d\\d\\d\\d\\d)$");
316 if(filter.indexIn(current) >= 0)
318 bool ok = false;
319 unsigned int temp = filter.cap(3).toUInt(&ok) + 10;
320 if(ok && (temp >= lamexp_version_confg()))
322 continue;
325 qWarning("Deleting obsolete group from config: %s", current.toUtf8().constData());
326 REMOVE_GROUP(configFile, current);
329 //Setup settings
330 configFile->beginGroup(groupKey);
331 configFile->setValue(g_settingsId_versionNumber, QApplication::applicationVersion());
332 configFile->sync();
334 //Create the cache
335 m_configCache = new SettingsCache(configFile);
338 ////////////////////////////////////////////////////////////
339 // Destructor
340 ////////////////////////////////////////////////////////////
342 SettingsModel::~SettingsModel(void)
344 LAMEXP_DELETE(m_configCache);
345 LAMEXP_DELETE(m_defaultLanguage);
348 ////////////////////////////////////////////////////////////
349 // Public Functions
350 ////////////////////////////////////////////////////////////
352 #define CHECK_RCMODE(NAME) do\
354 if(this->compressionRCMode##NAME() < SettingsModel::VBRMode || this->compressionRCMode##NAME() >= SettingsModel::RCMODE_COUNT) \
356 this->compressionRCMode##NAME(SettingsModel::VBRMode); \
359 while(0)
361 void SettingsModel::validate(void)
363 if(this->compressionEncoder() < SettingsModel::MP3Encoder || this->compressionEncoder() >= SettingsModel::ENCODER_COUNT)
365 this->compressionEncoder(SettingsModel::MP3Encoder);
368 CHECK_RCMODE(LAME);
369 CHECK_RCMODE(OggEnc);
370 CHECK_RCMODE(AacEnc);
371 CHECK_RCMODE(Aften);
372 CHECK_RCMODE(OpusEnc);
374 if(!(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")))
376 if(!(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll")))
378 if(!(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")))
380 if(this->compressionEncoder() == SettingsModel::AACEncoder)
382 qWarning("AAC encoder selected, but not available any more. Reverting to MP3!");
383 this->compressionEncoder(SettingsModel::MP3Encoder);
389 if(this->outputDir().isEmpty() || (!DIR_EXISTS(this->outputDir())))
391 qWarning("Output directory not set yet or does NOT exist anymore -> Resetting");
392 this->outputDir(defaultDirectory());
395 if(this->mostRecentInputPath().isEmpty() || (!DIR_EXISTS(this->mostRecentInputPath())))
397 qWarning("Most recent input directory not set yet or does NOT exist anymore -> Resetting");
398 this->mostRecentInputPath(defaultDirectory());
401 if(!this->currentLanguageFile().isEmpty())
403 const QString qmPath = QFileInfo(this->currentLanguageFile()).canonicalFilePath();
404 if(qmPath.isEmpty() || (!(QFileInfo(qmPath).exists() && QFileInfo(qmPath).isFile() && (QFileInfo(qmPath).suffix().compare("qm", Qt::CaseInsensitive) == 0))))
406 qWarning("Current language file missing, reverting to built-in translator!");
407 this->currentLanguageFile(QString());
411 if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive))
413 qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
414 this->currentLanguage(defaultLanguage());
417 if(this->hibernateComputer())
419 if(!lamexp_is_hibernation_supported())
421 this->hibernateComputer(false);
425 if(this->overwriteMode() < SettingsModel::Overwrite_KeepBoth || this->overwriteMode() > SettingsModel::Overwrite_Replaces)
427 this->overwriteMode(SettingsModel::Overwrite_KeepBoth);
432 void SettingsModel::syncNow(void)
434 m_configCache->flushValues();
437 ////////////////////////////////////////////////////////////
438 // Private Functions
439 ////////////////////////////////////////////////////////////
441 QString *SettingsModel::m_defaultLanguage = NULL;
443 QString SettingsModel::defaultLanguage(void) const
445 QReadLocker readLock(&s_lock);
447 //Default already initialized?
448 if(m_defaultLanguage)
450 return *m_defaultLanguage;
453 //Acquire write lock now
454 readLock.unlock();
455 QWriteLocker writeLock(&s_lock);
457 //Default still not initialized?
458 if(m_defaultLanguage)
460 return *m_defaultLanguage;
463 //Detect system langauge
464 QLocale systemLanguage= QLocale::system();
465 qDebug("[Locale]");
466 qDebug("Language: %s (%d)", QLocale::languageToString(systemLanguage.language()).toUtf8().constData(), systemLanguage.language());
467 qDebug("Country is: %s (%d)", QLocale::countryToString(systemLanguage.country()).toUtf8().constData(), systemLanguage.country());
468 qDebug("Script is: %s (%d)\n", QLocale::scriptToString(systemLanguage.script()).toUtf8().constData(), systemLanguage.script());
470 //Check if we can use the default translation
471 if(systemLanguage.language() == QLocale::English /*|| systemLanguage.language() == QLocale::C*/)
473 m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
474 return LAMEXP_DEFAULT_LANGID;
477 //Try to find a suitable translation for the user's system language *and* country
478 QStringList languages = lamexp_query_translations();
479 while(!languages.isEmpty())
481 QString currentLangId = languages.takeFirst();
482 if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
484 if(lamexp_translation_country(currentLangId) == systemLanguage.country())
486 m_defaultLanguage = new QString(currentLangId);
487 return currentLangId;
492 //Try to find a suitable translation for the user's system language
493 languages = lamexp_query_translations();
494 while(!languages.isEmpty())
496 QString currentLangId = languages.takeFirst();
497 if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
499 m_defaultLanguage = new QString(currentLangId);
500 return currentLangId;
504 //Fall back to the default translation
505 m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
506 return LAMEXP_DEFAULT_LANGID;
509 QString SettingsModel::defaultDirectory(void) const
511 QString defaultLocation = initDirectory(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
513 if(defaultLocation.isEmpty())
515 defaultLocation = initDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
517 if(defaultLocation.isEmpty())
519 defaultLocation = initDirectory(QDir::currentPath());
523 return defaultLocation;
526 QString SettingsModel::initDirectory(const QString &path) const
528 if(path.isEmpty())
530 return QString();
533 if(!QDir(path).exists())
535 for(int i = 0; i < 32; i++)
537 if(QDir(path).mkpath(".")) break;
538 Sleep(1);
542 if(!QDir(path).exists())
544 return QString();
547 return QDir(path).canonicalPath();
550 ////////////////////////////////////////////////////////////
551 // Getter and Setter
552 ////////////////////////////////////////////////////////////
554 LAMEXP_MAKE_OPTION_I(aacEncProfile, 0)
555 LAMEXP_MAKE_OPTION_I(aftenAudioCodingMode, 0)
556 LAMEXP_MAKE_OPTION_I(aftenDynamicRangeCompression, 5)
557 LAMEXP_MAKE_OPTION_I(aftenExponentSearchSize, 8)
558 LAMEXP_MAKE_OPTION_B(aftenFastBitAllocation, false)
559 LAMEXP_MAKE_OPTION_B(antivirNotificationsEnabled, true)
560 LAMEXP_MAKE_OPTION_B(autoUpdateCheckBeta, false)
561 LAMEXP_MAKE_OPTION_B(autoUpdateEnabled, true)
562 LAMEXP_MAKE_OPTION_S(autoUpdateLastCheck, "Never")
563 LAMEXP_MAKE_OPTION_B(bitrateManagementEnabled, false)
564 LAMEXP_MAKE_OPTION_I(bitrateManagementMaxRate, 500)
565 LAMEXP_MAKE_OPTION_I(bitrateManagementMinRate, 32)
566 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateAacEnc, 20)
567 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateAften, 15)
568 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateDcaEnc, 47)
569 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateFLAC, 0)
570 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateLAME, 10)
571 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateOggEnc, 20)
572 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateOpusEnc, 16)
573 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateWave, 0)
574 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateAacEnc, 20)
575 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateAften, 15)
576 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateDcaEnc, 47)
577 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateFLAC, 0)
578 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateLAME, 10)
579 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateOggEnc, 20)
580 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateOpusEnc, 16)
581 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateWave, 0)
582 LAMEXP_MAKE_OPTION_I(compressionEncoder, 0)
583 LAMEXP_MAKE_OPTION_I(compressionRCModeAacEnc, 0)
584 LAMEXP_MAKE_OPTION_I(compressionRCModeAften, 0)
585 LAMEXP_MAKE_OPTION_I(compressionRCModeDcaEnc, 0)
586 LAMEXP_MAKE_OPTION_I(compressionRCModeFLAC, 0)
587 LAMEXP_MAKE_OPTION_I(compressionRCModeLAME, 0)
588 LAMEXP_MAKE_OPTION_I(compressionRCModeOggEnc, 0)
589 LAMEXP_MAKE_OPTION_I(compressionRCModeOpusEnc, 0)
590 LAMEXP_MAKE_OPTION_I(compressionRCModeWave, 0)
591 LAMEXP_MAKE_OPTION_I(compressionVbrQualityAacEnc, 10)
592 LAMEXP_MAKE_OPTION_I(compressionVbrQualityAften, 8)
593 LAMEXP_MAKE_OPTION_I(compressionVbrQualityDcaEnc, 0)
594 LAMEXP_MAKE_OPTION_I(compressionVbrQualityFLAC, 8)
595 LAMEXP_MAKE_OPTION_I(compressionVbrQualityLAME, 7)
596 LAMEXP_MAKE_OPTION_I(compressionVbrQualityOggEnc, 5)
597 LAMEXP_MAKE_OPTION_I(compressionVbrQualityOpusEnc, 0)
598 LAMEXP_MAKE_OPTION_I(compressionVbrQualityWave, 0)
599 LAMEXP_MAKE_OPTION_B(createPlaylist, true)
600 LAMEXP_MAKE_OPTION_S(currentLanguage, defaultLanguage())
601 LAMEXP_MAKE_OPTION_S(currentLanguageFile, QString())
602 LAMEXP_MAKE_OPTION_S(customParametersAacEnc, QString())
603 LAMEXP_MAKE_OPTION_S(customParametersAften, QString())
604 LAMEXP_MAKE_OPTION_S(customParametersDcaEnc, QString())
605 LAMEXP_MAKE_OPTION_S(customParametersFLAC, QString())
606 LAMEXP_MAKE_OPTION_S(customParametersLAME, QString())
607 LAMEXP_MAKE_OPTION_S(customParametersOggEnc, QString())
608 LAMEXP_MAKE_OPTION_S(customParametersOpusEnc, QString())
609 LAMEXP_MAKE_OPTION_S(customParametersWave, QString())
610 LAMEXP_MAKE_OPTION_S(customTempPath, QDesktopServices::storageLocation(QDesktopServices::TempLocation))
611 LAMEXP_MAKE_OPTION_B(customTempPathEnabled, false)
612 LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled, true)
613 LAMEXP_MAKE_OPTION_S(favoriteOutputFolders, QString())
614 LAMEXP_MAKE_OPTION_B(forceStereoDownmix, false)
615 LAMEXP_MAKE_OPTION_B(hibernateComputer, false)
616 LAMEXP_MAKE_OPTION_I(interfaceStyle, 0)
617 LAMEXP_MAKE_OPTION_I(lameAlgoQuality, 2)
618 LAMEXP_MAKE_OPTION_I(lameChannelMode, 0)
619 LAMEXP_MAKE_OPTION_I(licenseAccepted, 0)
620 LAMEXP_MAKE_OPTION_U(maximumInstances, 0)
621 LAMEXP_MAKE_OPTION_U(metaInfoPosition, UINT_MAX)
622 LAMEXP_MAKE_OPTION_S(mostRecentInputPath, defaultDirectory())
623 LAMEXP_MAKE_OPTION_B(neroAACEnable2Pass, true)
624 LAMEXP_MAKE_OPTION_B(neroAacNotificationsEnabled, true)
625 LAMEXP_MAKE_OPTION_B(normalizationFilterEnabled, false)
626 LAMEXP_MAKE_OPTION_I(normalizationFilterEQMode, 0)
627 LAMEXP_MAKE_OPTION_I(normalizationFilterMaxVolume, -50)
628 LAMEXP_MAKE_OPTION_I(opusComplexity, 10)
629 LAMEXP_MAKE_OPTION_B(opusDisableResample, false)
630 LAMEXP_MAKE_OPTION_I(opusFramesize, 3)
631 LAMEXP_MAKE_OPTION_I(opusOptimizeFor, 0)
632 LAMEXP_MAKE_OPTION_S(outputDir, defaultDirectory())
633 LAMEXP_MAKE_OPTION_B(outputToSourceDir, false)
634 LAMEXP_MAKE_OPTION_I(overwriteMode, Overwrite_KeepBoth)
635 LAMEXP_MAKE_OPTION_B(prependRelativeSourcePath, false)
636 LAMEXP_MAKE_OPTION_B(renameOutputFilesEnabled, false)
637 LAMEXP_MAKE_OPTION_S(renameOutputFilesPattern, "[<TrackNo>] <Artist> - <Title>")
638 LAMEXP_MAKE_OPTION_I(samplingRate, 0)
639 LAMEXP_MAKE_OPTION_B(shellIntegrationEnabled, !lamexp_portable_mode())
640 LAMEXP_MAKE_OPTION_B(slowStartup, false)
641 LAMEXP_MAKE_OPTION_B(soundsEnabled, true)
642 LAMEXP_MAKE_OPTION_I(toneAdjustBass, 0)
643 LAMEXP_MAKE_OPTION_I(toneAdjustTreble, 0)
644 LAMEXP_MAKE_OPTION_B(writeMetaTags, true)