Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Merge branch 'master' of ssh://gelforn.xestia.co.uk/scmrepos/xestiaab
[xestiaab/.git] / source / frmMain.cpp
index 5c3695a..99784a6 100644 (file)
@@ -90,6 +90,9 @@ DEFINE_EVENT_TYPE(SYNCACCOUNT);
 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
+#if defined(__APPLE__)
+DEFINE_EVENT_TYPE(INVALIDSSLTRUST);
+#endif
 
 // Setup the event table using the event types.
 
@@ -119,6 +122,9 @@ EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
+#if defined(__APPLE__)
+EVT_COMMAND(wxID_ANY, INVALIDSSLTRUST, frmMain::DisplayTrustPanel)
+#endif
 END_EVENT_TABLE()
 
 frmMain::frmMain( wxWindow* parent )
@@ -132,6 +138,7 @@ frmMainADT( parent )
        wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
        wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
        wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
+       wxMemoryInputStream estream(icons_accunsupported_png, sizeof(icons_accunsupported_png));
     
        wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
        wxBitmap AccInet(icons_accinet_png, -1);
@@ -147,16 +154,22 @@ frmMainADT( parent )
        wxBitmap AccGrp(icons_accgroup_png, -1);
        wxIcon wxIAccGrp;
        wxIAccGrp.CopyFromBitmap(AccGrp);
-    
+
        wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
        wxBitmap AccNone(icons_accnone_png, -1);
        wxIcon wxIAccNone;
        wxIAccNone.CopyFromBitmap(AccNone);
+       
+       wxImage icons_accunsupported_png(estream, wxBITMAP_TYPE_PNG);
+       wxBitmap AccUnsupported(icons_accunsupported_png, -1);
+       wxIcon wxIAccUnsupported;
+       wxIAccUnsupported.CopyFromBitmap(AccUnsupported);
     
        AccountID = AccImgList->Add(wxIAccNIcon);
        AccountNetID = AccImgList->Add(wxIAccInet);
        AccountGrpID = AccImgList->Add(wxIAccGrp);
        AccountNoneID = AccImgList->Add(wxIAccNone);
+       AccountUnsupportedID = AccImgList->Add(wxIAccUnsupported);
     
        bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
     
@@ -239,7 +252,7 @@ frmMainADT( parent )
     
 #elif defined(__WIN32__)
     
-       int stbBottomData [4] = { -1, 8, 8, 8 };
+       int stbBottomData [4] = { -1, 16, 16, 16 };
     
 #else
     
@@ -258,8 +271,10 @@ frmMainADT( parent )
        stbBottom->GetFieldRect(3, rectActivity);
     
        SSLToolTip = new wxToolTip(wxT(""));
-    
-       imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
+
+#if defined(__WIN32__)
+
+       imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint(rectOnline.GetX(),rectOnline.GetY()), wxDefaultSize, 0 );
        imgConnStatus->SetBitmap(*imgOnline);
        imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
     
@@ -272,6 +287,23 @@ frmMainADT( parent )
        imgActivityStatus->SetBitmap(*imgActIconSleep);
        imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
     
+#else
+
+       imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()), (rectOnline.GetY())), wxDefaultSize, 0);
+       imgConnStatus->SetBitmap(*imgOnline);
+       imgConnStatus->Connect(wxEVT_LEFT_DCLICK, wxCommandEventHandler(frmMain::ToggleConnectionStatus), NULL, this);
+
+       imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()), (rectSSL.GetY())), wxDefaultSize, 0);
+       imgSSLStatus->SetBitmap(*imgNoSSL);
+       imgSSLStatus->SetToolTip(SSLToolTip);
+       imgSSLStatus->Connect(wxEVT_LEFT_DCLICK, wxCommandEventHandler(frmMain::ShowSSLCertificates), NULL, this);
+
+       imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()), (rectActivity.GetY())), wxDefaultSize, 0);
+       imgActivityStatus->SetBitmap(*imgActIconSleep);
+       imgActivityStatus->Connect(wxEVT_LEFT_DCLICK, wxCommandEventHandler(frmMain::ShowActivityWindow), NULL, this);
+
+#endif
+
        // Setup the window menu.
     
        // By default should be:
@@ -477,7 +509,7 @@ void frmMain::OpenNewABDialog( wxCommandEvent& event)
                // the application.
         
                this->LoadPreferences();
-           
+
        }
     
 }
@@ -535,6 +567,10 @@ void frmMain::LoadContactList( wxTreeEvent& event )
                                        imgSSLStatus->SetBitmap(*imgOffline);
                                        SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
                                        AccountTypeFinal.Append(wxT("local"));
