Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Clearup active account, file information and contact lists when reloading...
[xestiaab/.git] / source / frmMain.cpp
index 3c785f2..c32e61d 100644 (file)
@@ -54,7 +54,6 @@
 #include "common/events.h"
 #include "common/dirs.h"
 #include "vcard/vcard.h"
-#include "carddav/carddav.h"
 #include "contacteditor/frmContactEditor.h"
 #include "import/import.h"
 #include "export/export.h"
@@ -66,7 +65,6 @@
 // Define the event types.
 
 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
-DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
@@ -100,7 +98,6 @@ DEFINE_EVENT_TYPE(INVALIDSSLTRUST);
 BEGIN_EVENT_TABLE(frmMain, wxFrame)
 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
-EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
@@ -191,7 +188,40 @@ frmMainADT( parent )
     
        wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
        imgNoSSL = new wxBitmap(icons_nossl_png, -1);
-    
+       // Toolbar icons.
+
+       wxMemoryInputStream addaddressbook(toolbar_addaddressbook_png, sizeof(toolbar_addaddressbook_png));
+       wxMemoryInputStream preferences(toolbar_preferences_png, sizeof(toolbar_preferences_png));
+       wxMemoryInputStream searchcontacts(toolbar_searchcontacts_png, sizeof(toolbar_searchcontacts_png));
+       wxMemoryInputStream addcontact(toolbar_addcontact_png, sizeof(toolbar_addcontact_png));
+       wxMemoryInputStream editcontact(toolbar_editcontact_png, sizeof(toolbar_editcontact_png));
+       wxMemoryInputStream deletecontact(toolbar_deletecontact_png, sizeof(toolbar_deletecontact_png));
+
+       wxImage toolbar_addaddressbook_png(addaddressbook, wxBITMAP_TYPE_PNG);
+       imgAddAddressBook = new wxBitmap (toolbar_addaddressbook_png, -1);
+       tblMain->SetToolNormalBitmap(tbtNewAccount->GetId(), *imgAddAddressBook);
+
+       wxImage toolbar_preferences_png(preferences, wxBITMAP_TYPE_PNG);
+       imgPreferences = new wxBitmap (toolbar_preferences_png, -1);
+       tblMain->SetToolNormalBitmap(tbtPreferences->GetId(), *imgPreferences);
+
+       wxImage toolbar_searchcontacts_png(searchcontacts, wxBITMAP_TYPE_PNG);
+       imgSearchContacts = new wxBitmap (toolbar_searchcontacts_png, -1);
+       tblMain->SetToolNormalBitmap(tbtSearch->GetId(), *imgSearchContacts);
+
+       wxImage toolbar_addcontact_png(addcontact, wxBITMAP_TYPE_PNG);
+       imgAddContact = new wxBitmap (toolbar_addcontact_png, -1);
+       tblMain->SetToolNormalBitmap(tbtAddContact->GetId(), *imgAddContact);
+       
+       wxImage toolbar_editcontact_png(editcontact, wxBITMAP_TYPE_PNG);
+       imgEditContact = new wxBitmap (toolbar_editcontact_png, -1);
+       tblMain->SetToolNormalBitmap(tbtEditContact->GetId(), *imgEditContact);
+       
+       wxImage toolbar_deletecontact_png(deletecontact, wxBITMAP_TYPE_PNG);
+       imgDeleteContact = new wxBitmap (toolbar_deletecontact_png, -1);
+       tblMain->SetToolNormalBitmap(tbtDeleteContact->GetId(), *imgDeleteContact);
+
        // Activity Icon.
     
        wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
