ssufeaturemanager.cpp 2.11 KB
Newer Older
Aard's avatar
Aard committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/**
 * @file ssufeaturemanager.cpp
 * @copyright 2013 Jolla Ltd.
 * @author Bernd Wachter <bwachter@lart.info>
 * @date 2013
 */

#include <QStringList>
#include <QRegExp>
#include <QDirIterator>

#include "ssudeviceinfo.h"
#include "ssufeaturemanager.h"
14 15 16
#include "ssucoreconfig_p.h"
#include "ssulog_p.h"
#include "ssuvariables_p.h"
Aard's avatar
Aard committed
17 18 19 20
#include "ssu.h"

#include "../constants.h"

21 22 23
SsuFeatureManager::SsuFeatureManager(): QObject()
{
    featureSettings = new SsuSettings(SSU_FEATURE_CONFIGURATION, SSU_FEATURE_CONFIGURATION_DIR);
Aard's avatar
Aard committed
24 25 26 27 28 29 30 31 32 33
}


// @TODO - allow enabling/disabling features
//       - export feature file for mic through ssu-ks
//       - add feature header in ssu-ks
//
//    all features have a list of repositories in the repos key
//    if there are enabled/disabled features, check the repos keys from all enabled features
//    and only enable the repositories from those
34 35 36 37 38
QStringList SsuFeatureManager::repos(bool rndRepo, int filter)
{
    QStringList r;
    QStringList keys;
    SsuCoreConfig *settings = SsuCoreConfig::instance();
Aard's avatar
Aard committed
39

40 41 42 43
    // @TODO features currently can't be blacklisted, but just ignoring user filter
    // is still the best way atm
    if (filter == Ssu::UserFilter)
        return r;
Aard's avatar
Aard committed
44

45 46
    QString repoHeader = QString("repositories-%1/")
                         .arg(rndRepo ? "rnd" : "release");
Aard's avatar
Aard committed
47

48 49 50 51
    // take the global groups
    featureSettings->beginGroup("repositories");
    r.append(featureSettings->allKeys());
    featureSettings->endGroup();
Aard's avatar
Aard committed
52

53 54 55 56
    // and override with rnd/release specific groups
    featureSettings->beginGroup(repoHeader);
    r.append(featureSettings->allKeys());
    featureSettings->endGroup();
Aard's avatar
Aard committed
57

58 59
    r.removeDuplicates();
    return r;
Aard's avatar
Aard committed
60 61
}

62 63 64 65
QString SsuFeatureManager::url(QString repo, bool rndRepo)
{
    QString repoHeader = QString("repositories-%1/")
                         .arg(rndRepo ? "rnd" : "release");
Aard's avatar
Aard committed
66

67 68 69 70
    if (featureSettings->contains(repoHeader + repo))
        return featureSettings->value(repoHeader + repo).toString();
    else if (featureSettings->contains("repositories/" + repo))
        return featureSettings->value("repositories/" + repo).toString();
Aard's avatar
Aard committed
71

72
    return "";
Aard's avatar
Aard committed
73
}