Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Merge commits from upstream
[xestiaab/.git] / source / actmgr / frmActivityMgr.cpp
index 006c668..63755f8 100644 (file)
@@ -45,6 +45,7 @@ DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
 DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
 DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
 DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
+DEFINE_EVENT_TYPE(ACTMGR_STARTANIMATIONTIMER);
 
 BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
   EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
@@ -54,6 +55,7 @@ BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
   EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
   EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
   EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
+  EVT_COMMAND(wxID_ANY, ACTMGR_STARTANIMATIONTIMER, frmActivityMgr::StartAnimationTimer)
 END_EVENT_TABLE()
 
 frmActivityMgr::frmActivityMgr( wxWindow* parent )
@@ -194,6 +196,12 @@ void frmActivityMgr::ProcessTasksThread()
        
        }
        
+       if (ApplicationSleepMode == TRUE){
+               
+               return;
+               
+       }
+       
        std::map<int,int>::iterator TypeIter;
        std::map<int,wxString>::iterator StringIter;
        std::map<int,wxString>::iterator StringDataIter;
@@ -220,6 +228,12 @@ void frmActivityMgr::ProcessTasksThread()
                        continue;
                }
                
+               wxCommandEvent StartAnimationEvent(ACTMGR_STARTANIMATIONTIMER);
+               
+               wxPostEvent(this, StartAnimationEvent);
+               
+               // Start the animation timer if it hasn't started.
+               
                CardDAVIter = ActivityListConn.find(iter->first);
                TypeIter = ActivityListType.find(iter->first);
                StringETagIter = ActivityListETag.find(iter->first);
@@ -323,13 +337,10 @@ void frmActivityMgr::ProcessTasksThread()
                                        
                                        while (ExitLoop == FALSE){
                                                
-                                               ConnHandle.SetUploadMode(TRUE);
-                                               ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
-                                               ConnHandle.SetEditMode(EditMode);
-                                               ConnHandle.ProcessData();
-                                               
-                                               int ErrorCode = ConnHandle.GetResultCode();
+                                               // Verify that we have a trusted SSL connection first.
                                                
+                                               int ErrorCode = ConnHandle.SSLVerifyTest();
+
                                                if (ErrorCode != CURLE_OK){
                                                        
                                                        if (ErrorCode == CURLE_SSL_CACERT ||
@@ -363,14 +374,37 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        
                                                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
                                                                        
+
+                                                               }
+
+#elif defined(__WIN32__)
+
+                                                               BOOL ModifiedCertificateData;
+                                                               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
+
+                                                               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
+                                                                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
                                                                }
+
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+                                                               }
+
 #else
                                                                
                                                                // Setup the data to be sent in the wxPostEvent command.
                                                                
                                                                SSLInvalidCertNotifObj SSLICNProcData;
                                                                
-                                                               SSLCertCollection certcol = ConnHandle.GetCertificateData();
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
                                                                
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
@@ -448,13 +482,31 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                        
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                                       
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                        
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
                                        
 #endif
                                        
+                                       ConnHandle.SetUploadMode(TRUE);
+                                       ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
+                                       ConnHandle.SetEditMode(EditMode);
+                                       ConnHandle.ProcessData();
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+
+                                               iter->second = 4;
+                                               break;
+
+                                       }
+
                                        // Add contact to the ETag DB.
                                        
                                        ConnHandle.GetServerETagValueThread();
@@ -462,7 +514,6 @@ void frmActivityMgr::ProcessTasksThread()
                                        ETagDBPtr->AddETag(ContactFilename, ETagServer, ETagServer);
                                        
                                        iter->second = 4;
-                                       CardDAVIter->second = NULL;
                                        break;
                                        
                                }
@@ -512,14 +563,8 @@ void frmActivityMgr::ProcessTasksThread()
                                        bool ExitLoop = FALSE;
                                        
                                        while (ExitLoop == FALSE){
-                                               
-                                               ConnHandle.SetUploadMode(TRUE);
-                                               ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
-                                               ConnHandle.SetEditMode(EditMode);
-                                               ConnHandle.GetServerETagValueThread();
-                                               ETagServer = ConnHandle.ETagValueResult();
-                                               
-                                               int ErrorCode = ConnHandle.GetResultCode();
+                                                
+                                               int ErrorCode = ConnHandle.SSLVerifyTest();
                                                
                                                if (ErrorCode != CURLE_OK){
                                                        
@@ -555,13 +600,35 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
                                                                        
                                                                }
+
+#elif defined(__WIN32__)
+
+                                                               BOOL ModifiedCertificateData;
+                                                               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
+
+                                                               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
+                                                                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                                                               }
+
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+                                                               }
+
 #else
                                                                
                                                                // Setup the data to be sent in the wxPostEvent command.
                                                                
                                                                SSLInvalidCertNotifObj SSLICNProcData;
                                                                