+                               } else {
+                                       imgSSLStatus->SetBitmap(*imgOffline);
+                                       SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));                                       
+                                       AccountTypeFinal.Append(AccountType.Lower());
                                }
                 
                                AccountIndex = i;
@@ -565,6 +601,8 @@ void frmMain::LoadContactList( wxTreeEvent& event )
                        } else if (AccountType == wxT("Local")){
                                SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
                                AccountTypeFinal.Append(wxT("local"));
+                       } else {
+                               AccountTypeFinal.Append(AccountType.Lower());
                        }
             
                        AccountIndex = i;
@@ -608,7 +646,7 @@ void frmMain::LoadContactList( wxTreeEvent& event )
        long ContactSeekPoint = 0;
     
        wxDir vcardaccdir(AccountDirFinal);
-    
+
        // Get the wxTreeItemId and image icon and compare it to the list.
     
        if (ActiveItemIcon == AccountGrpID){
@@ -1074,6 +1112,17 @@ void frmMain::ShowContactEditorNew( wxCommandEvent& event )
                return;
         
        }
+       
+       // Check if the account type is a valid account type, otherwise
+       // display an error message.
+       
+       if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
+               ActiveAccountType != "Local" && ActiveAccountType != "local"){
+               
+               wxMessageBox(_("Cannot add a new contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
+               return;
+                       
+       }
     
        // Add Pointer to SetupPointers for the ETagDB.
     
@@ -1124,7 +1173,7 @@ void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
                return;
         
        }
-    
+       
        wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
        wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
        wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
@@ -1169,6 +1218,13 @@ void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
     
        ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
        ContactEditor->SetupHeaders();
+
+       if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
+               ActiveAccountType != "Local" && ActiveAccountType != "local"){
+                       
+               ContactEditor->SetupAccountData(true);
+                       
+       }
     
        // Check if pointer is NULL (not from the search forms) or not.
     
