1 // frmContactEditor-LoadTelephone.cpp - frmContactEditor load telephone 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::LoadTelephone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TelCount){
23 // Check TEL and make sure it is functioning properly.
25 size_t intPropertyLen = wxSPropertySeg1.Len();
26 std::map<int, int> SplitPoints;
27 std::map<int, int> SplitLength;
28 std::map<int, int> TypeSplitPoints;
29 std::map<int, int> TypeSplitLength;
30 std::map<int, int>::iterator SLiter;
31 std::map<int, int>::iterator SPoint;
32 std::map<int, int>::iterator TSLiter;
33 std::map<int, int>::iterator TSPoint;
34 wxString PropertyData;
35 wxString PropertyName;
36 wxString PropertyValue;
37 wxString PropertyTokens;
41 wxString TelTypeDetail;
42 bool FirstToken = TRUE;
43 int intSplitsFound = 0;
48 int intSplitPoint = 0;
51 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
55 // Look for type before continuing.
57 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
58 intiter != SplitPoints.end(); ++intiter){
60 SLiter = SplitLength.find(intiter->first);
62 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
64 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
65 PropertyName = PropertyElement.GetNextToken();
66 PropertyValue = PropertyElement.GetNextToken();
68 intPrevValue = intiter->second;
70 if (PropertyName == wxT("TYPE")){
72 // Process each value in type and translate each
75 // Strip out the quotes if they are there.
77 size_t intPropertyValueLen = PropertyValue.Len();
79 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
82 PropertyValue.RemoveLast();
86 if (PropertyValue.Mid(0, 1) == wxT("\"")){
88 PropertyValue.Remove(0, 1);
92 TelTypeDetail = PropertyValue;
98 for (int i = 0; i <= intPropertyValueLen; i++){
102 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
104 if (intSplitsFound == 0){
106 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
107 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
111 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
112 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
125 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
126 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
130 for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin();
131 typeiter != TypeSplitPoints.end(); ++typeiter){
133 wxString TypePropertyName;
135 TSLiter = TypeSplitLength.find(typeiter->first);
137 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
139 if (intTypeSeek == 0){
144 TelTypeUI.Append(wxT(","));
148 if (TypePropertyName == wxT("home")){
152 } else if (TypePropertyName == wxT("work")){
159 if (TypePropertyName == wxT("text")){
161 TelTypeUI.Append(_("text"));
164 } else if (TypePropertyName == wxT("voice")){
166 TelTypeUI.Append(_("voice"));
169 } else if (TypePropertyName == wxT("fax")){
171 TelTypeUI.Append(_("fax"));
174 } else if (TypePropertyName == wxT("cell")){
176 TelTypeUI.Append(_("mobile"));
179 } else if (TypePropertyName == wxT("video")){
181 TelTypeUI.Append(_("video"));
184 } else if (TypePropertyName == wxT("pager")){
186 TelTypeUI.Append(_("pager"));
189 } else if (TypePropertyName == wxT("textphone")){
191 TelTypeUI.Append(_("textphone"));
204 // Setup blank lines for later on.
208 GeneralTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
209 GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
210 GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
211 GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
212 GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
214 } else if (intType == 1){
216 HomeTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
217 HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
218 HomeTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
219 HomeTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
220 HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
222 } else if (intType == 2){
224 BusinessTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
225 BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
226 BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
227 BusinessTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
228 BusinessTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
234 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
235 intiter != SplitPoints.end(); ++intiter){
237 SLiter = SplitLength.find(intiter->first);
239 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
241 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
242 PropertyName = PropertyElement.GetNextToken();
243 PropertyValue = PropertyElement.GetNextToken();
245 intPrevValue = intiter->second;
247 size_t intPropertyValueLen = PropertyValue.Len();
249 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
251 PropertyValue.Trim();
252 PropertyValue.RemoveLast();
256 if (PropertyValue.Mid(0, 1) == wxT("\"")){
258 PropertyValue.Remove(0, 1);
262 ProcessCaptureStrings(&PropertyValue);
264 // Process properties.
266 if (PropertyName == wxT("ALTID")){
268 if (intType == 0){ GeneralTelephoneListAltID.erase(intValueSeek); GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
269 else if (intType == 1){ HomeTelephoneListAltID.erase(intValueSeek); HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
270 else if (intType == 2){ BusinessTelephoneListAltID.erase(intValueSeek); BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
272 } else if (PropertyName == wxT("PID")){
274 if (intType == 0){ GeneralTelephoneListPID.erase(intValueSeek); GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
275 else if (intType == 1){ HomeTelephoneListPID.erase(intValueSeek); HomeTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
276 else if (intType == 2){ BusinessTelephoneListPID.erase(intValueSeek); BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
278 } else if (PropertyName == wxT("PREF")){
280 intPref = wxAtoi(PropertyValue);
282 if (intPref > 0 && intPref < 101){
284 if (intType == 0){ GeneralTelephoneListPref.erase(intValueSeek); GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
285 else if (intType == 1){ HomeTelephoneListPref.erase(intValueSeek); HomeTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
286 else if (intType == 2){ BusinessTelephoneListPref.erase(intValueSeek); BusinessTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
292 // Something else we don't know about so append
293 // to the tokens variable.
295 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
297 if (FirstToken == TRUE){
299 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
304 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
314 // Split the address.
316 //std::map<int, int>::iterator SLiter;
317 intPropertyLen = wxSPropertySeg2.Len();
324 for (int i = 0; i <= intPropertyLen; i++){
328 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
331 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
333 if (intSplitsFound == 1){
335 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
346 // Split the data into several parts.
348 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
349 intiter != SplitPoints.end(); ++intiter){
351 if (intiter->first == 1){
355 SLiter = SplitLength.find(1);
357 //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
358 TelType = wxSPropertySeg2.Mid(0, SLiter->second);
359 intPrevValue = intiter->second;
361 TelNumber = wxSPropertySeg2.Mid(intPrevValue);
367 // Add the data to the General/Home/Work address variables.
369 ProcessCaptureStrings(&PropertyValue);
372 coldata.SetId(intValueSeek);
373 coldata.SetData(intValueSeek);
374 coldata.SetText(TelNumber);
378 ListCtrlIndex = lboTelephone->InsertItem(coldata);
380 lboTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
382 if (intPref > 0 && intPref < 101){
384 lboTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
388 GeneralTelephoneList.erase(intValueSeek);
389 GeneralTelephoneListType.erase(intValueSeek);
390 GeneralTelephoneListTokens.erase(intValueSeek);
391 GeneralTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
392 GeneralTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
393 GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
395 } else if (intType == 1){
397 ListCtrlIndex = lboHomeTelephone->InsertItem(coldata);
399 lboHomeTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
401 if (intPref > 0 && intPref < 101){
403 lboHomeTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
407 HomeTelephoneList.erase(intValueSeek);
408 HomeTelephoneListType.erase(intValueSeek);
409 HomeTelephoneListTokens.erase(intValueSeek);
410 HomeTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
411 HomeTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
412 HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
414 } else if (intType == 2){
416 ListCtrlIndex = lboBusinessTelephone->InsertItem(coldata);
418 lboBusinessTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
420 if (intPref > 0 && intPref < 101){
422 lboBusinessTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
426 BusinessTelephoneList.erase(intValueSeek);
427 BusinessTelephoneListType.erase(intValueSeek);
428 BusinessTelephoneListTokens.erase(intValueSeek);
429 BusinessTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
430 BusinessTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
431 BusinessTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));