QVariantList DBusPebble::InstalledApps() const
{
    QVariantList list;
    foreach (const QUuid &appId, m_pebble->installedAppIds()) {
        QVariantMap app;
        AppInfo info = m_pebble->appInfo(appId);
        app.insert("storeId", info.storeId());
        app.insert("name", info.shortName());
        app.insert("vendor", info.companyName());
        app.insert("watchface", info.isWatchface());
        app.insert("version", info.versionLabel());
        app.insert("uuid", info.uuid().toString());
        app.insert("hasSettings", info.hasSettings());
        app.insert("icon", info.path() + "/list_image.png");
        app.insert("systemApp", info.isSystemApp());

        list.append(app);
    }
    return list;
}
Beispiel #2
0
void AppDownloader::appJsonFetched()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(sender());
    reply->deleteLater();

    if (reply->error() != QNetworkReply::NoError) {
        qWarning() << "Error fetching App Json" << reply->errorString();
        return;
    }

    QJsonParseError error;
    QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
    if (error.error != QJsonParseError::NoError) {
        qWarning() << "Error parsing App Json" << error.errorString();
        return;
    }

    QVariantMap map = jsonDoc.toVariant().toMap();
    if (!map.contains("data") || map.value("data").toList().length() == 0) {
        qWarning() << "Unexpected json content:" << jsonDoc.toJson();
        return;
    }
    QVariantMap appMap = map.value("data").toList().first().toMap();
    QString pbwFileUrl = appMap.value("latest_release").toMap().value("pbw_file").toString();
    if (pbwFileUrl.isEmpty()) {
        qWarning() << "pbw file url empty." << jsonDoc.toJson();
        return;
    }

    QString appid = appMap.value("id").toString();
    QUuid quuid = appMap.value("uuid").toUuid();
    QDir dir;
    Pebble *p = (Pebble *)parent();
    if(p->installedAppIds().contains(quuid)) {
        AppInfo ai = p->appInfo(quuid);
        QString exId = ai.storeId();
        if(appid != exId && !dir.exists(m_storagePath+appid) && dir.exists(m_storagePath+exId)) {
            dir.rename(m_storagePath+exId,m_storagePath+appid);
        } else if(appid != exId) {
            qWarning() << "App exists but dir is out of sync:" << exId << "<!>" << appid;
        }
    } else {
        dir.mkpath(m_storagePath + appid);
    }

    QString iconFile = appMap.value("list_image").toMap().value("144x144").toString();
    QNetworkRequest request(iconFile);
    QNetworkReply *imageReply = m_nam->get(request);
    qDebug() << "fetching image" << iconFile;
    connect(imageReply, &QNetworkReply::finished, [this, imageReply, appid]() {
        imageReply->deleteLater();
        QString targetFile = m_storagePath + appid + "/list_image.png";
        qDebug() << "saving image to" << targetFile;
        QFile f(targetFile);
        if (f.open(QFile::WriteOnly)) {
            f.write(imageReply->readAll());
            f.close();
        }
    });
    appid += ("/v" + appMap.value("latest_release").toMap().value("version").toString() + ".pbw");
    fetchPackage(pbwFileUrl, appid);
}