~mardy/owncloud-app/test-se

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
 * Copyright: 2014 Daniel Holm, <d.holmen@gmail.com>
 *
 * This file is part of ownCloud app
 *
 * reminders is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * reminders is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import Ubuntu.Components 1.1
import Ubuntu.Components.Popups 0.1
import Ubuntu.Components.ListItems 1.0 as ListItem
import Ubuntu.OnlineAccounts 0.1
import Ubuntu.OnlineAccounts.Client 0.1
import U1db 1.0 as U1db
import Ubuntu.Web 0.2
import "owncloud.js" as OwnCloud
//import "components"

/*!
    \brief MainView with a Label and Button elements.
*/

MainView {
    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "mainView"

    // Note! applicationName needs to match the "name" field of the click manifest
    applicationName: "com.ubuntu.developer.danielholm.owncloud-app"

    /*
     This property enables the application to change orientation
     when the device is rotated. The default is false.
    */
    //automaticOrientation: true

    width: units.gu(100)
    height: units.gu(75)

    useDeprecatedToolbar: false

    // VARIABLES
    property string defaultURL: "http://owncloud.org"
    property int developerMode: 1

    // get username, pass and server from Online accounts

    // use it
    //OwnCloud.login(server,user,password,callback)

    // GENERAL FUNCTIONS
    function newURL(url) {
        if (url){
            url = checkURL(url) // but does it have http(s)
            // save the new url in the preferences
            ocURLDocument.contents = {"ocURL": url}
            // reload the webview with the new url
            dasWWW.url = url
            console.debug("URL is changed to: "+url)
        }
        else {
            dasWWW.url = url // reload anyway
            console.debug("No change to URL")
        }
    }

    function getContent(fieldName){
           var tempContents = {};
           tempContents = ocURLDocument.contents
           return tempContents[fieldName]
    }

    // check host url for http
    function checkURL(url) {
        // if the URL doesn't contain HTTP(S) then add it!
        if (url.indexOf('http') >= 0) {
            return url;
        }
        else {
            console.debug("Debug: added http")
            return 'http://'+url
        }
    }

    // U1DB

    // DB to store the preferences in
    U1db.Database {
        id: ocappDB
        path: "ownCloudDatabase"
    }

    // document to save the URL in
    U1db.Document {
        id: ocURLDocument
        create: true
        database: ocappDB
        docId: "ocURLDocument"
        defaults: { "ocURL": defaultURL }
    }

    function doLogin() {
        print("Debug: Got accounts:", accounts.count)

        // test if there is some ownCloud with permission for us (until the account plugin is in, this checks for default owncloud url)
        // No? Crap, ok, show dialog
        if (getContent('ocURL') === defaultURL || developerMode === 1) {
            PopupUtils.open(noAccountDialog)
        }
        // yes? cool, let's go.
        else {
            // oh, nothing yet, just load the url
        }
    }

    AccountServiceModel {
        id: accounts
        applicationId: "com.ubuntu.developer.danielholm.owncloud-app"
        //service: "owncloud"
    }

    AccountService {
        id: accountService
        onObjectHandleChanged: {
        }
        onAuthenticated: {
        }
        onAuthenticationError: {
            console.log("Authentication failed, code " + error.code)
        }
    }

    Component.onCompleted: {
        doLogin();
    }

    PageStack {
            id: pageStack

            Component.onCompleted: {
                push(dasWeb)
            }

            Page {
                title: "ownCloud"
                id: dasWeb // I believe "das" is "the" in german, but what do I know, I'm Swedish
                visible: false

                Column {
                    anchors.fill: parent

                    WebView {
                        id: dasWWW
                        anchors.fill: parent
                        url: getContent('ocURL')
                        fullscreen: true
                    }
                }
            }
        }

    Component {
           id: noAccountDialog
           Dialog {
               id: noAccount
               objectName: "noAccountDialog"
               title: i18n.tr("No account available")
               text: i18n.tr("Please setup an account in the system settings")

               Connections {
                   target: accounts
                   onCountChanged: {
                       if (accounts.count == 1) {
                           PopupUtils.close(noAccount)
                           doLogin();
                       }
                   }
               }

               Setup {
                   id: setup
                   applicationId: "com.ubuntu.developer.danielholm.owncloud-app"
                   providerId: "owncloud"
               }

               Button {
                   objectName: "openAccountButton"
                   text: i18n.tr("Add account")
                   enabled: developerMode === 1
                   color: UbuntuColors.orange
                   onClicked: {
                       console.debug("Debug: Open account auth")
                       setup.exec()
                   }
               }
/*
               Button {
                   objectName: "openAccount2"
                   text: i18n.tr("Accounts")
                   enabled: developerMode === 1
                   color: UbuntuColors.orange
                   onClicked: {
                       console.debug("Debug: Open accounts list")
                       PopupUtils.close(noAccount)
                       PopupUtils.open(accountDialog)
                   }
               }*/

               Button {
                   objectName: "openURLButton"
                   text: i18n.tr("Enter URL")
                   color: UbuntuColors.orange
                   onClicked: {
                       PopupUtils.close(noAccount)

                       // update url in urlField
                       //urlField.text = getContent('ocURL');

                       PopupUtils.open(ocURLDialog)
                   }
               }
           }
      }

    /*
    Component {
           id: accountDialog
           Dialog {
               id: accountDetails
               objectName: "AccountDialog"
               title: i18n.tr("ownCloud Accounts")
               text: i18n.tr("List of available ownCloud accounts")

               AccountServiceModel {
                   id: accounts2
                   applicationId: "com.ubuntu.developer.danielholm.owncloud-app"
                 }

                 Setup {
                   id: setup2
                   applicationId: accounts2.applicationId
                   providerId: "owncloud"
                 }

                 ListView {
                   model: accounts2
                   delegate: Text { text: "Account: " + model.displayName }
                 }

                 Button {
                   text: "Authorize a ownCloud account"
                   onClicked: setup2.exec()
                 }

               Button {
                   text: i18n.tr("Cancel")
                   color: UbuntuColors.silver
                   onClicked: {
                       PopupUtils.close(accountDetails)
                   }
               }
           }
      } */

    Component {
           id: ocURLDialog
           Dialog {
               id: urlDetails
               objectName: "urlAccountDialog"
               title: i18n.tr("ownCloud URL")
               text: i18n.tr("Please enter the URL of your ownCloud installation")

               Connections {
                   target: accounts
                   onCountChanged: {
                       if (accounts.count == 1) {
                           PopupUtils.close(noAccount)
                           doLogin();
                       }
                   }
               }

               TextField {
                   id: urlField
                   placeholderText: defaultURL
                   text: getContent('ocURL');
                   width: parent.width
                   inputMethodHints: Qt.ImhUrlCharactersOnly
                   // if there is a "s" in "https" check the checkbox
               }

               Button {
                   text: i18n.tr("Done")
                   color: "green"
                   onClicked: {
                       // Save all the beers
                       PopupUtils.close(urlDetails)
                       newURL(urlField.text);
                   }
               }

               Button {
                   text: i18n.tr("Cancel")
                   color: UbuntuColors.silver
                   onClicked: {
                       PopupUtils.close(urlDetails)
                       PopupUtils.open()
                   }
               }
           }
      }
}