2008-01-25 00:12:25 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
2008-06-30 22:09:45 +00:00
|
|
|
* $Id$
|
2008-01-25 00:12:25 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-02-25 21:05:57 +00:00
|
|
|
|
2008-01-25 00:12:25 +00:00
|
|
|
#include "rbsettings.h"
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
2009-02-25 21:05:57 +00:00
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
// 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", "" },
|
2009-06-15 19:06:03 +00:00
|
|
|
{ RbSettings::CurManual, ":platform:/manualname","rockbox-:platform:" },
|
2009-04-29 20:58:47 +00:00
|
|
|
{ RbSettings::CurBootloaderMethod, ":platform:/bootloadermethod", "none" },
|
|
|
|
{ RbSettings::CurBootloaderName, ":platform:/bootloadername", "" },
|
|
|
|
{ RbSettings::CurBootloaderFile, ":platform:/bootloaderfile", "" },
|
|
|
|
{ RbSettings::CurEncoder, ":platform:/encoder", "" },
|
|
|
|
{ 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" },
|
|
|
|
};
|
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
//! pointer to setting object to NULL
|
|
|
|
QSettings* RbSettings::systemSettings = NULL;
|
|
|
|
QSettings* RbSettings::userSettings = NULL;
|
|
|
|
|
|
|
|
void RbSettings::ensureRbSettingsExists()
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
//check and create settings object
|
|
|
|
if(systemSettings == NULL)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
// only use built-in rbutil.ini
|
|
|
|
systemSettings = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
2009-06-15 19:06:03 +00:00
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
if(userSettings == NULL)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
// 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, NULL);
|
2009-06-16 18:45:20 +00:00
|
|
|
qDebug() << "[Settings] configuration: portable";
|
2009-05-09 16:59:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
userSettings = new QSettings(QSettings::IniFormat,
|
|
|
|
QSettings::UserScope, "rockbox.org", "RockboxUtility",NULL);
|
2009-06-16 18:45:20 +00:00
|
|
|
qDebug() << "[Settings] configuration: system";
|
2009-05-09 16:59:14 +00:00
|
|
|
}
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RbSettings::sync()
|
|
|
|
{
|
2009-06-15 19:06:03 +00:00
|
|
|
ensureRbSettingsExists();
|
2009-05-09 16:59:14 +00:00
|
|
|
|
2008-01-25 00:12:25 +00:00
|
|
|
userSettings->sync();
|
2009-02-25 21:05:57 +00:00
|
|
|
#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);
|
2009-04-16 21:09:19 +00:00
|
|
|
// 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));
|
2009-02-25 21:05:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2008-01-25 00:12:25 +00:00
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
QString RbSettings::userSettingFilename()
|
|
|
|
{
|
2009-06-15 19:06:03 +00:00
|
|
|
ensureRbSettingsExists();
|
2009-05-09 16:59:14 +00:00
|
|
|
return userSettings->fileName();
|
|
|
|
}
|
2008-04-24 20:40:33 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QVariant RbSettings::value(enum SystemSettings setting)
|
2008-04-24 20:40:33 +00:00
|
|
|
{
|
2009-06-15 19:06:03 +00:00
|
|
|
ensureRbSettingsExists();
|
2009-05-09 16:59:14 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
// locate setting item
|
|
|
|
int i = 0;
|
|
|
|
while(SystemSettingsList[i].setting != setting)
|
|
|
|
i++;
|
2008-04-24 20:40:33 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
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);
|
2008-04-24 20:40:33 +00:00
|
|
|
}
|
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
QVariant RbSettings::value(enum UserSettings setting)
|
2009-06-15 19:06:03 +00:00
|
|
|
{
|
|
|
|
QString empty;
|
2009-05-09 16:59:14 +00:00
|
|
|
return subValue(empty, setting);
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
QVariant RbSettings::subValue(QString sub, enum UserSettings setting)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-06-15 19:06:03 +00:00
|
|
|
ensureRbSettingsExists();
|
2009-05-09 16:59:14 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
// locate setting item
|
|
|
|
int i = 0;
|
|
|
|
while(UserSettingsList[i].setting != setting)
|
|
|
|
i++;
|
2009-02-25 21:05:57 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QString s = constructSettingPath(UserSettingsList[i].name, sub);
|
|
|
|
qDebug() << "[Settings] GET U:" << s << userSettings->value(s).toString();
|
|
|
|
return userSettings->value(s, UserSettingsList[i].def);
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
2009-02-25 21:05:57 +00:00
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
void RbSettings::setValue(enum UserSettings setting , QVariant value)
|
|
|
|
{
|
2009-06-15 19:06:03 +00:00
|
|
|
QString empty;
|
2009-05-09 16:59:14 +00:00
|
|
|
return setSubValue(empty, setting, value);
|
|
|
|
}
|
2008-01-25 00:12:25 +00:00
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
void RbSettings::setSubValue(QString sub, enum UserSettings setting, QVariant value)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-06-15 19:06:03 +00:00
|
|
|
ensureRbSettingsExists();
|
2009-05-09 16:59:14 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
// locate setting item
|
|
|
|
int i = 0;
|
|
|
|
while(UserSettingsList[i].setting != setting)
|
|
|
|
i++;
|
2008-01-25 00:12:25 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QString s = constructSettingPath(UserSettingsList[i].name, sub);
|
|
|
|
qDebug() << "[Settings] SET U:" << s << userSettings->value(s).toString();
|
|
|
|
userSettings->setValue(s, value);
|
2008-02-11 17:39:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 17:02:35 +00:00
|
|
|
|
|
|
|
QVariant RbSettings::platformValue(QString platform, enum SystemSettings setting)
|
|
|
|
{
|
|
|
|
ensureRbSettingsExists();
|
|
|
|
|
|
|
|
// locate setting item
|
|
|
|
int i = 0;
|
|
|
|
while(SystemSettingsList[i].setting != setting)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
QString s = SystemSettingsList[i].name;
|
|
|
|
s.replace(":platform:", platform);
|
|
|
|
QString d = SystemSettingsList[i].def;
|
|
|
|
d.replace(":platform:", platform);
|
|
|
|
qDebug() << "[Settings] GET P:" << s << systemSettings->value(s, d).toString();
|
|
|
|
return systemSettings->value(s, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QStringList RbSettings::platforms()
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
ensureRbSettingsExists();
|
|
|
|
|
2008-01-25 00:12:25 +00:00
|
|
|
QStringList result;
|
2009-04-29 20:58:47 +00:00
|
|
|
systemSettings->beginGroup("platforms");
|
|
|
|
QStringList a = systemSettings->childKeys();
|
2009-02-25 21:05:57 +00:00
|
|
|
for(int i = 0; i < a.size(); i++)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-04-29 20:58:47 +00:00
|
|
|
result.append(systemSettings->value(a.at(i), "null").toString());
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
2009-04-29 20:58:47 +00:00
|
|
|
systemSettings->endGroup();
|
2008-01-25 00:12:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QStringList RbSettings::languages()
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
ensureRbSettingsExists();
|
|
|
|
|
2008-01-25 00:12:25 +00:00
|
|
|
QStringList result;
|
2009-04-29 20:58:47 +00:00
|
|
|
systemSettings->beginGroup("languages");
|
|
|
|
QStringList a = systemSettings->childKeys();
|
2009-02-25 21:05:57 +00:00
|
|
|
for(int i = 0; i < a.size(); i++)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-04-29 20:58:47 +00:00
|
|
|
result.append(systemSettings->value(a.at(i), "null").toString());
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
2009-04-29 20:58:47 +00:00
|
|
|
systemSettings->endGroup();
|
2008-01-25 00:12:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-08-11 17:02:35 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QString RbSettings::name(QString platform)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
ensureRbSettingsExists();
|
2009-04-29 20:58:47 +00:00
|
|
|
return systemSettings->value(platform + "/name").toString();
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QString RbSettings::brand(QString platform)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
ensureRbSettingsExists();
|
2009-04-29 20:58:47 +00:00
|
|
|
return systemSettings->value(platform + "/brand").toString();
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
|
|
|
|
2009-04-16 20:49:43 +00:00
|
|
|
QMap<int, QString> RbSettings::usbIdMap(enum MapType type)
|
2008-04-03 20:05:13 +00:00
|
|
|
{
|
2009-05-09 16:59:14 +00:00
|
|
|
ensureRbSettingsExists();
|
|
|
|
|
2008-04-03 20:05:13 +00:00
|
|
|
QMap<int, QString> map;
|
2009-04-29 20:58:47 +00:00
|
|
|
// get a list of ID -> target name
|
2008-04-03 20:05:13 +00:00
|
|
|
QStringList platforms;
|
2009-04-29 20:58:47 +00:00
|
|
|
systemSettings->beginGroup("platforms");
|
|
|
|
platforms = systemSettings->childKeys();
|
|
|
|
systemSettings->endGroup();
|
2009-02-25 21:05:57 +00:00
|
|
|
|
2009-04-16 20:49:43 +00:00
|
|
|
QString t;
|
|
|
|
switch(type) {
|
|
|
|
case MapDevice:
|
|
|
|
t = "usbid";
|
|
|
|
break;
|
|
|
|
case MapError:
|
|
|
|
t = "usberror";
|
|
|
|
break;
|
|
|
|
case MapIncompatible:
|
|
|
|
t = "usbincompat";
|
|
|
|
break;
|
2008-04-03 20:05:13 +00:00
|
|
|
}
|
2009-02-25 21:05:57 +00:00
|
|
|
|
2008-04-03 20:05:13 +00:00
|
|
|
for(int i = 0; i < platforms.size(); i++)
|
|
|
|
{
|
2009-04-29 20:58:47 +00:00
|
|
|
systemSettings->beginGroup("platforms");
|
|
|
|
QString target = systemSettings->value(platforms.at(i)).toString();
|
|
|
|
systemSettings->endGroup();
|
|
|
|
systemSettings->beginGroup(target);
|
|
|
|
QStringList ids = systemSettings->value(t).toStringList();
|
2008-04-03 23:14:58 +00:00
|
|
|
int j = ids.size();
|
|
|
|
while(j--)
|
|
|
|
map.insert(ids.at(j).toInt(0, 16), target);
|
2009-02-25 21:05:57 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
systemSettings->endGroup();
|
2008-04-05 21:48:54 +00:00
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2008-04-03 20:05:13 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
QString RbSettings::constructSettingPath(QString path, QString substitute)
|
2008-01-25 00:12:25 +00:00
|
|
|
{
|
2009-04-29 20:58:47 +00:00
|
|
|
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);
|
2008-01-25 00:12:25 +00:00
|
|
|
|
2009-04-29 20:58:47 +00:00
|
|
|
return path;
|
2008-01-25 00:12:25 +00:00
|
|
|
}
|
2008-09-28 17:02:36 +00:00
|
|
|
|