Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code for viewing vCard data within an unsupported account
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 8 Jul 2016 19:27:16 +0000 (20:27 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 8 Jul 2016 19:27:16 +0000 (20:27 +0100)
The code now makes unsupported accounts appear and features which are
used for managing supported accounts are restricted with unsupported
accounts.

- New contacts can't be added.
- Contacts can be viewed but not edited in the contact editor
- Contacts cannot be deleted.
- Account settings cannot be edited.
- Account can still be deleted like supported accounts.
- Data can still be exported.

source/common/preferences.cpp
source/common/timers.cpp
source/contacteditor/frmContactEditor-Save.cpp
source/contacteditor/frmContactEditor.cpp
source/contacteditor/frmContactEditor.h
source/frmMain.cpp
source/frmMain.h
source/frmPreferences.cpp

index d8c1a53..009afea 100644 (file)
@@ -195,6 +195,41 @@ XABPreferences::XABPreferences(wxString PreferencesFilename){
                                AccSSL, AccUsr, AccPass, 
                                AccPrefix, AccDir, AccRef);
             
+               } else {
+                       
+                       cfgfile->Read(wxT("accountdir"), &AccDir);
+                       accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
+                       accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
+                       accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
+                       if (AccSSLInc == wxT("true")){
+                               AccSSL = TRUE;
+                       }
+                       else {
+                               AccSSL = FALSE;
+                       }
+                       accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
+                       accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
+                       accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
+                       accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
+            
+                       if (AccDir.Len() > 4){
+
+                               accountdirvalid = TRUE;
+            
+                       }
+                
+                       // Make sure it is not bigger than 65535 or less than 1.
+                       // If so, default to port 8008.
+                
+                       if (accountport < 1 || accountport > 65535){
+                               accountport = 8008;
+                               accountportvalid = TRUE;
+                       }
+            
+                       accounts.AddAccount(accountname, EntryValue, AccAdr, AccPort,
+                               AccSSL, AccUsr, AccPass, 
+                               AccPrefix, AccDir, AccRef);
+                       
                }
 
                // Clear up for the next account.
index e95347e..88bbb3e 100644 (file)
@@ -423,13 +423,13 @@ void wxETagProcessTimer::ReloadAccounts(){
         
                AccountDir = PrefData.accounts.GetAccountDirectory(i);
                AccountType = PrefData.accounts.GetAccountType(i);
-        
+               
                if (AccountDir.IsEmpty()){
                        continue;
                }
         
-               if (AccountType == wxT("Local") || AccountType == wxT("local")){
-               continue;
+               if (AccountType != wxT("CardDAV") && AccountType != wxT("carddav")){
+                       continue;
                }
         
                AccountDir.Trim();
index bf743ee..ffaa5a0 100644 (file)
 void frmContactEditor::SaveContact( wxCommandEvent& event )
 {
     
+       // Do not save if the account is an unsupported account.
+       
+       if (boolUnsupportedAccount == true){
+       
+               wxMessageBox(_("Cannot make changes to a contact from an unsupported account type."), _("Unsupported account"), wxICON_ERROR);          
+               return;
+               
+       }
+       
        // Check if Display As combo box has a value in it.
        // Do not go any further if there is no value.
     
@@ -2462,7 +2471,7 @@ void frmContactEditor::SaveContact( wxCommandEvent& event )
        wxStringTokenizer wSTFilename(wxSContactFilename, wxT("/"));
     
 #endif
-    
+
        XABPreferences PrefData(PrefDir);
     
        wxString AccountType;
index 4acb350..b5ef96e 100644 (file)
@@ -159,6 +159,12 @@ void frmContactEditor::SetupContact( wxString AccountName )
     
 }
 
+void frmContactEditor::SetupAccountData(bool UnsupportedAccount){
+       
+       boolUnsupportedAccount = UnsupportedAccount;
+       
+}
+
 int frmContactEditor::GetLastInt(std::map<int, wxString> *MapData){
     
        /*
index 1cd897e..fabe5cb 100644 (file)
@@ -313,6 +313,7 @@ class frmContactEditor : public frmContactEditorADT
                frmContactEditor( wxWindow* parent );
                void SetupHeaders();
                void SetupContact(wxString AccountName);
+               void SetupAccountData(bool UnsupportedAccount);
                void SetupPointers(frmActivityMgr *ActMgr, wxETagProcessTimer *ETagProc,
                                        frmMain *MainPtrInc);
                bool LoadContact(wxString Filename);
@@ -711,6 +712,8 @@ class frmContactEditor : public frmContactEditorADT
                wxString wxSContactFilename;
                wxString wxSContactAccount;
                bool boolContactModified;
+               bool boolUnsupportedAccount = false;
+               
                int intSeekSelectedData;
                
                /* Section for saving/loading data */
index 6625432..b8a80cf 100644 (file)
@@ -138,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);
@@ -153,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));
     
