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 DEFINE_EVENT_TYPE(ACTMGR_RESUMEPROC);
42 DEFINE_EVENT_TYPE(ACTMGR_TOGGLECONN);
43 DEFINE_EVENT_TYPE(ACTMGR_STARTTIMER);
44 DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
45 DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
46 DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
47 DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
48 DEFINE_EVENT_TYPE(ACTMGR_STARTANIMATIONTIMER);
50 BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
51 EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
52 EVT_COMMAND(wxID_ANY, ACTMGR_TOGGLECONN, frmActivityMgr::ToggleConnectionStatus)
53 EVT_COMMAND(wxID_ANY, ACTMGR_STARTTIMER, frmActivityMgr::StartTimer)
54 EVT_COMMAND(wxID_ANY, ACTMGR_STOPTIMER, frmActivityMgr::StopTimer)
55 EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
56 EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
57 EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
58 EVT_COMMAND(wxID_ANY, ACTMGR_STARTANIMATIONTIMER, frmActivityMgr::StartAnimationTimer)
61 frmActivityMgr::frmActivityMgr( wxWindow* parent )
63 frmActivityMgrADT( parent )
66 wxMemoryInputStream istream(icons_activitywindow_png, sizeof(icons_activitywindow_png));
67 wxImage icons_activitywindow_pngi(istream, wxBITMAP_TYPE_PNG);
68 wxBitmap activityiconbmp(icons_activitywindow_pngi, -1);
70 activityicon.CopyFromBitmap(activityiconbmp);
71 this->SetIcon(activityicon);
73 wxMemoryInputStream istream2(misc_activitysleep_png, sizeof(misc_activitysleep_png));
74 wxImage misc_activitysleep_pngi(istream2, wxBITMAP_TYPE_PNG);
75 wxBitmap sleepiconbmp(misc_activitysleep_pngi, -1);
76 SleepBitmap = sleepiconbmp;
77 bmpActivity->SetBitmap(SleepBitmap);
78 ActProcessTimer.SetupPointers(this);
79 lblDetails->SetLabel(_("No activity."));
81 ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail,
82 &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
83 &ActProcessTimer, &ActivityListFinDate, &ActivityListConnObject);
85 AnimationTimer.SetBitmap(bmpActivity);
86 AnimationTimer.SetSleepBitmap(&SleepBitmap);
87 AnimationTimer.SetupPointer(this->GetParent());
89 wxListItem ColumnData;
91 ColumnData.SetText(_("Activity"));
92 ColumnData.SetWidth(175);
93 lstActivity->InsertColumn(0, ColumnData);
95 wxListItem ColumnData2;
97 ColumnData2.SetText(_("Account"));
98 ColumnData2.SetWidth(100);
99 lstActivity->InsertColumn(1, ColumnData2);
101 wxListItem ColumnData3;
102 ColumnData3.SetId(2);
103 ColumnData3.SetText(_("Status"));
104 ColumnData3.SetWidth(100);
105 lstActivity->InsertColumn(2, ColumnData3);
107 //AnimationTimer.StartAnimation();
109 // Create recovery database if it doesn't exist.
111 wxString RecoveryFilename = GetRecoveryDB();
115 if (wxFile::Exists(RecoveryFilename) == FALSE){
117 // Create the recovery database.
119 RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);
121 RecoveryDB.Write(wxT("BEGIN:XAB-RECOVERYDB\r\n"), wxConvUTF8);
122 RecoveryDB.Write(wxT("VERSION:1.0\r\n"), wxConvUTF8);
123 RecoveryDB.Write(wxT("COMMENT:Please do not alter or delete this file. DATA LOSS IS POSSIBLE!\r\n"), wxConvUTF8);
124 RecoveryDB.Write(wxT("END:XAB-RECOVERYDB\r\n"), wxConvUTF8);
131 #if wxABI_VERSION < 20900
132 RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
134 RecoveryDBF.Open(RecoveryFilename, wxT("r"));
137 // Load the recovery database for tasks not done.
139 if (RecoveryDBF.IsOpened() == TRUE){
141 wxString wxSRecoveryDB;
142 wxString RecoveryLine;
144 // Check if we are using wxWidgets version 2.8 or less and
145 // execute the required command accordingly.
147 RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
151 std::map<int, wxString> RecoveryFileLines;
152 std::map<int, wxString>::iterator striter;
154 wxStringTokenizer wSTRecoveryDBLines(wxSRecoveryDB, wxT("\r\n"));
156 int RecoveryLineSeek = 0;
158 while (wSTRecoveryDBLines.HasMoreTokens() == TRUE){
160 RecoveryLine = wSTRecoveryDBLines.GetNextToken();
161 RecoveryFileLines.insert(std::make_pair(RecoveryLineSeek, RecoveryLine));
170 //TestTimer.Start(50, FALSE);
173 void frmActivityMgr::OpenWindow()
178 void frmActivityMgr::CloseWindow( wxCommandEvent& event )
184 void frmActivityMgr::CloseWindow( wxCloseEvent& event )
190 void frmActivityMgr::ProcessTasksThread()
193 if (ProcessTasksData == FALSE){
199 if (ApplicationSleepMode == TRUE){
205 std::map<int,int>::iterator TypeIter;
206 std::map<int,wxString>::iterator StringIter;
207 std::map<int,wxString>::iterator StringDataIter;
208 std::map<int,wxString>::iterator StringURLIter;
209 std::map<int,wxString>::iterator StringDetailIter;
210 std::map<int,wxString>::iterator StringAccountIter;
211 std::map<int,wxString>::iterator StringFilenameIter;
212 std::map<int,wxString>::iterator StringFullFilenameIter;
213 std::map<int,wxString>::iterator StringTaskDetailIter;
214 std::map<int,wxString>::iterator StringETagIter;
215 std::map<int,wxString>::iterator StringETagOrigIter;
216 std::map<int,ConnectionObject*>::iterator ConnObjectIter;
217 std::map<int,ActivityMgrAccountSettings>::iterator AccountSettingsIter;
218 std::map<int,long>::iterator LongIter;
219 bool TasksFoundProc = FALSE;
222 for (std::map<int,int>::iterator iter = ActivityList.begin();
223 iter != ActivityList.end(); ++iter){
225 // Check for any queued tasks and start one.
227 if (iter->second > 4){
231 wxCommandEvent StartAnimationEvent(ACTMGR_STARTANIMATIONTIMER);
233 wxPostEvent(this, StartAnimationEvent);
235 // Start the animation timer if it hasn't started.
237 ConnObjectIter = ActivityListConnObject.find(iter->first);
238 TypeIter = ActivityListType.find(iter->first);
239 StringETagIter = ActivityListETag.find(iter->first);
240 StringETagOrigIter = ActivityListETagOriginal.find(iter->first);
241 StringAccountIter = ActivityListAccount.find(iter->first);
242 StringFilenameIter = ActivityListFilename.find(iter->first);
243 StringFullFilenameIter = ActivityListFullFilename.find(iter->first);
244 AccountSettingsIter = ActivityListAccSettings.find(iter->first);
246 // Setup the CardDAV object.
253 // 5 = Failed (UI Updated).
254 // 6 = Stopped (UI Updated).
255 // 7 = (Reserved) (UI Updated).
256 // 8 = Completed. (UI Updated).
258 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
259 XABPreferences PrefData(GetUserPrefDir());
261 if (iter->second == 0){
263 // Wait for process to finish.
266 TasksFoundProc = TRUE;
268 wxString ETagOriginal;
271 wxString ContactFilename;
272 wxString FullFilename;
274 bool EditMode = FALSE;
278 // Compare the ETags and work out if a conflict has occured.
280 if (TypeIter->second == 0){
284 StringDataIter = ActivityListData.find(iter->first);
285 StringURLIter = ActivityListURL.find(iter->first);
287 AccountDir = StringAccountIter->second;
288 ContactFilename = StringFilenameIter->second;
289 wxString AccountNameFriendly;
293 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
295 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
297 AccountDirCheck.Trim();
298 AccountDirCheck.Append(wxT(".carddav"));
300 if (AccountDirCheck == StringAccountIter->second){
302 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
309 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
311 ETag = StringETagIter->second;
312 ETagOriginal = StringETagOrigIter->second;
313 AccountDir = StringAccountIter->second;
314 ContactFilename = StringFilenameIter->second;
315 FullFilename = StringFullFilenameIter->second;
316 EditMode = ActivityListEditMode.find(iter->first)->second;
318 bool KeepUpdating = true;
320 while(KeepUpdating == true){
322 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
324 bool ExitLoop = false;
326 while (ExitLoop == false){
328 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
330 frmMainPtrGet->PauseAllTimers();
332 #if defined(__APPLE__)
333 #elif defined(__WIN32__)
336 bool UsingSSLBypass = false;
339 // Connect again and fetch SSL certificate information.
341 ConnObjectIter->second->BypassSSLVerification(true);
343 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
345 ConnObjectIter->second->BypassSSLVerification(false);
347 SSLInvalidCertNotifObjString SSLICNProcData;
349 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
351 bool *PauseMode = new bool;
355 qrn.QResponse = &SSLResult;
356 qrn.PausePtr = PauseMode;
358 SSLICNProcData.CertCollection = certcol;
359 SSLICNProcData.QRNotifData = &qrn;
360 SSLICNProcData.AccountName = AccountNameFriendly;
362 wxCommandEvent event(INVALIDSSLCERTSTRING);
363 event.SetClientData(&SSLICNProcData);
364 wxPostEvent(frmMainPtrGet, event);
366 while (*PauseMode == TRUE){
367 //nanosleep(&n1, &n2);
371 // Process the response from the user.
375 // Accept the Certificate.
377 UsingSSLBypass = true;
378 ConnObjectIter->second->BypassSSLVerification(true);
380 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
381 WriteServerCertificate(AccountDir, certcol);
383 ConnObjectIter->second->BypassSSLVerification(false);
385 } else if (SSLResult == 2){
387 // Reject the certificate, abort the task and mark as failed.
396 frmMainPtrGet->ResumeAllTimers();
399 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
401 ConnectResponse = ConnObjectIter->second->Connect(true);
403 if (ConnectResponse == COCONNECT_OK){
416 } else if (ConnectResponse == COCONNECT_OK){
418 ConnectResponse = ConnObjectIter->second->Connect(true);
433 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
437 #if defined(__APPLE__)
439 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
441 #elif defined(__WIN32__)
443 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
447 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
451 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(StringURLIter->second.ToStdString(),
452 StringDataIter->second.ToStdString());
454 if (AddContactResponse.RequestResult != COREQUEST_OK){
459 // Get the entity tag for the new contact.
461 COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
463 if (ETagGetResponse.RequestResult != COREQUEST_OK){
468 std::cout << ETagGetResponse.EntityTag << std::endl;
470 ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
477 } else if (TypeIter->second == 1){
481 StringDataIter = ActivityListData.find(iter->first);
482 StringURLIter = ActivityListURL.find(iter->first);
484 AccountDir = StringAccountIter->second;
485 ContactFilename = StringFilenameIter->second;
486 wxString AccountNameFriendly;
490 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
492 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
494 AccountDirCheck.Trim();
495 AccountDirCheck.Append(wxT(".carddav"));
497 if (AccountDirCheck == StringAccountIter->second){
499 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
506 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
508 ETag = StringETagIter->second;
509 ETagOriginal = StringETagOrigIter->second;
510 AccountDir = StringAccountIter->second;
511 ContactFilename = StringFilenameIter->second;
512 FullFilename = StringFullFilenameIter->second;
513 EditMode = ActivityListEditMode.find(iter->first)->second;
515 bool KeepUpdating = true;
517 while(KeepUpdating == true){
519 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
521 bool ExitLoop = false;
523 while(ExitLoop == false){
525 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
527 frmMainPtrGet->PauseAllTimers();
529 #if defined(__APPLE__)
530 #elif defined(__WIN32__)
533 bool UsingSSLBypass = false;
536 // Connect again and fetch SSL certificate information.
538 ConnObjectIter->second->BypassSSLVerification(true);
540 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
542 ConnObjectIter->second->BypassSSLVerification(false);
544 SSLInvalidCertNotifObjString SSLICNProcData;
546 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
548 bool *PauseMode = new bool;
552 qrn.QResponse = &SSLResult;
553 qrn.PausePtr = PauseMode;
555 SSLICNProcData.CertCollection = certcol;
556 SSLICNProcData.QRNotifData = &qrn;
557 SSLICNProcData.AccountName = AccountNameFriendly;
559 wxCommandEvent event(INVALIDSSLCERTSTRING);
560 event.SetClientData(&SSLICNProcData);
561 wxPostEvent(frmMainPtrGet, event);
563 while (*PauseMode == TRUE){
567 // Process the response from the user.
571 // Accept the Certificate.
573 UsingSSLBypass = true;
574 ConnObjectIter->second->BypassSSLVerification(true);
576 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
577 WriteServerCertificate(AccountDir, certcol);
579 ConnObjectIter->second->BypassSSLVerification(false);
581 } else if (SSLResult == 2){
583 // Reject the certificate, abort the task and mark as failed.
592 frmMainPtrGet->ResumeAllTimers();
595 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
597 ConnectResponse = ConnObjectIter->second->Connect(true);
599 if (ConnectResponse == COCONNECT_OK){
612 } else if (ConnectResponse == COCONNECT_OK){
614 ConnectResponse = ConnObjectIter->second->Connect(true);
629 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
633 COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
635 if (ETagGetResponse.RequestResult != COREQUEST_OK){
640 ETagServer = ETagGetResponse.EntityTag;
642 // Compare the ETag with the Server ETag.
644 if (ETagOriginal != ETagServer){
646 // Server ETag is different from original ETag.
647 // This is a conflict which the user will now
650 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
652 vCard34Conv vCard34Obj;
654 std::string ServerContactData;
655 wxString wxStringServerContactData;
657 vCard ConvertedV4Data;
659 // Load the client data from the filename given.
661 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(),
664 if (GetContactResponse.RequestResult != COREQUEST_OK){
669 wxStringServerContactData = wxString::FromUTF8((const char*)ServerContactData.c_str());
671 // Process v3 version into v4 version.
673 vCard34Obj.ConvertToV4(&wxStringServerContactData, &ConvertedV4Data);
675 vCardConflictObj vCardProcData;
677 vCardProcData.vCardLocalData = &ClientData;
678 vCardProcData.vCardServerData = &ConvertedV4Data;
679 ClientData.LoadFile(FullFilename);
681 // Setup Conflict Resolution Dialog.
683 // Fetch Data from Server and convert.
685 bool *PauseMode = new bool;
690 qrn.QResponse = &ConflictResult;
691 qrn.PausePtr = PauseMode;
693 vCardProcData.QRNotifData = &qrn;
695 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
696 event.SetClientData(&vCardProcData);
697 wxPostEvent(frmMainPtrGet, event);
699 while (*PauseMode == TRUE){
706 if (ConflictResult == 0){
713 } else if (ConflictResult == 1){
715 // Decided to use client version.
717 } else if (ConflictResult == 2){
719 // Decided to use server version.
721 // Download server version.
723 ConvertedV4Data.WriteFile(FullFilename);
729 // Upload the data to the server.
731 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(StringURLIter->second.ToStdString(),
732 StringDataIter->second.ToStdString());
734 if (EditContactResponse.RequestResult != COREQUEST_OK){
741 ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
743 if (ETagGetResponse.RequestResult != COREQUEST_OK){
748 ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
755 } else if (TypeIter->second == 2) {
757 // Delete the contact from the server and update the ETag DB.
759 AccountDir = StringAccountIter->second;
760 ContactFilename = StringFilenameIter->second;
761 wxString AccountNameFriendly;
765 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
767 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
769 AccountDirCheck.Trim();
770 AccountDirCheck.Append(wxT(".carddav"));
772 if (AccountDirCheck == StringAccountIter->second){
774 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
781 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
783 bool KeepUpdating = TRUE;
785 while(KeepUpdating == TRUE){
787 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
789 bool ExitLoop = FALSE;
791 while (ExitLoop == FALSE){
793 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
795 frmMainPtrGet->PauseAllTimers();
797 #if defined(__APPLE__)
798 #elif defined(__WIN32__)
801 bool UsingSSLBypass = false;
804 // Connect again and fetch SSL certificate information.
806 ConnObjectIter->second->BypassSSLVerification(true);
808 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
810 ConnObjectIter->second->BypassSSLVerification(false);
812 SSLInvalidCertNotifObjString SSLICNProcData;
814 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
816 bool *PauseMode = new bool;
820 qrn.QResponse = &SSLResult;
821 qrn.PausePtr = PauseMode;
823 SSLICNProcData.CertCollection = certcol;
824 SSLICNProcData.QRNotifData = &qrn;
825 SSLICNProcData.AccountName = AccountNameFriendly;
827 wxCommandEvent event(INVALIDSSLCERTSTRING);
828 event.SetClientData(&SSLICNProcData);
829 wxPostEvent(frmMainPtrGet, event);
831 while (*PauseMode == TRUE){
832 //nanosleep(&n1, &n2);
836 // Process the response from the user.
840 // Accept the Certificate.
842 UsingSSLBypass = true;
843 ConnObjectIter->second->BypassSSLVerification(true);
845 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
846 WriteServerCertificate(AccountDir, certcol);
848 ConnObjectIter->second->BypassSSLVerification(false);
850 } else if (SSLResult == 2){
852 // Reject the certificate, abort the task and mark as failed.
861 frmMainPtrGet->ResumeAllTimers();
864 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
866 ConnectResponse = ConnObjectIter->second->Connect(true);
868 if (ConnectResponse == COCONNECT_OK){
881 } else if (ConnectResponse == COCONNECT_OK){
883 ConnectResponse = ConnObjectIter->second->Connect(true);
898 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
902 #if defined(__APPLE__)
904 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
906 #elif defined(__WIN32__)
908 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
912 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
916 COServerResponse DeleteContactResponse = ConnObjectIter->second->DeleteContact(ContactFilename.ToStdString());
918 if (DeleteContactResponse.RequestResult != COREQUEST_OK){
923 ETagDBPtr->RemoveETag(ContactFilename);
930 } else if (TypeIter->second == 3) {
932 wxString AccountNameFriendly;
936 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
938 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
940 AccountDirCheck.Trim();
941 AccountDirCheck.Append(wxT(".carddav"));
943 if (AccountDirCheck == StringAccountIter->second){
945 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
952 bool KeepUpdating = TRUE;
954 while (KeepUpdating == TRUE){
956 StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
958 AccountDir = StringAccountIter->second;
960 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
962 wxArrayString vCardAdd;
963 wxArrayString vCardDelete;
964 wxArrayString vCardList;
965 wxArrayString vCardUpdateLocal;
966 wxArrayString vCardUpdateRemote;
967 wxArrayString vCardUpdateLog;
968 std::map<wxString,wxString> vCardETag;
970 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
972 // Get the list of vCard files locally.
974 wxString AccountDirFinal;
975 wxString AccountSyncTokenFilename;
976 wxString SyncTokenLoad;
978 #if defined(__HAIKU__)
980 //preffilename = wxT("noo");
982 #elif defined(__WIN32__)
984 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
985 AccountSyncTokenFilename = AccountDirFinal;
986 AccountSyncTokenFilename.Append(wxT("synctoken"));
990 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
991 AccountSyncTokenFilename = AccountDirFinal;
992 AccountSyncTokenFilename.Append(wxT("synctoken"));
996 // Suppress Error Messages.
998 wxLogNull PleaseDoNotDisturb;
1001 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
1003 if (SyncLoad.IsOpened()){
1005 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1010 // Get a list of vCard files from the server.
1012 // Get the list of vCard files from the ETagDB.
1014 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1016 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
1018 bool ExitLoop = FALSE;
1020 while (ExitLoop == FALSE){
1022 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
1024 frmMainPtrGet->PauseAllTimers();
1026 #if defined(__APPLE__)
1027 #elif defined(__WIN32__)
1030 bool UsingSSLBypass = false;
1033 // Connect again and fetch SSL certificate information.
1035 ConnObjectIter->second->BypassSSLVerification(true);
1037 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
1039 ConnObjectIter->second->BypassSSLVerification(false);
1041 SSLInvalidCertNotifObjString SSLICNProcData;
1043 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
1045 bool *PauseMode = new bool;
1049 qrn.QResponse = &SSLResult;
1050 qrn.PausePtr = PauseMode;
1052 SSLICNProcData.CertCollection = certcol;
1053 SSLICNProcData.QRNotifData = &qrn;
1054 SSLICNProcData.AccountName = AccountNameFriendly;
1056 wxCommandEvent event(INVALIDSSLCERTSTRING);
1057 event.SetClientData(&SSLICNProcData);
1058 wxPostEvent(frmMainPtrGet, event);
1060 while (*PauseMode == TRUE){
1061 //nanosleep(&n1, &n2);
1062 SleepFor(250000000);
1065 // Process the response from the user.
1067 if (SSLResult == 1){
1069 // Accept the Certificate.
1071 UsingSSLBypass = true;
1072 ConnObjectIter->second->BypassSSLVerification(true);
1074 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
1075 WriteServerCertificate(AccountDir, certcol);
1077 ConnObjectIter->second->BypassSSLVerification(false);
1079 } else if (SSLResult == 2){
1081 // Reject the certificate, abort the task and mark as failed.
1090 frmMainPtrGet->ResumeAllTimers();
1093 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
1095 ConnectResponse = ConnObjectIter->second->Connect(true);
1097 if (ConnectResponse == COCONNECT_OK){
1110 } else if (ConnectResponse == COCONNECT_OK){
1112 ConnectResponse = ConnObjectIter->second->Connect(true);
1127 #if defined(__APPLE__)
1129 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1131 #elif defined(__WIN32__)
1133 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1137 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1141 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1145 // Look in directory and see which vCards to add and delete
1148 // vCard exists but not in ETagDB - Add (and upload).
1149 // vCard missing but in ETagDB - Delete (from server).
1151 // Start by looking for vCards that are not in the ETagDB.
1153 wxDir AccDir(AccountDirFinal);
1154 wxString AccDirFilename;
1156 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1158 COContactList ServerContactList2 = ConnObjectIter->second->GetContactList(SyncTokenLoad.ToStdString());
1160 // Process the server data.
1162 for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1163 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1165 if (ContactInfo->Status == COCS_UPDATED){
1167 vCardDownloadDataFileClass vCardNewData;
1168 vCardNewData.DataType = 0;
1169 vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
1171 } else if (ContactInfo->Status == COCS_DELETED){
1173 vCardDelete.Add(ContactInfo->Location, 1);
1179 // Look for vCards that are missing but in the ETagDB.
1181 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1182 etagiter != ETagDBData.end(); etagiter++){
1184 // Check if the vCard exists.
1186 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1188 // vCard doesn't exist so mark for deleting.
1190 vCardDelete.Add(etagiter->first, 1);
1196 // Compare Server with the ETag DB. Work out which
1197 // needs to updated remotely and which needs to be
1200 for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1201 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1203 if (ETagDBData.find(ContactInfo->Location) == ETagDBData.end()){
1207 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(ContactInfo->Location);
1209 ETagData etd = lociter->second;
1211 wxString ETagSrv = ContactInfo->Data;
1213 // Check if the local ETag value has 'DELETED' set and skip
1214 // checking this file if it does.
1216 if (etd.ETagValue == "DELETED"){
1222 // Compare local ETag with original local ETag.
1223 // If different, update to server is required.
1225 if (etd.ETagValue != etd.ETagOrigValue){
1227 // Check if local original ETag is different from server ETag.
1228 // If it is then throw up a conflict resolution dialog.
1230 if (etd.ETagOrigValue != ETagSrv){
1232 vCard34Conv vCard34Obj;
1234 wxString FullFilename;
1236 vCard ConvertedV4Data;
1238 std::string ServerContactDataString;
1239 wxString ServerContactData;
1241 // Conflict. Bring up conflict resolution dialog.
1243 // Get the server contact data for comparison.
1245 ConnObjectIter->second->GetContact(ContactInfo->Location, &ServerContactDataString);
1246 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1248 FullFilename = CreateFilenamePath(AccountDirFinal, ContactInfo->Location);
1250 // Convert it to v4.
1252 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1254 vCardConflictObj vCardProcData;
1256 vCardProcData.vCardLocalData = &ClientData;
1257 vCardProcData.vCardServerData = &ConvertedV4Data;
1259 // Load the client data from the filename given.
1261 ClientData.LoadFile(FullFilename);
1265 bool *PauseMode = new bool;
1268 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1271 qrn.QResponse = &ConflictResult;
1272 qrn.PausePtr = PauseMode;
1274 vCardProcData.QRNotifData = &qrn;
1276 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1277 event.SetClientData(&vCardProcData);
1278 wxPostEvent(frmMainPtrGet, event);
1280 while (*PauseMode == TRUE){
1281 //nanosleep(&n1, &n2);
1282 SleepFor(250000000);
1288 // If replacing local version, store copy for now.
1289 // Otherwise upload to server.
1291 if (ConflictResult == 0){
1297 } else if (ConflictResult == 1){
1299 // Decided to use client version.
1301 vCardUpdateLocal.Remove(ContactInfo->Location);
1302 vCardUpdateRemote.Add(ContactInfo->Location, 1);
1304 } else if (ConflictResult == 2){
1306 // Decided to use server version.
1307 // Store the converted downloaded copy for
1308 // processing later.
1310 //vCardUpdateLocal.Add(srviter->first, 1);
1312 vCardDownloadDataFileClass vCardNewData;
1313 vCardNewData.DataType = 1;
1314 vCardNewData.FileData = ConvertedV4Data.WriteString();
1316 ConvertedV4Data.WriteFile(FullFilename);
1318 vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
1326 // Send vCard to the server.
1328 vCardUpdateRemote.Add(ContactInfo->Location, 1);
1334 // Check if local ETag is different from server ETag.
1335 // If different, obtain the vCard from the server.
1337 if (etd.ETagOrigValue != ETagSrv){
1339 vCardUpdateLocal.Add(ContactInfo->Location, 1);
1347 // Process the vCards that need to be downloaded and added/overwritten.
1349 wxString vCardFilenameFinal;
1350 wxString vCardOutputData;
1351 wxString vCardInputData;
1352 wxString ETagFileData;
1355 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1356 additer != vCardDownloadData.end(); additer++){
1358 vCardFilenameFinal.Clear();
1359 vCardInputData.Clear();
1360 vCardOutputData.Clear();
1361 ETagFileData.Clear();
1363 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1365 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1367 if (additer->second.DataType == 0){
1369 vCard ConvertedV4Data;
1371 // Grab the file from the server and write the contact out.
1373 vCard34Conv vCard34Obj;
1375 wxString ServerContactData;
1376 std::string ServerContactDataString;
1378 // Conflict. Bring up conflict resolution dialog.
1380 // Get the server contact data for comparison.
1382 ConnObjectIter->second->GetContact(additer->first.ToStdString(), &ServerContactDataString);
1383 vCardInputData = wxString::FromUTF8(ServerContactDataString.c_str());
1385 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1387 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1389 // Get the server ETag.
1391 wxString ServerETag;
1393 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1395 if (ServerEntityTag.RequestResult != COREQUEST_OK){
1400 ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1402 // Add to the ETag Database.
1404 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1406 } else if (additer->second.DataType == 1){
1408 // Write out the contact to the account directory.
1410 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1411 vCardOutputData = additer->second.FileData;
1413 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1415 if (vCardFile.IsOpened()){
1417 vCardFile.Write(vCardOutputData, wxConvAuto());
1422 // Update the ETagDB.
1424 wxString ServerETag;
1426 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1428 if (ServerEntityTag.RequestResult != COREQUEST_OK){
1433 ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1435 // Add to the ETag Database.
1437 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1442 // Check if any errors occured before continuing.
1444 if (iter->second != 1){
1448 // Look for vCard files which aren't in the ETagDB.
1450 while(ContinueProcess){
1452 // Check and make sure that the filename ends in .vcf/.vcard
1453 // Skip any file that beings with a dot.
1455 if (AccDirFilename.Left(1) == wxT(".")){
1457 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1462 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1463 AccDirFilename.Right(6) != wxT(".vcard")){
1465 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1470 // Look in the ETagDB for the file.
1472 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1474 if (ETagExists == FALSE){
1476 // Add the vCard to the list to be added.
1478 vCardAdd.Add(AccDirFilename, 1);
1482 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1486 // Process the vCards to add/update to the server.
1488 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1490 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1491 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1492 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1494 ContactFilename = vCardAdd[vi];
1495 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1497 ContactFilename.Trim();
1499 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1501 // Compare the ETag with the Server ETag.
1503 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1505 if (ServerEntityTag.RequestResult != COREQUEST_OK){
1510 // TODO: Continue from here!
1512 ETagServer = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1514 if (ETagOriginal != ETagServer){
1516 // Server ETag is different from original ETag.
1517 // This is a conflict which the user will now
1520 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1522 vCard34Conv vCard34Obj;
1524 wxString ServerContactData;
1525 std::string ServerContactDataString;
1527 vCard ConvertedV4Data;
1529 // Load the client data from the filename given.
1531 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1533 if (GetContactResponse.RequestResult != COREQUEST_OK){
1538 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1540 // Process v3 version into v4 version.
1542 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1544 vCardConflictObj vCardProcData;
1546 vCardProcData.vCardLocalData = &ClientData;
1547 vCardProcData.vCardServerData = &ConvertedV4Data;
1548 ClientData.LoadFile(FullFilename);
1550 // Setup Conflict Resolution Dialog.
1552 // Fetch Data from Server and convert.
1554 bool *PauseMode = new bool;
1559 qrn.QResponse = &ConflictResult;
1560 qrn.PausePtr = PauseMode;
1562 vCardProcData.QRNotifData = &qrn;
1564 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1565 event.SetClientData(&vCardProcData);
1566 wxPostEvent(frmMainPtrGet, event);
1568 while (*PauseMode == TRUE){
1569 //nanosleep(&n1, &n2);
1570 SleepFor(250000000);
1576 if (ConflictResult == 0){
1583 } else if (ConflictResult == 1){
1585 // Decided to use client version.
1587 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1589 if (EditContactResponse.RequestResult != COREQUEST_OK){
1596 } else if (ConflictResult == 2){
1598 // Decided to use server version.
1600 // Download server version.
1602 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1610 // Setup the filename for the contact being added.
1612 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1613 wxString wxSCardData;
1616 // Load the data from the file.
1619 wxFCard.Open(wxSFilename, wxT("r"));
1621 if (wxFCard.IsOpened()){
1623 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1628 // Convert the data to v3.
1630 vCard34Conv vCard34Obj;
1632 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1634 // Upload the data to the server.
1636 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1638 if (AddContactResponse.RequestResult != COREQUEST_OK){
1643 // Get the Server ETag and put it in the ETag database.
1645 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1647 if (EntityTagResponse.RequestResult != COREQUEST_OK){
1652 ETagServer = wxString::FromUTF8(EntityTagResponse.EntityTag.c_str());
1654 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1660 if (ETagOriginal != ETagServer){
1662 // Server ETag is different from original ETag.
1663 // This is a conflict which the user will now
1666 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1668 vCard34Conv vCard34Obj;
1670 std::string ServerContactDataString;
1671 wxString ServerContactData;
1673 vCard ConvertedV4Data;
1675 // Load the client data from the filename given.
1677 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1679 if (GetContactResponse.RequestResult != COREQUEST_OK){
1684 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1686 ClientData.LoadFile(FullFilename);
1688 // Process v3 version into v4 version.
1690 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1692 vCardConflictObj vCardProcData;
1694 vCardProcData.vCardLocalData = &ClientData;
1695 vCardProcData.vCardServerData = &ConvertedV4Data;
1697 bool *PauseMode = new bool;
1702 qrn.QResponse = &ConflictResult;
1703 qrn.PausePtr = PauseMode;
1705 vCardProcData.QRNotifData = &qrn;
1707 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1708 event.SetClientData(&vCardProcData);
1709 wxPostEvent(frmMainPtrGet, event);
1711 while (*PauseMode == TRUE){
1712 SleepFor(250000000);
1718 if (ConflictResult == 0){
1725 } else if (ConflictResult == 1){
1727 // Decided to use client version.
1729 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1731 if (EditContactResponse.RequestResult != COREQUEST_OK){
1738 } else if (ConflictResult == 2){
1740 // Decided to use server version.
1742 // Write server version to file.
1744 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1752 // Setup the filename for the contact being added.
1754 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1755 wxString wxSCardData;
1758 // Load the data from the file.
1761 wxFCard.Open(wxSFilename, wxT("r"));
1763 if (wxFCard.IsOpened()){
1765 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1770 // Convert the data to v3.
1772 vCard34Conv vCard34Obj;
1774 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1776 // Upload the data to the server.
1778 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1780 if (AddContactResponse.RequestResult != COREQUEST_OK){
1785 // Get the Server ETag and put it in the ETag database.
1787 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1789 if (EntityTagResponse.RequestResult != COREQUEST_OK){
1794 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1802 if (iter->second != 1){
1806 // Process the vCards to delete locally.
1808 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1810 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1814 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1820 // Process the vCards to delete from the server.
1822 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1823 std::list<wxString> DeleteList;
1825 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1826 deliter != ETagFilenameMap->end(); deliter++){
1828 // Look through the ETagDB and find contacts which are marked as DELETED.
1830 if (deliter->second == wxT("DELETED")){
1832 ConnObjectIter->second->DeleteContact(deliter->first.ToStdString());
1834 // Delete the ETag as the file has now been deleted.
1836 DeleteList.push_back(deliter->first);
1842 for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
1843 removeetagiter != DeleteList.end(); removeetagiter++){
1845 ETagDBPtr->RemoveETag(*removeetagiter);
1849 // Write out the update server sync token.
1851 wxString ServerSyncToken = wxString::FromUTF8(ServerContactList2.SyncToken.c_str());
1853 ServerSyncToken.Trim();
1855 if (!ServerSyncToken.IsEmpty()){
1858 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1860 if (SyncWrite.IsOpened()){
1862 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1869 // Check for another sync token. If there is another
1870 // sync token then repeat this. If token matches then stop processing.
1872 if (SyncTokenLoad == ServerSyncToken){
1874 KeepUpdating = FALSE;
1880 // Mark as completed.
1882 wxString AccountNameFinal;
1883 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1884 AccountNameFinal.Append(wxT(".carddav"));
1886 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1887 reloadevent.SetString(AccountNameFinal);
1888 wxPostEvent(this->GetParent(), reloadevent);
1895 // Update the data to the server.
1902 while (iter->second == 1){
1904 SleepFor(125000000);
1914 if (TasksFoundProc == FALSE){
1916 TasksActive = FALSE;
1917 ProcessTasksData = FALSE;
1921 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1922 wxPostEvent(this, eventp);
1926 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1927 wxPostEvent(this, event);
1931 void frmActivityMgr::ProcessTasks()
1934 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1935 ProcessThread.detach();
1939 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1942 ETagTmrPtr = ETagTmrPtrInc;
1944 frmMainPtr = frmMainPtrInc;
1948 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1950 QRNotif *qrn = (QRNotif *)event.GetClientData();
1952 int *QRes = qrn->QResponse;
1954 *qrn->PausePtr = FALSE;
1956 *QRes = event.GetInt();
1960 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
1962 wxCommandEvent connevent(CONNSTAT_UPDATE);
1964 if (ApplicationSleepMode == FALSE){
1966 connevent.SetInt(1);
1967 ApplicationSleepMode = TRUE;
1968 mnuSleepMode->Check(true);
1972 connevent.SetInt(0);
1973 ApplicationSleepMode = FALSE;
1974 mnuSleepMode->Check(false);
1976 wxCommandEvent event(ACTMGR_STARTTIMER);
1977 wxPostEvent(this, event);
1979 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
1980 wxPostEvent(this, eventp);
1984 wxPostEvent(GetParent(), connevent);
1988 void frmActivityMgr::SleepMode( wxCommandEvent &event ){
1990 wxCommandEvent connevent(ACTMGR_TOGGLECONN);
1992 wxPostEvent(this, connevent);
1996 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
1998 wxString ServerCertFinal;
2000 // Get the Cert section of the certificate and write it to the file.
2002 ServerCertFinal = GetAccountDir(AccountName, TRUE);
2006 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2007 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
2009 CertFile.Open(ServerCertFinal, wxFile::write);
2011 CertFile.Write(SSLDataIter->second, wxConvUTF8);
2016 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollectionString SSLCertInc){
2018 wxString ServerCertFinal;
2020 // Get the Cert section of the certificate and write it to the file.
2022 ServerCertFinal = GetAccountDir(AccountName, TRUE);
2026 std::map<int, SSLCertDataString>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2027 std::multimap<string,string>::iterator SSLDataIter = SSLCDIter->second.CertData.find("Cert");
2029 CertFile.Open(ServerCertFinal, wxFile::write);
2031 CertFile.Write(SSLDataIter->second, wxConvUTF8);
2036 void frmActivityMgr::StartTimer(wxCommandEvent& event){
2038 ActListProcTimer.Start(1000, FALSE);
2042 void frmActivityMgr::StopTimer(wxCommandEvent& event){
2044 ActListProcTimer.Stop();
2048 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
2050 ActProcessTimer.Start(1000, FALSE);
2054 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
2056 ActProcessTimer.Stop();
2060 void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
2062 AnimationTimer.StartAnimation();
2066 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2068 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2070 if (actmgrudata != NULL){
2072 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);