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, &ActivityListConn);
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,
183 CardDAV* CardDAVConn = new CardDAV;
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);
786 CardDAVIter->second = NULL;
788 } else if (TypeIter->second == 2) {
790 // Delete the contact from the server and update the ETag DB.
792 AccountDir = StringAccountIter->second;
793 ContactFilename = StringFilenameIter->second;
795 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
797 CardDAVIter->second->SetUploadMode(FALSE);
798 CardDAVIter->second->SetupData(wxT("DELETE"), ContactFilename, wxT(""));
799 //CardDAVIter->second.SetServerFilename();
800 CardDAVIter->second->ProcessData();
801 ETagDBPtr->RemoveETag(ContactFilename);
804 CardDAVIter->second = NULL;
806 } else if (TypeIter->second == 3) {
808 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
810 wxString AccountNameFriendly;
811 wxString PrefFilename = GetUserPrefDir();
813 XABPreferences PrefData(PrefFilename);
816 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
818 wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
820 AccountDirCheck.Trim();
821 AccountDirCheck.Append(wxT(".carddav"));
823 if (AccountDirCheck == StringAccountIter->second){
825 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
832 bool KeepUpdating = TRUE;
834 while (KeepUpdating == TRUE){
836 StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
838 AccountDir = StringAccountIter->second;
840 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
842 wxArrayString vCardAdd;
843 wxArrayString vCardDelete;
844 wxArrayString vCardList;
845 wxArrayString vCardUpdateLocal;
846 wxArrayString vCardUpdateRemote;
847 wxArrayString vCardUpdateLog;
848 std::map<wxString,wxString> vCardETag;
849 ContactListData ServerContactList;
851 std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
852 //wxArrayString vCardDownload;
853 //std::map<wxString,wxString> vCardDownloadData;
855 // Get the list of vCard files locally.
857 wxString AccountDirFinal;
858 wxString AccountSyncTokenFilename;
859 wxString SyncTokenLoad;
861 #if defined(__HAIKU__)
863 //preffilename = wxT("noo");
865 #elif defined(__WIN32__)
867 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
868 AccountSyncTokenFilename = AccountDirFinal;
869 AccountSyncTokenFilename.Append(wxT("synctoken"));
873 AccountDirFinal = GetAccountDir(AccountDir, FALSE);
874 AccountSyncTokenFilename = AccountDirFinal;
875 AccountSyncTokenFilename.Append(wxT("synctoken"));
879 // Suppress Error Messages.
881 wxLogNull PleaseDoNotDisturb;
884 SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
886 if (SyncLoad.IsOpened()){
888 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
893 // Get a list of vCard files from the server.
895 // Get the list of vCard files from the ETagDB.
897 std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
899 bool ExitLoop = FALSE;
901 std::map<wxString,FileSyncData> *SCListData = NULL;
903 while (ExitLoop == FALSE){
905 ServerContactList = CardDAVIter->second->GetContactList(SyncTokenLoad.ToUTF8());
906 SSLCertCollection certcol = CardDAVIter->second->GetCertificateData();
908 // Create a pointer for the std::map<wxString,FileSyncData>.
910 SCListData = &ServerContactList.ListData;
912 // Check if any errors have occured whilst getting the data.
914 int ErrorCode = CardDAVIter->second->GetResultCode();
918 if (ErrorCode == 60 || ErrorCode == 51){
920 // Invalid SSL certificate so bring up a dialog to the user
921 // explaining what has happened and the options available.
923 // Stop all the timers.
925 frmMainPtrGet->PauseAllTimers();
927 // Setup the data to be sent in the wxPostEvent command.
929 SSLInvalidCertNotifObj SSLICNProcData;
931 bool *PauseMode = new bool;
936 qrn.QResponse = &SSLResult;
937 qrn.PausePtr = PauseMode;
939 SSLICNProcData.CertCollection = certcol;
940 SSLICNProcData.QRNotifData = &qrn;
941 SSLICNProcData.AccountName = AccountNameFriendly;
943 wxCommandEvent event(INVALIDSSLCERT);
944 event.SetClientData(&SSLICNProcData);
945 wxPostEvent(frmMainPtrGet, event);
949 // Fall asleep until we get an response.
952 n1.tv_nsec = 250000000L;*/
954 while (*PauseMode == TRUE){
955 //nanosleep(&n1, &n2);
959 // Process the response from the user.
963 // Accept the certificate. Write the certificate into the account
964 // directory (as server.crt) - will overwrite old certificate.
966 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second->GetCertificateData());
967 WriteServerCertificate(AccountDir, CardDAVIter->second->GetCertificateData());
969 } else if (SSLResult == 2){
971 // Reject the certificate, abort the task and mark as failed.
973 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, CardDAVIter->second->GetCertificateData());
979 // Resume all the timers.
981 frmMainPtrGet->ResumeAllTimers();
998 if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1002 frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second->GetCertificateData());
1004 // Look in directory and see which vCards to add and delete
1007 // vCard exists but not in ETagDB - Add (and upload).
1008 // vCard missing but in ETagDB - Delete (from server).
1010 // Start by looking for vCards that are not in the ETagDB.
1012 wxDir AccDir(AccountDirFinal);
1013 wxString AccDirFilename;
1015 bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1017 // Process the server data.
1019 if (SCListData != NULL){
1021 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1022 fsiter != SCListData->end(); fsiter++){
1024 // Check the mode of the file before adding.
1026 // Get the HTTP status of the file from the list.
1028 FileSyncData fsd = fsiter->second;
1030 if (fsd.DataFlag == 1){
1032 // Added or modified contact.
1034 //vCardAdd.Add(fsiter->first, 1);
1036 vCardDownloadDataFileClass vCardNewData;
1037 vCardNewData.DataType = 0;
1038 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1040 //} else if (fsd.DataFlag == 1){
1042 // Contact has been modified on the server.
1044 // vCardUpdateLocal.Add(fsiter->first, 1);
1047 else if (fsd.DataFlag == 2){
1049 // Contact has been deleted.
1051 vCardDelete.Add(fsiter->first, 1);
1059 // Look for vCards that are missing but in the ETagDB.
1061 for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1062 etagiter != ETagDBData.end(); etagiter++){
1064 // Check if the vCard exists.
1066 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1068 // vCard doesn't exist so mark for deleting.
1070 vCardDelete.Add(etagiter->first, 1);
1076 // Compare Server with the ETag DB. Work out which
1077 // needs to updated remotely and which needs to be
1080 for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1081 srviter != SCListData->end(); srviter++){
1083 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1087 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1089 ETagData etd = lociter->second;
1090 FileSyncData fsd = srviter->second;
1092 wxString ETagSrv = fsd.ETagData;
1094 // Compare local ETag with original local ETag.
1095 // If different, update to server is required.
1097 if (etd.ETagValue != etd.ETagOrigValue){
1099 // Check if local original ETag is different from server ETag.
1100 // If it is then throw up a conflict resolution dialog.
1102 if (etd.ETagOrigValue != ETagSrv){
1104 vCard34Conv vCard34Obj;
1106 wxString ServerContactData;
1107 wxString FullFilename;
1109 vCard ConvertedV4Data;
1111 // Conflict. Bring up conflict resolution dialog.
1113 // Get the server contact data for comparison.
1115 CardDAVIter->second->SetServerFilename(srviter->first);
1116 CardDAVIter->second->GetServerContactData();
1117 ServerContactData = CardDAVIter->second->GetPageData();
1119 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1121 // Convert it to v4.
1123 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1125 vCardConflictObj vCardProcData;
1127 vCardProcData.vCardLocalData = &ClientData;
1128 vCardProcData.vCardServerData = &ConvertedV4Data;
1130 // Load the client data from the filename given.
1132 ClientData.LoadFile(FullFilename);
1136 bool *PauseMode = new bool;
1139 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1142 qrn.QResponse = &ConflictResult;
1143 qrn.PausePtr = PauseMode;
1145 vCardProcData.QRNotifData = &qrn;
1147 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1148 event.SetClientData(&vCardProcData);
1149 wxPostEvent(frmMainPtrGet, event);
1154 n1.tv_nsec = 250000000L;*/
1156 while (*PauseMode == TRUE){
1157 //nanosleep(&n1, &n2);
1158 SleepFor(250000000);
1164 // If replacing local version, store copy for now.
1165 // Otherwise upload to server.
1167 if (ConflictResult == 0){
1173 } else if (ConflictResult == 1){
1175 // Decided to use client version.
1177 vCardUpdateLocal.Remove(srviter->first);
1178 vCardUpdateRemote.Add(srviter->first, 1);
1180 } else if (ConflictResult == 2){
1182 // Decided to use server version.
1183 // Store the converted downloaded copy for
1184 // processing later.
1186 //vCardUpdateLocal.Add(srviter->first, 1);
1188 vCardDownloadDataFileClass vCardNewData;
1189 vCardNewData.DataType = 1;
1190 vCardNewData.FileData = ConvertedV4Data.WriteString();
1192 ConvertedV4Data.WriteFile(FullFilename);
1194 vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData));
1202 // Send vCard to the server.
1204 vCardUpdateRemote.Add(srviter->first, 1);
1210 // Check if local ETag is different from server ETag.
1211 // If different, obtain the vCard from the server.
1213 if (etd.ETagOrigValue != ETagSrv){
1215 vCardUpdateLocal.Add(srviter->first, 1);
1223 // Process the vCards that need to be downloaded and added/overwritten.
1225 wxString vCardFilenameFinal;
1226 wxString vCardOutputData;
1227 wxString vCardInputData;
1228 wxString ETagFileData;
1231 for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1232 additer != vCardDownloadData.end(); additer++){
1234 vCardFilenameFinal.Clear();
1235 vCardInputData.Clear();
1236 vCardOutputData.Clear();
1237 ETagFileData.Clear();
1239 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1241 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1243 if (additer->second.DataType == 0){
1245 vCard ConvertedV4Data;
1247 // Grab the file from the server and write the contact out.
1249 vCard34Conv vCard34Obj;
1251 CardDAVIter->second->SetServerFilename(additer->first);
1252 CardDAVIter->second->GetServerContactData();
1253 vCardInputData = CardDAVIter->second->GetPageData();
1255 vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1257 ConvertedV4Data.WriteFile(vCardFilenameFinal);
1259 // Update the ETagDB.
1261 //vCardFile.Open(vCardFilenameFinal, wxT("w"));
1263 //if (vCardFile.IsOpened()){
1265 // vCardFile.Write(vCardOutputData, wxConvAuto());
1266 // vCardFile.Close();
1270 // Get the server ETag.
1272 wxString ServerETag;
1273 CardDAVIter->second->GetServerETagValueThread();
1274 ServerETag = CardDAVIter->second->ETagValueResult();
1276 // Add to the ETag Database.
1278 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1280 } else if (additer->second.DataType == 1){
1282 // Write out the contact to the account directory.
1284 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1285 vCardOutputData = additer->second.FileData;
1287 vCardFile.Open(vCardFilenameFinal, wxT("w"));
1289 if (vCardFile.IsOpened()){
1291 vCardFile.Write(vCardOutputData, wxConvAuto());
1296 // Update the ETagDB.
1298 wxString ServerETag;
1299 CardDAVIter->second->GetServerETagValueThread();
1300 ServerETag = CardDAVIter->second->ETagValueResult();
1302 // Add to the ETag Database.
1304 ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1309 // Look for vCard files which aren't in the ETagDB.
1311 while(ContinueProcess){
1313 // Check and make sure that the filename ends in .vcf/.vcard
1314 // Skip any file that beings with a dot.
1316 if (AccDirFilename.Left(1) == wxT(".")){
1318 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1323 if (AccDirFilename.Right(4) != wxT(".vcf") &&
1324 AccDirFilename.Right(6) != wxT(".vcard")){
1326 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1331 // Look in the ETagDB for the file.
1333 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1335 if (ETagExists == FALSE){
1337 // Add the vCard to the list to be added.
1339 vCardAdd.Add(AccDirFilename, 1);
1343 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1347 // Process the vCards to add/update to the server.
1349 for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1351 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1352 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1353 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1355 ContactFilename = vCardAdd[vi];
1356 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1358 ContactFilename.Trim();
1360 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1362 // Compare the ETag with the Server ETag.
1364 CardDAVIter->second->SetServerFilename(vCardAdd[vi]);
1365 CardDAVIter->second->GetServerETagValueThread();
1366 ETagServer = CardDAVIter->second->ETagValueResult();
1368 if (ETagOriginal != ETagServer){
1370 // Server ETag is different from original ETag.
1371 // This is a conflict which the user will now
1374 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1376 vCard34Conv vCard34Obj;
1378 wxString ServerContactData;
1380 vCard ConvertedV4Data;
1382 // Load the client data from the filename given.
1384 CardDAVIter->second->GetServerContactData();
1385 ServerContactData = CardDAVIter->second->GetPageData();
1387 // Process v3 version into v4 version.
1389 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1391 vCardConflictObj vCardProcData;
1393 vCardProcData.vCardLocalData = &ClientData;
1394 vCardProcData.vCardServerData = &ConvertedV4Data;
1395 ClientData.LoadFile(FullFilename);
1397 //ContactConflictEvent event(ContactConflictCmdEnv);
1398 //event.SetData(ContactFilename, Moo1, Moo2);
1400 //wxPostEvent(frmMainPtrGet, event);
1402 // Setup Conflict Resolution Dialog.
1404 // Fetch Data from Server and convert.
1406 bool *PauseMode = new bool;
1411 qrn.QResponse = &ConflictResult;
1412 qrn.PausePtr = PauseMode;
1414 vCardProcData.QRNotifData = &qrn;
1416 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1417 event.SetClientData(&vCardProcData);
1418 wxPostEvent(frmMainPtrGet, event);
1423 n1.tv_nsec = 250000000L;*/
1425 while (*PauseMode == TRUE){
1426 //nanosleep(&n1, &n2);
1427 SleepFor(250000000);
1433 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1435 if (ConflictResult == 0){
1442 } else if (ConflictResult == 1){
1444 // Decided to use client version.
1446 CardDAVIter->second->ProcessData();
1450 } else if (ConflictResult == 2){
1452 // Decided to use server version.
1454 // Download server version.
1456 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1464 // Setup the filename for the contact being added.
1466 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1467 wxString wxSCardData;
1471 // Load the data from the file.
1474 wxFCard.Open(wxSFilename, wxT("r"));
1476 if (wxFCard.IsOpened()){
1478 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1483 // Convert the data to v3.
1485 vCard34Conv vCard34Obj;
1487 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1489 // Setup the URL address.
1491 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1493 // Upload the data to the server.
1495 CardDAVIter->second->SetUploadMode(TRUE);
1496 CardDAVIter->second->SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1497 CardDAVIter->second->ProcessData();
1499 // Get the Server ETag and put it in the ETag database.
1501 CardDAVIter->second->SetServerFilename(vCardAdd[vi]);
1502 CardDAVIter->second->GetServerETagValueThread();
1503 ETagServer = CardDAVIter->second->ETagValueResult();
1505 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1511 if (ETagOriginal != ETagServer){
1513 // Server ETag is different from original ETag.
1514 // This is a conflict which the user will now
1517 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1519 //ContactConflictEvent event(ContactConflictCmdEnv);
1520 //event.SetData(ContactFilename, Moo1, Moo2);
1522 vCard34Conv vCard34Obj;
1524 wxString ServerContactData;
1526 vCard ConvertedV4Data;
1528 // Load the client data from the filename given.
1530 CardDAVIter->second->GetServerContactData();
1531 ServerContactData = CardDAVIter->second->GetPageData();
1532 ClientData.LoadFile(FullFilename);
1534 // Process v3 version into v4 version.
1536 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1538 vCardConflictObj vCardProcData;
1540 vCardProcData.vCardLocalData = &ClientData;
1541 vCardProcData.vCardServerData = &ConvertedV4Data;
1543 bool *PauseMode = new bool;
1548 qrn.QResponse = &ConflictResult;
1549 qrn.PausePtr = PauseMode;
1551 vCardProcData.QRNotifData = &qrn;
1553 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1554 event.SetClientData(&vCardProcData);
1555 wxPostEvent(frmMainPtrGet, event);
1560 n1.tv_nsec = 250000000L;*/
1562 while (*PauseMode == TRUE){
1563 //nanosleep(&n1, &n2);
1564 SleepFor(250000000);
1570 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1572 if (ConflictResult == 0){
1579 } else if (ConflictResult == 1){
1581 // Decided to use client version.
1583 CardDAVIter->second->ProcessData();
1584 //ETagServer = CardDAVIter->second.GetServerETagValueThread();
1585 //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1589 } else if (ConflictResult == 2){
1591 // Decided to use server version.
1593 // Write server version to file.
1595 ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1603 // Setup the filename for the contact being added.
1605 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1606 wxString wxSCardData;
1610 // Load the data from the file.
1613 wxFCard.Open(wxSFilename, wxT("r"));
1615 if (wxFCard.IsOpened()){
1617 wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1622 // Convert the data to v3.
1624 vCard34Conv vCard34Obj;
1626 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1628 // Setup the URL address.
1630 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
1632 // Upload the data to the server.
1634 CardDAVIter->second->SetUploadMode(TRUE);
1635 CardDAVIter->second->SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
1636 CardDAVIter->second->ProcessData();
1638 // Get the Server ETag and put it in the ETag database.
1640 CardDAVIter->second->SetServerFilename(vCardAdd[vi]);
1641 CardDAVIter->second->GetServerETagValueThread();
1642 ETagServer = CardDAVIter->second->ETagValueResult();
1645 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1653 // Process the vCards to delete locally.
1655 for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1657 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1661 ETagDBPtr->RemoveETag(vCardDelete[vi]);
1667 // Process the vCards to delete from the server.
1669 std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1672 for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1673 deliter != ETagFilenameMap->end(); deliter++){
1675 // Look through the ETagDB and find contacts which are marked as DELETED.
1677 if (deliter->second == wxT("DELETED")){
1679 CardDAVIter->second->SetUploadMode(FALSE);
1680 CardDAVIter->second->SetupData(wxT("DELETE"), deliter->first, wxT(""));
1681 CardDAVIter->second->ProcessData();
1683 // Delete the ETag as the file has now been deleted.
1685 ETagDBPtr->RemoveETag(deliter->first);
1691 // Write out the update server sync token.
1693 wxString ServerSyncToken = ServerContactList.SyncToken;
1695 ServerSyncToken.Trim();
1697 if (!ServerSyncToken.IsEmpty()){
1700 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1702 if (SyncWrite.IsOpened()){
1704 SyncWrite.Write(ServerSyncToken, wxConvAuto());
1711 // Check for another sync token. If there is another
1712 // sync token then repeat this. If token matches then stop processing.
1714 if (SyncTokenLoad == ServerSyncToken){
1716 KeepUpdating = FALSE;
1722 // Mark as completed.
1724 wxString AccountNameFinal;
1725 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1726 AccountNameFinal.Append(wxT(".carddav"));
1728 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1729 reloadevent.SetString(AccountNameFinal);
1730 wxPostEvent(this->GetParent(), reloadevent);
1737 // Update the data to the server.
1739 CardDAVIter->second->ProcessData();
1748 n1.tv_nsec = 250000000L;*/
1750 while (iter->second == 1){
1752 SleepFor(250000000);
1753 //nanosleep(&n1, &n2);
1757 if ((iter->second == 4 && TypeIter->second == 0) ||
1758 (iter->second == 8 && TypeIter->second == 0)){
1760 AccountDir = StringAccountIter->second;
1761 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1763 CardDAVIter->second->GetServerETagValueThread();
1764 ETagServer = CardDAVIter->second->ETagValueResult();
1765 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1769 if ((iter->second == 4 && TypeIter->second == 1) ||
1770 (iter->second == 8 && TypeIter->second == 1)){
1772 AccountDir = StringAccountIter->second;
1773 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1775 CardDAVIter->second->GetServerETagValueThread();
1776 ETagServer = CardDAVIter->second->ETagValueResult();
1777 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
1787 if (TasksFoundProc == FALSE){
1789 TasksActive = FALSE;
1790 ProcessTasksData = FALSE;
1794 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1795 wxPostEvent(this, eventp);
1797 //AnimationTimer.StartAnimation();
1798 //ActListProcTimer.Start();
1802 wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1803 wxPostEvent(this, event);
1805 //ActProcessTimer.Start();
1809 void frmActivityMgr::ProcessTasks()
1812 std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1813 ProcessThread.detach();
1817 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1820 ETagTmrPtr = ETagTmrPtrInc;
1822 frmMainPtr = frmMainPtrInc;
1826 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1828 QRNotif *qrn = (QRNotif *)event.GetClientData();
1830 int *QRes = qrn->QResponse;
1832 *qrn->PausePtr = FALSE;
1834 *QRes = event.GetInt();
1838 int frmActivityMgr::GetTaskStatus(int intTaskID){
1842 if (ActivityList.find(intTaskID) == ActivityList.end()){
1848 std::map<int,int>::iterator taskiter = ActivityList.find(intTaskID);
1849 intResult = taskiter->second;
1855 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
1857 wxCommandEvent connevent(CONNSTAT_UPDATE);
1859 if (SleepMode == FALSE){
1861 connevent.SetInt(1);
1866 connevent.SetInt(0);
1871 wxPostEvent(GetParent(), connevent);
1875 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
1877 wxString ServerCertFinal;
1879 // Get the Cert section of the certificate and write it to the file.
1881 ServerCertFinal = GetAccountDir(AccountName, TRUE);
1885 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
1886 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
1888 CertFile.Open(ServerCertFinal, wxFile::write);
1890 CertFile.Write(SSLDataIter->second, wxConvUTF8);
1895 void frmActivityMgr::StartTimer(wxCommandEvent& event){
1897 ActListProcTimer.Start(1000, FALSE);
1901 void frmActivityMgr::StopTimer(wxCommandEvent& event){
1903 ActListProcTimer.Stop();
1907 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
1909 ActProcessTimer.Start(1000, FALSE);
1913 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
1915 ActProcessTimer.Stop();
1919 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
1921 ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
1923 if (actmgrudata != NULL){
1925 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
1927 /*if (!actmgrudata->ItemDes.IsEmpty()){
1928 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);