Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Altered SaveContact in frmContactEditor to use the ContactDataObject
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 3 Jul 2016 23:11:39 +0000 (00:11 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 3 Jul 2016 23:11:39 +0000 (00:11 +0100)
Commented out old code used directly in frmContactEditor when saving a
contact as that has now moved to the SaveFile/SaveString functions in
the ContactDataObject.

source/contacteditor/frmContactEditor-Save.cpp

index 24beefd..bf743ee 100644 (file)
@@ -43,7 +43,7 @@ void frmContactEditor::SaveContact( wxCommandEvent& event )
     
        // Save the updated contact data.
     
-       vCard ContactData;
+       //vCard ContactData;
        wxString FilenameFinal;
        bool ReplaceContact = FALSE;
     
@@ -157,7 +157,233 @@ void frmContactEditor::SaveContact( wxCommandEvent& event )
        std::map<int,int>::iterator intiter;
        std::map<int,wxString>::iterator striter;
     
-       ContactData.Add(wxT("BEGIN"), wxT("VCARD"), FALSE);
+       // Set some values for saving.
+       
+       ContactEditorData.NameForename = txtForename->GetValue();
+       ContactEditorData.NameSurname = txtSurname->GetValue();
+       ContactEditorData.NameOtherNames = txtOtherNames->GetValue();
+       ContactEditorData.NameTitle = txtTitle->GetValue();
+       ContactEditorData.NameSuffix = txtSuffix->GetValue();
+       
+       ContactEditorData.GenderDetails = txtGenderDescription->GetValue();
+       
+       // Process Birthday: Get Day, Month & Year.
+        
+       wxDateTime BirthdayDate;
+       wxDateTime::Month BirthdayMonth;
+       int BirthdayDay;
+       int BirthdayYear;
+       wxString DataBeforeT;
+       wxString DataAfterT;
+       wxString FinalBirthdayString;
+       bool ProcessDataAfterT = FALSE;
+        
+       BirthdayDate = dapBirthday->GetValue();
+        
+       if (!txtBirthday->IsEmpty()){
+       
+               // Birthday value is text so use this.
+               
+               ContactEditorData.Birthday = txtBirthday->GetValue();
+               
+       } else if (BirthdayDate.IsValid()){
+            
+               BirthdayDay = BirthdayDate.GetDay();
+               BirthdayMonth = BirthdayDate.GetMonth();
+               BirthdayYear = BirthdayDate.GetYear();
+            
+               // Look for T and replace data before this.
+            
+               wxStringTokenizer wSTDate(ContactEditorData.Birthday, wxT("T"));
+            
+               while (wSTDate.HasMoreTokens()){
+                
+                       if (ProcessDataAfterT == FALSE){
+                    
+                               DataBeforeT = wSTDate.GetNextToken();
+                               ProcessDataAfterT = TRUE;
+                    
+                       } else {
+                    
+                               DataAfterT = wSTDate.GetNextToken();
+                               break;
+                    
+                       }
+                
+               }
+            
+               // If there is not T then replace altogether.
+            
+               wxString FinalBirthdayDay;
+               wxString FinalBirthdayMonth;
+               wxString FinalBirthdayYear;
+            
+               if (BirthdayDay < 10){
+                
+                       FinalBirthdayDay = wxT("0") + wxString::Format(wxT("%i"), BirthdayDay);
+                
+               } else {
+                
+                       FinalBirthdayDay = wxString::Format(wxT("%i"), BirthdayDay);
+                
+               }
+            
+               if (((int)BirthdayMonth + 1) < 10){
+                
+                       FinalBirthdayMonth = wxT("0") + wxString::Format(wxT("%i"), ((int)BirthdayMonth + 1));
+                
+               } else {
+                
+                       FinalBirthdayMonth = wxString::Format(wxT("%i"), ((int)BirthdayMonth + 1));
+                
+               }
+            
+               if (BirthdayYear == 0){
+                
+                       FinalBirthdayYear = wxT("--");
+                
+               } else {
+                
+                       FinalBirthdayYear = wxString::Format(wxT("%i"), BirthdayYear);
+                
+               }
+            
+               if (!DataAfterT.IsEmpty()){
+                
+                       FinalBirthdayString = FinalBirthdayYear + FinalBirthdayMonth + FinalBirthdayDay + wxT("T") + DataAfterT;
+                
+               } else {
+                
+                       FinalBirthdayString = FinalBirthdayYear + FinalBirthdayMonth + FinalBirthdayDay;
+                
+               }
+               
+               if(!FinalBirthdayString.IsEmpty()){
+                       
+                       ContactEditorData.Birthday = FinalBirthdayString;
+                       
+               }
+               
+       }
+       
+       // Process Anniversary: Get Day, Month & Year.
+       
+       wxDateTime AnniversaryDate;
+       wxDateTime::Month AnniversaryMonth;
+       int AnniversaryDay;
+       int AnniversaryYear;
+       DataBeforeT = "";
+       DataAfterT = "";
+       wxString FinalAnniversaryString;
+       ProcessDataAfterT = FALSE;
+        
+       AnniversaryDate = dapAnniversary->GetValue();
+        
+       if (!txtAnniversary->IsEmpty()){
+       
+               // Birthday value is text so use this.
+               
+               ContactEditorData.Anniversary = txtAnniversary->GetValue();
+               
+       } else if (AnniversaryDate.IsValid()){
+            
+               AnniversaryDay = AnniversaryDate.GetDay();
+               AnniversaryMonth = AnniversaryDate.GetMonth();
+               AnniversaryYear = AnniversaryDate.GetYear();
+            
+               // Look for T and replace data before this.
+            
+               wxStringTokenizer wSTDate(ContactEditorData.Anniversary, wxT("T"));
+            
+               while (wSTDate.HasMoreTokens()){
+                
+                       if (ProcessDataAfterT == FALSE){
+                    
+                               DataBeforeT = wSTDate.GetNextToken();
+                               ProcessDataAfterT = TRUE;
+                    
+                       } else {
+                    
+                               DataAfterT = wSTDate.GetNextToken();
+                               break;
+                    
+                       }
+                
+               }
+            
+               // If there is not T then replace altogether.
+            
+               wxString FinalAnniversaryDay;
+               wxString FinalAnniversaryMonth;
+               wxString FinalAnniversaryYear;
+           
+               if (AnniversaryDay < 10){
+                
+                       FinalAnniversaryDay = wxT("0") + wxString::Format(wxT("%i"), AnniversaryDay);
+                
+               } else {
+                
+                       FinalAnniversaryDay = wxString::Format(wxT("%i"), AnniversaryDay);
+                
+               }
+            
+               if (((int)AnniversaryMonth + 1) < 10){
+                
+                       FinalAnniversaryMonth = wxT("0") + wxString::Format(wxT("%i"), ((int)AnniversaryMonth + 1));
+                
+               } else {
+                
+                       FinalAnniversaryMonth = wxString::Format(wxT("%i"), ((int)AnniversaryMonth + 1));
+                
+               }
+            
+               if (AnniversaryYear == 0){
+                
+                       FinalAnniversaryYear = wxT("--");
+                
+               } else {
+                
+                       FinalAnniversaryYear = wxString::Format(wxT("%i"), AnniversaryYear);
+                
+               }
+            
+               if (!DataAfterT.IsEmpty()){
+                
+                       FinalAnniversaryString = FinalAnniversaryYear + FinalAnniversaryMonth + FinalAnniversaryDay + wxT("T") + DataAfterT;
+                
+               } else {
+                
+                       FinalAnniversaryString = FinalAnniversaryYear + FinalAnniversaryMonth + FinalAnniversaryDay;
+                
+               }
+               
+               if(!FinalAnniversaryString.IsEmpty()){
+                       
+                       ContactEditorData.Birthday = FinalAnniversaryString;
+                       
+               }
+       
+       }
+       
+       // Process full name.
+       
+       if (ContactEditorData.FullNamesList.size() > 0){
+               
+               ContactEditorData.FullNamesList[0] = cmbDisplayAs->GetValue();
+               
+       } else {
+               
+               ContactEditorData.FullNamesList.insert(std::make_pair(0, cmbDisplayAs->GetValue()));
+               ContactEditorData.FullNamesListAltID.insert(std::make_pair(0, wxT("")));
+               ContactEditorData.FullNamesListPID.insert(std::make_pair(0, wxT("")));
+               ContactEditorData.FullNamesListType.insert(std::make_pair(0, wxT("")));
+               ContactEditorData.FullNamesListLanguage.insert(std::make_pair(0, wxT("")));
+               ContactEditorData.FullNamesListPref.insert(std::make_pair(0, 0));
+               ContactEditorData.FullNamesListTokens.insert(std::make_pair(0, wxT("")));
+               
+       }
+               
+       /*ContactData.Add(wxT("BEGIN"), wxT("VCARD"), FALSE);
        ContactData.Add(wxT("VERSION"), wxT("4.0"), FALSE);
     
        // Setup the version string.
@@ -2199,10 +2425,11 @@ void frmContactEditor::SaveContact( wxCommandEvent& event )
     
        // End the vCard File.
     
-       ContactData.Add(wxT("END"), wxT("VCARD"), FALSE);
+       ContactData.Add(wxT("END"), wxT("VCARD"), FALSE);*/
     
        FMTimer.Stop();
-       ContactData.WriteFile(FilenameFinal);
+       ContactEditorData.SaveFile(FilenameFinal);
+       //ContactData.WriteFile(FilenameFinal);
     
        vCard34Conv ConvFileFun;
     
@@ -2335,10 +2562,18 @@ void frmContactEditor::SaveContact( wxCommandEvent& event )
        // TODO: Workout nickname settings by priority and
        // type.
     
+       vCardName NameData;
+       
+       NameData.Forename = txtForename->GetValue();
+       NameData.Surname = txtSurname->GetValue();
+       NameData.OtherNames = txtOtherNames->GetValue();
+       NameData.Title = txtTitle->GetValue();
+       NameData.Suffix = txtSuffix->GetValue();
+       
        ucd->ContactAccount = wxSContactAccount;
        ucd->ContactFilename = FilenameFinal;
        ucd->ContactName = cmbDisplayAs->GetValue();
-       ucd->ContactNameArray = ContactData.GetName();
+       ucd->ContactNameArray = NameData;
     
        for (std::map<int,wxString>::iterator gniter = ContactEditorData.GeneralNicknamesList.begin();
                gniter != ContactEditorData.GeneralNicknamesList.end(); gniter++){
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