1 // frmContactEditor-LoadTitle.cpp - frmContactEditor load title subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditor.h"
21 void frmContactEditor::LoadTitle(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TitleCount){
23 std::map<int, int> SplitPoints;
24 std::map<int, int> SplitLength;
25 std::map<int, int>::iterator SLiter;
26 wxString PropertyData;
27 wxString PropertyName;
28 wxString PropertyValue;
29 wxString PropertyTokens;
30 bool FirstToken = TRUE;
36 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
40 // Look for type before continuing.
42 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
43 intiter != SplitPoints.end(); ++intiter){
45 SLiter = SplitLength.find(intiter->first);
47 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
49 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
50 PropertyName = PropertyElement.GetNextToken();
51 PropertyValue = PropertyElement.GetNextToken();
53 intPrevValue = intiter->second;
55 if (PropertyName == wxT("TYPE")){
57 if (PropertyValue == wxT("work")){
61 } else if (PropertyValue == wxT("home")){
75 // Setup blank lines for later on.
79 GeneralTitleList.insert(std::make_pair(intValueSeek, wxT("")));
80 GeneralTitleListAltID.insert(std::make_pair(intValueSeek, wxT("")));
81 GeneralTitleListPID.insert(std::make_pair(intValueSeek, wxT("")));
82 GeneralTitleListPref.insert(std::make_pair(intValueSeek, 0));
83 GeneralTitleListTokens.insert(std::make_pair(intValueSeek, wxT("")));
84 GeneralTitleListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
86 } else if (intType == 1){
88 HomeTitleList.insert(std::make_pair(intValueSeek, wxT("")));
89 HomeTitleListAltID.insert(std::make_pair(intValueSeek, wxT("")));
90 HomeTitleListPID.insert(std::make_pair(intValueSeek, wxT("")));
91 HomeTitleListPref.insert(std::make_pair(intValueSeek, 0));
92 HomeTitleListTokens.insert(std::make_pair(intValueSeek, wxT("")));
93 HomeTitleListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
95 } else if (intType == 2){
97 BusinessTitleList.insert(std::make_pair(intValueSeek, wxT("")));
98 BusinessTitleListAltID.insert(std::make_pair(intValueSeek, wxT("")));
99 BusinessTitleListPID.insert(std::make_pair(intValueSeek, wxT("")));
100 BusinessTitleListPref.insert(std::make_pair(intValueSeek, 0));
101 BusinessTitleListTokens.insert(std::make_pair(intValueSeek, wxT("")));
102 BusinessTitleListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
108 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
109 intiter != SplitPoints.end(); ++intiter){
111 SLiter = SplitLength.find(intiter->first);
113 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
115 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
116 PropertyName = PropertyElement.GetNextToken();
117 PropertyValue = PropertyElement.GetNextToken();
119 intPrevValue = intiter->second;
121 // Process properties.
123 size_t intPropertyValueLen = PropertyValue.Len();
125 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
127 PropertyValue.Trim();
128 PropertyValue.RemoveLast();
132 if (PropertyValue.Mid(0, 1) == wxT("\"")){
134 PropertyValue.Remove(0, 1);
138 ProcessCaptureStrings(&PropertyValue);
140 if (PropertyName == wxT("ALTID")){
142 if (intType == 0){ GeneralTitleListAltID.erase(intValueSeek); GeneralTitleListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
143 else if (intType == 1){ HomeTitleListAltID.erase(intValueSeek); HomeTitleListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
144 else if (intType == 2){ BusinessTitleListAltID.erase(intValueSeek); BusinessTitleListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
146 } else if (PropertyName == wxT("PID")){
148 if (intType == 0){ GeneralTitleListPID.erase(intValueSeek); GeneralTitleListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
149 else if (intType == 1){ HomeTitleListPID.erase(intValueSeek); HomeTitleListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
150 else if (intType == 2){ BusinessTitleListPID.erase(intValueSeek); BusinessTitleListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
152 } else if (PropertyName == wxT("PREF")){
154 intPref = wxAtoi(PropertyValue);
156 if (intType == 0){ GeneralTitleListPref.erase(intValueSeek); GeneralTitleListPref.insert(std::make_pair(intValueSeek, intPref)); }
157 else if (intType == 1){ HomeTitleListPref.erase(intValueSeek); HomeTitleListPref.insert(std::make_pair(intValueSeek, intPref)); }
158 else if (intType == 2){ BusinessTitleListPref.erase(intValueSeek); BusinessTitleListPref.insert(std::make_pair(intValueSeek, intPref)); }
160 } else if (PropertyName == wxT("LANGUAGE")){
162 if (intType == 0){ GeneralTitleListLanguage.erase(intValueSeek); GeneralTitleListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
163 else if (intType == 1){ HomeTitleListLanguage.erase(intValueSeek); HomeTitleListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
164 else if (intType == 2){ BusinessTitleListLanguage.erase(intValueSeek); BusinessTitleListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
168 // Something else we don't know about so append
169 // to the tokens variable.
171 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
173 if (FirstToken == TRUE){
175 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
180 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
190 // Add the data to the General/Home/Work address variables.
192 ProcessCaptureStrings(&wxSPropertySeg2);
196 coldata.SetId(intValueSeek);
197 coldata.SetData(intValueSeek);
198 coldata.SetText(wxSPropertySeg2);
202 ListCtrlIndex = lboTitles->InsertItem(coldata);
204 if (intPref > 0 && intPref < 101){
206 lboTitles->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
210 GeneralTitleList.erase(intValueSeek);
211 GeneralTitleListType.erase(intValueSeek);
212 GeneralTitleListTokens.erase(intValueSeek);
213 GeneralTitleList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
214 GeneralTitleListType.insert(std::make_pair(intValueSeek, wxT("")));
215 GeneralTitleListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
217 } else if (intType == 1){
219 ListCtrlIndex = lboHomeTitles->InsertItem(coldata);
221 if (intPref > 0 && intPref < 101){
223 lboHomeTitles->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
227 HomeTitleList.erase(intValueSeek);
228 HomeTitleListType.erase(intValueSeek);
229 HomeTitleListTokens.erase(intValueSeek);
230 HomeTitleList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
231 HomeTitleListType.insert(std::make_pair(intValueSeek, wxT("home")));
232 HomeTitleListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
234 } else if (intType == 2){
236 ListCtrlIndex = lboBusinessTitles->InsertItem(coldata);
238 if (intPref > 0 && intPref < 101){
240 lboBusinessTitles->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
244 BusinessTitleList.erase(intValueSeek);
245 BusinessTitleListType.erase(intValueSeek);
246 BusinessTitleListTokens.erase(intValueSeek);
247 BusinessTitleList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
248 BusinessTitleListType.insert(std::make_pair(intValueSeek, wxT("work")));
249 BusinessTitleListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));