1 #include "frmContactEditor.h"
3 void frmContactEditor::LoadTelephone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TelCount){
5 // Check TEL and make sure it is functioning properly.
7 size_t intPropertyLen = wxSPropertySeg1.Len();
8 std::map<int, int> SplitPoints;
9 std::map<int, int> SplitLength;
10 std::map<int, int> TypeSplitPoints;
11 std::map<int, int> TypeSplitLength;
12 std::map<int, int>::iterator SLiter;
13 std::map<int, int>::iterator SPoint;
14 std::map<int, int>::iterator TSLiter;
15 std::map<int, int>::iterator TSPoint;
16 wxString PropertyData;
17 wxString PropertyName;
18 wxString PropertyValue;
19 wxString PropertyTokens;
23 wxString TelTypeDetail;
24 bool FirstToken = TRUE;
25 int intSplitsFound = 0;
30 int intSplitPoint = 0;
33 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
37 // Look for type before continuing.
39 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
40 intiter != SplitPoints.end(); ++intiter){
42 SLiter = SplitLength.find(intiter->first);
44 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
46 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
47 PropertyName = PropertyElement.GetNextToken();
48 PropertyValue = PropertyElement.GetNextToken();
50 intPrevValue = intiter->second;
52 if (PropertyName == wxT("TYPE")){
54 // Process each value in type and translate each
57 // Strip out the quotes if they are there.
59 size_t intPropertyValueLen = PropertyValue.Len();
61 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
64 PropertyValue.RemoveLast();
68 if (PropertyValue.Mid(0, 1) == wxT("\"")){
70 PropertyValue.Remove(0, 1);
74 TelTypeDetail = PropertyValue;
80 for (int i = 0; i <= intPropertyValueLen; i++){
84 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
86 if (intSplitsFound == 0){
88 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
89 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
93 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
94 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
107 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
108 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
112 for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin();
113 typeiter != TypeSplitPoints.end(); ++typeiter){
115 wxString TypePropertyName;
117 TSLiter = TypeSplitLength.find(typeiter->first);
119 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
121 if (intTypeSeek == 0){
126 TelTypeUI.Append(wxT(","));
130 if (TypePropertyName == wxT("home")){
134 } else if (TypePropertyName == wxT("work")){
141 if (TypePropertyName == wxT("text")){
143 TelTypeUI.Append(_("text"));
146 } else if (TypePropertyName == wxT("voice")){
148 TelTypeUI.Append(_("voice"));
151 } else if (TypePropertyName == wxT("fax")){
153 TelTypeUI.Append(_("fax"));
156 } else if (TypePropertyName == wxT("cell")){
158 TelTypeUI.Append(_("mobile"));
161 } else if (TypePropertyName == wxT("video")){
163 TelTypeUI.Append(_("video"));
166 } else if (TypePropertyName == wxT("pager")){
168 TelTypeUI.Append(_("pager"));
171 } else if (TypePropertyName == wxT("textphone")){
173 TelTypeUI.Append(_("textphone"));
186 // Setup blank lines for later on.
190 GeneralTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
191 GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
192 GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
193 GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
194 GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
196 } else if (intType == 1){
198 HomeTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
199 HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
200 HomeTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
201 HomeTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
202 HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
204 } else if (intType == 2){
206 BusinessTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
207 BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
208 BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
209 BusinessTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
210 BusinessTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
216 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
217 intiter != SplitPoints.end(); ++intiter){
219 SLiter = SplitLength.find(intiter->first);
221 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
223 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
224 PropertyName = PropertyElement.GetNextToken();
225 PropertyValue = PropertyElement.GetNextToken();
227 intPrevValue = intiter->second;
229 size_t intPropertyValueLen = PropertyValue.Len();
231 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
233 PropertyValue.Trim();
234 PropertyValue.RemoveLast();
238 if (PropertyValue.Mid(0, 1) == wxT("\"")){
240 PropertyValue.Remove(0, 1);
244 ProcessCaptureStrings(&PropertyValue);
246 // Process properties.
248 if (PropertyName == wxT("ALTID")){
250 if (intType == 0){ GeneralTelephoneListAltID.erase(intValueSeek); GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
251 else if (intType == 1){ HomeTelephoneListAltID.erase(intValueSeek); HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
252 else if (intType == 2){ BusinessTelephoneListAltID.erase(intValueSeek); BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
254 } else if (PropertyName == wxT("PID")){
256 if (intType == 0){ GeneralTelephoneListPID.erase(intValueSeek); GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
257 else if (intType == 1){ HomeTelephoneListPID.erase(intValueSeek); HomeTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
258 else if (intType == 2){ BusinessTelephoneListPID.erase(intValueSeek); BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
260 } else if (PropertyName == wxT("PREF")){
262 intPref = wxAtoi(PropertyValue);
264 if (intPref > 0 && intPref < 101){
266 if (intType == 0){ GeneralTelephoneListPref.erase(intValueSeek); GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
267 else if (intType == 1){ HomeTelephoneListPref.erase(intValueSeek); HomeTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
268 else if (intType == 2){ BusinessTelephoneListPref.erase(intValueSeek); BusinessTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
274 // Something else we don't know about so append
275 // to the tokens variable.
277 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
279 if (FirstToken == TRUE){
281 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
286 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
296 // Split the address.
298 //std::map<int, int>::iterator SLiter;
299 intPropertyLen = wxSPropertySeg2.Len();
306 for (int i = 0; i <= intPropertyLen; i++){
310 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
313 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
315 if (intSplitsFound == 1){
317 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
328 // Split the data into several parts.
330 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
331 intiter != SplitPoints.end(); ++intiter){
333 if (intiter->first == 1){
337 SLiter = SplitLength.find(1);
339 //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
340 TelType = wxSPropertySeg2.Mid(0, SLiter->second);
341 intPrevValue = intiter->second;
343 TelNumber = wxSPropertySeg2.Mid(intPrevValue);
349 // Add the data to the General/Home/Work address variables.
351 ProcessCaptureStrings(&PropertyValue);
354 coldata.SetId(intValueSeek);
355 coldata.SetData(intValueSeek);
356 coldata.SetText(TelNumber);
360 ListCtrlIndex = lboTelephone->InsertItem(coldata);
362 lboTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
364 if (intPref > 0 && intPref < 101){
366 lboTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
370 GeneralTelephoneList.erase(intValueSeek);
371 GeneralTelephoneListType.erase(intValueSeek);
372 GeneralTelephoneListTokens.erase(intValueSeek);
373 GeneralTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
374 GeneralTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
375 GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
377 } else if (intType == 1){
379 ListCtrlIndex = lboHomeTelephone->InsertItem(coldata);
381 lboHomeTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
383 if (intPref > 0 && intPref < 101){
385 lboHomeTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
389 HomeTelephoneList.erase(intValueSeek);
390 HomeTelephoneListType.erase(intValueSeek);
391 HomeTelephoneListTokens.erase(intValueSeek);
392 HomeTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
393 HomeTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
394 HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
396 } else if (intType == 2){
398 ListCtrlIndex = lboBusinessTelephone->InsertItem(coldata);
400 lboBusinessTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
402 if (intPref > 0 && intPref < 101){
404 lboBusinessTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
408 BusinessTelephoneList.erase(intValueSeek);
409 BusinessTelephoneListType.erase(intValueSeek);
410 BusinessTelephoneListTokens.erase(intValueSeek);
411 BusinessTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
412 BusinessTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
413 BusinessTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));