Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
a066d8fe1878358f368c8585c659db8b9162a5a5
[xestiaab/.git] / source / actmgr / frmActivityMgr.cpp
1 // frmActivityMgr.cpp - Activity Manager form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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>
21 #include <wx/file.h>
22 #include <wx/ffile.h>
23 #include <wx/tokenzr.h>
24 #include <wx/dir.h>
25 #include <wx/filefn.h>
26 #include <thread>
27 #include <list>
28 #include <curl/curl.h>
30 #include "../bitmaps.h"
31 #include "../enums.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)
59 END_EVENT_TABLE()
61 frmActivityMgr::frmActivityMgr( wxWindow* parent )
62 :
63 frmActivityMgrADT( parent )
64 {
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);
69         wxIcon activityicon;
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."));
80         
81         ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail, 
82                                         &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
83                                         &ActProcessTimer, &ActivityListFinDate, &ActivityListConnObject);
84         
85         AnimationTimer.SetBitmap(bmpActivity);
86         AnimationTimer.SetSleepBitmap(&SleepBitmap);
87         AnimationTimer.SetupPointer(this->GetParent());
88         
89         wxListItem ColumnData;
90         ColumnData.SetId(0);
91         ColumnData.SetText(_("Activity"));
92         ColumnData.SetWidth(175);
93         lstActivity->InsertColumn(0, ColumnData);
94         
95         wxListItem ColumnData2;
96         ColumnData2.SetId(1);
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);
106         
107         //AnimationTimer.StartAnimation();
108         
109         // Create recovery database if it doesn't exist.
110         
111         wxString RecoveryFilename = GetRecoveryDB();
112         
113         wxFile RecoveryDB;
114         
115         if (wxFile::Exists(RecoveryFilename) == FALSE){
116         
117                 // Create the recovery database.
119                 RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);       
120         
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);
125                 RecoveryDB.Close();
127         }
128         
129         wxFFile RecoveryDBF;
130         
131 #if wxABI_VERSION < 20900
132         RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
133 #else
134         RecoveryDBF.Open(RecoveryFilename, wxT("r"));
135 #endif  
136         
137         // Load the recovery database for tasks not done.
138         
139         if (RecoveryDBF.IsOpened() == TRUE){
140         
141                 wxString wxSRecoveryDB;
142                 wxString RecoveryLine;
143         
144                 // Check if we are using wxWidgets version 2.8 or less and
145                 // execute the required command accordingly.
146         
147                 RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
148         
149                 // Split the lines.
150         
151                 std::map<int, wxString> RecoveryFileLines;
152                 std::map<int, wxString>::iterator striter;
153         
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));
162                         RecoveryLineSeek++;             
163         
164                 }
165         
166         }
167         
170         //TestTimer.Start(50, FALSE);
173 void frmActivityMgr::OpenWindow()
175         WindowOpen = TRUE;
178 void frmActivityMgr::CloseWindow( wxCommandEvent& event )
180         WindowOpen = FALSE;
181         this->Hide();
184 void frmActivityMgr::CloseWindow( wxCloseEvent& event )
186         WindowOpen = FALSE;
187         this->Hide();
190 void frmActivityMgr::ProcessTasksThread()
192         
193         if (ProcessTasksData == FALSE){
194         
195                 return;
196         
197         }
198         
199         if (ApplicationSleepMode == TRUE){
200                 
201                 return;
202                 
203         }
204         
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;
220         wxString TaskDetail;
221         
222         for (std::map<int,int>::iterator iter = ActivityList.begin(); 
223          iter != ActivityList.end(); ++iter){
224          
225                 // Check for any queued tasks and start one.
226                 
227                 if (iter->second > 4){
228                         continue;
229                 }
230                 
231                 wxCommandEvent StartAnimationEvent(ACTMGR_STARTANIMATIONTIMER);
232                 
233                 wxPostEvent(this, StartAnimationEvent);
234                 
235                 // Start the animation timer if it hasn't started.
236                 
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);
245                 
246                 // Setup the CardDAV object.
247                 
248                 // 0 = Queued.
249                 // 1 = Processing.
250                 // 2 = Failed.
251                 // 3 = Stopped.
252                 // 4 = Completed.
253                 // 5 = Failed (UI Updated).
254                 // 6 = Stopped (UI Updated).
255                 // 7 = (Reserved) (UI Updated).
256                 // 8 = Completed. (UI Updated). 
257                 
258                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
259                 XABPreferences PrefData(GetUserPrefDir());
260                 
261                 if (iter->second == 0){
262                         
263                         // Wait for process to finish.
265                         TasksActive = TRUE;
266                         TasksFoundProc = TRUE;
267                         wxString ETag;
268                         wxString ETagOriginal;
269                         wxString ETagServer;
270                         wxString AccountDir;
271                         wxString ContactFilename;
272                         wxString FullFilename;
273                         wxString ETagResult;
274                         bool EditMode = FALSE;
276                         iter->second = 1;
277                         
278                         // Compare the ETags and work out if a conflict has occured.
279                         
280                         if (TypeIter->second == 0){
281                         
282                                 // Add a contact.
283                                 
284                                 StringDataIter = ActivityListData.find(iter->first);
285                                 StringURLIter = ActivityListURL.find(iter->first);
286                                 
287                                 AccountDir = StringAccountIter->second;
288                                 ContactFilename = StringFilenameIter->second;
289                                 wxString AccountNameFriendly;
290                                 
291                                 int AccountID = 0;
292                                 
293                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
294                                         
295                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
296                                         
297                                         AccountDirCheck.Trim();
298                                         AccountDirCheck.Append(wxT(".carddav"));
299                                         
300                                         if (AccountDirCheck == StringAccountIter->second){
301                                                 
302                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
303                                                 AccountID = i;
304                                                 
305                                         }
306                                         
307                                 }
308                                 
309                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
310                                 
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;
317                                 
318                                 bool KeepUpdating = true;
319                                 
320                                 while(KeepUpdating == true){
321                                         
322                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
323                                         
324                                         bool ExitLoop = false;
325                                         
326                                         while (ExitLoop == false){
327                                                 
328                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
329                                                         
330                                                         frmMainPtrGet->PauseAllTimers();
331                                                         
332 #if defined(__APPLE__)
333 #elif defined(__WIN32__)
334 #else
335         
336                                                         bool UsingSSLBypass = false;
337                                                         int SSLResult = 0;
338                                                         
339                                                         // Connect again and fetch SSL certificate information.
340                 
341                                                         ConnObjectIter->second->BypassSSLVerification(true);
342                 
343                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
345                                                         ConnObjectIter->second->BypassSSLVerification(false);
347                                                         SSLInvalidCertNotifObjString SSLICNProcData;
348                                                         
349                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
350                                                                 
351                                                         bool *PauseMode = new bool;
352                                                         QRNotif qrn;
353                                                                 
354                                                         *PauseMode = TRUE;
355                                                         qrn.QResponse = &SSLResult;
356                                                         qrn.PausePtr = PauseMode;
357                                                                 
358                                                         SSLICNProcData.CertCollection = certcol;
359                                                         SSLICNProcData.QRNotifData = &qrn;
360                                                         SSLICNProcData.AccountName = AccountNameFriendly;
361                                                                 
362                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
363                                                         event.SetClientData(&SSLICNProcData);
364                                                         wxPostEvent(frmMainPtrGet, event);
365                                                                 
366                                                         while (*PauseMode == TRUE){
367                                                                 //nanosleep(&n1, &n2);
368                                                                 SleepFor(250000000);
369                                                         }
370                                                         
371                                                         // Process the response from the user.
372                                                         
373                                                         if (SSLResult == 1){
374                                                                 
375                                                                 // Accept the Certificate.
377                                                                 UsingSSLBypass = true;
378                                                                 ConnObjectIter->second->BypassSSLVerification(true);
379                 
380                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
381                                                                 WriteServerCertificate(AccountDir, certcol);
382                                                                 
383                                                                 ConnObjectIter->second->BypassSSLVerification(false);
384                                                                 
385                                                         } else if (SSLResult == 2){
386                                                 
387                                                                 // Reject the certificate, abort the task and mark as failed.
389                                                                 iter->second = 2;
390                                                                 break;
391                                                                 
392                                                         }
393                 
394 #endif
395                                                         
396                                                         frmMainPtrGet->ResumeAllTimers();
397                                                         ExitLoop = true;
398                                                         
399                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
400                                                         
401                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
402                                                         
403                                                         if (ConnectResponse == COCONNECT_OK){
404                                                                 
405                                                                 ExitLoop = true;
406                                                                 break;
407                                                                 
408                                                         } else {
409                                                                 
410                                                                 ExitLoop = true;                                                        
411                                                                 iter->second = 2;
412                                                                 break;
413                                                                 
414                                                         }
415                                                         
416                                                 } else if (ConnectResponse == COCONNECT_OK){
417                                                         
418                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
419                                                         
420                                                         ExitLoop = true;
421                                                         break;
422                                                         
423                                                 } else {
424                                                         
425                                                         ExitLoop = true;                                                        
426                                                         iter->second = 2;
427                                                         break;
428                                                         
429                                                 }
430                                                 
431                                         }
432                                         
433                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
434                                                 break;
435                                         }
436                                         
437 #if defined(__APPLE__)
438                                         
439                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
441 #elif defined(__WIN32__)
443                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
445 #else
446                                         
447                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
448                                         
449 #endif
450                                         
451                                         COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(StringURLIter->second.ToStdString(), 
452                                                         StringDataIter->second.ToStdString());
453                                         
454                                         if (AddContactResponse.RequestResult != COREQUEST_OK){
455                                                 iter->second = 2;
456                                                 break;
457                                         }
458                                         
459                                         // Get the entity tag for the new contact.
460                                         
461                                         COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
462                                         
463                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
464                                                 iter->second = 2;
465                                                 break;
466                                         }
467                                         
468                                         std::cout << ETagGetResponse.EntityTag << std::endl;
469                                         
470                                         ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
471                                         
472                                         iter->second = 4;
473                                         break;
474                                         
475                                 }
476                                 
477                         } else if (TypeIter->second == 1){
478                                 
479                                 // Update a contact.
480                                 
481                                 StringDataIter = ActivityListData.find(iter->first);
482                                 StringURLIter = ActivityListURL.find(iter->first);
483                                 
484                                 AccountDir = StringAccountIter->second;
485                                 ContactFilename = StringFilenameIter->second;
486                                 wxString AccountNameFriendly;
487                                 
488                                 int AccountID = 0;
489                                 
490                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
491                                         
492                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
493                                         
494                                         AccountDirCheck.Trim();
495                                         AccountDirCheck.Append(wxT(".carddav"));
496                                         
497                                         if (AccountDirCheck == StringAccountIter->second){
498                                                 
499                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
500                                                 AccountID = i;
501                                                 
502                                         }
503                                         
504                                 }
505                                 
506                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
507                                 
508                                 ETag = StringETagIter->second;
509                                 ETagOriginal = StringETagOrigIter->second;
510                                 AccountDir = StringAccountIter->second;
511                                 ContactFilename = StringFilenameIter->second;
512                                 FullFilename = StringFullFilenameIter->second;
513                                 EditMode = ActivityListEditMode.find(iter->first)->second;
514                                 
515                                 bool KeepUpdating = true;
516                                 
517                                 while(KeepUpdating == true){
518                                         
519                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
520                                         
521                                         bool ExitLoop = false;
522                                         
523                                         while(ExitLoop == false){
524                                                 
525                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
526                                                         
527                                                         frmMainPtrGet->PauseAllTimers();
528                                                         
529 #if defined(__APPLE__)
530 #elif defined(__WIN32__)
531 #else
532         
533                                                         bool UsingSSLBypass = false;
534                                                         int SSLResult = 0;
535                                                         
536                                                         // Connect again and fetch SSL certificate information.
537                 
538                                                         ConnObjectIter->second->BypassSSLVerification(true);
539                 
540                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
542                                                         ConnObjectIter->second->BypassSSLVerification(false);
544                                                         SSLInvalidCertNotifObjString SSLICNProcData;
545                                                         
546                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
547                                                                 
548                                                         bool *PauseMode = new bool;
549                                                         QRNotif qrn;
550                                                                 
551                                                         *PauseMode = TRUE;
552                                                         qrn.QResponse = &SSLResult;
553                                                         qrn.PausePtr = PauseMode;
554                                                                 
555                                                         SSLICNProcData.CertCollection = certcol;
556                                                         SSLICNProcData.QRNotifData = &qrn;
557                                                         SSLICNProcData.AccountName = AccountNameFriendly;
558                                                                 
559                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
560                                                         event.SetClientData(&SSLICNProcData);
561                                                         wxPostEvent(frmMainPtrGet, event);
562                                                                 
563                                                         while (*PauseMode == TRUE){
564                                                                 SleepFor(250000000);
565                                                         }
566                                                         
567                                                         // Process the response from the user.
568                                                         
569                                                         if (SSLResult == 1){
570                                                                 
571                                                                 // Accept the Certificate.
573                                                                 UsingSSLBypass = true;
574                                                                 ConnObjectIter->second->BypassSSLVerification(true);
575                 
576                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
577                                                                 WriteServerCertificate(AccountDir, certcol);
578                                                                 
579                                                                 ConnObjectIter->second->BypassSSLVerification(false);
580                                                                 
581                                                         } else if (SSLResult == 2){
582                                                 
583                                                                 // Reject the certificate, abort the task and mark as failed.
585                                                                 iter->second = 2;
586                                                                 break;
587                                                                 
588                                                         }
589                 
590 #endif
591                                                         
592                                                         frmMainPtrGet->ResumeAllTimers();
593                                                         ExitLoop = true;
594                                                         
595                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
596                                                         
597                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
598                                                         
599                                                         if (ConnectResponse == COCONNECT_OK){
600                                                                 
601                                                                 ExitLoop = true;
602                                                                 break;
603                                                                 
604                                                         } else {
605                                                                 
606                                                                 ExitLoop = true;                                                        
607                                                                 iter->second = 2;
608                                                                 break;
609                                                                 
610                                                         }
611                                                         
612                                                 } else if (ConnectResponse == COCONNECT_OK){
613                                                         
614                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
615                                                         
616                                                         ExitLoop = true;
617                                                         break;
618                                                         
619                                                 } else {
620                                                         
621                                                         ExitLoop = true;                                                        
622                                                         iter->second = 2;
623                                                         break;
624                                                         
625                                                 }
626                                                 
627                                         }
628                                         
629                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
630                                                 break;
631                                         }
632                                         
633                                         COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
634                                         
635                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
636                                                 iter->second = 2;
637                                                 break;
638                                         }
639                                         
640                                         ETagServer = ETagGetResponse.EntityTag;
641                                         
642                                         // Compare the ETag with the Server ETag.
643                                         
644                                         if (ETagOriginal != ETagServer){
645                                                 
646                                                 // Server ETag is different from original ETag.
647                                                 // This is a conflict which the user will now
648                                                 // need to resolve.
649                                                 
650                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
651                                                 
652                                                 vCard34Conv vCard34Obj;
653                                                 
654                                                 std::string ServerContactData;
655                                                 wxString wxStringServerContactData;
656                                                 vCard ClientData;
657                                                 vCard ConvertedV4Data;
658                                                 
659                                                 // Load the client data from the filename given.
660                                                 
661                                                 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(),
662                                                         &ServerContactData);
663                                                 
664                                                 if (GetContactResponse.RequestResult != COREQUEST_OK){
665                                                         iter->second = 2;
666                                                         break;
667                                                 }
668                                                 
669                                                 wxStringServerContactData = wxString::FromUTF8((const char*)ServerContactData.c_str());
670                                                 
671                                                 // Process v3 version into v4 version.
672                                                 
673                                                 vCard34Obj.ConvertToV4(&wxStringServerContactData, &ConvertedV4Data);
674                                                 
675                                                 vCardConflictObj vCardProcData;
676                                                 
677                                                 vCardProcData.vCardLocalData = &ClientData;
678                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
679                                                 ClientData.LoadFile(FullFilename);
680                                                 
681                                                 // Setup Conflict Resolution Dialog.
682                                                 
683                                                 // Fetch Data from Server and convert.
684                                                 
685                                                 bool *PauseMode = new bool;
686                                                 int ConflictResult;
687                                                 QRNotif qrn;
688                                                 
689                                                 *PauseMode = TRUE;
690                                                 qrn.QResponse = &ConflictResult;
691                                                 qrn.PausePtr = PauseMode;
692                                                 
693                                                 vCardProcData.QRNotifData = &qrn;
694                                                 
695                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
696                                                 event.SetClientData(&vCardProcData);
697                                                 wxPostEvent(frmMainPtrGet, event);
698                                                 
699                                                 while (*PauseMode == TRUE){
700                                                         SleepFor(250000000);
701                                                 }
702                                                 
703                                                 delete PauseMode;
704                                                 PauseMode = NULL;
705                                                 
706                                                 if (ConflictResult == 0){
707                                                         
708                                                         // Decide Later.
709                                                         
710                                                         iter->second = 4;
711                                                         break;
712                                                         
713                                                 } else if (ConflictResult == 1){
714                                                         
715                                                         // Decided to use client version.
716                                                         
717                                                 } else if (ConflictResult == 2){
718                                                         
719                                                         // Decided to use server version.
720                                                         
721                                                         // Download server version.
722                                                         
723                                                         ConvertedV4Data.WriteFile(FullFilename);
724                                                         
725                                                 }
726                                                 
727                                         } else {
728                                                 
729                                                 // Upload the data to the server.
730                                                 
731                                                 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(StringURLIter->second.ToStdString(), 
732                                                         StringDataIter->second.ToStdString());
733                                         
734                                                 if (EditContactResponse.RequestResult != COREQUEST_OK){
735                                                         iter->second = 2;
736                                                         break;
737                                                 }
738                                                 
739                                         }
740                                         
741                                         ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
742                                         
743                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
744                                                 iter->second = 2;
745                                                 break;
746                                         }
747                                         
748                                         ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
749                                         
750                                         iter->second = 4;
751                                         break;
752                                         
753                                 }
754                         
755                         } else if (TypeIter->second == 2) {
756                         
757                                 // Delete the contact from the server and update the ETag DB.
758                                 
759                                 AccountDir = StringAccountIter->second;
760                                 ContactFilename = StringFilenameIter->second;
761                                 wxString AccountNameFriendly;
762                                 
763                                 int AccountID = 0;
764                                 
765                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
766                                         
767                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
768                                         
769                                         AccountDirCheck.Trim();
770                                         AccountDirCheck.Append(wxT(".carddav"));
771                                         
772                                         if (AccountDirCheck == StringAccountIter->second){
773                                                 
774                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
775                                                 AccountID = i;
776                                                 
777                                         }
778                                         
779                                 }
780                                 
781                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
782                                 
783                                 bool KeepUpdating = TRUE;
784                                 
785                                 while(KeepUpdating == TRUE){
786                                 
787                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
788                                         
789                                         bool ExitLoop = FALSE;
790                                         
791                                         while (ExitLoop == FALSE){
792                                                 
793                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
794                                                         
795                                                         frmMainPtrGet->PauseAllTimers();
796                                                         
797 #if defined(__APPLE__)
798 #elif defined(__WIN32__)
799 #else
800         
801                                                         bool UsingSSLBypass = false;
802                                                         int SSLResult = 0;
803                                                         
804                                                         // Connect again and fetch SSL certificate information.
805                 
806                                                         ConnObjectIter->second->BypassSSLVerification(true);
807                 
808                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
810                                                         ConnObjectIter->second->BypassSSLVerification(false);
812                                                         SSLInvalidCertNotifObjString SSLICNProcData;
813                                                         
814                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
815                                                                 
816                                                         bool *PauseMode = new bool;
817                                                         QRNotif qrn;
818                                                                 
819                                                         *PauseMode = TRUE;
820                                                         qrn.QResponse = &SSLResult;
821                                                         qrn.PausePtr = PauseMode;
822                                                                 
823                                                         SSLICNProcData.CertCollection = certcol;
824                                                         SSLICNProcData.QRNotifData = &qrn;
825                                                         SSLICNProcData.AccountName = AccountNameFriendly;
826                                                                 
827                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
828                                                         event.SetClientData(&SSLICNProcData);
829                                                         wxPostEvent(frmMainPtrGet, event);
830                                                                 
831                                                         while (*PauseMode == TRUE){
832                                                                 //nanosleep(&n1, &n2);
833                                                                 SleepFor(250000000);
834                                                         }
835                                                         
836                                                         // Process the response from the user.
837                                                         
838                                                         if (SSLResult == 1){
839                                                                 
840                                                                 // Accept the Certificate.
842                                                                 UsingSSLBypass = true;
843                                                                 ConnObjectIter->second->BypassSSLVerification(true);
844                 
845                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
846                                                                 WriteServerCertificate(AccountDir, certcol);
847                                                                 
848                                                                 ConnObjectIter->second->BypassSSLVerification(false);
849                                                                 
850                                                         } else if (SSLResult == 2){
851                                                 
852                                                                 // Reject the certificate, abort the task and mark as failed.
854                                                                 iter->second = 2;
855                                                                 break;
856                                                                 
857                                                         }
858                 
859 #endif
860                                                         
861                                                         frmMainPtrGet->ResumeAllTimers();
862                                                         ExitLoop = true;
863                                                         
864                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
865                                                         
866                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
867                                                         
868                                                         if (ConnectResponse == COCONNECT_OK){
869                                                                 
870                                                                 ExitLoop = true;
871                                                                 break;
872                                                                 
873                                                         } else {
874                                                                 
875                                                                 ExitLoop = true;                                                        
876                                                                 iter->second = 2;
877                                                                 break;
878                                                                 
879                                                         }
880                                                         
881                                                 } else if (ConnectResponse == COCONNECT_OK){
882                                                         
883                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
884                                                         
885                                                         ExitLoop = true;
886                                                         break;
887                                                         
888                                                 } else {
889                                                         
890                                                         ExitLoop = true;                                                        
891                                                         iter->second = 2;
892                                                         break;
893                                                         
894                                                 }
895                                         
896                                         }
897                                 
898                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
899                                                 break;
900                                         }
901                         
902 #if defined(__APPLE__)
903                                 
904                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
906 #elif defined(__WIN32__)
908                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
910 #else
911                                 
912                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
913                                 
914 #endif
915                                         
916                                         COServerResponse DeleteContactResponse = ConnObjectIter->second->DeleteContact(ContactFilename.ToStdString());
917                                         
918                                         if (DeleteContactResponse.RequestResult != COREQUEST_OK){
919                                                 iter->second = 2;
920                                                 break;
921                                         }
922                                 
923                                         ETagDBPtr->RemoveETag(ContactFilename);
924                                 
925                                         iter->second = 4;
926                                         break;
927                                 
928                                 }
929                         
930                         } else if (TypeIter->second == 3) {
932                                 wxString AccountNameFriendly;
933         
934                                 int AccountID = 0;
936                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
937         
938                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
939                 
940                                         AccountDirCheck.Trim();
941                                         AccountDirCheck.Append(wxT(".carddav"));
942         
943                                         if (AccountDirCheck == StringAccountIter->second){
944                                         
945                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
946                                                 AccountID = i;
947                 
948                                         }
949         
950                                 }
951                         
952                                 bool KeepUpdating = TRUE;
954                                 while (KeepUpdating == TRUE){
956                                         StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
957                         
958                                         AccountDir = StringAccountIter->second;
960                                         ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
961                                 
962                                         wxArrayString vCardAdd;
963                                         wxArrayString vCardDelete;
964                                         wxArrayString vCardList;
965                                         wxArrayString vCardUpdateLocal;
966                                         wxArrayString vCardUpdateRemote;
967                                         wxArrayString vCardUpdateLog;
968                                         std::map<wxString,wxString> vCardETag;
969                                 
970                                         std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
971                                 
972                                         // Get the list of vCard files locally.
973         
974                                         wxString AccountDirFinal;
975                                         wxString AccountSyncTokenFilename;
976                                         wxString SyncTokenLoad;
977         
978 #if defined(__HAIKU__)
979     
980                                             //preffilename = wxT("noo");
982 #elif defined(__WIN32__)
984                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
985                                         AccountSyncTokenFilename = AccountDirFinal;
986                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
988 #else
990                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
991                                         AccountSyncTokenFilename = AccountDirFinal;
992                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
993         
994 #endif
996                                         // Suppress Error Messages.
997                                 
998                                         wxLogNull PleaseDoNotDisturb;
1000                                         wxFFile SyncLoad;
1001                                         SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
1002                                 
1003                                         if (SyncLoad.IsOpened()){
1004                                 
1005                                                 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1006                                                 SyncLoad.Close();
1007                                 
1008                                         }
1010                                         // Get a list of vCard files from the server.
1012                                         // Get the list of vCard files from the ETagDB.
1013                                 
1014                                         std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1015                                         
1016                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
1017                                         
1018                                         bool ExitLoop = FALSE;
1019                                         
1020                                         while (ExitLoop == FALSE){                                              
1021                                                 
1022                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
1023                                                         
1024                                                         frmMainPtrGet->PauseAllTimers();
1025                                                         
1026 #if defined(__APPLE__)
1027 #elif defined(__WIN32__)
1028 #else
1029         
1030                                                         bool UsingSSLBypass = false;
1031                                                         int SSLResult = 0;
1032                                                         
1033                                                         // Connect again and fetch SSL certificate information.
1034                 
1035                                                         ConnObjectIter->second->BypassSSLVerification(true);
1036                 
1037                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
1039                                                         ConnObjectIter->second->BypassSSLVerification(false);
1041                                                         SSLInvalidCertNotifObjString SSLICNProcData;
1042                                                         
1043                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
1044                                                                 
1045                                                         bool *PauseMode = new bool;
1046                                                         QRNotif qrn;
1047                                                                 
1048                                                         *PauseMode = TRUE;
1049                                                         qrn.QResponse = &SSLResult;
1050                                                         qrn.PausePtr = PauseMode;
1051                                                                 
1052                                                         SSLICNProcData.CertCollection = certcol;
1053                                                         SSLICNProcData.QRNotifData = &qrn;
1054                                                         SSLICNProcData.AccountName = AccountNameFriendly;
1055                                                                 
1056                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
1057                                                         event.SetClientData(&SSLICNProcData);
1058                                                         wxPostEvent(frmMainPtrGet, event);
1059                                                                 
1060                                                         while (*PauseMode == TRUE){
1061                                                                 //nanosleep(&n1, &n2);
1062                                                                 SleepFor(250000000);
1063                                                         }
1064                                                         
1065                                                         // Process the response from the user.
1066                                                         
1067                                                         if (SSLResult == 1){
1068                                                                 
1069                                                                 // Accept the Certificate.
1071                                                                 UsingSSLBypass = true;
1072                                                                 ConnObjectIter->second->BypassSSLVerification(true);
1073                 
1074                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
1075                                                                 WriteServerCertificate(AccountDir, certcol);
1076                                                                 
1077                                                                 ConnObjectIter->second->BypassSSLVerification(false);
1078                                                                 
1079                                                         } else if (SSLResult == 2){
1080                                                 
1081                                                                 // Reject the certificate, abort the task and mark as failed.
1083                                                                 iter->second = 2;
1084                                                                 break;
1085                                                                 
1086                                                         }
1087                 
1088 #endif
1089                                                         
1090                                                         frmMainPtrGet->ResumeAllTimers();
1091                                                         ExitLoop = true;
1092                                                         
1093                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
1094                                                         
1095                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
1096                                                         
1097                                                         if (ConnectResponse == COCONNECT_OK){
1098                                                                 
1099                                                                 ExitLoop = true;
1100                                                                 break;
1101                                                                 
1102                                                         } else {
1103                                                                 
1104                                                                 ExitLoop = true;                                                        
1105                                                                 iter->second = 2;
1106                                                                 break;
1107                                                                 
1108                                                         }
1109                                                         
1110                                                 } else if (ConnectResponse == COCONNECT_OK){
1111                                                         
1112                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
1113                                                         
1114                                                         ExitLoop = true;
1115                                                         break;
1116                                                         
1117                                                 } else {
1118                                                         
1119                                                         ExitLoop = true;                                                        
1120                                                         iter->second = 2;
1121                                                         break;
1122                                                         
1123                                                 }
1124                                         
1125                                         }
1126                                 
1127 #if defined(__APPLE__)
1128                                         
1129                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1131 #elif defined(__WIN32__)
1133                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1135 #else
1136                                         
1137                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
1138                         
1139 #endif
1140                                         
1141                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1142                                                 break;
1143                                         }
1144                                         
1145                                         // Look in directory and see which vCards to add and delete
1146                                 
1147                                         // In short:
1148                                         // vCard exists but not in ETagDB - Add (and upload).
1149                                         // vCard missing but in ETagDB - Delete (from server).
1150                                 
1151                                         // Start by looking for vCards that are not in the ETagDB.
1152                                 
1153                                         wxDir AccDir(AccountDirFinal);
1154                                         wxString AccDirFilename;
1155                                 
1156                                         bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1157                                 
1158                                         COContactList ServerContactList2 = ConnObjectIter->second->GetContactList(SyncTokenLoad.ToStdString());
1160                                         // Process the server data.
1162                                         for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1163                                                 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1164                                                 
1165                                                 if (ContactInfo->Status == COCS_UPDATED){
1166                                                         
1167                                                         vCardDownloadDataFileClass vCardNewData;
1168                                                         vCardNewData.DataType = 0;
1169                                                         vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
1170                                                         
1171                                                 } else if (ContactInfo->Status == COCS_DELETED){
1172                                                         
1173                                                         vCardDelete.Add(ContactInfo->Location, 1);
1174                                                         
1175                                                 }
1176                                                         
1177                                         }
1178                                 
1179                                         // Look for vCards that are missing but in the ETagDB.
1180         
1181                                         for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1182                                                 etagiter != ETagDBData.end(); etagiter++){
1183                                 
1184                                                 // Check if the vCard exists.
1185                                         
1186                                                 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1187                                         
1188                                                         // vCard doesn't exist so mark for deleting.
1189                                         
1190                                                         vCardDelete.Add(etagiter->first, 1);
1191                                         
1192                                                 }
1193                                 
1194                                         }
1196                                         // Compare Server with the ETag DB. Work out which
1197                                         // needs to updated remotely and which needs to be
1198                                         // updated locally.
1200                                         for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
1201                                                 ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
1202                                                 
1203                                                 if (ETagDBData.find(ContactInfo->Location) == ETagDBData.end()){
1204                                                         continue;
1205                                                 }
1207                                                 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(ContactInfo->Location);
1208                                                 
1209                                                 ETagData etd = lociter->second;
1210                                                 
1211                                                 wxString ETagSrv = ContactInfo->Data;
1213                                                 // Check if the local ETag value has 'DELETED' set and skip
1214                                                 // checking this file if it does.
1215                                         
1216                                                 if (etd.ETagValue == "DELETED"){
1217                                                         
1218                                                         continue;
1219                                                         
1220                                                 }
1221                                                 
1222                                                 // Compare local ETag with original local ETag.
1223                                                 // If different, update to server is required.
1224                                 
1225                                                 if (etd.ETagValue != etd.ETagOrigValue){
1226                                 
1227                                                         // Check if local original ETag is different from server ETag.
1228                                                         // If it is then throw up a conflict resolution dialog.
1229                                 
1230                                                         if (etd.ETagOrigValue != ETagSrv){
1231                                         
1232                                                                 vCard34Conv vCard34Obj;
1233                                                 
1234                                                                 wxString FullFilename;
1235                                                                 vCard ClientData;
1236                                                                 vCard ConvertedV4Data;
1237                                         
1238                                                                 std::string ServerContactDataString;
1239                                                                 wxString ServerContactData;
1240                                                                 
1241                                                                 // Conflict. Bring up conflict resolution dialog.
1242                                                         
1243                                                                 // Get the server contact data for comparison.
1244                                                         
1245                                                                 ConnObjectIter->second->GetContact(ContactInfo->Location, &ServerContactDataString);
1246                                                                 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1247                                                         
1248                                                                 FullFilename = CreateFilenamePath(AccountDirFinal, ContactInfo->Location);
1249                                                         
1250                                                                 // Convert it to v4.
1251                                         
1252                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1253                                         
1254                                                                 vCardConflictObj vCardProcData;
1255                                         
1256                                                                 vCardProcData.vCardLocalData = &ClientData;
1257                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1258                                                         
1259                                                                 // Load the client data from the filename given.
1260                                                         
1261                                                                 ClientData.LoadFile(FullFilename);
1262                                                         
1263                                                                 // Show dialog.
1264                                         
1265                                                                 bool *PauseMode = new bool;
1266                                                                 int ConflictResult;
1267                                                                 QRNotif qrn;
1268                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1270                                                                 *PauseMode = TRUE;
1271                                                                 qrn.QResponse = &ConflictResult;
1272                                                                 qrn.PausePtr = PauseMode;
1273                                                 
1274                                                                 vCardProcData.QRNotifData = &qrn;
1275                                         
1276                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1277                                                                 event.SetClientData(&vCardProcData);
1278                                                                 wxPostEvent(frmMainPtrGet, event);
1279                                                 
1280                                                                 while (*PauseMode == TRUE){
1281                                                                         //nanosleep(&n1, &n2);
1282                                                                         SleepFor(250000000);
1283                                                                 }
1284                                         
1285                                                                 delete PauseMode;
1286                                                                 PauseMode = NULL;
1287                                                         
1288                                                                 // If replacing local version, store copy for now.
1289                                                                 // Otherwise upload to server.
1290                                         
1291                                                                 if (ConflictResult == 0){
1292                                         
1293                                                                         // Decide Later.
1294                                         
1295                                                                         continue;
1296                                         
1297                                                                 } else if (ConflictResult == 1){
1298                                         
1299                                                                         // Decided to use client version.
1300                                         
1301                                                                         vCardUpdateLocal.Remove(ContactInfo->Location);
1302                                                                         vCardUpdateRemote.Add(ContactInfo->Location, 1);                                                                
1303                                         
1304                                                                 } else if (ConflictResult == 2){
1305                                         
1306                                                                         // Decided to use server version.
1307                                                                         // Store the converted downloaded copy for
1308                                                                         // processing later.
1310                                                                         //vCardUpdateLocal.Add(srviter->first, 1);
1311                                                                 
1312                                                                         vCardDownloadDataFileClass vCardNewData;
1313                                                                         vCardNewData.DataType = 1;
1314                                                                         vCardNewData.FileData = ConvertedV4Data.WriteString();
1316                                                                         ConvertedV4Data.WriteFile(FullFilename);
1317                                                                 
1318                                                                         vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));  
1319                                                                 
1320                                                                 
1321                                                                 
1322                                                                 }
1323                                         
1324                                                         } else {
1325                                         
1326                                                                 // Send vCard to the server.
1327                                                 
1328                                                                 vCardUpdateRemote.Add(ContactInfo->Location, 1);
1329                                         
1330                                                         }
1331                                 
1332                                                 } else {
1333                                 
1334                                                         // Check if local ETag is different from server ETag.
1335                                                         // If different, obtain the vCard from the server.
1336                                         
1337                                                         if (etd.ETagOrigValue != ETagSrv){
1338                                         
1339                                                                 vCardUpdateLocal.Add(ContactInfo->Location, 1);
1340                                         
1341                                                         }
1342                                 
1343                                                 }
1344                                                 
1345                                         }
1346                                 
1347                                         // Process the vCards that need to be downloaded and added/overwritten.
1348                                 
1349                                         wxString vCardFilenameFinal;
1350                                         wxString vCardOutputData;
1351                                         wxString vCardInputData;
1352                                         wxString ETagFileData;
1353                                         wxFFile vCardFile;
1354                                 
1355                                         for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1356                                                 additer != vCardDownloadData.end(); additer++){
1357                                         
1358                                                 vCardFilenameFinal.Clear();
1359                                                 vCardInputData.Clear();
1360                                                 vCardOutputData.Clear();
1361                                                 ETagFileData.Clear();
1362                                         
1363                                                 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1364                                         
1365                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1366                                         
1367                                                 if (additer->second.DataType == 0){
1368                                         
1369                                                         vCard ConvertedV4Data;
1370                                         
1371                                                         // Grab the file from the server and write the contact out.
1372                                         
1373                                                         vCard34Conv vCard34Obj;
1374                                                         
1375                                                         wxString ServerContactData;
1376                                                         std::string ServerContactDataString;
1377                                                                 
1378                                                         // Conflict. Bring up conflict resolution dialog.
1379                                                         
1380                                                         // Get the server contact data for comparison.
1381                                                         
1382                                                         ConnObjectIter->second->GetContact(additer->first.ToStdString(), &ServerContactDataString);
1383                                                         vCardInputData = wxString::FromUTF8(ServerContactDataString.c_str());
1384                                                 
1385                                                         vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1386                                                 
1387                                                         ConvertedV4Data.WriteFile(vCardFilenameFinal);
1388                                                 
1389                                                         // Get the server ETag.
1390                                                 
1391                                                         wxString ServerETag;
1392                                                         
1393                                                         COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1394                                                         
1395                                                         if (ServerEntityTag.RequestResult != COREQUEST_OK){
1396                                                                 iter->second = 2;
1397                                                                 break;
1398                                                         }
1399                                                         
1400                                                         ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1402                                                         // Add to the ETag Database.
1403                                                 
1404                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1405                                                 
1406                                                 } else if (additer->second.DataType == 1){
1407                                         
1408                                                         // Write out the contact to the account directory.
1409                                         
1410                                                         vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1411                                                         vCardOutputData = additer->second.FileData;
1412                                                 
1413                                                         vCardFile.Open(vCardFilenameFinal, wxT("w"));
1414                                 
1415                                                         if (vCardFile.IsOpened()){
1416                                 
1417                                                                 vCardFile.Write(vCardOutputData, wxConvAuto());
1418                                                                 vCardFile.Close();
1419                                 
1420                                                         }
1421                                                 
1422                                                         // Update the ETagDB.
1424                                                         wxString ServerETag;
1425                                                         
1426                                                         COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString());
1427                                                         
1428                                                         if (ServerEntityTag.RequestResult != COREQUEST_OK){
1429                                                                 iter->second = 2;
1430                                                                 break;
1431                                                         }
1432                                                         
1433                                                         ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1434                                                 
1435                                                         // Add to the ETag Database.
1436                                                 
1437                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1438                                                                                         
1439                                                 }
1440                                         }
1441                                         
1442                                         // Check if any errors occured before continuing.
1443                                         
1444                                         if (iter->second != 1){
1445                                                 break;
1446                                         }
1447         
1448                                         // Look for vCard files which aren't in the ETagDB.
1449         
1450                                         while(ContinueProcess){
1451                                 
1452                                                 // Check and make sure that the filename ends in .vcf/.vcard
1453                                                 // Skip any file that beings with a dot.
1454                                         
1455                                                 if (AccDirFilename.Left(1) == wxT(".")){
1456                                         
1457                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
1458                                                         continue;
1459                                         
1460                                                 }
1461                                         
1462                                                 if (AccDirFilename.Right(4) != wxT(".vcf") && 
1463                                                 AccDirFilename.Right(6) != wxT(".vcard")){
1464                                         
1465                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
1466                                                         continue;
1467                                         
1468                                                 }
1469                                 
1470                                                 // Look in the ETagDB for the file.
1471                                         
1472                                                 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
1473                                         
1474                                                 if (ETagExists == FALSE){
1475                                         
1476                                                         // Add the vCard to the list to be added.
1477                                                 
1478                                                         vCardAdd.Add(AccDirFilename, 1);
1479                                         
1480                                                 }
1481                                         
1482                                                 ContinueProcess = AccDir.GetNext(&AccDirFilename);
1483                                 
1484                                         }
1485                                 
1486                                         // Process the vCards to add/update to the server.
1487                                 
1488                                         for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
1490                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1491                                                 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
1492                                                 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
1493                                                 
1494                                                 ContactFilename = vCardAdd[vi];
1495                                                 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1497                                                 ContactFilename.Trim();
1498                         
1499                                                 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
1500                         
1501                                                         // Compare the ETag with the Server ETag.
1502                                                         
1503                                                         COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1504                                                         
1505                                                         if (ServerEntityTag.RequestResult != COREQUEST_OK){
1506                                                                 iter->second = 2;
1507                                                                 break;
1508                                                         }
1509                                                         
1510                                                         // TODO: Continue from here!
1511                                                         
1512                                                         ETagServer = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str());
1513                                 
1514                                                         if (ETagOriginal != ETagServer){
1515                                 
1516                                                                 // Server ETag is different from original ETag.
1517                                                                 // This is a conflict which the user will now
1518                                                                 // need to resolve.
1519                                         
1520                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1521                                         
1522                                                                 vCard34Conv vCard34Obj;
1523                                                 
1524                                                                 wxString ServerContactData;
1525                                                                 std::string ServerContactDataString;
1526                                                                 vCard ClientData;
1527                                                                 vCard ConvertedV4Data;
1528                                         
1529                                                                 // Load the client data from the filename given.
1530                                                                 
1531                                                                 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1532                                                 
1533                                                                 if (GetContactResponse.RequestResult != COREQUEST_OK){
1534                                                                         iter->second = 2;
1535                                                                         break;
1536                                                                 }
1537                                                                 
1538                                                                 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1539                                                 
1540                                                                 // Process v3 version into v4 version.
1541                                                 
1542                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1543                                         
1544                                                                 vCardConflictObj vCardProcData;
1545                                         
1546                                                                 vCardProcData.vCardLocalData = &ClientData;
1547                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1548                                                                 ClientData.LoadFile(FullFilename);
1550                                                                 // Setup Conflict Resolution Dialog.
1551                                         
1552                                                                 // Fetch Data from Server and convert.
1553                                         
1554                                                                 bool *PauseMode = new bool;
1555                                                                 int ConflictResult;
1556                                                                 QRNotif qrn;
1558                                                                 *PauseMode = TRUE;                                              
1559                                                                 qrn.QResponse = &ConflictResult;
1560                                                                 qrn.PausePtr = PauseMode;
1561                                                 
1562                                                                 vCardProcData.QRNotifData = &qrn;
1563                                         
1564                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1565                                                                 event.SetClientData(&vCardProcData);
1566                                                                 wxPostEvent(frmMainPtrGet, event);
1567                                                 
1568                                                                 while (*PauseMode == TRUE){
1569                                                                         //nanosleep(&n1, &n2);
1570                                                                         SleepFor(250000000);
1571                                                                 }
1572                                         
1573                                                                 delete PauseMode;
1574                                                                 PauseMode = NULL;
1575                                         
1576                                                                 if (ConflictResult == 0){
1577                                         
1578                                                                         // Decide Later.
1579                                         
1580                                                                         iter->second = 4;
1581                                                                         continue;
1582                                         
1583                                                                 } else if (ConflictResult == 1){
1584                                         
1585                                                                         // Decided to use client version.
1586                                         
1587                                                                         COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1588                                                 
1589                                                                         if (EditContactResponse.RequestResult != COREQUEST_OK){
1590                                                                                 iter->second = 2;
1591                                                                                 break;
1592                                                                         }
1593                                                                         
1594                                                                         iter->second = 4;
1595                                         
1596                                                                 } else if (ConflictResult == 2){
1597                                         
1598                                                                         // Decided to use server version.
1599                                                 
1600                                                                         // Download server version.
1601                                                                 
1602                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1603                                                 
1604                                                                         iter->second = 4;
1605                                         
1606                                                                 }
1607                                 
1608                                                         } else {
1609                                 
1610                                                                 // Setup the filename for the contact being added.
1611                                                         
1612                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1613                                                                 wxString wxSCardData;
1614                                                                 wxString TaskData;
1615                                                         
1616                                                                 // Load the data from the file.
1617                                                         
1618                                                                 wxFFile wxFCard;
1619                                                                 wxFCard.Open(wxSFilename, wxT("r"));
1620                                 
1621                                                                 if (wxFCard.IsOpened()){
1622                                 
1623                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1624                                                                         wxFCard.Close();
1625                                 
1626                                                                 }
1627                                                         
1628                                                                 // Convert the data to v3.
1629                                                         
1630                                                                 vCard34Conv vCard34Obj;
1631                                                         
1632                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1634                                                                 // Upload the data to the server.
1635                                                                 
1636                                                                 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1637                                                         
1638                                                                 if (AddContactResponse.RequestResult != COREQUEST_OK){
1639                                                                         iter->second = 2;
1640                                                                         break;
1641                                                                 }
1642                                                                 
1643                                                                 // Get the Server ETag and put it in the ETag database.
1645                                                                 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1646                                                                 
1647                                                                 if (EntityTagResponse.RequestResult != COREQUEST_OK){
1648                                                                         iter->second = 2;
1649                                                                         break;
1650                                                                 }
1651                                                                 
1652                                                                 ETagServer = wxString::FromUTF8(EntityTagResponse.EntityTag.c_str());
1653                                 
1654                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1655                                 
1656                                                         }
1657                         
1658                                                 } else {
1659                         
1660                                                         if (ETagOriginal != ETagServer){
1661                                 
1662                                                                 // Server ETag is different from original ETag.
1663                                                                 // This is a conflict which the user will now
1664                                                                 // need to resolve.
1665                                         
1666                                                                 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
1667                                         
1668                                                                 vCard34Conv vCard34Obj;
1669                                                 
1670                                                                 std::string ServerContactDataString;
1671                                                                 wxString ServerContactData;
1672                                                                 vCard ClientData;
1673                                                                 vCard ConvertedV4Data;
1674                                         
1675                                                                 // Load the client data from the filename given.
1676                                         
1677                                                                 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString);
1678                                                 
1679                                                                 if (GetContactResponse.RequestResult != COREQUEST_OK){
1680                                                                         iter->second = 2;
1681                                                                         break;
1682                                                                 }
1683                                                                 
1684                                                                 ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str());
1685                                                                 
1686                                                                 ClientData.LoadFile(FullFilename);
1687                                                 
1688                                                                 // Process v3 version into v4 version.
1689                                                 
1690                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1691                                         
1692                                                                 vCardConflictObj vCardProcData;
1693                                         
1694                                                                 vCardProcData.vCardLocalData = &ClientData;
1695                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1696                                         
1697                                                                 bool *PauseMode = new bool;
1698                                                                 int ConflictResult;
1699                                                                 QRNotif qrn;
1701                                                                 *PauseMode = TRUE;                                              
1702                                                                 qrn.QResponse = &ConflictResult;
1703                                                                 qrn.PausePtr = PauseMode;
1704                                                 
1705                                                                 vCardProcData.QRNotifData = &qrn;
1706                                         
1707                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1708                                                                 event.SetClientData(&vCardProcData);
1709                                                                 wxPostEvent(frmMainPtrGet, event);
1711                                                                 while (*PauseMode == TRUE){
1712                                                                         SleepFor(250000000);
1713                                                                 }
1714                                         
1715                                                                 delete PauseMode;
1716                                                                 PauseMode = NULL;
1717                                         
1718                                                                 if (ConflictResult == 0){
1719                                         
1720                                                                         // Decide Later.
1721                                         
1722                                                                         iter->second = 4;
1723                                                                         continue;
1724                                         
1725                                                                 } else if (ConflictResult == 1){
1726                                         
1727                                                                         // Decided to use client version.
1728                                                                 
1729                                                                         COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
1731                                                                         if (EditContactResponse.RequestResult != COREQUEST_OK){
1732                                                                                 iter->second = 2;
1733                                                                                 break;
1734                                                                         }
1735                                                                         
1736                                                                         iter->second = 4;
1737                                         
1738                                                                 } else if (ConflictResult == 2){
1739                                         
1740                                                                         // Decided to use server version.
1741                                                 
1742                                                                         // Write server version to file.
1743                                                                 
1744                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
1745                                                 
1746                                                                         iter->second = 4;
1747                                         
1748                                                                 }
1749                                 
1750                                                         } else {
1751                                 
1752                                                                 // Setup the filename for the contact being added.
1753                                                         
1754                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
1755                                                                 wxString wxSCardData;
1756                                                                 wxString TaskData;
1757                                                         
1758                                                                 // Load the data from the file.
1759                                                         
1760                                                                 wxFFile wxFCard;
1761                                                                 wxFCard.Open(wxSFilename, wxT("r"));
1762                                 
1763                                                                 if (wxFCard.IsOpened()){
1764                                 
1765                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
1766                                                                         wxFCard.Close();
1767                                 
1768                                                                 }
1769                                                         
1770                                                                 // Convert the data to v3.
1771                                                         
1772                                                                 vCard34Conv vCard34Obj;
1773                                                         
1774                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
1776                                                                 // Upload the data to the server.
1777                                                                 
1778                                                                 COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), TaskData.ToStdString());
1780                                                                 if (AddContactResponse.RequestResult != COREQUEST_OK){
1781                                                                         iter->second = 2;
1782                                                                         break;
1783                                                                 }
1784                                                                 
1785                                                                 // Get the Server ETag and put it in the ETag database.
1786                                                         
1787                                                                 COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString());
1788                                 
1789                                                                 if (EntityTagResponse.RequestResult != COREQUEST_OK){
1790                                                                         iter->second = 2;
1791                                                                         break;
1792                                                                 }
1793                                                                 
1794                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
1795                                 
1796                                                         }
1797                                         
1798                                                 }
1800                                         }                       
1801                                 
1802                                         if (iter->second != 1){
1803                                                 break;
1804                                         }
1805                                         
1806                                         // Process the vCards to delete locally.
1807                                 
1808                                         for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
1810                                                 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
1812                                                 } else {
1813                                         
1814                                                         ETagDBPtr->RemoveETag(vCardDelete[vi]);
1815                                         
1816                                                 }
1818                                         }
1819                                 
1820                                         // Process the vCards to delete from the server.
1821                                 
1822                                         std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
1823                                         std::list<wxString> DeleteList;
1824                                 
1825                                         for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
1826                                                 deliter != ETagFilenameMap->end(); deliter++){
1827                                 
1828                                                 // Look through the ETagDB and find contacts which are marked as DELETED.
1829                                         
1830                                                 if (deliter->second == wxT("DELETED")){
1832                                                         ConnObjectIter->second->DeleteContact(deliter->first.ToStdString());
1833                                         
1834                                                         // Delete the ETag as the file has now been deleted.
1835                                         
1836                                                         DeleteList.push_back(deliter->first);
1837                                         
1838                                                 }
1839                                 
1840                                         }
1841                                         
1842                                         for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
1843                                                 removeetagiter != DeleteList.end(); removeetagiter++){
1844                                         
1845                                                 ETagDBPtr->RemoveETag(*removeetagiter);
1846                                                 
1847                                         }
1848                                 
1849                                         // Write out the update server sync token.
1851                                         wxString ServerSyncToken = wxString::FromUTF8(ServerContactList2.SyncToken.c_str());
1852                                 
1853                                         ServerSyncToken.Trim();
1854                                 
1855                                         if (!ServerSyncToken.IsEmpty()){
1856                                 
1857                                                 wxFFile SyncWrite;
1858                                                 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
1859                                 
1860                                                 if (SyncWrite.IsOpened()){
1861                                 
1862                                                         SyncWrite.Write(ServerSyncToken, wxConvAuto());
1863                                                         SyncWrite.Close();
1864                                 
1865                                                 }
1866                                 
1867                                         }
1868                                 
1869                                         // Check for another sync token. If there is another 
1870                                         // sync token then repeat this. If token matches then stop processing.
1871                                 
1872                                         if (SyncTokenLoad == ServerSyncToken){
1873                                         
1874                                                 KeepUpdating = FALSE;
1875                                         
1876                                         }
1877                                         
1878                                 }
1879                                 
1880                                 // Mark as completed.
1881                         
1882                                 wxString AccountNameFinal;
1883                                 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
1884                                 AccountNameFinal.Append(wxT(".carddav"));
1885                                 
1886                                 wxCommandEvent reloadevent(RELOADCONTACTLIST);
1887                                 reloadevent.SetString(AccountNameFinal);
1888                                 wxPostEvent(this->GetParent(), reloadevent);
1889                                 
1890                                 iter->second = 4;
1891                                 continue;
1892                         
1893                         } else {
1894                         
1895                                 // Update the data to the server.
1897                                 iter->second = 4;
1898                                 continue;
1899                         
1900                         }
1902                         while (iter->second == 1){
1904                                 SleepFor(125000000);
1905         
1906                         }
1907                         
1908                         break;
1909                         
1910                 }
1912         }
1913         
1914         if (TasksFoundProc == FALSE){
1915         
1916                 TasksActive = FALSE;
1917                 ProcessTasksData = FALSE;
1918         
1919         } else {
1921                 wxCommandEvent eventp(ACTMGR_STARTTIMER);
1922                 wxPostEvent(this, eventp);
1923         
1924         }
1925         
1926         wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
1927         wxPostEvent(this, event);
1931 void frmActivityMgr::ProcessTasks()
1933         
1934         std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
1935         ProcessThread.detach();
1939 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
1942         ETagTmrPtr = ETagTmrPtrInc;
1943         
1944         frmMainPtr = frmMainPtrInc;
1948 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
1950         QRNotif *qrn = (QRNotif *)event.GetClientData(); 
1951         
1952         int *QRes = qrn->QResponse;
1954         *qrn->PausePtr = FALSE;
1956         *QRes = event.GetInt();
1957         
1960 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
1962         wxCommandEvent connevent(CONNSTAT_UPDATE);
1963         
1964         if (ApplicationSleepMode == FALSE){
1965         
1966                 connevent.SetInt(1);
1967                 ApplicationSleepMode = TRUE;
1968                 mnuSleepMode->Check(true);
1969         
1970         } else {
1971         
1972                 connevent.SetInt(0);
1973                 ApplicationSleepMode = FALSE;
1974                 mnuSleepMode->Check(false);
1975                 
1976                 wxCommandEvent event(ACTMGR_STARTTIMER);
1977                 wxPostEvent(this, event);
1979                 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
1980                 wxPostEvent(this, eventp);
1981         
1982         }
1984         wxPostEvent(GetParent(), connevent);
1988 void frmActivityMgr::SleepMode( wxCommandEvent &event ){
1989         
1990         wxCommandEvent connevent(ACTMGR_TOGGLECONN);
1991         
1992         wxPostEvent(this, connevent);
1993         
1996 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
1998         wxString ServerCertFinal;
2000         // Get the Cert section of the certificate and write it to the file.
2002         ServerCertFinal = GetAccountDir(AccountName, TRUE);
2004         wxFile CertFile;
2005         
2006         std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2007         std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
2008         
2009         CertFile.Open(ServerCertFinal, wxFile::write);  
2010         
2011         CertFile.Write(SSLDataIter->second, wxConvUTF8);
2012         CertFile.Close();
2016 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollectionString SSLCertInc){
2018         wxString ServerCertFinal;
2020         // Get the Cert section of the certificate and write it to the file.
2022         ServerCertFinal = GetAccountDir(AccountName, TRUE);
2024         wxFile CertFile;
2025         
2026         std::map<int, SSLCertDataString>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2027         std::multimap<string,string>::iterator SSLDataIter = SSLCDIter->second.CertData.find("Cert");
2028         
2029         CertFile.Open(ServerCertFinal, wxFile::write);  
2030         
2031         CertFile.Write(SSLDataIter->second, wxConvUTF8);
2032         CertFile.Close();
2036 void frmActivityMgr::StartTimer(wxCommandEvent& event){
2038         ActListProcTimer.Start(1000, FALSE);
2042 void frmActivityMgr::StopTimer(wxCommandEvent& event){
2044         ActListProcTimer.Stop();
2048 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
2050         ActProcessTimer.Start(1000, FALSE);
2054 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
2056         ActProcessTimer.Stop();
2060 void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
2061         
2062         AnimationTimer.StartAnimation();
2063         
2066 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2068         ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2069         
2070         if (actmgrudata != NULL){
2071         
2072                 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
2073         
2074                 delete actmgrudata;
2075                 actmgrudata = NULL;
2076         
2077         }
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy