forked from Konstantin2/CallMyPhone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
297 lines (233 loc) · 9.12 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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import QtQuick 2.9
import QtQuick.Controls 2.2
import Qt.labs.settings 1.0
ApplicationWindow {
id: mainApplication
visible: true
width: 640
height: 480
maximumWidth: 640
maximumHeight: 480
title: qsTr("Набор номера")
Settings {
id: settings
category: 'main'
property string phone_url: 'http://127.0.0.1';
property string phone_user: 'admin';
property string phone_passwd: 'password';
property string outgoing_uri: '[email protected]';
property string lastcalls: "{}"
property string contacts: "{}"
property bool full_mode_switch: false
}
function change_window_mode(mode) {
if (mode === true){
mainApplication.maximumHeight = 480;
mainApplication.maximumWidth = 640;
mainApplication.height = 480;
mainApplication.width = 640;
settings.full_mode_switch = true
} else {
mainApplication.maximumHeight = 70;
mainApplication.maximumWidth = 640;
mainApplication.height = 70;
mainApplication.width = 640;
settings.full_mode_switch = false
}
}
function clear_number(number){ //Удаляет лишние символы из номера
return number.replace(/[^0-9\+\*\#a-zA-Z\_]/g, '') || ""; //Оставляем только нужные символы
}
Component.onCompleted: { //Выполняется после старта приложения
// switch1.checked = settings_window.full_mode_switch;
change_window_mode(settings.full_mode_switch);
var i;
// try {
// //Загружаем контакты
// var datamodel_contacts = JSON.parse(settings.contacts)
// contacts1.listModel.clear();
// for (i = 0; i < datamodel_contacts.length; ++i) contacts1.listModel.append(datamodel_contacts[i])
// } catch (err) {
// }
// function get_name(contacts, number){
// for (var i = 0; i < contacts.length; ++i){
// if ((clear_number(contacts[i].number) === clear_number(number))&& contacts[i].name !== "Не указан"){
// return contacts[i].name;
// }
// }
// return "";
// }
try {
//Загружаем посление звонки
var datamodel_lastcalls = JSON.parse(settings.lastcalls)
lastcalls1.listModel.clear();
for (i = 0; i < datamodel_lastcalls.length; ++i){
// datamodel_lastcalls[i].name = get_name(datamodel_contacts, datamodel_lastcalls[i].number) || datamodel_lastcalls[i].name;
lastcalls1.listModel.append(datamodel_lastcalls[i])
}
} catch (err) {
}
phonenumber.text = get_cmd_phonenumber(); //Загружаем вызываемый номер
phonenumber.phone_name = get_cmd_phonename() || qsTr("Не указан"); //Загружаем ФИО вызываемого номер если указано
}
function get_cmd_phonenumber(){
if (Qt.application.arguments.length > 1){
var only_number = Qt.application.arguments[1];
only_number = only_number.replace(/^tel\:/gi, '') || ""; //Удаляем лишние символы
only_number = only_number.replace(/^callto\:/gi, '') || ""; //Удаляем лишние символы
return only_number;
//Qt.application.arguments.length //gives argc
}
return '';
}
function get_cmd_phonename(){
if (Qt.application.arguments.length > 2){
return Qt.application.arguments[2] //access items in argv
//Qt.application.arguments.length //gives argc
}
return '';
}
// Qt.application.arguments[argIndex] //access items in argv
// Qt.application.arguments.length //gives argc
function call_number(number, out_uri){
var only_number = clear_number(number); //Оставляем только нужные символы
// var only_number = number.replace(/[ \(\)\-]/g, '') || ""; //Удаляем лишние символы
if (only_number !== "") {
var request = new XMLHttpRequest();
request.open('GET', settings.phone_url + '/cgi-bin/ConfigManApp.com?number=' + encodeURIComponent(only_number) + '&outgoing_uri=' + encodeURIComponent(out_uri))
request.setRequestHeader("Authorization", "Basic " + Qt.btoa(settings.phone_user + ':' + settings.phone_passwd));
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200) {
console.log(request.responseText)
} else {
console.log("HTTP request failed", request.status)
}
}
}
request.send();
}
}
function send_key(key){
if (key !== "") {
var request = new XMLHttpRequest();
request.open('GET', settings.phone_url + '/servlet?key=' + encodeURIComponent(key))
request.setRequestHeader("Authorization", "Basic " + Qt.btoa(settings.phone_user + ':' + settings.phone_passwd));
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200) {
console.log(request.responseText)
} else {
console.log("HTTP request failed", request.status)
}
}
}
request.send();
}
}
function add_lastcall(param){
if (lastcalls1.listModel.count > 20){
lastcalls1.listModel.remove(lastcalls1.listModel.count - 1);
}
if (phonenumber.text !== get_cmd_phonenumber()){
phonenumber.phone_name = qsTr("Не указан");
param.name = qsTr("Не указан");
}
// lastcalls1.listModel.append(param)
lastcalls1.listModel.insert(0, param)
var datamodel = []
for (var i = 0; i < lastcalls1.listModel.count; ++i) datamodel.push(lastcalls1.listModel.get(i))
//datastore = JSON.stringify(datamodel)
settings.lastcalls = JSON.stringify(datamodel)
}
function formatDate(date) {
var dd = date.getDate();
if (dd < 10) dd = '0' + dd;
var mm = date.getMonth() + 1;
if (mm < 10) mm = '0' + mm;
var yyyy = date.getFullYear();
var hh = date.getHours();
if (hh < 10) hh = '0' + hh;
var MM = date.getMinutes();
if (MM < 10) MM = '0' + MM;
return dd + '.' + mm + '.' + yyyy + ' ' + hh + ':' + MM;
}
header: Item {
Row {
anchors.right: parent.right
anchors.left: parent.left
spacing: 6
TextField {
id: phonenumber
placeholderText: qsTr("Введите номер телефона")
text: qsTr("")
font.pixelSize: 24
selectByMouse: true
onAccepted: call.clicked()
property string phone_name: qsTr("Не указан")
}
Button {
id: call
// icon.source: "img/icons8-call-32.png"
font.pixelSize: 24
text: qsTr("Позвонить")
onClicked: {
call_number(phonenumber.text, settings.outgoing_uri);
add_lastcall({
"number": phonenumber.text,
"name" : phonenumber.phone_name,
"date" : formatDate(new Date())
})
}
}
Button {
id: call_stop
// icon.source: "img/icons8-phone-32.png"
font.pixelSize: 24
text: qsTr("Положить")
onClicked: send_key('Cancel')
}
Switch {
id: switch1
// anchors.top: call_stop.bottom
// x: 117
// y: 282
text: qsTr("Дополнительно")
checked: settings.full_mode_switch
onClicked: {
change_window_mode(this.checked);
}
}
}
}
SwipeView{
id: swipeView
anchors.fill: parent
visible: settings.full_mode_switch
currentIndex: tabBar.currentIndex
Lastcalls{
id: lastcalls1
}
// Contacts{
// id: contacts1
// }
Options{
id: options1
}
}
footer: TabBar{
id: tabBar
currentIndex: swipeView.currentIndex
visible: settings.full_mode_switch
font.pixelSize: 20
TabButton{
text: qsTr("Вызовы")
}
// TabButton{
// text: qsTr("Контакты")
// }
TabButton{
text: qsTr("Настройки")
}
}
}