2010-11-12 19:02:01 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2011-01-01 17:04:25 +01:00
|
|
|
// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-12 19:02:01 +01:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Model_Settings.h"
|
|
|
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QApplication>
|
2010-11-20 02:14:22 +01:00
|
|
|
#include <QString>
|
|
|
|
#include <QFileInfo>
|
2011-01-24 00:04:07 +01:00
|
|
|
#include <QDir>
|
2010-12-30 16:12:21 +01:00
|
|
|
#include <QStringList>
|
2011-01-02 20:47:26 +01:00
|
|
|
#include <QLocale>
|
2010-11-12 19:02:01 +01:00
|
|
|
|
2010-11-21 21:51:22 +01:00
|
|
|
//Constants
|
2010-11-15 04:42:06 +01:00
|
|
|
static const char *g_settingsId_versionNumber = "VersionNumber";
|
|
|
|
static const char *g_settingsId_licenseAccepted = "LicenseAccepted";
|
|
|
|
static const char *g_settingsId_interfaceStyle = "InterfaceStyle";
|
|
|
|
static const char *g_settingsId_compressionEncoder = "Compression/Encoder";
|
|
|
|
static const char *g_settingsId_compressionRCMode = "Compression/RCMode";
|
|
|
|
static const char *g_settingsId_compressionBitrate = "Compression/Bitrate";
|
2010-11-21 21:51:22 +01:00
|
|
|
static const char *g_settingsId_outputDir = "OutputDirectory/SelectedPath";
|
|
|
|
static const char *g_settingsId_outputToSourceDir = "OutputDirectory/OutputToSourceFolder";
|
2010-12-14 01:25:13 +01:00
|
|
|
static const char *g_settingsId_prependRelativeSourcePath = "OutputDirectory/PrependRelativeSourcePath";
|
2010-11-29 20:36:27 +01:00
|
|
|
static const char *g_settingsId_writeMetaTags = "Flags/WriteMetaTags";
|
|
|
|
static const char *g_settingsId_createPlaylist = "Flags/AutoCreatePlaylist";
|
|
|
|
static const char *g_settingsId_autoUpdateLastCheck = "AutoUpdate/LastCheck";
|
|
|
|
static const char *g_settingsId_autoUpdateEnabled = "AutoUpdate/Enabled";
|
|
|
|
static const char *g_settingsId_soundsEnabled = "Flags/EnableSounds";
|
2010-12-19 21:23:43 +01:00
|
|
|
static const char *g_settingsId_neroAacNotificationsEnabled = "Flags/EnableNeroAacNotifications";
|
|
|
|
static const char *g_settingsId_wmaDecoderNotificationsEnabled = "Flags/EnableWmaDecoderNotifications";
|
2010-12-22 01:01:01 +01:00
|
|
|
static const char *g_settingsId_dropBoxWidgetEnabled = "Flags/EnableDropBoxWidget";
|
2010-12-28 21:26:16 +01:00
|
|
|
static const char *g_settingsId_currentLanguage = "Localization/Language";
|
2011-01-21 19:14:11 +01:00
|
|
|
static const char *g_settingsId_lameAlgoQuality = "AdvancedOptions/LAME/AlgorithmQuality";
|
2011-01-22 22:19:20 +01:00
|
|
|
static const char *g_settingsId_lameChannelMode = "AdvancedOptions/LAME/ChannelMode";
|
2011-01-21 21:41:50 +01:00
|
|
|
static const char *g_settingsId_bitrateManagementEnabled = "AdvancedOptions/BitrateManagement/Enabled";
|
|
|
|
static const char *g_settingsId_bitrateManagementMinRate = "AdvancedOptions/BitrateManagement/MinRate";
|
|
|
|
static const char *g_settingsId_bitrateManagementMaxRate = "AdvancedOptions/BitrateManagement/MaxRate";
|
2011-01-22 22:19:20 +01:00
|
|
|
static const char *g_settingsId_samplingRate = "AdvancedOptions/Common/Resampling";
|
|
|
|
static const char *g_settingsId_neroAACEnable2Pass = "AdvancedOptions/NeroAAC/Enable2Pass";
|
|
|
|
static const char *g_settingsId_neroAACProfile = "AdvancedOptions/NeroAAC/ForceProfile";
|
2011-01-24 01:13:08 +01:00
|
|
|
static const char *g_settingsId_normalizationFilterEnabled = "AdvancedOptions/VolumeNormalization/Enabled";
|
|
|
|
static const char *g_settingsId_normalizationFilterMaxVolume = "AdvancedOptions/VolumeNormalization/MaxVolume";
|
2011-01-26 20:16:46 +01:00
|
|
|
static const char *g_settingsId_toneAdjustBass = "AdvancedOptions/ToneAdjustment/Bass";
|
|
|
|
static const char *g_settingsId_toneAdjustTreble = "AdvancedOptions/ToneAdjustment/Treble";
|
2011-01-21 19:14:11 +01:00
|
|
|
|
2010-11-21 21:51:22 +01:00
|
|
|
//Macros
|
|
|
|
#define MAKE_OPTION1(OPT,DEF) \
|
|
|
|
int SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toInt(); } \
|
2011-01-23 02:19:18 +01:00
|
|
|
void SettingsModel::OPT(int value) { m_settings->setValue(g_settingsId_##OPT, value); } \
|
|
|
|
int SettingsModel::OPT##Default(void) { return DEF; }
|
2010-11-12 19:02:01 +01:00
|
|
|
|
2010-11-21 21:51:22 +01:00
|
|
|
#define MAKE_OPTION2(OPT,DEF) \
|
|
|
|
QString SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toString().trimmed(); } \
|
2011-01-23 02:19:18 +01:00
|
|
|
void SettingsModel::OPT(const QString &value) { m_settings->setValue(g_settingsId_##OPT, value); } \
|
|
|
|
QString SettingsModel::OPT##Default(void) { return DEF; }
|
2010-11-21 21:51:22 +01:00
|
|
|
|
|
|
|
#define MAKE_OPTION3(OPT,DEF) \
|
|
|
|
bool SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toBool(); } \
|
2011-01-23 02:19:18 +01:00
|
|
|
void SettingsModel::OPT(bool value) { m_settings->setValue(g_settingsId_##OPT, value); } \
|
|
|
|
bool SettingsModel::OPT##Default(void) { return DEF; }
|
2010-11-21 21:51:22 +01:00
|
|
|
|
|
|
|
//LUT
|
2010-11-15 21:07:58 +01:00
|
|
|
const int SettingsModel::mp3Bitrates[15] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1};
|
2011-01-23 02:19:18 +01:00
|
|
|
const int SettingsModel::samplingRates[8] = {0, 16000, 22050, 24000, 32000, 44100, 48000, -1};
|
2010-11-15 21:07:58 +01:00
|
|
|
|
2010-11-12 19:02:01 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SettingsModel::SettingsModel(void)
|
2011-01-02 01:09:05 +01:00
|
|
|
:
|
|
|
|
m_defaultLanguage(NULL)
|
2010-11-12 19:02:01 +01:00
|
|
|
{
|
2011-01-24 00:04:07 +01:00
|
|
|
QString configPath;
|
|
|
|
|
|
|
|
if(!lamexp_portable_mode())
|
|
|
|
{
|
|
|
|
QString dataPath = QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)).canonicalPath();
|
|
|
|
if(dataPath.isEmpty()) dataPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
|
|
QDir(dataPath).mkpath(".");
|
|
|
|
configPath = QString("%1/config.ini").arg(dataPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n");
|
|
|
|
QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath();
|
|
|
|
if(appPath.isEmpty()) appPath = QApplication::applicationFilePath();
|
|
|
|
configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_settings = new QSettings(configPath, QSettings::IniFormat);
|
2010-11-12 19:02:01 +01:00
|
|
|
m_settings->beginGroup(QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()));
|
2010-11-15 04:42:06 +01:00
|
|
|
m_settings->setValue(g_settingsId_versionNumber, QApplication::applicationVersion());
|
2010-11-12 19:02:01 +01:00
|
|
|
m_settings->sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Destructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SettingsModel::~SettingsModel(void)
|
|
|
|
{
|
|
|
|
LAMEXP_DELETE(m_settings);
|
2011-01-02 01:09:05 +01:00
|
|
|
LAMEXP_DELETE(m_defaultLanguage);
|
2010-11-12 19:02:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Public Functions
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2010-11-15 04:42:06 +01:00
|
|
|
void SettingsModel::validate(void)
|
|
|
|
{
|
|
|
|
if(this->compressionEncoder() < SettingsModel::MP3Encoder || this->compressionEncoder() > SettingsModel::PCMEncoder)
|
|
|
|
{
|
|
|
|
this->compressionEncoder(SettingsModel::MP3Encoder);
|
|
|
|
}
|
2010-12-30 16:12:21 +01:00
|
|
|
|
2010-11-15 04:42:06 +01:00
|
|
|
if(this->compressionRCMode() < SettingsModel::VBRMode || this->compressionRCMode() > SettingsModel::CBRMode)
|
|
|
|
{
|
|
|
|
this->compressionEncoder(SettingsModel::VBRMode);
|
|
|
|
}
|
2010-12-30 16:12:21 +01:00
|
|
|
|
2010-11-15 04:42:06 +01:00
|
|
|
if(!(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")))
|
|
|
|
{
|
2010-12-03 23:01:17 +01:00
|
|
|
if(this->compressionEncoder() == SettingsModel::AACEncoder)
|
|
|
|
{
|
|
|
|
qWarning("Nero encoder selected, but not available any more. Reverting to MP3!");
|
|
|
|
this->compressionEncoder(SettingsModel::MP3Encoder);
|
|
|
|
}
|
2010-11-15 04:42:06 +01:00
|
|
|
}
|
2010-12-30 16:12:21 +01:00
|
|
|
|
2010-11-20 02:14:22 +01:00
|
|
|
if(this->outputDir().isEmpty() || !QFileInfo(this->outputDir()).isDir())
|
|
|
|
{
|
|
|
|
this->outputDir(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
|
|
|
|
}
|
2010-12-30 16:12:21 +01:00
|
|
|
|
|
|
|
if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive))
|
|
|
|
{
|
2011-01-02 20:47:26 +01:00
|
|
|
qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
|
2011-01-02 01:09:05 +01:00
|
|
|
this->currentLanguage(defaultLanguage());
|
2010-12-30 16:12:21 +01:00
|
|
|
}
|
2010-11-15 04:42:06 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 01:09:05 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Private Functions
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QString SettingsModel::defaultLanguage(void)
|
|
|
|
{
|
|
|
|
if(m_defaultLanguage)
|
|
|
|
{
|
|
|
|
return *m_defaultLanguage;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if we can use the default translation
|
2011-01-02 20:47:26 +01:00
|
|
|
QLocale systemLanguage= QLocale::system();
|
|
|
|
if(systemLanguage.language() == QLocale::English || systemLanguage.language() == QLocale::C)
|
2011-01-02 01:09:05 +01:00
|
|
|
{
|
|
|
|
m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
|
|
|
|
return LAMEXP_DEFAULT_LANGID;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Try to find a suitable translation for the user's system language
|
|
|
|
QStringList languages = lamexp_query_translations();
|
|
|
|
while(!languages.isEmpty())
|
|
|
|
{
|
|
|
|
QString currentLangId = languages.takeFirst();
|
2011-01-02 20:47:26 +01:00
|
|
|
if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
|
2011-01-02 01:09:05 +01:00
|
|
|
{
|
|
|
|
m_defaultLanguage = new QString(currentLangId);
|
|
|
|
return currentLangId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Fall back to the default translation
|
|
|
|
m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
|
|
|
|
return LAMEXP_DEFAULT_LANGID;
|
|
|
|
}
|
|
|
|
|
2010-11-15 04:42:06 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Getter and Setter
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2010-11-21 21:51:22 +01:00
|
|
|
MAKE_OPTION1(licenseAccepted, 0)
|
|
|
|
MAKE_OPTION1(interfaceStyle, 0)
|
|
|
|
MAKE_OPTION1(compressionEncoder, 0)
|
|
|
|
MAKE_OPTION1(compressionRCMode, 0)
|
|
|
|
MAKE_OPTION1(compressionBitrate, 7)
|
|
|
|
MAKE_OPTION2(outputDir, QString())
|
|
|
|
MAKE_OPTION3(outputToSourceDir, false)
|
2010-12-14 01:25:13 +01:00
|
|
|
MAKE_OPTION3(prependRelativeSourcePath, false)
|
2010-11-21 21:51:22 +01:00
|
|
|
MAKE_OPTION3(writeMetaTags, true)
|
|
|
|
MAKE_OPTION3(createPlaylist, true)
|
2010-11-29 20:36:27 +01:00
|
|
|
MAKE_OPTION2(autoUpdateLastCheck, "Never")
|
|
|
|
MAKE_OPTION3(autoUpdateEnabled, true)
|
|
|
|
MAKE_OPTION3(soundsEnabled, true)
|
2010-12-19 21:23:43 +01:00
|
|
|
MAKE_OPTION3(neroAacNotificationsEnabled, true)
|
|
|
|
MAKE_OPTION3(wmaDecoderNotificationsEnabled, true)
|
2010-12-22 01:01:01 +01:00
|
|
|
MAKE_OPTION3(dropBoxWidgetEnabled, true)
|
2011-01-02 01:09:05 +01:00
|
|
|
MAKE_OPTION2(currentLanguage, defaultLanguage());
|
2011-01-21 19:14:11 +01:00
|
|
|
MAKE_OPTION1(lameAlgoQuality, 3)
|
2011-01-22 22:19:20 +01:00
|
|
|
MAKE_OPTION1(lameChannelMode, 0);
|
2011-01-21 21:41:50 +01:00
|
|
|
MAKE_OPTION3(bitrateManagementEnabled, false)
|
|
|
|
MAKE_OPTION1(bitrateManagementMinRate, 32)
|
|
|
|
MAKE_OPTION1(bitrateManagementMaxRate, 500)
|
2011-01-22 22:19:20 +01:00
|
|
|
MAKE_OPTION1(samplingRate, 0)
|
|
|
|
MAKE_OPTION3(neroAACEnable2Pass, true)
|
|
|
|
MAKE_OPTION1(neroAACProfile, 0)
|
2011-01-24 01:13:08 +01:00
|
|
|
MAKE_OPTION3(normalizationFilterEnabled, false)
|
|
|
|
MAKE_OPTION1(normalizationFilterMaxVolume, -50)
|
2011-01-26 20:16:46 +01:00
|
|
|
MAKE_OPTION1(toneAdjustBass, 0)
|
|
|
|
MAKE_OPTION1(toneAdjustTreble, 0)
|