Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Improved importing support.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Sep 2015 12:18:26 +0000 (13:18 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Sep 2015 12:18:26 +0000 (13:18 +0100)
source/import/frmImportContacts.cpp
source/import/frmImportContacts.h
source/import/import.cpp

index 9031a3a..0160598 100644 (file)
@@ -77,6 +77,7 @@ frmImportContactsADT( parent )
     wxString AccDirFull;
     wxString AccDirFullSfx;
     wxString AccName;
+    wxString AccType;
     wxString AccDirFinal;
     wxTreeItemId AccountTreeId;
     wxTreeItemId GroupTreeId;
@@ -100,7 +101,10 @@ frmImportContactsADT( parent )
        AccDirFull.Append(AccDirFullSfx);
        AccName = preferences.accounts.GetAccountName(i);
        AccName.Trim();
+       AccType = preferences.accounts.GetAccountType(i);
+       AccType.Trim();
        AccountAccDirList.insert(std::make_pair(i, AccDirFull));
+       AccountAccTypeList.insert(std::make_pair(i, AccType));
        
        if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
        preferences.accounts.GetAccountType(i) == wxT("carddav")){
@@ -125,6 +129,18 @@ frmImportContactsADT( parent )
 
 }
 
+frmImportContacts::~frmImportContacts()
+{
+       
+       /*delete AccControl;
+       AccControl = NULL;
+       delete treAccounts;
+       treAccounts = NULL;
+       delete AccImgList;
+       AccImgList = NULL;*/
+       
+}
+
 void frmImportContacts::GetResult()
 {
 
@@ -237,4 +253,44 @@ wxString frmImportContacts::GetAccount()
        
        return AccountName;
 
+}
+
+wxString frmImportContacts::GetAccountType()
+{
+
+       wxString preffilename = GetUserPrefDir();
+
+       XABPreferences preferences(preffilename);
+
+       wxString AccountType;
+       
+       //XABPrefAccounts prefaccounts;
+       
+       wxTreeItemIdValue cookie;
+       wxTreeItemId next = treAccounts->GetRootItem();
+
+       wxTreeItemId selectedChild = treAccounts->GetSelection();
+       wxTreeItemId nextChild;
+
+       for (int i = 0; i < preferences.accounts.GetCount(); i++){
+
+               if (!nextChild){
+                       nextChild = treAccounts->GetFirstChild(next, cookie);
+               } else {
+                       nextChild = treAccounts->GetNextSibling(nextChild);
+               }
+               
+               if (nextChild == selectedChild){
+       
+                       std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
+                       
+                       AccountType = AccTypeIter->second;
+       
+               }
+       
+
+       }
+       
+       return AccountType;
+
 }
\ No newline at end of file
index 4ee0fcf..7862fb4 100644 (file)
@@ -20,8 +20,12 @@ class frmImportContacts : public frmImportContactsADT
        private:
                wxComboCtrl* AccControl = new wxComboCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCB_READONLY|wxEXPAND);
                XABAccountView* treAccounts = new XABAccountView();
-               std::map<int, wxString> AccountAccDirList;
                wxImageList *AccImgList =  new wxImageList(16,16,true);
+               //wxComboCtrl* AccControl;
+               //XABAccountView* treAccounts;
+               std::map<int, wxString> AccountAccDirList;
+               std::map<int, wxString> AccountAccTypeList;
+               //wxImageList *AccImgList;
                int AccountID;
                int AccountNetID;
                int AccountGrpID;
@@ -34,9 +38,11 @@ class frmImportContacts : public frmImportContactsADT
        public:
                /** Constructor */
                frmImportContacts( wxWindow* parent );
+               ~frmImportContacts();
                void SetupList(std::map<int,ImportDataContact>* ContactDataInc);
                void GetResults(std::map<int,ImportDataContact>* ContactDataInc);
                wxString GetAccount();
+               wxString GetAccountType();
        //// end generated class members
        
 };
