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 // TODO: Pass the ETagDB for the account to the connection.
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);
654 // Update the data to the server.
656 CardDAVIter->second.ProcessData();
662 if (ETagOriginal != ETagServer){
664 // Server ETag is different from original ETag.
665 // This is a conflict which the user will now
668 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
670 //ContactConflictEvent event(ContactConflictCmdEnv);
671 //event.SetData(ContactFilename, Moo1, Moo2);
673 vCard34Conv vCard34Obj;
675 wxString ServerContactData;
677 vCard ConvertedV4Data;
679 // Load the client data from the filename given.
681 CardDAVIter->second.GetServerContactData();
682 ServerContactData = CardDAVIter->second.GetPageData();
683 ClientData.LoadFile(FullFilename);
685 // Process v3 version into v4 version.
687 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
689 vCardConflictObj vCardProcData;
691 vCardProcData.vCardLocalData = &ClientData;
692 vCardProcData.vCardServerData = &ConvertedV4Data;
694 bool *PauseMode = new bool;
699 qrn.QResponse = &ConflictResult;
700 qrn.PausePtr = PauseMode;
702 vCardProcData.QRNotifData = &qrn;
704 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
705 event.SetClientData(&vCardProcData);
706 wxPostEvent(frmMainPtrGet, event);
711 n1.tv_nsec = 250000000L;*/
713 while (*PauseMode == TRUE){
714 //nanosleep(&n1, &n2);
721 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
723 if (ConflictResult == 0){
730 } else if (ConflictResult == 1){
732 // Decided to use client version.
734 CardDAVIter->second.ProcessData();
735 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
736 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
740 } else if (ConflictResult == 2){
742 // Decided to use server version.
744 // Write server version to file.
746 ConvertedV4Data.WriteFile(FullFilename);
754 // Update the data to the server.
756 CardDAVIter->second.ProcessData();
762 // Update the ETag DB.
764 CardDAVIter->second.GetServerETagValueThread();
765 ETagServer = CardDAVIter->second.ETagValueResult();
766 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
770 } else if (TypeIter->second == 2) {
772 // Delete the contact from the server and update the ETag DB.
774 AccountDir = StringAccountIter->second;
775 ContactFilename = StringFilenameIter->second;
777 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
779 CardDAVIter->second.SetUploadMode(FALSE);
780 CardDAVIter->second.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
781 //CardDAVIter->second.SetServerFilename();
782 CardDAVIter->second.ProcessData();
783 ETagDBPtr->RemoveETag(ContactFilename);
787 } else if (TypeIter->second == 3) {
789 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
791 wxString AccountNameFriendly;
792 wxString PrefFilename = GetUserPrefDir();
794 XABPreferences PrefData(PrefFilename);
797 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
799 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
801 AccountDirCheck.Trim();
802 AccountDirCheck.Append(wxT(".carddav"));
804 if (AccountDirCheck == StringAccountIter->second){
806 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
813 bool KeepUpdating = TRUE;
815 while (KeepUpdating == TRUE){
817 StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
819 AccountDir = StringAccountIter->second;
821 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
823 wxArrayString vCardAdd;
824 wxArrayString vCardDelete;
825 wxArrayString vCardList;
826 wxArrayString vCardUpdateLocal;
827 wxArrayString vCardUpdateRemote;
828 wxArrayString vCardUpdateLog;
829 std::map<wxString,wxString> vCardETag;
830 ContactListData ServerContactList;
832 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
833 //wxArrayString vCardDownload;
834 //std::map<wxString,wxString> vCardDownloadData;
836 // Get the list of vCard files locally.
838 wxString AccountDirFinal;
839 wxString AccountSyncTokenFilename;
840 wxString SyncTokenLoad;
842 #if defined(__HAIKU__)
844 //preffilename = wxT("noo");
846 #elif defined(__WIN32__)
848 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
849 AccountSyncTokenFilename = AccountDirFinal;
850 AccountSyncTokenFilename.Append(wxT("synctoken"));
854 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
855 AccountSyncTokenFilename = AccountDirFinal;
856 AccountSyncTokenFilename.Append(wxT("synctoken"));
860 // Suppress Error Messages.
862 wxLogNull PleaseDoNotDisturb;
865 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
867 if (SyncLoad.IsOpened()){
869 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
874 // Get a list of vCard files from the server.
876 // Get the list of vCard files from the ETagDB.
878 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
880 CardDAV CardDAVInstance = CardDAVIter->second;
882 bool ExitLoop = FALSE;
884 std::map<wxString,FileSyncData> *SCListData = NULL;
886 while (ExitLoop == FALSE){
888 //ServerContactList = CardDAVInstance.GetContactList(SyncTokenLoad.ToUTF8());
889 ServerContactList = CardDAVIter->second.GetContactList(SyncTokenLoad.ToUTF8());
890 SSLCertCollection certcol = CardDAVIter->second.GetCertificateData();
892 // Create a pointer for the std::map<wxString,FileSyncData>.
894 SCListData = &ServerContactList.ListData;
896 // Check if any errors have occured whilst getting the data.
898 int ErrorCode = CardDAVIter->second.GetResultCode();
902 if (ErrorCode == 60 || ErrorCode == 51){
904 // Invalid SSL certificate so bring up a dialog to the user
905 // explaining what has happened and the options available.
907 // Stop all the timers.
909 frmMainPtrGet->PauseAllTimers();
911 // Setup the data to be sent in the wxPostEvent command.
913 SSLInvalidCertNotifObj SSLICNProcData;
915 bool *PauseMode = new bool;
920 qrn.QResponse = &SSLResult;
921 qrn.PausePtr = PauseMode;
923 SSLICNProcData.CertCollection = certcol;
924 SSLICNProcData.QRNotifData = &qrn;
925 SSLICNProcData.AccountName = AccountNameFriendly;
927 wxCommandEvent event(INVALIDSSLCERT);
928 event.SetClientData(&SSLICNProcData);
929 wxPostEvent(frmMainPtrGet, event);
933 // Fall asleep until we get an response.
936 n1.tv_nsec = 250000000L;*/
938 while (*PauseMode == TRUE){
939 //nanosleep(&n1, &n2);
943 // Process the response from the user.
947 // Accept the certificate. Write the certificate into the account
948 // directory (as server.crt) - will overwrite old certificate.
950 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
951 WriteServerCertificate(AccountDir, CardDAVIter->second.GetCertificateData());
953 } else if (SSLResult == 2){
955 // Reject the certificate, abort the task and mark as failed.
957 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, CardDAVIter->second.GetCertificateData());
963 // Resume all the timers.
965 frmMainPtrGet->ResumeAllTimers();
982 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
986 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
988 // Look in directory and see which vCards to add and delete
991 // vCard exists but not in ETagDB - Add (and upload).
992 // vCard missing but in ETagDB - Delete (from server).
994 // Start by looking for vCards that are not in the ETagDB.
996 wxDir AccDir(AccountDirFinal);
997 wxString AccDirFilename;
999 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1001 // Process the server data.
1003 if (SCListData != NULL){
1005 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1006 fsiter != SCListData->end(); fsiter++){
1008 // Check the mode of the file before adding.
1010 // Get the HTTP status of the file from the list.
1012 FileSyncData fsd = fsiter->second;
1014 if (fsd.DataFlag == 1){
1016 // Added or modified contact.
1018 //vCardAdd.Add(fsiter->first, 1);
1020 vCardDownloadDataFileClass vCardNewData;
1021 vCardNewData.DataType = 0;
1022 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1024 //} else if (fsd.DataFlag == 1){
1026 // Contact has been modified on the server.
1028 // vCardUpdateLocal.Add(fsiter->first, 1);
1031 else if (fsd.DataFlag == 2){
1033 // Contact has been deleted.
1035 vCardDelete.Add(fsiter->first, 1);
1043 // Look for vCards that are missing but in the ETagDB.
1045 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1046 etagiter != ETagDBData.end(); etagiter++){
1048 // Check if the vCard exists.
1050 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1052 // vCard doesn't exist so mark for deleting.
1054 vCardDelete.Add(etagiter->first, 1);
1060 // Compare Server with the ETag DB. Work out which
1061 // needs to updated remotely and which needs to be
1064 for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1065 srviter != SCListData->end(); srviter++){
1067 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1071 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1073 ETagData etd = lociter->second;
1074 FileSyncData fsd = srviter->second;
1076 wxString ETagSrv = fsd.ETagData;
1078 // Compare local ETag with original local ETag.
1079 // If different, update to server is required.
1081 if (etd.ETagValue != etd.ETagOrigValue){
1083 // Check if local original ETag is different from server ETag.
1084 // If it is then throw up a conflict resolution dialog.
1086 if (etd.ETagOrigValue != ETagSrv){
1088 vCard34Conv vCard34Obj;
1090 wxString ServerContactData;
1091 wxString FullFilename;
1093 vCard ConvertedV4Data;
1095 // Conflict. Bring up conflict resolution dialog.
1097 // Get the server contact data for comparison.
1099 CardDAVIter->second.SetServerFilename(srviter->first);
1100 CardDAVIter->second.GetServerContactData();
1101 ServerContactData = CardDAVIter->second.GetPageData();
1103 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1105 // Convert it to v4.
1107 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1109 vCardConflictObj vCardProcData;
1111 vCardProcData.vCardLocalData = &ClientData;
1112 vCardProcData.vCardServerData = &ConvertedV4Data;
1114 // Load the client data from the filename given.
1116 ClientData.LoadFile(FullFilename);
1120 bool *PauseMode = new bool;
1123 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1126 qrn.QResponse = &ConflictResult;
1127 qrn.PausePtr = PauseMode;
1129 vCardProcData.QRNotifData = &qrn;
1131 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1132 event.SetClientData(&vCardProcData);
1133 wxPostEvent(frmMainPtrGet, event);
1138 n1.tv_nsec = 250000000L;*/
1140 while (*PauseMode == TRUE){
1141 //nanosleep(&n1, &n2);
1142 SleepFor(250000000);
1148 // If replacing local version, store copy for now.
1149 // Otherwise upload to server.
1151 if (ConflictResult == 0){
1157 } else if (ConflictResult == 1){
1159 // Decided to use client version.
1161 vCardUpdateLocal.Remove(srviter->first);
1162 vCardUpdateRemote.Add(srviter->first, 1);
1164 } else if (ConflictResult == 2){
1166 // Decided to use server version.
1167 // Store the converted downloaded copy for
1168 // processing later.
1170 //vCardUpdateLocal.Add(srviter->first, 1);
1172 vCardDownloadDataFileClass vCardNewData;
1173 vCardNewData.DataType = 1;
1174 vCardNewData.FileData = ConvertedV4Data.WriteString();
1176 ConvertedV4Data.WriteFile(FullFilename);
1178 vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData));
1186 // Send vCard to the server.
1188 vCardUpdateRemote.Add(srviter->first, 1);
1194 // Check if local ETag is different from server ETag.
1195 // If different, obtain the vCard from the server.
1197 if (etd.ETagOrigValue != ETagSrv){
1199 vCardUpdateLocal.Add(srviter->first, 1);
1207 // Process the vCards that need to be downloaded and added/overwritten.
1209 wxString vCardFilenameFinal;
1210 wxString vCardOutputData;
1211 wxString vCardInputData;
1212 wxString ETagFileData;
1215 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1216 additer != vCardDownloadData.end(); additer++){
1218 vCardFilenameFinal.Clear();
1219 vCardInputData.Clear();
1220 vCardOutputData.Clear();
1221 ETagFileData.Clear();
1223 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1225 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1227 if (additer->second.DataType == 0){
1229 vCard ConvertedV4Data;
1231 // Grab the file from the server and write the contact out.
1233 vCard34Conv vCard34Obj;
1235 CardDAVIter->second.SetServerFilename(additer->first);
1236 CardDAVIter->second.GetServerContactData();
1237 vCardInputData = CardDAVIter->second.GetPageData();
1239 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1241 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1243 // Update the ETagDB.
1245 //vCardFile.Open(vCardFilenameFinal, wxT("w"));
1247 //if (vCardFile.IsOpened()){
1249 // vCardFile.Write(vCardOutputData, wxConvAuto());
1250 // vCardFile.Close();
1254 // Get the server ETag.
1256 wxString ServerETag;
1257 CardDAVIter->second.GetServerETagValueThread();
1258 ServerETag = CardDAVIter->second.ETagValueResult();
1260 // Add to the ETag Database.
1262 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1264 } else if (additer->second.DataType == 1){
1266 // Write out the contact to the account directory.
1268 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1269 vCardOutputData = additer->second.FileData;
1271 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1273 if (vCardFile.IsOpened()){
1275 vCardFile.Write(vCardOutputData, wxConvAuto());
1280 // Update the ETagDB.
1282 wxString ServerETag;
1283 CardDAVIter->second.GetServerETagValueThread();
1284 ServerETag = CardDAVIter->second.ETagValueResult();
1286 // Add to the ETag Database.
1288 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1293 // Look for vCard files which aren't in the ETagDB.
1295 while(ContinueProcess){
1297 // Check and make sure that the filename ends in .vcf/.vcard
1298 // Skip any file that beings with a dot.
1300 if (AccDirFilename.Left(1) == wxT(".")){
1302 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1307 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1308 AccDirFilename.Right(6) != wxT(".vcard")){
1310 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1315 // Look in the ETagDB for the file.
1317 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1319 if (ETagExists == FALSE){
1321 // Add the vCard to the list to be added.
1323 vCardAdd.Add(AccDirFilename, 1);
1327 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1331 // Process the vCards to add/update to the server.
1333 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1335 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1336 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1337 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1339 ContactFilename = vCardAdd[vi];
1340 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1342 ContactFilename.Trim();
1344 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1346 // Compare the ETag with the Server ETag.
1348 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1349 CardDAVIter->second.GetServerETagValueThread();
1350 ETagServer = CardDAVIter->second.ETagValueResult();
1352 if (ETagOriginal != ETagServer){
1354 // Server ETag is different from original ETag.
1355 // This is a conflict which the user will now
1358 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1360 vCard34Conv vCard34Obj;
1362 wxString ServerContactData;
1364 vCard ConvertedV4Data;
1366 // Load the client data from the filename given.
1368 CardDAVIter->second.GetServerContactData();
1369 ServerContactData = CardDAVIter->second.GetPageData();
1371 // Process v3 version into v4 version.
1373 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1375 vCardConflictObj vCardProcData;
1377 vCardProcData.vCardLocalData = &ClientData;
1378 vCardProcData.vCardServerData = &ConvertedV4Data;
1379 ClientData.LoadFile(FullFilename);
1381 //ContactConflictEvent event(ContactConflictCmdEnv);
1382 //event.SetData(ContactFilename, Moo1, Moo2);
1384 //wxPostEvent(frmMainPtrGet, event);
1386 // Setup Conflict Resolution Dialog.
1388 // Fetch Data from Server and convert.
1390 bool *PauseMode = new bool;
1395 qrn.QResponse = &ConflictResult;
1396 qrn.PausePtr = PauseMode;
1398 vCardProcData.QRNotifData = &qrn;
1400 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1401 event.SetClientData(&vCardProcData);
1402 wxPostEvent(frmMainPtrGet, event);
1407 n1.tv_nsec = 250000000L;*/
1409 while (*PauseMode == TRUE){
1410 //nanosleep(&n1, &n2);
1411 SleepFor(250000000);
1417 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1419 if (ConflictResult == 0){
1426 } else if (ConflictResult == 1){
1428 // Decided to use client version.
1430 CardDAVIter->second.ProcessData();
1434 } else if (ConflictResult == 2){
1436 // Decided to use server version.
1438 // Download server version.
1440 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1448 // Setup the filename for the contact being added.
1450 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1451 wxString wxSCardData;
1455 // Load the data from the file.
1458 wxFCard.Open(wxSFilename, wxT("r"));
1460 if (wxFCard.IsOpened()){
1462 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1467 // Convert the data to v3.
1469 vCard34Conv vCard34Obj;
1471 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1473 // Setup the URL address.
1475 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1477 // Upload the data to the server.
1479 CardDAVIter->second.SetUploadMode(TRUE);
1480 CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1481 CardDAVIter->second.ProcessData();
1483 // Get the Server ETag and put it in the ETag database.
1485 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1486 CardDAVIter->second.GetServerETagValueThread();
1487 ETagServer = CardDAVIter->second.ETagValueResult();
1489 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1495 if (ETagOriginal != ETagServer){
1497 // Server ETag is different from original ETag.
1498 // This is a conflict which the user will now
1501 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1503 //ContactConflictEvent event(ContactConflictCmdEnv);
1504 //event.SetData(ContactFilename, Moo1, Moo2);
1506 vCard34Conv vCard34Obj;
1508 wxString ServerContactData;
1510 vCard ConvertedV4Data;
1512 // Load the client data from the filename given.
1514 CardDAVIter->second.GetServerContactData();
1515 ServerContactData = CardDAVIter->second.GetPageData();
1516 ClientData.LoadFile(FullFilename);
1518 // Process v3 version into v4 version.
1520 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1522 vCardConflictObj vCardProcData;
1524 vCardProcData.vCardLocalData = &ClientData;
1525 vCardProcData.vCardServerData = &ConvertedV4Data;
1527 bool *PauseMode = new bool;
1532 qrn.QResponse = &ConflictResult;
1533 qrn.PausePtr = PauseMode;
1535 vCardProcData.QRNotifData = &qrn;
1537 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1538 event.SetClientData(&vCardProcData);
1539 wxPostEvent(frmMainPtrGet, event);
1544 n1.tv_nsec = 250000000L;*/
1546 while (*PauseMode == TRUE){
1547 //nanosleep(&n1, &n2);
1548 SleepFor(250000000);
1554 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1556 if (ConflictResult == 0){
1563 } else if (ConflictResult == 1){
1565 // Decided to use client version.
1567 CardDAVIter->second.ProcessData();
1568 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
1569 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1573 } else if (ConflictResult == 2){
1575 // Decided to use server version.
1577 // Write server version to file.
1579 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1587 // Setup the filename for the contact being added.
1589 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1590 wxString wxSCardData;
1594 // Load the data from the file.
1597 wxFCard.Open(wxSFilename, wxT("r"));
1599 if (wxFCard.IsOpened()){
1601 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1606 // Convert the data to v3.
1608 vCard34Conv vCard34Obj;
1610 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1612 // Setup the URL address.
1614 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1616 // Upload the data to the server.
1618 CardDAVIter->second.SetUploadMode(TRUE);
1619 CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1620 CardDAVIter->second.ProcessData();
1622 // Get the Server ETag and put it in the ETag database.
1624 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1625 CardDAVIter->second.GetServerETagValueThread();
1626 ETagServer = CardDAVIter->second.ETagValueResult();
1629 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1637 // Process the vCards to delete locally.
1639 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1641 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1645 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1651 // Process the vCards to delete from the server.
1653 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1656 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1657 deliter != ETagFilenameMap->end(); deliter++){
1659 // Look through the ETagDB and find contacts which are marked as DELETED.
1661 if (deliter->second == wxT("DELETED")){
1663 CardDAVIter->second.SetUploadMode(FALSE);
1664 CardDAVIter->second.SetupData(wxT("DELETE"), deliter->first, wxT(""));
1665 CardDAVIter->second.ProcessData();
1667 // Delete the ETag as the file has now been deleted.
1669 ETagDBPtr->RemoveETag(deliter->first);
1675 // Write out the update server sync token.
1677 wxString ServerSyncToken = ServerContactList.SyncToken;
1679 ServerSyncToken.Trim();
1681 if (!ServerSyncToken.IsEmpty()){
1684 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1686 if (SyncWrite.IsOpened()){
1688 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1695 // Check for another sync token. If there is another
1696 // sync token then repeat this. If token matches then stop processing.
1698 if (SyncTokenLoad == ServerSyncToken){
1700 KeepUpdating = FALSE;
1706 // Mark as completed.
1713 // Update the data to the server.
1715 CardDAVIter->second.ProcessData();
1722 n1.tv_nsec = 250000000L;*/
1724 while (iter->second == 1){
1726 SleepFor(250000000);
1727 //nanosleep(&n1, &n2);
1731 if ((iter->second == 4 && TypeIter->second == 0) ||
1732 (iter->second == 8 && TypeIter->second == 0)){
1734 AccountDir = StringAccountIter->second;
1735 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1737 CardDAVIter->second.GetServerETagValueThread();
1738 ETagServer = CardDAVIter->second.ETagValueResult();
1739 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1743 if ((iter->second == 4 && TypeIter->second == 1) ||
1744 (iter->second == 8 && TypeIter->second == 1)){
1746 AccountDir = StringAccountIter->second;
1747 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1749 CardDAVIter->second.GetServerETagValueThread();
1750 ETagServer = CardDAVIter->second.ETagValueResult();
1751 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1761 if (TasksFoundProc == FALSE){
1763 TasksActive = FALSE;
1764 ProcessTasksData = FALSE;
1768 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1769 wxPostEvent(this, eventp);
1771 //AnimationTimer.StartAnimation();
1772 //ActListProcTimer.Start();
1776 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1777 wxPostEvent(this, event);
1779 //ActProcessTimer.Start();
1783 void frmActivityMgr::ProcessTasks()
1786 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1787 ProcessThread.detach();
1791 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1794 ETagTmrPtr = ETagTmrPtrInc;
1796 frmMainPtr = frmMainPtrInc;
1800 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1802 QRNotif *qrn = (QRNotif *)event.GetClientData();
1804 int *QRes = qrn->QResponse;
1806 *qrn->PausePtr = FALSE;
1808 *QRes = event.GetInt();
1812 int frmActivityMgr::GetTaskStatus(int intTaskID){
1816 if (ActivityList.find(intTaskID) == ActivityList.end()){
1822 std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
1823 intResult = taskiter->second;
1829 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
1831 wxCommandEvent connevent(CONNSTAT_UPDATE);
1833 if (SleepMode == FALSE){
1835 connevent.SetInt(1);
1840 connevent.SetInt(0);
1845 wxPostEvent(GetParent(), connevent);
1849 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
1851 wxString ServerCertFinal;
1853 // Get the Cert section of the certificate and write it to the file.
1855 ServerCertFinal = GetAccountDir(AccountName, TRUE);
1859 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
1860 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
1862 CertFile.Open(ServerCertFinal, wxFile::write);
1864 CertFile.Write(SSLDataIter->second, wxConvUTF8);
1869 void frmActivityMgr::StartTimer(wxCommandEvent& event){
1871 ActListProcTimer.Start(1000, FALSE);
1875 void frmActivityMgr::StopTimer(wxCommandEvent& event){
1877 ActListProcTimer.Stop();
1881 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
1883 ActProcessTimer.Start(1000, FALSE);
1887 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
1889 ActProcessTimer.Stop();
1893 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
1895 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
1897 if (actmgrudata != NULL){
1899 wxPuts(wxT("ItemIndex:") + actmgrudata->ItemIndex);
1900 wxPuts(wxT("ItemLabel:") + actmgrudata->ItemLabel);
1901 wxPuts(wxT("ItemDes: ") + actmgrudata->ItemDes);
1903 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
1905 /*if (!actmgrudata->ItemDes.IsEmpty()){
1906 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);