~zhangew401/scope-aggregator/fix-empty-query-to-clickstore

« back to all changes in this revision

Viewing changes to src/utils.cpp

Tags: 4.11
This is the 4.11 release. 

There are two main changes, both related to the quick start help (local hints).

CHANGE 1
========

Currently there are two types of quick start help results:

* A login result specific to a child scope. Now, if the child scope
is not installed, the login result is not displayed.

* A button that takes the user to settings > accounts for a specific account
(for example Google) but not for any particular child scope/app. To suppress
these results in parts of the world where they are not appropriate, you
now modify hints.json for the item to specifically state the locales (ll_CC)
in which the result should NOT display. For example, the following
supresses display of Google account result in zh_CN locale:
    "items": [
        {
            "hide_in_locales": "zh_CN",
            "_title": "<b>   Review your Google sync settings</b>",
            "_description": "Adding you Google....",
            "art":"icons/today/google.png",
            "action": {
                "_name": "Add account",
                "uri": "settings:///system/online-accounts"
            }
        }
    ]

CHANGE 2
========

Apparently 15.04.4 introduces an online accounts change that requireis a
different ServiceName (used to create an online account client).

* Previously the ServiceName was just the fully qualified scope ID, for
example: com.canonical.scopes.fbphotos_fbphotos

* With 15.04.4, the ServiceName also requires the provider, for example:
com.canonical.scopes.fbphotos_fbphotos_facebook ('facebook' is the provider)

Aggregator scopes whose quick start help provides a login button for
child scopes that are updated to 15.04.4 online accounts *must* change
the ServiceName for the specific result in the hints.json file to include
the provider.

For example, facebook photos 1.32 uses online accounts 15.04.4. photos-scope
hints.json is now (note ServiceName includes provider ("faceboook") at the end:
        "items": [
            {
                "_title": "<b>   Add your account</b>",
                "art": "facebook.png",
                "oaccount": {
                    "ServiceName": "com.canonical.scopes.fbphotos_fbphotos_facebook",
                    "ServiceType": "com.canonical.scopes.fbphotos_fbphotos",
                    "ProviderName": "facebook",
                    "QueryScope": "com.canonical.scopes.fbphotos_fbphotos",
                    "_loggedin": "<b>   Successfully logged in</b>"
                },
                "action": {
                    "_name": "Add account",
                    "uri": "settings:///system/online-accounts"
                }
            }
        ]


Previoulsy (before facebook photos scope switched to 15.04.4 online accounts) the 
ServiceName was only the fully qualified scope ID:
                "ServiceName": "com.canonical.scopes.fbphotos_fbphotos",

Show diffs side-by-side

added added

removed removed

Lines of Context:
1231
1231
            res["subtitle"] = _(sstr(res_[QStringLiteral("_subtitle")].toString()).c_str());
1232
1232
            res["description"] = _(sstr(res_[QStringLiteral("_description")].toString()).c_str());
1233
1233
            std::string uri = "http://www.ubuntu.com";
 
1234
            if (res_.contains(QStringLiteral("hide_in_locales")))
 
1235
            {
 
1236
                QStringList hide_in_locales = res_[QStringLiteral("hide_in_locales")].toString().split(",");
 
1237
                std::string lcRaw = setlocale(LC_ALL, ""); 
 
1238
                std::string lc_lang = lcRaw.size() > 5 ? lcRaw.substr(0, 2) : "";
 
1239
                std::string lc_country  = lcRaw.size() > 5 ? lcRaw.substr(3, 2) : "";
 
1240
                std::string lc = lc_lang + "_" + lc_country;
 
1241
                if (hide_in_locales.contains(qstr(lc)))
 
1242
                {
 
1243
                    continue;
 
1244
                }
 
1245
            }
1234
1246
            if (res_.contains("uri"))
1235
1247
            {
1236
1248
                uri = sstr(res_["uri"].toString());
1255
1267
                auto oaccount = res_[QStringLiteral("oaccount")].toObject();
1256
1268
                auto queryScope = sstr(oaccount[QStringLiteral("QueryScope")].toString());
1257
1269
 
1258
 
                us::OnlineAccountClient oa_client(sstr(oaccount[QStringLiteral("ServiceName")].toString()),
 
1270
                // before framework 15.0.4.4 the service name is the FQ scope id and contains one "_"
 
1271
                // with 15.04.4, it is FQ scope id += _PROVIDER
 
1272
                // we also want the fully qualified scope id to check with registry if it is installed.
 
1273
                // to support both cases:
 
1274
                QStringList parts = oaccount[QStringLiteral("ServiceName")].toString().split("_");
 
1275
                QString provider = oaccount[QStringLiteral("ProviderName")].toString();
 
1276
                QString sc_id = parts[0] + "_" + parts[1];
 
1277
                QString id = sc_id;
 
1278
                if (parts.size() > 2) // framework 15.04.4 or higher 
 
1279
                {
 
1280
                    id += "_" + provider;
 
1281
                }
 
1282
                us::OnlineAccountClient oa_client(sstr(id),
1259
1283
                                                  sstr(oaccount[QStringLiteral("ServiceType")].toString()),
1260
 
                                                  sstr(oaccount[QStringLiteral("ProviderName")].toString()));
 
1284
                                                  sstr(provider));
1261
1285
                bool alreadyLoggedIn = false;
1262
1286
                oa_client.refresh_service_statuses();
1263
 
                auto vectoraccounts = oa_client.get_service_statuses();
1264
1287
                for (auto const& status : oa_client.get_service_statuses())
1265
1288
                {
1266
1289
                    if (status.service_enabled)
1269
1292
                        break;
1270
1293
                    }
1271
1294
                }
 
1295
                // do not display quick start help for scopes that are not registered in the system
 
1296
                auto reg_scopes = registry_->list();
 
1297
                us::MetadataMap::const_iterator scope_it;
 
1298
                scope_it = reg_scopes.find(sstr(sc_id));
 
1299
                if (scope_it == reg_scopes.end()) {
 
1300
                    qWarning () << QString("%1: OA scope is NOT REGISTERED, skipping for HINTS: %2").arg(oaccount[QStringLiteral("ServiceName")].toString());
 
1301
                    continue;
 
1302
                }
1272
1303
                if (alreadyLoggedIn) {
1273
1304
                    //the hints code does this when the person is already logged in to the service.
1274
1305
                    //auto tmp = oaccount["_loggedin"].toString().toStdString();