@@ -358,17 +388,11 @@ void frmMain::QuitApp()
 {
 
        // Function to run when quitting.
-    
-       //Go through the windows and close each one (be it search
-       //or contact editor). Abort if user wants to cancel.
-    
-       // Close the contact editor windows.
-    
-       // Close the contact windows.
-    
-       // Close the search windows.
-    
+       
        // Write out the ETag databases.
+       
+       ETagProcTimer.Stop();
+       ETagProcTimer.Notify();
     
        // Save Preferences: Save the window position if that option is enabled.
     
@@ -404,7 +428,7 @@ void frmMain::QuitApp()
     
        if (SaveWindowPos == TRUE){
         
-               wxRect frmMainPos = this->GetRect();
+               wxRect frmMainPos = GetRect();
         
                cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
                cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
@@ -416,7 +440,7 @@ void frmMain::QuitApp()
        delete cfgfile;
        cfgfile = NULL;
     
-       //Everything closed... exit.
+       // Everything closed... exit.
     
        std::exit(0);
     
@@ -451,6 +475,13 @@ void frmMain::ShowAboutWindow( wxCommandEvent& event )
 void frmMain::OpenPreferences( wxCommandEvent& event)
 {
 
+       // Close all windows first.
+       
+       if (CloseAllWindows() == false)
+       {
+               return;
+       }
+
        // Open the preferences window.
     
        ReloadAccounts = FALSE;
@@ -466,7 +497,7 @@ void frmMain::OpenPreferences( wxCommandEvent& event)
                // Reload the accounts as a change has been made within
                // the application and clear the current contact information.
         
-               this->LoadPreferences();
+               this->LoadPreferences(true);
                this->ResetContactInfo();
        
        }
@@ -491,7 +522,7 @@ void frmMain::OpenNewABDialog( wxCommandEvent& event)
                // Reload the accounts as a change has been made within
                // the application.
         
-               this->LoadPreferences();
+               this->LoadPreferences(true);
 
        }
     
@@ -1077,7 +1108,7 @@ void frmMain::ShowContactInfo( wxListEvent& event )
     
        OldSessionID = SessionID;
        SessionID = wxString::Format(wxT("%i"), rand() % 32768);
-       LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
+       LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList, ContactBackgroundColour);
        ActiveFilename = ContactsFileIndex[ContactSeekNum];
     
 }
@@ -1323,6 +1354,7 @@ void frmMain::OpenContactInfoList( wxListEvent& event )
        wxPostEvent(this, addevent);
     
        Contact->SetupPointers(&MemoryFileList);
+       Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
        Contact->SetupContactData(&Person);
     
        Contact->SetIcon(contacticon);
@@ -1380,6 +1412,7 @@ void frmMain::OpenContactInfo( wxCommandEvent& event )
        wxPostEvent(this, addevent);
     
        Contact->SetupPointers(&MemoryFileList);
+       Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
        Contact->SetupContactData(&Person);
     
        Contact->SetIcon(contacticon);
@@ -1393,11 +1426,11 @@ void frmMain::LoadPreferences( wxActivateEvent& event)
 
        // Load the preferences.
 
-       this->LoadPreferences();
+       this->LoadPreferences(true);
        
 }
 
