From: Steve Brokenshire Date: Sun, 3 Jul 2016 23:11:39 +0000 (+0100) Subject: Altered SaveContact in frmContactEditor to use the ContactDataObject X-Git-Tag: release-0.14~14 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=df9d3b01ecdfa3b0291eded5f374c550ff8903a3;p=xestiaab%2F.git Altered SaveContact in frmContactEditor to use the ContactDataObject 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. --- diff --git a/source/contacteditor/frmContactEditor-Save.cpp b/source/contacteditor/frmContactEditor-Save.cpp index 24beefd..bf743ee 100644 --- a/source/contacteditor/frmContactEditor-Save.cpp +++ b/source/contacteditor/frmContactEditor-Save.cpp @@ -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::iterator intiter; std::map::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::iterator gniter = ContactEditorData.GeneralNicknamesList.begin(); gniter != ContactEditorData.GeneralNicknamesList.end(); gniter++){