-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.qml
138 lines (119 loc) · 3.53 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
/**
* @file Main.qml
* @brief The main user interface
* @author Giang Nguyen
* Contact: [email protected]
*/
import QtQuick 2.9
import QtQuick.Window 2.3
Window {
id: onchatmain
visible: true
x: 0
y: 0
width: 600
height: 500
title: "Login to your OnChat account"
property int userIP
signal userloggedin(string object)
signal userloggedout
signal newconversation(string object)
// if the IDE said that this is invalid. It's a false positive. The program works fine.
onClosing: logout()
// get the recent messages when user opens a new chat window
function newWindow (usernameinput, partnerinput) {
chatServer.getRecentMessage(usernameinput,partnerinput);
}
// log the user in
function login () {
onchatmain.title = "Welcome " + username.content
userloggedin(username.content)
if (!chatServer.userExist(username.content))
chatServer.registerClient(username.content)
chatServer.userLogin(username.content,userIP)
loginInterface.visible = false
userInterface.visible = true
}
// start a new conversation
function startnewconversation () {
if (chatServer.userExist(partnerID.content))
newconversation(partnerID.content)
}
// log the user out
function logout () {
onchatmain.title = "Login to your OnChat account"
chatServer.userLogout(username.content);
userloggedout()
userInterface.visible = false
loginInterface.visible = true
}
Item {
id: loginInterface
visible: true
anchors.fill:parent
width: parent.width
height: parent.height
MPInputBox {
id: username
hint: "Type your username"
Keys.onReturnPressed: login()
anchors.bottom: loginbtn.top
anchors.horizontalCenter: parent.horizontalCenter
width: loginbtn.width
height: loginbtn.height
Rectangle {
anchors.fill: parent
opacity: 0.15
color: "lightgrey"
border{
width: 1
color: "black"
}
}
}
MPButton {
id: loginbtn
label: "Login/Create new account"
anchors.centerIn: parent
onPressBtn: login()
}
}
Item {
id: userInterface
visible: false
anchors.fill:parent
width: parent.width
height: parent.height
MPInputBox {
id: partnerID
hint: "Type your partner username"
Keys.onReturnPressed: startnewconversation()
anchors.bottom: newconversationbtn.top
anchors.horizontalCenter: parent.horizontalCenter
width: loginbtn.width
height: loginbtn.height
Rectangle {
anchors.fill: parent
opacity: 0.15
color: "lightgrey"
border{
width: 1
color: "black"
}
}
}
MPButton {
id: newconversationbtn
label: "Start new conversation"
anchors.bottom: logoutbtn.top
anchors.horizontalCenter: parent.horizontalCenter
onPressBtn: startnewconversation()
}
MPButton {
id: logoutbtn
label: "Log out"
anchors.centerIn: parent
onPressBtn: logout()
}
}
}