~ubuntu-branches/ubuntu/wily/unity-webapps-qml/wily-proposed

« back to all changes in this revision

Viewing changes to examples/facebook-share/unity-webapps-facebook/Share.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Ken VanDine, Alexandre Abreu
  • Date: 2014-06-26 01:48:37 UTC
  • mfrom: (1.1.33)
  • Revision ID: package-import@ubuntu.com-20140626014837-kdt1gvd2vnxfcrqx
Tags: 0.1+14.10.20140626.1-0ubuntu1
[ Ken VanDine ]
* add content share

[ Alexandre Abreu ]
* add content share

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012-2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtQuick.Window 2.0
 
19
import Ubuntu.Components 0.1
 
20
import Ubuntu.Components.ListItems 0.1 as ListItem
 
21
import Ubuntu.OnlineAccounts 0.1
 
22
 
 
23
Rectangle {
 
24
    id: root
 
25
    anchors.fill: parent
 
26
    color: Theme.palette.normal.background
 
27
    property string fileToShare
 
28
    property var callback
 
29
    property string serviceType: "webapps"
 
30
    property string provider: "facebook"
 
31
    property string userAccountId
 
32
    property string accessToken
 
33
    property var account
 
34
    signal accountSelected
 
35
    signal canceled()
 
36
    signal uploadCompleted(bool success)
 
37
 
 
38
    onUploadCompleted: {
 
39
        activitySpinner.visible = false;
 
40
        if (success)
 
41
            print ("Successfully posted");
 
42
        else
 
43
            print ("Failed to post");
 
44
    }
 
45
 
 
46
    AccountServiceModel {
 
47
        id: accounts
 
48
        serviceType: root.serviceType
 
49
        provider: root.provider
 
50
        Component.onCompleted: {
 
51
            if (count == 1) {
 
52
                srv.objectHandle = get(0, "accountServiceHandle");
 
53
            }
 
54
        }
 
55
    }
 
56
 
 
57
    AccountService {
 
58
        id: srv
 
59
        onObjectHandleChanged: {
 
60
            root.account = srv;
 
61
            root.account.authenticate(null);
 
62
        }
 
63
        onAuthenticated: {
 
64
            root.userAccountId = accountId;
 
65
            root.accessToken = reply.AccessToken;
 
66
            shareComponent.visible = true;
 
67
            sharemenu.visible = false;
 
68
        }
 
69
    }
 
70
 
 
71
 
 
72
    Rectangle {
 
73
        id: shareComponent
 
74
        objectName: "shareComponent"
 
75
        anchors.fill: parent
 
76
        color: Theme.palette.normal.background
 
77
        visible: false
 
78
 
 
79
        Column {
 
80
            anchors.fill: parent
 
81
            spacing: units.gu(1)
 
82
 
 
83
            Item {
 
84
                id: serviceHeader
 
85
                y: 0
 
86
                anchors.left: parent.left
 
87
                anchors.right: parent.right
 
88
                anchors.topMargin: units.gu(1)
 
89
                anchors.leftMargin: units.gu(1)
 
90
                anchors.rightMargin: units.gu(1)
 
91
                height: childrenRect.height
 
92
 
 
93
                ListItem.Subtitled {
 
94
                    anchors {
 
95
                        left: parent.left
 
96
                        right: parent.right
 
97
                    }
 
98
                    iconName: root.account.provider.iconName
 
99
                    text: root.account.provider.displayName
 
100
                    subText: root.account.displayName
 
101
                    showDivider: false
 
102
                }
 
103
            }
 
104
 
 
105
            ListItem.ThinDivider {}
 
106
 
 
107
            UbuntuShape {
 
108
                id: messageArea
 
109
                objectName: "messageArea"
 
110
                anchors.left: parent.left
 
111
                anchors.right: parent.right
 
112
                anchors.topMargin: units.gu(1)
 
113
                anchors.leftMargin: units.gu(1)
 
114
                anchors.rightMargin: units.gu(1)
 
115
 
 
116
                height: units.gu(20)
 
117
                color: "#f2f2f2"
 
118
 
 
119
                TextEdit {
 
120
                    id: message
 
121
                    color: "#333333"
 
122
                    anchors.top: parent.top
 
123
                    anchors.left: snapshot.right
 
124
                    anchors.bottom: parent.bottom
 
125
                    anchors.margins: units.gu(1)
 
126
                    wrapMode: Text.Wrap
 
127
                    width: parent.width - snapshot.width -
 
128
                           snapshot.anchors.margins * 2 -
 
129
                           message.anchors.leftMargin - message.anchors.rightMargin
 
130
                    clip: true
 
131
                    font.pixelSize: FontUtils.sizeToPixels("medium")
 
132
                    font.weight: Font.Light
 
133
                    focus: true
 
134
                }
 
135
 
 
136
                ActivityIndicator {
 
137
                    id: activitySpinner
 
138
                    anchors.centerIn: message
 
139
                    visible: false
 
140
                    running: visible
 
141
                }
 
142
 
 
143
                UbuntuShape {
 
144
                    id: snapshot
 
145
                    anchors.top: parent.top
 
146
                    anchors.left: parent.left
 
147
                    anchors.margins: units.gu(1)
 
148
                    width: units.gu(10)
 
149
                    height: units.gu(10)
 
150
 
 
151
                    image: Image {
 
152
                        source: fileToShare
 
153
                        sourceSize.height: snapshot.height
 
154
                        sourceSize.width: snapshot.width
 
155
                        fillMode: Image.PreserveAspectCrop
 
156
                    }
 
157
                }
 
158
            }
 
159
 
 
160
            Item {
 
161
                id: actionsBar
 
162
                anchors.left: parent.left
 
163
                anchors.right: parent.right
 
164
                anchors.topMargin: units.gu(2)
 
165
                anchors.leftMargin: units.gu(1)
 
166
                anchors.rightMargin: units.gu(1)
 
167
                height: childrenRect.height
 
168
 
 
169
                Button {
 
170
                    objectName: "cancelButton"
 
171
                    anchors.left: parent.left
 
172
                    text: i18n.dtr("ubuntu-ui-extras", "Cancel")
 
173
                    color: "#cccccc"
 
174
                    width: units.gu(10)
 
175
                    height: units.gu(4)
 
176
                    onClicked: canceled()
 
177
                }
 
178
 
 
179
                Button {
 
180
                    objectName: "postButton"
 
181
                    anchors.right: parent.right
 
182
                    anchors.top: parent.top
 
183
                    text: i18n.dtr("ubuntu-ui-extras", "Post")
 
184
                    color: "#dd4814"
 
185
                    width: units.gu(10)
 
186
                    height: units.gu(4)
 
187
                    enabled: !activitySpinner.visible
 
188
                    onClicked: {
 
189
                        activitySpinner.visible = true;
 
190
                        callback(accessToken, fileToShare, message.text, uploadCompleted);
 
191
                    }
 
192
                }
 
193
            }
 
194
 
 
195
            UbuntuShape {
 
196
                id: useLocation
 
197
                anchors {
 
198
                    left: parent.left
 
199
                    leftMargin: units.gu(1)
 
200
                    topMargin: units.gu(1)
 
201
                }
 
202
                color: selected ? "#cccccc" : "transparent"
 
203
                property bool selected: false
 
204
                width: units.gu(4.5)
 
205
                height: units.gu(4)
 
206
 
 
207
                AbstractButton {
 
208
                    anchors.fill: parent
 
209
                    onClicked: parent.selected = !parent.selected
 
210
                    Image {
 
211
                        source: "assets/icon_location.png"
 
212
                        anchors.centerIn: parent
 
213
                        height: parent.height * 0.75
 
214
                        fillMode: Image.PreserveAspectFit
 
215
                        smooth: true
 
216
                    }
 
217
                }
 
218
            }
 
219
 
 
220
            Label {
 
221
                anchors.left: useLocation.right
 
222
                anchors.baseline: useLocation.top
 
223
                anchors.baselineOffset: units.gu(3)
 
224
                anchors.leftMargin: units.gu(1)
 
225
                text: i18n.dtr("ubuntu-ui-extras", "Include location")
 
226
                fontSize: "small"
 
227
            }
 
228
 
 
229
        }
 
230
 
 
231
        states: [
 
232
            State {
 
233
                name: "landscape-with-keyborad"
 
234
                PropertyChanges {
 
235
                    target: serviceHeader
 
236
                    y: - serviceHeader.height
 
237
                }
 
238
                PropertyChanges {
 
239
                    target: messageArea
 
240
                    height: units.gu(12)
 
241
                }
 
242
            }
 
243
        ]
 
244
 
 
245
        state: ((Screen.orientation === Qt.LandscapeOrientation) ||
 
246
                (Screen.orientation === Qt.InvertedLandscapeOrientation)) &&
 
247
               Qt.inputMethod.visible ? "landscape-with-keyborad" : ""
 
248
    }
 
249
 
 
250
    /* Menu listing online accounts */
 
251
    Item {
 
252
        id: sharemenu
 
253
        anchors.fill: parent
 
254
        visible: true
 
255
 
 
256
        signal selected(string accountId, string token)
 
257
 
 
258
        Component.onCompleted: {
 
259
            visible = true;
 
260
        }
 
261
        onSelected: {
 
262
            root.userAccountId = accountId;
 
263
            root.accessToken = token;
 
264
            shareComponent.visible = true;
 
265
            sharemenu.visible = false;
 
266
        }
 
267
 
 
268
        Component {
 
269
            id: acctDelegate
 
270
            Item {
 
271
                anchors {
 
272
                    left: parent.left
 
273
                    right: parent.right
 
274
                }
 
275
                AccountService {
 
276
                    id: service
 
277
                    objectHandle: accountServiceHandle
 
278
                    onAuthenticated: {
 
279
                        sharemenu.selected(accountId, reply.AccessToken);
 
280
                    }
 
281
                }
 
282
 
 
283
                height: childrenRect.height
 
284
 
 
285
                ListItem.Subtitled {
 
286
                    anchors {
 
287
                        left: parent.left
 
288
                        right: parent.right
 
289
                    }
 
290
                    text: service.provider.displayName
 
291
                    subText: displayName
 
292
                    iconName: service.provider.iconName
 
293
                    __iconHeight: units.gu(5)
 
294
                    __iconWidth: units.gu(5)
 
295
 
 
296
                    onClicked: {                        
 
297
                        root.account = service;
 
298
                        root.account.authenticate(null);
 
299
                    }
 
300
                }
 
301
            }
 
302
        }
 
303
 
 
304
        ListView {
 
305
            anchors {
 
306
                top: parent.top
 
307
                left: parent.left
 
308
                right: parent.right
 
309
            }
 
310
            height: childrenRect.height
 
311
            interactive: false
 
312
            model: accounts
 
313
            header: ListItem.Header {
 
314
                anchors {
 
315
                    left: parent.left
 
316
                    right: parent.right
 
317
                }
 
318
                text: i18n.tr("Select account")
 
319
            }
 
320
            delegate: acctDelegate
 
321
        }
 
322
    }
 
323
}