From 19c258847109d04d65eaddc07532c250ab7df5dc Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Wed, 29 Apr 2009 21:36:05 +0000 Subject: Move Settings class to base. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20827 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/rbsettings.cpp | 285 ++++++++++++++++++++++++++++++++++++ rbutil/rbutilqt/base/rbsettings.h | 142 ++++++++++++++++++ rbutil/rbutilqt/rbsettings.cpp | 285 ------------------------------------ rbutil/rbutilqt/rbsettings.h | 142 ------------------ rbutil/rbutilqt/rbutilqt.pro | 4 +- 5 files changed, 429 insertions(+), 429 deletions(-) create mode 100644 rbutil/rbutilqt/base/rbsettings.cpp create mode 100644 rbutil/rbutilqt/base/rbsettings.h delete mode 100644 rbutil/rbutilqt/rbsettings.cpp delete mode 100644 rbutil/rbutilqt/rbsettings.h (limited to 'rbutil') diff --git a/rbutil/rbutilqt/base/rbsettings.cpp b/rbutil/rbutilqt/base/rbsettings.cpp new file mode 100644 index 0000000000..12654cd288 --- /dev/null +++ b/rbutil/rbutilqt/base/rbsettings.cpp @@ -0,0 +1,285 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id$ + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "rbsettings.h" + +#include + +#if defined(Q_OS_LINUX) +#include +#endif + +// device settings +const static struct { + RbSettings::SystemSettings setting; + const char* name; + const char* def; +} SystemSettingsList[] = { + { RbSettings::ManualUrl, "manual_url", "" }, + { RbSettings::BleedingUrl, "bleeding_url", "" }, + { RbSettings::BootloaderUrl, "bootloader_url", "" }, + { RbSettings::BootloaderInfoUrl, "bootloader_info_url", "" }, + { RbSettings::FontUrl, "font_url", "" }, + { RbSettings::VoiceUrl, "voice_url", "" }, + { RbSettings::DoomUrl, "doom_url", "" }, + { RbSettings::ReleaseUrl, "release_url", "" }, + { RbSettings::DailyUrl, "daily_url", "" }, + { RbSettings::ServerConfUrl, "server_conf_url", "" }, + { RbSettings::GenlangUrl, "genlang_url", "" }, + { RbSettings::ThemesUrl, "themes_url", "" }, + { RbSettings::BleedingInfo, "bleeding_info", "" }, + { RbSettings::CurPlatformName, ":platform:/name", "" }, + { RbSettings::CurManual, ":platform:/manual", "rockbox-:platform:" }, + { RbSettings::CurBootloaderMethod, ":platform:/bootloadermethod", "none" }, + { RbSettings::CurBootloaderName, ":platform:/bootloadername", "" }, + { RbSettings::CurBootloaderFile, ":platform:/bootloaderfile", "" }, + { RbSettings::CurEncoder, ":platform:/encoder", "" }, + { RbSettings::CurResolution, ":platform:/resolution", "" }, + { RbSettings::CurBrand, ":platform:/brand", "" }, + { RbSettings::CurName, ":platform:/name", "" }, + { RbSettings::CurBuildserverModel, ":platform:/buildserver_modelname", "" }, + { RbSettings::CurConfigureModel, ":platform:/configure_modelname", "" }, + { RbSettings::CurTargetId, ":platform:/targetid", "" }, +}; + +// user settings +const static struct { + RbSettings::UserSettings setting; + const char* name; + const char* def; +} UserSettingsList[] = { + { RbSettings::RbutilVersion, "rbutil_version", "" }, + { RbSettings::CurrentPlatform, "platform", "" }, + { RbSettings::Mountpoint, "mountpoint", "" }, + { RbSettings::CachePath, "cachepath", "" }, + { RbSettings::Build, "build", "" }, + { RbSettings::ProxyType, "proxytype", "" }, + { RbSettings::Proxy, "proxy", "" }, + { RbSettings::OfPath, "ofpath", "" }, + { RbSettings::Platform, "platform", "" }, + { RbSettings::Language, "lang", "" }, + { RbSettings::Tts, "tts", "" }, + { RbSettings::LastTalkedFolder, "last_talked_folder", "" }, + { RbSettings::VoiceLanguage, "voicelanguage", "" }, + { RbSettings::TtsLanguage, ":tts:/language", "" }, + { RbSettings::TtsOptions, ":tts:/options", "" }, + { RbSettings::TtsPath, ":tts:/path", "" }, + { RbSettings::TtsVoice, ":tts:/voice", "" }, + { RbSettings::EncoderPath, ":encoder:/encoderpath", "" }, + { RbSettings::EncoderOptions, ":encoder:/encoderoptions", "" }, + { RbSettings::CacheOffline, "offline", "false" }, + { RbSettings::CacheDisabled, "cachedisable", "false" }, + { RbSettings::TtsUseSapi4, "sapi/useSapi4", "false" }, + { RbSettings::EncoderNarrowBand, ":encoder:/narrowband", "false" }, + { RbSettings::WavtrimThreshold, "wavtrimthreshold", "500"}, + { RbSettings::TtsSpeed, ":tts:/speed", "0" }, + { RbSettings::EncoderComplexity, ":encoder:/complexity", "10" }, + { RbSettings::EncoderQuality, ":encoder:/quality", "8.0" }, + { RbSettings::EncoderVolume, ":encoder:/volume", "1.0" }, +}; + +void RbSettings::open() +{ + // only use built-in rbutil.ini + systemSettings = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0); + // portable installation: + // check for a configuration file in the program folder. + QFileInfo config; + config.setFile(QCoreApplication::instance()->applicationDirPath() + + "/RockboxUtility.ini"); + if(config.isFile()) + { + userSettings = new QSettings(QCoreApplication::instance()->applicationDirPath() + + "/RockboxUtility.ini", QSettings::IniFormat, this); + qDebug() << "config: portable"; + } + else + { + userSettings = new QSettings(QSettings::IniFormat, + QSettings::UserScope, "rockbox.org", "RockboxUtility",this); + qDebug() << "config: system"; + } +} + +void RbSettings::sync() +{ + userSettings->sync(); +#if defined(Q_OS_LINUX) + // when using sudo it runs rbutil with uid 0 but unfortunately without a + // proper login shell, thus the configuration file gets placed in the + // calling users $HOME. This in turn will cause issues if trying to + // run rbutil later as user. Try to detect this case via the environment + // variable SUDO_UID and SUDO_GID and if set chown the user config file. + if(getuid() == 0) + { + char* realuser = getenv("SUDO_UID"); + char* realgroup = getenv("SUDO_GID"); + if(realuser != NULL && realgroup != NULL) + { + int realuid = atoi(realuser); + int realgid = atoi(realgroup); + // chown is attribute warn_unused_result, but in case this fails + // we can't do anything useful about it. Notifying the user + // is somewhat pointless. Add hack to suppress compiler warning. + if(chown(qPrintable(userSettings->fileName()), realuid, realgid)); + } + } +#endif +} + + +QVariant RbSettings::value(enum SystemSettings setting) +{ + // locate setting item + int i = 0; + while(SystemSettingsList[i].setting != setting) + i++; + + QString s = constructSettingPath(SystemSettingsList[i].name); + QString d = SystemSettingsList[i].def; + d.replace(":platform:", userSettings->value("platform").toString()); + qDebug() << "[Settings] GET S:" << s << systemSettings->value(s, d).toString(); + return systemSettings->value(s, d); +} + + +QString RbSettings::userSettingFilename() +{ + return userSettings->fileName(); +} + + +QVariant RbSettings::subValue(QString& sub, enum UserSettings setting) +{ + // locate setting item + int i = 0; + while(UserSettingsList[i].setting != setting) + i++; + + QString s = constructSettingPath(UserSettingsList[i].name, sub); + qDebug() << "[Settings] GET U:" << s << userSettings->value(s).toString(); + return userSettings->value(s, UserSettingsList[i].def); +} + + +void RbSettings::setSubValue(QString& sub, enum UserSettings setting, QVariant value) +{ + // locate setting item + int i = 0; + while(UserSettingsList[i].setting != setting) + i++; + + QString s = constructSettingPath(UserSettingsList[i].name, sub); + qDebug() << "[Settings] SET U:" << s << userSettings->value(s).toString(); + userSettings->setValue(s, value); +} + + + +QStringList RbSettings::platforms() +{ + QStringList result; + systemSettings->beginGroup("platforms"); + QStringList a = systemSettings->childKeys(); + for(int i = 0; i < a.size(); i++) + { + result.append(systemSettings->value(a.at(i), "null").toString()); + } + systemSettings->endGroup(); + return result; +} + +QStringList RbSettings::languages() +{ + QStringList result; + systemSettings->beginGroup("languages"); + QStringList a = systemSettings->childKeys(); + for(int i = 0; i < a.size(); i++) + { + result.append(systemSettings->value(a.at(i), "null").toString()); + } + systemSettings->endGroup(); + return result; +} + +QString RbSettings::name(QString platform) +{ + return systemSettings->value(platform + "/name").toString(); +} + +QString RbSettings::brand(QString platform) +{ + return systemSettings->value(platform + "/brand").toString(); +} + +QMap RbSettings::usbIdMap(enum MapType type) +{ + QMap map; + // get a list of ID -> target name + QStringList platforms; + systemSettings->beginGroup("platforms"); + platforms = systemSettings->childKeys(); + systemSettings->endGroup(); + + QString t; + switch(type) { + case MapDevice: + t = "usbid"; + break; + case MapError: + t = "usberror"; + break; + case MapIncompatible: + t = "usbincompat"; + break; + } + + for(int i = 0; i < platforms.size(); i++) + { + systemSettings->beginGroup("platforms"); + QString target = systemSettings->value(platforms.at(i)).toString(); + systemSettings->endGroup(); + systemSettings->beginGroup(target); + QStringList ids = systemSettings->value(t).toStringList(); + int j = ids.size(); + while(j--) + map.insert(ids.at(j).toInt(0, 16), target); + + systemSettings->endGroup(); + } + return map; +} + + +QString RbSettings::constructSettingPath(QString path, QString substitute) +{ + QString platform = userSettings->value("platform").toString(); + if(!substitute.isEmpty()) { + path.replace(":tts:", substitute); + path.replace(":encoder:", substitute); + } + else { + path.replace(":tts:", userSettings->value("tts").toString()); + path.replace(":encoder:", systemSettings->value(platform + "/encoder").toString()); + } + path.replace(":platform:", platform); + + return path; +} + diff --git a/rbutil/rbutilqt/base/rbsettings.h b/rbutil/rbutilqt/base/rbsettings.h new file mode 100644 index 0000000000..341577abc8 --- /dev/null +++ b/rbutil/rbutilqt/base/rbsettings.h @@ -0,0 +1,142 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id$ + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef RBSETTINGS_H +#define RBSETTINGS_H + +#include + +class QSettings; + +class RbSettings : public QObject +{ + Q_OBJECT + + public: + RbSettings() {} + + //! open the settings files + void open(); + //! call this to flush the user Settings + void sync(); + + // returns the filename of the usersettings file + QString userSettingFilename(); + + enum MapType { + MapDevice, + MapError, + MapIncompatible, + }; + enum UserSettings { + RbutilVersion, + CurrentPlatform, + Mountpoint, + CachePath, + Build, + ProxyType, + Proxy, + OfPath, + Platform, + Language, + Tts, + LastTalkedFolder, + VoiceLanguage, + TtsLanguage, + TtsOptions, + TtsPath, + TtsVoice, + EncoderPath, + EncoderOptions, + WavtrimThreshold, + EncoderComplexity, + TtsSpeed, + CacheOffline, + CacheDisabled, + TtsUseSapi4, + EncoderNarrowBand, + EncoderQuality, + EncoderVolume, + }; + enum SystemSettings { + ManualUrl, + BleedingUrl, + BootloaderUrl, + BootloaderInfoUrl, + FontUrl, + VoiceUrl, + DoomUrl, + ReleaseUrl, + DailyUrl, + ServerConfUrl, + GenlangUrl, + ThemesUrl, + BleedingInfo, + CurPlatformName, + CurManual, + CurBootloaderMethod, + CurBootloaderName, + CurBootloaderFile, + CurEncoder, + CurResolution, + CurBrand, + CurName, + CurBuildserverModel, + CurConfigureModel, + CurTargetId, + }; + + QVariant value(enum SystemSettings setting); + // generic and "current selection" values -- getters + QVariant value(enum UserSettings setting) + { QString empty; return subValue(empty, setting); } + void setValue(enum UserSettings setting , QVariant value) + { QString empty; return setSubValue(empty, setting, value); } + + QVariant subValue(QString& sub, enum UserSettings setting); + QVariant subValue(const char* sub, enum UserSettings setting) + { QString s = sub; return subValue(s, setting); } + void setSubValue(QString& sub, enum UserSettings setting, QVariant value); + void setSubValue(const char* sub, enum UserSettings setting, QVariant value) + { QString s = sub; return setSubValue(s, setting, value); } + + QStringList platforms(void); + QStringList languages(void); + + QString name(QString plattform); + QString brand(QString plattform); + + QMap usbIdMap(enum MapType); + + private: + //! private copy constructors to prvent copying + RbSettings& operator= (const RbSettings& other) + { (void)other; return *this; } + RbSettings(const RbSettings& other) :QObject() + { (void)other; } + QString constructSettingPath(QString path, QString substitute = QString()); + + //! pointers to our setting objects + QSettings *systemSettings; + QSettings *userSettings; +}; + +#endif diff --git a/rbutil/rbutilqt/rbsettings.cpp b/rbutil/rbutilqt/rbsettings.cpp deleted file mode 100644 index 12654cd288..0000000000 --- a/rbutil/rbutilqt/rbsettings.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "rbsettings.h" - -#include - -#if defined(Q_OS_LINUX) -#include -#endif - -// device settings -const static struct { - RbSettings::SystemSettings setting; - const char* name; - const char* def; -} SystemSettingsList[] = { - { RbSettings::ManualUrl, "manual_url", "" }, - { RbSettings::BleedingUrl, "bleeding_url", "" }, - { RbSettings::BootloaderUrl, "bootloader_url", "" }, - { RbSettings::BootloaderInfoUrl, "bootloader_info_url", "" }, - { RbSettings::FontUrl, "font_url", "" }, - { RbSettings::VoiceUrl, "voice_url", "" }, - { RbSettings::DoomUrl, "doom_url", "" }, - { RbSettings::ReleaseUrl, "release_url", "" }, - { RbSettings::DailyUrl, "daily_url", "" }, - { RbSettings::ServerConfUrl, "server_conf_url", "" }, - { RbSettings::GenlangUrl, "genlang_url", "" }, - { RbSettings::ThemesUrl, "themes_url", "" }, - { RbSettings::BleedingInfo, "bleeding_info", "" }, - { RbSettings::CurPlatformName, ":platform:/name", "" }, - { RbSettings::CurManual, ":platform:/manual", "rockbox-:platform:" }, - { RbSettings::CurBootloaderMethod, ":platform:/bootloadermethod", "none" }, - { RbSettings::CurBootloaderName, ":platform:/bootloadername", "" }, - { RbSettings::CurBootloaderFile, ":platform:/bootloaderfile", "" }, - { RbSettings::CurEncoder, ":platform:/encoder", "" }, - { RbSettings::CurResolution, ":platform:/resolution", "" }, - { RbSettings::CurBrand, ":platform:/brand", "" }, - { RbSettings::CurName, ":platform:/name", "" }, - { RbSettings::CurBuildserverModel, ":platform:/buildserver_modelname", "" }, - { RbSettings::CurConfigureModel, ":platform:/configure_modelname", "" }, - { RbSettings::CurTargetId, ":platform:/targetid", "" }, -}; - -// user settings -const static struct { - RbSettings::UserSettings setting; - const char* name; - const char* def; -} UserSettingsList[] = { - { RbSettings::RbutilVersion, "rbutil_version", "" }, - { RbSettings::CurrentPlatform, "platform", "" }, - { RbSettings::Mountpoint, "mountpoint", "" }, - { RbSettings::CachePath, "cachepath", "" }, - { RbSettings::Build, "build", "" }, - { RbSettings::ProxyType, "proxytype", "" }, - { RbSettings::Proxy, "proxy", "" }, - { RbSettings::OfPath, "ofpath", "" }, - { RbSettings::Platform, "platform", "" }, - { RbSettings::Language, "lang", "" }, - { RbSettings::Tts, "tts", "" }, - { RbSettings::LastTalkedFolder, "last_talked_folder", "" }, - { RbSettings::VoiceLanguage, "voicelanguage", "" }, - { RbSettings::TtsLanguage, ":tts:/language", "" }, - { RbSettings::TtsOptions, ":tts:/options", "" }, - { RbSettings::TtsPath, ":tts:/path", "" }, - { RbSettings::TtsVoice, ":tts:/voice", "" }, - { RbSettings::EncoderPath, ":encoder:/encoderpath", "" }, - { RbSettings::EncoderOptions, ":encoder:/encoderoptions", "" }, - { RbSettings::CacheOffline, "offline", "false" }, - { RbSettings::CacheDisabled, "cachedisable", "false" }, - { RbSettings::TtsUseSapi4, "sapi/useSapi4", "false" }, - { RbSettings::EncoderNarrowBand, ":encoder:/narrowband", "false" }, - { RbSettings::WavtrimThreshold, "wavtrimthreshold", "500"}, - { RbSettings::TtsSpeed, ":tts:/speed", "0" }, - { RbSettings::EncoderComplexity, ":encoder:/complexity", "10" }, - { RbSettings::EncoderQuality, ":encoder:/quality", "8.0" }, - { RbSettings::EncoderVolume, ":encoder:/volume", "1.0" }, -}; - -void RbSettings::open() -{ - // only use built-in rbutil.ini - systemSettings = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0); - // portable installation: - // check for a configuration file in the program folder. - QFileInfo config; - config.setFile(QCoreApplication::instance()->applicationDirPath() - + "/RockboxUtility.ini"); - if(config.isFile()) - { - userSettings = new QSettings(QCoreApplication::instance()->applicationDirPath() - + "/RockboxUtility.ini", QSettings::IniFormat, this); - qDebug() << "config: portable"; - } - else - { - userSettings = new QSettings(QSettings::IniFormat, - QSettings::UserScope, "rockbox.org", "RockboxUtility",this); - qDebug() << "config: system"; - } -} - -void RbSettings::sync() -{ - userSettings->sync(); -#if defined(Q_OS_LINUX) - // when using sudo it runs rbutil with uid 0 but unfortunately without a - // proper login shell, thus the configuration file gets placed in the - // calling users $HOME. This in turn will cause issues if trying to - // run rbutil later as user. Try to detect this case via the environment - // variable SUDO_UID and SUDO_GID and if set chown the user config file. - if(getuid() == 0) - { - char* realuser = getenv("SUDO_UID"); - char* realgroup = getenv("SUDO_GID"); - if(realuser != NULL && realgroup != NULL) - { - int realuid = atoi(realuser); - int realgid = atoi(realgroup); - // chown is attribute warn_unused_result, but in case this fails - // we can't do anything useful about it. Notifying the user - // is somewhat pointless. Add hack to suppress compiler warning. - if(chown(qPrintable(userSettings->fileName()), realuid, realgid)); - } - } -#endif -} - - -QVariant RbSettings::value(enum SystemSettings setting) -{ - // locate setting item - int i = 0; - while(SystemSettingsList[i].setting != setting) - i++; - - QString s = constructSettingPath(SystemSettingsList[i].name); - QString d = SystemSettingsList[i].def; - d.replace(":platform:", userSettings->value("platform").toString()); - qDebug() << "[Settings] GET S:" << s << systemSettings->value(s, d).toString(); - return systemSettings->value(s, d); -} - - -QString RbSettings::userSettingFilename() -{ - return userSettings->fileName(); -} - - -QVariant RbSettings::subValue(QString& sub, enum UserSettings setting) -{ - // locate setting item - int i = 0; - while(UserSettingsList[i].setting != setting) - i++; - - QString s = constructSettingPath(UserSettingsList[i].name, sub); - qDebug() << "[Settings] GET U:" << s << userSettings->value(s).toString(); - return userSettings->value(s, UserSettingsList[i].def); -} - - -void RbSettings::setSubValue(QString& sub, enum UserSettings setting, QVariant value) -{ - // locate setting item - int i = 0; - while(UserSettingsList[i].setting != setting) - i++; - - QString s = constructSettingPath(UserSettingsList[i].name, sub); - qDebug() << "[Settings] SET U:" << s << userSettings->value(s).toString(); - userSettings->setValue(s, value); -} - - - -QStringList RbSettings::platforms() -{ - QStringList result; - systemSettings->beginGroup("platforms"); - QStringList a = systemSettings->childKeys(); - for(int i = 0; i < a.size(); i++) - { - result.append(systemSettings->value(a.at(i), "null").toString()); - } - systemSettings->endGroup(); - return result; -} - -QStringList RbSettings::languages() -{ - QStringList result; - systemSettings->beginGroup("languages"); - QStringList a = systemSettings->childKeys(); - for(int i = 0; i < a.size(); i++) - { - result.append(systemSettings->value(a.at(i), "null").toString()); - } - systemSettings->endGroup(); - return result; -} - -QString RbSettings::name(QString platform) -{ - return systemSettings->value(platform + "/name").toString(); -} - -QString RbSettings::brand(QString platform) -{ - return systemSettings->value(platform + "/brand").toString(); -} - -QMap RbSettings::usbIdMap(enum MapType type) -{ - QMap map; - // get a list of ID -> target name - QStringList platforms; - systemSettings->beginGroup("platforms"); - platforms = systemSettings->childKeys(); - systemSettings->endGroup(); - - QString t; - switch(type) { - case MapDevice: - t = "usbid"; - break; - case MapError: - t = "usberror"; - break; - case MapIncompatible: - t = "usbincompat"; - break; - } - - for(int i = 0; i < platforms.size(); i++) - { - systemSettings->beginGroup("platforms"); - QString target = systemSettings->value(platforms.at(i)).toString(); - systemSettings->endGroup(); - systemSettings->beginGroup(target); - QStringList ids = systemSettings->value(t).toStringList(); - int j = ids.size(); - while(j--) - map.insert(ids.at(j).toInt(0, 16), target); - - systemSettings->endGroup(); - } - return map; -} - - -QString RbSettings::constructSettingPath(QString path, QString substitute) -{ - QString platform = userSettings->value("platform").toString(); - if(!substitute.isEmpty()) { - path.replace(":tts:", substitute); - path.replace(":encoder:", substitute); - } - else { - path.replace(":tts:", userSettings->value("tts").toString()); - path.replace(":encoder:", systemSettings->value(platform + "/encoder").toString()); - } - path.replace(":platform:", platform); - - return path; -} - diff --git a/rbutil/rbutilqt/rbsettings.h b/rbutil/rbutilqt/rbsettings.h deleted file mode 100644 index 341577abc8..0000000000 --- a/rbutil/rbutilqt/rbsettings.h +++ /dev/null @@ -1,142 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef RBSETTINGS_H -#define RBSETTINGS_H - -#include - -class QSettings; - -class RbSettings : public QObject -{ - Q_OBJECT - - public: - RbSettings() {} - - //! open the settings files - void open(); - //! call this to flush the user Settings - void sync(); - - // returns the filename of the usersettings file - QString userSettingFilename(); - - enum MapType { - MapDevice, - MapError, - MapIncompatible, - }; - enum UserSettings { - RbutilVersion, - CurrentPlatform, - Mountpoint, - CachePath, - Build, - ProxyType, - Proxy, - OfPath, - Platform, - Language, - Tts, - LastTalkedFolder, - VoiceLanguage, - TtsLanguage, - TtsOptions, - TtsPath, - TtsVoice, - EncoderPath, - EncoderOptions, - WavtrimThreshold, - EncoderComplexity, - TtsSpeed, - CacheOffline, - CacheDisabled, - TtsUseSapi4, - EncoderNarrowBand, - EncoderQuality, - EncoderVolume, - }; - enum SystemSettings { - ManualUrl, - BleedingUrl, - BootloaderUrl, - BootloaderInfoUrl, - FontUrl, - VoiceUrl, - DoomUrl, - ReleaseUrl, - DailyUrl, - ServerConfUrl, - GenlangUrl, - ThemesUrl, - BleedingInfo, - CurPlatformName, - CurManual, - CurBootloaderMethod, - CurBootloaderName, - CurBootloaderFile, - CurEncoder, - CurResolution, - CurBrand, - CurName, - CurBuildserverModel, - CurConfigureModel, - CurTargetId, - }; - - QVariant value(enum SystemSettings setting); - // generic and "current selection" values -- getters - QVariant value(enum UserSettings setting) - { QString empty; return subValue(empty, setting); } - void setValue(enum UserSettings setting , QVariant value) - { QString empty; return setSubValue(empty, setting, value); } - - QVariant subValue(QString& sub, enum UserSettings setting); - QVariant subValue(const char* sub, enum UserSettings setting) - { QString s = sub; return subValue(s, setting); } - void setSubValue(QString& sub, enum UserSettings setting, QVariant value); - void setSubValue(const char* sub, enum UserSettings setting, QVariant value) - { QString s = sub; return setSubValue(s, setting, value); } - - QStringList platforms(void); - QStringList languages(void); - - QString name(QString plattform); - QString brand(QString plattform); - - QMap usbIdMap(enum MapType); - - private: - //! private copy constructors to prvent copying - RbSettings& operator= (const RbSettings& other) - { (void)other; return *this; } - RbSettings(const RbSettings& other) :QObject() - { (void)other; } - QString constructSettingPath(QString path, QString substitute = QString()); - - //! pointers to our setting objects - QSettings *systemSettings; - QSettings *userSettings; -}; - -#endif diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 961115daad..0723e2b4f9 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro @@ -71,7 +71,7 @@ SOURCES += rbutilqt.cpp \ ../../tools/voicefont.c \ voicefile.cpp \ createvoicewindow.cpp \ - rbsettings.cpp \ + base/rbsettings.cpp \ base/rbunzip.cpp \ base/rbzip.cpp \ base/detect.cpp \ @@ -123,7 +123,7 @@ HEADERS += rbutilqt.h \ ../../tools/voicefont.h \ voicefile.h \ createvoicewindow.h \ - rbsettings.h \ + base/rbsettings.h \ base/rbunzip.h \ base/rbzip.h \ sysinfo.h \ -- cgit v1.2.3