-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.qml
152 lines (126 loc) · 3.95 KB
/
Main.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
import QtQuick 2.4
import Ubuntu.Components 1.3
import Ubuntu.Components.Popups 1.3
import io.thp.pyotherside 1.4
import "ui"
MainView {
id: main
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "sparseqml.delijati"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
// Removes the old toolbar and enables new features of the new header.
//useDeprecatedToolbar: false
width: units.gu(50)
height: units.gu(75)
property real spacing: units.gu(1)
property real margins: units.gu(2)
property real buttonWidth: units.gu(9)
property var path: []
property var activeRoom: null
property var userId: null
RoomList {
id: room_list
}
RoomView {
id: room_view
}
LoginDialog {
id: login_dialog
property var current: null
}
Loading {
id: loading
}
function loadRooms() {
py.call("backend.mgr.get_rooms", [], function(rooms) {
room_list.model.clear()
for (var i=0; i < rooms.length; i++) {
console.log("Name: " + rooms[i].room_id)
room_list.model.append(rooms[i]);
}
pageStack.pop(loading)
pageStack.push(room_list)
console.log("Logged In in gui")
})
}
function login_end(data) {
// XXX should we rather send signals?
pageStack.pop(loading)
PopupUtils.close(login_dialog.current)
main.userId = data.user_id
loadRooms()
}
function load_with_token(exists) {
// this is called when app starts!
// XXX should we rather send signals?
if (!exists) {
login_dialog.current = PopupUtils.open(login_dialog);
}
else {
pageStack.push(loading)
py.call("backend.mgr.login_with_token", [], function(data) {
main.userId = data.user_id
loadRooms()
})
}
}
PageStack {
id: pageStack
anchors.fill: parent
Component.onCompleted: {
py.call("backend.file_exists", [], load_with_token)
}
}
function insertionSortByKey(model, key) {
var length = model.count;
for(var i = 1; i < length; i++) {
var temp = model.get(i).event;
for(var j = i - 1; j >= 0 && model.get(j).event[key] > temp[key]; j--) {
model.move(j, j+1, 1);
}
}
return model;
}
Python {
id: py
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
addImportPath(Qt.resolvedUrl('./lib/py'));
importModule('backend', function(){
console.log("python loaded");
});
setHandler('r.room.message', function (entry) {
// console.log('New entries from ' + entry.sender + ' with ' + entry.content.body);
room_view.model.append(entry);
// TODO we sort now on every new message event :/
insertionSortByKey(room_view.model, "origin_server_ts")
});
}
onError: {
console.log('Error: ' + traceback);
var dialog = PopupUtils.open(errorDialog);
dialog.traceback = traceback;
}
}
Component {
id: errorDialog
Dialog {
id: dialog
title: i18n.tr("Error")
property string traceback: ""
text: i18n.tr("An error has occured: %1").arg(traceback)
property string id_
Button {
id: cancelButton
text: i18n.tr("Close")
onClicked: PopupUtils.close(dialog)
}
}
}
}