-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogleupdatedialog.cpp
163 lines (121 loc) · 4.87 KB
/
googleupdatedialog.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
#include "googleupdatedialog.h"
#include "ui_googleupdatedialog.h"
#include "configuration.h"
#include "../Lib/supportfunctions.h"
#include "../Lib/alertsound.h"
#include "contactdatabase.h"
#include "calendar.h"
#include "contact.h"
GoogleUpdateDialog::GoogleUpdateDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::GoogleUpdateDialog)
{
state = 0 ;
ui->setupUi(this);
}
GoogleUpdateDialog::~GoogleUpdateDialog()
{
delete ui;
}
int GoogleUpdateDialog::doUpdate(GoogleAccess& google, class ContactDatabase& db, class Calendar& cal)
{
state = 1 ; // Processing
ui->progressBar->setRange(0, 1000);
ui->progressBar->setValue(0) ;
setModal(true) ;
ui->pushButton->setAccessibleName("Abort Update") ;
ui->pushButton->setText("Abort Update");
show() ;
ui->pushButton->setFocus() ;
// Set the OAUTH2 Refresh Token
QString refreshtoken = gConf->getGoogleOauth2RefreshToken() ;
google.setupRToken(refreshtoken) ;
// Set the sync tokens before synchronisation
// google.setCalendarSyncToken(gConf->getLastGoogleCalendarSyncToken());
// google.setContactSyncToken(gConf->getLastGoogleContactSyncToken());
QString contactsyncdatestr = gConf->getLastGoogleContactSyncDate() ;
QDateTime contactsyncdate = isoStringToDateTime(contactsyncdatestr) ;
QString calendarsyncdatestr = gConf->getLastGoogleCalendarSyncDate() ;
QDateTime calendarsyncdate = isoStringToDateTime(calendarsyncdatestr) ;
bool calsuccess = true ;
ui->updateStatusReport->append(QString("\nSYNCHRONISING CALENDAR")) ;
if (gConf->calendarSyncEnabled()) {
ui->updateStatusReport->append(QString("\nSYNCHRONISING CALENDAR")) ;
ui->updateStatusReport->append(QString("Last Calendar Synchronisation Date: ") + calendarsyncdatestr ) ;
calsuccess = processCalendarUpdate(calendarsyncdate, google, cal) ;
if (!calsuccess) {
ui->updateStatusReport->append(QString("CALENDAR SYNCHRONISATION FAILED: ") + google.getNetworkError()) ;
} else {
// Sleep to allow local changes that have been made during the sync to be
// recorded as before the sync, to prevent re-syncing
qSleep(1000) ;
QString nextsyncdate = nowToIsoString() ;
gConf->setLastGoogleCalendarSyncDate(nextsyncdate) ;
// And store sync token for next time
// gConf->setLastGoogleCalendarSyncToken(google.getCalendarSyncToken());
ui->updateStatusReport->append(QString("CALENDAR SYCHRONISATION SUCCESS.")) ;
}
} else {
ui->updateStatusReport->append(QString("Calendar Synchronisation disabled in configuration.")) ;
}
ui->progressBar->setValue(500) ;
bool consuccess = true ;
ui->updateStatusReport->append(QString("\nSYNCHRONISING CONTACTS")) ;
if (gConf->contactSyncEnabled()) {
ui->updateStatusReport->append(QString("Last Contact Synchronisation Date: ") + contactsyncdatestr ) ;
consuccess = processContactUpdate(contactsyncdate, google, db) ;
if (!consuccess) {
ui->updateStatusReport->append(QString("CONTACTS SYNCHRONISATION FAILED: ") + google.getNetworkError()) ;
} else {
// next syncdate after sync means anything changed on google during the sync may be lost
qSleep(1000) ;
QString nextsyncdate = nowToIsoString() ;
gConf->setLastGoogleContactSyncDate(nextsyncdate) ;
// And store sync token for next time
// gConf->setLastGoogleContactSyncToken(google.getContactSyncToken());
ui->updateStatusReport->append(QString("CONTACTS SYCHRONISATION SUCCESS.")) ;
}
} else {
ui->updateStatusReport->append(QString("Calendar Synchronisation disabled in configuration.")) ;
}
ui->updateStatusReport->append(QString("")) ;
ui->progressBar->setValue(1000) ;
play(Query) ;
if (state<0) {
// Abort Pressed
} else {
// Update button labels and wait for press
if (consuccess && calsuccess) {
ui->pushButton->setAccessibleName("Update Complete") ;
ui->pushButton->setText("Update Complete");
ui->pushButton->setFocus() ;
state = 2 ;
} else {
ui->pushButton->setAccessibleName("Update Failed") ;
ui->pushButton->setText("Update Failed");
ui->pushButton->setFocus() ;
state = 3 ;
}
exec() ;
}
hide() ;
return state ;
}
// Abort Button
void GoogleUpdateDialog::on_pushButton_clicked()
{
switch (state) {
case 0: // Not Running
state=0 ;
break ;
case 1: // Running, Abort Pressed
state=-1 ;
break ;
case 2: // Finished (Success), OK Pressed
accept() ;
break ;
case 3: // Finished (Failure), OK Pressed
accept() ;
break ;
}
}