summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/rbsettings.cpp
blob: 909dba4951717f99863ebc421d4ef8d179ad4e85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/***************************************************************************
 *             __________               __   ___.
 *   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 <QSettings>

#if defined(Q_OS_LINUX)
#include <unistd.h>
#endif

void RbSettings::open()
{
    // only use built-in rbutil.ini
    devices = 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(qPrintable(userSettings->fileName()), realuid, realgid);
        }
    }
#endif
}

QVariant RbSettings::deviceSettingCurGet(QString entry,QString def)
{
    QString platform = userSettings->value("platform").toString();
    devices->beginGroup(platform);
    QVariant result = devices->value(entry,def);
    devices->endGroup();
    return result;
}

QVariant RbSettings::userSettingsGroupGet(QString group,QString entry,QVariant def)
{
    userSettings->beginGroup(group);
    QVariant result = userSettings->value(entry,def);
    userSettings->endGroup();
    return result;
}

void RbSettings::userSettingsGroupSet(QString group,QString entry,QVariant value)
{
    userSettings->beginGroup(group);
    userSettings->setValue(entry,value);
    userSettings->endGroup();
}

QString RbSettings::userSettingFilename()
{
    return userSettings->fileName();
}

QString RbSettings::curVersion()
{
    return userSettings->value("rbutil_version").toString();
}

bool RbSettings::cacheOffline()
{
    return userSettings->value("offline").toBool();
}

QString RbSettings::mountpoint()
{
    return userSettings->value("mountpoint").toString();
}

QString RbSettings::manualUrl()
{
    return devices->value("manual_url").toString();
}

QString RbSettings::bleedingUrl()
{
    return devices->value("bleeding_url").toString();
}

QString RbSettings::cachePath()
{
    return userSettings->value("cachepath", QDir::tempPath()).toString();
}

QString RbSettings::build()
{
    return userSettings->value("build").toString();
}

QString RbSettings::bootloaderUrl()
{
    return devices->value("bootloader_url").toString();
}

QString RbSettings::bootloaderInfoUrl()
{
    return devices->value("bootloader_info_url").toString();
}

QString RbSettings::fontUrl()
{
    return devices->value("font_url").toString();
}

QString RbSettings::voiceUrl()
{
    return devices->value("voice_url").toString();
}

QString RbSettings::doomUrl()
{
    return devices->value("doom_url").toString();
}

QString RbSettings::releaseUrl()
{
    return devices->value("release_url").toString();
}

QString RbSettings::dailyUrl()
{
    return devices->value("daily_url").toString();
}

QString RbSettings::serverConfUrl()
{
    return devices->value("server_conf_url").toString();
}

QString RbSettings::genlangUrl()
{
    return devices->value("genlang_url").toString();
}

QString RbSettings::themeUrl()
{
    return devices->value("themes_url").toString();
}

QString RbSettings::bleedingInfo()
{
    return devices->value("bleeding_info").toString();
}

bool RbSettings::cacheDisabled()
{
    return userSettings->value("cachedisable").toBool();
}

QString RbSettings::proxyType()
{
    return userSettings->value("proxytype", "none").toString();
}

QString RbSettings::proxy()
{
    return userSettings->value("proxy").toString();
}

QString RbSettings::ofPath()
{
    return userSettings->value("ofpath").toString();
}

QString RbSettings::curBrand()
{
    QString platform = userSettings->value("platform").toString();
    return brand(platform);
}

QString RbSettings::curName()
{
    QString platform = userSettings->value("platform").toString();
    return name(platform);
}

QString RbSettings::curPlatform()
{
    return userSettings->value("platform").toString();
}

QString RbSettings::curBuildserver_Modelname()
{
    return deviceSettingCurGet("buildserver_modelname").toString();
}

QString RbSettings::curManual()
{
    return deviceSettingCurGet("manualname","rockbox-" +
            devices->value("platform").toString()).toString();
}

QString RbSettings::curBootloaderMethod()
{
    return deviceSettingCurGet("bootloadermethod", "none").toString();
}

QString RbSettings::curBootloaderName()
{
    return deviceSettingCurGet("bootloadername").toString();
}

QString RbSettings::curBootloaderFile()
{
    return deviceSettingCurGet("bootloaderfile").toString();
}

QString RbSettings::curConfigure_Modelname()
{
    return deviceSettingCurGet("configure_modelname").toString();
}

QString RbSettings::curLang()
{
    // QSettings::value only returns the default when the setting
    // doesn't exist. Make sure to return the system language if
    // the language in the configuration is present but empty too.
    QString lang = userSettings->value("lang").toString();
    if(lang.isEmpty())
        lang = QLocale::system().name();
    return lang;
}

QString RbSettings::curEncoder()
{
    return deviceSettingCurGet("encoder").toString();
}

QString RbSettings::curTTS()
{
    return userSettings->value("tts").toString();
}

QString RbSettings::lastTalkedFolder()
{
    return userSettings->value("last_talked_folder").toString();
}

QString RbSettings::voiceLanguage()
{
    return userSettings->value("voicelanguage").toString();
}

int RbSettings::wavtrimTh()
{
    return userSettings->value("wavtrimthreshold",500).toInt();
}

QString RbSettings::ttsPath(QString tts)
{
    return userSettingsGroupGet(tts,"ttspath").toString();
}
QString RbSettings::ttsOptions(QString tts)
{
    return userSettingsGroupGet(tts,"ttsoptions").toString();
}
QString RbSettings::ttsVoice(QString tts)
{
    return userSettingsGroupGet(tts,"ttsvoice","Microsoft Sam").toString();
}
int RbSettings::ttsSpeed(QString tts)
{
    return userSettingsGroupGet(tts,"ttsspeed",0).toInt();
}
QString RbSettings::ttsLang(QString tts)
{
    return userSettingsGroupGet(tts,"ttslanguage","english").toString();
}

bool RbSettings::ttsUseSapi4()
{
    return userSettingsGroupGet("sapi","useSapi4",false).toBool();
}

QString RbSettings::encoderPath(QString enc)
{
    return userSettingsGroupGet(enc,"encoderpath").toString();
}
QString RbSettings::encoderOptions(QString enc)
{
    return userSettingsGroupGet(enc,"encoderoptions").toString();
}

double RbSettings::encoderQuality(QString enc)
{
    return userSettingsGroupGet(enc,"quality",8.f).toDouble();
}
int RbSettings::encoderComplexity(QString enc)
{
    return userSettingsGroupGet(enc,"complexity",10).toInt();
}
double RbSettings::encoderVolume(QString enc)
{
    return userSettingsGroupGet(enc,"volume",1.f).toDouble();
}
bool RbSettings::encoderNarrowband(QString enc)
{
    return userSettingsGroupGet(enc,"narrowband",false).toBool();
}

QStringList RbSettings::allPlatforms()
{
    QStringList result;
    devices->beginGroup("platforms");
    QStringList a = devices->childKeys();
    for(int i = 0; i < a.size(); i++)
    {
        result.append(devices->value(a.at(i), "null").toString());
    }
    devices->endGroup();
    return result;
}

QStringList RbSettings::allLanguages()
{
    QStringList result;
    devices->beginGroup("languages");
    QStringList a = devices->childKeys();
    for(int i = 0; i < a.size(); i++)
    {
        result.append(devices->value(a.at(i), "null").toString());
    }
    devices->endGroup();
    return result;
}

QString RbSettings::name(QString plattform)
{
    devices->beginGroup(plattform);
    QString name = devices->value("name").toString();
    devices->endGroup();
    return name;
}

QString RbSettings::brand(QString plattform)
{
    devices->beginGroup(plattform);
    QString brand = devices->value("brand").toString();
    devices->endGroup();
    return brand;
}

QMap<int, QString> RbSettings::usbIdMap()
{
    QMap<int, QString> map;
     // get a list of ID -> target name
    QStringList platforms;
    devices->beginGroup("platforms");
    platforms = devices->childKeys();
    devices->endGroup();

    for(int i = 0; i < platforms.size(); i++)
    {
        devices->beginGroup("platforms");
        QString target = devices->value(platforms.at(i)).toString();
        devices->endGroup();
        devices->beginGroup(target);
        QStringList ids = devices->value("usbid").toStringList();
        int j = ids.size();
        while(j--)
            map.insert(ids.at(j).toInt(0, 16), target);

        devices->endGroup();
    }
    return map;
}

QMap<int, QString> RbSettings::usbIdErrorMap()
{

    QMap<int, QString> map;
     // get a list of ID -> target name
    QStringList platforms;
    devices->beginGroup("platforms");
    platforms = devices->childKeys();
    devices->endGroup();

    for(int i = 0; i < platforms.size(); i++)
    {
        devices->beginGroup("platforms");
        QString target = devices->value(platforms.at(i)).toString();
        devices->endGroup();
        devices->beginGroup(target);
        QStringList ids = devices->value("usberror").toStringList();
        int j = ids.size();
        while(j--)
            map.insert(ids.at(j).toInt(0, 16), target);
        devices->endGroup();
    }
    return map;
}


QMap<int, QString> RbSettings::usbIdIncompatMap()
{

    QMap<int, QString> map;
     // get a list of ID -> target name
    QStringList platforms;
    devices->beginGroup("platforms");
    platforms = devices->childKeys();
    devices->endGroup();

    for(int i = 0; i < platforms.size(); i++)
    {
        devices->beginGroup("platforms");
        QString target = devices->value(platforms.at(i)).toString();
        devices->endGroup();
        devices->beginGroup(target);
        QStringList ids = devices->value("usbincompat").toStringList();
        int j = ids.size();
        while(j--)
            map.insert(ids.at(j).toInt(0, 16), target);
        devices->endGroup();
    }
    return map;
}


QString RbSettings::curResolution()
{
    return deviceSettingCurGet("resolution").toString();
}

int RbSettings::curTargetId()
{
    return deviceSettingCurGet("targetid").toInt();
}

void RbSettings::setCurVersion(QString version)
{
    userSettings->setValue("rbutil_version",version);
}

void RbSettings::setOfPath(QString path)
{
    userSettings->setValue("ofpath",path);
}

void RbSettings::setCachePath(QString path)
{
    userSettings->setValue("cachepath", path);
}

void RbSettings::setBuild(QString build)
{
    userSettings->setValue("build", build);
}

void RbSettings::setLastTalkedDir(QString dir)
{
    userSettings->setValue("last_talked_folder", dir);
}

void RbSettings::setVoiceLanguage(QString dir)
{
    userSettings->setValue("voicelanguage", dir);
}

void RbSettings::setWavtrimTh(int th)
{
    userSettings->setValue("wavtrimthreshold", th);
}

void RbSettings::setProxy(QString proxy)
{
    userSettings->setValue("proxy", proxy);
}

void RbSettings::setProxyType(QString proxytype)
{
    userSettings->setValue("proxytype", proxytype);
}

void RbSettings::setLang(QString lang)
{
    userSettings->setValue("lang", lang);
}

void RbSettings::setMountpoint(QString mp)
{
    userSettings->setValue("mountpoint",mp);
}

void RbSettings::setCurPlatform(QString platt)
{
    userSettings->setValue("platform",platt);
}


void RbSettings::setCacheDisable(bool on)
{
    userSettings->setValue("cachedisable",on);
}

void RbSettings::setCacheOffline(bool on)
{
    userSettings->setValue("offline",on);
}

void RbSettings::setCurTTS(QString tts)
{
    userSettings->setValue("tts",tts);
}

void RbSettings::setTTSPath(QString tts, QString path)
{
    userSettingsGroupSet(tts,"ttspath",path);
}

void RbSettings::setTTSOptions(QString tts, QString options)
{
    userSettingsGroupSet(tts,"ttsoptions",options);
}

void RbSettings::setTTSVoice(QString tts, QString voice)
{
    userSettingsGroupSet(tts,"ttsvoice",voice);
}

void RbSettings::setTTSSpeed(QString tts, int speed)
{
    userSettingsGroupSet(tts,"ttsspeed",speed);
}

void RbSettings::setTTSLang(QString tts, QString lang)
{
    userSettingsGroupSet(tts,"ttslanguage",lang);
}

void RbSettings::setTTSUseSapi4(bool value)
{
    userSettingsGroupSet("sapi","useSapi4",value);
}

void RbSettings::setEncoderPath(QString enc, QString path)
{
    userSettingsGroupSet(enc,"encoderpath",path);
}

void RbSettings::setEncoderOptions(QString enc, QString options)
{
    userSettingsGroupSet(enc,"encoderoptions",options);
}

void RbSettings::setEncoderQuality(QString enc, double q)
{
    userSettingsGroupSet(enc,"quality",q);
}
void RbSettings::setEncoderComplexity(QString enc, int c)
{
    userSettingsGroupSet(enc,"complexity",c);
}
void RbSettings::setEncoderVolume(QString enc,double v)
{
    userSettingsGroupSet(enc,"volume",v);
}
void RbSettings::setEncoderNarrowband(QString enc,bool nb)
{
    userSettingsGroupSet(enc,"narrowband",nb);
}