ssudeviceinfo.h 4.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/**
 * @file ssudeviceinfo.h
 * @copyright 2013 2013 Jolla Ltd.
 * @author Bernd Wachter <bwachter@lart.info>
 * @date 2013
 */

#ifndef _SSUDEVICEINFO_H
#define _SSUDEVICEINFO_H

#include <QObject>

Aard's avatar
Aard committed
13
#include "ssu.h"
14

15 16
class SsuSettings;

17 18
class SsuDeviceInfo: public QObject
{
19 20
    Q_OBJECT

21
public:
22 23 24
    /**
     * Initialize with device to override autodetection
     */
25
    SsuDeviceInfo(QString model = "");
26 27 28 29
    /**
     * Return the list of adaptations used for the set model
     */
    QStringList adaptationRepos();
30 31 32 33 34
    /**
     * Resolve adaptation-specific variables for adaptationName, and store them in storageHash
     * Returns "adaptation" if a valid adaptation was found, adaptationName otherwise
     */
    QString adaptationVariables(const QString &adaptationName, QHash<QString, QString> *storageHash);
35
    /**
36 37 38 39
     * Check if a given model is available in the deviceinfo database, either directly,
     * or as variant. If no model is provided as argument the autodetected or previously
     * set model is used.
     */
40
    bool contains(const QString &model = "");
41 42 43 44
    /**
     * Try to find the device family for the system this is running on. This function
     * temporarily changes the detected model, and therefore should not be used in a
     * multithreaded environment, unless you like funny results.
45 46
     */
    Q_INVOKABLE QString deviceFamily();
47 48
    /**
     * Try to find the device variant for the system this is running on.
49 50
     * If the device is not a variant it will return an empty string. If
     * fallback is set to true it return the device model in this case.
51
     */
52
    Q_INVOKABLE QString deviceVariant(bool fallback = false);
53 54 55 56 57
    /**
     * Try to find out ond what kind of system this is running
     */
    Q_INVOKABLE QString deviceModel();
    /**
58
     * Calculate the device ID used in ssu requests
59
     * @return The first imei from oFono ModemManager API, if available, or WLAN mac address, or device uid fallback code similar to QDeviceInfo::uniqueDeviceID()
60 61
     */
    Q_INVOKABLE QString deviceUid();
62 63
    /**
     * Return the list of repositories explicitely disabled for this device
Aard's avatar
Aard committed
64
     * This does not include repositories only disabled in the user configuration.
65 66
     */
    QStringList disabledRepos();
67 68 69 70 71
    /**
     * Return a string suitable for display in dialogs, ...
     *
     * See Ssu::DeviceTypes for supported types.
     *
72
     * If not configured the model name used by ssu will be returned instead
73 74 75 76 77
     * for product and type.
     * If no manufacturer is found UNKNOWN is returned.
     * For an invalid type an empty string is returned.
     */
    Q_INVOKABLE QString displayName(const int type);
78
    /**
Aard's avatar
Aard committed
79 80 81 82
     * Return the complete list of repositories configured for a device.
     * Depending on the filter options, all repostories (user and board),
     * only board-specific, or only user-specific are returned.
     * Disabled repositories are excluded depending on filter settings.
83
     */
84
    QStringList repos(bool rnd = false, int filter = Ssu::NoFilter);
85 86 87
    /**
     * Override device model autodetection
     */
88
    Q_INVOKABLE void setDeviceModel(QString model = "");
89 90 91 92 93 94 95
    /**
     * Return a variable from the given variable section. 'var'- is automatically
     * prepended to the section name if not specified already. Recursive search
     * through several variable sections (specified in the section) is supported,
     * returned will be the first occurence of the variable.
     */
    QVariant variable(QString section, const QString &key);
96 97 98 99
    /**
     * Return the requested variable section. 'var-' is automatically
     * prepended to the section name if not specified already.
     */
100
    void variableSection(QString section, QHash<QString, QString> *storageHash);
101 102 103
    /**
     * Return a value from an adaptation section. Returns an empty string
     * or a given default value if key does not exist.
104 105 106 107
     *
     * If a device is marked as variant, and the requested key exists in a
     * dedicated device section the key from the device section will get
     * returned, otherwise the one from the variant.
108
     */
109
    QVariant value(const QString &key, const QVariant &value = QVariant());
110

111

112
private:
113
    SsuSettings *boardMappings;
114
    QString cachedFamily, cachedModel, cachedVariant;
115 116

    void clearCache();
117 118 119 120 121

    /**
     * Return a map of key, value pairs parsed from /etc/hw-release
     */
    QMap<QString, QString> hwRelease();
122 123
};
#endif