@@ -1212,7 +1268,7 @@ void frmMain::RefreshAddressBook( wxCommandEvent& event ){
     
        if (!ActiveAccount.IsEmpty()){
    
-               if (ActiveAccountType != wxT("Local")){
+               if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
         
                        // Account type is not local.
        
@@ -1222,7 +1278,7 @@ void frmMain::RefreshAddressBook( wxCommandEvent& event ){
         
                } else {
        
-                       wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
+                       wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported"), wxICON_ERROR);
        
                }
        
@@ -1393,9 +1449,22 @@ void frmMain::LoadPreferences(){
                AccTmrPtr = NULL;
         
        }
+
+#if defined(__WIN32__)
+
+       for (std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.begin();
+               CertificateIter != AccountCertificateData.end(); CertificateIter++){
+
+               CertFreeCertificateContext(CertificateIter->second);
+
+       }
+
+       AccountCertificateData.clear();
+
+#endif
     
        AccountSyncTimers.clear();
-    
+        
        wxString AccDir;
        wxString AccDirFull;
        wxString AccDirFullSfx;
@@ -1408,9 +1477,13 @@ void frmMain::LoadPreferences(){
        wxTreeItemId AccountTreeId;
        wxTreeItemId GroupTreeId;
        int intGroupID = 0;
+        
+        // Relaod the accounts for the ETagProcTimer.
+        
+        ETagProcTimer.ReloadAccounts();
     
        for (int i = 0; i < preferences.accounts.GetCount(); i++){
-        
+               
                if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
                        preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
             
@@ -1435,7 +1508,7 @@ void frmMain::LoadPreferences(){
                AccName = preferences.accounts.GetAccountName(i);
                AccName.Trim();
                AccountAccDirList.insert(std::make_pair(i, AccDirFull));
-        
+               
                if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
                        preferences.accounts.GetAccountType(i) == wxT("carddav")){
             
@@ -1459,10 +1532,15 @@ void frmMain::LoadPreferences(){
             
                        AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
             
-               } else {
+               } else if (preferences.accounts.GetAccountType(i) == wxT("Local") ||
+                       preferences.accounts.GetAccountType(i) == wxT("local")) {
             
                        AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
             
+               } else {
+
+                       AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountUnsupportedID, -1);
+                       
                }
         
                // Go through the account directory and find contact files with
@@ -1475,7 +1553,7 @@ void frmMain::LoadPreferences(){
                wxString vCardFilename;
                wxString vCardDataString;
                wxString vCardFilenameFull;
-
+               
                bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
         
                while(ProcFiles){
@@ -1904,7 +1982,7 @@ void frmMain::RevealContact(wxCommandEvent& event){
 void frmMain::DeleteContact(wxCommandEvent& event){
     
        // Delete a contact from the main window.
-    
+       
        // Check if a contact is selected.
     
        long intSelected = -1;
@@ -1918,6 +1996,17 @@ void frmMain::DeleteContact(wxCommandEvent& event){
        if (intSelected == -1){
                return;
        }
+       
+       // Check if the account type is a valid account type, otherwise
+       // display an error message.
+       
+       if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
+               ActiveAccountType != "Local" && ActiveAccountType != "local"){
+               
+               wxMessageBox(_("Cannot delete contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
+               return;
+                       
+       }
     
        frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
     
@@ -2480,8 +2569,108 @@ void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
        wxString AccTypeLower;
        wxString AccType;
        bool AccountSSL;
-       std::map<int, SSLCertCollection>::iterator SSLColIter;
     
+#if defined(__APPLE__)
+
+       std::map<int, SecTrustRef>::iterator SSLTrustIter;
+        
+        for (int i = 0; i < prefaccounts.GetCount(); i++){
+                
+                SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
+                AccType.Append(prefaccounts.GetAccountType(i));
+                AccountSSL = prefaccounts.GetAccountSSL(i);
+                AccTypeLower = AccType.MakeLower();
+                SeekAccount.Append(wxT("."));
+                SeekAccount.Append(AccTypeLower);
+                
+                if (SeekAccount == ActiveAccount){
+                        
+                        if (AccTypeLower == wxT("local")){
+                                
+                                return;
+                                
+                        }
+                        
+                        if (AccountSSL == false){
+                                
+                                return;
+                                
+                        }
+                        
+                        SSLTrustIter = AccountTrustData.find(i);
+                        
+                        // Setup and display the form.
+                        
+                        DisplayCertificate(SSLTrustIter->second);
+                        
+                }
+                
+                SeekAccount.Clear();
+                AccTypeLower.Clear();
+                AccType.clear();
+                
+        }
+   
+#elif defined(__WIN32__)
+
+       std::map<int, PCCERT_CONTEXT>::iterator SSLCertificateIter;
+
+       for (int i = 0; i < prefaccounts.GetCount(); i++){
+
+               SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
+               AccType.Append(prefaccounts.GetAccountType(i));
+               AccountSSL = prefaccounts.GetAccountSSL(i);
+               AccTypeLower = AccType.MakeLower();
+               SeekAccount.Append(wxT("."));
+               SeekAccount.Append(AccTypeLower);
+
+               if (SeekAccount == ActiveAccount){
+
+                       if (AccTypeLower == wxT("local")){
+
+                               return;
+
+                       }
+
+                       if (AccountSSL == false){
+
+                               return;
+
+                       }
+
+                       SSLCertificateIter = AccountCertificateData.find(i);
+
+                       // Setup and display the form.
+
+                       if (SSLCertificateIter == AccountCertificateData.end() || SSLCertificateIter->second->pCertInfo == NULL){
+
+                               wxMessageBox("No certificate information is available due to invalid connection details, connection being in progress or invalid certificate data received.");
+
+                       } else {
+
+                               BOOL ModifiedCertificateData;
+                               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(SSLCertificateIter->second, (HWND)this->GetHandle());
+
+                               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
+                                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                               }
+
+                       }
+
+                       //DisplayCertificate(SSLTrustIter->second);
+
+               }
+
+               SeekAccount.Clear();
+               AccTypeLower.Clear();
+               AccType.clear();
+
+       }
+
+#else
+    
+       std::map<int, SSLCertCollection>::iterator SSLColIter;
+        
        for (int i = 0; i < prefaccounts.GetCount(); i++){
         
                SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
@@ -2524,6 +2713,8 @@ void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
                AccType.clear();
         
        }
+
+#endif
     
 }
 
@@ -2553,61 +2744,6 @@ void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
     
 }
 
-void frmMain::SetupSSLStatus( int AccountID ){
-    
-       // Check if account ID given is
-       // the active account and if not, do nothing.
-    
-       wxString AccType;
-       wxString AccTypeLower;
-    
-       AccType = prefaccounts.GetAccountType(AccountID);
-       AccTypeLower = AccType.MakeLower();
-    
-       wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
-               AccTypeLower;
-    
-       if (AccountIDName != ActiveAccount){
-        
-               return;
-        
-       }
-    
-       // Check if the account has SSL enabled.
-    
-       bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
-    
-       if (SSLInUse == FALSE){
-        
-               SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
-               imgSSLStatus->SetBitmap(*imgNoSSL);
-        
-       } else {
-        
-               // Get the SSL Collection Data.
-        
-               std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
-        
-               if (SSLResultIter->second == 1){
-            
-                       imgSSLStatus->SetBitmap(*imgSSLWarning);
-                       SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") + 
-                               prefaccounts.GetAccountName(AccountID) +
-                       wxT("' (Connection denied by user)\n\nDouble click for more information."));
-            
-               } else if (SSLResultIter->second == 0){
-            
-                       imgSSLStatus->SetBitmap(*imgSSL);
-                       SSLToolTip->SetTip(wxT("Account '") + 
-                               prefaccounts.GetAccountName(AccountID) +
-                       wxT("' secured using SSL\n\nDouble click for more information."));
-            
-               }
-        
-       }
-    
-}
-
 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
     
        // Display the form for showing an invalid SSL certificate.
@@ -2630,6 +2766,7 @@ void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
     
        frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
        wxPostEvent(frameActMgr, event2);
+        
 }
 
 void frmMain::PauseAllTimers(){
@@ -2658,6 +2795,32 @@ void frmMain::ResumeAllTimers(){
     
 }
 
+#if defined(__APPLE__)
+
+#elif defined(__WIN32__)
+
+void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext){
+
+       // Delete existing data.
+
+       std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.find(AccountID);
+
+       if (CertificateIter != AccountCertificateData.end()){
+               CertFreeCertificateContext(CertificateIter->second);
+       }
+
+       AccountCertificateData.erase(AccountID);
+       AccountSSLResult.erase(AccountID);
+
+       // Insert new data.
+
+       AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
+       AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
+
+}
+
+#else
+
 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
     
        // Delete existing data.
@@ -2672,6 +2835,84 @@ void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollec
     
 }
 
+#endif
+
+void frmMain::SetupSSLStatus( int AccountID ){
+        
+        // Check if account ID given is
+        // the active account and if not, do nothing.
+        
+        wxString AccType;
+        wxString AccTypeLower;
+        
+        AccType = prefaccounts.GetAccountType(AccountID);
+        AccTypeLower = AccType.MakeLower();
+        
+        wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
+        AccTypeLower;
+        
+        if (AccountIDName != ActiveAccount){
+                
+                return;
+                
+        }
+        
+       // Check the account type is a supported account type.
+       
+       if (AccType != "CardDAV" && AccType != "carddav" &&
+               AccType != "Local" && AccType != "local"){
+       
+                SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
+                imgSSLStatus->SetBitmap(*imgNoSSL);
+               return;
+                       
+       }
+       
+        // Check if the account has SSL enabled.
+        
+        bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
+        
+        if (SSLInUse == FALSE){
+                
+                SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
+                imgSSLStatus->SetBitmap(*imgNoSSL);
+                
+        } else {
+                
+                // Get the SSL Collection Data.
+                
+                std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
+                
+               // Check if a result value has been set.
+
+               if (SSLResultIter == AccountSSLResult.end()){
+
+                       imgSSLStatus->SetBitmap(*imgSSLWarning);
+                       SSLToolTip->SetTip(wxT("Unable to determine SSL information for the '") + prefaccounts.GetAccountName(AccountID) + wxT("' account."));
+                       return;
+
+               }
+
+                if (SSLResultIter->second == 1){
+                        
+                        imgSSLStatus->SetBitmap(*imgSSLWarning);
+                        SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
+                                           prefaccounts.GetAccountName(AccountID) +
+                                           wxT("' (Connection denied by user)\n\nDouble click for more information."));
+                        
+                } else if (SSLResultIter->second == 0){
+                        
+                        imgSSLStatus->SetBitmap(*imgSSL);
+                        SSLToolTip->SetTip(wxT("Account '") +
+                                           prefaccounts.GetAccountName(AccountID) +
+                                           wxT("' secured using SSL\n\nDouble click for more information."));
+                        
+                }
+                
+        }
+        
+}
+
 void frmMain::CheckUpdates( wxCommandEvent& event ){
     
        // Check for updates to Xestia Address Book.
@@ -2886,7 +3127,7 @@ void frmMain::ShowContactMenu( wxMouseEvent& event ){
 
        bool EnableRefresh = FALSE;
 
-       if (!ActiveAccount.IsEmpty()){
+       if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" || ActiveAccountType == "carddav")){
 
                EnableRefresh = TRUE;
        
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