-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfallback.qml
231 lines (204 loc) · 7.65 KB
/
fallback.qml
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
import QtQuick 2.0
import Ubuntu.Components 0.1
import QtWebKit 3.0
MainView {
width: units.gu(48)
height: units.gu(60)
PageStack {
id: pageStack
Component.onCompleted: initialize();
Tabs {
id: tabs
//TabBar {
// selectionMode: false
//}
Tab {
id: contactListTab
title: i18n.tr("Contact List")
Page {
id: contactListPage
Component {
id: contactDelegate
Item {
width: units.gu(48)
height: units.gu(5)
Item {
id: icon
width: units.gu(5)
}
Item {
id: name
anchors.left: icon.right
Text { text: contactModel.getByIndex(index).name() }
}
Item {
id: status
width: units.gu(5)
anchors.right : parent.right
}
MouseArea {
anchors.fill: parent
onClicked: {
conversationTab.init(contactModel.getByIndex(index).id)
}
}
}
}
/*
Rectangle {
id: simplebutton
color: "grey"
width: 150; height: 75
MouseArea{
id: buttonMouseArea
anchors.fill: parent //anchor all sides of the mouse area to the rectangle's anchors
//onClicked handles valid mouse button clicks
onClicked: convos.disconnect()
}
}
*/
ListView {
//anchors.top: simplebutton.bottom
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
model: contactModel.len
delegate: contactDelegate
focus: true
}
}
}
Tab {
id: conversationTab
title: "Contact Name Goes Here"
property string withId
Page {
id: conversationPage
Component {
id: messageDelegate
Column {
width: units.gu(48)
Row{
width: parent.width
Text {
width: parent.width
wrapMode: Text.Wrap
textFormat: Text.StyledText
text: makeMsgText(convos.current.getMessageByIndex(index))
function makeMsgText(msg){
var text = '<font color="'
if ( msg.sender.isMe ){
text += 'red';
}else{
text += 'blue';
}
text += '">' + msg.sender.name() + ": </font>" + msg.msg
return text
}
}
}
}
}
ListView {
id: messageList
anchors.top : parent.top
anchors.bottom : entry.top
anchors.left : parent.left
anchors.right : parent.right
model: convos.current.len
delegate: messageDelegate
focus: true
}
TextArea {
id: entry
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: sendBtn.left
focus: true
Keys.onReturnPressed: parent.send()
autoSize: true
maximumLineCount: 3
}
Button {
id: sendBtn
width: 32
height: 32
anchors.bottom: parent.bottom
anchors.right: parent.right
iconSource: '/usr/share/icons/gnome/48x48/actions/document-send.png'
onClicked: parent.send()
}
function send(){
console.log("sending!!!")
if( entry.text == ""){
return;
}
convos.current.send(entry.text);
entry.text = "";
}
}
function init(id){
conversationTab.title = id;
tabs.selectedTabIndex = 1;
convos.changeCurrent(id)
}
}
}
Page {
id: firstRun
visible: false
title: "Fallback Messenger"
Button {
anchors.centerIn: parent
onClicked: {
pageStack.push(oauthPage)
}
text: "Sign in to Google"
}
tools: ToolbarItems {
locked: true
opened: false
}
}
Page {
id: oauthPage
visible: false
title: "Google Authentication"
WebView {
id: webview
url: oauth.getInitialRequestUrl()
width: parent.width
height: parent.height
onNavigationRequested: {
// detectCodeResponse
if (oauth.getCodeFromUrl(request.url)) {
request.action = WebView.IgnoreRequest;
oauth.getAccessToken(loginWithToken)
while(pageStack.depth > 1){
pageStack.pop();
}
} else {
request.action = WebView.AcceptRequest;
}
}
}
}
}
function initialize(){
pageStack.push(tabs);
if(!oauth.refreshAccessToken(loginWithToken)){
pageStack.push(firstRun);
}
}
GoogleAuthentication{
id: oauth
}
function loginWithToken (accessToken){
oauth.getEmail(function(email){
console.log("attempting login...");
convos.login(email, accessToken)
console.log("finished login")
})
}
}