1 #include "frmActivityMgr.h"
2 #include <wx/mstream.h>
5 #include <wx/tokenzr.h>
13 #include "common/preferences.h"
14 #include "frmConflictResolution.h"
15 #include "frmInvalidSSLCertificate.h"
17 #include "common/events.h"
18 #include "common/filename.h"
19 #include "common/dirs.h"
20 #include "vcard/vcard34conv.h"
21 #include "vcard/vcard.h"
24 #ifndef FRMACTIVITYMGR_H
25 #define FRMACTIVITYMGR_H
27 DEFINE_EVENT_TYPE(ACTMGR_RESUMEPROC);
28 DEFINE_EVENT_TYPE(ACTMGR_TOGGLECONN);
29 DEFINE_EVENT_TYPE(ACTMGR_STARTTIMER);
30 DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
31 DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
32 DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
33 DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
35 BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
36 EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
37 EVT_COMMAND(wxID_ANY, ACTMGR_TOGGLECONN, frmActivityMgr::ToggleConnectionStatus)
38 EVT_COMMAND(wxID_ANY, ACTMGR_STARTTIMER, frmActivityMgr::StartTimer)
39 EVT_COMMAND(wxID_ANY, ACTMGR_STOPTIMER, frmActivityMgr::StopTimer)
40 EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
41 EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
42 EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
45 frmActivityMgr::frmActivityMgr( wxWindow* parent )
47 frmActivityMgrADT( parent )
50 wxMemoryInputStream istream(icons_activitywindow_png, sizeof(icons_activitywindow_png));
51 wxImage icons_activitywindow_pngi(istream, wxBITMAP_TYPE_PNG);
52 wxBitmap activityiconbmp(icons_activitywindow_pngi, -1);
54 activityicon.CopyFromBitmap(activityiconbmp);
55 this->SetIcon(activityicon);
57 wxMemoryInputStream istream2(misc_activitysleep_png, sizeof(misc_activitysleep_png));
58 wxImage misc_activitysleep_pngi(istream2, wxBITMAP_TYPE_PNG);
59 wxBitmap sleepiconbmp(misc_activitysleep_pngi, -1);
60 SleepBitmap = sleepiconbmp;
61 bmpActivity->SetBitmap(SleepBitmap);
62 ActProcessTimer.SetupPointers(this);
63 lblDetails->SetLabel(_("No activity."));
65 ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail,
66 &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
67 &ActProcessTimer, &ActivityListFinDate);
69 AnimationTimer.SetBitmap(bmpActivity);
70 AnimationTimer.SetSleepBitmap(&SleepBitmap);
71 AnimationTimer.SetupPointer(this->GetParent());
73 wxListItem ColumnData;
75 ColumnData.SetText(_("Activity"));
76 ColumnData.SetWidth(175);
77 lstActivity->InsertColumn(0, ColumnData);
79 wxListItem ColumnData2;
81 ColumnData2.SetText(_("Account"));
82 ColumnData2.SetWidth(100);
83 lstActivity->InsertColumn(1, ColumnData2);
85 wxListItem ColumnData3;
87 ColumnData3.SetText(_("Status"));
88 ColumnData3.SetWidth(100);
89 lstActivity->InsertColumn(2, ColumnData3);
91 //AnimationTimer.StartAnimation();
93 // Create recovery database if it doesn't exist.
95 wxString RecoveryFilename = GetRecoveryDB();
99 if (wxFile::Exists(RecoveryFilename) == FALSE){
101 // Create the recovery database.
103 RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);
105 RecoveryDB.Write(wxT("BEGIN:XAB-RECOVERYDB\r\n"), wxConvUTF8);
106 RecoveryDB.Write(wxT("VERSION:1.0\r\n"), wxConvUTF8);
107 RecoveryDB.Write(wxT("COMMENT:Please do not alter or delete this file. DATA LOSS IS POSSIBLE!\r\n"), wxConvUTF8);
108 RecoveryDB.Write(wxT("END:XAB-RECOVERYDB\r\n"), wxConvUTF8);
115 #if wxABI_VERSION < 20900
116 RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
118 RecoveryDBF.Open(RecoveryFilename, wxT("r"));
121 // Load the recovery database for tasks not done.
123 if (RecoveryDBF.IsOpened() == TRUE){
125 wxString wxSRecoveryDB;
126 wxString RecoveryLine;
128 // Check if we are using wxWidgets version 2.8 or less and
129 // execute the required command accordingly.
131 RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
135 std::map<int, wxString> RecoveryFileLines;
136 std::map<int, wxString>::iterator striter;
138 wxStringTokenizer wSTRecoveryDBLines(wxSRecoveryDB, wxT("\r\n"));
140 int RecoveryLineSeek = 0;
142 while (wSTRecoveryDBLines.HasMoreTokens() == TRUE){
144 RecoveryLine = wSTRecoveryDBLines.GetNextToken();
145 RecoveryFileLines.insert(std::make_pair(RecoveryLineSeek, RecoveryLine));
154 //TestTimer.Start(50, FALSE);
157 int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAccount,
158 wxString TaskURL, wxString TaskFilename, wxString TaskFullFilename,
167 coldata.SetId(ActivityTaskID);
168 coldata.SetData(ActivityTaskID);
170 AnimationTimer.StartAnimation();
172 // Get the preferences file.
174 wxString PrefFilename = GetUserPrefDir();
176 XABPreferences PrefData(PrefFilename);
178 wxString AccountName;
180 wxString AccountAddress;
182 wxString AccountUsername;
183 wxString AccountPassword;
184 bool AccountSSL = FALSE;
185 wxString AccountPrefix;
187 // Look for the account and get the friendly name for the account.
189 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
191 AccountDir = PrefData.accounts.GetAccountDirectory(i);
194 AccountDir.Append(wxT(".carddav"));
196 if (AccountDir == TaskAccount){
198 AccountName = PrefData.accounts.GetAccountName(i);
199 AccountAddress = PrefData.accounts.GetAccountAddress(i);
200 AccountPort = PrefData.accounts.GetAccountPort(i);
201 AccountUsername = PrefData.accounts.GetAccountUsername(i);
202 AccountPassword = PrefData.accounts.GetAccountPassword(i);
203 AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
204 AccountSSL = PrefData.accounts.GetAccountSSL(i);
207 AccountAddress.Trim();
208 //AccountPort.Trim();
209 AccountUsername.Trim();
210 AccountPassword.Trim();
211 AccountPrefix.Trim();
218 CardDAVConn.SetupConnection(AccountAddress, AccountPort, AccountUsername, AccountPassword, AccountSSL, AccountPrefix, AccountDir);
219 CardDAVConn.SetupVariables(&ActivityList, ActivityTaskID);
220 CardDAVConn.SetupResultBools(&BlankBool, &BlankBool);
223 // 0 - Add a contact.
224 // 1 - Update a contact.
225 // 2 - Delete a contact.
226 // 3 - Account syncronisation.
230 coldata.SetText(_("Adding Contact '") + TaskDetail + _("'"));
231 itemindex = lstActivity->InsertItem(coldata);
233 lstActivity->SetItem(itemindex, 1, AccountName);
234 lstActivity->SetItem(itemindex, 2, _("Queued"));
236 CardDAVConn.SetUploadMode(TRUE);
237 CardDAVConn.SetupData(wxT("PUT"), TaskURL, TaskData);
239 // Setup all of the task details.
241 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
243 ActivityListType.insert(std::make_pair(ActivityTaskID, 0));
244 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
245 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
246 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
247 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
248 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
249 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
250 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
252 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
253 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
254 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
256 } else if (TaskType == 1){
258 coldata.SetText(_("Updating Contact '") + TaskDetail + _("'"));
259 itemindex = lstActivity->InsertItem(coldata);
261 lstActivity->SetItem(itemindex, 1, AccountName);
262 lstActivity->SetItem(itemindex, 2, _("Queued"));
264 CardDAVConn.SetUploadMode(TRUE);
265 CardDAVConn.SetupData(wxT("PUT"), TaskURL, TaskData);
266 CardDAVConn.SetEditMode(TRUE);
268 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
270 ActivityListType.insert(std::make_pair(ActivityTaskID, 1));
271 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
272 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
273 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
274 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
275 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
276 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
277 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
279 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
280 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
281 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
283 } else if (TaskType == 2){
285 coldata.SetText(_("Deleting Contact '") + TaskDetail + _("'"));
286 itemindex = lstActivity->InsertItem(coldata);
288 lstActivity->SetItem(itemindex, 1, AccountName);
289 lstActivity->SetItem(itemindex, 2, _("Queued"));
291 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
293 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
294 ActivityListType.insert(std::make_pair(ActivityTaskID, 2));
295 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
296 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
297 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
298 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
299 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
301 } else if (TaskType == 3){
303 coldata.SetText(_("Syncronising All Contacts"));
304 itemindex = lstActivity->InsertItem(coldata);
306 lstActivity->SetItem(itemindex, 1, AccountName);
307 lstActivity->SetItem(itemindex, 2, _("Queued"));
309 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
310 ActivityListType.insert(std::make_pair(ActivityTaskID, 3));
311 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
312 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
313 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, AccountPrefix));
314 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
315 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
319 ProcessTasksData = TRUE;
321 if (!ActProcessTimer.IsRunning()) {
323 wxCommandEvent event(ACTMGR_STARTTIMER);
324 wxPostEvent(this, event);
326 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
327 wxPostEvent(this, eventp);
329 //ActProcessTimer.Start(1000, FALSE);
330 //ActListProcTimer.Start(1000, FALSE);
334 // Update the recovery database.
336 return ActivityTaskID;
340 void frmActivityMgr::RemoveTask(){
342 // Remove task from the recovery database.
346 void frmActivityMgr::StopTask( wxCommandEvent& event ){
348 // Check if activity has been completed already before stopping.
350 long longSelected = -1;
351 int intSelectedData = 0;
353 longSelected = lstActivity->GetNextItem(longSelected,
355 wxLIST_STATE_SELECTED);
357 intSelectedData = (int)lstActivity->GetItemData(longSelected);
359 if (longSelected == -1){
363 std::map<int,CardDAV>::iterator CDAVter;
365 CDAVter = ActivityListConn.find(intSelectedData);
367 CDAVter->second.Abort();
369 lstActivity->SetItem(longSelected, 2, _("Stopped"));
373 void frmActivityMgr::StopAllTasks( wxCommandEvent& event ){
375 // Check if activity has been completed already before stopping.
377 // TODO: Look through for '1' and stop the running task(s).
379 long longSelected = -1;
380 int intSelectedData = 0;
382 longSelected = lstActivity->GetNextItem(longSelected,
384 wxLIST_STATE_SELECTED);
386 intSelectedData = (int)lstActivity->GetItemData(longSelected);
388 if (longSelected == -1){
392 std::map<int,CardDAV>::iterator CDAVter;
394 CDAVter = ActivityListConn.find(intSelectedData);
396 CDAVter->second.Abort();
398 lstActivity->SetItem(longSelected, 2, _("Stopped"));
399 AnimationTimer.StopAnimation();
400 bmpActivity->SetBitmap(SleepBitmap);
401 lblDetails->SetLabel(_("No activity."));
405 void frmActivityMgr::RetryTask( wxCommandEvent& event ){
407 // Check if activity has been completed already before retrying.
409 long longSelected = -1;
410 int intSelectedData = 0;
412 longSelected = lstActivity->GetNextItem(longSelected,
414 wxLIST_STATE_SELECTED);
416 intSelectedData = (int)lstActivity->GetItemData(longSelected);
418 if (longSelected == -1){
422 std::map<int,CardDAV>::iterator CDAVter;
424 CDAVter = ActivityListConn.find(intSelectedData);
428 //CDAVter->second.Abort();
430 std::map<int,int>::iterator Iter;
431 Iter = ActivityList.find(intSelectedData);
435 AnimationTimer.StartAnimation();
437 if (!ActProcessTimer.IsRunning()) {
439 ActProcessTimer.Start(150, FALSE);
440 ActListProcTimer.Start(150, FALSE);
444 //lstActivity->SetItem(longSelected, 2, _("Processing..."));
448 void frmActivityMgr::OpenWindow()
453 void frmActivityMgr::CloseWindow( wxCommandEvent& event )
459 void frmActivityMgr::CloseWindow( wxCloseEvent& event )
465 void frmActivityMgr::ProcessTasksThread()
468 if (ProcessTasksData == FALSE){
474 std::map<int,int>::iterator TypeIter;
475 std::map<int,wxString>::iterator StringIter;
476 std::map<int,wxString>::iterator StringDetailIter;
477 std::map<int,wxString>::iterator StringAccountIter;
478 std::map<int,wxString>::iterator StringFilenameIter;
479 std::map<int,wxString>::iterator StringFullFilenameIter;
480 std::map<int,wxString>::iterator StringTaskDetailIter;
481 std::map<int,wxString>::iterator StringETagIter;
482 std::map<int,wxString>::iterator StringETagOrigIter;
483 std::map<int,CardDAV>::iterator CardDAVIter;
484 std::map<int,long>::iterator LongIter;
485 bool TasksFoundProc = FALSE;
488 for (std::map<int,int>::iterator iter = ActivityList.begin();
489 iter != ActivityList.end(); ++iter){
491 // Check for any queued tasks and start one.
493 if (iter->second > 4){
497 CardDAVIter = ActivityListConn.find(iter->first);
498 TypeIter = ActivityListType.find(iter->first);
499 StringETagIter = ActivityListETag.find(iter->first);
500 StringETagOrigIter = ActivityListETagOriginal.find(iter->first);
501 StringAccountIter = ActivityListAccount.find(iter->first);
502 StringFilenameIter = ActivityListFilename.find(iter->first);
503 StringFullFilenameIter = ActivityListFullFilename.find(iter->first);
510 // 5 = Failed (UI Updated).
511 // 6 = Stopped (UI Updated).
512 // 7 = (Reserved) (UI Updated).
513 // 8 = Completed. (UI Updated).
515 if (iter->second == 0){
517 //CardDAVIter->second.
519 // Wait for process to finish.
522 TasksFoundProc = TRUE;
524 wxString ETagOriginal;
527 wxString ContactFilename;
528 wxString FullFilename;
533 if (TypeIter->second == 1){
534 CardDAVIter->second.GetServerETagValueThread();
535 ETagServer = CardDAVIter->second.ETagValueResult();
538 // Compare the ETags and work out if a conflict has occured.
540 if (TypeIter->second == 1){
542 ETag = StringETagIter->second;
543 ETagOriginal = StringETagOrigIter->second;
544 AccountDir = StringAccountIter->second;
545 ContactFilename = StringFilenameIter->second;
546 FullFilename = StringFullFilenameIter->second;
548 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
550 if (ETag == ETagOriginal){
552 // Compare the ETag with the Server ETag.
554 if (ETagOriginal != ETagServer){
556 // Server ETag is different from original ETag.
557 // This is a conflict which the user will now
563 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
565 vCard34Conv vCard34Obj;
567 wxString ServerContactData;
569 vCard ConvertedV4Data;
571 // Load the client data from the filename given.
573 CardDAVIter->second.GetServerContactData();
574 ServerContactData = CardDAVIter->second.GetPageData();
576 // Process v3 version into v4 version.
578 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
580 vCardConflictObj vCardProcData;
582 vCardProcData.vCardLocalData = &ClientData;
583 vCardProcData.vCardServerData = &ConvertedV4Data;
584 ClientData.LoadFile(FullFilename);
586 //ContactConflictEvent event(ContactConflictCmdEnv);
587 //event.SetData(ContactFilename, Moo1, Moo2);
589 //wxPostEvent(frmMainPtrGet, event);
591 // Setup Conflict Resolution Dialog.
593 // Fetch Data from Server and convert.
595 bool *PauseMode = new bool;
600 qrn.QResponse = &ConflictResult;
601 qrn.PausePtr = PauseMode;
603 vCardProcData.QRNotifData = &qrn;
605 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
606 event.SetClientData(&vCardProcData);
607 wxPostEvent(frmMainPtrGet, event);
612 n1.tv_nsec = 250000000L;*/
614 while (*PauseMode == TRUE){
615 //nanosleep(&n1, &n2);
622 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
624 if (ConflictResult == 0){
631 } else if (ConflictResult == 1){
633 // Decided to use client version.
635 CardDAVIter->second.ProcessData();
639 } else if (ConflictResult == 2){
641 // Decided to use server version.
643 // Download server version.
645 ConvertedV4Data.WriteFile(FullFilename);
653 // Update the data to the server.
655 CardDAVIter->second.ProcessData();
661 if (ETagOriginal != ETagServer){
663 // Server ETag is different from original ETag.
664 // This is a conflict which the user will now
667 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
669 //ContactConflictEvent event(ContactConflictCmdEnv);
670 //event.SetData(ContactFilename, Moo1, Moo2);
672 vCard34Conv vCard34Obj;
674 wxString ServerContactData;
676 vCard ConvertedV4Data;
678 // Load the client data from the filename given.
680 CardDAVIter->second.GetServerContactData();
681 ServerContactData = CardDAVIter->second.GetPageData();
682 ClientData.LoadFile(FullFilename);
684 // Process v3 version into v4 version.
686 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
688 vCardConflictObj vCardProcData;
690 vCardProcData.vCardLocalData = &ClientData;
691 vCardProcData.vCardServerData = &ConvertedV4Data;
693 bool *PauseMode = new bool;
698 qrn.QResponse = &ConflictResult;
699 qrn.PausePtr = PauseMode;
701 vCardProcData.QRNotifData = &qrn;
703 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
704 event.SetClientData(&vCardProcData);
705 wxPostEvent(frmMainPtrGet, event);
710 n1.tv_nsec = 250000000L;*/
712 while (*PauseMode == TRUE){
713 //nanosleep(&n1, &n2);
720 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
722 if (ConflictResult == 0){
729 } else if (ConflictResult == 1){
731 // Decided to use client version.
733 CardDAVIter->second.ProcessData();
734 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
735 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
739 } else if (ConflictResult == 2){
741 // Decided to use server version.
743 // Write server version to file.
745 ConvertedV4Data.WriteFile(FullFilename);
753 // Update the data to the server.
755 CardDAVIter->second.ProcessData();
761 // Update the ETag DB.
763 CardDAVIter->second.GetServerETagValueThread();
764 ETagServer = CardDAVIter->second.ETagValueResult();
765 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
769 } else if (TypeIter->second == 2) {
771 // Delete the contact from the server and update the ETag DB.
773 AccountDir = StringAccountIter->second;
774 ContactFilename = StringFilenameIter->second;
776 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
778 CardDAVIter->second.SetUploadMode(FALSE);
779 CardDAVIter->second.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
780 //CardDAVIter->second.SetServerFilename();
781 CardDAVIter->second.ProcessData();
782 ETagDBPtr->RemoveETag(ContactFilename);
786 } else if (TypeIter->second == 3) {
788 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
790 wxString AccountNameFriendly;
791 wxString PrefFilename = GetUserPrefDir();
793 XABPreferences PrefData(PrefFilename);
796 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
798 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
800 AccountDirCheck.Trim();
801 AccountDirCheck.Append(wxT(".carddav"));
803 if (AccountDirCheck == StringAccountIter->second){
805 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
812 bool KeepUpdating = TRUE;
814 while (KeepUpdating == TRUE){
816 StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
818 AccountDir = StringAccountIter->second;
820 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
822 wxArrayString vCardAdd;
823 wxArrayString vCardDelete;
824 wxArrayString vCardList;
825 wxArrayString vCardUpdateLocal;
826 wxArrayString vCardUpdateRemote;
827 wxArrayString vCardUpdateLog;
828 std::map<wxString,wxString> vCardETag;
829 ContactListData ServerContactList;
831 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
832 //wxArrayString vCardDownload;
833 //std::map<wxString,wxString> vCardDownloadData;
835 // Get the list of vCard files locally.
837 wxString AccountDirFinal;
838 wxString AccountSyncTokenFilename;
839 wxString SyncTokenLoad;
841 #if defined(__HAIKU__)
843 //preffilename = wxT("noo");
845 #elif defined(__WIN32__)
847 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
848 AccountSyncTokenFilename = AccountDirFinal;
849 AccountSyncTokenFilename.Append(wxT("synctoken"));
853 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
854 AccountSyncTokenFilename = AccountDirFinal;
855 AccountSyncTokenFilename.Append(wxT("synctoken"));
859 // Suppress Error Messages.
861 wxLogNull PleaseDoNotDisturb;
864 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
866 if (SyncLoad.IsOpened()){
868 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
873 // Get a list of vCard files from the server.
875 // Get the list of vCard files from the ETagDB.
877 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
879 CardDAV CardDAVInstance = CardDAVIter->second;
881 bool ExitLoop = FALSE;
883 std::map<wxString,FileSyncData> *SCListData = NULL;
885 while (ExitLoop == FALSE){
887 //ServerContactList = CardDAVInstance.GetContactList(SyncTokenLoad.ToUTF8());
888 ServerContactList = CardDAVIter->second.GetContactList(SyncTokenLoad.ToUTF8());
889 SSLCertCollection certcol = CardDAVIter->second.GetCertificateData();
891 // Create a pointer for the std::map<wxString,FileSyncData>.
893 SCListData = &ServerContactList.ListData;
895 // Check if any errors have occured whilst getting the data.
897 int ErrorCode = CardDAVIter->second.GetResultCode();
901 if (ErrorCode == 60 || ErrorCode == 51){
903 // Invalid SSL certificate so bring up a dialog to the user
904 // explaining what has happened and the options available.
906 // Stop all the timers.
908 frmMainPtrGet->PauseAllTimers();
910 // Setup the data to be sent in the wxPostEvent command.
912 SSLInvalidCertNotifObj SSLICNProcData;
914 bool *PauseMode = new bool;
919 qrn.QResponse = &SSLResult;
920 qrn.PausePtr = PauseMode;
922 SSLICNProcData.CertCollection = certcol;
923 SSLICNProcData.QRNotifData = &qrn;
924 SSLICNProcData.AccountName = AccountNameFriendly;
926 wxCommandEvent event(INVALIDSSLCERT);
927 event.SetClientData(&SSLICNProcData);
928 wxPostEvent(frmMainPtrGet, event);
932 // Fall asleep until we get an response.
935 n1.tv_nsec = 250000000L;*/
937 while (*PauseMode == TRUE){
938 //nanosleep(&n1, &n2);
942 // Process the response from the user.
946 // Accept the certificate. Write the certificate into the account
947 // directory (as server.crt) - will overwrite old certificate.
949 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
950 WriteServerCertificate(AccountDir, CardDAVIter->second.GetCertificateData());
952 } else if (SSLResult == 2){
954 // Reject the certificate, abort the task and mark as failed.
956 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, CardDAVIter->second.GetCertificateData());
962 // Resume all the timers.
964 frmMainPtrGet->ResumeAllTimers();
981 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
985 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
987 // Look in directory and see which vCards to add and delete
990 // vCard exists but not in ETagDB - Add (and upload).
991 // vCard missing but in ETagDB - Delete (from server).
993 // Start by looking for vCards that are not in the ETagDB.
995 wxDir AccDir(AccountDirFinal);
996 wxString AccDirFilename;
998 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1000 // Process the server data.
1002 if (SCListData != NULL){
1004 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1005 fsiter != SCListData->end(); fsiter++){
1007 // Check the mode of the file before adding.
1009 // Get the HTTP status of the file from the list.
1011 FileSyncData fsd = fsiter->second;
1013 if (fsd.DataFlag == 1){
1015 // Added or modified contact.
1017 //vCardAdd.Add(fsiter->first, 1);
1019 vCardDownloadDataFileClass vCardNewData;
1020 vCardNewData.DataType = 0;
1021 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1023 //} else if (fsd.DataFlag == 1){
1025 // Contact has been modified on the server.
1027 // vCardUpdateLocal.Add(fsiter->first, 1);
1030 else if (fsd.DataFlag == 2){
1032 // Contact has been deleted.
1034 vCardDelete.Add(fsiter->first, 1);
1042 // Look for vCards that are missing but in the ETagDB.
1044 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1045 etagiter != ETagDBData.end(); etagiter++){
1047 // Check if the vCard exists.
1049 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1051 // vCard doesn't exist so mark for deleting.
1053 vCardDelete.Add(etagiter->first, 1);
1059 // Compare Server with the ETag DB. Work out which
1060 // needs to updated remotely and which needs to be
1063 for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1064 srviter != SCListData->end(); srviter++){
1066 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1070 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1072 ETagData etd = lociter->second;
1073 FileSyncData fsd = srviter->second;
1075 wxString ETagSrv = fsd.ETagData;
1077 // Compare local ETag with original local ETag.
1078 // If different, update to server is required.
1080 if (etd.ETagValue != etd.ETagOrigValue){
1082 // Check if local original ETag is different from server ETag.
1083 // If it is then throw up a conflict resolution dialog.
1085 if (etd.ETagOrigValue != ETagSrv){
1087 vCard34Conv vCard34Obj;
1089 wxString ServerContactData;
1090 wxString FullFilename;
1092 vCard ConvertedV4Data;
1094 // Conflict. Bring up conflict resolution dialog.
1096 // Get the server contact data for comparison.
1098 CardDAVIter->second.SetServerFilename(srviter->first);
1099 CardDAVIter->second.GetServerContactData();
1100 ServerContactData = CardDAVIter->second.GetPageData();
1102 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1104 // Convert it to v4.
1106 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1108 vCardConflictObj vCardProcData;
1110 vCardProcData.vCardLocalData = &ClientData;
1111 vCardProcData.vCardServerData = &ConvertedV4Data;
1113 // Load the client data from the filename given.
1115 ClientData.LoadFile(FullFilename);
1119 bool *PauseMode = new bool;
1122 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1125 qrn.QResponse = &ConflictResult;
1126 qrn.PausePtr = PauseMode;
1128 vCardProcData.QRNotifData = &qrn;
1130 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1131 event.SetClientData(&vCardProcData);
1132 wxPostEvent(frmMainPtrGet, event);
1137 n1.tv_nsec = 250000000L;*/
1139 while (*PauseMode == TRUE){
1140 //nanosleep(&n1, &n2);
1141 SleepFor(250000000);
1147 // If replacing local version, store copy for now.
1148 // Otherwise upload to server.
1150 if (ConflictResult == 0){
1156 } else if (ConflictResult == 1){
1158 // Decided to use client version.
1160 vCardUpdateLocal.Remove(srviter->first);
1161 vCardUpdateRemote.Add(srviter->first, 1);
1163 } else if (ConflictResult == 2){
1165 // Decided to use server version.
1166 // Store the converted downloaded copy for
1167 // processing later.
1169 //vCardUpdateLocal.Add(srviter->first, 1);
1171 vCardDownloadDataFileClass vCardNewData;
1172 vCardNewData.DataType = 1;
1173 vCardNewData.FileData = ConvertedV4Data.WriteString();
1175 ConvertedV4Data.WriteFile(FullFilename);
1177 vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData));
1185 // Send vCard to the server.
1187 vCardUpdateRemote.Add(srviter->first, 1);
1193 // Check if local ETag is different from server ETag.
1194 // If different, obtain the vCard from the server.
1196 if (etd.ETagOrigValue != ETagSrv){
1198 vCardUpdateLocal.Add(srviter->first, 1);
1206 // Process the vCards that need to be downloaded and added/overwritten.
1208 wxString vCardFilenameFinal;
1209 wxString vCardOutputData;
1210 wxString vCardInputData;
1211 wxString ETagFileData;
1214 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1215 additer != vCardDownloadData.end(); additer++){
1217 vCardFilenameFinal.Clear();
1218 vCardInputData.Clear();
1219 vCardOutputData.Clear();
1220 ETagFileData.Clear();
1222 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1224 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1226 if (additer->second.DataType == 0){
1228 vCard ConvertedV4Data;
1230 // Grab the file from the server and write the contact out.
1232 vCard34Conv vCard34Obj;
1234 CardDAVIter->second.SetServerFilename(additer->first);
1235 CardDAVIter->second.GetServerContactData();
1236 vCardInputData = CardDAVIter->second.GetPageData();
1238 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1240 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1242 // Update the ETagDB.
1244 //vCardFile.Open(vCardFilenameFinal, wxT("w"));
1246 //if (vCardFile.IsOpened()){
1248 // vCardFile.Write(vCardOutputData, wxConvAuto());
1249 // vCardFile.Close();
1253 // Get the server ETag.
1255 wxString ServerETag;
1256 CardDAVIter->second.GetServerETagValueThread();
1257 ServerETag = CardDAVIter->second.ETagValueResult();
1259 // Add to the ETag Database.
1261 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1263 } else if (additer->second.DataType == 1){
1265 // Write out the contact to the account directory.
1267 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1268 vCardOutputData = additer->second.FileData;
1270 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1272 if (vCardFile.IsOpened()){
1274 vCardFile.Write(vCardOutputData, wxConvAuto());
1279 // Update the ETagDB.
1281 wxString ServerETag;
1282 CardDAVIter->second.GetServerETagValueThread();
1283 ServerETag = CardDAVIter->second.ETagValueResult();
1285 // Add to the ETag Database.
1287 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1292 // Look for vCard files which aren't in the ETagDB.
1294 while(ContinueProcess){
1296 // Check and make sure that the filename ends in .vcf/.vcard
1297 // Skip any file that beings with a dot.
1299 if (AccDirFilename.Left(1) == wxT(".")){
1301 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1306 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1307 AccDirFilename.Right(6) != wxT(".vcard")){
1309 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1314 // Look in the ETagDB for the file.
1316 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1318 if (ETagExists == FALSE){
1320 // Add the vCard to the list to be added.
1322 vCardAdd.Add(AccDirFilename, 1);
1326 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1330 // Process the vCards to add/update to the server.
1332 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1334 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1335 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1336 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1338 ContactFilename = vCardAdd[vi];
1339 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1341 ContactFilename.Trim();
1343 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1345 // Compare the ETag with the Server ETag.
1347 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1348 CardDAVIter->second.GetServerETagValueThread();
1349 ETagServer = CardDAVIter->second.ETagValueResult();
1351 if (ETagOriginal != ETagServer){
1353 // Server ETag is different from original ETag.
1354 // This is a conflict which the user will now
1357 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1359 vCard34Conv vCard34Obj;
1361 wxString ServerContactData;
1363 vCard ConvertedV4Data;
1365 // Load the client data from the filename given.
1367 CardDAVIter->second.GetServerContactData();
1368 ServerContactData = CardDAVIter->second.GetPageData();
1370 // Process v3 version into v4 version.
1372 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1374 vCardConflictObj vCardProcData;
1376 vCardProcData.vCardLocalData = &ClientData;
1377 vCardProcData.vCardServerData = &ConvertedV4Data;
1378 ClientData.LoadFile(FullFilename);
1380 //ContactConflictEvent event(ContactConflictCmdEnv);
1381 //event.SetData(ContactFilename, Moo1, Moo2);
1383 //wxPostEvent(frmMainPtrGet, event);
1385 // Setup Conflict Resolution Dialog.
1387 // Fetch Data from Server and convert.
1389 bool *PauseMode = new bool;
1394 qrn.QResponse = &ConflictResult;
1395 qrn.PausePtr = PauseMode;
1397 vCardProcData.QRNotifData = &qrn;
1399 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1400 event.SetClientData(&vCardProcData);
1401 wxPostEvent(frmMainPtrGet, event);
1406 n1.tv_nsec = 250000000L;*/
1408 while (*PauseMode == TRUE){
1409 //nanosleep(&n1, &n2);
1410 SleepFor(250000000);
1416 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1418 if (ConflictResult == 0){
1425 } else if (ConflictResult == 1){
1427 // Decided to use client version.
1429 CardDAVIter->second.ProcessData();
1433 } else if (ConflictResult == 2){
1435 // Decided to use server version.
1437 // Download server version.
1439 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1447 // Setup the filename for the contact being added.
1449 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1450 wxString wxSCardData;
1454 // Load the data from the file.
1457 wxFCard.Open(wxSFilename, wxT("r"));
1459 if (wxFCard.IsOpened()){
1461 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1466 // Convert the data to v3.
1468 vCard34Conv vCard34Obj;
1470 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1472 // Setup the URL address.
1474 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1476 // Upload the data to the server.
1478 CardDAVIter->second.SetUploadMode(TRUE);
1479 CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1480 CardDAVIter->second.ProcessData();
1482 // Get the Server ETag and put it in the ETag database.
1484 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1485 CardDAVIter->second.GetServerETagValueThread();
1486 ETagServer = CardDAVIter->second.ETagValueResult();
1488 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1494 if (ETagOriginal != ETagServer){
1496 // Server ETag is different from original ETag.
1497 // This is a conflict which the user will now
1500 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1502 //ContactConflictEvent event(ContactConflictCmdEnv);
1503 //event.SetData(ContactFilename, Moo1, Moo2);
1505 vCard34Conv vCard34Obj;
1507 wxString ServerContactData;
1509 vCard ConvertedV4Data;
1511 // Load the client data from the filename given.
1513 CardDAVIter->second.GetServerContactData();
1514 ServerContactData = CardDAVIter->second.GetPageData();
1515 ClientData.LoadFile(FullFilename);
1517 // Process v3 version into v4 version.
1519 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1521 vCardConflictObj vCardProcData;
1523 vCardProcData.vCardLocalData = &ClientData;
1524 vCardProcData.vCardServerData = &ConvertedV4Data;
1526 bool *PauseMode = new bool;
1531 qrn.QResponse = &ConflictResult;
1532 qrn.PausePtr = PauseMode;
1534 vCardProcData.QRNotifData = &qrn;
1536 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1537 event.SetClientData(&vCardProcData);
1538 wxPostEvent(frmMainPtrGet, event);
1543 n1.tv_nsec = 250000000L;*/
1545 while (*PauseMode == TRUE){
1546 //nanosleep(&n1, &n2);
1547 SleepFor(250000000);
1553 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1555 if (ConflictResult == 0){
1562 } else if (ConflictResult == 1){
1564 // Decided to use client version.
1566 CardDAVIter->second.ProcessData();
1567 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
1568 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1572 } else if (ConflictResult == 2){
1574 // Decided to use server version.
1576 // Write server version to file.
1578 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1586 // Setup the filename for the contact being added.
1588 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1589 wxString wxSCardData;
1593 // Load the data from the file.
1596 wxFCard.Open(wxSFilename, wxT("r"));
1598 if (wxFCard.IsOpened()){
1600 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1605 // Convert the data to v3.
1607 vCard34Conv vCard34Obj;
1609 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1611 // Setup the URL address.
1613 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1615 // Upload the data to the server.
1617 CardDAVIter->second.SetUploadMode(TRUE);
1618 CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1619 CardDAVIter->second.ProcessData();
1621 // Get the Server ETag and put it in the ETag database.
1623 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1624 CardDAVIter->second.GetServerETagValueThread();
1625 ETagServer = CardDAVIter->second.ETagValueResult();
1628 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1636 // Process the vCards to delete locally.
1638 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1640 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1644 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1650 // Process the vCards to delete from the server.
1652 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1655 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1656 deliter != ETagFilenameMap->end(); deliter++){
1658 // Look through the ETagDB and find contacts which are marked as DELETED.
1660 if (deliter->second == wxT("DELETED")){
1662 CardDAVIter->second.SetUploadMode(FALSE);
1663 CardDAVIter->second.SetupData(wxT("DELETE"), deliter->first, wxT(""));
1664 CardDAVIter->second.ProcessData();
1666 // Delete the ETag as the file has now been deleted.
1668 ETagDBPtr->RemoveETag(deliter->first);
1674 // Write out the update server sync token.
1676 wxString ServerSyncToken = ServerContactList.SyncToken;
1678 ServerSyncToken.Trim();
1680 if (!ServerSyncToken.IsEmpty()){
1683 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1685 if (SyncWrite.IsOpened()){
1687 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1694 // Check for another sync token. If there is another
1695 // sync token then repeat this. If token matches then stop processing.
1697 if (SyncTokenLoad == ServerSyncToken){
1699 KeepUpdating = FALSE;
1705 // Mark as completed.
1707 wxString AccountNameFinal;
1708 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1709 AccountNameFinal.Append(wxT(".carddav"));
1711 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1712 reloadevent.SetString(AccountNameFinal);
1713 wxPostEvent(this->GetParent(), reloadevent);
1720 // Update the data to the server.
1722 CardDAVIter->second.ProcessData();
1731 n1.tv_nsec = 250000000L;*/
1733 while (iter->second == 1){
1735 SleepFor(250000000);
1736 //nanosleep(&n1, &n2);
1740 if ((iter->second == 4 && TypeIter->second == 0) ||
1741 (iter->second == 8 && TypeIter->second == 0)){
1743 AccountDir = StringAccountIter->second;
1744 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1746 CardDAVIter->second.GetServerETagValueThread();
1747 ETagServer = CardDAVIter->second.ETagValueResult();
1748 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1752 if ((iter->second == 4 && TypeIter->second == 1) ||
1753 (iter->second == 8 && TypeIter->second == 1)){
1755 AccountDir = StringAccountIter->second;
1756 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1758 CardDAVIter->second.GetServerETagValueThread();
1759 ETagServer = CardDAVIter->second.ETagValueResult();
1760 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1770 if (TasksFoundProc == FALSE){
1772 TasksActive = FALSE;
1773 ProcessTasksData = FALSE;
1777 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1778 wxPostEvent(this, eventp);
1780 //AnimationTimer.StartAnimation();
1781 //ActListProcTimer.Start();
1785 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1786 wxPostEvent(this, event);
1788 //ActProcessTimer.Start();
1792 void frmActivityMgr::ProcessTasks()
1795 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1796 ProcessThread.detach();
1800 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1803 ETagTmrPtr = ETagTmrPtrInc;
1805 frmMainPtr = frmMainPtrInc;
1809 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1811 QRNotif *qrn = (QRNotif *)event.GetClientData();
1813 int *QRes = qrn->QResponse;
1815 *qrn->PausePtr = FALSE;
1817 *QRes = event.GetInt();
1821 int frmActivityMgr::GetTaskStatus(int intTaskID){
1825 if (ActivityList.find(intTaskID) == ActivityList.end()){
1831 std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
1832 intResult = taskiter->second;
1838 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
1840 wxCommandEvent connevent(CONNSTAT_UPDATE);
1842 if (SleepMode == FALSE){
1844 connevent.SetInt(1);
1849 connevent.SetInt(0);
1854 wxPostEvent(GetParent(), connevent);
1858 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
1860 wxString ServerCertFinal;
1862 // Get the Cert section of the certificate and write it to the file.
1864 ServerCertFinal = GetAccountDir(AccountName, TRUE);
1868 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
1869 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
1871 CertFile.Open(ServerCertFinal, wxFile::write);
1873 CertFile.Write(SSLDataIter->second, wxConvUTF8);
1878 void frmActivityMgr::StartTimer(wxCommandEvent& event){
1880 ActListProcTimer.Start(1000, FALSE);
1884 void frmActivityMgr::StopTimer(wxCommandEvent& event){
1886 ActListProcTimer.Stop();
1890 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
1892 ActProcessTimer.Start(1000, FALSE);
1896 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
1898 ActProcessTimer.Stop();
1902 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
1904 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
1906 if (actmgrudata != NULL){
1908 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
1910 /*if (!actmgrudata->ItemDes.IsEmpty()){
1911 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);