@@ -541,6 +548,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;
@@ -571,6 +582,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;
@@ -614,7 +627,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){
@@ -1080,6 +1093,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.
     
@@ -1130,7 +1154,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);
@@ -1175,6 +1199,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.
     
@@ -1218,7 +1249,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.
        
@@ -1228,7 +1259,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);
        
                }
        
@@ -1433,7 +1464,7 @@ void frmMain::LoadPreferences(){
         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){
             
@@ -1458,7 +1489,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")){
             
@@ -1482,10 +1513,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
@@ -1498,7 +1534,7 @@ void frmMain::LoadPreferences(){
                wxString vCardFilename;
                wxString vCardDataString;
                wxString vCardFilenameFull;
-
+               
                bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
         
                while(ProcFiles){
@@ -1927,7 +1963,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;
@@ -1941,6 +1977,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);
     
@@ -2791,6 +2838,17 @@ void frmMain::SetupSSLStatus( int AccountID ){
                 
         }
         
+       // 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);
@@ -3050,7 +3108,7 @@ void frmMain::ShowContactMenu( wxMouseEvent& event ){
 
        bool EnableRefresh = FALSE;
 
-       if (!ActiveAccount.IsEmpty()){
+       if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" || ActiveAccountType == "carddav")){
 
                EnableRefresh = TRUE;
        
index 8a5ac21..8d3c58d 100644 (file)
@@ -171,6 +171,7 @@ class frmMain : public frmMainADT
                int AccountID;
                int AccountNetID;
                int AccountGrpID;
+               int AccountUnsupportedID;
                int AccountNoneID;
                bool ReloadAccounts = FALSE;
                bool AscendingMode = FALSE;
index b12e712..c9623e0 100644 (file)
@@ -43,6 +43,7 @@ frmPreferencesADT( parent )
        
        wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
        wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
+       wxMemoryInputStream cstream(icons_accunsupported_png, sizeof(icons_accunsupported_png));
        
        wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
        wxBitmap AccInet(icons_accinet_png, -1);
@@ -53,9 +54,15 @@ frmPreferencesADT( parent )
        wxBitmap AccNIcon(icons_acclocal_png, -1);
        wxIcon wxIAccNIcon;
        wxIAccNIcon.CopyFromBitmap(AccNIcon);
+
+       wxImage icons_accunsupported_png(cstream, wxBITMAP_TYPE_PNG);
+       wxBitmap AccUIcon(icons_accunsupported_png, -1);
+       wxIcon wxIAccUIcon;
+       wxIAccUIcon.CopyFromBitmap(AccUIcon);
        
        AccountID = AccImgList->Add(wxIAccNIcon);
        AccountNetID = AccImgList->Add(wxIAccInet);
+       AccountUnsupportedID = AccImgList->Add(wxIAccUIcon);
 
        NbtPreferences->RemovePage(1);
 
@@ -125,14 +132,27 @@ void frmPreferences::ModifyABAccount( wxCommandEvent& event )
        long lstAccountsIndex = -1;
        wxString AccFilename = GetAccountsFile();
        wxString AccName;
+       wxString AccType;
     
        wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
-    
+       
        // Get the account name.
     
        lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
                wxLIST_NEXT_ALL,
                wxLIST_STATE_SELECTED);
+       
+       // Check that the account type is a supported account type.
+       
+       AccType = preferences->accounts.GetAccountType((int)lstAccountsIndex);
+       
+       if (AccType != "CardDAV" && AccType != "carddav" &&
+               AccType != "Local" && AccType != "local"){
+       
+               wxMessageBox(_("Cannot modify the selected account settings as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
+               return;
+                       
+       }
     
        AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
     
@@ -226,6 +246,10 @@ void frmPreferences::DeleteABAccount( wxCommandEvent& event )
        
                        AccountDirFull.Append(wxT("carddav"));
        
+               } else {
+                       
+                       AccountDirFull.Append(AccountType.Lower());
+                       
                }
        
                lstAccounts->DeleteItem(lstAccountsIndex);
@@ -254,6 +278,9 @@ void frmPreferences::DeleteABAccount( wxCommandEvent& event )
     
        }
 
+       btnAccountModify->Enable(FALSE);
+       btnAccountDelete->Enable(FALSE);
+       
 }
 
 void frmPreferences::LoadPreferences( wxInitDialogEvent& event )
@@ -344,6 +371,10 @@ void frmPreferences::ReloadAccounts(){
        
                        col0.SetImage(AccountID);
        
+               } else {
+
+                       col0.SetImage(AccountUnsupportedID);
+                       
                }
        
                long itemindex = lstAccounts->InsertItem( col0 );
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