Updated SoX binary to v14.4.2-Git (2014-10-06), compiled with ICL 15.0 and MSVC 12.0.
[LameXP.git] / src / Model_Settings.cpp
blobb7301baa19f8e6445a2e8a5177384a6ece81e92d
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
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, 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"
25 #include "Global.h"
26 #include "Registry_Encoder.h"
28 #include <QSettings>
29 #include <QDesktopServices>
30 #include <QApplication>
31 #include <QString>
32 #include <QFileInfo>
33 #include <QDir>
34 #include <QStringList>
35 #include <QLocale>
36 #include <QRegExp>
37 #include <QReadWriteLock>
38 #include <QReadLocker>
39 #include <QWriteLocker>
40 #include <QHash>
41 #include <QMutex>
42 #include <QSet>
44 ////////////////////////////////////////////////////////////
45 // SettingsCache Class
46 ////////////////////////////////////////////////////////////
48 class SettingsCache
50 public:
51 SettingsCache(QSettings *configFile) : m_configFile(configFile)
53 m_cache = new QHash<QString, QVariant>();
54 m_cacheLock = new QMutex();
55 m_cacheDirty = new QSet<QString>();
58 ~SettingsCache(void)
60 flushValues();
62 LAMEXP_DELETE(m_cache);
63 LAMEXP_DELETE(m_cacheDirty);
64 LAMEXP_DELETE(m_cacheLock);
65 LAMEXP_DELETE(m_configFile);
68 inline void storeValue(const QString &key, const QVariant &value)
70 QMutexLocker lock(m_cacheLock);
72 if(!m_cache->contains(key))
74 m_cache->insert(key, value);
75 m_cacheDirty->insert(key);
77 else
79 if(m_cache->value(key) != value)
81 m_cache->insert(key, value);
82 m_cacheDirty->insert(key);
87 inline QVariant loadValue(const QString &key, const QVariant &defaultValue) const
89 QMutexLocker lock(m_cacheLock);
91 if(!m_cache->contains(key))
93 const QVariant storedValue = m_configFile->value(key, defaultValue);
94 m_cache->insert(key, storedValue);
97 return m_cache->value(key, defaultValue);
100 inline void flushValues(void)
102 QMutexLocker lock(m_cacheLock);
104 if(!m_cacheDirty->isEmpty())
106 QSet<QString>::ConstIterator iter;
107 for(iter = m_cacheDirty->constBegin(); iter != m_cacheDirty->constEnd(); iter++)
109 if(m_cache->contains(*iter))
111 m_configFile->setValue((*iter), m_cache->value(*iter));
113 else
115 qWarning("Could not find '%s' in cache, but it has been marked as dirty!", QUTF8(*iter));
118 m_configFile->sync();
119 m_cacheDirty->clear();
123 private:
124 QSettings *m_configFile;
125 QHash<QString, QVariant> *m_cache;
126 QSet<QString> *m_cacheDirty;
127 QMutex *m_cacheLock;
130 ////////////////////////////////////////////////////////////
131 // Macros
132 ////////////////////////////////////////////////////////////
134 #define LAMEXP_MAKE_OPTION_I(OPT,DEF) \
135 int SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toInt(); } \
136 void SettingsModel::OPT(int value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
137 int SettingsModel::OPT##Default(void) { return (DEF); }
139 #define LAMEXP_MAKE_OPTION_S(OPT,DEF) \
140 QString SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toString().trimmed(); } \
141 void SettingsModel::OPT(const QString &value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
142 QString SettingsModel::OPT##Default(void) { return (DEF); }
144 #define LAMEXP_MAKE_OPTION_B(OPT,DEF) \
145 bool SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toBool(); } \
146 void SettingsModel::OPT(bool value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
147 bool SettingsModel::OPT##Default(void) { return (DEF); }
149 #define LAMEXP_MAKE_OPTION_U(OPT,DEF) \
150 unsigned int SettingsModel::OPT(void) const { return m_configCache->loadValue(g_settingsId_##OPT, (DEF)).toUInt(); } \
151 void SettingsModel::OPT(unsigned int value) { m_configCache->storeValue(g_settingsId_##OPT, value); } \
152 unsigned int SettingsModel::OPT##Default(void) { return (DEF); }
154 #define LAMEXP_MAKE_ID(DEC,STR) static const char *g_settingsId_##DEC = STR
156 #define REMOVE_GROUP(OBJ,ID) do \
158 OBJ->beginGroup(ID); \
159 OBJ->remove(""); \
160 OBJ->endGroup(); \
162 while(0)
164 #define DIR_EXISTS(PATH) (QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
166 ////////////////////////////////////////////////////////////
167 // Constants
168 ////////////////////////////////////////////////////////////
170 //Setting ID's
171 LAMEXP_MAKE_ID(aacEncProfile, "AdvancedOptions/AACEnc/ForceProfile");
172 LAMEXP_MAKE_ID(aftenAudioCodingMode, "AdvancedOptions/Aften/AudioCodingMode");
173 LAMEXP_MAKE_ID(aftenDynamicRangeCompression, "AdvancedOptions/Aften/DynamicRangeCompression");
174 LAMEXP_MAKE_ID(aftenExponentSearchSize, "AdvancedOptions/Aften/ExponentSearchSize");
175 LAMEXP_MAKE_ID(aftenFastBitAllocation, "AdvancedOptions/Aften/FastBitAllocation");
176 LAMEXP_MAKE_ID(antivirNotificationsEnabled, "Flags/EnableAntivirusNotifications");
177 LAMEXP_MAKE_ID(autoUpdateCheckBeta, "AutoUpdate/CheckForBetaVersions");
178 LAMEXP_MAKE_ID(autoUpdateEnabled, "AutoUpdate/Enabled");
179 LAMEXP_MAKE_ID(autoUpdateLastCheck, "AutoUpdate/LastCheck");
180 LAMEXP_MAKE_ID(bitrateManagementEnabled, "AdvancedOptions/BitrateManagement/Enabled");
181 LAMEXP_MAKE_ID(bitrateManagementMaxRate, "AdvancedOptions/BitrateManagement/MaxRate");
182 LAMEXP_MAKE_ID(bitrateManagementMinRate, "AdvancedOptions/BitrateManagement/MinRate");
183 LAMEXP_MAKE_ID(compressionAbrBitrateAacEnc, "Compression/AbrTaretBitrate/AacEnc");
184 LAMEXP_MAKE_ID(compressionAbrBitrateAften, "Compression/AbrTaretBitrate/Aften");
185 LAMEXP_MAKE_ID(compressionAbrBitrateDcaEnc, "Compression/AbrTaretBitrate/DcaEnc");
186 LAMEXP_MAKE_ID(compressionAbrBitrateFLAC, "Compression/AbrTaretBitrate/FLAC");
187 LAMEXP_MAKE_ID(compressionAbrBitrateLAME, "Compression/AbrTaretBitrate/LAME");
188 LAMEXP_MAKE_ID(compressionAbrBitrateMacEnc, "Compression/AbrTaretBitrate/MacEnc");
189 LAMEXP_MAKE_ID(compressionAbrBitrateOggEnc, "Compression/AbrTaretBitrate/OggEnc");
190 LAMEXP_MAKE_ID(compressionAbrBitrateOpusEnc, "Compression/AbrTaretBitrate/OpusEnc");
191 LAMEXP_MAKE_ID(compressionAbrBitrateWave, "Compression/AbrTaretBitrate/Wave");
192 LAMEXP_MAKE_ID(compressionCbrBitrateAacEnc, "Compression/CbrTaretBitrate/AacEnc");
193 LAMEXP_MAKE_ID(compressionCbrBitrateAften, "Compression/CbrTaretBitrate/Aften");
194 LAMEXP_MAKE_ID(compressionCbrBitrateDcaEnc, "Compression/CbrTaretBitrate/DcaEnc");
195 LAMEXP_MAKE_ID(compressionCbrBitrateFLAC, "Compression/CbrTaretBitrate/FLAC");
196 LAMEXP_MAKE_ID(compressionCbrBitrateLAME, "Compression/CbrTaretBitrate/LAME");
197 LAMEXP_MAKE_ID(compressionCbrBitrateMacEnc, "Compression/CbrTaretBitrate/MacEnc");
198 LAMEXP_MAKE_ID(compressionCbrBitrateOggEnc, "Compression/CbrTaretBitrate/OggEnc");
199 LAMEXP_MAKE_ID(compressionCbrBitrateOpusEnc, "Compression/CbrTaretBitrate/OpusEnc");
200 LAMEXP_MAKE_ID(compressionCbrBitrateWave, "Compression/CbrTaretBitrate/Wave");
201 LAMEXP_MAKE_ID(compressionEncoder, "Compression/Encoder");
202 LAMEXP_MAKE_ID(compressionRCModeAacEnc, "Compression/RCMode/AacEnc");
203 LAMEXP_MAKE_ID(compressionRCModeAften, "Compression/RCMode/Aften");
204 LAMEXP_MAKE_ID(compressionRCModeDcaEnc, "Compression/RCMode/DcaEnc");
205 LAMEXP_MAKE_ID(compressionRCModeFLAC, "Compression/RCMode/FLAC");
206 LAMEXP_MAKE_ID(compressionRCModeLAME, "Compression/RCMode/LAME");
207 LAMEXP_MAKE_ID(compressionRCModeMacEnc, "Compression/RCMode/MacEnc");
208 LAMEXP_MAKE_ID(compressionRCModeOggEnc, "Compression/RCMode/OggEnc");
209 LAMEXP_MAKE_ID(compressionRCModeOpusEnc, "Compression/RCMode/OpusEnc");
210 LAMEXP_MAKE_ID(compressionRCModeWave, "Compression/RCMode/Wave");
211 LAMEXP_MAKE_ID(compressionVbrQualityAacEnc, "Compression/VbrQualityLevel/AacEnc");
212 LAMEXP_MAKE_ID(compressionVbrQualityAften, "Compression/VbrQualityLevel/Aften");
213 LAMEXP_MAKE_ID(compressionVbrQualityDcaEnc, "Compression/VbrQualityLevel/DcaEnc");
214 LAMEXP_MAKE_ID(compressionVbrQualityFLAC, "Compression/VbrQualityLevel/FLAC");
215 LAMEXP_MAKE_ID(compressionVbrQualityLAME, "Compression/VbrQualityLevel/LAME");
216 LAMEXP_MAKE_ID(compressionVbrQualityMacEnc, "Compression/VbrQualityLevel/MacEnc");
217 LAMEXP_MAKE_ID(compressionVbrQualityOggEnc, "Compression/VbrQualityLevel/OggEnc");
218 LAMEXP_MAKE_ID(compressionVbrQualityOpusEnc, "Compression/VbrQualityLevel/OpusEnc");
219 LAMEXP_MAKE_ID(compressionVbrQualityWave, "Compression/VbrQualityLevel/Wave");
220 LAMEXP_MAKE_ID(createPlaylist, "Flags/AutoCreatePlaylist");
221 LAMEXP_MAKE_ID(currentLanguage, "Localization/Language");
222 LAMEXP_MAKE_ID(currentLanguageFile, "Localization/UseQMFile");
223 LAMEXP_MAKE_ID(customParametersAacEnc, "AdvancedOptions/CustomParameters/AacEnc");
224 LAMEXP_MAKE_ID(customParametersAften, "AdvancedOptions/CustomParameters/Aften");
225 LAMEXP_MAKE_ID(customParametersDcaEnc, "AdvancedOptions/CustomParameters/DcaEnc");
226 LAMEXP_MAKE_ID(customParametersFLAC, "AdvancedOptions/CustomParameters/FLAC");
227 LAMEXP_MAKE_ID(customParametersLAME, "AdvancedOptions/CustomParameters/LAME");
228 LAMEXP_MAKE_ID(customParametersMacEnc, "AdvancedOptions/CustomParameters/MacEnc");
229 LAMEXP_MAKE_ID(customParametersOggEnc, "AdvancedOptions/CustomParameters/OggEnc");
230 LAMEXP_MAKE_ID(customParametersOpusEnc, "AdvancedOptions/CustomParameters/OpusEnc");
231 LAMEXP_MAKE_ID(customParametersWave, "AdvancedOptions/CustomParameters/Wave");
232 LAMEXP_MAKE_ID(customTempPath, "AdvancedOptions/TempDirectory/CustomPath");
233 LAMEXP_MAKE_ID(customTempPathEnabled, "AdvancedOptions/TempDirectory/UseCustomPath");
234 LAMEXP_MAKE_ID(dropBoxWidgetEnabled, "DropBoxWidget/Enabled");
235 LAMEXP_MAKE_ID(dropBoxWidgetPositionX, "DropBoxWidget/Position/X");
236 LAMEXP_MAKE_ID(dropBoxWidgetPositionY, "DropBoxWidget/Position/Y");
237 LAMEXP_MAKE_ID(favoriteOutputFolders, "OutputDirectory/Favorites");
238 LAMEXP_MAKE_ID(forceStereoDownmix, "AdvancedOptions/StereoDownmix/Force");
239 LAMEXP_MAKE_ID(hibernateComputer, "AdvancedOptions/HibernateComputerOnShutdown");
240 LAMEXP_MAKE_ID(interfaceStyle, "InterfaceStyle");
241 LAMEXP_MAKE_ID(lameAlgoQuality, "AdvancedOptions/LAME/AlgorithmQuality");
242 LAMEXP_MAKE_ID(lameChannelMode, "AdvancedOptions/LAME/ChannelMode");
243 LAMEXP_MAKE_ID(licenseAccepted, "LicenseAccepted");
244 LAMEXP_MAKE_ID(maximumInstances, "AdvancedOptions/Threading/MaximumInstances");
245 LAMEXP_MAKE_ID(metaInfoPosition, "MetaInformation/PlaylistPosition");
246 LAMEXP_MAKE_ID(mostRecentInputPath, "InputDirectory/MostRecentPath");
247 LAMEXP_MAKE_ID(neroAACEnable2Pass, "AdvancedOptions/AACEnc/Enable2Pass");
248 LAMEXP_MAKE_ID(neroAacNotificationsEnabled, "Flags/EnableNeroAacNotifications");
249 LAMEXP_MAKE_ID(normalizationFilterEnabled, "AdvancedOptions/VolumeNormalization/Enabled");
250 LAMEXP_MAKE_ID(normalizationFilterEQMode, "AdvancedOptions/VolumeNormalization/EqualizationMode");
251 LAMEXP_MAKE_ID(normalizationFilterMaxVolume, "AdvancedOptions/VolumeNormalization/MaxVolume");
252 LAMEXP_MAKE_ID(opusComplexity, "AdvancedOptions/Opus/EncodingComplexity");
253 LAMEXP_MAKE_ID(opusDisableResample, "AdvancedOptions/Opus/DisableResample");
254 LAMEXP_MAKE_ID(opusFramesize, "AdvancedOptions/Opus/FrameSize");
255 LAMEXP_MAKE_ID(opusOptimizeFor, "AdvancedOptions/Opus/OptimizeForSignalType");
256 LAMEXP_MAKE_ID(outputDir, "OutputDirectory/SelectedPath");
257 LAMEXP_MAKE_ID(outputToSourceDir, "OutputDirectory/OutputToSourceFolder");
258 LAMEXP_MAKE_ID(overwriteMode, "AdvancedOptions/OverwriteMode");
259 LAMEXP_MAKE_ID(prependRelativeSourcePath, "OutputDirectory/PrependRelativeSourcePath");
260 LAMEXP_MAKE_ID(renameOutputFilesEnabled, "AdvancedOptions/RenameOutputFiles/Enabled");
261 LAMEXP_MAKE_ID(renameOutputFilesPattern, "AdvancedOptions/RenameOutputFiles/Pattern");
262 LAMEXP_MAKE_ID(samplingRate, "AdvancedOptions/Common/Resampling");
263 LAMEXP_MAKE_ID(shellIntegrationEnabled, "Flags/EnableShellIntegration");
264 LAMEXP_MAKE_ID(slowStartup, "Flags/SlowStartupDetected");
265 LAMEXP_MAKE_ID(soundsEnabled, "Flags/EnableSounds");
266 LAMEXP_MAKE_ID(toneAdjustBass, "AdvancedOptions/ToneAdjustment/Bass");
267 LAMEXP_MAKE_ID(toneAdjustTreble, "AdvancedOptions/ToneAdjustment/Treble");
268 LAMEXP_MAKE_ID(versionNumber, "VersionNumber");
269 LAMEXP_MAKE_ID(writeMetaTags, "Flags/WriteMetaTags");
271 //LUT
272 const int SettingsModel::samplingRates[8] = {0, 16000, 22050, 24000, 32000, 44100, 48000, -1};
274 static QReadWriteLock s_lock;
276 ////////////////////////////////////////////////////////////
277 // Constructor
278 ////////////////////////////////////////////////////////////
280 SettingsModel::SettingsModel(void)
282 QString configPath = "LameXP.ini";
284 if(!lamexp_portable_mode())
286 QString dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
287 if(!dataPath.isEmpty())
289 configPath = QString("%1/config.ini").arg(QDir(dataPath).canonicalPath());
291 else
293 qWarning("SettingsModel: DataLocation could not be initialized!");
294 dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
295 if(!dataPath.isEmpty())
297 configPath = QString("%1/LameXP.ini").arg(QDir(dataPath).canonicalPath());
301 else
303 qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n");
304 QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath();
305 if(appPath.isEmpty())
307 appPath = QFileInfo(QApplication::applicationFilePath()).absoluteFilePath();
309 if(QFileInfo(appPath).exists() && QFileInfo(appPath).isFile())
311 configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName());
315 //Create settings
316 QSettings *configFile = new QSettings(configPath, QSettings::IniFormat);
317 const QString groupKey = QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_confg());
318 QStringList childGroups =configFile->childGroups();
320 //Clean-up settings
321 while(!childGroups.isEmpty())
323 QString current = childGroups.takeFirst();
324 QRegExp filter("^LameXP_(\\d+)(\\d\\d)(\\d\\d\\d\\d\\d)$");
325 if(filter.indexIn(current) >= 0)
327 bool ok = false;
328 unsigned int temp = filter.cap(3).toUInt(&ok) + 10;
329 if(ok && (temp >= lamexp_version_confg()))
331 continue;
334 qWarning("Deleting obsolete group from config: %s", QUTF8(current));
335 REMOVE_GROUP(configFile, current);
338 //Setup settings
339 configFile->beginGroup(groupKey);
340 configFile->setValue(g_settingsId_versionNumber, QApplication::applicationVersion());
341 configFile->sync();
343 //Create the cache
344 m_configCache = new SettingsCache(configFile);
347 ////////////////////////////////////////////////////////////
348 // Destructor
349 ////////////////////////////////////////////////////////////
351 SettingsModel::~SettingsModel(void)
353 LAMEXP_DELETE(m_configCache);
354 LAMEXP_DELETE(m_defaultLanguage);
357 ////////////////////////////////////////////////////////////
358 // Public Functions
359 ////////////////////////////////////////////////////////////
361 #define CHECK_RCMODE(NAME) do\
363 if(this->compressionRCMode##NAME() < SettingsModel::VBRMode || this->compressionRCMode##NAME() >= SettingsModel::RCMODE_COUNT) \
365 this->compressionRCMode##NAME(SettingsModel::VBRMode); \
368 while(0)
370 void SettingsModel::validate(void)
372 if(this->compressionEncoder() < SettingsModel::MP3Encoder || this->compressionEncoder() >= SettingsModel::ENCODER_COUNT)
374 this->compressionEncoder(SettingsModel::MP3Encoder);
377 CHECK_RCMODE(LAME);
378 CHECK_RCMODE(OggEnc);
379 CHECK_RCMODE(AacEnc);
380 CHECK_RCMODE(Aften);
381 CHECK_RCMODE(OpusEnc);
383 if(EncoderRegistry::getAacEncoder() == AAC_ENCODER_NONE)
385 if(this->compressionEncoder() == SettingsModel::AACEncoder)
387 qWarning("AAC encoder selected, but not available any more. Reverting to MP3!");
388 this->compressionEncoder(SettingsModel::MP3Encoder);
392 if(this->outputDir().isEmpty() || (!DIR_EXISTS(this->outputDir())))
394 qWarning("Output directory not set yet or does NOT exist anymore -> Resetting");
395 this->outputDir(defaultDirectory());
398 if(this->mostRecentInputPath().isEmpty() || (!DIR_EXISTS(this->mostRecentInputPath())))
400 qWarning("Most recent input directory not set yet or does NOT exist anymore -> Resetting");
401 this->mostRecentInputPath(defaultDirectory());
404 if(!this->currentLanguageFile().isEmpty())
406 const QString qmPath = QFileInfo(this->currentLanguageFile()).canonicalFilePath();
407 if(qmPath.isEmpty() || (!(QFileInfo(qmPath).exists() && QFileInfo(qmPath).isFile() && (QFileInfo(qmPath).suffix().compare("qm", Qt::CaseInsensitive) == 0))))
409 qWarning("Current language file missing, reverting to built-in translator!");
410 this->currentLanguageFile(QString());
414 if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive))
416 qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
417 this->currentLanguage(defaultLanguage());
420 if(this->hibernateComputer())
422 if(!lamexp_is_hibernation_supported())
424 this->hibernateComputer(false);
428 if(this->overwriteMode() < SettingsModel::Overwrite_KeepBoth || this->overwriteMode() > SettingsModel::Overwrite_Replaces)
430 this->overwriteMode(SettingsModel::Overwrite_KeepBoth);
435 void SettingsModel::syncNow(void)
437 m_configCache->flushValues();
440 ////////////////////////////////////////////////////////////
441 // Private Functions
442 ////////////////////////////////////////////////////////////
444 QString *SettingsModel::m_defaultLanguage = NULL;
446 QString SettingsModel::defaultLanguage(void) const
448 QReadLocker readLock(&s_lock);
450 //Default already initialized?
451 if(m_defaultLanguage)
453 return *m_defaultLanguage;
456 //Acquire write lock now
457 readLock.unlock();
458 QWriteLocker writeLock(&s_lock);
460 //Default still not initialized?
461 if(m_defaultLanguage)
463 return *m_defaultLanguage;
466 //Detect system langauge
467 QLocale systemLanguage= QLocale::system();
468 qDebug("[Locale]");
469 qDebug("Language: %s (%d)", QUTF8(QLocale::languageToString(systemLanguage.language())), systemLanguage.language());
470 qDebug("Country is: %s (%d)", QUTF8(QLocale::countryToString(systemLanguage.country())), systemLanguage.country());
471 qDebug("Script is: %s (%d)\n", QUTF8(QLocale::scriptToString(systemLanguage.script())), systemLanguage.script());
473 //Check if we can use the default translation
474 if(systemLanguage.language() == QLocale::English /*|| systemLanguage.language() == QLocale::C*/)
476 m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
477 return LAMEXP_DEFAULT_LANGID;
480 //Try to find a suitable translation for the user's system language *and* country
481 QStringList languages = lamexp_query_translations();
482 while(!languages.isEmpty())
484 QString currentLangId = languages.takeFirst();
485 if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
487 if(lamexp_translation_country(currentLangId) == systemLanguage.country())
489 m_defaultLanguage = new QString(currentLangId);
490 return currentLangId;
495 //Try to find a suitable translation for the user's system language
496 languages = lamexp_query_translations();
497 while(!languages.isEmpty())
499 QString currentLangId = languages.takeFirst();
500 if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
502 m_defaultLanguage = new QString(currentLangId);
503 return currentLangId;
507 //Fall back to the default translation
508 m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
509 return LAMEXP_DEFAULT_LANGID;
512 QString SettingsModel::defaultDirectory(void) const
514 QString defaultLocation = initDirectory(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
516 if(defaultLocation.isEmpty())
518 defaultLocation = initDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
520 if(defaultLocation.isEmpty())
522 defaultLocation = initDirectory(QDir::currentPath());
526 return defaultLocation;
529 QString SettingsModel::initDirectory(const QString &path) const
531 if(path.isEmpty())
533 return QString();
536 if(!QDir(path).exists())
538 for(int i = 0; i < 32; i++)
540 if(QDir(path).mkpath(".")) break;
541 lamexp_sleep(1);
545 if(!QDir(path).exists())
547 return QString();
550 return QDir(path).canonicalPath();
553 ////////////////////////////////////////////////////////////
554 // Getter and Setter
555 ////////////////////////////////////////////////////////////
557 LAMEXP_MAKE_OPTION_I(aacEncProfile, 0)
558 LAMEXP_MAKE_OPTION_I(aftenAudioCodingMode, 0)
559 LAMEXP_MAKE_OPTION_I(aftenDynamicRangeCompression, 5)
560 LAMEXP_MAKE_OPTION_I(aftenExponentSearchSize, 8)
561 LAMEXP_MAKE_OPTION_B(aftenFastBitAllocation, false)
562 LAMEXP_MAKE_OPTION_B(antivirNotificationsEnabled, true)
563 LAMEXP_MAKE_OPTION_B(autoUpdateCheckBeta, false)
564 LAMEXP_MAKE_OPTION_B(autoUpdateEnabled, (!lamexp_portable_mode()));
565 LAMEXP_MAKE_OPTION_S(autoUpdateLastCheck, "Never")
566 LAMEXP_MAKE_OPTION_B(bitrateManagementEnabled, false)
567 LAMEXP_MAKE_OPTION_I(bitrateManagementMaxRate, 500)
568 LAMEXP_MAKE_OPTION_I(bitrateManagementMinRate, 32)
569 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateAacEnc, 19)
570 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateAften, 17)
571 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateDcaEnc, 13)
572 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateFLAC, 5)
573 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateLAME, 10)
574 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateMacEnc, 2)
575 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateOggEnc, 16)
576 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateOpusEnc, 11)
577 LAMEXP_MAKE_OPTION_I(compressionAbrBitrateWave, 0)
578 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateAacEnc, 19)
579 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateAften, 17)
580 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateDcaEnc, 13)
581 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateFLAC, 5)
582 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateLAME, 10)
583 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateMacEnc, 2)
584 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateOggEnc, 16)
585 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateOpusEnc, 11)
586 LAMEXP_MAKE_OPTION_I(compressionCbrBitrateWave, 0)
587 LAMEXP_MAKE_OPTION_I(compressionEncoder, 0)
588 LAMEXP_MAKE_OPTION_I(compressionRCModeAacEnc, 0)
589 LAMEXP_MAKE_OPTION_I(compressionRCModeAften, 0)
590 LAMEXP_MAKE_OPTION_I(compressionRCModeDcaEnc, 2)
591 LAMEXP_MAKE_OPTION_I(compressionRCModeFLAC, 0)
592 LAMEXP_MAKE_OPTION_I(compressionRCModeLAME, 0)
593 LAMEXP_MAKE_OPTION_I(compressionRCModeMacEnc, 0)
594 LAMEXP_MAKE_OPTION_I(compressionRCModeOggEnc, 0)
595 LAMEXP_MAKE_OPTION_I(compressionRCModeOpusEnc, 0)
596 LAMEXP_MAKE_OPTION_I(compressionRCModeWave, 2)
597 LAMEXP_MAKE_OPTION_I(compressionVbrQualityAacEnc, 10)
598 LAMEXP_MAKE_OPTION_I(compressionVbrQualityAften, 15)
599 LAMEXP_MAKE_OPTION_I(compressionVbrQualityDcaEnc, 13)
600 LAMEXP_MAKE_OPTION_I(compressionVbrQualityFLAC, 5)
601 LAMEXP_MAKE_OPTION_I(compressionVbrQualityLAME, 7)
602 LAMEXP_MAKE_OPTION_I(compressionVbrQualityMacEnc, 2)
603 LAMEXP_MAKE_OPTION_I(compressionVbrQualityOggEnc, 7)
604 LAMEXP_MAKE_OPTION_I(compressionVbrQualityOpusEnc, 11)
605 LAMEXP_MAKE_OPTION_I(compressionVbrQualityWave, 0)
606 LAMEXP_MAKE_OPTION_B(createPlaylist, true)
607 LAMEXP_MAKE_OPTION_S(currentLanguage, defaultLanguage())
608 LAMEXP_MAKE_OPTION_S(currentLanguageFile, QString())
609 LAMEXP_MAKE_OPTION_S(customParametersAacEnc, QString())
610 LAMEXP_MAKE_OPTION_S(customParametersAften, QString())
611 LAMEXP_MAKE_OPTION_S(customParametersDcaEnc, QString())
612 LAMEXP_MAKE_OPTION_S(customParametersFLAC, QString())
613 LAMEXP_MAKE_OPTION_S(customParametersLAME, QString())
614 LAMEXP_MAKE_OPTION_S(customParametersMacEnc, QString())
615 LAMEXP_MAKE_OPTION_S(customParametersOggEnc, QString())
616 LAMEXP_MAKE_OPTION_S(customParametersOpusEnc, QString())
617 LAMEXP_MAKE_OPTION_S(customParametersWave, QString())
618 LAMEXP_MAKE_OPTION_S(customTempPath, QDesktopServices::storageLocation(QDesktopServices::TempLocation))
619 LAMEXP_MAKE_OPTION_B(customTempPathEnabled, false)
620 LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled, true)
621 LAMEXP_MAKE_OPTION_I(dropBoxWidgetPositionX, -1)
622 LAMEXP_MAKE_OPTION_I(dropBoxWidgetPositionY, -1)
623 LAMEXP_MAKE_OPTION_S(favoriteOutputFolders, QString())
624 LAMEXP_MAKE_OPTION_B(forceStereoDownmix, false)
625 LAMEXP_MAKE_OPTION_B(hibernateComputer, false)
626 LAMEXP_MAKE_OPTION_I(interfaceStyle, 0)
627 LAMEXP_MAKE_OPTION_I(lameAlgoQuality, 2)
628 LAMEXP_MAKE_OPTION_I(lameChannelMode, 0)
629 LAMEXP_MAKE_OPTION_I(licenseAccepted, 0)
630 LAMEXP_MAKE_OPTION_U(maximumInstances, 0)
631 LAMEXP_MAKE_OPTION_U(metaInfoPosition, UINT_MAX)
632 LAMEXP_MAKE_OPTION_S(mostRecentInputPath, defaultDirectory())
633 LAMEXP_MAKE_OPTION_B(neroAACEnable2Pass, true)
634 LAMEXP_MAKE_OPTION_B(neroAacNotificationsEnabled, true)
635 LAMEXP_MAKE_OPTION_B(normalizationFilterEnabled, false)
636 LAMEXP_MAKE_OPTION_I(normalizationFilterEQMode, 0)
637 LAMEXP_MAKE_OPTION_I(normalizationFilterMaxVolume, -50)
638 LAMEXP_MAKE_OPTION_I(opusComplexity, 10)
639 LAMEXP_MAKE_OPTION_B(opusDisableResample, false)
640 LAMEXP_MAKE_OPTION_I(opusFramesize, 3)
641 LAMEXP_MAKE_OPTION_I(opusOptimizeFor, 0)
642 LAMEXP_MAKE_OPTION_S(outputDir, defaultDirectory())
643 LAMEXP_MAKE_OPTION_B(outputToSourceDir, false)
644 LAMEXP_MAKE_OPTION_I(overwriteMode, Overwrite_KeepBoth)
645 LAMEXP_MAKE_OPTION_B(prependRelativeSourcePath, false)
646 LAMEXP_MAKE_OPTION_B(renameOutputFilesEnabled, false)
647 LAMEXP_MAKE_OPTION_S(renameOutputFilesPattern, "[<TrackNo>] <Artist> - <Title>")
648 LAMEXP_MAKE_OPTION_I(samplingRate, 0)
649 LAMEXP_MAKE_OPTION_B(shellIntegrationEnabled, !lamexp_portable_mode())
650 LAMEXP_MAKE_OPTION_B(slowStartup, false)
651 LAMEXP_MAKE_OPTION_B(soundsEnabled, true)
652 LAMEXP_MAKE_OPTION_I(toneAdjustBass, 0)
653 LAMEXP_MAKE_OPTION_I(toneAdjustTreble, 0)
654 LAMEXP_MAKE_OPTION_B(writeMetaTags, true)