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__)
335 ConnObjectIter->second->BypassSSLVerification(true);
337 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
339 ConnObjectIter->second->BypassSSLVerification(false);
341 BOOL ModifiedCertificateData = false;
342 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle());
344 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) {
345 wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
348 if (ModifiedCertificateData == false) {
350 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection());
356 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
362 bool UsingSSLBypass = false;
365 // Connect again and fetch SSL certificate information.
367 ConnObjectIter->second->BypassSSLVerification(true);
369 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
371 ConnObjectIter->second->BypassSSLVerification(false);
373 SSLInvalidCertNotifObjString SSLICNProcData;
375 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
377 bool *PauseMode = new bool;
381 qrn.QResponse = &SSLResult;
382 qrn.PausePtr = PauseMode;
384 SSLICNProcData.CertCollection = certcol;
385 SSLICNProcData.QRNotifData = &qrn;
386 SSLICNProcData.AccountName = AccountNameFriendly;
388 wxCommandEvent event(INVALIDSSLCERTSTRING);
389 event.SetClientData(&SSLICNProcData);
390 wxPostEvent(frmMainPtrGet, event);
392 while (*PauseMode == TRUE){
393 //nanosleep(&n1, &n2);
397 // Process the response from the user.
401 // Accept the Certificate.
403 UsingSSLBypass = true;
404 ConnObjectIter->second->BypassSSLVerification(true);
406 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
407 WriteServerCertificate(AccountDir, certcol);
409 ConnObjectIter->second->BypassSSLVerification(false);
411 } else if (SSLResult == 2){
413 // Reject the certificate, abort the task and mark as failed.
422 frmMainPtrGet->ResumeAllTimers();
425 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
427 ConnectResponse = ConnObjectIter->second->Connect(true);
429 if (ConnectResponse == COCONNECT_OK){
442 } else if (ConnectResponse == COCONNECT_OK){
444 ConnectResponse = ConnObjectIter->second->Connect(true);
459 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
463 #if defined(__APPLE__)
465 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
467 #elif defined(__WIN32__)
469 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
473 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
477 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(StringURLIter->second.ToStdString(),
478 StringDataIter->second.ToStdString());
480 if (AddContactResponse.RequestResult != COREQUEST_OK){
485 // Get the entity tag for the new contact.
487 COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
489 if (ETagGetResponse.RequestResult != COREQUEST_OK){
494 std::cout << ETagGetResponse.EntityTag << std::endl;
496 ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
503 } else if (TypeIter->second == 1){
507 StringDataIter = ActivityListData.find(iter->first);
508 StringURLIter = ActivityListURL.find(iter->first);
510 AccountDir = StringAccountIter->second;
511 ContactFilename = StringFilenameIter->second;
512 wxString AccountNameFriendly;
516 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
518 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
520 AccountDirCheck.Trim();
521 AccountDirCheck.Append(wxT(".carddav"));
523 if (AccountDirCheck == StringAccountIter->second){
525 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
532 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
534 ETag = StringETagIter->second;
535 ETagOriginal = StringETagOrigIter->second;
536 AccountDir = StringAccountIter->second;
537 ContactFilename = StringFilenameIter->second;
538 FullFilename = StringFullFilenameIter->second;
539 EditMode = ActivityListEditMode.find(iter->first)->second;
541 bool KeepUpdating = true;
543 while(KeepUpdating == true){
545 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
547 bool ExitLoop = false;
549 while(ExitLoop == false){
551 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
553 frmMainPtrGet->PauseAllTimers();
555 #if defined(__APPLE__)
556 #elif defined(__WIN32__)
558 ConnObjectIter->second->BypassSSLVerification(true);
560 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
562 ConnObjectIter->second->BypassSSLVerification(false);
564 BOOL ModifiedCertificateData = false;
565 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle());
567 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) {
568 wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
571 if (ModifiedCertificateData == FALSE) {
573 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection());
579 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
585 bool UsingSSLBypass = false;
588 // Connect again and fetch SSL certificate information.
590 ConnObjectIter->second->BypassSSLVerification(true);
592 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
594 ConnObjectIter->second->BypassSSLVerification(false);
596 SSLInvalidCertNotifObjString SSLICNProcData;
598 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
600 bool *PauseMode = new bool;
604 qrn.QResponse = &SSLResult;
605 qrn.PausePtr = PauseMode;
607 SSLICNProcData.CertCollection = certcol;
608 SSLICNProcData.QRNotifData = &qrn;
609 SSLICNProcData.AccountName = AccountNameFriendly;
611 wxCommandEvent event(INVALIDSSLCERTSTRING);
612 event.SetClientData(&SSLICNProcData);
613 wxPostEvent(frmMainPtrGet, event);
615 while (*PauseMode == TRUE){
619 // Process the response from the user.
623 // Accept the Certificate.
625 UsingSSLBypass = true;
626 ConnObjectIter->second->BypassSSLVerification(true);
628 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
629 WriteServerCertificate(AccountDir, certcol);
631 ConnObjectIter->second->BypassSSLVerification(false);
633 } else if (SSLResult == 2){
635 // Reject the certificate, abort the task and mark as failed.
644 frmMainPtrGet->ResumeAllTimers();
647 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
649 ConnectResponse = ConnObjectIter->second->Connect(true);
651 if (ConnectResponse == COCONNECT_OK){
664 } else if (ConnectResponse == COCONNECT_OK){
666 ConnectResponse = ConnObjectIter->second->Connect(true);
681 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
685 COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
687 if (ETagGetResponse.RequestResult != COREQUEST_OK){
692 ETagServer = ETagGetResponse.EntityTag;
694 // Compare the ETag with the Server ETag.
696 if (ETagOriginal != ETagServer){
698 // Server ETag is different from original ETag.
699 // This is a conflict which the user will now
702 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
704 vCard34Conv vCard34Obj;
706 std::string ServerContactData;
707 wxString wxStringServerContactData;
709 vCard ConvertedV4Data;
711 // Load the client data from the filename given.
713 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(),
716 if (GetContactResponse.RequestResult != COREQUEST_OK){
721 wxStringServerContactData = wxString::FromUTF8((const char*)ServerContactData.c_str());
723 // Process v3 version into v4 version.
725 vCard34Obj.ConvertToV4(&wxStringServerContactData, &ConvertedV4Data);
727 vCardConflictObj vCardProcData;
729 vCardProcData.vCardLocalData = &ClientData;
730 vCardProcData.vCardServerData = &ConvertedV4Data;
731 ClientData.LoadFile(FullFilename);
733 // Setup Conflict Resolution Dialog.
735 // Fetch Data from Server and convert.
737 bool *PauseMode = new bool;
742 qrn.QResponse = &ConflictResult;
743 qrn.PausePtr = PauseMode;
745 vCardProcData.QRNotifData = &qrn;
747 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
748 event.SetClientData(&vCardProcData);
749 wxPostEvent(frmMainPtrGet, event);
751 while (*PauseMode == TRUE){
758 if (ConflictResult == 0){
765 } else if (ConflictResult == 1){
767 // Decided to use client version.
769 } else if (ConflictResult == 2){
771 // Decided to use server version.
773 // Download server version.
775 ConvertedV4Data.WriteFile(FullFilename);
781 // Upload the data to the server.
783 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(StringURLIter->second.ToStdString(),
784 StringDataIter->second.ToStdString());
786 if (EditContactResponse.RequestResult != COREQUEST_OK){
793 ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
795 if (ETagGetResponse.RequestResult != COREQUEST_OK){
800 ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
807 } else if (TypeIter->second == 2) {
809 // Delete the contact from the server and update the ETag DB.
811 AccountDir = StringAccountIter->second;
812 ContactFilename = StringFilenameIter->second;
813 wxString AccountNameFriendly;
817 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
819 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
821 AccountDirCheck.Trim();
822 AccountDirCheck.Append(wxT(".carddav"));
824 if (AccountDirCheck == StringAccountIter->second){
826 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
833 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
835 bool KeepUpdating = TRUE;
837 while(KeepUpdating == TRUE){
839 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
841 bool ExitLoop = FALSE;
843 while (ExitLoop == FALSE){
845 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
847 frmMainPtrGet->PauseAllTimers();
849 #if defined(__APPLE__)
850 #elif defined(__WIN32__)
852 ConnObjectIter->second->BypassSSLVerification(true);
854 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
856 ConnObjectIter->second->BypassSSLVerification(false);
858 BOOL ModifiedCertificateData = false;
859 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle());
861 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) {
862 wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
865 if (ModifiedCertificateData == false) {
867 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection());
873 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
879 bool UsingSSLBypass = false;
882 // Connect again and fetch SSL certificate information.
884 ConnObjectIter->second->BypassSSLVerification(true);
886 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
888 ConnObjectIter->second->BypassSSLVerification(false);
890 SSLInvalidCertNotifObjString SSLICNProcData;
892 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
894 bool *PauseMode = new bool;
898 qrn.QResponse = &SSLResult;
899 qrn.PausePtr = PauseMode;
901 SSLICNProcData.CertCollection = certcol;
902 SSLICNProcData.QRNotifData = &qrn;
903 SSLICNProcData.AccountName = AccountNameFriendly;
905 wxCommandEvent event(INVALIDSSLCERTSTRING);
906 event.SetClientData(&SSLICNProcData);
907 wxPostEvent(frmMainPtrGet, event);
909 while (*PauseMode == TRUE){
910 //nanosleep(&n1, &n2);
914 // Process the response from the user.
918 // Accept the Certificate.
920 UsingSSLBypass = true;
921 ConnObjectIter->second->BypassSSLVerification(true);
923 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
924 WriteServerCertificate(AccountDir, certcol);
926 ConnObjectIter->second->BypassSSLVerification(false);
928 } else if (SSLResult == 2){
930 // Reject the certificate, abort the task and mark as failed.
939 frmMainPtrGet->ResumeAllTimers();
942 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
944 ConnectResponse = ConnObjectIter->second->Connect(true);
946 if (ConnectResponse == COCONNECT_OK){
959 } else if (ConnectResponse == COCONNECT_OK){
961 ConnectResponse = ConnObjectIter->second->Connect(true);
976 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
980 #if defined(__APPLE__)
982 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
984 #elif defined(__WIN32__)
986 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
990 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
994 COServerResponse DeleteContactResponse = ConnObjectIter->second->DeleteContact(ContactFilename.ToStdString());
996 if (DeleteContactResponse.RequestResult != COREQUEST_OK){
1001 ETagDBPtr->RemoveETag(ContactFilename);
1008 } else if (TypeIter->second == 3) {
1010 wxString AccountNameFriendly;
1014 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
1016 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
1018 AccountDirCheck.Trim();
1019 AccountDirCheck.Append(wxT(".carddav"));
1021 if (AccountDirCheck == StringAccountIter->second){
1023 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
1030 bool KeepUpdating = TRUE;
1032 while (KeepUpdating == TRUE){
1034 StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
1036 AccountDir = StringAccountIter->second;
1038 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1040 wxArrayString vCardAdd;
1041 wxArrayString vCardDelete;
1042 wxArrayString vCardList;
1043 wxArrayString vCardUpdateLocal;
1044 wxArrayString vCardUpdateRemote;
1045 wxArrayString vCardUpdateLog;
1046 std::map<wxString,wxString> vCardETag;
1048 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
1050 // Get the list of vCard files locally.
1052 wxString AccountDirFinal;
1053 wxString AccountSyncTokenFilename;
1054 wxString SyncTokenLoad;
1056 #if defined(__HAIKU__)
1058 //preffilename = wxT("noo");
1060 #elif defined(__WIN32__)
1062 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
1063 AccountSyncTokenFilename = AccountDirFinal;
1064 AccountSyncTokenFilename.Append(wxT("synctoken"));
1068 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
1069 AccountSyncTokenFilename = AccountDirFinal;
1070 AccountSyncTokenFilename.Append(wxT("synctoken"));
1074 // Suppress Error Messages.
1076 wxLogNull PleaseDoNotDisturb;
1079 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
1081 if (SyncLoad.IsOpened()){
1083 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1088 // Get a list of vCard files from the server.
1090 // Get the list of vCard files from the ETagDB.
1092 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1094 COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
1096 bool ExitLoop = FALSE;
1098 while (ExitLoop == FALSE){
1100 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
1102 frmMainPtrGet->PauseAllTimers();
1104 #if defined(__APPLE__)
1105 #elif defined(__WIN32__)
1107 ConnObjectIter->second->BypassSSLVerification(true);
1109 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
1111 ConnObjectIter->second->BypassSSLVerification(false);
1113 BOOL ModifiedCertificateData = false;
1114 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle());
1116 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) {
1117 wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
1120 if (ModifiedCertificateData == false) {
1122 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection());
1128 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1134 bool UsingSSLBypass = false;
1137 // Connect again and fetch SSL certificate information.
1139 ConnObjectIter->second->BypassSSLVerification(true);
1141 COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
1143 ConnObjectIter->second->BypassSSLVerification(false);
1145 SSLInvalidCertNotifObjString SSLICNProcData;
1147 SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
1149 bool *PauseMode = new bool;
1153 qrn.QResponse = &SSLResult;
1154 qrn.PausePtr = PauseMode;
1156 SSLICNProcData.CertCollection = certcol;
1157 SSLICNProcData.QRNotifData = &qrn;
1158 SSLICNProcData.AccountName = AccountNameFriendly;
1160 wxCommandEvent event(INVALIDSSLCERTSTRING);
1161 event.SetClientData(&SSLICNProcData);
1162 wxPostEvent(frmMainPtrGet, event);
1164 while (*PauseMode == TRUE){
1165 //nanosleep(&n1, &n2);
1166 SleepFor(250000000);
1169 // Process the response from the user.
1171 if (SSLResult == 1){
1173 // Accept the Certificate.
1175 UsingSSLBypass = true;
1176 ConnObjectIter->second->BypassSSLVerification(true);
1178 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
1179 WriteServerCertificate(AccountDir, certcol);
1181 ConnObjectIter->second->BypassSSLVerification(false);
1183 } else if (SSLResult == 2){
1185 // Reject the certificate, abort the task and mark as failed.
1194 frmMainPtrGet->ResumeAllTimers();
1197 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
1199 ConnectResponse = ConnObjectIter->second->Connect(true);
1201 if (ConnectResponse == COCONNECT_OK){
1214 } else if (ConnectResponse == COCONNECT_OK){
1216 ConnectResponse = ConnObjectIter->second->Connect(true);
1231 #if defined(__APPLE__)
1233 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1235 #elif defined(__WIN32__)
1237 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1241 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1245 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1249 // Look in directory and see which vCards to add and delete
1252 // vCard exists but not in ETagDB - Add (and upload).
1253 // vCard missing but in ETagDB - Delete (from server).
1255 // Start by looking for vCards that are not in the ETagDB.
1257 wxDir AccDir(AccountDirFinal);
1258 wxString AccDirFilename;
1260 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1262 COContactList ServerContactList2 = ConnObjectIter->second->GetContactList(SyncTokenLoad.ToStdString());
1264 // Process the server data.
1266 for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1267 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1269 if (ContactInfo->Status == COCS_UPDATED){
1271 vCardDownloadDataFileClass vCardNewData;
1272 vCardNewData.DataType = 0;
1273 vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
1275 } else if (ContactInfo->Status == COCS_DELETED){
1277 vCardDelete.Add(ContactInfo->Location, 1);
1283 // Look for vCards that are missing but in the ETagDB.
1285 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1286 etagiter != ETagDBData.end(); etagiter++){
1288 // Check if the vCard exists.
1290 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1292 // vCard doesn't exist so mark for deleting.
1294 vCardDelete.Add(etagiter->first, 1);
1300 // Compare Server with the ETag DB. Work out which
1301 // needs to updated remotely and which needs to be
1304 for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1305 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1307 if (ETagDBData.find(ContactInfo->Location) == ETagDBData.end()){
1311 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(ContactInfo->Location);
1313 ETagData etd = lociter->second;
1315 wxString ETagSrv = ContactInfo->Data;
1317 // Check if the local ETag value has 'DELETED' set and skip
1318 // checking this file if it does.
1320 if (etd.ETagValue == "DELETED"){
1326 // Compare local ETag with original local ETag.
1327 // If different, update to server is required.
1329 if (etd.ETagValue != etd.ETagOrigValue){
1331 // Check if local original ETag is different from server ETag.
1332 // If it is then throw up a conflict resolution dialog.
1334 if (etd.ETagOrigValue != ETagSrv){
1336 vCard34Conv vCard34Obj;
1338 wxString FullFilename;
1340 vCard ConvertedV4Data;
1342 std::string ServerContactDataString;
1343 wxString ServerContactData;
1345 // Conflict. Bring up conflict resolution dialog.
1347 // Get the server contact data for comparison.
1349 ConnObjectIter->second->GetContact(ContactInfo->Location, &ServerContactDataString);
1350 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1352 FullFilename = CreateFilenamePath(AccountDirFinal, ContactInfo->Location);
1354 // Convert it to v4.
1356 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1358 vCardConflictObj vCardProcData;
1360 vCardProcData.vCardLocalData = &ClientData;
1361 vCardProcData.vCardServerData = &ConvertedV4Data;
1363 // Load the client data from the filename given.
1365 ClientData.LoadFile(FullFilename);
1369 bool *PauseMode = new bool;
1372 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1375 qrn.QResponse = &ConflictResult;
1376 qrn.PausePtr = PauseMode;
1378 vCardProcData.QRNotifData = &qrn;
1380 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1381 event.SetClientData(&vCardProcData);
1382 wxPostEvent(frmMainPtrGet, event);
1384 while (*PauseMode == TRUE){
1385 //nanosleep(&n1, &n2);
1386 SleepFor(250000000);
1392 // If replacing local version, store copy for now.
1393 // Otherwise upload to server.
1395 if (ConflictResult == 0){
1401 } else if (ConflictResult == 1){
1403 // Decided to use client version.
1405 vCardUpdateLocal.Remove(ContactInfo->Location);
1406 vCardUpdateRemote.Add(ContactInfo->Location, 1);
1408 } else if (ConflictResult == 2){
1410 // Decided to use server version.
1411 // Store the converted downloaded copy for
1412 // processing later.
1414 //vCardUpdateLocal.Add(srviter->first, 1);
1416 vCardDownloadDataFileClass vCardNewData;
1417 vCardNewData.DataType = 1;
1418 vCardNewData.FileData = ConvertedV4Data.WriteString();
1420 ConvertedV4Data.WriteFile(FullFilename);
1422 vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
1430 // Send vCard to the server.
1432 vCardUpdateRemote.Add(ContactInfo->Location, 1);
1438 // Check if local ETag is different from server ETag.
1439 // If different, obtain the vCard from the server.
1441 if (etd.ETagOrigValue != ETagSrv){
1443 vCardUpdateLocal.Add(ContactInfo->Location, 1);
1451 // Process the vCards that need to be downloaded and added/overwritten.
1453 wxString vCardFilenameFinal;
1454 wxString vCardOutputData;
1455 wxString vCardInputData;
1456 wxString ETagFileData;
1459 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1460 additer != vCardDownloadData.end(); additer++){
1462 vCardFilenameFinal.Clear();
1463 vCardInputData.Clear();
1464 vCardOutputData.Clear();
1465 ETagFileData.Clear();
1467 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1469 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1471 if (additer->second.DataType == 0){
1473 vCard ConvertedV4Data;
1475 // Grab the file from the server and write the contact out.
1477 vCard34Conv vCard34Obj;
1479 wxString ServerContactData;
1480 std::string ServerContactDataString;
1482 // Conflict. Bring up conflict resolution dialog.
1484 // Get the server contact data for comparison.
1486 ConnObjectIter->second->GetContact(additer->first.ToStdString(), &ServerContactDataString);
1487 vCardInputData = wxString::FromUTF8(ServerContactDataString.c_str());
1489 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1491 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1493 // Get the server ETag.
1495 wxString ServerETag;
1497 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1499 if (ServerEntityTag.RequestResult != COREQUEST_OK){
1504 ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1506 // Add to the ETag Database.
1508 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1510 } else if (additer->second.DataType == 1){
1512 // Write out the contact to the account directory.
1514 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1515 vCardOutputData = additer->second.FileData;
1517 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1519 if (vCardFile.IsOpened()){
1521 vCardFile.Write(vCardOutputData, wxConvAuto());
1526 // Update the ETagDB.
1528 wxString ServerETag;
1530 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1532 if (ServerEntityTag.RequestResult != COREQUEST_OK){
1537 ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1539 // Add to the ETag Database.
1541 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1546 // Check if any errors occured before continuing.
1548 if (iter->second != 1){
1552 // Look for vCard files which aren't in the ETagDB.
1554 while(ContinueProcess){
1556 // Check and make sure that the filename ends in .vcf/.vcard
1557 // Skip any file that beings with a dot.
1559 if (AccDirFilename.Left(1) == wxT(".")){
1561 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1566 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1567 AccDirFilename.Right(6) != wxT(".vcard")){
1569 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1574 // Look in the ETagDB for the file.
1576 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1578 if (ETagExists == FALSE){
1580 // Add the vCard to the list to be added.
1582 vCardAdd.Add(AccDirFilename, 1);
1586 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1590 // Process the vCards to add/update to the server.
1592 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1594 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1595 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1596 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1598 ContactFilename = vCardAdd[vi];
1599 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1601 ContactFilename.Trim();
1603 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1605 // Compare the ETag with the Server ETag.
1607 COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1609 if (ServerEntityTag.RequestResult != COREQUEST_OK){
1614 // TODO: Continue from here!
1616 ETagServer = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1618 if (ETagOriginal != ETagServer){
1620 // Server ETag is different from original ETag.
1621 // This is a conflict which the user will now
1624 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1626 vCard34Conv vCard34Obj;
1628 wxString ServerContactData;
1629 std::string ServerContactDataString;
1631 vCard ConvertedV4Data;
1633 // Load the client data from the filename given.
1635 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1637 if (GetContactResponse.RequestResult != COREQUEST_OK){
1642 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1644 // Process v3 version into v4 version.
1646 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1648 vCardConflictObj vCardProcData;
1650 vCardProcData.vCardLocalData = &ClientData;
1651 vCardProcData.vCardServerData = &ConvertedV4Data;
1652 ClientData.LoadFile(FullFilename);
1654 // Setup Conflict Resolution Dialog.
1656 // Fetch Data from Server and convert.
1658 bool *PauseMode = new bool;
1663 qrn.QResponse = &ConflictResult;
1664 qrn.PausePtr = PauseMode;
1666 vCardProcData.QRNotifData = &qrn;
1668 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1669 event.SetClientData(&vCardProcData);
1670 wxPostEvent(frmMainPtrGet, event);
1672 while (*PauseMode == TRUE){
1673 //nanosleep(&n1, &n2);
1674 SleepFor(250000000);
1680 if (ConflictResult == 0){
1687 } else if (ConflictResult == 1){
1689 // Decided to use client version.
1691 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1693 if (EditContactResponse.RequestResult != COREQUEST_OK){
1700 } else if (ConflictResult == 2){
1702 // Decided to use server version.
1704 // Download server version.
1706 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1714 // Setup the filename for the contact being added.
1716 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1717 wxString wxSCardData;
1720 // Load the data from the file.
1723 wxFCard.Open(wxSFilename, wxT("r"));
1725 if (wxFCard.IsOpened()){
1727 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1732 // Convert the data to v3.
1734 vCard34Conv vCard34Obj;
1736 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1738 // Upload the data to the server.
1740 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1742 if (AddContactResponse.RequestResult != COREQUEST_OK){
1747 // Get the Server ETag and put it in the ETag database.
1749 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1751 if (EntityTagResponse.RequestResult != COREQUEST_OK){
1756 ETagServer = wxString::FromUTF8(EntityTagResponse.EntityTag.c_str());
1758 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1764 if (ETagOriginal != ETagServer){
1766 // Server ETag is different from original ETag.
1767 // This is a conflict which the user will now
1770 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1772 vCard34Conv vCard34Obj;
1774 std::string ServerContactDataString;
1775 wxString ServerContactData;
1777 vCard ConvertedV4Data;
1779 // Load the client data from the filename given.
1781 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1783 if (GetContactResponse.RequestResult != COREQUEST_OK){
1788 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1790 ClientData.LoadFile(FullFilename);
1792 // Process v3 version into v4 version.
1794 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1796 vCardConflictObj vCardProcData;
1798 vCardProcData.vCardLocalData = &ClientData;
1799 vCardProcData.vCardServerData = &ConvertedV4Data;
1801 bool *PauseMode = new bool;
1806 qrn.QResponse = &ConflictResult;
1807 qrn.PausePtr = PauseMode;
1809 vCardProcData.QRNotifData = &qrn;
1811 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1812 event.SetClientData(&vCardProcData);
1813 wxPostEvent(frmMainPtrGet, event);
1815 while (*PauseMode == TRUE){
1816 SleepFor(250000000);
1822 if (ConflictResult == 0){
1829 } else if (ConflictResult == 1){
1831 // Decided to use client version.
1833 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1835 if (EditContactResponse.RequestResult != COREQUEST_OK){
1842 } else if (ConflictResult == 2){
1844 // Decided to use server version.
1846 // Write server version to file.
1848 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1856 // Setup the filename for the contact being added.
1858 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1859 wxString wxSCardData;
1862 // Load the data from the file.
1865 wxFCard.Open(wxSFilename, wxT("r"));
1867 if (wxFCard.IsOpened()){
1869 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1874 // Convert the data to v3.
1876 vCard34Conv vCard34Obj;
1878 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1880 // Upload the data to the server.
1882 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1884 if (AddContactResponse.RequestResult != COREQUEST_OK){
1889 // Get the Server ETag and put it in the ETag database.
1891 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1893 if (EntityTagResponse.RequestResult != COREQUEST_OK){
1898 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1906 if (iter->second != 1){
1910 // Process the vCards to delete locally.
1912 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1914 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1918 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1924 // Process the vCards to delete from the server.
1926 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1927 std::list<wxString> DeleteList;
1929 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1930 deliter != ETagFilenameMap->end(); deliter++){
1932 // Look through the ETagDB and find contacts which are marked as DELETED.
1934 if (deliter->second == wxT("DELETED")){
1936 ConnObjectIter->second->DeleteContact(deliter->first.ToStdString());
1938 // Delete the ETag as the file has now been deleted.
1940 DeleteList.push_back(deliter->first);
1946 for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
1947 removeetagiter != DeleteList.end(); removeetagiter++){
1949 ETagDBPtr->RemoveETag(*removeetagiter);
1953 // Write out the update server sync token.
1955 wxString ServerSyncToken = wxString::FromUTF8(ServerContactList2.SyncToken.c_str());
1957 ServerSyncToken.Trim();
1959 if (!ServerSyncToken.IsEmpty()){
1962 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1964 if (SyncWrite.IsOpened()){
1966 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1973 // Check for another sync token. If there is another
1974 // sync token then repeat this. If token matches then stop processing.
1976 if (SyncTokenLoad == ServerSyncToken){
1978 KeepUpdating = FALSE;
1984 // Mark as completed.
1986 wxString AccountNameFinal;
1987 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1988 AccountNameFinal.Append(wxT(".carddav"));
1990 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1991 reloadevent.SetString(AccountNameFinal);
1992 wxPostEvent(this->GetParent(), reloadevent);
1999 // Update the data to the server.
2006 while (iter->second == 1){
2008 SleepFor(125000000);
2018 if (TasksFoundProc == FALSE){
2020 TasksActive = FALSE;
2021 ProcessTasksData = FALSE;
2025 wxCommandEvent eventp(ACTMGR_STARTTIMER);
2026 wxPostEvent(this, eventp);
2030 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
2031 wxPostEvent(this, event);
2035 void frmActivityMgr::ProcessTasks()
2038 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
2039 ProcessThread.detach();
2043 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
2046 ETagTmrPtr = ETagTmrPtrInc;
2048 frmMainPtr = frmMainPtrInc;
2052 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
2054 QRNotif *qrn = (QRNotif *)event.GetClientData();
2056 int *QRes = qrn->QResponse;
2058 *qrn->PausePtr = FALSE;
2060 *QRes = event.GetInt();
2064 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
2066 wxCommandEvent connevent(CONNSTAT_UPDATE);
2068 if (ApplicationSleepMode == FALSE){
2070 connevent.SetInt(1);
2071 ApplicationSleepMode = TRUE;
2072 mnuSleepMode->Check(true);
2076 connevent.SetInt(0);
2077 ApplicationSleepMode = FALSE;
2078 mnuSleepMode->Check(false);
2080 wxCommandEvent event(ACTMGR_STARTTIMER);
2081 wxPostEvent(this, event);
2083 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
2084 wxPostEvent(this, eventp);
2088 wxPostEvent(GetParent(), connevent);
2092 void frmActivityMgr::SleepMode( wxCommandEvent &event ){
2094 wxCommandEvent connevent(ACTMGR_TOGGLECONN);
2096 wxPostEvent(this, connevent);
2100 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
2102 wxString ServerCertFinal;
2104 // Get the Cert section of the certificate and write it to the file.
2106 ServerCertFinal = GetAccountDir(AccountName, TRUE);
2110 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2111 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
2113 CertFile.Open(ServerCertFinal, wxFile::write);
2115 CertFile.Write(SSLDataIter->second, wxConvUTF8);
2120 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollectionString SSLCertInc){
2122 wxString ServerCertFinal;
2124 // Get the Cert section of the certificate and write it to the file.
2126 ServerCertFinal = GetAccountDir(AccountName, TRUE);
2130 std::map<int, SSLCertDataString>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2131 std::multimap<string,string>::iterator SSLDataIter = SSLCDIter->second.CertData.find("Cert");
2133 CertFile.Open(ServerCertFinal, wxFile::write);
2135 CertFile.Write(SSLDataIter->second, wxConvUTF8);
2140 void frmActivityMgr::StartTimer(wxCommandEvent& event){
2142 ActListProcTimer.Start(1000, FALSE);
2146 void frmActivityMgr::StopTimer(wxCommandEvent& event){
2148 ActListProcTimer.Stop();
2152 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
2154 ActProcessTimer.Start(1000, FALSE);
2158 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
2160 ActProcessTimer.Stop();
2164 void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
2166 AnimationTimer.StartAnimation();
2170 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2172 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2174 if (actmgrudata != NULL){
2176 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);