index 416a39f..948f83f 100644 (file)
@@ -19,10 +19,6 @@ void ImportRun(frmMain *frmMainPtrInc){
        // Bring up a dialog selecting one or multiple 
        // files for processing based on type.
 
-       struct ImportResultData{
-               
-       };
-
        frmMainPtrInc->PauseAllTimers();
 
        wxString FileTypes;
@@ -35,9 +31,10 @@ void ImportRun(frmMain *frmMainPtrInc){
        wxArrayString SelectedFileList;
        wxString SelectedFileDirectory;
        wxString AccountName;
+       wxString AccountType;
        int ImportErrorCount = 0;
        
-       std::map<int,wxString> ResultData;
+       std::map<int,wxString> *ResultData = new std::map<int,wxString>;
        
        FileTypes.Append(wxT("vCard 4.0 Contact(s) (*.vcf)"));
        FileTypes.Append(wxT("|*.vcf|"));
@@ -105,6 +102,10 @@ void ImportRun(frmMain *frmMainPtrInc){
        frmIC->ShowModal();
        frmIC->GetResults(&ContactData);
        AccountName = frmIC->GetAccount();
+       AccountType = frmIC->GetAccountType();
+
+       delete frmIC;
+       frmIC = NULL;
 
        // Import the contacts into the selected account.
 
@@ -139,7 +140,7 @@ void ImportRun(frmMain *frmMainPtrInc){
        
                if (iter->second.ContactSelected == TRUE){
                
-                       // Workout the file name.
+                       // Workout the file name.               void CloseWindow( wxCommandEvent& event );
                        // Get the UID value and check if it is empty.
                        // If it isn't empty, check it can be used for a valid
                        // filename other wise generate a file name for the purposes
@@ -223,7 +224,7 @@ void ImportRun(frmMain *frmMainPtrInc){
                        
                                // File already exists so mark as an error.
                                
-                               ResultData.insert(std::make_pair(ImportSeek, wxString::Format(_("Unable to import '%s'(%s): "), iter->second.FriendlyName, UIDToken)));
+                               ResultData->insert(std::make_pair(ImportSeek, wxString::Format(_("Unable to import '%s'(%s): %s"), iter->second.FriendlyName, UIDToken, _("Contact already exists."))));
                                ImportErrorCount++;
                                ImportSeek++;
                                GeneratedFilename.Clear();
@@ -240,16 +241,19 @@ void ImportRun(frmMain *frmMainPtrInc){
                                wxFFile OutputFile;
                        
 #if wxABI_VERSION < 20900
-                               OutputFile.Open(OutputFilename, wxT("w"));
+                               if(!OutputFile.Open(OutputFilename, wxT("w"))){
 #else
-                               OutputFile.Open(OutputFilename, wxT("w"));
+                               if(!OutputFile.Open(OutputFilename, wxT("w"))){
 #endif
+                                       ResultData->insert(std::make_pair(ImportSeek, wxString::Format(_("Unable to import '%s'(%s): %s"), iter->second.FriendlyName, UIDToken, _("Error occured whilst trying to create this contact. Please check permissions and storage device."))));
+                       
+                               }
                        
                                OutputFile.Write(iter->second.ContactData, wxConvAuto());
                        
                                OutputFile.Close();
                                
-                               ResultData.insert(std::make_pair(ImportSeek, wxString::Format(_("Contact '%s'(%s) was successfully imported."))));
+                               ResultData->insert(std::make_pair(ImportSeek, wxString::Format(_("Contact '%s'(%s) was successfully imported."), iter->second.FriendlyName, UIDToken)));
                        
                        }
                        
@@ -274,24 +278,25 @@ void ImportRun(frmMain *frmMainPtrInc){
        // Check if the import error count is more than 0. If it is, then
        // display the results dialog.
        
-       frmImportResults *frmIR = new frmImportResults(frmMainPtrInc);
-       frmIR->LoadData(&ResultData);
-       frmIR->ShowModal();
+       wxCommandEvent imprres(IMPORT_RESULTSSHOW);
+       imprres.SetClientData(ResultData);
+       imprres.SetInt(ImportCount);
+       imprres.SetExtraLong(ImportErrorCount);
+       wxPostEvent(frmMainPtrInc, imprres);
                
-       delete frmIR;
-       frmIR = NULL;
-
-       delete frmIC;
-       frmIC = NULL;
-       
        // Syncronise the account which the contacts got imported to.
+       // (If the account is not a local account).
        
-       wxString *AccNamePostEventPtr = new wxString;
+       if (AccountType != wxT("Local") && AccountType != wxT("local")){
        
-       wxCommandEvent accevent(SYNCACCOUNT);
-       accevent.SetClientData(AccNamePostEventPtr);
+               wxString *AccNamePostEventPtr = new wxString;
        
-       wxPostEvent(frmMainPtrInc, accevent);
+               wxCommandEvent accevent(SYNCACCOUNT);
+               accevent.SetClientData(AccNamePostEventPtr);
+       
+               wxPostEvent(frmMainPtrInc, accevent);
+       
+       }
        
        //wxPostEvent
        
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