summaryrefslogtreecommitdiff
path: root/rockworkd/libpebble/appinfo.cpp
blob: 4aeeeb7c274f5be950225387cde399243bde4b4a (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
#include <QSharedData>
#include <QBuffer>
#include <QDir>
#include <QJsonDocument>
#include <QUuid>
#include "appinfo.h"
#include "watchdatareader.h"
#include "pebble.h"

namespace {
struct ResourceEntry {
    int index;
    quint32 offset;
    quint32 length;
    quint32 crc;
};
}

AppInfo::AppInfo(const QString &path):
    Bundle(path)
{
    if (path.isEmpty()) {
        return;
    }

    QFile f(path + "/appinfo.json");
    if (!f.open(QFile::ReadOnly)) {
        qWarning() << "Error opening appinfo.json";
        return;
    }

    QJsonParseError error;
    QJsonDocument jsonDoc = QJsonDocument::fromJson(f.readAll(), &error);
    if (error.error != QJsonParseError::NoError) {
        qWarning() << "Error parsing appinfo.json";
        return;
    }

    m_storeId = path.split("/").last();

    QVariantMap map = jsonDoc.toVariant().toMap();

    m_uuid = map.value("uuid").toUuid();
    m_shortName = map.value("shortName").toString();
    m_longName = map.value("longName").toString();
    m_companyName = map.value("companyName").toString();
    m_versionCode = map.value("versionCode").toInt();
    m_versionLabel = map.value("versionLabel").toString();
    m_capabilities = 0;

    m_isWatchface = map.value("watchapp").toMap().value("watchface").toBool();

    if (map.contains("appKeys")) {
        QVariantMap appKeyMap = map.value("appKeys").toMap();
        foreach (const QString &key, appKeyMap.keys()) {
            m_appKeys.insert(key, appKeyMap.value(key).toInt());
        }
    }

    if (map.contains("capabilities")) {
        QList<QVariant> capabilities = map.value("capabilities").toList();

        foreach (const QVariant &value, capabilities) {
            QString capability = value.toString();
            if (capability == "location") {
                m_capabilities |= Location;
            }
            else if (capability == "configurable") {
                m_capabilities |= Configurable;
            }
        }
    }

    QFile jsApp(path + "/pebble-js-app.js");
    m_isJsKit = jsApp.exists();
}

AppInfo::AppInfo(const QUuid &uuid, bool isWatchFace, const QString &name, const QString &vendor, bool hasSettings):
    m_uuid(uuid),
    m_shortName(name),
    m_companyName(vendor),
    m_capabilities(hasSettings ? Configurable : None),
    m_isWatchface(isWatchFace),
    m_isSystemApp(true)
{

}


AppInfo::~AppInfo()
{}


bool AppInfo::isValid() const
{
    return !m_uuid.isNull();
}

QUuid AppInfo::uuid() const
{
    return m_uuid;
}

QString AppInfo::storeId() const
{
    return m_storeId;
}

QString AppInfo::shortName() const
{
    return m_shortName;
}

QString AppInfo::longName() const
{
    return m_longName;
}

QString AppInfo::companyName() const
{
    return m_companyName;
}

int AppInfo::versionCode() const
{
    return m_versionCode;
}

QString AppInfo::versionLabel() const
{
    return m_versionLabel;
}

bool AppInfo::isWatchface() const
{
    return m_isWatchface;
}

bool AppInfo::isJSKit() const
{
    return m_isJsKit;
}

bool AppInfo::isSystemApp() const
{
    return m_isSystemApp;
}

QHash<QString, int> AppInfo::appKeys() const
{
    return m_appKeys;
}

bool AppInfo::hasSettings() const
{
    return (m_capabilities & Configurable);
}

AppInfo::Capabilities AppInfo::capabilities() const
{
    return m_capabilities;
}