~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
/*
 * 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

    // get usernae, pass and server from Online accounts

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

    // GENERAL FUNCTIONS
    function newURL(url) {
        // save the new url in the preferences
        ocURLDocument.contents = {"ocURL": url}

        // reload the webview with the new url
        dasWWW.url = url
    }

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

    // 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": "http://owncloud.org" }
    }

    // Online accounts stuff (copied from Reminders app: http://bazaar.launchpad.net/~reminders-app-dev/reminders-app/trunk/view/head:/src/app/qml/reminders.qml)

    property var accountPage;

    function openAccountPage(isChangingAccount) {
        if (accountPage) {
            accountPage.destroy(100)
        }
        var component = Qt.createComponent(Qt.resolvedUrl("ui/AccountSelector.qml"));
        accountPage = component.createObject(root, {accounts: accounts, isChangingAccount: isChangingAccount});
        accountPage.accountSelected.connect(function(handle) { accountService.objectHandle = handle; pagestack.pop(); });
        pagestack.push(accountPage);
    }

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

        // test if there is some ownCloud with permission for us

        // yes? cool, let's go.

        // No? Crap, ok, show dialog
        PopupUtils.open(noAccountDialog)
    }

    AccountServiceModel {
        id: accounts
        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)
            }

            /* I just remebered that this part should be in the plugin. Keeping it here until moved there..
            Page {
                id: firstRun
                title: i18n.tr("First run")
                visible: false
                Column {
                    anchors.fill: parent
                    TextField {
                        id: urlField
                        placeholderText: "URL"
                        width: parent.width
                        // if there is a "s" in "https" check the checkbox
                    }
                    TextField {
                        id: nameField
                        placeholderText: "username"
                        width: parent.width
                    }
                    TextField {
                        id: passField
                        placeholderText: "password"
                        echoMode: TextInput.Password
                        width: parent.width
                    }
                    CheckBox {
                        id: httpsCheck
                        text: "HTTPS" // doesnt show
                        checked: false
                        //onCheckedChanged: // when changed, add or remove the "s" from the URL
                    }
                    Button {
                            text: i18n.tr("Done")
                            width: parent.width
                            onClicked: {
                                print("clicked text-only Button")

                                // check if all is there

                                // if https, we might need to check the certificate, but maybe rather do that in the account plugin

                                // try to login using function
                                getAuth()

                                // if all works, save it (the settings)

                                // now push to the page that will show the website
                            }
                    }
                }
            }*/

            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")
                   color: UbuntuColors.orange
                   onClicked: setup.exec()
               }

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

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