main.qml 5.87 KB
Newer Older
armin's avatar
armin committed
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
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import "."

import "qrc:/qml/popups"
import "qrc:/qml/pages"
import "qrc:/qml/various"
import "qrc:/qml/popups"
import "qrc:/qml/style"

import "qrc:/javascript/emoji.js" as Emoji
import "qrc:/javascript/print.js" as Print


ApplicationWindow {
    id: window
    visible: true
    title: qsTr("ucom")


    width: Screen.desktopAvailableWidth
    height: Screen.desktopAvailableHeight
    property int connectionState: 0

    //find better place for that
    property var avatars: Object.create(null)
    property var fileCache: Object.create(null)
    property var channelModels: Object.create(null)
    property bool firstLaunch: true
    property string activeChannel


    background:StdImageHighDPI {
        source: "qrc:/res/images/loginbg.png"
        width: parent.width
        height: parent.height
        fillMode: Image.Stretch
    }

    WelcomePopup {
        id: welcomePopup
    }
    JitsiMeetMissing{
        id: jitsiMeetMissing
    }
48
49
50
    AddServerEntry{
        id:addServerEntry
    }
armin's avatar
armin committed
51
52
53
54
55
56

    Component {
        id: loginComponent
        LoginPage {
        }
    }
57
58
59
60
61
62
    Component {
        id:serverSelectionComponent
        ServerSelectionPage {
        }
    }

armin's avatar
armin committed
63
64
65
66
67
68
69
70
71
72
    ListModel {
        id: uploadsModel
    }

    StackView {
        width: parent.width
        height: parent.height
        property bool mainViewPushed: false
        property bool channelPushed: false
        id: mainStack
73
        initialItem: serverSelectionComponent
armin's avatar
armin committed
74
75
76
77
78
79
80
        function reset() {
            rocketChatController.setUsername("default","")
            rocketChatController.setPassword("default","")
            rocketChatController.setCurrentChannel("default", "", "")
            mainStack.clear()
            mainViewPushed = false
            channelPushed = false
81
            mainStack.push(serverSelectionComponent)
armin's avatar
armin committed
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
        }
        function toMainView() {
            if (!mainViewPushed) {
                mainViewPushed = 1
                mainStack.push("qrc:/qml/pages/MainView.qml")
            }
        }
        function navBack() {
            if (mainStack.depth > 2) {
                mainStack.pop()
            }
            if (mainStack.depth != 4){
                rocketChatController.setCurrentChannel("default","","")
            }
        }
        pushEnter: Transition {
        }
        pushExit: Transition {

        }
        popExit: Transition {

        }
        popEnter: Transition {
        }
    }
    MessageDialog {
        id: messageDialog
        title: "Ooops"
        text: 'Sorry, some error occured. <br>Please close the App and restart.'
    }
    LogoutDialog {
        id: logoutDialog
        text: qsTr("logout ?")

        onYes: {
            console.log("logout accepted")
            rocketChatController.logout("default")
        }
        onRejected: {

        }
    }
    ListModel {
        id: emojiCustomGridModel
        property var contents: Object()
    }
    ListModel {
        id: emojiPersonsGridModel
    }
    ListModel {
        id: emojiNatureGridModel
    }
    ListModel {
        id: emojiFoodGridModel
    }
    ListModel {
        id: emojiCategoryGridModel
    }
    ListModel {
        id: emojiTravelGridModel
    }
    ListModel {
        id: emojiObjectsGridModel
    }
    ListModel {
        id: emojiSymbolsGridModel
    }
    ListModel {
        id: emojiFlagsGridModel
    }

    Component.onCompleted: {
        if(rocketChatController.customEmojisReady){
           // Emoji.addEmojisPerCategory()
        }
        if (rocketChatController.getDdpConnectionEstablished()) {
            connectionState = 1
        }
        rocketChatController.checkLoggedIn();
       }
    Connections {
        target: rocketChatController
        onLoginError: {
            Print.log("error login")
            if (mainStack.mainViewPushed) {
                mainStack.reset()
            }
            if (connectionState == 2) {
                connectionState = 1
            }
        }
        onLoggedOut: {
            mainStack.reset()
        }
        onServerConnected: {
            connectionState = 1
        }
        onLoggedIn: {
            connectionState = 2
        }
        onOffline: {
            connectionState = 0
        }
        onError: {
            messageDialog.text = text + '<br>Please select a file. <br>We recommend the Amaze App as file manager. Get it from the f-droid.org or Google app store.'
            messageDialog.open()
        }
        function getUserAvatar(url){

        }

        onFileRessourceProcessed: {
//            if(rocketChatController.isStorageReady()){
//                getUserAvatar(url);
//            }
            var user = rocketChatController.getUsername("default")
            if (url == "/avatar/" + user + ".jpg") {      
                var suffix = path.substring(path.length - 3, path.length)
                var file = pathPrefix + path
                if (suffix === "svg") {
                    file = "qrc:res/user-identity.svg"
                }
                window.avatars[user] = file
            }


        }
        /*onStorageReady:{
            getUserAvatar();
        }*/
        onEmojisReady:{
            Emoji.addEmojisPerCategory(emojis);
        }
    }
    onClosing: {
        if (Qt.platform.os !== "linux" && Qt.platform.os !== "windows"
                && Qt.platform.os !== "macOS") {
            Print.log(close)
            Print.log(mainStack.depth)
            if (mainStack.depth <= 2) {

                close.accepted = true
            } else {
                close.accepted = false
                mainStack.navBack()
            }
        }
    }
    Connections{
            target:rocketChatController
            onStorageReady:{
                Fonts.updateSettings()
            }
            onNoJitsiMeetAvailable:{
                jitsiMeetMissing.open()
            }
        }
}