summaryrefslogtreecommitdiff
path: root/settings/accounts/ui/MastodonSettingsDisplay.qml
blob: 61e9f1210798011335d0ff244975f23a4f0d9e8f (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
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.Accounts 1.0
import com.jolla.settings.accounts 1.0
import org.nemomobile.configuration 1.0

StandardAccountSettingsDisplay {
    id: root

    settingsModified: true

    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() {
        var providerDisplayName = root.accountProvider && root.accountProvider.displayName
                ? root.accountProvider.displayName.toString().trim()
                : ""
        return providerDisplayName.length > 0 ? providerDisplayName : "Mastodon"
    }

    onAboutToSaveAccount: {
        settingsLoader.updateAllSyncProfiles()

        var editedDescription = root.account.displayName
                ? root.account.displayName.toString().trim()
                : ""
        var providerDisplayName = _providerDisplayName()
        if (editedDescription === providerDisplayName) {
            editedDescription = ""
        }

        var storedDescriptionValue = root.account.configurationValues("")["description"]
        var storedDescription = storedDescriptionValue ? storedDescriptionValue.toString().trim() : ""
        if (storedDescription !== editedDescription) {
            root.account.setConfigurationValue("", "description", editedDescription)
        }

        var storedCredentialsUserName = root.account.defaultCredentialsUserName
                ? root.account.defaultCredentialsUserName.toString().trim()
                : ""
        if (storedCredentialsUserName !== editedDescription) {
            root.account.setConfigurationValue("", "default_credentials_username", editedDescription)
        }

        // Keep account list title fixed to provider name.
        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.displayName
                visible: text.length > 0
                onCheckedChanged: {
                    if (checked) {
                        root.account.enableWithService(model.serviceName)
                    } else {
                        root.account.disableWithService(model.serviceName)
                    }
                }
            }
        }

        TextSwitch {
            id: eventsSyncSwitch

            text: "Sync Mastodon feed automatically"
            description: "Fetch new posts periodically when browsing Events Mastodon feed."

            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)
            }
        }
    }
}