-void frmMain::LoadPreferences(){
+void frmMain::LoadPreferences(bool skipWindowSizeReload){
     
        // Load the preferences.
     
@@ -1405,17 +1438,35 @@ void frmMain::LoadPreferences(){
     
        XABPreferences preferences(preffilename);
     
+       // Clear the active account/filename information and account list.
+
+       ActiveAccount = "";
+       ActiveAccountType = "";
+       ActiveFilename = "";
+       lstContacts->DeleteAllItems();
+
        // Setup the main window position (if needed).
     
        bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
        bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
+       bool UseBackgroundContactColour = preferences.GetBoolData(wxT("UseBackgroundContactColour"));
     
-       if (SaveWindowPos == TRUE){
+       if (SaveWindowPos == true && skipWindowSizeReload == false){
         
                this->SetSize(preferences.GetMainWindowData());
         
        }
     
+       if (UseBackgroundContactColour == true){
+               
+               ContactBackgroundColour = preferences.GetBackgroundContactColourData();
+               
+        } else {
+                
+                ContactBackgroundColour = wxTransparentColour;
+                
+        }
+       
        treAccounts->DeleteAllItems();
     
        wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
@@ -1468,7 +1519,7 @@ void frmMain::LoadPreferences(){
        for (int i = 0; i < preferences.accounts.GetCount(); i++){
                
                if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
-                       preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
+                       preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == true){
             
                        continue;
             
@@ -1608,7 +1659,7 @@ void frmMain::ConflictResolution(wxCommandEvent& event){
        vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
        vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
        vCard *ServerDataPtr = vCardConfObj->vCardServerData;
-       frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
+       frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList, ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
        frameCR->ShowModal();
     
        int FinalConflictResult = frameCR->GetResult();
@@ -1718,6 +1769,7 @@ void frmMain::UpdateContactList(wxCommandEvent& event){
             
                        vCard UpdatedPerson;
                        UpdatedPerson.LoadFile(ucd->ContactFilename);
+                       frmContactPtr->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
                        frmContactPtr->SetupContactData(&UpdatedPerson);
             
                }
@@ -1742,12 +1794,6 @@ void frmMain::UpdateContactList(wxCommandEvent& event){
     
 }
 
-void frmMain::UpdateAccountList(wxCommandEvent& event){
-    
-       // Update the account list (currently unimplemented).
-    
-}
-
 void frmMain::SetupPointers(void *ActMgrPtrInc){
     
        // Setup the pointers for the main window.
@@ -1791,7 +1837,7 @@ void frmMain::SetupForm(){
        ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
        wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
     
-       LoadPreferences();
+       LoadPreferences(false);
     
 }
 
@@ -1916,8 +1962,8 @@ void frmMain::RevealContact(wxCommandEvent& event){
                
                if (uc->ContactAccount == AccountAccDirList[i]){
             
-               treAccounts->SelectItem(nextChild, TRUE);
-               AccCtrl->SetText(treAccounts->GetItemText(nextChild));
+                       treAccounts->SelectItem(nextChild, TRUE);
+                       AccCtrl->SetText(treAccounts->GetItemText(nextChild));
             
                }
         
@@ -2105,13 +2151,14 @@ void frmMain::DeleteContact(wxCommandEvent& event){
                        if (nextChild == selectedChild){
                        
                                wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
+                               break;
 
                        }
             
                }
         
                // Add task to the activity monitor to delete the contact.
-        
+               
                frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
         
        }
@@ -2652,7 +2699,7 @@ void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
 
 #else
     
-       std::map<int, SSLCertCollection>::iterator SSLColIter;
+       std::map<int, SSLCertCollectionString>::iterator SSLColIter;
         
        for (int i = 0; i < prefaccounts.GetCount(); i++){
         
@@ -2679,11 +2726,11 @@ void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
             
                        SSLColIter = AccountSSLData.find(i);
             
-                       SSLCertCollection SSLCertInfo = SSLColIter->second;
-            
+                       SSLCertCollectionString SSLCertInfo = SSLColIter->second;
+                       
                        frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
                        frameSSLCert->StartCertFrom(0);
-                       frameSSLCert->SetupCerts(SSLCertInfo);
+                       frameSSLCert->SetupCertsString(SSLCertInfo);
                        frameSSLCert->ShowModal();
             
                        delete frameSSLCert;
@@ -2829,7 +2876,7 @@ void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEX
 
 #else
 
-void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
+void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc){
     
        // Delete existing data.
     
@@ -3135,7 +3182,10 @@ void frmMain::ShowContactMenu( wxMouseEvent& event ){
 
        bool EnableRefresh = FALSE;
 
-       if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" || ActiveAccountType == "carddav")){
+       if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" ||
+                ActiveAccountType == "carddav" ||
+                ActiveAccountType == "Local" ||
+                ActiveAccountType == "local")){
 
                EnableRefresh = TRUE;
        
@@ -3155,4 +3205,29 @@ void frmMain::ResetContactInfo(){
        htmContactData->SetPage(EmptyPage);
        AccCtrl->SetValue("");
        
-}
\ No newline at end of file
+}
+
+bool frmMain::CloseAllWindows()
+{
+       // Attempt to close all windows.
+       
+       if (WindowListPointersMenu.size() == 0)
+       {
+               return true;
+       }
+       
+       if (wxMessageBox(_("Before preforming the action, all windows that are open will need to close. Do you wish to continue?"), _("Close All Windowss"), wxYES_NO) == wxYES)
+       {
+               for(std::map<int, void*>::iterator windowIter = WindowListPointers.begin();
+                       windowIter != WindowListPointers.end(); windowIter++)
+               {
+                       wxWindow *windowPointer = static_cast<wxWindow*>(windowIter->second);
+                       windowPointer->Close();
+               }
+               return true;
+       }
+       else
+       {
+               return false;
+       }
+}
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