Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Altered frmActivityMgr to accommodate for SSL support for OS X (and other OSes in...
[xestiaab/.git] / source / actmgr / frmActivityMgr.cpp
1 // frmActivityMgr.cpp - Activity Manager form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmActivityMgr.h"
20 #include <wx/mstream.h>
21 #include <wx/file.h>
22 #include <wx/ffile.h>
23 #include <wx/tokenzr.h>
24 #include <wx/dir.h>
25 #include <wx/filefn.h>
26 #include <thread>
27 #include <list>
28 #include <curl/curl.h>
30 #include "../bitmaps.h"
31 #include "../enums.h"
32 #include "../common/preferences.h"
33 #include "../frmConflictResolution.h"
34 #include "../frmInvalidSSLCertificate.h"
35 #include "../frmMain.h"
36 #include "../common/events.h"
37 #include "../common/filename.h"
38 #include "../vcard/vcard34conv.h"
39 #include "../vcard/vcard.h"
41 #ifndef FRMACTIVITYMGR_H
42 #define FRMACTIVITYMGR_H
44 DEFINE_EVENT_TYPE(ACTMGR_RESUMEPROC);
45 DEFINE_EVENT_TYPE(ACTMGR_TOGGLECONN);
46 DEFINE_EVENT_TYPE(ACTMGR_STARTTIMER);
47 DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
48 DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
49 DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
50 DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
52 BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
53   EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
54   EVT_COMMAND(wxID_ANY, ACTMGR_TOGGLECONN, frmActivityMgr::ToggleConnectionStatus)
55   EVT_COMMAND(wxID_ANY, ACTMGR_STARTTIMER, frmActivityMgr::StartTimer)
56   EVT_COMMAND(wxID_ANY, ACTMGR_STOPTIMER, frmActivityMgr::StopTimer)
57   EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
58   EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
59   EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
60 END_EVENT_TABLE()
62 frmActivityMgr::frmActivityMgr( wxWindow* parent )
63 :
64 frmActivityMgrADT( parent )
65 {
67         wxMemoryInputStream istream(icons_activitywindow_png, sizeof(icons_activitywindow_png));
68         wxImage icons_activitywindow_pngi(istream, wxBITMAP_TYPE_PNG);
69         wxBitmap activityiconbmp(icons_activitywindow_pngi, -1);
70         wxIcon activityicon;
71         activityicon.CopyFromBitmap(activityiconbmp);
72         this->SetIcon(activityicon); 
74         wxMemoryInputStream istream2(misc_activitysleep_png, sizeof(misc_activitysleep_png));
75         wxImage misc_activitysleep_pngi(istream2, wxBITMAP_TYPE_PNG);
76         wxBitmap sleepiconbmp(misc_activitysleep_pngi, -1);
77         SleepBitmap = sleepiconbmp;
78         bmpActivity->SetBitmap(SleepBitmap);
79         ActProcessTimer.SetupPointers(this);
80         lblDetails->SetLabel(_("No activity."));
81         
82         ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail, 
83                                         &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
84                                         &ActProcessTimer, &ActivityListFinDate, &ActivityListConn);
85         
86         AnimationTimer.SetBitmap(bmpActivity);
87         AnimationTimer.SetSleepBitmap(&SleepBitmap);
88         AnimationTimer.SetupPointer(this->GetParent());
89         
90         wxListItem ColumnData;
91         ColumnData.SetId(0);
92         ColumnData.SetText(_("Activity"));
93         ColumnData.SetWidth(175);
94         lstActivity->InsertColumn(0, ColumnData);
95         
96         wxListItem ColumnData2;
97         ColumnData2.SetId(1);
98         ColumnData2.SetText(_("Account"));
99         ColumnData2.SetWidth(100);
100         lstActivity->InsertColumn(1, ColumnData2);
102         wxListItem ColumnData3;
103         ColumnData3.SetId(2);
104         ColumnData3.SetText(_("Status"));
105         ColumnData3.SetWidth(100);
106         lstActivity->InsertColumn(2, ColumnData3);
107         
108         //AnimationTimer.StartAnimation();
109         
110         // Create recovery database if it doesn't exist.
111         
112         wxString RecoveryFilename = GetRecoveryDB();
113         
114         wxFile RecoveryDB;
115         
116         if (wxFile::Exists(RecoveryFilename) == FALSE){
117         
118                 // Create the recovery database.
120                 RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);       
121         
122                 RecoveryDB.Write(wxT("BEGIN:XAB-RECOVERYDB\r\n"), wxConvUTF8);
123                 RecoveryDB.Write(wxT("VERSION:1.0\r\n"), wxConvUTF8);
124                 RecoveryDB.Write(wxT("COMMENT:Please do not alter or delete this file. DATA LOSS IS POSSIBLE!\r\n"), wxConvUTF8);
125                 RecoveryDB.Write(wxT("END:XAB-RECOVERYDB\r\n"), wxConvUTF8);
126                 RecoveryDB.Close();
128         }
129         
130         wxFFile RecoveryDBF;
131         
132 #if wxABI_VERSION < 20900
133         RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
134 #else
135         RecoveryDBF.Open(RecoveryFilename, wxT("r"));
136 #endif  
137         
138         // Load the recovery database for tasks not done.
139         
140         if (RecoveryDBF.IsOpened() == TRUE){
141         
142                 wxString wxSRecoveryDB;
143                 wxString RecoveryLine;
144         
145                 // Check if we are using wxWidgets version 2.8 or less and
146                 // execute the required command accordingly.
147         
148                 RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
149         
150                 // Split the lines.
151         
152                 std::map<int, wxString> RecoveryFileLines;
153                 std::map<int, wxString>::iterator striter;
154         
155                 wxStringTokenizer wSTRecoveryDBLines(wxSRecoveryDB, wxT("\r\n"));
157                 int RecoveryLineSeek = 0;
159                 while (wSTRecoveryDBLines.HasMoreTokens() == TRUE){
161                         RecoveryLine = wSTRecoveryDBLines.GetNextToken();
162                         RecoveryFileLines.insert(std::make_pair(RecoveryLineSeek, RecoveryLine));
163                         RecoveryLineSeek++;             
164         
165                 }
166         
167         }
168         
171         //TestTimer.Start(50, FALSE);
174 void frmActivityMgr::OpenWindow()
176         WindowOpen = TRUE;
179 void frmActivityMgr::CloseWindow( wxCommandEvent& event )
181         WindowOpen = FALSE;
182         this->Hide();
185 void frmActivityMgr::CloseWindow( wxCloseEvent& event )
187         WindowOpen = FALSE;
188         this->Hide();
191 void frmActivityMgr::ProcessTasksThread()
193         
194         if (ProcessTasksData == FALSE){
195         
196                 return;
197         
198         }
199         
200         std::map<int,int>::iterator TypeIter;
201         std::map<int,wxString>::iterator StringIter;
202         std::map<int,wxString>::iterator StringDataIter;
203         std::map<int,wxString>::iterator StringURLIter;
204         std::map<int,wxString>::iterator StringDetailIter;
205         std::map<int,wxString>::iterator StringAccountIter;
206         std::map<int,wxString>::iterator StringFilenameIter;
207         std::map<int,wxString>::iterator StringFullFilenameIter;
208         std::map<int,wxString>::iterator StringTaskDetailIter;
209         std::map<int,wxString>::iterator StringETagIter;
210         std::map<int,wxString>::iterator StringETagOrigIter;
211         std::map<int,CardDAV*>::iterator CardDAVIter;
212         std::map<int,ActivityMgrAccountSettings>::iterator AccountSettingsIter;
213         std::map<int,long>::iterator LongIter;
214         bool TasksFoundProc = FALSE;
215         wxString TaskDetail;
216         
217         for (std::map<int,int>::iterator iter = ActivityList.begin(); 
218          iter != ActivityList.end(); ++iter){
219          
220                 // Check for any queued tasks and start one.
221                 
222                 if (iter->second > 4){
223                         continue;
224                 }
225                 
226                 CardDAVIter = ActivityListConn.find(iter->first);
227                 TypeIter = ActivityListType.find(iter->first);
228                 StringETagIter = ActivityListETag.find(iter->first);
229                 StringETagOrigIter = ActivityListETagOriginal.find(iter->first);
230                 StringAccountIter = ActivityListAccount.find(iter->first);
231                 StringFilenameIter = ActivityListFilename.find(iter->first);
232                 StringFullFilenameIter = ActivityListFullFilename.find(iter->first);
233                 AccountSettingsIter = ActivityListAccSettings.find(iter->first);
234                 
235                 // Setup the CardDAV object.
236                 
237                 CardDAV ConnHandle;
238                 
239                 ConnHandle.SetupConnection(AccountSettingsIter->second.Address,
240                                          AccountSettingsIter->second.Port,
241                                          AccountSettingsIter->second.Username,
242                                          AccountSettingsIter->second.Password,
243                                          AccountSettingsIter->second.SSL,
244                                          AccountSettingsIter->second.Prefix,
245                                          AccountSettingsIter->second.Dir);
246                 ConnHandle.SetupVariables(&ActivityList, iter->first);
247                 ConnHandle.SetupResultBools(&BlankBool, &BlankBool);
248                 
249                 // 0 = Queued.
250                 // 1 = Processing.
251                 // 2 = Failed.
252                 // 3 = Stopped.
253                 // 4 = Completed.
254                 // 5 = Failed (UI Updated).
255                 // 6 = Stopped (UI Updated).
256                 // 7 = (Reserved) (UI Updated).
257                 // 8 = Completed. (UI Updated). 
258                 
259                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
260                 XABPreferences PrefData(GetUserPrefDir());
261                 
262                 if (iter->second == 0){
263                 
264                         //CardDAVIter->second.
265                         
266                         // Wait for process to finish.
268                         TasksActive = TRUE;
269                         TasksFoundProc = TRUE;
270                         wxString ETag;
271                         wxString ETagOriginal;
272                         wxString ETagServer;
273                         wxString AccountDir;
274                         wxString ContactFilename;
275                         wxString FullFilename;
276                         wxString ETagResult;
277                         bool EditMode = FALSE;
279                         iter->second = 1;
280                         
281                         // Compare the ETags and work out if a conflict has occured.
282                         
283                         if (TypeIter->second == 0){
284                         
285                                 // Add a contact.
286                                 
287                                 StringDataIter = ActivityListData.find(iter->first);
288                                 StringURLIter = ActivityListURL.find(iter->first);
289                                 
290                                 AccountDir = StringAccountIter->second;
291                                 ContactFilename = StringFilenameIter->second;
292                                 wxString AccountNameFriendly;
293                                 
294                                 int AccountID = 0;
295                                 
296                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
297                                         
298                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
299                                         
300                                         AccountDirCheck.Trim();
301                                         AccountDirCheck.Append(wxT(".carddav"));
302                                         
303                                         if (AccountDirCheck == StringAccountIter->second){
304                                                 
305                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
306                                                 AccountID = i;
307                                                 
308                                         }
309                                         
310                                 }
311                                 
312                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
313                                 
314                                 ETag = StringETagIter->second;
315                                 ETagOriginal = StringETagOrigIter->second;
316                                 AccountDir = StringAccountIter->second;
317                                 ContactFilename = StringFilenameIter->second;
318                                 FullFilename = StringFullFilenameIter->second;
319                                 EditMode = ActivityListEditMode.find(iter->first)->second;
320                                 
321                                 bool KeepUpdating = TRUE;
322                                 
323                                 while(KeepUpdating == TRUE){
324                                         
325                                         bool ExitLoop = FALSE;
326                                         
327                                         while (ExitLoop == FALSE){
328                                                 
329                                                 ConnHandle.SetUploadMode(TRUE);
330                                                 ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
331                                                 ConnHandle.SetEditMode(EditMode);
332                                                 ConnHandle.ProcessData();
333                                                 
334                                                 int ErrorCode = ConnHandle.GetResultCode();
335                                                 
336                                                 if (ErrorCode != 0){
337                                                         
338                                                         if (ErrorCode == 60 || ErrorCode == 51){
339                                                                 
340                                                                 // Invalid SSL certificate so bring up a dialog to the user
341                                                                 // explaining what has happened and the options available.
342                                                                 
343                                                                 // Stop all the timers.
344                                                                 
345                                                                 frmMainPtrGet->PauseAllTimers();
346                                                                 
347                                                                 int SSLResult;
348                                                                 
349 #if defined(__APPLE__)
350                                                                 
351                                                                 // Bring up the trust panel and display the SSL certificate dialog.
352                                                                 
353                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
354                                                                 
355                                                                 // Update the SSL account with the trust object.
356                                                                 
357                                                                 if (SSLResult != NSOKButton){
358                                                                         
359                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
360                                                                         iter->second = 2;
361                                                                         break;
362                                                                         
363                                                                 } else {
364                                                                         
365                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
366                                                                         
367                                                                 }
368 #else
369                                                                 
370                                                                 // Setup the data to be sent in the wxPostEvent command.
371                                                                 
372                                                                 SSLInvalidCertNotifObj SSLICNProcData;
373                                                                 
374                                                                 bool *PauseMode = new bool;
375                                                                 QRNotif qrn;
376                                                                 
377                                                                 *PauseMode = TRUE;
378                                                                 qrn.QResponse = &SSLResult;
379                                                                 qrn.PausePtr = PauseMode;
380                                                                 
381                                                                 SSLICNProcData.CertCollection = certcol;
382                                                                 SSLICNProcData.QRNotifData = &qrn;
383                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
384                                                                 
385                                                                 wxCommandEvent event(INVALIDSSLCERT);
386                                                                 event.SetClientData(&SSLICNProcData);
387                                                                 wxPostEvent(frmMainPtrGet, event);
388                                                                 
389                                                                 /*timespec n1, n2;
390                                                                  
391                                                                         // Fall asleep until we get an response.
392                                                                  
393                                                                         n1.tv_sec = 0;
394                                                                         n1.tv_nsec = 250000000L;*/
395                                                                 
396                                                                 while (*PauseMode == TRUE){
397                                                                         //nanosleep(&n1, &n2);
398                                                                         SleepFor(250000000);
399                                                                 }
400                                                                 
401                                                                 // Process the response from the user.
402                                                                 
403                                                                 if (SSLResult == 1){
404                                                                         
405                                                                         // Accept the certificate. Write the certificate into the account
406                                                                         // directory (as server.crt) - will overwrite old certificate.
407                                                                         
408                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
409                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
410                                                                         
411                                                                 } else if (SSLResult == 2){
412                                                                         
413                                                                         // Reject the certificate, abort the task and mark as failed.
414                                                                         
415                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
416                                                                         iter->second = 2;
417                                                                         break;
418                                                                         
419                                                                 }
420                                                                 
421 #endif
422                                                                 
423                                                                 // Resume all the timers.
424                                                                 
425                                                                 frmMainPtrGet->ResumeAllTimers();
426                                                                 ExitLoop = TRUE;
427                                                                 
428                                                         } else {
429                                                                 
430                                                                 iter->second = 2;
431                                                                 break;
432                                                                 
433                                                         }
434                                                         
435                                                 } else {
436                                                         
437                                                         ExitLoop = TRUE;
438                                                         
439                                                 }
440                                                 
441                                         }
442                                         
443                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
444                                                 break;
445                                         }
446                                         
447 #if defined(__APPLE__)
448                                         
449                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
450                                         
451 #else
452                                         
453                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
454                                         
455 #endif
456                                         
457                                         // Add contact to the ETag DB.
458                                         
459                                         ConnHandle.GetServerETagValueThread();
460                                         ETagServer = ConnHandle.ETagValueResult();
461                                         ETagDBPtr->AddETag(ContactFilename, ETagServer, ETagServer);
462                                         
463                                         iter->second = 4;
464                                         CardDAVIter->second = NULL;
465                                         break;
466                                         
467                                 }
468                                 
469                         } else if (TypeIter->second == 1){
470                                 
471                                 // Update a contact.
472                                 
473                                 StringDataIter = ActivityListData.find(iter->first);
474                                 StringURLIter = ActivityListURL.find(iter->first);
475                                 
476                                 AccountDir = StringAccountIter->second;
477                                 ContactFilename = StringFilenameIter->second;
478                                 wxString AccountNameFriendly;
479                                 
480                                 int AccountID = 0;
481                                 
482                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
483                                         
484                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
485                                         
486                                         AccountDirCheck.Trim();
487                                         AccountDirCheck.Append(wxT(".carddav"));
488                                         
489                                         if (AccountDirCheck == StringAccountIter->second){
490                                                 
491                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
492                                                 AccountID = i;
493                                                 
494                                         }
495                                         
496                                 }
497                                 
498                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
499                                 
500                                 ETag = StringETagIter->second;
501                                 ETagOriginal = StringETagOrigIter->second;
502                                 AccountDir = StringAccountIter->second;
503                                 ContactFilename = StringFilenameIter->second;
504                                 FullFilename = StringFullFilenameIter->second;
505                                 EditMode = ActivityListEditMode.find(iter->first)->second;
506                                 
507                                 bool KeepUpdating = TRUE;
508                                 
509                                 while(KeepUpdating == TRUE){
510                                         
511                                         bool ExitLoop = FALSE;
512                                         
513                                         while (ExitLoop == FALSE){
514                                                 
515                                                 ConnHandle.SetUploadMode(TRUE);
516                                                 ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
517                                                 ConnHandle.SetEditMode(EditMode);
518                                                 ConnHandle.GetServerETagValueThread();
519                                                 ETagServer = ConnHandle.ETagValueResult();
520                                                 
521                                                 int ErrorCode = ConnHandle.GetResultCode();
522                                                 
523                                                 if (ErrorCode != 0){
524                                                         
525                                                         if (ErrorCode == 60 || ErrorCode == 51){
526                                                                 
527                                                                 // Invalid SSL certificate so bring up a dialog to the user
528                                                                 // explaining what has happened and the options available.
529                                                                 
530                                                                 // Stop all the timers.
531                                                                 
532                                                                 frmMainPtrGet->PauseAllTimers();
533                                                                 
534                                                                 int SSLResult;
535                                                                 
536 #if defined(__APPLE__)
537                                                                 
538                                                                 // Bring up the trust panel and display the SSL certificate dialog.
539                                                                 
540                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
541                                                                 
542                                                                 // Update the SSL account with the trust object.
543                                                                 
544                                                                 if (SSLResult != NSOKButton){
545                                                                         
546                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
547                                                                         iter->second = 2;
548                                                                         break;
549                                                                         
550                                                                 } else {
551                                                                         
552                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
553                                                                         
554                                                                 }
555 #else
556                                                                 
557                                                                 // Setup the data to be sent in the wxPostEvent command.
558                                                                 
559                                                                 SSLInvalidCertNotifObj SSLICNProcData;
560                                                                 
561                                                                 bool *PauseMode = new bool;
562                                                                 QRNotif qrn;
563                                                                 
564                                                                 *PauseMode = TRUE;
565                                                                 qrn.QResponse = &SSLResult;
566                                                                 qrn.PausePtr = PauseMode;
567                                                                 
568                                                                 SSLICNProcData.CertCollection = certcol;
569                                                                 SSLICNProcData.QRNotifData = &qrn;
570                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
571                                                                 
572                                                                 wxCommandEvent event(INVALIDSSLCERT);
573                                                                 event.SetClientData(&SSLICNProcData);
574                                                                 wxPostEvent(frmMainPtrGet, event);
575                                                                 
576                                                                 while (*PauseMode == TRUE){
577                                                                         //nanosleep(&n1, &n2);
578                                                                         SleepFor(250000000);
579                                                                 }
580                                                                 
581                                                                 // Process the response from the user.
582                                                                 
583                                                                 if (SSLResult == 1){
584                                                                         
585                                                                         // Accept the certificate. Write the certificate into the account
586                                                                         // directory (as server.crt) - will overwrite old certificate.
587                                                                         
588                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
589                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
590                                                                         
591                                                                 } else if (SSLResult == 2){
592                                                                         
593                                                                         // Reject the certificate, abort the task and mark as failed.
594                                                                         
595                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
596                                                                         iter->second = 2;
597                                                                         break;
598                                                                         
599                                                                 }
600                                                                 
601 #endif
602                                                                 
603                                                                 // Resume all the timers.
604                                                                 
605                                                                 frmMainPtrGet->ResumeAllTimers();
606                                                                 ExitLoop = TRUE;
607                                                                 
608                                                         } else {
609                                                                 
610                                                                 iter->second = 2;
611                                                                 break;
612                                                                 
613                                                         }
614                                                         
615                                                 } else {
616                                                         
617                                                         ExitLoop = TRUE;
618                                                         
619                                                 }
620                                                 
621                                         }
622                                         
623                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
624                                                 break;
625                                         }
626                                         
627 #if defined(__APPLE__)
628                                         
629                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
630                                         
631 #else
632                                         
633                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
634                                         
635 #endif
636                                         
637                                         // Compare the ETag with the Server ETag.
638                                         
639                                         if (ETagOriginal != ETagServer){
640                                                 
641                                                 // Server ETag is different from original ETag.
642                                                 // This is a conflict which the user will now
643                                                 // need to resolve.
644                                                 
645                                                 vCard Moo1;
646                                                 vCard Moo2;
647                                                 
648                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
649                                                 
650                                                 vCard34Conv vCard34Obj;
651                                                 
652                                                 wxString ServerContactData;
653                                                 vCard ClientData;
654                                                 vCard ConvertedV4Data;
655                                                 
656                                                 // Load the client data from the filename given.
657                                                 
658                                                 ConnHandle.GetServerContactData();
659                                                 ServerContactData = ConnHandle.GetPageData();
660                                                 
661                                                 // Process v3 version into v4 version.
662                                                 
663                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
664                                                 
665                                                 vCardConflictObj vCardProcData;
666                                                 
667                                                 vCardProcData.vCardLocalData = &ClientData;
668                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
669                                                 ClientData.LoadFile(FullFilename);
670                                                 
671                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
672                                                 //event.SetData(ContactFilename, Moo1, Moo2);
673                                                 
674                                                 //wxPostEvent(frmMainPtrGet, event);
675                                                 
676                                                 // Setup Conflict Resolution Dialog.
677                                                 
678                                                 // Fetch Data from Server and convert.
679                                                 
680                                                 bool *PauseMode = new bool;
681                                                 int ConflictResult;
682                                                 QRNotif qrn;
683                                                 
684                                                 *PauseMode = TRUE;
685                                                 qrn.QResponse = &ConflictResult;
686                                                 qrn.PausePtr = PauseMode;
687                                                 
688                                                 vCardProcData.QRNotifData = &qrn;
689                                                 
690                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
691                                                 event.SetClientData(&vCardProcData);
692                                                 wxPostEvent(frmMainPtrGet, event);
693                                                 
694                                                 while (*PauseMode == TRUE){
695                                                         //nanosleep(&n1, &n2);
696                                                         SleepFor(250000000);
697                                                 }
698                                                 
699                                                 delete PauseMode;
700                                                 PauseMode = NULL;
701                                                 
702                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
703                                                 
704                                                 if (ConflictResult == 0){
705                                                         
706                                                         // Decide Later.
707                                                         
708                                                         iter->second = 4;
709                                                         break;
710                                                         
711                                                 } else if (ConflictResult == 1){
712                                                         
713                                                         // Decided to use client version.
714                                                         
715                                                         ConnHandle.ProcessData();
716                                                         
717                                                 } else if (ConflictResult == 2){
718                                                         
719                                                         // Decided to use server version.
720                                                         
721                                                         // Download server version.
722                                                         
723                                                         ConvertedV4Data.WriteFile(FullFilename);
724                                                         
725                                                 }
726                                                 
727                                         } else {
728                                                 
729                                                 // Update the data to the server.
730                                                 
731                                                 ConnHandle.ProcessData();
732                                                 
733                                         }
734                                         
735                                         // Update the ETag DB.
736                                         
737                                         ConnHandle.GetServerETagValueThread();
738                                         ETagServer = ConnHandle.ETagValueResult();
739                                         ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
740                                         
741                                         iter->second = 4;
742                                         break;
743                                         
744                                 }
745                         
746                         } else if (TypeIter->second == 2) {
747                         
748                                 // Delete the contact from the server and update the ETag DB.
749                                 
750                                 AccountDir = StringAccountIter->second;
751                                 ContactFilename = StringFilenameIter->second;
752                                 wxString AccountNameFriendly;
753                                 
754                                 int AccountID = 0;
755                                 
756                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
757                                         
758                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
759                                         
760                                         AccountDirCheck.Trim();
761                                         AccountDirCheck.Append(wxT(".carddav"));
762                                         
763                                         if (AccountDirCheck == StringAccountIter->second){
764                                                 
765                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
766                                                 AccountID = i;
767                                                 
768                                         }
769                                         
770                                 }
771                                 
772                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
773                                 
774                                 bool KeepUpdating = TRUE;
775                                 
776                                 while(KeepUpdating == TRUE){
777                                 
778                                         bool ExitLoop = FALSE;
779                                         
780                                         while (ExitLoop == FALSE){
781                                                 
782                                                 ConnHandle.SetUploadMode(FALSE);
783                                                 ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
784                                                 ConnHandle.ProcessData();
785                                                 SSLCertCollection certcol = ConnHandle.GetCertificateData();
786                                                 
787                                                 // Check if any errors have occured whilst getting the data.
788                                                 
789                                                 int ErrorCode = ConnHandle.GetResultCode();
790                                                 
791                                                 if (ErrorCode != 0){
792                                                         
793                                                         if (ErrorCode == 60 || ErrorCode == 51){
794                                                                 
795                                                                 // Invalid SSL certificate so bring up a dialog to the user
796                                                                 // explaining what has happened and the options available.
797                                                                 
798                                                                 // Stop all the timers.
799                                                                 
800                                                                 frmMainPtrGet->PauseAllTimers();
801                                                                 
802                                                                 int SSLResult;
803                                                                 
804 #if defined(__APPLE__)
805                                                                 
806                                                                 // Bring up the trust panel and display the SSL certificate dialog.
807                                                                 
808                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
809                                                                 
810                                                                 // Update the SSL account with the trust object.
811                                                                 
812                                                                 if (SSLResult != NSOKButton){
813                                                                         
814                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
815                                                                         iter->second = 2;
816                                                                         break;
817                                                                         
818                                                                 } else {
819                                                                         
820                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
821                                                                         
822                                                                 }
823 #else
824                                                                 
825                                                                 // Setup the data to be sent in the wxPostEvent command.
826                                                                 
827                                                                 SSLInvalidCertNotifObj SSLICNProcData;
828                                                                 
829                                                                 bool *PauseMode = new bool;
830                                                                 QRNotif qrn;
831                                                                 
832                                                                 *PauseMode = TRUE;
833                                                                 qrn.QResponse = &SSLResult;
834                                                                 qrn.PausePtr = PauseMode;
835                                                                 
836                                                                 SSLICNProcData.CertCollection = certcol;
837                                                                 SSLICNProcData.QRNotifData = &qrn;
838                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
839                                                                 
840                                                                 wxCommandEvent event(INVALIDSSLCERT);
841                                                                 event.SetClientData(&SSLICNProcData);
842                                                                 wxPostEvent(frmMainPtrGet, event);
843                                                                 
844                                                                 /*timespec n1, n2;
845                                                                  
846                                                                         // Fall asleep until we get an response.
847                                                                  
848                                                                         n1.tv_sec = 0;
849                                                                         n1.tv_nsec = 250000000L;*/
850                                                                 
851                                                                 while (*PauseMode == TRUE){
852                                                                         //nanosleep(&n1, &n2);
853                                                                         SleepFor(250000000);
854                                                                 }
855                                                         
856                                                                 // Process the response from the user.
857                                                         
858                                                                 if (SSLResult == 1){
859                                                                 
860                                                                         // Accept the certificate. Write the certificate into the account
861                                                                         // directory (as server.crt) - will overwrite old certificate.
862                                                                 
863                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
864                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
865                                                                 
866                                                                 } else if (SSLResult == 2){
867                                                                 
868                                                                 // Reject the certificate, abort the task and mark as failed.
869                                                                 
870                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
871                                                                         iter->second = 2;
872                                                                         break;
873                                                                 
874                                                                 }
875                                                         
876 #endif
877                                                         
878                                                                 // Resume all the timers.
879                                                         
880                                                                 frmMainPtrGet->ResumeAllTimers();
881                                                                 ExitLoop = TRUE;
882                                                         
883                                                         } else {
884                                                         
885                                                                 iter->second = 4;
886                                                                 break;
887                                                         
888                                                         }
889                                                 
890                                                 } else {
891                                                 
892                                                         ExitLoop = TRUE;
893                                                 
894                                                 }
895                                         
896                                         }
897                                 
898                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
899                                                 break;
900                                         }
901                         
902 #if defined(__APPLE__)
903                                 
904                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
905                                 
906 #else
907                                 
908                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
909                                 
910 #endif
912                                 
913                                         ETagDBPtr->RemoveETag(ContactFilename);
914                                 
915                                         iter->second = 4;
916                                         CardDAVIter->second = NULL;
917                                         break;
918                                 
919                                 }
920                         
921                         } else if (TypeIter->second == 3) {
923                                 wxString AccountNameFriendly;
924         
925                                 int AccountID = 0;
927                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
928         
929                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
930                 
931                                         AccountDirCheck.Trim();
932                                         AccountDirCheck.Append(wxT(".carddav"));
933         
934                                         if (AccountDirCheck == StringAccountIter->second){
935                                         
936                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
937                                                 AccountID = i;
938                 
939                                         }
940         
941                                 }
942                         
943                                 bool KeepUpdating = TRUE;
945                                 while (KeepUpdating == TRUE){
947                                         StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
948                         
949                                         AccountDir = StringAccountIter->second;
951                                         ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
952                                 
953                                         wxArrayString vCardAdd;
954                                         wxArrayString vCardDelete;
955                                         wxArrayString vCardList;
956                                         wxArrayString vCardUpdateLocal;
957                                         wxArrayString vCardUpdateRemote;
958                                         wxArrayString vCardUpdateLog;
959                                         std::map<wxString,wxString> vCardETag;
960                                         ContactListData ServerContactList;
961                                 
962                                         std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
963                                         //wxArrayString vCardDownload;
964                                         //std::map<wxString,wxString> vCardDownloadData;
965                                 
966                                         // Get the list of vCard files locally.
967         
968                                         wxString AccountDirFinal;
969                                         wxString AccountSyncTokenFilename;
970                                         wxString SyncTokenLoad;
971         
972 #if defined(__HAIKU__)
973     
974                                             //preffilename = wxT("noo");
976 #elif defined(__WIN32__)
978                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
979                                         AccountSyncTokenFilename = AccountDirFinal;
980                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
982 #else
984                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
985                                         AccountSyncTokenFilename = AccountDirFinal;
986                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
987         
988 #endif
990                                         // Suppress Error Messages.
991                                 
992                                         wxLogNull PleaseDoNotDisturb;
994                                         wxFFile SyncLoad;
995                                         SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
996                                 
997                                         if (SyncLoad.IsOpened()){
998                                 
999                                                 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1000                                                 SyncLoad.Close();
1001                                 
1002                                         }
1004                                         // Get a list of vCard files from the server.
1006                                         // Get the list of vCard files from the ETagDB.
1007                                 
1008                                         std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1009                                         
1010                                         bool ExitLoop = FALSE;
1012                                         std::map<wxString,FileSyncData> *SCListData = NULL;
1013                                         
1014                                         while (ExitLoop == FALSE){
1015                                         
1016                                                 ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
1017                                                 SSLCertCollection certcol = ConnHandle.GetCertificateData();
1018                                 
1019                                                 // Create a pointer for the std::map<wxString,FileSyncData>.
1020                                 
1021                                                 SCListData = &ServerContactList.ListData;
1022                                 
1023                                                 // Check if any errors have occured whilst getting the data.
1024                                 
1025                                                 int ErrorCode = ConnHandle.GetResultCode();
1026                                 
1027                                                 if (ErrorCode != 0){
1028                                         
1029                                                         if (ErrorCode == 60 || ErrorCode == 51){
1030                                                 
1031                                                                 // Invalid SSL certificate so bring up a dialog to the user
1032                                                                 // explaining what has happened and the options available.
1033                                                         
1034                                                                 // Stop all the timers.
1035                                                                 
1036                                                                 frmMainPtrGet->PauseAllTimers();
1037                                                         
1038                                                                 int SSLResult;
1040 #if defined(__APPLE__)
1041                                                                 
1042                                                                 // Bring up the trust panel and display the SSL certificate dialog.
1043                                                                 
1044                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
1045                                 
1046                                                                 // Update the SSL account with the trust object.
1047                                                                 
1048                                                                 if (SSLResult != NSOKButton){
1049                                                                         
1050                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
1051                                                                         iter->second = 2;
1052                                                                         break;
1053                                                                         
1054                                                                 } else {
1056                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1057                                                                         
1058                                                                 }
1059 #else
1060                                 
1061                                                                 // Setup the data to be sent in the wxPostEvent command.
1063                                                                 SSLInvalidCertNotifObj SSLICNProcData;
1065                                                                 bool *PauseMode = new bool;
1066                                                                 QRNotif qrn;
1068                                                                 *PauseMode = TRUE;                                              
1069                                                                 qrn.QResponse = &SSLResult;
1070                                                                 qrn.PausePtr = PauseMode;
1071                                                                 
1072                                                                 SSLICNProcData.CertCollection = certcol;
1073                                                                 SSLICNProcData.QRNotifData = &qrn;
1074                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
1075                                                         
1076                                                                 wxCommandEvent event(INVALIDSSLCERT);
1077                                                                 event.SetClientData(&SSLICNProcData);
1078                                                                 wxPostEvent(frmMainPtrGet, event);
1079                                         
1080                                                                 /*timespec n1, n2;
1081                                                 
1082                                                                 // Fall asleep until we get an response.
1083                                                 
1084                                                                 n1.tv_sec = 0;
1085                                                                 n1.tv_nsec = 250000000L;*/
1086                                         
1087                                                                 while (*PauseMode == TRUE){
1088                                                                         //nanosleep(&n1, &n2);
1089                                                                         SleepFor(250000000);
1090                                                                 }
1091                                                         
1092                                                                 // Process the response from the user.
1093                                                         
1094                                                                 if (SSLResult == 1){
1095                                                                 
1096                                                                         // Accept the certificate. Write the certificate into the account
1097                                                                         // directory (as server.crt) - will overwrite old certificate.
1099                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
1100                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
1101                                                                 
1102                                                                 } else if (SSLResult == 2){
1103                                                                 
1104                                                                         // Reject the certificate, abort the task and mark as failed.
1106                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
1107                                                                         iter->second = 2;
1108                                                                         break;
1109                                                                 
1110                                                                 }
1111                                                                 
1112 #endif
1113                                                         
1114                                                                 // Resume all the timers.
1115                                                                 
1116                                                                 frmMainPtrGet->ResumeAllTimers();
1117                                                                 ExitLoop = TRUE;
1118                                                 
1119                                                         } else {
1120                                                         
1121                                                                 iter->second = 4;
1122                                                                 break;
1123                                                         
1124                                                         }
1125                                         
1126                                                 } else {
1127                                         
1128                                                         ExitLoop = TRUE;
1129                                         
1130                                                 }
1131                                         
1132                                         }
1133                                         
1134                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1135                                                 break;
1136                                         }
1137                                 
1138 #if defined(__APPLE__)
1139                                         
1140                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1141                                         
1142 #else
1143                                         
1144                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
1145                         
1146 #endif
1147                                         
1148                                         // Look in directory and see which vCards to add and delete
1149                                 
1150                                         // In short:
1151                                         // vCard exists but not in ETagDB - Add (and upload).
1152                                         // vCard missing but in ETagDB - Delete (from server).
1153                                 
1154                                         // Start by looking for vCards that are not in the ETagDB.
1155                                 
1156                                         wxDir AccDir(AccountDirFinal);
1157                                         wxString AccDirFilename;
1158                                 
1159                                         bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1160                                 
1161                                         // Process the server data.
1163                                         if (SCListData != NULL){
1165                                                 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1166                                                         fsiter != SCListData->end(); fsiter++){
1168                                                         // Check the mode of the file before adding.
1170                                                         // Get the HTTP status of the file from the list.
1172                                                         FileSyncData fsd = fsiter->second;
1174                                                         if (fsd.DataFlag == 1){
1176                                                                 // Added or modified contact.
1178                                                                 //vCardAdd.Add(fsiter->first, 1);
1180                                                                 vCardDownloadDataFileClass vCardNewData;
1181                                                                 vCardNewData.DataType = 0;
1182                                                                 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1184                                                                 //} else if (fsd.DataFlag == 1){
1186                                                                 // Contact has been modified on the server.
1188                                                                 //      vCardUpdateLocal.Add(fsiter->first, 1);
1190                                                         }
1191                                                         else if (fsd.DataFlag == 2){
1193                                                                 // Contact has been deleted.
1195                                                                 vCardDelete.Add(fsiter->first, 1);
1197                                                         }
1199                                                 }
1201                                         }
1202                                 
1203                                         // Look for vCards that are missing but in the ETagDB.
1204         
1205                                         for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1206                                                 etagiter != ETagDBData.end(); etagiter++){
1207                                 
1208                                                 // Check if the vCard exists.
1209                                         
1210                                                 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1211                                         
1212                                                         // vCard doesn't exist so mark for deleting.
1213                                         
1214                                                         vCardDelete.Add(etagiter->first, 1);
1215                                         
1216                                                 }
1217                                 
1218                                         }
1220                                         // Compare Server with the ETag DB. Work out which
1221                                         // needs to updated remotely and which needs to be
1222                                         // updated locally.
1224                                         for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1225                                                 srviter != SCListData->end(); srviter++){
1227                                                 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1228                                                         continue;
1229                                                 }
1230                                         
1231                                                 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1232                                 
1233                                                 ETagData etd = lociter->second;
1234                                                 FileSyncData fsd = srviter->second;
1235                                         
1236                                                 wxString ETagSrv = fsd.ETagData;
1238                                                 // Check if the local ETag value has 'DELETED' set and skip
1239                                                 // checking this file if it does.
1240                                         
1241                                                 if (etd.ETagValue == "DELETED"){
1242                                                         
1243                                                         continue;
1244                                                         
1245                                                 }
1246                                                 
1247                                                 // Compare local ETag with original local ETag.
1248                                                 // If different, update to server is required.
1249                                 
1250                                                 if (etd.ETagValue != etd.ETagOrigValue){
1251                                 
1252                                                         // Check if local original ETag is different from server ETag.
1253                                                         // If it is then throw up a conflict resolution dialog.
1254                                 
1255                                                         if (etd.ETagOrigValue != ETagSrv){
1256                                         
1257                                                                 vCard34Conv vCard34Obj;
1258                                                 
1259                                                                 wxString ServerContactData;
1260                                                                 wxString FullFilename;
1261                                                                 vCard ClientData;
1262                                                                 vCard ConvertedV4Data;
1263                                         
1264                                                                 // Conflict. Bring up conflict resolution dialog.
1265                                                         
1266                                                                 // Get the server contact data for comparison.
1267                                                         
1268                                                                 ConnHandle.SetServerFilename(srviter->first);
1269                                                                 ConnHandle.GetServerContactData();
1270                                                                 ServerContactData = ConnHandle.GetPageData();
1271                                                         
1272                                                                 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1273                                                         
1274                                                                 // Convert it to v4.
1275                                         
1276                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1277                                         
1278                                                                 vCardConflictObj vCardProcData;
1279                                         
1280                                                                 vCardProcData.vCardLocalData = &ClientData;
1281                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1282                                                         
1283                                                                 // Load the client data from the filename given.
1284                                                         
1285                                                                 ClientData.LoadFile(FullFilename);
1286                                                         
1287                                                                 // Show dialog.
1288                                         
1289                                                                 bool *PauseMode = new bool;
1290                                                                 int ConflictResult;
1291                                                                 QRNotif qrn;
1292                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1294                                                                 *PauseMode = TRUE;
1295                                                                 qrn.QResponse = &ConflictResult;
1296                                                                 qrn.PausePtr = PauseMode;
1297                                                 
1298                                                                 vCardProcData.QRNotifData = &qrn;
1299                                         
1300                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1301                                                                 event.SetClientData(&vCardProcData);
1302                                                                 wxPostEvent(frmMainPtrGet, event);
1303                                                 
1304                                                                 /*timespec n1, n2;
1305                                                 
1306                                                                 n1.tv_sec = 0;
1307                                                                 n1.tv_nsec = 250000000L;*/
1308                                                 
1309                                                                 while (*PauseMode == TRUE){
1310                                                                         //nanosleep(&n1, &n2);
1311                                                                         SleepFor(250000000);
1312                                                                 }
1313                                         
1314                                                                 delete PauseMode;
1315                                                                 PauseMode = NULL;
1316                                                         
1317                                                                 // If replacing local version, store copy for now.
1318                                                                 // Otherwise upload to server.
1319                                         
1320                                                                 if (ConflictResult == 0){
1321                                         
1322                                                                         // Decide Later.
1323                                         
1324                                                                         continue;
1325                                         
1326                                                                 } else if (ConflictResult == 1){
1327                                         
1328                                                                         // Decided to use client version.
1329                                         
1330                                                                         vCardUpdateLocal.Remove(srviter->first);
1331                                                                         vCardUpdateRemote.Add(srviter->first, 1);                                                               
1332                                         
1333                                                                 } else if (ConflictResult == 2){
1334                                         
1335                                                                         // Decided to use server version.
1336                                                                         // Store the converted downloaded copy for
1337                                                                         // processing later.
1339                                                                         //vCardUpdateLocal.Add(srviter->first, 1);
1340                                                                 
1341                                                                         vCardDownloadDataFileClass vCardNewData;
1342                                                                         vCardNewData.DataType = 1;
1343                                                                         vCardNewData.FileData = ConvertedV4Data.WriteString();
1345                                                                         ConvertedV4Data.WriteFile(FullFilename);
1346                                                                 
1347                                                                         vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData)); 
1348                                                                 
1349                                                                 
1350                                                                 
1351                                                                 }
1352                                         
1353                                                         } else {
1354                                         
1355                                                                 // Send vCard to the server.
1356                                                 
1357                                                                 vCardUpdateRemote.Add(srviter->first, 1);
1358                                         
1359                                                         }
1360                                 
1361                                                 } else {
1362                                 
1363                                                         // Check if local ETag is different from server ETag.
1364                                                         // If different, obtain the vCard from the server.
1365                                         
1366                                                         if (etd.ETagOrigValue != ETagSrv){
1367                                         
1368                                                                 vCardUpdateLocal.Add(srviter->first, 1);
1369                                         
1370                                                         }
1371                                 
1372                                                 }
1373                         
1374                                         }
1375                                 
1376                                         // Process the vCards that need to be downloaded and added/overwritten.
1377                                 
1378                                         wxString vCardFilenameFinal;
1379                                         wxString vCardOutputData;
1380                                         wxString vCardInputData;
1381                                         wxString ETagFileData;
1382                                         wxFFile vCardFile;
1383                                 
1384                                         for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1385                                                 additer != vCardDownloadData.end(); additer++){
1386                                         
1387                                                 vCardFilenameFinal.Clear();
1388                                                 vCardInputData.Clear();
1389                                                 vCardOutputData.Clear();
1390                                                 ETagFileData.Clear();
1391                                         
1392                                                 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1393                                         
1394                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1395                                         
1396                                                 if (additer->second.DataType == 0){
1397                                         
1398                                                         vCard ConvertedV4Data;
1399                                         
1400                                                         // Grab the file from the server and write the contact out.
1401                                         
1402                                                         vCard34Conv vCard34Obj;
1403                                                 
1404                                                         ConnHandle.SetServerFilename(additer->first);
1405                                                         ConnHandle.GetServerContactData();
1406                                                         vCardInputData = ConnHandle.GetPageData();
1407                                                 
1408                                                         vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1409                                                 
1410                                                         ConvertedV4Data.WriteFile(vCardFilenameFinal);
1411                                                 
1412                                                         // Update the ETagDB.
1413                                                 
1414                                                         //vCardFile.Open(vCardFilenameFinal, wxT("w"));
1415                                 
1416                                                         //if (vCardFile.IsOpened()){
1417                                 
1418                                                         //      vCardFile.Write(vCardOutputData, wxConvAuto());
1419                                                         //      vCardFile.Close();
1420                                 
1421                                                         //}
1422                                                 
1423                                                         // Get the server ETag.
1424                                                 
1425                                                         wxString ServerETag;
1426                                                         ConnHandle.GetServerETagValueThread();
1427                                                         ServerETag = ConnHandle.ETagValueResult();
1428                                                 
1429                                                         // Add to the ETag Database.
1430                                                 
1431                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1432                                                 
1433                                                 } else if (additer->second.DataType == 1){
1434                                         
1435                                                         // Write out the contact to the account directory.
1436                                         
1437                                                         vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1438                                                         vCardOutputData = additer->second.FileData;
1439                                                 
1440                                                         vCardFile.Open(vCardFilenameFinal, wxT("w"));
1441                                 
1442                                                         if (vCardFile.IsOpened()){
1443                                 
1444                                                                 vCardFile.Write(vCardOutputData, wxConvAuto());
1445                                                                 vCardFile.Close();
1446                                 
1447                                                         }
1448                                                 
1449                                                         // Update the ETagDB.
1451                                                         wxString ServerETag;
1452                                                         ConnHandle.GetServerETagValueThread();
1453                                                         ServerETag = ConnHandle.ETagValueResult();
1454                                                 
1455                                                         // Add to the ETag Database.
1456                                                 
1457                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1458                                                                                         
1459                                                 }
1460                                         }
1461         
1462                                         // Look for vCard files which aren't in the ETagDB.
1463         
1464                                         while(ContinueProcess){
1465                                 
1466                                                 // Check and make sure that the filename ends in .vcf/.vcard
1467                                                 // Skip any file that beings with a dot.
1468                                         
1469                                                 if (AccDirFilename.Left(1) == wxT(".")){
1470                                         
1471                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
1472                                                         continue;
1473                                         
1474                                                 }
1475                                         
1476                                                 if (AccDirFilename.Right(4) != wxT(".vcf") && 
1477                                                 AccDirFilename.Right(6) != wxT(".vcard")){
1478                                         
1479                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
1480                                                         continue;
1481                                         
1482                                                 }
1483                                 
1484                                                 // Look in the ETagDB for the file.
1485                                         
1486                                                 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1487                                         
1488                                                 if (ETagExists == FALSE){
1489                                         
1490                                                         // Add the vCard to the list to be added.
1491                                                 
1492                                                         vCardAdd.Add(AccDirFilename, 1);
1493                                         
1494                                                 }
1495                                         
1496                                                 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1497                                 
1498                                         }
1499                                 
1500                                         // Process the vCards to add/update to the server.
1501                                 
1502                                         for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1504                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1505                                                 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1506                                                 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1507                                                 
1508                                                 ContactFilename = vCardAdd[vi];
1509                                                 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1511                                                 ContactFilename.Trim();
1512                         
1513                                                 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1514                         
1515                                                         // Compare the ETag with the Server ETag.
1516                                                 
1517                                                         ConnHandle.SetServerFilename(vCardAdd[vi]);
1518                                                         ConnHandle.GetServerETagValueThread();
1519                                                         ETagServer = ConnHandle.ETagValueResult();
1520                                 
1521                                                         if (ETagOriginal != ETagServer){
1522                                 
1523                                                                 // Server ETag is different from original ETag.
1524                                                                 // This is a conflict which the user will now
1525                                                                 // need to resolve.
1526                                         
1527                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1528                                         
1529                                                                 vCard34Conv vCard34Obj;
1530                                                 
1531                                                                 wxString ServerContactData;
1532                                                                 vCard ClientData;
1533                                                                 vCard ConvertedV4Data;
1534                                         
1535                                                                 // Load the client data from the filename given.
1536                                         
1537                                                                 ConnHandle.GetServerContactData();
1538                                                                 ServerContactData = ConnHandle.GetPageData();
1539                                                 
1540                                                                 // Process v3 version into v4 version.
1541                                                 
1542                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1543                                         
1544                                                                 vCardConflictObj vCardProcData;
1545                                         
1546                                                                 vCardProcData.vCardLocalData = &ClientData;
1547                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1548                                                                 ClientData.LoadFile(FullFilename);
1550                                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
1551                                                                 //event.SetData(ContactFilename, Moo1, Moo2);
1552                                         
1553                                                                 //wxPostEvent(frmMainPtrGet, event);
1554                                         
1555                                                                 // Setup Conflict Resolution Dialog.
1556                                         
1557                                                                 // Fetch Data from Server and convert.
1558                                         
1559                                                                 bool *PauseMode = new bool;
1560                                                                 int ConflictResult;
1561                                                                 QRNotif qrn;
1563                                                                 *PauseMode = TRUE;                                              
1564                                                                 qrn.QResponse = &ConflictResult;
1565                                                                 qrn.PausePtr = PauseMode;
1566                                                 
1567                                                                 vCardProcData.QRNotifData = &qrn;
1568                                         
1569                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1570                                                                 event.SetClientData(&vCardProcData);
1571                                                                 wxPostEvent(frmMainPtrGet, event);
1572                                                 
1573                                                                 /*timespec n1, n2;
1574                                                 
1575                                                                 n1.tv_sec = 0;
1576                                                                 n1.tv_nsec = 250000000L;*/
1577                                                 
1578                                                                 while (*PauseMode == TRUE){
1579                                                                         //nanosleep(&n1, &n2);
1580                                                                         SleepFor(250000000);
1581                                                                 }
1582                                         
1583                                                                 delete PauseMode;
1584                                                                 PauseMode = NULL;
1585                                         
1586                                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1587                                         
1588                                                                 if (ConflictResult == 0){
1589                                         
1590                                                                         // Decide Later.
1591                                         
1592                                                                         iter->second = 4;
1593                                                                         continue;
1594                                         
1595                                                                 } else if (ConflictResult == 1){
1596                                         
1597                                                                         // Decided to use client version.
1598                                         
1599                                                                         ConnHandle.ProcessData();
1600                                                 
1601                                                                         iter->second = 4;
1602                                         
1603                                                                 } else if (ConflictResult == 2){
1604                                         
1605                                                                         // Decided to use server version.
1606                                                 
1607                                                                         // Download server version.
1608                                                                 
1609                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1610                                                 
1611                                                                         iter->second = 4;
1612                                         
1613                                                                 }
1614                                 
1615                                                         } else {
1616                                 
1617                                                                 // Setup the filename for the contact being added.
1618                                                         
1619                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1620                                                                 wxString wxSCardData;
1621                                                                 wxString TaskData;
1622                                                                 //wxString TaskURL;
1623                                                         
1624                                                                 // Load the data from the file.
1625                                                         
1626                                                                 wxFFile wxFCard;
1627                                                                 wxFCard.Open(wxSFilename, wxT("r"));
1628                                 
1629                                                                 if (wxFCard.IsOpened()){
1630                                 
1631                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1632                                                                         wxFCard.Close();
1633                                 
1634                                                                 }
1635                                                         
1636                                                                 // Convert the data to v3.
1637                                                         
1638                                                                 vCard34Conv vCard34Obj;
1639                                                         
1640                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1641                                                         
1642                                                                 // Setup the URL address.
1643                                                         
1644                                                                 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1646                                                                 // Upload the data to the server.
1647                                         
1648                                                                 ConnHandle.SetUploadMode(TRUE);
1649                                                                 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1650                                                                 ConnHandle.ProcessData();
1651                                                         
1652                                                                 // Get the Server ETag and put it in the ETag database.
1653                                                         
1654                                                                 ConnHandle.SetServerFilename(vCardAdd[vi]);
1655                                                                 ConnHandle.GetServerETagValueThread();
1656                                                                 ETagServer = ConnHandle.ETagValueResult();
1657                                 
1658                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1659                                 
1660                                                         }
1661                         
1662                                                 } else {
1663                         
1664                                                         if (ETagOriginal != ETagServer){
1665                                 
1666                                                                 // Server ETag is different from original ETag.
1667                                                                 // This is a conflict which the user will now
1668                                                                 // need to resolve.
1669                                         
1670                                                                 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1671                                         
1672                                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
1673                                                                 //event.SetData(ContactFilename, Moo1, Moo2);
1674                                         
1675                                                                 vCard34Conv vCard34Obj;
1676                                                 
1677                                                                 wxString ServerContactData;
1678                                                                 vCard ClientData;
1679                                                                 vCard ConvertedV4Data;
1680                                         
1681                                                                 // Load the client data from the filename given.
1682                                         
1683                                                                 ConnHandle.GetServerContactData();
1684                                                                 ServerContactData = ConnHandle.GetPageData();
1685                                                                 ClientData.LoadFile(FullFilename);
1686                                                 
1687                                                                 // Process v3 version into v4 version.
1688                                                 
1689                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1690                                         
1691                                                                 vCardConflictObj vCardProcData;
1692                                         
1693                                                                 vCardProcData.vCardLocalData = &ClientData;
1694                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1695                                         
1696                                                                 bool *PauseMode = new bool;
1697                                                                 int ConflictResult;
1698                                                                 QRNotif qrn;
1700                                                                 *PauseMode = TRUE;                                              
1701                                                                 qrn.QResponse = &ConflictResult;
1702                                                                 qrn.PausePtr = PauseMode;
1703                                                 
1704                                                                 vCardProcData.QRNotifData = &qrn;
1705                                         
1706                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1707                                                                 event.SetClientData(&vCardProcData);
1708                                                                 wxPostEvent(frmMainPtrGet, event);
1709                                         
1710                                                                 /*timespec n1, n2;
1711                                                 
1712                                                                 n1.tv_sec = 0;
1713                                                                 n1.tv_nsec = 250000000L;*/
1714                                         
1715                                                                 while (*PauseMode == TRUE){
1716                                                                         //nanosleep(&n1, &n2);
1717                                                                         SleepFor(250000000);
1718                                                                 }
1719                                         
1720                                                                 delete PauseMode;
1721                                                                 PauseMode = NULL;
1722                                         
1723                                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1724                                         
1725                                                                 if (ConflictResult == 0){
1726                                         
1727                                                                         // Decide Later.
1728                                         
1729                                                                         iter->second = 4;
1730                                                                         continue;
1731                                         
1732                                                                 } else if (ConflictResult == 1){
1733                                         
1734                                                                         // Decided to use client version.
1735                                                                 
1736                                                                         ConnHandle.ProcessData();
1737                                                                         //ETagServer = CardDAVIter->second.GetServerETagValueThread();
1738                                                                         //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1739                                                 
1740                                                                         iter->second = 4;
1741                                         
1742                                                                 } else if (ConflictResult == 2){
1743                                         
1744                                                                         // Decided to use server version.
1745                                                 
1746                                                                         // Write server version to file.
1747                                                                 
1748                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1749                                                 
1750                                                                         iter->second = 4;
1751                                         
1752                                                                 }
1753                                 
1754                                                         } else {
1755                                 
1756                                                                 // Setup the filename for the contact being added.
1757                                                         
1758                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1759                                                                 wxString wxSCardData;
1760                                                                 wxString TaskData;
1761                                                                 //wxString TaskURL;
1762                                                         
1763                                                                 // Load the data from the file.
1764                                                         
1765                                                                 wxFFile wxFCard;
1766                                                                 wxFCard.Open(wxSFilename, wxT("r"));
1767                                 
1768                                                                 if (wxFCard.IsOpened()){
1769                                 
1770                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1771                                                                         wxFCard.Close();
1772                                 
1773                                                                 }
1774                                                         
1775                                                                 // Convert the data to v3.
1776                                                         
1777                                                                 vCard34Conv vCard34Obj;
1778                                                         
1779                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1780                                                         
1781                                                                 // Setup the URL address.
1782                                                         
1783                                                                 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1785                                                                 // Upload the data to the server.
1786                                         
1787                                                                 ConnHandle.SetUploadMode(TRUE);
1788                                                                 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1789                                                                 ConnHandle.ProcessData();
1790                                                         
1791                                                                 // Get the Server ETag and put it in the ETag database.
1792                                                         
1793                                                                 ConnHandle.SetServerFilename(vCardAdd[vi]);
1794                                                                 ConnHandle.GetServerETagValueThread();
1795                                                                 ETagServer = ConnHandle.ETagValueResult();
1796                                 
1797                                 
1798                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1799                                 
1800                                                         }
1801                                         
1802                                                 }
1804                                         }                       
1805                                 
1806                                         // Process the vCards to delete locally.
1807                                 
1808                                         for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1810                                                 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1812                                                 } else {
1813                                         
1814                                                         ETagDBPtr->RemoveETag(vCardDelete[vi]);
1815                                         
1816                                                 }
1818                                         }
1819                                 
1820                                         // Process the vCards to delete from the server.
1821                                 
1822                                         std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1823                                         std::list<wxString> DeleteList;
1824                                 
1825                                         for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1826                                                 deliter != ETagFilenameMap->end(); deliter++){
1827                                 
1828                                                 // Look through the ETagDB and find contacts which are marked as DELETED.
1829                                         
1830                                                 if (deliter->second == wxT("DELETED")){
1832                                                         ConnHandle.SetUploadMode(FALSE);
1833                                                         ConnHandle.SetupData(wxT("DELETE"), deliter->first, wxT(""));
1834                                                         ConnHandle.ProcessDataThread();
1835                                         
1836                                                         // Delete the ETag as the file has now been deleted.
1837                                         
1838                                                         DeleteList.push_back(deliter->first);
1839                                         
1840                                                 }
1841                                 
1842                                         }
1843                                         
1844                                         for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
1845                                              removeetagiter != DeleteList.end(); removeetagiter++){
1846                                         
1847                                                 ETagDBPtr->RemoveETag(*removeetagiter);
1848                                                 
1849                                         }
1850                                 
1851                                         // Write out the update server sync token.
1853                                         wxString ServerSyncToken = ServerContactList.SyncToken;
1854                                 
1855                                         ServerSyncToken.Trim();
1856                                 
1857                                         if (!ServerSyncToken.IsEmpty()){
1858                                 
1859                                                 wxFFile SyncWrite;
1860                                                 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1861                                 
1862                                                 if (SyncWrite.IsOpened()){
1863                                 
1864                                                         SyncWrite.Write(ServerSyncToken, wxConvAuto());
1865                                                         SyncWrite.Close();
1866                                 
1867                                                 }
1868                                 
1869                                         }
1870                                 
1871                                         // Check for another sync token. If there is another 
1872                                         // sync token then repeat this. If token matches then stop processing.
1873                                 
1874                                         if (SyncTokenLoad == ServerSyncToken){
1875                                         
1876                                                 KeepUpdating = FALSE;
1877                                         
1878                                         }
1879                                         
1880                                 }
1881                                 
1882                                 // Mark as completed.
1883                         
1884                                 wxString AccountNameFinal;
1885                                 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1886                                 AccountNameFinal.Append(wxT(".carddav"));
1887                                 
1888                                 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1889                                 reloadevent.SetString(AccountNameFinal);
1890                                 wxPostEvent(this->GetParent(), reloadevent);
1891                                 
1892                                 iter->second = 4;
1893                                 continue;
1894                         
1895                         } else {
1896                         
1897                                 // Update the data to the server.
1898                                         
1899                                 ConnHandle.ProcessData();
1900                                 iter->second = 4;
1901                                 continue;
1902                         
1903                         }
1905                         /*timespec n1, n2;
1906                                                 
1907                         n1.tv_sec = 0;
1908                         n1.tv_nsec = 250000000L;*/
1910                         while (iter->second == 1){
1912                                 SleepFor(250000000);
1913                                 //nanosleep(&n1, &n2);
1914         
1915                         }
1916                         
1917                         if ((iter->second == 4 && TypeIter->second == 0) || 
1918                         (iter->second == 8 && TypeIter->second == 0)){
1920                                 AccountDir = StringAccountIter->second;
1921                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1922                                 
1923                                 ConnHandle.GetServerETagValueThread();
1924                                 ETagServer = ConnHandle.ETagValueResult();
1925                                 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1926                         
1927                         }
1928                         
1929                         if ((iter->second == 4 && TypeIter->second == 1) || 
1930                         (iter->second == 8 && TypeIter->second == 1)){
1931                         
1932                                 AccountDir = StringAccountIter->second;
1933                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);                 
1935                                 ConnHandle.GetServerETagValueThread();
1936                                 ETagServer = ConnHandle.ETagValueResult();
1937                                 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1938                         
1939                         }
1940                         
1941                         break;
1942                         
1943                 }
1945         }
1946         
1947         if (TasksFoundProc == FALSE){
1948         
1949                 TasksActive = FALSE;
1950                 ProcessTasksData = FALSE;
1951         
1952         } else {
1954                 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1955                 wxPostEvent(this, eventp);
1957                 //AnimationTimer.StartAnimation();
1958                 //ActListProcTimer.Start();
1959         
1960         }
1962         wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1963         wxPostEvent(this, event);
1965         //ActProcessTimer.Start();
1969 void frmActivityMgr::ProcessTasks()
1972         std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1973         ProcessThread.detach();
1977 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1980         ETagTmrPtr = ETagTmrPtrInc;
1981         
1982         frmMainPtr = frmMainPtrInc;
1986 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1988         QRNotif *qrn = (QRNotif *)event.GetClientData(); 
1989         
1990         int *QRes = qrn->QResponse;
1992         *qrn->PausePtr = FALSE;
1994         *QRes = event.GetInt();
1995         
1998 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
2000         wxCommandEvent connevent(CONNSTAT_UPDATE);
2001         
2002         if (SleepMode == FALSE){
2003         
2004                 connevent.SetInt(1);
2005                 SleepMode = TRUE;
2006         
2007         } else {
2008         
2009                 connevent.SetInt(0);
2010                 SleepMode = FALSE;
2011         
2012         }
2014         wxPostEvent(GetParent(), connevent);
2018 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
2020         wxString ServerCertFinal;
2022         // Get the Cert section of the certificate and write it to the file.
2024         ServerCertFinal = GetAccountDir(AccountName, TRUE);
2026         wxFile CertFile;
2027         
2028         std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2029         std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
2030         
2031         CertFile.Open(ServerCertFinal, wxFile::write);  
2032         
2033         CertFile.Write(SSLDataIter->second, wxConvUTF8);
2034         CertFile.Close();
2038 void frmActivityMgr::StartTimer(wxCommandEvent& event){
2040         ActListProcTimer.Start(1000, FALSE);
2044 void frmActivityMgr::StopTimer(wxCommandEvent& event){
2046         ActListProcTimer.Stop();
2050 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
2052         ActProcessTimer.Start(1000, FALSE);
2056 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
2058         ActProcessTimer.Stop();
2062 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2064         ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2065         
2066         if (actmgrudata != NULL){
2067         
2068                 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
2069         
2070                 /*if (!actmgrudata->ItemDes.IsEmpty()){
2071                 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);
2072                 }*/
2073         
2074                 delete actmgrudata;
2075                 actmgrudata = NULL;
2076         
2077         }
2081 #endif
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy