diff options
Diffstat (limited to 'settings/accounts')
| -rw-r--r-- | settings/accounts/ui/fediverse.qml | 92 |
1 files changed, 72 insertions, 20 deletions
diff --git a/settings/accounts/ui/fediverse.qml b/settings/accounts/ui/fediverse.qml index 3f5968a..b29e68e 100644 --- a/settings/accounts/ui/fediverse.qml +++ b/settings/accounts/ui/fediverse.qml @@ -88,6 +88,7 @@ AccountCreationAgent { return { "apiHost": normalizedApiHost, "oauthHost": oauthHost(normalizedApiHost), + //% "Fediverse" "instanceTitle": title.length > 0 ? title : qsTrId("settings-accounts-fediverse-la-provider_name"), "instanceDescription": "", "instanceIconUrl": "", @@ -130,24 +131,70 @@ AccountCreationAgent { return "" } - if (responseData.thumbnail) { - if (typeof responseData.thumbnail === "string") { - return _normalizeResourceUrl(responseData.thumbnail, apiHost) - } - if (responseData.thumbnail.url) { - return _normalizeResourceUrl(responseData.thumbnail.url, apiHost) + function normalizedIconUrl(candidate) { + return _normalizeResourceUrl(_trimmedString(candidate), apiHost) + } + + function iconScore(iconObject) { + var size = _trimmedString(iconObject && iconObject.size) + var match = size.match(/^(\d+)x(\d+)$/) + if (!match) { + return 1000000 } - if (responseData.thumbnail.static_url) { - return _normalizeResourceUrl(responseData.thumbnail.static_url, apiHost) + + var width = parseInt(match[1], 10) + var height = parseInt(match[2], 10) + if (!(width > 0) || !(height > 0)) { + return 1000000 } + + var area = width * height + var squarenessPenalty = Math.abs(width - height) * 1000 + var sizePenalty = Math.abs(Math.max(width, height) - 64) + return squarenessPenalty + sizePenalty + area } if (responseData.icon) { if (typeof responseData.icon === "string") { - return _normalizeResourceUrl(responseData.icon, apiHost) + return normalizedIconUrl(responseData.icon) + } + + if (responseData.icon.src) { + return normalizedIconUrl(responseData.icon.src) + } + + if (responseData.icon.length > 0) { + var bestIndex = -1 + var bestScore = Number.MAX_VALUE + for (var i = 0; i < responseData.icon.length; ++i) { + var candidate = responseData.icon[i] + var candidateUrl = normalizedIconUrl(candidate && candidate.src) + if (candidateUrl.length === 0) { + continue + } + + var score = iconScore(candidate) + if (score < bestScore) { + bestScore = score + bestIndex = i + } + } + + if (bestIndex >= 0) { + return normalizedIconUrl(responseData.icon[bestIndex].src) + } } - if (responseData.icon.url) { - return _normalizeResourceUrl(responseData.icon.url, apiHost) + } + + if (responseData.thumbnail) { + if (typeof responseData.thumbnail === "string") { + return normalizedIconUrl(responseData.thumbnail) + } + if (responseData.thumbnail.url) { + return normalizedIconUrl(responseData.thumbnail.url) + } + if (responseData.thumbnail.static_url) { + return normalizedIconUrl(responseData.thumbnail.static_url) } } @@ -192,6 +239,7 @@ AccountCreationAgent { } if (xhr.status < 200 || xhr.status >= 300) { + //% "Failed to register the Fediverse application for %1" _showRegistrationError(qsTrId("settings-accounts-fediverse-la-register_app_failed").arg(context.apiHost), busyPage) return } @@ -200,11 +248,13 @@ AccountCreationAgent { try { response = JSON.parse(xhr.responseText) } catch (err) { + //% "Invalid response while registering the Fediverse application" _showRegistrationError(qsTrId("settings-accounts-fediverse-la-invalid_app_registration_response"), busyPage) return } if (!response.client_id || !response.client_secret) { + //% "Fediverse application registration did not return client credentials" _showRegistrationError(qsTrId("settings-accounts-fediverse-la-app_registration_missing_credentials"), busyPage) return } @@ -215,6 +265,7 @@ AccountCreationAgent { } var postData = [] + //% "SailfishOS Fediverse" postData.push("client_name=" + encodeURIComponent(qsTrId("settings-accounts-fediverse-la-client_name"))) postData.push("redirect_uris=" + encodeURIComponent(callbackUri)) postData.push("scopes=" + encodeURIComponent("read write")) @@ -358,6 +409,7 @@ AccountCreationAgent { _goToSettings(accountId) }) _accountSetup.error.connect(function() { + //% "Failed to finish Fediverse account setup" accountCreationError(qsTrId("settings-accounts-fediverse-la-account_setup_failed")) }) } @@ -427,6 +479,7 @@ AccountCreationAgent { width: parent.width - promptIcon.width - parent.spacing wrapMode: Text.Wrap color: Theme.highlightColor + //% "Enter the server address, then sign in." text: qsTrId("settings-accounts-fediverse-la-enter_server_then_sign_in") } } @@ -435,6 +488,7 @@ AccountCreationAgent { id: instanceField x: Theme.horizontalPageMargin width: parent.width - x * 2 + //% "Server" label: qsTrId("settings-accounts-fediverse-la-server") placeholderText: root.defaultServerHost inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhUrlCharactersOnly @@ -451,6 +505,7 @@ AccountCreationAgent { Component { id: busyComponent AccountBusyPage { + //% "Preparing Fediverse sign-in..." busyDescription: qsTrId("settings-accounts-fediverse-la-preparing_sign_in") onStatusChanged: { if (status === PageStatus.Active && root._pendingApiHost.length > 0) { @@ -532,6 +587,7 @@ AccountCreationAgent { function _effectiveInstanceTitle() { var title = root._trimmedString(instanceTitle) + //% "Fediverse" return title.length > 0 ? title : qsTrId("settings-accounts-fediverse-la-provider_name") } @@ -542,10 +598,6 @@ AccountCreationAgent { function _applyIconPath(iconPath) { instanceIconPath = iconPath newAccount.setConfigurationValue("", "iconPath", _effectiveIconPath()) - var services = _serviceNames() - for (var i = 0; i < services.length; ++i) { - newAccount.setConfigurationValue(services[i], "iconPath", _effectiveIconPath()) - } if (hasConfigured) { newAccount.sync() } @@ -580,7 +632,11 @@ AccountCreationAgent { } for (var i = 0; i < services.length; ++i) { - var service = services[i] + newAccount.enableWithService(services[i]) + } + + for (var j = 0; j < services.length; ++j) { + var service = services[j] newAccount.setConfigurationValue(service, "api/Host", apiHost) newAccount.setConfigurationValue(service, "auth/oauth2/web_server/Host", oauthHost) newAccount.setConfigurationValue(service, "auth/oauth2/web_server/AuthPath", "oauth/authorize") @@ -592,10 +648,6 @@ AccountCreationAgent { newAccount.setConfigurationValue(service, "auth/oauth2/web_server/ClientSecret", clientSecret) } - for (var j = 0; j < services.length; ++j) { - newAccount.enableWithService(services[j]) - } - if (instanceIconUrl.length > 0 && instanceIconPath.length === 0) { instanceIconCache.cacheIcon(apiHost, instanceIconUrl) } |
