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, &ActivityListConn);
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, ConnHandle.GetCertificateContextPointer());
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, ConnHandle.GetCertificateContextPointer());
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;
969 ContactListData ServerContactList;
971 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
973 // Get the list of vCard files locally.
975 wxString AccountDirFinal;
976 wxString AccountSyncTokenFilename;
977 wxString SyncTokenLoad;
979 #if defined(__HAIKU__)
981 //preffilename = wxT("noo");
983 #elif defined(__WIN32__)
985 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
986 AccountSyncTokenFilename = AccountDirFinal;
987 AccountSyncTokenFilename.Append(wxT("synctoken"));
991 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
992 AccountSyncTokenFilename = AccountDirFinal;
993 AccountSyncTokenFilename.Append(wxT("synctoken"));
997 // Suppress Error Messages.
999 wxLogNull PleaseDoNotDisturb;
1002 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
1004 if (SyncLoad.IsOpened()){
1006 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1011 // Get a list of vCard files from the server.
1013 // Get the list of vCard files from the ETagDB.
1015 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1017 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
1019 bool ExitLoop = FALSE;
1021 std::map<wxString,FileSyncData> *SCListData = NULL;
1023 while (ExitLoop == FALSE){
1025 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
1027 frmMainPtrGet->PauseAllTimers();
1029 #if defined(__APPLE__)
1030 #elif defined(__WIN32__)
1033 bool UsingSSLBypass = false;
1036 // Connect again and fetch SSL certificate information.
1038 ConnObjectIter->second->BypassSSLVerification(true);
1040 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
1042 ConnObjectIter->second->BypassSSLVerification(false);
1044 SSLInvalidCertNotifObjString SSLICNProcData;
1046 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
1048 bool *PauseMode = new bool;
1052 qrn.QResponse = &SSLResult;
1053 qrn.PausePtr = PauseMode;
1055 SSLICNProcData.CertCollection = certcol;
1056 SSLICNProcData.QRNotifData = &qrn;
1057 SSLICNProcData.AccountName = AccountNameFriendly;
1059 wxCommandEvent event(INVALIDSSLCERTSTRING);
1060 event.SetClientData(&SSLICNProcData);
1061 wxPostEvent(frmMainPtrGet, event);
1063 while (*PauseMode == TRUE){
1064 //nanosleep(&n1, &n2);
1065 SleepFor(250000000);
1068 // Process the response from the user.
1070 if (SSLResult == 1){
1072 // Accept the Certificate.
1074 UsingSSLBypass = true;
1075 ConnObjectIter->second->BypassSSLVerification(true);
1077 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
1078 WriteServerCertificate(AccountDir, certcol);
1080 ConnObjectIter->second->BypassSSLVerification(false);
1082 } else if (SSLResult == 2){
1084 // Reject the certificate, abort the task and mark as failed.
1093 frmMainPtrGet->ResumeAllTimers();
1096 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
1098 ConnectResponse = ConnObjectIter->second->Connect(true);
1100 if (ConnectResponse == COCONNECT_OK){
1113 } else if (ConnectResponse == COCONNECT_OK){
1115 ConnectResponse = ConnObjectIter->second->Connect(true);
1130 #if defined(__APPLE__)
1132 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1134 #elif defined(__WIN32__)
1136 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1140 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1144 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1148 // Look in directory and see which vCards to add and delete
1151 // vCard exists but not in ETagDB - Add (and upload).
1152 // vCard missing but in ETagDB - Delete (from server).
1154 // Start by looking for vCards that are not in the ETagDB.
1156 wxDir AccDir(AccountDirFinal);
1157 wxString AccDirFilename;
1159 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1161 COContactList ServerContactList2 = ConnObjectIter->second->GetContactList(SyncTokenLoad.ToStdString());
1163 // Process the server data.
1165 for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1166 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1168 if (ContactInfo->Status == COCS_UPDATED){
1170 vCardDownloadDataFileClass vCardNewData;
1171 vCardNewData.DataType = 0;
1172 vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
1174 } else if (ContactInfo->Status == COCS_DELETED){
1176 vCardDelete.Add(ContactInfo->Location, 1);
1182 // Look for vCards that are missing but in the ETagDB.
1184 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1185 etagiter != ETagDBData.end(); etagiter++){
1187 // Check if the vCard exists.
1189 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1191 // vCard doesn't exist so mark for deleting.
1193 vCardDelete.Add(etagiter->first, 1);
1199 // Compare Server with the ETag DB. Work out which
1200 // needs to updated remotely and which needs to be
1203 for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1204 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1206 if (ETagDBData.find(ContactInfo->Location) == ETagDBData.end()){
1210 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(ContactInfo->Location);
1212 ETagData etd = lociter->second;
1214 wxString ETagSrv = ContactInfo->Data;
1216 // Check if the local ETag value has 'DELETED' set and skip
1217 // checking this file if it does.
1219 if (etd.ETagValue == "DELETED"){
1225 // Compare local ETag with original local ETag.
1226 // If different, update to server is required.
1228 if (etd.ETagValue != etd.ETagOrigValue){
1230 // Check if local original ETag is different from server ETag.
1231 // If it is then throw up a conflict resolution dialog.
1233 if (etd.ETagOrigValue != ETagSrv){
1235 vCard34Conv vCard34Obj;
1237 wxString FullFilename;
1239 vCard ConvertedV4Data;
1241 std::string ServerContactDataString;
1242 wxString ServerContactData;
1244 // Conflict. Bring up conflict resolution dialog.
1246 // Get the server contact data for comparison.
1248 ConnObjectIter->second->GetContact(ContactInfo->Location, &ServerContactDataString);
1249 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1251 FullFilename = CreateFilenamePath(AccountDirFinal, ContactInfo->Location);
1253 // Convert it to v4.
1255 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1257 vCardConflictObj vCardProcData;
1259 vCardProcData.vCardLocalData = &ClientData;
1260 vCardProcData.vCardServerData = &ConvertedV4Data;
1262 // Load the client data from the filename given.
1264 ClientData.LoadFile(FullFilename);
1268 bool *PauseMode = new bool;
1271 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1274 qrn.QResponse = &ConflictResult;
1275 qrn.PausePtr = PauseMode;
1277 vCardProcData.QRNotifData = &qrn;
1279 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1280 event.SetClientData(&vCardProcData);
1281 wxPostEvent(frmMainPtrGet, event);
1283 while (*PauseMode == TRUE){
1284 //nanosleep(&n1, &n2);
1285 SleepFor(250000000);
1291 // If replacing local version, store copy for now.
1292 // Otherwise upload to server.
1294 if (ConflictResult == 0){
1300 } else if (ConflictResult == 1){
1302 // Decided to use client version.
1304 vCardUpdateLocal.Remove(ContactInfo->Location);
1305 vCardUpdateRemote.Add(ContactInfo->Location, 1);
1307 } else if (ConflictResult == 2){
1309 // Decided to use server version.
1310 // Store the converted downloaded copy for
1311 // processing later.
1313 //vCardUpdateLocal.Add(srviter->first, 1);
1315 vCardDownloadDataFileClass vCardNewData;
1316 vCardNewData.DataType = 1;
1317 vCardNewData.FileData = ConvertedV4Data.WriteString();
1319 ConvertedV4Data.WriteFile(FullFilename);
1321 vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
1329 // Send vCard to the server.
1331 vCardUpdateRemote.Add(ContactInfo->Location, 1);
1337 // Check if local ETag is different from server ETag.
1338 // If different, obtain the vCard from the server.
1340 if (etd.ETagOrigValue != ETagSrv){
1342 vCardUpdateLocal.Add(ContactInfo->Location, 1);
1350 // Process the vCards that need to be downloaded and added/overwritten.
1352 wxString vCardFilenameFinal;
1353 wxString vCardOutputData;
1354 wxString vCardInputData;
1355 wxString ETagFileData;
1358 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1359 additer != vCardDownloadData.end(); additer++){
1361 vCardFilenameFinal.Clear();
1362 vCardInputData.Clear();
1363 vCardOutputData.Clear();
1364 ETagFileData.Clear();
1366 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1368 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1370 if (additer->second.DataType == 0){
1372 vCard ConvertedV4Data;
1374 // Grab the file from the server and write the contact out.
1376 vCard34Conv vCard34Obj;
1378 wxString ServerContactData;
1379 std::string ServerContactDataString;
1381 // Conflict. Bring up conflict resolution dialog.
1383 // Get the server contact data for comparison.
1385 ConnObjectIter->second->GetContact(additer->first.ToStdString(), &ServerContactDataString);
1386 vCardInputData = wxString::FromUTF8(ServerContactDataString.c_str());
1388 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1390 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1392 // Get the server ETag.
1394 wxString ServerETag;
1396 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1398 ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1400 // Add to the ETag Database.
1402 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1404 } else if (additer->second.DataType == 1){
1406 // Write out the contact to the account directory.
1408 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1409 vCardOutputData = additer->second.FileData;
1411 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1413 if (vCardFile.IsOpened()){
1415 vCardFile.Write(vCardOutputData, wxConvAuto());
1420 // Update the ETagDB.
1422 wxString ServerETag;
1424 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1426 ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1428 // Add to the ETag Database.
1430 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1435 // Look for vCard files which aren't in the ETagDB.
1437 while(ContinueProcess){
1439 // Check and make sure that the filename ends in .vcf/.vcard
1440 // Skip any file that beings with a dot.
1442 if (AccDirFilename.Left(1) == wxT(".")){
1444 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1449 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1450 AccDirFilename.Right(6) != wxT(".vcard")){
1452 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1457 // Look in the ETagDB for the file.
1459 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1461 if (ETagExists == FALSE){
1463 // Add the vCard to the list to be added.
1465 vCardAdd.Add(AccDirFilename, 1);
1469 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1473 // Process the vCards to add/update to the server.
1475 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1477 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1478 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1479 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1481 ContactFilename = vCardAdd[vi];
1482 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1484 ContactFilename.Trim();
1486 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1488 // Compare the ETag with the Server ETag.
1490 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1492 ETagServer = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
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 = static_cast<frmMain*>(frmMainPtr);
1502 vCard34Conv vCard34Obj;
1504 wxString ServerContactData;
1505 std::string ServerContactDataString;
1507 vCard ConvertedV4Data;
1509 // Load the client data from the filename given.
1511 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1513 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1515 // Process v3 version into v4 version.
1517 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1519 vCardConflictObj vCardProcData;
1521 vCardProcData.vCardLocalData = &ClientData;
1522 vCardProcData.vCardServerData = &ConvertedV4Data;
1523 ClientData.LoadFile(FullFilename);
1525 // Setup Conflict Resolution Dialog.
1527 // Fetch Data from Server and convert.
1529 bool *PauseMode = new bool;
1534 qrn.QResponse = &ConflictResult;
1535 qrn.PausePtr = PauseMode;
1537 vCardProcData.QRNotifData = &qrn;
1539 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1540 event.SetClientData(&vCardProcData);
1541 wxPostEvent(frmMainPtrGet, event);
1543 while (*PauseMode == TRUE){
1544 //nanosleep(&n1, &n2);
1545 SleepFor(250000000);
1551 if (ConflictResult == 0){
1558 } else if (ConflictResult == 1){
1560 // Decided to use client version.
1562 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1566 } else if (ConflictResult == 2){
1568 // Decided to use server version.
1570 // Download server version.
1572 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1580 // Setup the filename for the contact being added.
1582 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1583 wxString wxSCardData;
1586 // Load the data from the file.
1589 wxFCard.Open(wxSFilename, wxT("r"));
1591 if (wxFCard.IsOpened()){
1593 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1598 // Convert the data to v3.
1600 vCard34Conv vCard34Obj;
1602 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1604 // Upload the data to the server.
1606 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1608 // Get the Server ETag and put it in the ETag database.
1610 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1612 ETagServer = wxString::FromUTF8(EntityTagResponse.EntityTag.c_str());
1614 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1620 if (ETagOriginal != ETagServer){
1622 // Server ETag is different from original ETag.
1623 // This is a conflict which the user will now
1626 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1628 vCard34Conv vCard34Obj;
1630 std::string ServerContactDataString;
1631 wxString ServerContactData;
1633 vCard ConvertedV4Data;
1635 // Load the client data from the filename given.
1637 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1639 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1641 ClientData.LoadFile(FullFilename);
1643 // Process v3 version into v4 version.
1645 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1647 vCardConflictObj vCardProcData;
1649 vCardProcData.vCardLocalData = &ClientData;
1650 vCardProcData.vCardServerData = &ConvertedV4Data;
1652 bool *PauseMode = new bool;
1657 qrn.QResponse = &ConflictResult;
1658 qrn.PausePtr = PauseMode;
1660 vCardProcData.QRNotifData = &qrn;
1662 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1663 event.SetClientData(&vCardProcData);
1664 wxPostEvent(frmMainPtrGet, event);
1666 while (*PauseMode == TRUE){
1667 SleepFor(250000000);
1673 if (ConflictResult == 0){
1680 } else if (ConflictResult == 1){
1682 // Decided to use client version.
1684 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1688 } else if (ConflictResult == 2){
1690 // Decided to use server version.
1692 // Write server version to file.
1694 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1702 // Setup the filename for the contact being added.
1704 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1705 wxString wxSCardData;
1708 // Load the data from the file.
1711 wxFCard.Open(wxSFilename, wxT("r"));
1713 if (wxFCard.IsOpened()){
1715 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1720 // Convert the data to v3.
1722 vCard34Conv vCard34Obj;
1724 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1726 // Upload the data to the server.
1728 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1730 // Get the Server ETag and put it in the ETag database.
1732 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1734 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1742 // Process the vCards to delete locally.
1744 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1746 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1750 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1756 // Process the vCards to delete from the server.
1758 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1759 std::list<wxString> DeleteList;
1761 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1762 deliter != ETagFilenameMap->end(); deliter++){
1764 // Look through the ETagDB and find contacts which are marked as DELETED.
1766 if (deliter->second == wxT("DELETED")){
1768 ConnObjectIter->second->DeleteContact(deliter->first.ToStdString());
1770 // Delete the ETag as the file has now been deleted.
1772 DeleteList.push_back(deliter->first);
1778 for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
1779 removeetagiter != DeleteList.end(); removeetagiter++){
1781 ETagDBPtr->RemoveETag(*removeetagiter);
1785 // Write out the update server sync token.
1787 wxString ServerSyncToken = wxString::FromUTF8(ServerContactList2.SyncToken.c_str());
1789 ServerSyncToken.Trim();
1791 if (!ServerSyncToken.IsEmpty()){
1794 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1796 if (SyncWrite.IsOpened()){
1798 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1805 // Check for another sync token. If there is another
1806 // sync token then repeat this. If token matches then stop processing.
1808 if (SyncTokenLoad == ServerSyncToken){
1810 KeepUpdating = FALSE;
1816 // Mark as completed.
1818 wxString AccountNameFinal;
1819 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1820 AccountNameFinal.Append(wxT(".carddav"));
1822 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1823 reloadevent.SetString(AccountNameFinal);
1824 wxPostEvent(this->GetParent(), reloadevent);
1831 // Update the data to the server.
1838 while (iter->second == 1){
1840 SleepFor(125000000);
1850 if (TasksFoundProc == FALSE){
1852 TasksActive = FALSE;
1853 ProcessTasksData = FALSE;
1857 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1858 wxPostEvent(this, eventp);
1862 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1863 wxPostEvent(this, event);
1867 void frmActivityMgr::ProcessTasks()
1870 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1871 ProcessThread.detach();
1875 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1878 ETagTmrPtr = ETagTmrPtrInc;
1880 frmMainPtr = frmMainPtrInc;
1884 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1886 QRNotif *qrn = (QRNotif *)event.GetClientData();
1888 int *QRes = qrn->QResponse;
1890 *qrn->PausePtr = FALSE;
1892 *QRes = event.GetInt();
1896 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
1898 wxCommandEvent connevent(CONNSTAT_UPDATE);
1900 if (ApplicationSleepMode == FALSE){
1902 connevent.SetInt(1);
1903 ApplicationSleepMode = TRUE;
1904 mnuSleepMode->Check(true);
1908 connevent.SetInt(0);
1909 ApplicationSleepMode = FALSE;
1910 mnuSleepMode->Check(false);
1912 wxCommandEvent event(ACTMGR_STARTTIMER);
1913 wxPostEvent(this, event);
1915 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
1916 wxPostEvent(this, eventp);
1920 wxPostEvent(GetParent(), connevent);
1924 void frmActivityMgr::SleepMode( wxCommandEvent &event ){
1926 wxCommandEvent connevent(ACTMGR_TOGGLECONN);
1928 wxPostEvent(this, connevent);
1932 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
1934 wxString ServerCertFinal;
1936 // Get the Cert section of the certificate and write it to the file.
1938 ServerCertFinal = GetAccountDir(AccountName, TRUE);
1942 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
1943 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
1945 CertFile.Open(ServerCertFinal, wxFile::write);
1947 CertFile.Write(SSLDataIter->second, wxConvUTF8);
1952 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollectionString SSLCertInc){
1954 wxString ServerCertFinal;
1956 // Get the Cert section of the certificate and write it to the file.
1958 ServerCertFinal = GetAccountDir(AccountName, TRUE);
1962 std::map<int, SSLCertDataString>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
1963 std::multimap<string,string>::iterator SSLDataIter = SSLCDIter->second.CertData.find("Cert");
1965 CertFile.Open(ServerCertFinal, wxFile::write);
1967 CertFile.Write(SSLDataIter->second, wxConvUTF8);
1972 void frmActivityMgr::StartTimer(wxCommandEvent& event){
1974 ActListProcTimer.Start(1000, FALSE);
1978 void frmActivityMgr::StopTimer(wxCommandEvent& event){
1980 ActListProcTimer.Stop();
1984 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
1986 ActProcessTimer.Start(1000, FALSE);
1990 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
1992 ActProcessTimer.Stop();
1996 void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
1998 AnimationTimer.StartAnimation();
2002 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2004 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2006 if (actmgrudata != NULL){
2008 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);