-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
788 lines (640 loc) · 22.9 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
//
// Contact Manager
//
// mainwindow.cpp
//
//
// ==========================================================================
#include <QProcess>
#include <QMessageBox>
#include <QShortcut>
#include "mainwindow.h"
#include "sendsmsform.h"
#include "../Lib/itemselect.h"
#include "../Lib/alertsound.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
searchtext="" ;
gConf=NULL ;
timer=NULL ;
enc=NULL ;
find=NULL ;
ui->setupUi(this);
// Enable debug
setupdebug();
// Set the application icon
QIcon icon(":icon-image.png");
setWindowIcon(icon);
// Initialise and load configuration
gConf = new Configuration(this) ;
// Initialise encryption i/o
enc = new Encryption(QString("trumpton.uk"), QString("TextFileEncryption")) ;
gConf->setEncryption(enc);
// Set up Calendar Model
calendarlist.clear() ;
ui->listCalendar->setModel(&calendarlist) ;
// Populate contact record with a blank entry
db.selectContact(SELECT_OVERVIEW);
gSavePath = gConf->getDatabasePath() ;
gContactSavePath = gSavePath + "contact" + QDir::toNativeSeparators("/") ;
gCalendarSavePath = gSavePath + "calendar" + QDir::toNativeSeparators("/") ;
// Set the Default Codecs for Strings
QTextCodec::setCodecForLocale(QTextCodec::codecForName(gConf->getCodec().toLatin1().constData()));
// Login if not already done so
int count=0 ;
if (!enc->loggedIn()) do {
dbg("Logging In") ;
enc->login() ;
} while (!enc->loggedIn() && ++count<3) ;
// Login failed, so set key
while (!enc->loggedIn()) {
if (QMessageBox::question(this, "Contact Manager", "You have failed to login. To set or reset the key, select Yes, and otherwise select Close to exit the program", QMessageBox::Yes|QMessageBox::Close)==QMessageBox::Yes) {
dbg("Login Complete") ;
enc->setKey();
} else {
// Calling abort from Constructor doesn't work - it has to be from a function initiated with a signal
dbg("Sending abort signal, login failed") ;
QTimer::singleShot(1, this, SLOT(abort())) ;
return ;
}
}
// Load the local data
dbg("Loading database and calendar") ;
db.load() ;
calendar.load() ;
ui->editDateOfBirth->setFormat("", "dd/MMM/yyyy", true) ;
//populateDialog(SELECT_OVERVIEW) ;
//on_tabBar_currentChanged(1) ;
//on_actionGotoToday_triggered() ;
// Warn if no synchronisation has taken place in a while
bool changed=false ;
QDateTime lastcalendarsync = isoStringToDateTime(gConf->getLastGoogleCalendarSyncDate()) ;
QDateTime lastcontactsync = isoStringToDateTime(gConf->getLastGoogleContactSyncDate()) ;
for (int i=0; i<db.size() && !changed; i++) {
if (db.getContact(i).getDate(Contact::Updated) > lastcontactsync)
changed=true ;
}
for (int i=0; i<calendar.size() && !changed; i++) {
if (calendar.getAppointment(i).getDate(Appointment::Updated) > lastcalendarsync)
changed=true ;
}
if (changed) {
QDateTime now = QDateTime::currentDateTimeUtc() ;
if (lastcalendarsync > now.addDays(14) || lastcontactsync > now.addDays(14)) {
warningOkDialog(this, "Contact Manager Warning", "You have made changes to contacts / calendar, and it is some time since you synchronised with google.") ;
}
}
// Tidy up old log files
dbg("Tidying old log files") ;
google.resetLogFiles();
// Setup Advanced Find
find = new AdvancedFind(this) ;
// Connect signals for password menu and calendar list
// ref: https://stackoverflow.com/questions/26422154/my-signal-slot-connection-does-not-work
connect(ui->menuKeyandPassword,
&QMenu::aboutToShow,
this,
&MainWindow::refreshPasswordMenu) ;
connect(ui->listCalendar,
&SafeListView::selectionChanged,
this,
&MainWindow::on_listCalendar_SelectionChanged) ;
QShortcut* delshortcut = new QShortcut(QKeySequence(Qt::Key_Delete), ui->listCalendar);
connect(delshortcut,
&QShortcut::activated,
this,
&MainWindow::on_actionRemoveAppointment_triggered) ;
// Timer ticks every second
timer = new QTimer(this);
connect(timer,
&QTimer::timeout,
this,
&MainWindow::tick) ;
timer->start(1000);
// Fire 'Goto Today' after initialisation complete
QTimer::singleShot(500, this, SLOT(on_initial_focus()));
dbg("Initialisation complete") ;
}
void MainWindow::on_initial_focus()
{
populateDialog(SELECT_OVERVIEW) ;
on_tabBar_currentChanged(1) ;
on_actionGotoToday_triggered() ;
}
void MainWindow::abort()
{
QApplication::exit() ;
}
MainWindow::~MainWindow()
{
// Save current details if required
SaveTabs() ;
play(FileSave) ;
ui->tabBar->setTabEnabled(CONTACTDETAILSTABPOS, false);
// Free up memory
if (gConf) delete gConf ; gConf=NULL ;
if (timer) delete timer ; timer=NULL ;
if (ui) delete ui; ui=NULL ;
if (enc) delete enc ; enc=NULL ;
if (find) delete find ; find=NULL ;
}
void MainWindow::refreshPasswordMenu()
{
bool loggedin = enc->loggedIn() ;
ui->actionSetEncryptionKey->setEnabled(!loggedin) ;
ui->actionChangePassword->setEnabled(!loggedin) ;
ui->actionLogout->setEnabled(loggedin) ;
}
////////////////////////////////////////////////////////////////////////////////
// Contact Navigation
//
// RefreshMenus
//
//
void MainWindow::refreshMenus(Contact &contact, bool isediting, bool isnew, bool resetcursorpos)
{
if (contact.isNull()) {
// With no Contact selected, only the Calendar is accessible
ui->tabBar->setTabEnabled(OVERVIEWTABPOS, false);
ui->tabBar->setTabEnabled(CALENDARTABPOS, true);
ui->tabBar->setTabEnabled(TODOTABPOS, false);
ui->tabBar->setTabEnabled(CONTACTDETAILSTABPOS, false);
ui->tabBar->setTabEnabled(HISTORYTABPOS, false);
// Enable appropriate menus
ui->actionDeleteContact->setEnabled(false) ;
ui->actionEnableContactDetailsEdit->setEnabled(false) ;
ui->actionEnableEditHistoryEdit->setEnabled(false) ;
ui->actionGotoJournal->setEnabled(false) ;
ui->actionGotoToDoList->setEnabled(false) ;
ui->actionNewAppointment->setEnabled(false) ;
ui->actionNewMyAppointment->setEnabled(true) ;
ui->action_Insert_Appointment_After->setEnabled(false) ;
ui->actionInsert_My_Appointment_After->setEnabled(true) ;
ui->actionIncome->setEnabled(false) ;
ui->actionPayment->setEnabled(false) ;
ui->action_Email_Contact->setEnabled(false) ;
ui->action_SMS_Contact->setEnabled(false) ;
} else if (isnew) {
// New Entry (not yet saved)
// Enable Tabs
ui->tabBar->setTabEnabled(OVERVIEWTABPOS, false);
ui->tabBar->setTabEnabled(CALENDARTABPOS, true);
ui->tabBar->setTabEnabled(TODOTABPOS, false);
ui->tabBar->setTabEnabled(CONTACTDETAILSTABPOS, true);
ui->tabBar->setTabEnabled(HISTORYTABPOS, false);
// Enable appropriate menus
ui->actionDeleteContact->setEnabled(false) ;
ui->actionEnableContactDetailsEdit->setEnabled(true) ;
ui->actionEnableEditHistoryEdit->setEnabled(false) ;
ui->actionGotoJournal->setEnabled(false) ;
ui->actionGotoToDoList->setEnabled(false) ;
ui->actionIncome->setEnabled(false) ;
ui->actionPayment->setEnabled(false) ;
ui->actionNewAppointment->setEnabled(false) ;
ui->actionNewMyAppointment->setEnabled(true) ;
ui->action_Insert_Appointment_After->setEnabled(false) ;
ui->actionInsert_My_Appointment_After->setEnabled(true) ;
ui->action_Email_Contact->setEnabled(false) ;
ui->action_SMS_Contact->setEnabled(false) ;
} else {
// Contact Selected / Opened
// Enable Tabs
ui->tabBar->setTabEnabled(OVERVIEWTABPOS, true);
ui->tabBar->setTabEnabled(CALENDARTABPOS, true);
ui->tabBar->setTabEnabled(TODOTABPOS, true);
ui->tabBar->setTabEnabled(CONTACTDETAILSTABPOS, isediting);
ui->tabBar->setTabEnabled(HISTORYTABPOS, true);
// Enable appropriate menus
ui->actionDeleteContact->setEnabled(true) ;
ui->actionEnableContactDetailsEdit->setEnabled(true) ;
ui->actionEnableEditHistoryEdit->setEnabled(true) ;
ui->actionGotoJournal->setEnabled(true) ;
ui->actionGotoToDoList->setEnabled(true) ;
ui->actionIncome->setEnabled(true) ;
ui->actionPayment->setEnabled(true) ;
ui->actionNewAppointment->setEnabled(true) ;
ui->actionNewMyAppointment->setEnabled(true) ;
ui->action_Insert_Appointment_After->setEnabled(true) ;
ui->actionInsert_My_Appointment_After->setEnabled(true) ;
ui->action_Email_Contact->setEnabled(true) ;
ui->action_SMS_Contact->setEnabled(true) ;
}
if (resetcursorpos) {
// Move to the selected tab
if (contact.isNull()) {
// No Contact
if (ui->tabBar->currentIndex()!=CALENDARTABPOS) {
dbg("tabBar->setCurrentIndex(CALENDARTABPOS)") ;
ui->tabBar->setCurrentIndex(CALENDARTABPOS) ;
}
dbg("listCalendar->setFocus()") ;
ui->listCalendar->setFocus() ;
} else if (isnew) {
// Create
if (ui->tabBar->currentIndex()!=CONTACTDETAILSTABPOS) {
dbg("tabBar->setCurrentIndex(CONTACTDETAILSTABPOS)") ;
ui->tabBar->setCurrentIndex(CONTACTDETAILSTABPOS);
}
dbg("editFirstName->setFocus()") ;
ui->editFirstName->setFocus() ;
} else {
// Open
if (ui->tabBar->currentIndex()!=OVERVIEWTABPOS) {
dbg("tabBar->setCurrentIndex(OVERVIEWTABPOS)") ;
ui->tabBar->setCurrentIndex(OVERVIEWTABPOS) ;
}
dbg("editOverview->setFocus()") ;
ui->editOverview->setFocus() ;
}
}
QString name = contact.getFormattedName(false, false) ;
setAccessibleTextAndWindowTitle(name) ;
}
//
// PopulateDialog
//
// Populate all of the dialog fields, and enable the
// appropriate tabs. Index is the index in the drop-down
// contacts menu.
//
void MainWindow::populateDialog(QString id, bool switchtooverview)
{
Contact& dro = db.getSelected() ;
QString oldid = dro.getField(Contact::ID) ;
// Save current contact & disable the editing tab
SaveTabs() ;
// If the contact has changed, force a switch to the overview tab
int currentindex = ui->tabBar->currentIndex() ;
bool contactdetailstabselected = (currentindex == CONTACTDETAILSTABPOS) ;
bool contactchanged = (!id.isEmpty() && oldid.compare(id)!=0) ;
if (!contactdetailstabselected || contactchanged) {
ui->tabBar->setTabEnabled(CONTACTDETAILSTABPOS, false);
}
if (contactchanged) {
switchtooverview=true ;
}
if (id.compare(SELECT_OVERVIEW)==0) {
// No Contact Selected
// -- Select Contact --
db.selectContact(id) ;
LoadTabs() ;
// And refresh the menus
refreshMenus(db.getSelected(), false, false, true) ;
// Goto Today
on_actionGotoToday_triggered() ;
} else if (id.compare(SELECT_ADDENTRY)==0) {
createContact() ;
} else {
// Open Contact
play(FileOpen) ;
db.selectContact(id) ;
LoadTabs() ;
refreshMenus(db.getSelected(), false, false, true) ;
if (switchtooverview) {
Contact &c = db.getSelected() ;
msg(QString("Switching contact to ") + c.getFormattedName(false,false) + QString(" (") + c.getField(Contact::ID) + QString(")")) ;
currentindex=OVERVIEWTABPOS ;
}
if (ui->tabBar->currentIndex()!=currentindex) {
dbg("tabBar->setCurrentIndex()") ;
ui->tabBar->setCurrentIndex(currentindex) ;
}
switch (currentindex) {
case OVERVIEWTABPOS:
dbg("editOverview->setFocus()") ;
ui->editOverview->setFocus() ;
break ;
case CALENDARTABPOS:
dbg("listCalendar->setFocus()") ;
ui->listCalendar->setFocus() ;
break ;
case TODOTABPOS:
dbg("editToDo->setFocus()") ;
ui->editToDo->setFocus() ;
break ;
case CONTACTDETAILSTABPOS:
break ;
case HISTORYTABPOS:
dbg("editHistory->setFocus()") ;
ui->editHistory->setFocus() ;
break ;
}
}
}
// TODO: Fix all tab-specific menu options
void MainWindow::on_tabBar_currentChanged(int index)
{
if (index==1) { // Calendar
ui->actionMoveAppointment->setEnabled(true) ;
ui->actionRemoveAppointment->setEnabled(true) ;
} else {
ui->actionMoveAppointment->setEnabled(false) ;
ui->actionRemoveAppointment->setEnabled(false) ;
}
if (index==3) { // Contact Details
ui->menuGoto_Contact_Details->setEnabled(true) ;
ui->actionE_Mail->setEnabled(true) ;
ui->action_Name->setEnabled(true) ;
ui->action_Address->setEnabled(true) ;
ui->action_Phone->setEnabled(true) ;
ui->action_Birthday->setEnabled(true) ;
} else {
ui->menuGoto_Contact_Details->setEnabled(false) ;
ui->actionE_Mail->setEnabled(false) ;
ui->action_Name->setEnabled(false) ;
ui->action_Address->setEnabled(false) ;
ui->action_Phone->setEnabled(false) ;
ui->action_Birthday->setEnabled(false) ;
}
}
//
// File I/O functions
//
void MainWindow::LoadTabs()
{
if (db.getSelected().isSet(Contact::Deleted)) {
// Select a blank entry, and refresh the screen / menus
db.selectContact(SELECT_OVERVIEW);
populateDialog(SELECT_OVERVIEW) ;
dbg("Contact has been deleted - de-selecting") ;
}
LoadOverviewTab() ;
LoadContactTab() ;
LoadCalendarTab() ;
LoadEditHistory() ;
LoadTodo() ;
}
void MainWindow::SaveTabs()
{
SaveTodo() ;
SaveEditHistory() ;
SaveCalendarTab();
SaveContactTab() ;
LoadOverviewTab() ;
db.save() ;
calendar.save() ;
}
//
// Menu Handlers
//
// FILE MENU
void MainWindow::on_actionSave_triggered()
{
// TODO: If the contact is a new one, at the moment, it has to be re-opened
// once saved. There is something open does that this does not - something to
// do with enabling menus?
msg("Saving Contact ...") ;
SaveTabs() ;
LoadOverviewTab() ;
LoadContactTab() ;
LoadEditHistory() ;
LoadTodo() ;
// Refresh menus, just in case the contact is a new one
int isediting = ui->tabBar->isTabEnabled(CONTACTDETAILSTABPOS) ;
refreshMenus(db.getSelected(), isediting, false, false) ;
play(FileSave) ;
}
void MainWindow::on_actionExit_triggered()
{
QApplication::quit() ;
}
void MainWindow::on_actionSetup_triggered()
{
gConf->SetupForm(&db, &google) ;
play(Query) ;
gConf->exec() ;
gConf->SaveForm() ;
}
//
// on_actionGoogleSync_triggered
//
//
void MainWindow::on_action_Google_Sync_triggered()
{
class GoogleUpdateDialog *frm ;
// Save tabs before sync
SaveTabs() ;
frm = new GoogleUpdateDialog(this) ;
play(Ok) ;
frm->doUpdate(google, db, calendar) ;
delete frm ;
// And re-load
LoadTabs() ;
}
void MainWindow::on_actionExportContacts_triggered()
{
QFileDialog fd ;
QString dir=QDir::homePath() ;
play(Query) ;
QString fileName = fd.getSaveFileName(this, tr("Contacts List File"),
dir,
tr("Text Files (*.txt)"));
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
// TODO: Report file open error
return ;
}
// TODO: update working directory from fd.
QTextStream out(&file);
out << "Contacts Database\n\n" ;
msg("Exporting ....") ;
db.sort() ;
for (int i=0; i<db.size(); i++) {
Contact& c = db.getContact(i) ;
if (!c.isSet(Contact::Deleted) && !c.isSet(Contact::Hidden)) {
out << c.getOverview(Contact::contactAsText) << "--------------------------------\n";
}
}
file.close() ;
msg("Exporting complete.") ;
}
void MainWindow::on_actionExportAppointments_triggered()
{
}
void MainWindow::on_actionShow_Log_triggered()
{
LogForm form ;
form.setText(getLog()) ;
play(Ok) ;
form.exec() ;
}
void MainWindow::msg(QString msg)
{
ui->statusBar->showMessage(msg, 6000) ;
}
void MainWindow::on_actionOpen_triggered()
{
ItemSelect list ;
QString thisid=db.getSelected().getField(Contact::ID) ;
list.setTitle("Contact Manager Open", "Load Contact");
list.addEntry("-- Add Contact --", SELECT_ADDENTRY) ;
for (int i=0, sz=db.size(); i<sz; i++) {
Contact& c=db.getContact(i) ;
if (!c.isSet(Contact::Deleted) && !c.isSet(Contact::Hidden)) {
QString name = c.getFormattedName() ;
QString data = c.getField(Contact::ID) ;
list.addEntry(name, data) ;
}
}
list.selectData(thisid) ;
if (list.index()<=0) list.setIndex(1) ;
play(Query) ;
bool result = list.exec() ;
if (result) {
QString data=list.getData() ;
populateDialog(data) ;
}
}
void MainWindow::on_actionGotoJournal_triggered()
{
Contact &c = db.getSelected() ;
if (c.isNull()) {
play(NotFound) ;
} else {
QString file = gConf->getJournalPath(c.getFormattedName(false, false)) ;
QString app = gConf->getEasyNotepadPath() ;
if (app.isEmpty() || file.isEmpty()) {
errorOkDialog(this, "Error, Not Configured", "EasyNotepad path or Journal folder not configured") ;
} else {
QStringList args ;
args.append(file) ;
QProcess *myProcess = new QProcess(NULL) ;
myProcess->start(app, args) ;
}
}
}
// Tick triggered every second
void MainWindow::tick()
{
static int everyhour=1800 ; // First backup occurs in 30 minutes
static int everyday=86400 ;
if ((++everyhour)>=3600) {
everyhour=0 ;
doBackup() ;
}
if (gConf->getEnableReminders()) {
if ((++everyday)>86400) {
everyday=0 ;
int balance = GetSMSBalance() ;
addLog(QString("SMS Balance = ") + QString::number(balance)) ;
if (balance>=0 && balance<100) {
warningOkDialog(this,"Send SMS", "You have low SMS credit") ;
}
}
sendMailSMS() ;
}
}
void MainWindow::on_action_Email_Contact_triggered()
{
Contact &c = db.getSelected() ;
QString email, name ;
email = c.getField(Contact::Email) ;
if (email.isEmpty()) email = c.getField(Contact::Email2) ;
name = c.getFormattedName() ;
if (email.isEmpty()) {
warningOkDialog(this, "Email Not Found", "The current contact does not have an email address") ;
return ;
}
QString cmd = gConf->getEmailCommand(name, email) ;
if (cmd.isEmpty()) {
errorOkDialog(this, "Error, Not Configured", "Mail program not configured") ;
return ;
}
QProcess *myProcess = new QProcess(NULL) ;
QStringList args = cmd.split( QRegularExpression(" (?=[^\"]*(\"[^\"]*\"[^\"]*)*$)") );
for (int a=0; a<args.length(); a++) {
QString entry = args.at(a) ;
entry = entry.replace("\\\"", "***REALQUOTE***") ;
entry = entry.replace("\"", "") ;
entry = entry.replace("***REALQUOTE***", "\\\"") ;
args.replace(a, entry) ;
}
QString app = args.at(0) ;
args.removeAt(0) ;
myProcess->start(app, args) ;
// TODO: Check for error launching
}
void MainWindow::on_action_SMS_Contact_triggered()
{
Contact& c = db.getSelected() ;
QString mobile = c.getField(Contact::Mobile) ;
if (c.isNull() || mobile.isEmpty()) {
warningOkDialog(this, "Unable to Send", "No contact is selected, or the current contact does not have a mobile") ;
}
SendSMSForm smsform ;
smsform.setRecipient(c.getFormattedName(false, true) + QString(" (") + c.getField(Contact::Mobile) + QString(")")) ;
play(Query) ;
if (smsform.exec()) {
// TODO: from should be gConf->getSMSFrom() ;
QString from = QString("") ;
QString message = smsform.getMessage() ;
if (message.isEmpty()) {
warningOkDialog(this, "Unable to Send", "No Message Provided") ;
} else {
SMS sms(gConf->getSMSAgent(), gConf->getSMSUsername(), gConf->getSMSPassword()) ;
bool success = sms.send(mobile, from, message) ;
int balance = sms.getBalance() ;
if (!success) {
if (balance>=0 && balance<30) {
warningOkDialog(this, "Unable to Send", "Low Balance / Out of Credit.") ;
} else {
warningOkDialog(this, "Unable to Send", "Send Message Failed.") ;
}
} else {
if (balance<0) {
warningOkDialog(this, "Message Sent", "Message sent successfully. Unable to get balance.") ;
} else {
warningOkDialog(this, "Message Sent", "Message sent successfully. Balance = £" + QString::number(balance/100) + QString(".") + QString::number(balance%100) ) ;
}
c.getHistory().addEntry(QString("Sent SMS: ") + message) ;
LoadEditHistory() ;
}
}
}
}
void MainWindow::setAccessibleTextAndWindowTitle(QString name)
{
dbg(QString("setAccessibleTextAndWindowTitle(%1)").arg(name)) ;
// Setup the accessible text, window name etc, to include the current contact
if (name.isEmpty()) {
setWindowTitle("Contact Manager") ;
ui->editOverview->setAccessibleDescription("Overview") ;
ui->editHistory->setAccessibleDescription("History") ;
ui->editToDo->setAccessibleDescription("To Do List") ;
} else {
setWindowTitle(name + " - Contact Manager") ;
ui->editOverview->setAccessibleDescription("Overview for " + name) ;
ui->editHistory->setAccessibleDescription("History for " + name) ;
ui->editToDo->setAccessibleDescription("To Do List for " + name) ;
}
dbg("title set complete") ;
}
void MainWindow::createContact()
{
// Add new contact
play(FileOpen) ;
// -- Add and select Contact --
db.selectContact(db.addContact()) ;
LoadTabs() ;
// Enable the menus
refreshMenus(db.getSelected(),true,true,true) ;
}
void MainWindow::on_actionNewContact_triggered()
{
createContact() ;
}
//
// Password Functions
//
void MainWindow::on_actionSetEncryptionKey_triggered()
{
if (enc) enc->setKey();
}
void MainWindow::on_actionChangePassword_triggered()
{
if (enc) enc->changePassword();
}
void MainWindow::on_actionLogout_triggered()
{
if (enc) enc->logout();
}