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>
27 #include <curl/curl.h>
31 #include "common/preferences.h"
32 #include "frmConflictResolution.h"
33 #include "frmInvalidSSLCertificate.h"
35 #include "common/events.h"
36 #include "common/filename.h"
37 #include "common/dirs.h"
38 #include "vcard/vcard34conv.h"
39 #include "vcard/vcard.h"
42 #ifndef FRMACTIVITYMGR_H
43 #define FRMACTIVITYMGR_H
45 DEFINE_EVENT_TYPE(ACTMGR_RESUMEPROC);
46 DEFINE_EVENT_TYPE(ACTMGR_TOGGLECONN);
47 DEFINE_EVENT_TYPE(ACTMGR_STARTTIMER);
48 DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
49 DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
50 DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
51 DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
53 BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
54 EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
55 EVT_COMMAND(wxID_ANY, ACTMGR_TOGGLECONN, frmActivityMgr::ToggleConnectionStatus)
56 EVT_COMMAND(wxID_ANY, ACTMGR_STARTTIMER, frmActivityMgr::StartTimer)
57 EVT_COMMAND(wxID_ANY, ACTMGR_STOPTIMER, frmActivityMgr::StopTimer)
58 EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
59 EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
60 EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
63 frmActivityMgr::frmActivityMgr( wxWindow* parent )
65 frmActivityMgrADT( parent )
68 wxMemoryInputStream istream(icons_activitywindow_png, sizeof(icons_activitywindow_png));
69 wxImage icons_activitywindow_pngi(istream, wxBITMAP_TYPE_PNG);
70 wxBitmap activityiconbmp(icons_activitywindow_pngi, -1);
72 activityicon.CopyFromBitmap(activityiconbmp);
73 this->SetIcon(activityicon);
75 wxMemoryInputStream istream2(misc_activitysleep_png, sizeof(misc_activitysleep_png));
76 wxImage misc_activitysleep_pngi(istream2, wxBITMAP_TYPE_PNG);
77 wxBitmap sleepiconbmp(misc_activitysleep_pngi, -1);
78 SleepBitmap = sleepiconbmp;
79 bmpActivity->SetBitmap(SleepBitmap);
80 ActProcessTimer.SetupPointers(this);
81 lblDetails->SetLabel(_("No activity."));
83 ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail,
84 &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
85 &ActProcessTimer, &ActivityListFinDate);
87 AnimationTimer.SetBitmap(bmpActivity);
88 AnimationTimer.SetSleepBitmap(&SleepBitmap);
89 AnimationTimer.SetupPointer(this->GetParent());
91 wxListItem ColumnData;
93 ColumnData.SetText(_("Activity"));
94 ColumnData.SetWidth(175);
95 lstActivity->InsertColumn(0, ColumnData);
97 wxListItem ColumnData2;
99 ColumnData2.SetText(_("Account"));
100 ColumnData2.SetWidth(100);
101 lstActivity->InsertColumn(1, ColumnData2);
103 wxListItem ColumnData3;
104 ColumnData3.SetId(2);
105 ColumnData3.SetText(_("Status"));
106 ColumnData3.SetWidth(100);
107 lstActivity->InsertColumn(2, ColumnData3);
109 //AnimationTimer.StartAnimation();
111 // Create recovery database if it doesn't exist.
113 wxString RecoveryFilename = GetRecoveryDB();
117 if (wxFile::Exists(RecoveryFilename) == FALSE){
119 // Create the recovery database.
121 RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);
123 RecoveryDB.Write(wxT("BEGIN:XAB-RECOVERYDB\r\n"), wxConvUTF8);
124 RecoveryDB.Write(wxT("VERSION:1.0\r\n"), wxConvUTF8);
125 RecoveryDB.Write(wxT("COMMENT:Please do not alter or delete this file. DATA LOSS IS POSSIBLE!\r\n"), wxConvUTF8);
126 RecoveryDB.Write(wxT("END:XAB-RECOVERYDB\r\n"), wxConvUTF8);
133 #if wxABI_VERSION < 20900
134 RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
136 RecoveryDBF.Open(RecoveryFilename, wxT("r"));
139 // Load the recovery database for tasks not done.
141 if (RecoveryDBF.IsOpened() == TRUE){
143 wxString wxSRecoveryDB;
144 wxString RecoveryLine;
146 // Check if we are using wxWidgets version 2.8 or less and
147 // execute the required command accordingly.
149 RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
153 std::map<int, wxString> RecoveryFileLines;
154 std::map<int, wxString>::iterator striter;
156 wxStringTokenizer wSTRecoveryDBLines(wxSRecoveryDB, wxT("\r\n"));
158 int RecoveryLineSeek = 0;
160 while (wSTRecoveryDBLines.HasMoreTokens() == TRUE){
162 RecoveryLine = wSTRecoveryDBLines.GetNextToken();
163 RecoveryFileLines.insert(std::make_pair(RecoveryLineSeek, RecoveryLine));
172 //TestTimer.Start(50, FALSE);
175 int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAccount,
176 wxString TaskURL, wxString TaskFilename, wxString TaskFullFilename,
185 coldata.SetId(ActivityTaskID);
186 coldata.SetData(ActivityTaskID);
188 AnimationTimer.StartAnimation();
190 // Get the preferences file.
192 wxString PrefFilename = GetUserPrefDir();
194 XABPreferences PrefData(PrefFilename);
196 wxString AccountName;
198 wxString AccountAddress;
200 wxString AccountUsername;
201 wxString AccountPassword;
202 bool AccountSSL = FALSE;
203 wxString AccountPrefix;
205 // Look for the account and get the friendly name for the account.
207 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
209 AccountDir = PrefData.accounts.GetAccountDirectory(i);
212 AccountDir.Append(wxT(".carddav"));
214 if (AccountDir == TaskAccount){
216 AccountName = PrefData.accounts.GetAccountName(i);
217 AccountAddress = PrefData.accounts.GetAccountAddress(i);
218 AccountPort = PrefData.accounts.GetAccountPort(i);
219 AccountUsername = PrefData.accounts.GetAccountUsername(i);
220 AccountPassword = PrefData.accounts.GetAccountPassword(i);
221 AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
222 AccountSSL = PrefData.accounts.GetAccountSSL(i);
225 AccountAddress.Trim();
226 //AccountPort.Trim();
227 AccountUsername.Trim();
228 AccountPassword.Trim();
229 AccountPrefix.Trim();
236 CardDAVConn.SetupConnection(AccountAddress, AccountPort, AccountUsername, AccountPassword, AccountSSL, AccountPrefix, AccountDir);
237 CardDAVConn.SetupVariables(&ActivityList, ActivityTaskID);
238 CardDAVConn.SetupResultBools(&BlankBool, &BlankBool);
241 // 0 - Add a contact.
242 // 1 - Update a contact.
243 // 2 - Delete a contact.
244 // 3 - Account syncronisation.
248 coldata.SetText(_("Adding Contact '") + TaskDetail + _("'"));
249 itemindex = lstActivity->InsertItem(coldata);
251 lstActivity->SetItem(itemindex, 1, AccountName);
252 lstActivity->SetItem(itemindex, 2, _("Queued"));
254 CardDAVConn.SetUploadMode(TRUE);
255 CardDAVConn.SetupData(wxT("PUT"), TaskURL, TaskData);
257 // Setup all of the task details.
259 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
261 ActivityListType.insert(std::make_pair(ActivityTaskID, 0));
262 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
263 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
264 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
265 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
266 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
267 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
268 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
270 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
271 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
272 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
274 } else if (TaskType == 1){
276 coldata.SetText(_("Updating Contact '") + TaskDetail + _("'"));
277 itemindex = lstActivity->InsertItem(coldata);
279 lstActivity->SetItem(itemindex, 1, AccountName);
280 lstActivity->SetItem(itemindex, 2, _("Queued"));
282 CardDAVConn.SetUploadMode(TRUE);
283 CardDAVConn.SetupData(wxT("PUT"), TaskURL, TaskData);
284 CardDAVConn.SetEditMode(TRUE);
286 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
288 ActivityListType.insert(std::make_pair(ActivityTaskID, 1));
289 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
290 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
291 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
292 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail));
293 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
294 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
295 ActivityListFullFilename.insert(std::make_pair(ActivityTaskID, TaskFullFilename));
297 ActivityListETag.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETag(TaskFilename)));
298 ActivityListETagOriginal.insert(std::make_pair(ActivityTaskID, ETagDBPtr->GetETagOriginal(TaskFilename)));
299 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
301 } else if (TaskType == 2){
303 coldata.SetText(_("Deleting Contact '") + TaskDetail + _("'"));
304 itemindex = lstActivity->InsertItem(coldata);
306 lstActivity->SetItem(itemindex, 1, AccountName);
307 lstActivity->SetItem(itemindex, 2, _("Queued"));
309 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
311 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
312 ActivityListType.insert(std::make_pair(ActivityTaskID, 2));
313 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
314 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
315 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
316 ActivityListFilename.insert(std::make_pair(ActivityTaskID, TaskFilename));
317 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
319 } else if (TaskType == 3){
321 coldata.SetText(_("Syncronising All Contacts"));
322 itemindex = lstActivity->InsertItem(coldata);
324 lstActivity->SetItem(itemindex, 1, AccountName);
325 lstActivity->SetItem(itemindex, 2, _("Queued"));
327 ActivityList.insert(std::make_pair(ActivityTaskID, 0));
328 ActivityListType.insert(std::make_pair(ActivityTaskID, 3));
329 ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData));
330 ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn));
331 ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, AccountPrefix));
332 ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount));
333 ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex));
337 ProcessTasksData = TRUE;
339 if (!ActProcessTimer.IsRunning()) {
341 wxCommandEvent event(ACTMGR_STARTTIMER);
342 wxPostEvent(this, event);
344 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
345 wxPostEvent(this, eventp);
347 //ActProcessTimer.Start(1000, FALSE);
348 //ActListProcTimer.Start(1000, FALSE);
352 // Update the recovery database.
354 return ActivityTaskID;
358 void frmActivityMgr::RemoveTask(){
360 // Remove task from the recovery database.
364 void frmActivityMgr::StopTask( wxCommandEvent& event ){
366 // Check if activity has been completed already before stopping.
368 long longSelected = -1;
369 int intSelectedData = 0;
371 longSelected = lstActivity->GetNextItem(longSelected,
373 wxLIST_STATE_SELECTED);
375 intSelectedData = (int)lstActivity->GetItemData(longSelected);
377 if (longSelected == -1){
381 std::map<int,CardDAV>::iterator CDAVter;
383 CDAVter = ActivityListConn.find(intSelectedData);
385 CDAVter->second.Abort();
387 lstActivity->SetItem(longSelected, 2, _("Stopped"));
391 void frmActivityMgr::StopAllTasks( wxCommandEvent& event ){
393 // Check if activity has been completed already before stopping.
395 // TODO: Look through for '1' and stop the running task(s).
397 long longSelected = -1;
398 int intSelectedData = 0;
400 longSelected = lstActivity->GetNextItem(longSelected,
402 wxLIST_STATE_SELECTED);
404 intSelectedData = (int)lstActivity->GetItemData(longSelected);
406 if (longSelected == -1){
410 std::map<int,CardDAV>::iterator CDAVter;
412 CDAVter = ActivityListConn.find(intSelectedData);
414 CDAVter->second.Abort();
416 lstActivity->SetItem(longSelected, 2, _("Stopped"));
417 AnimationTimer.StopAnimation();
418 bmpActivity->SetBitmap(SleepBitmap);
419 lblDetails->SetLabel(_("No activity."));
423 void frmActivityMgr::RetryTask( wxCommandEvent& event ){
425 // Check if activity has been completed already before retrying.
427 long longSelected = -1;
428 int intSelectedData = 0;
430 longSelected = lstActivity->GetNextItem(longSelected,
432 wxLIST_STATE_SELECTED);
434 intSelectedData = (int)lstActivity->GetItemData(longSelected);
436 if (longSelected == -1){
440 std::map<int,CardDAV>::iterator CDAVter;
442 CDAVter = ActivityListConn.find(intSelectedData);
446 //CDAVter->second.Abort();
448 std::map<int,int>::iterator Iter;
449 Iter = ActivityList.find(intSelectedData);
453 AnimationTimer.StartAnimation();
455 if (!ActProcessTimer.IsRunning()) {
457 ActProcessTimer.Start(150, FALSE);
458 ActListProcTimer.Start(150, FALSE);
462 //lstActivity->SetItem(longSelected, 2, _("Processing..."));
466 void frmActivityMgr::OpenWindow()
471 void frmActivityMgr::CloseWindow( wxCommandEvent& event )
477 void frmActivityMgr::CloseWindow( wxCloseEvent& event )
483 void frmActivityMgr::ProcessTasksThread()
486 if (ProcessTasksData == FALSE){
492 std::map<int,int>::iterator TypeIter;
493 std::map<int,wxString>::iterator StringIter;
494 std::map<int,wxString>::iterator StringDetailIter;
495 std::map<int,wxString>::iterator StringAccountIter;
496 std::map<int,wxString>::iterator StringFilenameIter;
497 std::map<int,wxString>::iterator StringFullFilenameIter;
498 std::map<int,wxString>::iterator StringTaskDetailIter;
499 std::map<int,wxString>::iterator StringETagIter;
500 std::map<int,wxString>::iterator StringETagOrigIter;
501 std::map<int,CardDAV>::iterator CardDAVIter;
502 std::map<int,long>::iterator LongIter;
503 bool TasksFoundProc = FALSE;
506 for (std::map<int,int>::iterator iter = ActivityList.begin();
507 iter != ActivityList.end(); ++iter){
509 // Check for any queued tasks and start one.
511 if (iter->second > 4){
515 CardDAVIter = ActivityListConn.find(iter->first);
516 TypeIter = ActivityListType.find(iter->first);
517 StringETagIter = ActivityListETag.find(iter->first);
518 StringETagOrigIter = ActivityListETagOriginal.find(iter->first);
519 StringAccountIter = ActivityListAccount.find(iter->first);
520 StringFilenameIter = ActivityListFilename.find(iter->first);
521 StringFullFilenameIter = ActivityListFullFilename.find(iter->first);
528 // 5 = Failed (UI Updated).
529 // 6 = Stopped (UI Updated).
530 // 7 = (Reserved) (UI Updated).
531 // 8 = Completed. (UI Updated).
533 if (iter->second == 0){
535 //CardDAVIter->second.
537 // Wait for process to finish.
540 TasksFoundProc = TRUE;
542 wxString ETagOriginal;
545 wxString ContactFilename;
546 wxString FullFilename;
551 if (TypeIter->second == 1){
552 CardDAVIter->second.GetServerETagValueThread();
553 ETagServer = CardDAVIter->second.ETagValueResult();
556 // Compare the ETags and work out if a conflict has occured.
558 if (TypeIter->second == 1){
560 ETag = StringETagIter->second;
561 ETagOriginal = StringETagOrigIter->second;
562 AccountDir = StringAccountIter->second;
563 ContactFilename = StringFilenameIter->second;
564 FullFilename = StringFullFilenameIter->second;
566 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
568 if (ETag == ETagOriginal){
570 // Compare the ETag with the Server ETag.
572 if (ETagOriginal != ETagServer){
574 // Server ETag is different from original ETag.
575 // This is a conflict which the user will now
581 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
583 vCard34Conv vCard34Obj;
585 wxString ServerContactData;
587 vCard ConvertedV4Data;
589 // Load the client data from the filename given.
591 CardDAVIter->second.GetServerContactData();
592 ServerContactData = CardDAVIter->second.GetPageData();
594 // Process v3 version into v4 version.
596 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
598 vCardConflictObj vCardProcData;
600 vCardProcData.vCardLocalData = &ClientData;
601 vCardProcData.vCardServerData = &ConvertedV4Data;
602 ClientData.LoadFile(FullFilename);
604 //ContactConflictEvent event(ContactConflictCmdEnv);
605 //event.SetData(ContactFilename, Moo1, Moo2);
607 //wxPostEvent(frmMainPtrGet, event);
609 // Setup Conflict Resolution Dialog.
611 // Fetch Data from Server and convert.
613 bool *PauseMode = new bool;
618 qrn.QResponse = &ConflictResult;
619 qrn.PausePtr = PauseMode;
621 vCardProcData.QRNotifData = &qrn;
623 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
624 event.SetClientData(&vCardProcData);
625 wxPostEvent(frmMainPtrGet, event);
630 n1.tv_nsec = 250000000L;*/
632 while (*PauseMode == TRUE){
633 //nanosleep(&n1, &n2);
640 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
642 if (ConflictResult == 0){
649 } else if (ConflictResult == 1){
651 // Decided to use client version.
653 CardDAVIter->second.ProcessData();
657 } else if (ConflictResult == 2){
659 // Decided to use server version.
661 // Download server version.
663 ConvertedV4Data.WriteFile(FullFilename);
671 // Update the data to the server.
673 CardDAVIter->second.ProcessData();
679 if (ETagOriginal != ETagServer){
681 // Server ETag is different from original ETag.
682 // This is a conflict which the user will now
685 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
687 //ContactConflictEvent event(ContactConflictCmdEnv);
688 //event.SetData(ContactFilename, Moo1, Moo2);
690 vCard34Conv vCard34Obj;
692 wxString ServerContactData;
694 vCard ConvertedV4Data;
696 // Load the client data from the filename given.
698 CardDAVIter->second.GetServerContactData();
699 ServerContactData = CardDAVIter->second.GetPageData();
700 ClientData.LoadFile(FullFilename);
702 // Process v3 version into v4 version.
704 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
706 vCardConflictObj vCardProcData;
708 vCardProcData.vCardLocalData = &ClientData;
709 vCardProcData.vCardServerData = &ConvertedV4Data;
711 bool *PauseMode = new bool;
716 qrn.QResponse = &ConflictResult;
717 qrn.PausePtr = PauseMode;
719 vCardProcData.QRNotifData = &qrn;
721 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
722 event.SetClientData(&vCardProcData);
723 wxPostEvent(frmMainPtrGet, event);
728 n1.tv_nsec = 250000000L;*/
730 while (*PauseMode == TRUE){
731 //nanosleep(&n1, &n2);
738 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
740 if (ConflictResult == 0){
747 } else if (ConflictResult == 1){
749 // Decided to use client version.
751 CardDAVIter->second.ProcessData();
752 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
753 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
757 } else if (ConflictResult == 2){
759 // Decided to use server version.
761 // Write server version to file.
763 ConvertedV4Data.WriteFile(FullFilename);
771 // Update the data to the server.
773 CardDAVIter->second.ProcessData();
779 // Update the ETag DB.
781 CardDAVIter->second.GetServerETagValueThread();
782 ETagServer = CardDAVIter->second.ETagValueResult();
783 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
787 } else if (TypeIter->second == 2) {
789 // Delete the contact from the server and update the ETag DB.
791 AccountDir = StringAccountIter->second;
792 ContactFilename = StringFilenameIter->second;
794 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
796 CardDAVIter->second.SetUploadMode(FALSE);
797 CardDAVIter->second.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
798 //CardDAVIter->second.SetServerFilename();
799 CardDAVIter->second.ProcessData();
800 ETagDBPtr->RemoveETag(ContactFilename);
804 } else if (TypeIter->second == 3) {
806 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
808 wxString AccountNameFriendly;
809 wxString PrefFilename = GetUserPrefDir();
811 XABPreferences PrefData(PrefFilename);
814 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
816 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
818 AccountDirCheck.Trim();
819 AccountDirCheck.Append(wxT(".carddav"));
821 if (AccountDirCheck == StringAccountIter->second){
823 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
830 bool KeepUpdating = TRUE;
832 while (KeepUpdating == TRUE){
834 StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
836 AccountDir = StringAccountIter->second;
838 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
840 wxArrayString vCardAdd;
841 wxArrayString vCardDelete;
842 wxArrayString vCardList;
843 wxArrayString vCardUpdateLocal;
844 wxArrayString vCardUpdateRemote;
845 wxArrayString vCardUpdateLog;
846 std::map<wxString,wxString> vCardETag;
847 ContactListData ServerContactList;
849 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
850 //wxArrayString vCardDownload;
851 //std::map<wxString,wxString> vCardDownloadData;
853 // Get the list of vCard files locally.
855 wxString AccountDirFinal;
856 wxString AccountSyncTokenFilename;
857 wxString SyncTokenLoad;
859 #if defined(__HAIKU__)
861 //preffilename = wxT("noo");
863 #elif defined(__WIN32__)
865 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
866 AccountSyncTokenFilename = AccountDirFinal;
867 AccountSyncTokenFilename.Append(wxT("synctoken"));
871 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
872 AccountSyncTokenFilename = AccountDirFinal;
873 AccountSyncTokenFilename.Append(wxT("synctoken"));
877 // Suppress Error Messages.
879 wxLogNull PleaseDoNotDisturb;
882 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
884 if (SyncLoad.IsOpened()){
886 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
891 // Get a list of vCard files from the server.
893 // Get the list of vCard files from the ETagDB.
895 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
897 CardDAV CardDAVInstance = CardDAVIter->second;
899 bool ExitLoop = FALSE;
901 std::map<wxString,FileSyncData> *SCListData = NULL;
903 while (ExitLoop == FALSE){
905 //ServerContactList = CardDAVInstance.GetContactList(SyncTokenLoad.ToUTF8());
906 ServerContactList = CardDAVIter->second.GetContactList(SyncTokenLoad.ToUTF8());
907 SSLCertCollection certcol = CardDAVIter->second.GetCertificateData();
909 // Create a pointer for the std::map<wxString,FileSyncData>.
911 SCListData = &ServerContactList.ListData;
913 // Check if any errors have occured whilst getting the data.
915 int ErrorCode = CardDAVIter->second.GetResultCode();
919 if (ErrorCode == 60 || ErrorCode == 51){
921 // Invalid SSL certificate so bring up a dialog to the user
922 // explaining what has happened and the options available.
924 // Stop all the timers.
926 frmMainPtrGet->PauseAllTimers();
928 // Setup the data to be sent in the wxPostEvent command.
930 SSLInvalidCertNotifObj SSLICNProcData;
932 bool *PauseMode = new bool;
937 qrn.QResponse = &SSLResult;
938 qrn.PausePtr = PauseMode;
940 SSLICNProcData.CertCollection = certcol;
941 SSLICNProcData.QRNotifData = &qrn;
942 SSLICNProcData.AccountName = AccountNameFriendly;
944 wxCommandEvent event(INVALIDSSLCERT);
945 event.SetClientData(&SSLICNProcData);
946 wxPostEvent(frmMainPtrGet, event);
950 // Fall asleep until we get an response.
953 n1.tv_nsec = 250000000L;*/
955 while (*PauseMode == TRUE){
956 //nanosleep(&n1, &n2);
960 // Process the response from the user.
964 // Accept the certificate. Write the certificate into the account
965 // directory (as server.crt) - will overwrite old certificate.
967 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
968 WriteServerCertificate(AccountDir, CardDAVIter->second.GetCertificateData());
970 } else if (SSLResult == 2){
972 // Reject the certificate, abort the task and mark as failed.
974 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, CardDAVIter->second.GetCertificateData());
980 // Resume all the timers.
982 frmMainPtrGet->ResumeAllTimers();
999 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1003 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second.GetCertificateData());
1005 // Look in directory and see which vCards to add and delete
1008 // vCard exists but not in ETagDB - Add (and upload).
1009 // vCard missing but in ETagDB - Delete (from server).
1011 // Start by looking for vCards that are not in the ETagDB.
1013 wxDir AccDir(AccountDirFinal);
1014 wxString AccDirFilename;
1016 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1018 // Process the server data.
1020 if (SCListData != NULL){
1022 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1023 fsiter != SCListData->end(); fsiter++){
1025 // Check the mode of the file before adding.
1027 // Get the HTTP status of the file from the list.
1029 FileSyncData fsd = fsiter->second;
1031 if (fsd.DataFlag == 1){
1033 // Added or modified contact.
1035 //vCardAdd.Add(fsiter->first, 1);
1037 vCardDownloadDataFileClass vCardNewData;
1038 vCardNewData.DataType = 0;
1039 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1041 //} else if (fsd.DataFlag == 1){
1043 // Contact has been modified on the server.
1045 // vCardUpdateLocal.Add(fsiter->first, 1);
1048 else if (fsd.DataFlag == 2){
1050 // Contact has been deleted.
1052 vCardDelete.Add(fsiter->first, 1);
1060 // Look for vCards that are missing but in the ETagDB.
1062 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1063 etagiter != ETagDBData.end(); etagiter++){
1065 // Check if the vCard exists.
1067 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1069 // vCard doesn't exist so mark for deleting.
1071 vCardDelete.Add(etagiter->first, 1);
1077 // Compare Server with the ETag DB. Work out which
1078 // needs to updated remotely and which needs to be
1081 for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1082 srviter != SCListData->end(); srviter++){
1084 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1088 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1090 ETagData etd = lociter->second;
1091 FileSyncData fsd = srviter->second;
1093 wxString ETagSrv = fsd.ETagData;
1095 // Compare local ETag with original local ETag.
1096 // If different, update to server is required.
1098 if (etd.ETagValue != etd.ETagOrigValue){
1100 // Check if local original ETag is different from server ETag.
1101 // If it is then throw up a conflict resolution dialog.
1103 if (etd.ETagOrigValue != ETagSrv){
1105 vCard34Conv vCard34Obj;
1107 wxString ServerContactData;
1108 wxString FullFilename;
1110 vCard ConvertedV4Data;
1112 // Conflict. Bring up conflict resolution dialog.
1114 // Get the server contact data for comparison.
1116 CardDAVIter->second.SetServerFilename(srviter->first);
1117 CardDAVIter->second.GetServerContactData();
1118 ServerContactData = CardDAVIter->second.GetPageData();
1120 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1122 // Convert it to v4.
1124 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1126 vCardConflictObj vCardProcData;
1128 vCardProcData.vCardLocalData = &ClientData;
1129 vCardProcData.vCardServerData = &ConvertedV4Data;
1131 // Load the client data from the filename given.
1133 ClientData.LoadFile(FullFilename);
1137 bool *PauseMode = new bool;
1140 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1143 qrn.QResponse = &ConflictResult;
1144 qrn.PausePtr = PauseMode;
1146 vCardProcData.QRNotifData = &qrn;
1148 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1149 event.SetClientData(&vCardProcData);
1150 wxPostEvent(frmMainPtrGet, event);
1155 n1.tv_nsec = 250000000L;*/
1157 while (*PauseMode == TRUE){
1158 //nanosleep(&n1, &n2);
1159 SleepFor(250000000);
1165 // If replacing local version, store copy for now.
1166 // Otherwise upload to server.
1168 if (ConflictResult == 0){
1174 } else if (ConflictResult == 1){
1176 // Decided to use client version.
1178 vCardUpdateLocal.Remove(srviter->first);
1179 vCardUpdateRemote.Add(srviter->first, 1);
1181 } else if (ConflictResult == 2){
1183 // Decided to use server version.
1184 // Store the converted downloaded copy for
1185 // processing later.
1187 //vCardUpdateLocal.Add(srviter->first, 1);
1189 vCardDownloadDataFileClass vCardNewData;
1190 vCardNewData.DataType = 1;
1191 vCardNewData.FileData = ConvertedV4Data.WriteString();
1193 ConvertedV4Data.WriteFile(FullFilename);
1195 vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData));
1203 // Send vCard to the server.
1205 vCardUpdateRemote.Add(srviter->first, 1);
1211 // Check if local ETag is different from server ETag.
1212 // If different, obtain the vCard from the server.
1214 if (etd.ETagOrigValue != ETagSrv){
1216 vCardUpdateLocal.Add(srviter->first, 1);
1224 // Process the vCards that need to be downloaded and added/overwritten.
1226 wxString vCardFilenameFinal;
1227 wxString vCardOutputData;
1228 wxString vCardInputData;
1229 wxString ETagFileData;
1232 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1233 additer != vCardDownloadData.end(); additer++){
1235 vCardFilenameFinal.Clear();
1236 vCardInputData.Clear();
1237 vCardOutputData.Clear();
1238 ETagFileData.Clear();
1240 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1242 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1244 if (additer->second.DataType == 0){
1246 vCard ConvertedV4Data;
1248 // Grab the file from the server and write the contact out.
1250 vCard34Conv vCard34Obj;
1252 CardDAVIter->second.SetServerFilename(additer->first);
1253 CardDAVIter->second.GetServerContactData();
1254 vCardInputData = CardDAVIter->second.GetPageData();
1256 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1258 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1260 // Update the ETagDB.
1262 //vCardFile.Open(vCardFilenameFinal, wxT("w"));
1264 //if (vCardFile.IsOpened()){
1266 // vCardFile.Write(vCardOutputData, wxConvAuto());
1267 // vCardFile.Close();
1271 // Get the server ETag.
1273 wxString ServerETag;
1274 CardDAVIter->second.GetServerETagValueThread();
1275 ServerETag = CardDAVIter->second.ETagValueResult();
1277 // Add to the ETag Database.
1279 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1281 } else if (additer->second.DataType == 1){
1283 // Write out the contact to the account directory.
1285 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1286 vCardOutputData = additer->second.FileData;
1288 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1290 if (vCardFile.IsOpened()){
1292 vCardFile.Write(vCardOutputData, wxConvAuto());
1297 // Update the ETagDB.
1299 wxString ServerETag;
1300 CardDAVIter->second.GetServerETagValueThread();
1301 ServerETag = CardDAVIter->second.ETagValueResult();
1303 // Add to the ETag Database.
1305 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1310 // Look for vCard files which aren't in the ETagDB.
1312 while(ContinueProcess){
1314 // Check and make sure that the filename ends in .vcf/.vcard
1315 // Skip any file that beings with a dot.
1317 if (AccDirFilename.Left(1) == wxT(".")){
1319 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1324 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1325 AccDirFilename.Right(6) != wxT(".vcard")){
1327 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1332 // Look in the ETagDB for the file.
1334 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1336 if (ETagExists == FALSE){
1338 // Add the vCard to the list to be added.
1340 vCardAdd.Add(AccDirFilename, 1);
1344 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1348 // Process the vCards to add/update to the server.
1350 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1352 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1353 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1354 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1356 ContactFilename = vCardAdd[vi];
1357 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1359 ContactFilename.Trim();
1361 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1363 // Compare the ETag with the Server ETag.
1365 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1366 CardDAVIter->second.GetServerETagValueThread();
1367 ETagServer = CardDAVIter->second.ETagValueResult();
1369 if (ETagOriginal != ETagServer){
1371 // Server ETag is different from original ETag.
1372 // This is a conflict which the user will now
1375 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1377 vCard34Conv vCard34Obj;
1379 wxString ServerContactData;
1381 vCard ConvertedV4Data;
1383 // Load the client data from the filename given.
1385 CardDAVIter->second.GetServerContactData();
1386 ServerContactData = CardDAVIter->second.GetPageData();
1388 // Process v3 version into v4 version.
1390 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1392 vCardConflictObj vCardProcData;
1394 vCardProcData.vCardLocalData = &ClientData;
1395 vCardProcData.vCardServerData = &ConvertedV4Data;
1396 ClientData.LoadFile(FullFilename);
1398 //ContactConflictEvent event(ContactConflictCmdEnv);
1399 //event.SetData(ContactFilename, Moo1, Moo2);
1401 //wxPostEvent(frmMainPtrGet, event);
1403 // Setup Conflict Resolution Dialog.
1405 // Fetch Data from Server and convert.
1407 bool *PauseMode = new bool;
1412 qrn.QResponse = &ConflictResult;
1413 qrn.PausePtr = PauseMode;
1415 vCardProcData.QRNotifData = &qrn;
1417 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1418 event.SetClientData(&vCardProcData);
1419 wxPostEvent(frmMainPtrGet, event);
1424 n1.tv_nsec = 250000000L;*/
1426 while (*PauseMode == TRUE){
1427 //nanosleep(&n1, &n2);
1428 SleepFor(250000000);
1434 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1436 if (ConflictResult == 0){
1443 } else if (ConflictResult == 1){
1445 // Decided to use client version.
1447 CardDAVIter->second.ProcessData();
1451 } else if (ConflictResult == 2){
1453 // Decided to use server version.
1455 // Download server version.
1457 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1465 // Setup the filename for the contact being added.
1467 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1468 wxString wxSCardData;
1472 // Load the data from the file.
1475 wxFCard.Open(wxSFilename, wxT("r"));
1477 if (wxFCard.IsOpened()){
1479 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1484 // Convert the data to v3.
1486 vCard34Conv vCard34Obj;
1488 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1490 // Setup the URL address.
1492 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1494 // Upload the data to the server.
1496 CardDAVIter->second.SetUploadMode(TRUE);
1497 CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1498 CardDAVIter->second.ProcessData();
1500 // Get the Server ETag and put it in the ETag database.
1502 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1503 CardDAVIter->second.GetServerETagValueThread();
1504 ETagServer = CardDAVIter->second.ETagValueResult();
1506 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1512 if (ETagOriginal != ETagServer){
1514 // Server ETag is different from original ETag.
1515 // This is a conflict which the user will now
1518 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1520 //ContactConflictEvent event(ContactConflictCmdEnv);
1521 //event.SetData(ContactFilename, Moo1, Moo2);
1523 vCard34Conv vCard34Obj;
1525 wxString ServerContactData;
1527 vCard ConvertedV4Data;
1529 // Load the client data from the filename given.
1531 CardDAVIter->second.GetServerContactData();
1532 ServerContactData = CardDAVIter->second.GetPageData();
1533 ClientData.LoadFile(FullFilename);
1535 // Process v3 version into v4 version.
1537 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1539 vCardConflictObj vCardProcData;
1541 vCardProcData.vCardLocalData = &ClientData;
1542 vCardProcData.vCardServerData = &ConvertedV4Data;
1544 bool *PauseMode = new bool;
1549 qrn.QResponse = &ConflictResult;
1550 qrn.PausePtr = PauseMode;
1552 vCardProcData.QRNotifData = &qrn;
1554 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1555 event.SetClientData(&vCardProcData);
1556 wxPostEvent(frmMainPtrGet, event);
1561 n1.tv_nsec = 250000000L;*/
1563 while (*PauseMode == TRUE){
1564 //nanosleep(&n1, &n2);
1565 SleepFor(250000000);
1571 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1573 if (ConflictResult == 0){
1580 } else if (ConflictResult == 1){
1582 // Decided to use client version.
1584 CardDAVIter->second.ProcessData();
1585 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
1586 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1590 } else if (ConflictResult == 2){
1592 // Decided to use server version.
1594 // Write server version to file.
1596 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1604 // Setup the filename for the contact being added.
1606 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1607 wxString wxSCardData;
1611 // Load the data from the file.
1614 wxFCard.Open(wxSFilename, wxT("r"));
1616 if (wxFCard.IsOpened()){
1618 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1623 // Convert the data to v3.
1625 vCard34Conv vCard34Obj;
1627 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1629 // Setup the URL address.
1631 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1633 // Upload the data to the server.
1635 CardDAVIter->second.SetUploadMode(TRUE);
1636 CardDAVIter->second.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1637 CardDAVIter->second.ProcessData();
1639 // Get the Server ETag and put it in the ETag database.
1641 CardDAVIter->second.SetServerFilename(vCardAdd[vi]);
1642 CardDAVIter->second.GetServerETagValueThread();
1643 ETagServer = CardDAVIter->second.ETagValueResult();
1646 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1654 // Process the vCards to delete locally.
1656 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1658 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1662 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1668 // Process the vCards to delete from the server.
1670 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1673 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1674 deliter != ETagFilenameMap->end(); deliter++){
1676 // Look through the ETagDB and find contacts which are marked as DELETED.
1678 if (deliter->second == wxT("DELETED")){
1680 CardDAVIter->second.SetUploadMode(FALSE);
1681 CardDAVIter->second.SetupData(wxT("DELETE"), deliter->first, wxT(""));
1682 CardDAVIter->second.ProcessData();
1684 // Delete the ETag as the file has now been deleted.
1686 ETagDBPtr->RemoveETag(deliter->first);
1692 // Write out the update server sync token.
1694 wxString ServerSyncToken = ServerContactList.SyncToken;
1696 ServerSyncToken.Trim();
1698 if (!ServerSyncToken.IsEmpty()){
1701 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1703 if (SyncWrite.IsOpened()){
1705 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1712 // Check for another sync token. If there is another
1713 // sync token then repeat this. If token matches then stop processing.
1715 if (SyncTokenLoad == ServerSyncToken){
1717 KeepUpdating = FALSE;
1723 // Mark as completed.
1725 wxString AccountNameFinal;
1726 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1727 AccountNameFinal.Append(wxT(".carddav"));
1729 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1730 reloadevent.SetString(AccountNameFinal);
1731 wxPostEvent(this->GetParent(), reloadevent);
1738 // Update the data to the server.
1740 CardDAVIter->second.ProcessData();
1749 n1.tv_nsec = 250000000L;*/
1751 while (iter->second == 1){
1753 SleepFor(250000000);
1754 //nanosleep(&n1, &n2);
1758 if ((iter->second == 4 && TypeIter->second == 0) ||
1759 (iter->second == 8 && TypeIter->second == 0)){
1761 AccountDir = StringAccountIter->second;
1762 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1764 CardDAVIter->second.GetServerETagValueThread();
1765 ETagServer = CardDAVIter->second.ETagValueResult();
1766 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1770 if ((iter->second == 4 && TypeIter->second == 1) ||
1771 (iter->second == 8 && TypeIter->second == 1)){
1773 AccountDir = StringAccountIter->second;
1774 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1776 CardDAVIter->second.GetServerETagValueThread();
1777 ETagServer = CardDAVIter->second.ETagValueResult();
1778 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1788 if (TasksFoundProc == FALSE){
1790 TasksActive = FALSE;
1791 ProcessTasksData = FALSE;
1795 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1796 wxPostEvent(this, eventp);
1798 //AnimationTimer.StartAnimation();
1799 //ActListProcTimer.Start();
1803 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1804 wxPostEvent(this, event);
1806 //ActProcessTimer.Start();
1810 void frmActivityMgr::ProcessTasks()
1813 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1814 ProcessThread.detach();
1818 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1821 ETagTmrPtr = ETagTmrPtrInc;
1823 frmMainPtr = frmMainPtrInc;
1827 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1829 QRNotif *qrn = (QRNotif *)event.GetClientData();
1831 int *QRes = qrn->QResponse;
1833 *qrn->PausePtr = FALSE;
1835 *QRes = event.GetInt();
1839 int frmActivityMgr::GetTaskStatus(int intTaskID){
1843 if (ActivityList.find(intTaskID) == ActivityList.end()){
1849 std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
1850 intResult = taskiter->second;
1856 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
1858 wxCommandEvent connevent(CONNSTAT_UPDATE);
1860 if (SleepMode == FALSE){
1862 connevent.SetInt(1);
1867 connevent.SetInt(0);
1872 wxPostEvent(GetParent(), connevent);
1876 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
1878 wxString ServerCertFinal;
1880 // Get the Cert section of the certificate and write it to the file.
1882 ServerCertFinal = GetAccountDir(AccountName, TRUE);
1886 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
1887 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
1889 CertFile.Open(ServerCertFinal, wxFile::write);
1891 CertFile.Write(SSLDataIter->second, wxConvUTF8);
1896 void frmActivityMgr::StartTimer(wxCommandEvent& event){
1898 ActListProcTimer.Start(1000, FALSE);
1902 void frmActivityMgr::StopTimer(wxCommandEvent& event){
1904 ActListProcTimer.Stop();
1908 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
1910 ActProcessTimer.Start(1000, FALSE);
1914 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
1916 ActProcessTimer.Stop();
1920 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
1922 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
1924 if (actmgrudata != NULL){
1926 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
1928 /*if (!actmgrudata->ItemDes.IsEmpty()){
1929 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);