summaryrefslogtreecommitdiff
path: root/settings/accounts/ui/mastodon-settings.qml
blob: c66cbb7e2dc1e38a82894318f6940aca7cf0544e (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
/*
 * Copyright (C) 2013-2026 Jolla Ltd.
 */

import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.Accounts 1.0
import com.jolla.settings.accounts 1.0

AccountSettingsAgent {
    id: root

    property string accountSubtitle: {
        var description = account.configurationValues("")["description"]
        var detail = description ? description.toString().trim() : ""
        if (detail.length > 0) {
            return detail
        }
        var apiHost = account.configurationValues("")["api/Host"]
        var host = apiHost ? apiHost.toString().trim() : ""
        host = host.replace(/^https?:\/\//i, "")
        var pathSeparator = host.indexOf("/")
        if (pathSeparator !== -1) {
            host = host.substring(0, pathSeparator)
        }
        if (host.length > 0) {
            return host
        }
        var displayName = account.displayName ? account.displayName.toString().trim() : ""
        if (displayName.length > 0) {
            return displayName
        }
        return host
    }

    Account {
        id: account
        identifier: root.accountId
    }

    initialPage: Page {
        onStatusChanged: {
            if (status === PageStatus.Active && !credentialsUpdater.running) {
                settingsDisplay.refreshDescriptionEditor()
            }
        }

        onPageContainerChanged: {
            if (pageContainer == null && !credentialsUpdater.running) {
                root.delayDeletion = true
                settingsDisplay.saveAccount()
            }
        }

        Component.onDestruction: {
            if (status == PageStatus.Active) {
                settingsDisplay.saveAccount(true)
            }
        }

        AccountCredentialsUpdater {
            id: credentialsUpdater
        }

        SilicaFlickable {
            anchors.fill: parent
            contentHeight: header.height + settingsDisplay.height + Theme.paddingLarge

            StandardAccountSettingsPullDownMenu {
                visible: settingsDisplay.accountValid
                allowSync: true
                onCredentialsUpdateRequested: {
                    credentialsUpdater.replaceWithCredentialsUpdatePage(root.accountId)
                }
                onAccountDeletionRequested: {
                    root.accountDeletionRequested()
                    pageStack.pop()
                }
                onSyncRequested: {
                    settingsDisplay.saveAccountAndSync()
                }
            }

            PageHeader {
                id: header
                title: root.accountsHeaderText
                description: root.accountSubtitle
            }

            MastodonSettingsDisplay {
                id: settingsDisplay
                anchors.top: header.bottom
                accountManager: root.accountManager
                accountProvider: root.accountProvider
                accountId: root.accountId

                onAccountSaveCompleted: {
                    root.delayDeletion = false
                }
            }

            VerticalScrollDecorator {}
        }
    }
}