-                                                               SSLCertCollection certcol = ConnHandle.GetCertificateData();
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
                                                                
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
@@ -590,14 +657,14 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        // Accept the certificate. Write the certificate into the account
                                                                        // directory (as server.crt) - will overwrite old certificate.
                                                                        
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
-                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
+                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
                                                                        
                                                                } else if (SSLResult == 2){
                                                                        
                                                                        // Reject the certificate, abort the task and mark as failed.
                                                                        
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
                                                                        iter->second = 2;
                                                                        break;
                                                                        
@@ -632,13 +699,30 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                        
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                                       
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                        
-                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
                                        
 #endif
                                        
+                                       ConnHandle.SetUploadMode(TRUE);
+                                       ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
+                                       ConnHandle.SetEditMode(EditMode);
+                                       ConnHandle.GetServerETagValueThread();
+                                       ETagServer = ConnHandle.ETagValueResult();
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
+
                                        // Compare the ETag with the Server ETag.
                                        
                                        if (ETagOriginal != ETagServer){
@@ -784,15 +868,8 @@ void frmActivityMgr::ProcessTasksThread()
                                        
                                        while (ExitLoop == FALSE){
                                                
-                                               ConnHandle.SetUploadMode(FALSE);
-                                               ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
-                                               ConnHandle.ProcessData();
-                                               SSLCertCollection certcol = ConnHandle.GetCertificateData();
-                                               
-                                               // Check if any errors have occured whilst getting the data.
-                                               
-                                               int ErrorCode = ConnHandle.GetResultCode();
-                                               
+                                               int ErrorCode = ConnHandle.SSLVerifyTest();
+
                                                if (ErrorCode != CURLE_OK){
                                                        
                                                        if (ErrorCode == CURLE_SSL_CACERT ||
@@ -827,12 +904,36 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
                                                                        
                                                                }
+
+#elif defined(__WIN32__)
+
+                                                               BOOL ModifiedCertificateData;
+                                                               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
+
+                                                               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
+                                                                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                                                               }
+
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+                                                               }
+
 #else
                                                                
                                                                // Setup the data to be sent in the wxPostEvent command.
                                                                
                                                                SSLInvalidCertNotifObj SSLICNProcData;
                                                                
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
+                                                               
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
                                                                
@@ -867,14 +968,14 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        // Accept the certificate. Write the certificate into the account
                                                                        // directory (as server.crt) - will overwrite old certificate.
                                                                
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
-                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
+                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
                                                                
                                                                } else if (SSLResult == 2){
                                                                
                                                                // Reject the certificate, abort the task and mark as failed.
                                                                
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
                                                                        iter->second = 2;
                                                                        break;
                                                                
@@ -909,13 +1010,31 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                               
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                
-                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
                                
 #endif
 
+                                       ConnHandle.SetUploadMode(FALSE);
+                                       ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
+                                       ConnHandle.ProcessData();
+                                       
+                                       SSLCertCollection certcol = ConnHandle.GetCertificateData();
+
+                                       // Check if any errors have occured whilst getting the data.
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
                                
                                        ETagDBPtr->RemoveETag(ContactFilename);
                                
@@ -1068,12 +1187,25 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
                                                                }
 
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+                                                               }
 #else
                                 
                                                                // Setup the data to be sent in the wxPostEvent command.
 
                                                                SSLInvalidCertNotifObj SSLICNProcData;
 
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
+
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
 
@@ -1108,14 +1240,14 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        // Accept the certificate. Write the certificate into the account
                                                                        // directory (as server.crt) - will overwrite old certificate.
 
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
-                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
+                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
                                                                
                                                                } else if (SSLResult == 2){
                                                                
                                                                        // Reject the certificate, abort the task and mark as failed.
 
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
                                                                        iter->second = 2;
                                                                        break;
                                                                
@@ -1150,10 +1282,14 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                         
                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                                        
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                         
-                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
                        
 #endif
                                         
@@ -1171,6 +1307,16 @@ void frmActivityMgr::ProcessTasksThread()
                                        bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
                                
                                        ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+
+                                               iter->second = 4;
+                                               break;
+
+                                       }
+
                                        SSLCertCollection certcol = ConnHandle.GetCertificateData();
 
                                        // Create a pointer for the std::map<wxString,FileSyncData>.
@@ -1977,7 +2123,7 @@ void frmActivityMgr::ProcessTasksThread()
                //ActListProcTimer.Start();
        
        }
-
+       
        wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
        wxPostEvent(this, event);
 
@@ -1987,7 +2133,7 @@ void frmActivityMgr::ProcessTasksThread()
 
 void frmActivityMgr::ProcessTasks()
 {
-
+       
        std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
        ProcessThread.detach();
 
@@ -2018,15 +2164,23 @@ void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
 
        wxCommandEvent connevent(CONNSTAT_UPDATE);
        
-       if (SleepMode == FALSE){
+       if (ApplicationSleepMode == FALSE){
        
                connevent.SetInt(1);
-               SleepMode = TRUE;
+               ApplicationSleepMode = TRUE;
+               mnuSleepMode->Check(true);
        
        } else {
        
                connevent.SetInt(0);
-               SleepMode = FALSE;
+               ApplicationSleepMode = FALSE;
+               mnuSleepMode->Check(false);
+               
+               wxCommandEvent event(ACTMGR_STARTTIMER);
+               wxPostEvent(this, event);
+
+               wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
+               wxPostEvent(this, eventp);
        
        }
 
@@ -2034,6 +2188,14 @@ void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
 
 }
 
+void frmActivityMgr::SleepMode( wxCommandEvent &event ){
+       
+       wxCommandEvent connevent(ACTMGR_TOGGLECONN);
+       
+       wxPostEvent(this, connevent);
+       
+}
+
 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
 
        wxString ServerCertFinal;
@@ -2078,6 +2240,12 @@ void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
 
 }
 
+void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
+       
+       AnimationTimer.StartAnimation();
+       
+}
+
 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
 
        ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
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