diff options
| author | Andrew Branson <andrew.branson@jolla.com> | 2026-04-03 22:55:30 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@jolla.com> | 2026-04-04 11:55:25 +0200 |
| commit | a35c9fa159173388d88ef77e1d31f53488aad094 (patch) | |
| tree | e4691b5bbf054ca13e35d98d9df653bf9cdc0054 /settings/accounts/ui/FediverseSettingsDisplay.qml | |
| parent | 5f999f7a4712c4a4d1c89054b544064cfd4b769e (diff) | |
Generalize for all fediverse accounts
Diffstat (limited to 'settings/accounts/ui/FediverseSettingsDisplay.qml')
| -rw-r--r-- | settings/accounts/ui/FediverseSettingsDisplay.qml | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/settings/accounts/ui/FediverseSettingsDisplay.qml b/settings/accounts/ui/FediverseSettingsDisplay.qml new file mode 100644 index 0000000..7494460 --- /dev/null +++ b/settings/accounts/ui/FediverseSettingsDisplay.qml @@ -0,0 +1,181 @@ +/* + * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import Sailfish.Accounts 1.0 +import com.jolla.settings.accounts 1.0 +import com.jolla.settings.accounts.fediverse 1.0 +import org.nemomobile.configuration 1.0 + +StandardAccountSettingsDisplay { + id: root + + settingsModified: true + property bool postsServiceEnabled: false + property string instanceTitle: { + var value = root.account.configurationValues("")["instance/Title"] + return value ? value.toString().trim() : "" + } + + function refreshDescriptionEditor() { + var description = root.account.configurationValues("")["description"] + var descriptionValue = description ? description.toString().trim() : "" + var credentialsUserName = root.account.defaultCredentialsUserName + ? root.account.defaultCredentialsUserName.toString().trim() + : "" + if (descriptionValue.length > 0 && credentialsUserName !== descriptionValue) { + root.account.setConfigurationValue("", "default_credentials_username", descriptionValue) + } + + // Reuse the standard "Description" field as the account handle editor. + if (descriptionValue.length > 0) { + root.account.displayName = descriptionValue + } else if (credentialsUserName.length > 0) { + root.account.displayName = credentialsUserName + } else { + root.account.displayName = "" + } + } + + function _providerDisplayName() { + if (instanceTitle.length > 0) { + return instanceTitle + } + + var providerDisplayName = root.accountProvider && root.accountProvider.displayName + ? root.accountProvider.displayName.toString().trim() + : "" + return providerDisplayName.length > 0 ? providerDisplayName : qsTrId("settings-accounts-fediverse-la-provider_name") + } + + onAboutToSaveAccount: { + settingsLoader.updateAllSyncProfiles() + + var storedDescriptionValue = root.account.configurationValues("")["description"] + var storedDescription = storedDescriptionValue ? storedDescriptionValue.toString().trim() : "" + var storedCredentialsUserName = root.account.defaultCredentialsUserName + ? root.account.defaultCredentialsUserName.toString().trim() + : "" + var editedDescription = root.account.displayName + ? root.account.displayName.toString().trim() + : "" + var providerDisplayName = _providerDisplayName() + if (editedDescription === providerDisplayName) { + // Avoid clobbering stored handle if displayName temporarily reverts to provider name. + editedDescription = storedDescription.length > 0 ? storedDescription : storedCredentialsUserName + } + + if (storedDescription !== editedDescription) { + root.account.setConfigurationValue("", "description", editedDescription) + } + + if (storedCredentialsUserName !== editedDescription) { + root.account.setConfigurationValue("", "default_credentials_username", editedDescription) + } + + // Keep account list title fixed to the discovered instance title. + root.account.displayName = providerDisplayName + + if (eventsSyncSwitch.checked !== root.account.configurationValues("")["FeedViewAutoSync"]) { + root.account.setConfigurationValue("", "FeedViewAutoSync", eventsSyncSwitch.checked) + } + } + + StandardAccountSettingsLoader { + id: settingsLoader + account: root.account + accountProvider: root.accountProvider + accountManager: root.accountManager + autoEnableServices: root.autoEnableAccount + + onSettingsLoaded: { + syncServicesRepeater.model = syncServices + otherServicesDisplay.serviceModel = otherServices + + refreshDescriptionEditor() + + var autoSync = root.account.configurationValues("")["FeedViewAutoSync"] + var isNewAccount = root.autoEnableAccount + eventsSyncSwitch.checked = (isNewAccount || autoSync === true) + } + } + + Column { + id: syncServicesDisplay + width: parent.width + + SectionHeader { + //: Options for data to be downloaded from a remote server + //% "Download" + text: qsTrId("settings-accounts-la-download_options") + } + + Repeater { + id: syncServicesRepeater + TextSwitch { + checked: model.enabled + text: model.serviceName === "fediverse-microblog" + //% "Posts" + ? qsTrId("settings-accounts-fediverse-la-service_posts") + : (model.serviceName === "fediverse-notifications" + //% "Notifications" + ? qsTrId("settings-accounts-fediverse-la-service_notifications") + : model.displayName) + description: model.serviceName === "fediverse-microblog" + //% "Show Fediverse posts in the Events view." + ? qsTrId("settings-accounts-fediverse-la-service_posts_description") + : (model.serviceName === "fediverse-notifications" + //% "Show Fediverse notifications." + ? qsTrId("settings-accounts-fediverse-la-service_notifications_description") + : "") + visible: text.length > 0 + onCheckedChanged: { + if (model.serviceName === "fediverse-microblog") { + root.postsServiceEnabled = checked + } + if (checked) { + root.account.enableWithService(model.serviceName) + } else { + root.account.disableWithService(model.serviceName) + } + } + } + } + + TextSwitch { + id: eventsSyncSwitch + + //% "Sync Fediverse feed automatically" + text: qsTrId("settings-accounts-fediverse-la-auto_sync_feed") + //% "Fetch new posts periodically when browsing Events Fediverse feed." + description: qsTrId("settings-accounts-fediverse-la-auto_sync_feed_description") + enabled: root.postsServiceEnabled + + onCheckedChanged: { + autoSyncConf.value = checked + } + } + } + + ConfigurationValue { + id: autoSyncConf + key: "/desktop/lipstick-jolla-home/events/auto_sync_feeds/" + root.account.identifier + } + + AccountServiceSettingsDisplay { + id: otherServicesDisplay + enabled: root.accountEnabled + + onUpdateServiceEnabledStatus: { + if (enabled) { + root.account.enableWithService(serviceName) + } else { + root.account.disableWithService(serviceName) + } + } + } +} |
