1 // frmActivityMgr.cpp - Activity Manager form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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>
23 #include <wx/tokenzr.h>
25 #include <wx/filefn.h>
28 #include <curl/curl.h>
30 #include "../bitmaps.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)
62 frmActivityMgr::frmActivityMgr( wxWindow* parent )
64 frmActivityMgrADT( parent )
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);
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."));
82 ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail,
83 &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
84 &ActProcessTimer, &ActivityListFinDate, &ActivityListConn);
86 AnimationTimer.SetBitmap(bmpActivity);
87 AnimationTimer.SetSleepBitmap(&SleepBitmap);
88 AnimationTimer.SetupPointer(this->GetParent());
90 wxListItem ColumnData;
92 ColumnData.SetText(_("Activity"));
93 ColumnData.SetWidth(175);
94 lstActivity->InsertColumn(0, ColumnData);
96 wxListItem ColumnData2;
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);
108 //AnimationTimer.StartAnimation();
110 // Create recovery database if it doesn't exist.
112 wxString RecoveryFilename = GetRecoveryDB();
116 if (wxFile::Exists(RecoveryFilename) == FALSE){
118 // Create the recovery database.
120 RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);
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);
132 #if wxABI_VERSION < 20900
133 RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
135 RecoveryDBF.Open(RecoveryFilename, wxT("r"));
138 // Load the recovery database for tasks not done.
140 if (RecoveryDBF.IsOpened() == TRUE){
142 wxString wxSRecoveryDB;
143 wxString RecoveryLine;
145 // Check if we are using wxWidgets version 2.8 or less and
146 // execute the required command accordingly.
148 RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
152 std::map<int, wxString> RecoveryFileLines;
153 std::map<int, wxString>::iterator striter;
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));
171 //TestTimer.Start(50, FALSE);
174 void frmActivityMgr::OpenWindow()
179 void frmActivityMgr::CloseWindow( wxCommandEvent& event )
185 void frmActivityMgr::CloseWindow( wxCloseEvent& event )
191 void frmActivityMgr::ProcessTasksThread()
194 if (ProcessTasksData == FALSE){
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;
217 for (std::map<int,int>::iterator iter = ActivityList.begin();
218 iter != ActivityList.end(); ++iter){
220 // Check for any queued tasks and start one.
222 if (iter->second > 4){
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);
235 // Setup the CardDAV object.
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);
254 // 5 = Failed (UI Updated).
255 // 6 = Stopped (UI Updated).
256 // 7 = (Reserved) (UI Updated).
257 // 8 = Completed. (UI Updated).
259 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
260 XABPreferences PrefData(GetUserPrefDir());
262 if (iter->second == 0){
264 //CardDAVIter->second.
266 // Wait for process to finish.
269 TasksFoundProc = TRUE;
271 wxString ETagOriginal;
274 wxString ContactFilename;
275 wxString FullFilename;
277 bool EditMode = FALSE;
281 // Compare the ETags and work out if a conflict has occured.
283 if (TypeIter->second == 0){
287 StringDataIter = ActivityListData.find(iter->first);
288 StringURLIter = ActivityListURL.find(iter->first);
290 AccountDir = StringAccountIter->second;
291 ContactFilename = StringFilenameIter->second;
292 wxString AccountNameFriendly;
296 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
298 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
300 AccountDirCheck.Trim();
301 AccountDirCheck.Append(wxT(".carddav"));
303 if (AccountDirCheck == StringAccountIter->second){
305 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
312 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
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;
321 bool KeepUpdating = TRUE;
323 while(KeepUpdating == TRUE){
325 bool ExitLoop = FALSE;
327 while (ExitLoop == FALSE){
329 ConnHandle.SetUploadMode(TRUE);
330 ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
331 ConnHandle.SetEditMode(EditMode);
332 ConnHandle.ProcessData();
334 int ErrorCode = ConnHandle.GetResultCode();
338 if (ErrorCode == 60 || ErrorCode == 51){
340 // Invalid SSL certificate so bring up a dialog to the user
341 // explaining what has happened and the options available.
343 // Stop all the timers.
345 frmMainPtrGet->PauseAllTimers();
349 #if defined(__APPLE__)
351 // Bring up the trust panel and display the SSL certificate dialog.
353 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
355 // Update the SSL account with the trust object.
357 if (SSLResult != NSOKButton){
359 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
365 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
370 // Setup the data to be sent in the wxPostEvent command.
372 SSLInvalidCertNotifObj SSLICNProcData;
374 SSLCertCollection certcol = ConnHandle.GetCertificateData();
376 bool *PauseMode = new bool;
380 qrn.QResponse = &SSLResult;
381 qrn.PausePtr = PauseMode;
383 SSLICNProcData.CertCollection = certcol;
384 SSLICNProcData.QRNotifData = &qrn;
385 SSLICNProcData.AccountName = AccountNameFriendly;
387 wxCommandEvent event(INVALIDSSLCERT);
388 event.SetClientData(&SSLICNProcData);
389 wxPostEvent(frmMainPtrGet, event);
393 // Fall asleep until we get an response.
396 n1.tv_nsec = 250000000L;*/
398 while (*PauseMode == TRUE){
399 //nanosleep(&n1, &n2);
403 // Process the response from the user.
407 // Accept the certificate. Write the certificate into the account
408 // directory (as server.crt) - will overwrite old certificate.
410 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
411 WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
413 } else if (SSLResult == 2){
415 // Reject the certificate, abort the task and mark as failed.
417 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
425 // Resume all the timers.
427 frmMainPtrGet->ResumeAllTimers();
445 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
449 #if defined(__APPLE__)
451 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
455 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
459 // Add contact to the ETag DB.
461 ConnHandle.GetServerETagValueThread();
462 ETagServer = ConnHandle.ETagValueResult();
463 ETagDBPtr->AddETag(ContactFilename, ETagServer, ETagServer);
466 CardDAVIter->second = NULL;
471 } else if (TypeIter->second == 1){
475 StringDataIter = ActivityListData.find(iter->first);
476 StringURLIter = ActivityListURL.find(iter->first);
478 AccountDir = StringAccountIter->second;
479 ContactFilename = StringFilenameIter->second;
480 wxString AccountNameFriendly;
484 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
486 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
488 AccountDirCheck.Trim();
489 AccountDirCheck.Append(wxT(".carddav"));
491 if (AccountDirCheck == StringAccountIter->second){
493 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
500 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
502 ETag = StringETagIter->second;
503 ETagOriginal = StringETagOrigIter->second;
504 AccountDir = StringAccountIter->second;
505 ContactFilename = StringFilenameIter->second;
506 FullFilename = StringFullFilenameIter->second;
507 EditMode = ActivityListEditMode.find(iter->first)->second;
509 bool KeepUpdating = TRUE;
511 while(KeepUpdating == TRUE){
513 bool ExitLoop = FALSE;
515 while (ExitLoop == FALSE){
517 ConnHandle.SetUploadMode(TRUE);
518 ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
519 ConnHandle.SetEditMode(EditMode);
520 ConnHandle.GetServerETagValueThread();
521 ETagServer = ConnHandle.ETagValueResult();
523 int ErrorCode = ConnHandle.GetResultCode();
527 if (ErrorCode == 60 || ErrorCode == 51){
529 // Invalid SSL certificate so bring up a dialog to the user
530 // explaining what has happened and the options available.
532 // Stop all the timers.
534 frmMainPtrGet->PauseAllTimers();
538 #if defined(__APPLE__)
540 // Bring up the trust panel and display the SSL certificate dialog.
542 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
544 // Update the SSL account with the trust object.
546 if (SSLResult != NSOKButton){
548 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
554 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
559 // Setup the data to be sent in the wxPostEvent command.
561 SSLInvalidCertNotifObj SSLICNProcData;
563 SSLCertCollection certcol = ConnHandle.GetCertificateData();
565 bool *PauseMode = new bool;
569 qrn.QResponse = &SSLResult;
570 qrn.PausePtr = PauseMode;
572 SSLICNProcData.CertCollection = certcol;
573 SSLICNProcData.QRNotifData = &qrn;
574 SSLICNProcData.AccountName = AccountNameFriendly;
576 wxCommandEvent event(INVALIDSSLCERT);
577 event.SetClientData(&SSLICNProcData);
578 wxPostEvent(frmMainPtrGet, event);
580 while (*PauseMode == TRUE){
581 //nanosleep(&n1, &n2);
585 // Process the response from the user.
589 // Accept the certificate. Write the certificate into the account
590 // directory (as server.crt) - will overwrite old certificate.
592 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
593 WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
595 } else if (SSLResult == 2){
597 // Reject the certificate, abort the task and mark as failed.
599 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
607 // Resume all the timers.
609 frmMainPtrGet->ResumeAllTimers();
627 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
631 #if defined(__APPLE__)
633 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
637 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
641 // Compare the ETag with the Server ETag.
643 if (ETagOriginal != ETagServer){
645 // Server ETag is different from original ETag.
646 // This is a conflict which the user will now
652 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
654 vCard34Conv vCard34Obj;
656 wxString ServerContactData;
658 vCard ConvertedV4Data;
660 // Load the client data from the filename given.
662 ConnHandle.GetServerContactData();
663 ServerContactData = ConnHandle.GetPageData();
665 // Process v3 version into v4 version.
667 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
669 vCardConflictObj vCardProcData;
671 vCardProcData.vCardLocalData = &ClientData;
672 vCardProcData.vCardServerData = &ConvertedV4Data;
673 ClientData.LoadFile(FullFilename);
675 //ContactConflictEvent event(ContactConflictCmdEnv);
676 //event.SetData(ContactFilename, Moo1, Moo2);
678 //wxPostEvent(frmMainPtrGet, event);
680 // Setup Conflict Resolution Dialog.
682 // Fetch Data from Server and convert.
684 bool *PauseMode = new bool;
689 qrn.QResponse = &ConflictResult;
690 qrn.PausePtr = PauseMode;
692 vCardProcData.QRNotifData = &qrn;
694 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
695 event.SetClientData(&vCardProcData);
696 wxPostEvent(frmMainPtrGet, event);
698 while (*PauseMode == TRUE){
699 //nanosleep(&n1, &n2);
706 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
708 if (ConflictResult == 0){
715 } else if (ConflictResult == 1){
717 // Decided to use client version.
719 ConnHandle.ProcessData();
721 } else if (ConflictResult == 2){
723 // Decided to use server version.
725 // Download server version.
727 ConvertedV4Data.WriteFile(FullFilename);
733 // Update the data to the server.
735 ConnHandle.ProcessData();
739 // Update the ETag DB.
741 ConnHandle.GetServerETagValueThread();
742 ETagServer = ConnHandle.ETagValueResult();
743 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
750 } else if (TypeIter->second == 2) {
752 // Delete the contact from the server and update the ETag DB.
754 AccountDir = StringAccountIter->second;
755 ContactFilename = StringFilenameIter->second;
756 wxString AccountNameFriendly;
760 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
762 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
764 AccountDirCheck.Trim();
765 AccountDirCheck.Append(wxT(".carddav"));
767 if (AccountDirCheck == StringAccountIter->second){
769 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
776 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
778 bool KeepUpdating = TRUE;
780 while(KeepUpdating == TRUE){
782 bool ExitLoop = FALSE;
784 while (ExitLoop == FALSE){
786 ConnHandle.SetUploadMode(FALSE);
787 ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
788 ConnHandle.ProcessData();
789 SSLCertCollection certcol = ConnHandle.GetCertificateData();
791 // Check if any errors have occured whilst getting the data.
793 int ErrorCode = ConnHandle.GetResultCode();
797 if (ErrorCode == 60 || ErrorCode == 51){
799 // Invalid SSL certificate so bring up a dialog to the user
800 // explaining what has happened and the options available.
802 // Stop all the timers.
804 frmMainPtrGet->PauseAllTimers();
808 #if defined(__APPLE__)
810 // Bring up the trust panel and display the SSL certificate dialog.
812 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
814 // Update the SSL account with the trust object.
816 if (SSLResult != NSOKButton){
818 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
824 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
829 // Setup the data to be sent in the wxPostEvent command.
831 SSLInvalidCertNotifObj SSLICNProcData;
833 bool *PauseMode = new bool;
837 qrn.QResponse = &SSLResult;
838 qrn.PausePtr = PauseMode;
840 SSLICNProcData.CertCollection = certcol;
841 SSLICNProcData.QRNotifData = &qrn;
842 SSLICNProcData.AccountName = AccountNameFriendly;
844 wxCommandEvent event(INVALIDSSLCERT);
845 event.SetClientData(&SSLICNProcData);
846 wxPostEvent(frmMainPtrGet, event);
850 // Fall asleep until we get an response.
853 n1.tv_nsec = 250000000L;*/
855 while (*PauseMode == TRUE){
856 //nanosleep(&n1, &n2);
860 // Process the response from the user.
864 // Accept the certificate. Write the certificate into the account
865 // directory (as server.crt) - will overwrite old certificate.
867 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
868 WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
870 } else if (SSLResult == 2){
872 // Reject the certificate, abort the task and mark as failed.
874 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
882 // Resume all the timers.
884 frmMainPtrGet->ResumeAllTimers();
902 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
906 #if defined(__APPLE__)
908 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
912 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
917 ETagDBPtr->RemoveETag(ContactFilename);
920 CardDAVIter->second = NULL;
925 } else if (TypeIter->second == 3) {
927 wxString AccountNameFriendly;
931 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
933 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
935 AccountDirCheck.Trim();
936 AccountDirCheck.Append(wxT(".carddav"));
938 if (AccountDirCheck == StringAccountIter->second){
940 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
947 bool KeepUpdating = TRUE;
949 while (KeepUpdating == TRUE){
951 StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
953 AccountDir = StringAccountIter->second;
955 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
957 wxArrayString vCardAdd;
958 wxArrayString vCardDelete;
959 wxArrayString vCardList;
960 wxArrayString vCardUpdateLocal;
961 wxArrayString vCardUpdateRemote;
962 wxArrayString vCardUpdateLog;
963 std::map<wxString,wxString> vCardETag;
964 ContactListData ServerContactList;
966 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
967 //wxArrayString vCardDownload;
968 //std::map<wxString,wxString> vCardDownloadData;
970 // Get the list of vCard files locally.
972 wxString AccountDirFinal;
973 wxString AccountSyncTokenFilename;
974 wxString SyncTokenLoad;
976 #if defined(__HAIKU__)
978 //preffilename = wxT("noo");
980 #elif defined(__WIN32__)
982 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
983 AccountSyncTokenFilename = AccountDirFinal;
984 AccountSyncTokenFilename.Append(wxT("synctoken"));
988 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
989 AccountSyncTokenFilename = AccountDirFinal;
990 AccountSyncTokenFilename.Append(wxT("synctoken"));
994 // Suppress Error Messages.
996 wxLogNull PleaseDoNotDisturb;
999 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
1001 if (SyncLoad.IsOpened()){
1003 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1008 // Get a list of vCard files from the server.
1010 // Get the list of vCard files from the ETagDB.
1012 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1014 bool ExitLoop = FALSE;
1016 std::map<wxString,FileSyncData> *SCListData = NULL;
1018 while (ExitLoop == FALSE){
1020 ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
1021 SSLCertCollection certcol = ConnHandle.GetCertificateData();
1023 // Create a pointer for the std::map<wxString,FileSyncData>.
1025 SCListData = &ServerContactList.ListData;
1027 // Check if any errors have occured whilst getting the data.
1029 int ErrorCode = ConnHandle.GetResultCode();
1031 if (ErrorCode != 0){
1033 if (ErrorCode == 60 || ErrorCode == 51){
1035 // Invalid SSL certificate so bring up a dialog to the user
1036 // explaining what has happened and the options available.
1038 // Stop all the timers.
1040 frmMainPtrGet->PauseAllTimers();
1044 #if defined(__APPLE__)
1046 // Bring up the trust panel and display the SSL certificate dialog.
1048 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
1050 // Update the SSL account with the trust object.
1052 if (SSLResult != NSOKButton){
1054 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
1060 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1065 // Setup the data to be sent in the wxPostEvent command.
1067 SSLInvalidCertNotifObj SSLICNProcData;
1069 bool *PauseMode = new bool;
1073 qrn.QResponse = &SSLResult;
1074 qrn.PausePtr = PauseMode;
1076 SSLICNProcData.CertCollection = certcol;
1077 SSLICNProcData.QRNotifData = &qrn;
1078 SSLICNProcData.AccountName = AccountNameFriendly;
1080 wxCommandEvent event(INVALIDSSLCERT);
1081 event.SetClientData(&SSLICNProcData);
1082 wxPostEvent(frmMainPtrGet, event);
1086 // Fall asleep until we get an response.
1089 n1.tv_nsec = 250000000L;*/
1091 while (*PauseMode == TRUE){
1092 //nanosleep(&n1, &n2);
1093 SleepFor(250000000);
1096 // Process the response from the user.
1098 if (SSLResult == 1){
1100 // Accept the certificate. Write the certificate into the account
1101 // directory (as server.crt) - will overwrite old certificate.
1103 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
1104 WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
1106 } else if (SSLResult == 2){
1108 // Reject the certificate, abort the task and mark as failed.
1110 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
1118 // Resume all the timers.
1120 frmMainPtrGet->ResumeAllTimers();
1138 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1142 #if defined(__APPLE__)
1144 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1148 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
1152 // Look in directory and see which vCards to add and delete
1155 // vCard exists but not in ETagDB - Add (and upload).
1156 // vCard missing but in ETagDB - Delete (from server).
1158 // Start by looking for vCards that are not in the ETagDB.
1160 wxDir AccDir(AccountDirFinal);
1161 wxString AccDirFilename;
1163 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1165 // Process the server data.
1167 if (SCListData != NULL){
1169 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1170 fsiter != SCListData->end(); fsiter++){
1172 // Check the mode of the file before adding.
1174 // Get the HTTP status of the file from the list.
1176 FileSyncData fsd = fsiter->second;
1178 if (fsd.DataFlag == 1){
1180 // Added or modified contact.
1182 //vCardAdd.Add(fsiter->first, 1);
1184 vCardDownloadDataFileClass vCardNewData;
1185 vCardNewData.DataType = 0;
1186 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1188 //} else if (fsd.DataFlag == 1){
1190 // Contact has been modified on the server.
1192 // vCardUpdateLocal.Add(fsiter->first, 1);
1195 else if (fsd.DataFlag == 2){
1197 // Contact has been deleted.
1199 vCardDelete.Add(fsiter->first, 1);
1207 // Look for vCards that are missing but in the ETagDB.
1209 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1210 etagiter != ETagDBData.end(); etagiter++){
1212 // Check if the vCard exists.
1214 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1216 // vCard doesn't exist so mark for deleting.
1218 vCardDelete.Add(etagiter->first, 1);
1224 // Compare Server with the ETag DB. Work out which
1225 // needs to updated remotely and which needs to be
1228 for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1229 srviter != SCListData->end(); srviter++){
1231 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1235 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1237 ETagData etd = lociter->second;
1238 FileSyncData fsd = srviter->second;
1240 wxString ETagSrv = fsd.ETagData;
1242 // Check if the local ETag value has 'DELETED' set and skip
1243 // checking this file if it does.
1245 if (etd.ETagValue == "DELETED"){
1251 // Compare local ETag with original local ETag.
1252 // If different, update to server is required.
1254 if (etd.ETagValue != etd.ETagOrigValue){
1256 // Check if local original ETag is different from server ETag.
1257 // If it is then throw up a conflict resolution dialog.
1259 if (etd.ETagOrigValue != ETagSrv){
1261 vCard34Conv vCard34Obj;
1263 wxString ServerContactData;
1264 wxString FullFilename;
1266 vCard ConvertedV4Data;
1268 // Conflict. Bring up conflict resolution dialog.
1270 // Get the server contact data for comparison.
1272 ConnHandle.SetServerFilename(srviter->first);
1273 ConnHandle.GetServerContactData();
1274 ServerContactData = ConnHandle.GetPageData();
1276 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1278 // Convert it to v4.
1280 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1282 vCardConflictObj vCardProcData;
1284 vCardProcData.vCardLocalData = &ClientData;
1285 vCardProcData.vCardServerData = &ConvertedV4Data;
1287 // Load the client data from the filename given.
1289 ClientData.LoadFile(FullFilename);
1293 bool *PauseMode = new bool;
1296 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1299 qrn.QResponse = &ConflictResult;
1300 qrn.PausePtr = PauseMode;
1302 vCardProcData.QRNotifData = &qrn;
1304 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1305 event.SetClientData(&vCardProcData);
1306 wxPostEvent(frmMainPtrGet, event);
1311 n1.tv_nsec = 250000000L;*/
1313 while (*PauseMode == TRUE){
1314 //nanosleep(&n1, &n2);
1315 SleepFor(250000000);
1321 // If replacing local version, store copy for now.
1322 // Otherwise upload to server.
1324 if (ConflictResult == 0){
1330 } else if (ConflictResult == 1){
1332 // Decided to use client version.
1334 vCardUpdateLocal.Remove(srviter->first);
1335 vCardUpdateRemote.Add(srviter->first, 1);
1337 } else if (ConflictResult == 2){
1339 // Decided to use server version.
1340 // Store the converted downloaded copy for
1341 // processing later.
1343 //vCardUpdateLocal.Add(srviter->first, 1);
1345 vCardDownloadDataFileClass vCardNewData;
1346 vCardNewData.DataType = 1;
1347 vCardNewData.FileData = ConvertedV4Data.WriteString();
1349 ConvertedV4Data.WriteFile(FullFilename);
1351 vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData));
1359 // Send vCard to the server.
1361 vCardUpdateRemote.Add(srviter->first, 1);
1367 // Check if local ETag is different from server ETag.
1368 // If different, obtain the vCard from the server.
1370 if (etd.ETagOrigValue != ETagSrv){
1372 vCardUpdateLocal.Add(srviter->first, 1);
1380 // Process the vCards that need to be downloaded and added/overwritten.
1382 wxString vCardFilenameFinal;
1383 wxString vCardOutputData;
1384 wxString vCardInputData;
1385 wxString ETagFileData;
1388 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1389 additer != vCardDownloadData.end(); additer++){
1391 vCardFilenameFinal.Clear();
1392 vCardInputData.Clear();
1393 vCardOutputData.Clear();
1394 ETagFileData.Clear();
1396 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1398 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1400 if (additer->second.DataType == 0){
1402 vCard ConvertedV4Data;
1404 // Grab the file from the server and write the contact out.
1406 vCard34Conv vCard34Obj;
1408 ConnHandle.SetServerFilename(additer->first);
1409 ConnHandle.GetServerContactData();
1410 vCardInputData = ConnHandle.GetPageData();
1412 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1414 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1416 // Update the ETagDB.
1418 //vCardFile.Open(vCardFilenameFinal, wxT("w"));
1420 //if (vCardFile.IsOpened()){
1422 // vCardFile.Write(vCardOutputData, wxConvAuto());
1423 // vCardFile.Close();
1427 // Get the server ETag.
1429 wxString ServerETag;
1430 ConnHandle.GetServerETagValueThread();
1431 ServerETag = ConnHandle.ETagValueResult();
1433 // Add to the ETag Database.
1435 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1437 } else if (additer->second.DataType == 1){
1439 // Write out the contact to the account directory.
1441 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1442 vCardOutputData = additer->second.FileData;
1444 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1446 if (vCardFile.IsOpened()){
1448 vCardFile.Write(vCardOutputData, wxConvAuto());
1453 // Update the ETagDB.
1455 wxString ServerETag;
1456 ConnHandle.GetServerETagValueThread();
1457 ServerETag = ConnHandle.ETagValueResult();
1459 // Add to the ETag Database.
1461 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1466 // Look for vCard files which aren't in the ETagDB.
1468 while(ContinueProcess){
1470 // Check and make sure that the filename ends in .vcf/.vcard
1471 // Skip any file that beings with a dot.
1473 if (AccDirFilename.Left(1) == wxT(".")){
1475 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1480 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1481 AccDirFilename.Right(6) != wxT(".vcard")){
1483 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1488 // Look in the ETagDB for the file.
1490 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1492 if (ETagExists == FALSE){
1494 // Add the vCard to the list to be added.
1496 vCardAdd.Add(AccDirFilename, 1);
1500 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1504 // Process the vCards to add/update to the server.
1506 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1508 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1509 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1510 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1512 ContactFilename = vCardAdd[vi];
1513 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1515 ContactFilename.Trim();
1517 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1519 // Compare the ETag with the Server ETag.
1521 ConnHandle.SetServerFilename(vCardAdd[vi]);
1522 ConnHandle.GetServerETagValueThread();
1523 ETagServer = ConnHandle.ETagValueResult();
1525 if (ETagOriginal != ETagServer){
1527 // Server ETag is different from original ETag.
1528 // This is a conflict which the user will now
1531 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1533 vCard34Conv vCard34Obj;
1535 wxString ServerContactData;
1537 vCard ConvertedV4Data;
1539 // Load the client data from the filename given.
1541 ConnHandle.GetServerContactData();
1542 ServerContactData = ConnHandle.GetPageData();
1544 // Process v3 version into v4 version.
1546 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1548 vCardConflictObj vCardProcData;
1550 vCardProcData.vCardLocalData = &ClientData;
1551 vCardProcData.vCardServerData = &ConvertedV4Data;
1552 ClientData.LoadFile(FullFilename);
1554 //ContactConflictEvent event(ContactConflictCmdEnv);
1555 //event.SetData(ContactFilename, Moo1, Moo2);
1557 //wxPostEvent(frmMainPtrGet, event);
1559 // Setup Conflict Resolution Dialog.
1561 // Fetch Data from Server and convert.
1563 bool *PauseMode = new bool;
1568 qrn.QResponse = &ConflictResult;
1569 qrn.PausePtr = PauseMode;
1571 vCardProcData.QRNotifData = &qrn;
1573 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1574 event.SetClientData(&vCardProcData);
1575 wxPostEvent(frmMainPtrGet, event);
1580 n1.tv_nsec = 250000000L;*/
1582 while (*PauseMode == TRUE){
1583 //nanosleep(&n1, &n2);
1584 SleepFor(250000000);
1590 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1592 if (ConflictResult == 0){
1599 } else if (ConflictResult == 1){
1601 // Decided to use client version.
1603 ConnHandle.ProcessData();
1607 } else if (ConflictResult == 2){
1609 // Decided to use server version.
1611 // Download server version.
1613 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1621 // Setup the filename for the contact being added.
1623 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1624 wxString wxSCardData;
1628 // Load the data from the file.
1631 wxFCard.Open(wxSFilename, wxT("r"));
1633 if (wxFCard.IsOpened()){
1635 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1640 // Convert the data to v3.
1642 vCard34Conv vCard34Obj;
1644 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1646 // Setup the URL address.
1648 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1650 // Upload the data to the server.
1652 ConnHandle.SetUploadMode(TRUE);
1653 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1654 ConnHandle.ProcessData();
1656 // Get the Server ETag and put it in the ETag database.
1658 ConnHandle.SetServerFilename(vCardAdd[vi]);
1659 ConnHandle.GetServerETagValueThread();
1660 ETagServer = ConnHandle.ETagValueResult();
1662 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1668 if (ETagOriginal != ETagServer){
1670 // Server ETag is different from original ETag.
1671 // This is a conflict which the user will now
1674 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1676 //ContactConflictEvent event(ContactConflictCmdEnv);
1677 //event.SetData(ContactFilename, Moo1, Moo2);
1679 vCard34Conv vCard34Obj;
1681 wxString ServerContactData;
1683 vCard ConvertedV4Data;
1685 // Load the client data from the filename given.
1687 ConnHandle.GetServerContactData();
1688 ServerContactData = ConnHandle.GetPageData();
1689 ClientData.LoadFile(FullFilename);
1691 // Process v3 version into v4 version.
1693 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1695 vCardConflictObj vCardProcData;
1697 vCardProcData.vCardLocalData = &ClientData;
1698 vCardProcData.vCardServerData = &ConvertedV4Data;
1700 bool *PauseMode = new bool;
1705 qrn.QResponse = &ConflictResult;
1706 qrn.PausePtr = PauseMode;
1708 vCardProcData.QRNotifData = &qrn;
1710 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1711 event.SetClientData(&vCardProcData);
1712 wxPostEvent(frmMainPtrGet, event);
1717 n1.tv_nsec = 250000000L;*/
1719 while (*PauseMode == TRUE){
1720 //nanosleep(&n1, &n2);
1721 SleepFor(250000000);
1727 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1729 if (ConflictResult == 0){
1736 } else if (ConflictResult == 1){
1738 // Decided to use client version.
1740 ConnHandle.ProcessData();
1741 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
1742 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1746 } else if (ConflictResult == 2){
1748 // Decided to use server version.
1750 // Write server version to file.
1752 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1760 // Setup the filename for the contact being added.
1762 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1763 wxString wxSCardData;
1767 // Load the data from the file.
1770 wxFCard.Open(wxSFilename, wxT("r"));
1772 if (wxFCard.IsOpened()){
1774 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1779 // Convert the data to v3.
1781 vCard34Conv vCard34Obj;
1783 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1785 // Setup the URL address.
1787 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1789 // Upload the data to the server.
1791 ConnHandle.SetUploadMode(TRUE);
1792 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1793 ConnHandle.ProcessData();
1795 // Get the Server ETag and put it in the ETag database.
1797 ConnHandle.SetServerFilename(vCardAdd[vi]);
1798 ConnHandle.GetServerETagValueThread();
1799 ETagServer = ConnHandle.ETagValueResult();
1802 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1810 // Process the vCards to delete locally.
1812 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1814 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1818 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1824 // Process the vCards to delete from the server.
1826 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1827 std::list<wxString> DeleteList;
1829 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1830 deliter != ETagFilenameMap->end(); deliter++){
1832 // Look through the ETagDB and find contacts which are marked as DELETED.
1834 if (deliter->second == wxT("DELETED")){
1836 ConnHandle.SetUploadMode(FALSE);
1837 ConnHandle.SetupData(wxT("DELETE"), deliter->first, wxT(""));
1838 ConnHandle.ProcessDataThread();
1840 // Delete the ETag as the file has now been deleted.
1842 DeleteList.push_back(deliter->first);
1848 for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
1849 removeetagiter != DeleteList.end(); removeetagiter++){
1851 ETagDBPtr->RemoveETag(*removeetagiter);
1855 // Write out the update server sync token.
1857 wxString ServerSyncToken = ServerContactList.SyncToken;
1859 ServerSyncToken.Trim();
1861 if (!ServerSyncToken.IsEmpty()){
1864 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1866 if (SyncWrite.IsOpened()){
1868 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1875 // Check for another sync token. If there is another
1876 // sync token then repeat this. If token matches then stop processing.
1878 if (SyncTokenLoad == ServerSyncToken){
1880 KeepUpdating = FALSE;
1886 // Mark as completed.
1888 wxString AccountNameFinal;
1889 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1890 AccountNameFinal.Append(wxT(".carddav"));
1892 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1893 reloadevent.SetString(AccountNameFinal);
1894 wxPostEvent(this->GetParent(), reloadevent);
1901 // Update the data to the server.
1903 ConnHandle.ProcessData();
1912 n1.tv_nsec = 250000000L;*/
1914 while (iter->second == 1){
1916 SleepFor(250000000);
1917 //nanosleep(&n1, &n2);
1921 if ((iter->second == 4 && TypeIter->second == 0) ||
1922 (iter->second == 8 && TypeIter->second == 0)){
1924 AccountDir = StringAccountIter->second;
1925 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1927 ConnHandle.GetServerETagValueThread();
1928 ETagServer = ConnHandle.ETagValueResult();
1929 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1933 if ((iter->second == 4 && TypeIter->second == 1) ||
1934 (iter->second == 8 && TypeIter->second == 1)){
1936 AccountDir = StringAccountIter->second;
1937 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1939 ConnHandle.GetServerETagValueThread();
1940 ETagServer = ConnHandle.ETagValueResult();
1941 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1951 if (TasksFoundProc == FALSE){
1953 TasksActive = FALSE;
1954 ProcessTasksData = FALSE;
1958 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1959 wxPostEvent(this, eventp);
1961 //AnimationTimer.StartAnimation();
1962 //ActListProcTimer.Start();
1966 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1967 wxPostEvent(this, event);
1969 //ActProcessTimer.Start();
1973 void frmActivityMgr::ProcessTasks()
1976 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1977 ProcessThread.detach();
1981 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1984 ETagTmrPtr = ETagTmrPtrInc;
1986 frmMainPtr = frmMainPtrInc;
1990 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1992 QRNotif *qrn = (QRNotif *)event.GetClientData();
1994 int *QRes = qrn->QResponse;
1996 *qrn->PausePtr = FALSE;
1998 *QRes = event.GetInt();
2002 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
2004 wxCommandEvent connevent(CONNSTAT_UPDATE);
2006 if (SleepMode == FALSE){
2008 connevent.SetInt(1);
2013 connevent.SetInt(0);
2018 wxPostEvent(GetParent(), connevent);
2022 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
2024 wxString ServerCertFinal;
2026 // Get the Cert section of the certificate and write it to the file.
2028 ServerCertFinal = GetAccountDir(AccountName, TRUE);
2032 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2033 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
2035 CertFile.Open(ServerCertFinal, wxFile::write);
2037 CertFile.Write(SSLDataIter->second, wxConvUTF8);
2042 void frmActivityMgr::StartTimer(wxCommandEvent& event){
2044 ActListProcTimer.Start(1000, FALSE);
2048 void frmActivityMgr::StopTimer(wxCommandEvent& event){
2050 ActListProcTimer.Stop();
2054 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
2056 ActProcessTimer.Start(1000, FALSE);
2060 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
2062 ActProcessTimer.Stop();
2066 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2068 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2070 if (actmgrudata != NULL){
2072 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
2074 /*if (!actmgrudata->ItemDes.IsEmpty()){
2075 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);