~danielholm/account-plugin-owncloud/account-plugin-owncloud

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
import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.OnlineAccounts 0.1

Column {
    id: root

    property variant __account: account

    signal finished

    anchors.margins: units.gu(1)
    spacing: units.gu(2)

    Label {
        text: i18n.tr("URL:")

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.margins: parent.anchors.margins
    }

    TextField {
        id: urlField
        objectName: "urlField"
        placeholderText: i18n.tr("http://example.org")
        width: root.width - (2 * root.anchors.margins)
        anchors.left: parent.left
        anchors.margins: parent.anchors.margins
        focus: true

        inputMethodHints: Qt.ImhUrlCharactersOnly
    }

    Label {
        text: i18n.tr("Username:")

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.margins: parent.anchors.margins
    }

    TextField {
        id: usernameField
        objectName: "usernameField"
        placeholderText: i18n.tr("Your username")
        width: root.width - (2 * root.anchors.margins)
        anchors.left: parent.left
        anchors.margins: parent.anchors.margins

        KeyNavigation.tab: passwordField
    }

    Label {
        text: i18n.tr("Password:")

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.margins: parent.anchors.margins
    }

    TextField {
        id: passwordField
        objectName: "passwordField"
        placeholderText: i18n.tr("Your password")
        echoMode: TextInput.Password
        width: root.width - (2 * root.anchors.margins)
        anchors.left: parent.left
        anchors.margins: parent.anchors.margins

        inputMethodHints: Qt.ImhSensitiveData
    }

    Row {
        id: buttons
        height: units.gu(5)
        anchors.left: parent.left
        anchors.right: parent.right
        spacing: units.gu(1)
        Button {
            id: btnCancel
            objectName: "cancelButton"
            text: i18n.tr("Cancel")
            color: "#1c091a"
            height: parent.height
            width: (parent.width / 2) - 0.5 * parent.spacing
            onClicked: finished()
        }
        Button {
            id: btnContinue
            objectName: "continueButton"
            text: i18n.tr("Continue")
            color: "#cc3300"
            height: parent.height
            width: (parent.width / 2) - 0.5 * parent.spacing
            onClicked: {
                account.updateDisplayName(usernameField.text)

                creds.userName = usernameField.text
                creds.secret = passwordField.text
                creds.sync()
            }
        }
    }

    Credentials {
        id: creds
        caption: account.provider.id
        acl: "*" // untill later
        storeSecret: true
        onCredentialsIdChanged: root.credentialsStored()
    }

    AccountService {
        id: globalAccountSettings
        objectHandle: account.accountServiceHandle
        autoSync: false
    }

    function credentialsStored() {
        console.log("Credentials stored, id: " + creds.credentialsId)
        if (creds.credentialsId == 0) return

        globalAccountSettings.updateServiceEnabled(true)
        globalAccountSettings.credentials = creds
        globalAccountSettings.updateSettings({
            "host": checkURL(urlField.text)
        })
        account.synced.connect(finished)
        account.sync()
    }

    function checkURL(url) {
        // if the URL doesn't contain HTTP(S) then add it!
        if (url.indexOf('http') >= 0) {
            return 'http://'+urlField.text
        }
        else {
             return urlField.text
        }
    }

}