-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
1730 lines (1520 loc) · 47.4 KB
/
mainwindow.cpp
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Id: mainwindow.cpp */
/*
* Copyright (C) 2012-2014 Dmytro Mishchenko <arkadiamail@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "callhistory.h"
#include "accountnewdialog.h"
#include "settingsdialog.h"
#include "genconfig.h"
#include "generalsettings.h"
#include "sysdepapp.h"
#include "calldetails.h"
#include "helpwindow.h"
#include "helpdoc.h"
#include "callsactionmenu.h"
#include "transferactionmenu.h"
#include "dialeractionmenu.h"
#include "contactsactionmenu.h"
#include "historyactionmenu.h"
#include "accountsactionmenu.h"
#include "phone.h"
#include "projectstrings.h"
#include "messagehistory.h"
#include "messageview.h"
#include "accountstatus.h"
#include <unistd.h>
#include <QSettings>
#include <QDebug>
#include <QStatusBar>
#include <QPlainTextDocumentLayout>
//#include <QElapsedTimer>
#if defined(Q_OS_QNX)
#include <bps/bps.h>
#include <bps/soundplayer.h>
#include <bps/netstatus.h>
#include <bps/navigator.h>
#include <bps/screen.h>
#include <errno.h>
#ifdef BB10_BLD
#include <time.h>
#include <bps/notification.h>
#include <bps/netstatus.h>
#include <bps/screen_input_guard.h>
#include <bps/navigator_invoke.h>
#include <bb/platform/Notification>
#include <bb/platform/NotificationDialog>
#include <bb/platform/NotificationError>
#include <bb/platform/NotificationResult>
#include <bb/system/SystemUiButton>
using namespace bb::platform;
#endif
#endif
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
confIsRec(false),
confIsMute(false),
confIsOnSpeaker(false),
selectedCallId(-1),
settingsGeneral(new GeneralSettings(this)),
settingsAccounts(new AccountsSettings(this)),
statusBar(new QStatusBar(this)),
messageDB(new MessageDB(this)),
uriToDial(""),
logDocument(new QTextDocument(this)),
cursor(new QTextCursor(logDocument)),
#if defined(Q_OS_QNX)
callsScroller(new QsKineticScroller(this)),
historyScroller(new QsKineticScroller(this)),
contactsScroller(new QsKineticScroller(this)),
accountsScroller(new QsKineticScroller(this)),
#endif
accountNameHtmlItemDeligate(new HtmlDelegate()),
accountVMHtmlItemDeligate(new HtmlDelegate()),
#if defined(Q_OS_QNX)
bpsH(new BpsHandler(this)),
#endif
appVersion(QString(ProjectStrings::userAgent) + " " + QString(ProjectStrings::userAgentVersion)),
windowActive(true),
netAvailable(false),
netInterfaceType(0),
lastDialedNumber("")
{
QPlainTextDocumentLayout *layout = new QPlainTextDocumentLayout(logDocument);
logDocument->setDocumentLayout(layout);
logDocument->setMaximumBlockCount(2000);
ui->setupUi(this);
logMsg(appVersion);
ui->lbLogoVersion->setText(appVersion);
qRegisterMetaType<Cont>("Cont");
qRegisterMetaType<CallInfo>("CallInfo");
qRegisterMetaType<Cdr>("Cdr");
qRegisterMetaType<Account>("Account");
qRegisterMetaType<MessageRec>("MessageRec");
connect(this, SIGNAL(dialInvoke()), this, SLOT(onDialInvoke()));
connect(this, SIGNAL(reloadPhone()), this, SLOT(onReloadPhone()));
//geometry = saveGeometry();
ch = new CallHistory(ui->callHistory, settingsGeneral->callHistoryMaxCalls, this);
updateCallHistoryTab();
connect(ch, SIGNAL(dialNumber(const QString &, const QString &, bool)),
this, SLOT(callUri(const QString &, const QString &, bool)));
connect(ch, SIGNAL(addNewContcat(const QString &,const QString &)),
this, SLOT(addressBookAddItem(const QString &, const QString &)));
connect(ch, SIGNAL(callDetails(const Cdr &)),
this, SLOT(onCallDetails(const Cdr &)));
AddressBookSettings abs = {
settingsGeneral->displayContOrder
};
ab = new AddressBook(ui->contacts, abs, this);
connect(ab, SIGNAL(dialContact(const Cont &)), this, SLOT(onCallContact(const Cont &)));
connect(ab, SIGNAL(copyContact(const Cont &)), this, SLOT(copyContact(const Cont &)));
connect(ab, SIGNAL(msgContact(const Cont &)), this, SLOT(onMsgView(const Cont &)));
updateContactsTab();
statusBar->setSizeGripEnabled(false);
//ui->callFrame->layout()->addWidget(statusBar);
ui->mainLayout->addWidget(statusBar, 1, 0);
statusBar->addPermanentWidget(ui->btActiveAccount);
if (!settingsAccounts->getDefaultAccount()) {
ui->btActiveAccount->hide();
}
ui->callFrame->hide();
ui->confFrame->hide();
#if defined(Q_OS_QNX)
ui->appMenuFrame->hide();
#endif
//ui->tabWidget->tabBar()->setTabButton(5, QTabBar::LeftSide, ui->tbActionMenu);
ui->tabWidget->setCornerWidget(ui->tbActionMenu, Qt::TopRightCorner);
//ui->tbActionMenu->hide();
ui->tabWidget->setCurrentIndex(settingsGeneral->defaultTab);
#if defined(Q_OS_QNX)
callsScroller->enableKineticScrollFor(ui->saCalls);
historyScroller->enableKineticScrollFor(ui->callHistory);
contactsScroller->enableKineticScrollFor(ui->contacts);
accountsScroller->enableKineticScrollFor(ui->twAccounts);
#endif
ui->frNoAccounts->hide();
ui->twAccounts->setItemDelegateForColumn(AccountsSettings::ColAccName, accountNameHtmlItemDeligate);
ui->twAccounts->setItemDelegateForColumn(AccountsSettings::ColAccVM, accountVMHtmlItemDeligate);
//ui->callHistory->grabGesture(Qt::TapGesture);
//ui->callHistory->grabGesture(Qt::TapAndHoldGesture);
//ui->callHistory->grabGesture(Qt::PanGesture);
//ui->callHistory->grabGesture(Qt::PinchGesture);
//ui->callHistory->grabGesture(Qt::SwipeGesture);
#ifdef BB10_BLD
#else
ui->btConfSpeaker->hide();
#endif
convertV1Settings();
connect(this, SIGNAL(msgNew(MessageRec *)),
messageDB, SLOT(onMsgNew(MessageRec*)));
connect(this, SIGNAL(msgStatus(const MessageRec &)),
messageDB, SLOT(onMsgStatus(const MessageRec &)));
connect(this, SIGNAL(msgDeleteChat(const Cont &)),
messageDB, SLOT(onMsgDeleteChat(const Cont &)));
connect(this, SIGNAL(msgDeleteAll()),
messageDB, SLOT(onMsgDeleteAll()));
connect(this, SIGNAL(msgUpdated()),
messageDB, SLOT(onMsgUpdated()));
Phone *phone = new Phone();
phone->moveToThread(&phoneThread);
connect(&phoneThread, SIGNAL(finished()), phone, SLOT(deleteLater()));
connect(phone, SIGNAL(logInfo(const QString &)),
this, SLOT(logMsg(const QString &)));
connect(phone, SIGNAL(logStatus(const QString &,int)),
this, SLOT(logStatusMsg(const QString &,int)));
connect(phone, SIGNAL(callState(const CallInfo &)),
this, SLOT(onCallState(const CallInfo &)));
connect(phone, SIGNAL(mediaState(int,int)), this, SLOT(onMediaState(int,int)));
connect(phone, SIGNAL(regState(const Account &)),
this, SLOT(onRegState(const Account &)));
connect(phone, SIGNAL(callRecorded(int, const QString &, bool)),
this, SLOT(onCallRecorded(int, const QString &, bool)));
connect(phone, SIGNAL(getTransfereeNumber(int)),
this, SLOT(onGetTransfereeNumber(int)));
connect(phone, SIGNAL(msgStatus(const MessageRec &)),
this, SLOT(onMsgStatus(const MessageRec &)));
connect(phone, SIGNAL(msgNew(MessageRec *)),
this, SLOT(onMsgNew(MessageRec *)));
connect(phone, SIGNAL(zrtpStatusSecureOn(int,const QString &)),
this, SLOT(onZrtpStatusSecureOn(int,const QString &)));
connect(phone, SIGNAL(zrtpStatusSecureOff(int)),
this, SLOT(onZrtpStatusSecureOff(int)));
connect(phone, SIGNAL(zrtpStatusShowSas(int,const QString &,int)),
this, SLOT(onZrtpStatusShowSas(int,const QString &,int)));
connect(this, SIGNAL(reloadPhoneStack(bool)), phone, SLOT(onReloadPhone(bool)));
connect(this, SIGNAL(sendDTMF(int,const QString &)),
phone, SLOT(onSendDTMF(int,const QString &)));
connect(this, SIGNAL(callContact(const Cont &,int)),
phone, SLOT(onCallContact(const Cont &,int)));
connect(this, SIGNAL(callBtnClick(const QString &,int,bool)),
phone, SLOT(onCallBtnClick(const QString &,int,bool)));
connect(this, SIGNAL(callTransferBtnClick(const QString &,int, const QString &)),
phone, SLOT(onCallTransferBtnClick(const QString &,int, const QString &)));
connect(this, SIGNAL(startWavPlayback(const QString &)),
phone, SLOT(onStartWavPlayback(const QString &)));
connect(this, SIGNAL(stopWavPlayback()), phone, SLOT(onStopWavPlayback()));
connect(this, SIGNAL(newLogLevel(int)), phone, SLOT(onSetLogLevel(int)));
connect(this, SIGNAL(playTestRing(int)), phone, SLOT(onStartTestRing(int)));
connect(this, SIGNAL(setConfConnect(int,bool)),
phone, SLOT(onSetConfConnect(int,bool)));
connect(this, SIGNAL(confButton(const QString &)),
phone, SLOT(onConfButtonClicked(const QString &)));
connect(this, SIGNAL(setSelectedCall(int)),
phone, SLOT(setSelectedCall(int)));
connect(this, SIGNAL(msgSend(MessageRec *)),
phone, SLOT(onMsgNew(MessageRec *)));
phoneThread.start(QThread::HighPriority);
#if defined(Q_OS_QNX)
QObject::connect(bpsH, SIGNAL(windowActive()), this, SLOT(onWindowActive()));
QObject::connect(bpsH, SIGNAL(windowInactive()), this, SLOT(onWindowInactive()));
QObject::connect(bpsH, SIGNAL(swipeDown()), this, SLOT(onSwipeDown()));
QObject::connect(bpsH, SIGNAL(netStatus(bool, int)), this, SLOT(onNetStatus(bool, int)));
QObject::connect(bpsH, SIGNAL(callBtnClicked(const QString &, int)),
this, SLOT(onCallBtnClick(const QString &, int)));
#else
onNetStatus(true);
#endif
}
MainWindow::~MainWindow()
{
phoneThread.quit();
if (!phoneThread.wait(30000)) {
qDebug() << "Terminating Phone thread. Didn't respond in time";
phoneThread.terminate();
phoneThread.wait();
}
delete ui;
delete accountNameHtmlItemDeligate;
delete accountVMHtmlItemDeligate;
}
void MainWindow::logMsg(const QString &text)
{
if (cursor) {
cursor->movePosition(QTextCursor::End);
cursor->insertText(text + "\n");
}
else {
qCritical() << "Log object not found";
}
}
void MainWindow::logStatusMsg(const QString &text, int timeout)
{
logMsg("Status bar: " + text);
statusBar->showMessage(text, timeout);
}
void MainWindow::convertV1Settings()
{
QSettings settings;
Account *acnt;
acnt = new Account();
settings.beginGroup("SIPAccount");
acnt->displayName = settings.value("displayName", "").toString();
acnt->userId = settings.value("userId", "").toString();
acnt->userPassword = settings.value("userPassword", "").toString();
acnt->domain = settings.value("domain", "").toString();
QString stun(settings.value("stun", "").toString());
acnt->sipRegister = settings.value("sipRegister", false).toBool();
settings.endGroup();
if (!stun.isEmpty()) {
settingsGeneral->stunServer = stun;
settingsGeneral->useStunServer = true;
settingsGeneral->save();
}
if (acnt->userId.isEmpty() && acnt->domain.isEmpty()) {
delete acnt;
return;
}
qDebug() << "adding old account";
settingsAccounts->addAccount(acnt);
settings.beginGroup("SIPAccount");
settings.remove("");
settings.endGroup();
settings.sync();
}
void MainWindow::onReloadPhone()
{
settingsAccounts->reloadAccounts();
settingsAccounts->initAccountWidget(ui->twAccounts);
updateDefaultAccount();
if (!settingsAccounts->configuredAccounts()) {
logStatusMsg(tr("Welcome to Taki! Please configure at least one SIP account."));
ui->tabWidget->setCurrentIndex(GeneralSettings::TabAccounts);
ui->frNoAccounts->show();
ui->twAccounts->hide();
}
else {
ui->frNoAccounts->hide();
ui->twAccounts->show();
bool netStatus = netAvailable;
switch (settingsGeneral->requiredNetworkInterface) {
#if defined(Q_OS_QNX)
case GeneralSettings::NetWifi:
if (netInterfaceType != NETSTATUS_INTERFACE_TYPE_WIFI) {
logMsg("Disable network. Default interface type is not Wi-Fi.");
netStatus = false;
}
break;
case GeneralSettings::NetCellular:
if (netInterfaceType != NETSTATUS_INTERFACE_TYPE_CELLULAR) {
logMsg("Disable network. Default interface type is not cellular.");
netStatus = false;
}
break;
#endif
default:
logMsg("Any network interface is acceptable.");
break;
}
emit reloadPhoneStack(netStatus);
}
}
void MainWindow::dialPadKeyPress()
{
QObject* callingButton = QObject::sender();
QString d;
#if defined(Q_OS_QNX)
soundplayer_prepare_sound("input_keypress");
soundplayer_play_sound("input_keypress");
#endif
if (callingButton == ui->pushButton1) {
d = "1";
} else if (callingButton == ui->pushButton2) {
d = "2";
} else if (callingButton == ui->pushButton3) {
d = "3";
} else if (callingButton == ui->pushButton4) {
d = "4";
} else if (callingButton == ui->pushButton5) {
d = "5";
} else if (callingButton == ui->pushButton6) {
d = "6";
} else if (callingButton == ui->pushButton7) {
d = "7";
} else if (callingButton == ui->pushButton8) {
d = "8";
} else if (callingButton == ui->pushButton9) {
d = "9";
} else if (callingButton == ui->pushButton0) {
d = "0";
} else if (callingButton == ui->pushButtonStar) {
d = "*";
} else if (callingButton == ui->pushButtonPound) {
d = "#";
} else if (callingButton == ui->pushButtonCallDp) {
callDp();
} else if (callingButton == ui->pushButtonBs) {
ui->leNumberToDial->backspace();
}
if (!d.isEmpty()) {
ui->leNumberToDial->insert(d);
}
}
void MainWindow::onSendDTMF(int callId, const QString &key)
{
emit sendDTMF(callId,key);
}
void MainWindow::copyContact(const Cont &cont)
{
ui->leNumberToDial->setText(cont.getPhoneNumber());
ui->tabWidget->setCurrentIndex(GeneralSettings::TabDialer);
}
void MainWindow::callDp()
{
QString directCallUri(ui->leNumberToDial->text().trimmed());
if (directCallUri.isEmpty()) {
if (lastDialedNumber.isEmpty()) {
logStatusMsg(tr("Please enter the number you wish to call"), 10000);
}
else {
ui->leNumberToDial->setText(lastDialedNumber);
}
return;
}
else {
ui->leNumberToDial->clear();
}
callUri(directCallUri, "");
}
void MainWindow::callVm(const Account *ac)
{
if (!ac) {
logStatusMsg(tr("Acount not found"), 10000);
return;
}
if (ac->vmNumber.isEmpty()) {
logStatusMsg(tr("Voicemail number is not configured for this account"), 10000);
voicemainSettings();
return;
}
callUri(ac->vmNumber, ac->vmDTMF);
}
void MainWindow::callUri(const QString &url, const QString &dtmf, bool translateNumber, int transfereeCallId)
{
logMsg("callUri()");
Cont cont;
cont.setPhoneNumber(url);
cont.setSecStagePhoneNumber(dtmf);
onCallContact(cont, translateNumber, transfereeCallId);
}
void MainWindow::onCallContact(const Cont &cont, bool translateNumber, int transfereeCallId)
{
const Account *ac = settingsAccounts->getDefaultAccount();
if (!ac) {
logStatusMsg(tr("Acount not found"), 10000);
return;
}
Cont newCont(cont);
newCont.buildDirectCallUri(*ac, translateNumber);
newCont.setPjSipAccId(ac->pjSipAccId);
lastDialedNumber = cont.getPhoneNumber();
logMsg("onCallContact UI. Uri: " + newCont.getDirectCallUri());
emit callContact(newCont, transfereeCallId);
}
void MainWindow::onCallBtnClick(const QString &btn, int callId)
{
logMsg("onCallBtnClick UI: " + btn + " for call: " + QString::number(callId));
notificationStop(callId);
if (btn == "btKick") {
kickConfCall(callId);
if (getNumberOfCalls(ui->confLayout) <= 1) {
confButtonClicked("btConfSplit");
}
}
else if (btn == "btCallBack") {
CallWidget *cw = qobject_cast<CallWidget *>(sender());
if (cw) {
QString number(cw->getNumber());
int transfereeCallId = cw->getTransfereeCallId();
cw->close();
callUri(number, "", false, transfereeCallId);
}
}
else if (btn == "btDialpad" || btn == "btDialpadC") {
actionMenu();
}
else {
logMsg("onCallBtnClick UI emit signal");
emit callBtnClick(btn, callId, true);
}
}
void MainWindow::onCallState(const CallInfo &ci)
{
int call_id = ci.c_id;
QString state(ci.state_text);
QString from(ci.remote_info);
QString last_status(ci.last_status);
QString last_status_text(ci.last_status_text);
bool ring = ci.ring;
if (state == "DISCONNCTD") {
notificationStop(call_id);
onCallBtnClick("btKick", call_id);
if (selectedCallId == call_id) {
selectedCallId = -1;
}
}
if (state == "CALLING" || state == "INCOMING") {
QString contactName, contactNumber, domain, contactIcon;
const Account *acnt = settingsAccounts->getPjSipAccount(ci.acc_id);
if (!acnt) {
logMsg("onCallState. Account not found");
return;
}
if (acnt) {
domain = acnt->domain;
}
parseCallerId(from, domain, contactName, contactNumber);
if (contactName.isEmpty()) {
Cont cont = ab->findContByNumber(contactNumber);
contactName = cont.getDisplayName();
contactIcon = cont.getPhotoFilepath();
}
CallWidget *cw = new CallWidget(call_id, ci.transfereeCallId, state,
contactName, contactNumber, contactIcon, this);
if (!cw) {
logMsg("onCallState. Unable to create CallWidget");
return;
}
ui->cfLayout->addWidget(cw);
ui->tabWidget->setCurrentIndex(GeneralSettings::TabCalls);
ui->phoneLogo->setVisible(false);
ui->callFrame->setVisible(true);
#ifdef BB10_BLD
screen_input_guard_request_events(0);
screen_input_guard_enable();
#endif
if (state == "INCOMING") {
if (acnt->autoAnswer) {
cw->buttonClicked("btAnswer");
}
else {
notificationStart(call_id, contactName, contactNumber);
}
}
}
else {
emit setPjCallState(call_id, state, last_status, last_status_text, ring);
}
}
void MainWindow::onCallEnd(const Cdr &cdr)
{
ch->addCall(cdr);
updateCallHistoryTab();
}
void MainWindow::onCallDestroy()
{
if (!getNumberOfCalls()) {
ui->tabWidget->setCurrentIndex(settingsGeneral->defaultTab);
ui->callFrame->setVisible(false);
ui->phoneLogo->setVisible(true);
#ifdef BB10_BLD
screen_input_guard_disable();
screen_input_guard_stop_events(0);
#endif
}
}
int MainWindow::getNumberOfCalls()
{
int numRegcalls = getNumberOfCalls(ui->cfLayout);
int numConfCalls = getNumberOfCalls(ui->confLayout);
int numCalls = numRegcalls + numConfCalls;
return numCalls;
}
int MainWindow::getNumberOfCalls(const QLayout *layout)
{
int numOfCalls = 0;
for (int i = 0; i < layout->count(); ++i) {
QLayoutItem *li = layout->itemAt(i);
CallWidget *cw = qobject_cast<CallWidget *>(li->widget());
if (cw) {
++numOfCalls;
}
}
return numOfCalls;
}
void MainWindow::onMediaState(int call_id, int state)
{
emit setPjMediaState(call_id, state);
}
void MainWindow::onRegState(const Account &acnt)
{
Account *ac = settingsAccounts->getAccountById(acnt.accId());
if (ac) {
*ac = acnt;
settingsAccounts->updateAccountWidget(ui->twAccounts, ac);
updateDefaultAccount();
}
}
void MainWindow::callHistoryDeleteItem()
{
if (ch->deleteCurrent()) {
logStatusMsg(tr("Please select a call"), 5000);
}
updateCallHistoryTab();
}
void MainWindow::callHistoryClear()
{
ch->deleteAll();
updateCallHistoryTab();
}
void MainWindow::callHistoryDial()
{
QTreeWidgetItem *item = ui->callHistory->currentItem();
callHistoryDial(item, 0);
}
void MainWindow::callHistoryDial(QTreeWidgetItem *item, int column)
{
if (!item) {
logStatusMsg(tr("Please select a call"), 5000);
return;
}
ch->openCallDetails(item, column);
}
void MainWindow::callHistoryAddContact()
{
QTreeWidgetItem *item = ui->callHistory->currentItem();
if (!item) {
logStatusMsg(tr("Please select a call"), 5000);
return;
}
ch->addToContact(item);
}
void MainWindow::callHistoryToolTip()
{
//qDebug() << "call history tool tip slot";
}
void MainWindow::callHistoryDetails()
{
qDebug() << "call history details slot";
QTreeWidgetItem *item = ui->callHistory->currentItem();
if (!item) {
logStatusMsg(tr("Please select a call"), 5000);
return;
}
ch->openCallDetails(item, 1);
}
void MainWindow::onCallDetails(const Cdr &cdr)
{
CallDetails cd(cdr);
connect(&cd, SIGNAL(delCallDetail()), ch, SLOT(deleteCurrent()));
connect(&cd, SIGNAL(addCallDetailToContact()), this, SLOT(callHistoryAddContact()));
connect(&cd, SIGNAL(startWavPlayback(const QString &)),
this, SLOT(callHistoryStartPlayback(const QString &)));
connect(&cd, SIGNAL(stopWavPlayback()),
this, SLOT(callHistoryStopPlayback()));
#if defined(Q_OS_QNX)
cd.setWindowState(cd.windowState() ^ Qt::WindowMaximized ^ Qt::WindowActive);
#endif
cd.exec();
}
void MainWindow::callHistoryStartPlayback()
{
QTreeWidgetItem *item = ui->callHistory->currentItem();
if (!item) {
logStatusMsg(tr("Please select a call"), 5000);
return;
}
QVariant v = item->data(0, Qt::UserRole);
Cdr cdr = v.value<Cdr>();
QString fn(cdr.getRecordingPath());
if (fn.isEmpty()) {
return;
}
emit startWavPlayback(fn);
}
void MainWindow::callHistoryStartPlayback(const QString &fn)
{
emit startWavPlayback(fn);
}
void MainWindow::callHistoryStopPlayback()
{
emit stopWavPlayback();
}
void MainWindow::addressBookDeleteItem()
{
int res = ab->delContact();
if (res) {
logStatusMsg(tr("Please select a contact"), 5000);
}
updateContactsTab();
}
void MainWindow::addressBookDial()
{
QTreeWidgetItem *item = ui->contacts->currentItem();
if (item) {
addressBookDial(item, 0);
}
else {
logStatusMsg(tr("Please select a contact with the phone number."), 5000);
}
}
void MainWindow::addressBookDial(QTreeWidgetItem *item, int column)
{
ab->openContact(item, column);
}
void MainWindow::addressBookMsg()
{
QTreeWidgetItem *item = ui->contacts->currentItem();
if (item) {
addressBookMsg(item, 0);
}
else {
logStatusMsg(tr("Please select a contact with the phone number."), 5000);
}
}
void MainWindow::addressBookMsg(QTreeWidgetItem *item, int column)
{
bool forMsg = true;
ab->openContact(item, column, forMsg);
}
void MainWindow::addressBookAddItem(const QString &name, const QString &number)
{
int res = ab->addContact(name, number);
updateContactsTab();
if (res == QDialog::Accepted) {
ui->tabWidget->setCurrentIndex(GeneralSettings::TabContacts);
logStatusMsg(tr("Contact added"), 5000);
}
}
void MainWindow::addressBookEditItem()
{
ab->editContact();
}
void MainWindow::addressBookSearch(const QString &searchStr)
{
ab->load(searchStr);
updateContactsTab();
}
void MainWindow::onCallSelect(int callId)
{
selectedCallId = callId;
emit setSelectedCall(callId);
emit callActivated(callId);
}
void MainWindow::notificationStart(int call_id,
const QString &displayName,
const QString &displayNumber)
{
#if defined(Q_OS_QNX)
if (windowActive) {
return;
}
Cdr cdr;
cdr.setName(displayName);
cdr.setNumber(displayNumber);
notification_message_t *nt;
int ret = notification_message_create(&nt);
if (ret != BPS_SUCCESS) {
qWarning() << "Error creating notification event";
return;
}
activeNotifications[call_id] = nt;
char itemId[20];
snprintf(itemId, sizeof(itemId), "%d", call_id);
notification_message_set_item_id(nt, itemId);
qDebug() << "notification_message_set_item_id Item id:" << itemId;
notification_message_set_title(nt, "Taki. Incoming call");
QStringList sl;
if (!cdr.getName().isEmpty()) {
sl << cdr.getName();
}
if (!cdr.getNumber().isEmpty()) {
sl << cdr.getDisplayNumber();
}
QString display(sl.join("\n"));
QByteArray baDisplay(display.toLocal8Bit());
notification_message_set_subtitle(nt, baDisplay.data());
notification_message_add_prompt_choice(nt, "Answer", "btAnswer");
notification_message_add_prompt_choice(nt, "Reject", "btReject");
notification_alert(nt);
#else
Q_UNUSED(call_id);
Q_UNUSED(displayName);
Q_UNUSED(displayNumber);
#endif
}
void MainWindow::notificationStop(int call_id)
{
#if defined(Q_OS_QNX)
notification_message_t *nt = activeNotifications[call_id];
if (nt) {
notification_cancel(nt);
notification_delete(nt);
notification_message_destroy(&nt);
activeNotifications[call_id] = NULL;
}
#else
Q_UNUSED(call_id);
#endif
}
void MainWindow::setLogLevel(int level)
{
level = (level) ? 4 : 3;
settingsGeneral->logLevel = level;
settingsGeneral->save();
emit newLogLevel(level);
}
void MainWindow::addNewAccount()
{
Account *acnt = new Account();
AccountNewDialog accDlg(acnt, this);
#if defined(Q_OS_QNX)
accDlg.showMaximized();
#else
accDlg.show();
#endif
int ret = accDlg.exec();
if (ret != QDialog::Accepted) {
delete acnt;
return;
}
if (acnt->domain.isEmpty()) {
logStatusMsg(tr("Account not saved. Domain name can't be empty"));
delete acnt;
return;
}
logMsg("Adding new account");
settingsAccounts->addAccount(acnt);
logStatusMsg(tr("Settings saved"));
emit reloadPhone();
}
void MainWindow::advancedSettingsHelper(Account *acnt, int loadTab)
{
SettingsDialog advSettings(acnt, loadTab, this);
connect(&advSettings, SIGNAL(testRing(int)),
this, SLOT(startTestRing(int)), Qt::QueuedConnection);
#if defined(Q_OS_QNX)
advSettings.showMaximized();
#else
advSettings.show();
#endif
int ret = advSettings.exec();
if (ret != QDialog::Accepted) {
return;
}
logMsg("Saving account advanced settings");
advSettings.getResult();
if (! acnt->accId()) {
settingsAccounts->addAccount(acnt);
}
else {
settingsAccounts->saveAccounts();
}
logStatusMsg(tr("Settings saved"));
emit reloadPhone();
}
void MainWindow::advancedSettings()
{
Account *acnt;
acnt = settingsAccounts->getSelectedAccount(ui->twAccounts);
bool newAcc = false;
if (!acnt) {
acnt = new Account();
newAcc = true;
}
advancedSettingsHelper(acnt);
if (newAcc && acnt->accId() == 0) {
delete acnt;
}
return;
}
void MainWindow::voicemainSettings()
{
Account *ac = settingsAccounts->getSelectedAccount(ui->twAccounts);
if (ac) {
advancedSettingsHelper(ac, SettingsDialog::Voicemail);
}
}
void MainWindow::startTestRing(int ringToneIndex)
{
emit playTestRing(ringToneIndex);
}
void MainWindow::generalSettingsHelper(int loadTab)
{
#if defined(Q_OS_QNX)
if (ui->appMenuFrame->isVisible()) {
ui->appMenuFrame->hide();
}
#endif
GenConfig genConfig(settingsGeneral, loadTab, this);
#if defined(Q_OS_QNX)
genConfig.showMaximized();
#else
genConfig.show();
#endif
int ret = genConfig.exec();
if (ret != QDialog::Accepted) {
return;
}
logMsg("Saving general settings");
genConfig.getResult();
settingsGeneral->save();
logStatusMsg(tr("Settings saved"));
ch->setMaxCalls(settingsGeneral->callHistoryMaxCalls);
AddressBookSettings abs = {