fix red and remove tabs
[kugel-rb.git] / rbutil / rbutilqt / rbsettings.cpp
blob78457809a3dd87b710f126d33346222736f78dfb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: rbsettings.cpp 16150 2008-01-23 21:54:40Z domonoky $
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "rbsettings.h"
22 #include <QSettings>
24 void RbSettings::open()
26 // only use built-in rbutil.ini
27 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
28 // portable installation:
29 // check for a configuration file in the program folder.
30 QFileInfo config;
31 config.setFile(QCoreApplication::instance()->applicationDirPath() + "/RockboxUtility.ini");
32 if(config.isFile())
34 userSettings = new QSettings(QCoreApplication::instance()->applicationDirPath() + "/RockboxUtility.ini",
35 QSettings::IniFormat, this);
36 qDebug() << "config: portable";
38 else
40 userSettings = new QSettings(QSettings::IniFormat,
41 QSettings::UserScope, "rockbox.org", "RockboxUtility",this);
42 qDebug() << "config: system";
46 void RbSettings::sync()
48 userSettings->sync();
51 QString RbSettings::userSettingFilename()
53 return userSettings->fileName();
56 bool RbSettings::cacheOffline()
58 return userSettings->value("offline").toBool();
61 bool RbSettings::curNeedsBootloader()
63 QString platform = userSettings->value("platform").toString();
64 devices->beginGroup(platform);
65 QString result = devices->value("needsbootloader", "").toString();
66 devices->endGroup();
67 if( result == "no")
69 return false;
71 else
72 return true;
75 QString RbSettings::mountpoint()
77 return userSettings->value("mountpoint").toString();
80 QString RbSettings::manualUrl()
82 return devices->value("manual_url").toString();
85 QString RbSettings::bleedingUrl()
87 return devices->value("bleeding_url").toString();
91 QString RbSettings::lastRelease()
93 return devices->value("last_release").toString();
96 QString RbSettings::cachePath()
98 return userSettings->value("cachepath", QDir::tempPath()).toString();
101 QString RbSettings::bootloaderUrl()
103 return devices->value("bootloader_url").toString();
106 QString RbSettings::bootloaderInfoUrl()
108 return devices->value("bootloader_info_url").toString();
111 QString RbSettings::fontUrl()
113 return devices->value("font_url").toString();
116 QString RbSettings::voiceUrl()
118 return devices->value("voice_url").toString();
121 QString RbSettings::doomUrl()
123 return devices->value("doom_url").toString();
126 QString RbSettings::downloadUrl()
128 return devices->value("download_url").toString();
131 QString RbSettings::dailyUrl()
133 return devices->value("daily_url").toString();
136 QString RbSettings::serverConfUrl()
138 return devices->value("server_conf_url").toString();
141 QString RbSettings::genlangUrl()
143 return devices->value("genlang_url").toString();
146 QString RbSettings::themeUrl()
148 return devices->value("themes_url").toString();
151 QString RbSettings::bleedingInfo()
153 return devices->value("bleeding_info").toString();
156 bool RbSettings::cacheDisabled()
158 return userSettings->value("cachedisable").toBool();
161 QString RbSettings::proxyType()
163 return userSettings->value("proxytype", "none").toString();
166 QString RbSettings::proxy()
168 return userSettings->value("proxy").toString();
171 QString RbSettings::ofPath()
173 return userSettings->value("ofpath").toString();
176 QString RbSettings::curBrand()
178 QString platform = userSettings->value("platform").toString();
179 return brand(platform);
182 QString RbSettings::curName()
184 QString platform = userSettings->value("platform").toString();
185 return name(platform);
188 QString RbSettings::curPlatform()
190 return userSettings->value("platform").toString();
193 QString RbSettings::curPlatformName()
195 QString platform = userSettings->value("platform").toString();
196 devices->beginGroup(platform);
197 QString name = devices->value("platform").toString();
198 devices->endGroup();
199 return name;
202 QString RbSettings::curManual()
204 QString platform = userSettings->value("platform").toString();
205 devices->beginGroup(platform);
206 QString name = devices->value("manualname","rockbox-" +
207 devices->value("platform").toString()).toString();
208 devices->endGroup();
209 return name;
212 bool RbSettings::curReleased()
214 QString platform = userSettings->value("platform").toString();
215 devices->beginGroup(platform);
216 QString released = devices->value("released").toString();
217 devices->endGroup();
219 if(released == "yes")
220 return true;
221 else
222 return false;
225 QString RbSettings::curBootloaderMethod()
227 QString platform = userSettings->value("platform").toString();
228 devices->beginGroup(platform);
229 QString method = devices->value("bootloadermethod").toString();
230 devices->endGroup();
231 return method;
234 QString RbSettings::curBootloaderName()
236 QString platform = userSettings->value("platform").toString();
237 devices->beginGroup(platform);
238 QString name = devices->value("bootloadername").toString();
239 devices->endGroup();
240 return name;
243 QString RbSettings::curVoiceName()
245 QString platform = userSettings->value("platform").toString();
246 devices->beginGroup(platform);
247 QString name = devices->value("voicename").toString();
248 devices->endGroup();
249 return name;
252 QString RbSettings::curLang()
254 return userSettings->value("lang").toString();
257 QString RbSettings::curEncoder()
259 return userSettings->value("encoder").toString();
262 QString RbSettings::curTTS()
264 return userSettings->value("tts").toString();
267 QString RbSettings::lastTalkedFolder()
269 return userSettings->value("last_talked_folder").toString();
272 QString RbSettings::voiceLanguage()
274 return userSettings->value("voicelanguage").toString();
277 int RbSettings::wavtrimTh()
279 return userSettings->value("wavtrimthreshold",500).toInt();
282 QString RbSettings::ttsPath(QString tts)
284 userSettings->beginGroup(tts);
285 QString path = userSettings->value("ttspath").toString();
286 userSettings->endGroup();
287 return path;
290 QString RbSettings::ttsOptions(QString tts)
292 userSettings->beginGroup(tts);
293 QString op = userSettings->value("ttsoptions").toString();
294 userSettings->endGroup();
295 return op;
297 QString RbSettings::ttsVoice(QString tts)
299 userSettings->beginGroup(tts);
300 QString op = userSettings->value("ttsvoice","Microsoft Sam").toString();
301 userSettings->endGroup();
302 return op;
304 int RbSettings::ttsSpeed(QString tts)
306 userSettings->beginGroup(tts);
307 int sp = userSettings->value("ttsspeed",0).toInt();
308 userSettings->endGroup();
309 return sp;
311 QString RbSettings::ttsLang(QString tts)
313 userSettings->beginGroup(tts);
314 QString op = userSettings->value("ttslanguage","english").toString();
315 userSettings->endGroup();
316 return op;
319 bool RbSettings::ttsUseSapi4()
321 userSettings->beginGroup("sapi");
322 bool op = userSettings->value("useSapi4",false).toBool();
323 userSettings->endGroup();
324 return op;
327 QString RbSettings::encoderPath(QString enc)
329 userSettings->beginGroup(enc);
330 QString path = userSettings->value("encoderpath").toString();
331 userSettings->endGroup();
332 return path;
334 QString RbSettings::encoderOptions(QString enc)
336 userSettings->beginGroup(enc);
337 QString op = userSettings->value("encoderoptions").toString();
338 userSettings->endGroup();
339 return op;
342 double RbSettings::encoderQuality(QString enc)
344 userSettings->beginGroup(enc);
345 double q =userSettings->value("quality",8.f).toDouble();
346 userSettings->endGroup();
347 return q;
349 int RbSettings::encoderComplexity(QString enc)
351 userSettings->beginGroup(enc);
352 int c = userSettings->value("complexity",10).toInt();
353 userSettings->endGroup();
354 return c;
356 double RbSettings::encoderVolume(QString enc)
358 userSettings->beginGroup(enc);
359 double v = userSettings->value("volume",1.f).toDouble();
360 userSettings->endGroup();
361 return v;
363 bool RbSettings::encoderNarrowband(QString enc)
365 userSettings->beginGroup(enc);
366 bool nb = userSettings->value("narrowband",false).toBool();
367 userSettings->endGroup();
368 return nb;
371 QStringList RbSettings::allPlatforms()
373 QStringList result;
374 devices->beginGroup("platforms");
375 QStringList a = devices->childKeys();
376 for(int i = 0; i < a.size(); i++)
378 result.append(devices->value(a.at(i), "null").toString());
380 devices->endGroup();
381 return result;
384 QStringList RbSettings::allLanguages()
386 QStringList result;
387 devices->beginGroup("languages");
388 QStringList a = devices->childKeys();
389 for(int i = 0; i < a.size(); i++)
391 result.append(devices->value(a.at(i), "null").toString());
393 devices->endGroup();
394 return result;
397 QString RbSettings::name(QString plattform)
399 devices->beginGroup(plattform);
400 QString name = devices->value("name").toString();
401 devices->endGroup();
402 return name;
405 QString RbSettings::brand(QString plattform)
407 devices->beginGroup(plattform);
408 QString brand = devices->value("brand").toString();
409 devices->endGroup();
410 return brand;
413 QMap<int, QString> RbSettings::usbIdMap()
415 QMap<int, QString> map;
416 // get a list of ID -> target name
417 QStringList platforms;
418 devices->beginGroup("platforms");
419 platforms = devices->childKeys();
420 devices->endGroup();
422 for(int i = 0; i < platforms.size(); i++)
424 devices->beginGroup("platforms");
425 QString target = devices->value(platforms.at(i)).toString();
426 devices->endGroup();
427 devices->beginGroup(target);
428 QStringList ids = devices->value("usbid").toStringList();
429 int j = ids.size();
430 while(j--)
431 map.insert(ids.at(j).toInt(0, 16), target);
433 devices->endGroup();
435 return map;
438 QMap<int, QString> RbSettings::usbIdErrorMap()
441 QMap<int, QString> map;
442 // get a list of ID -> target name
443 QStringList platforms;
444 devices->beginGroup("platforms");
445 platforms = devices->childKeys();
446 devices->endGroup();
448 for(int i = 0; i < platforms.size(); i++)
450 devices->beginGroup("platforms");
451 QString target = devices->value(platforms.at(i)).toString();
452 devices->endGroup();
453 devices->beginGroup(target);
454 QStringList ids = devices->value("usberror").toStringList();
455 int j = ids.size();
456 while(j--)
457 map.insert(ids.at(j).toInt(0, 16), target);
458 devices->endGroup();
460 return map;
464 QMap<int, QString> RbSettings::usbIdIncompatMap()
467 QMap<int, QString> map;
468 // get a list of ID -> target name
469 QStringList platforms;
470 devices->beginGroup("platforms");
471 platforms = devices->childKeys();
472 devices->endGroup();
474 for(int i = 0; i < platforms.size(); i++)
476 devices->beginGroup("platforms");
477 QString target = devices->value(platforms.at(i)).toString();
478 devices->endGroup();
479 devices->beginGroup(target);
480 QStringList ids = devices->value("usbincompat").toStringList();
481 int j = ids.size();
482 while(j--)
483 map.insert(ids.at(j).toInt(0, 16), target);
484 devices->endGroup();
486 return map;
490 QString RbSettings::curResolution()
492 QString platform = userSettings->value("platform").toString();
493 devices->beginGroup(platform);
494 QString resolution = devices->value("resolution").toString();
495 devices->endGroup();
496 return resolution;
499 int RbSettings::curTargetId()
501 QString platform = userSettings->value("platform").toString();
502 devices->beginGroup(platform);
503 int id = devices->value("targetid").toInt();
504 devices->endGroup();
505 return id;
509 void RbSettings::setOfPath(QString path)
511 userSettings->setValue("ofpath",path);
514 void RbSettings::setCachePath(QString path)
516 userSettings->setValue("cachepath", path);
519 void RbSettings::setBuild(QString build)
521 userSettings->setValue("build", build);
524 void RbSettings::setLastTalkedDir(QString dir)
526 userSettings->setValue("last_talked_folder", dir);
529 void RbSettings::setVoiceLanguage(QString dir)
531 userSettings->setValue("voicelanguage", dir);
534 void RbSettings::setWavtrimTh(int th)
536 userSettings->setValue("wavtrimthreshold", th);
539 void RbSettings::setProxy(QString proxy)
541 userSettings->setValue("proxy", proxy);
544 void RbSettings::setProxyType(QString proxytype)
546 userSettings->setValue("proxytype", proxytype);
549 void RbSettings::setLang(QString lang)
551 userSettings->setValue("lang", lang);
554 void RbSettings::setMountpoint(QString mp)
556 userSettings->setValue("mountpoint",mp);
559 void RbSettings::setCurPlatform(QString platt)
561 userSettings->setValue("platform",platt);
565 void RbSettings::setCacheDisable(bool on)
567 userSettings->setValue("cachedisable",on);
570 void RbSettings::setCacheOffline(bool on)
572 userSettings->setValue("offline",on);
575 void RbSettings::setCurTTS(QString tts)
577 userSettings->setValue("tts",tts);
580 void RbSettings::setCurEncoder(QString enc)
582 userSettings->setValue("encoder",enc);
585 void RbSettings::setTTSPath(QString tts, QString path)
587 userSettings->beginGroup(tts);
588 userSettings->setValue("ttspath",path);
589 userSettings->endGroup();
592 void RbSettings::setTTSOptions(QString tts, QString options)
594 userSettings->beginGroup(tts);
595 userSettings->setValue("ttsoptions",options);
596 userSettings->endGroup();
599 void RbSettings::setTTSVoice(QString tts, QString voice)
601 userSettings->beginGroup(tts);
602 userSettings->setValue("ttsvoice",voice);
603 userSettings->endGroup();
606 void RbSettings::setTTSSpeed(QString tts, int speed)
608 userSettings->beginGroup(tts);
609 userSettings->setValue("ttsspeed",speed);
610 userSettings->endGroup();
613 void RbSettings::setTTSLang(QString tts, QString lang)
615 userSettings->beginGroup(tts);
616 userSettings->setValue("ttslanguage",lang);
617 userSettings->endGroup();
620 void RbSettings::setTTSUseSapi4(bool value)
622 userSettings->beginGroup("sapi");
623 userSettings->setValue("useSapi4",value);
624 userSettings->endGroup();
628 void RbSettings::setEncoderPath(QString enc, QString path)
630 userSettings->beginGroup(enc);
631 userSettings->setValue("encoderpath",path);
632 userSettings->endGroup();
635 void RbSettings::setEncoderOptions(QString enc, QString options)
637 userSettings->beginGroup(enc);
638 userSettings->setValue("encoderoptions",options);
639 userSettings->endGroup();
642 void RbSettings::setEncoderQuality(QString enc, double q)
644 userSettings->beginGroup(enc);
645 userSettings->setValue("quality",q);
646 userSettings->endGroup();
648 void RbSettings::setEncoderComplexity(QString enc, int c)
650 userSettings->beginGroup(enc);
651 userSettings->setValue("complexity",c);
652 userSettings->endGroup();
654 void RbSettings::setEncoderVolume(QString enc,double v)
656 userSettings->beginGroup(enc);
657 userSettings->setValue("volume",v);
658 userSettings->endGroup();
660 void RbSettings::setEncoderNarrowband(QString enc,bool nb)
662 userSettings->beginGroup(enc);
663 userSettings->setValue("narrowband",nb);
664 userSettings->endGroup();