1 // frmContactEditor-LoadNickname.cpp - frmContactEditor load nickname 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::LoadNickname(wxString wxSPropertySeg1, wxString wxSPropertySeg2,
22 int *NicknameCount, vCard *ContactData){
24 std::map<int, int> SplitPoints;
25 std::map<int, int> SplitLength;
26 std::map<int, int>::iterator SLiter;
27 wxString PropertyData;
28 wxString PropertyName;
29 wxString PropertyValue;
30 wxString PropertyTokens;
31 bool FirstToken = TRUE;
32 int intPrevValue = 10;
37 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
41 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
42 intiter != SplitPoints.end(); ++intiter){
44 SLiter = SplitLength.find(intiter->first);
46 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
48 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
49 PropertyName = PropertyElement.GetNextToken();
50 PropertyValue = PropertyElement.GetNextToken();
52 intPrevValue = intiter->second;
54 if (PropertyName == wxT("TYPE")){
56 if (PropertyValue == wxT("work")){
60 } else if (PropertyValue == wxT("home")){
74 // Setup blank lines for later on.
78 GeneralNicknamesList.insert(std::make_pair(intValueSeek, wxT("")));
79 GeneralNicknamesListAltID.insert(std::make_pair(intValueSeek, wxT("")));
80 GeneralNicknamesListPID.insert(std::make_pair(intValueSeek, wxT("")));
81 GeneralNicknamesListPref.insert(std::make_pair(intValueSeek, 0));
82 GeneralNicknamesListTokens.insert(std::make_pair(intValueSeek, wxT("")));
83 GeneralNicknamesListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
85 } else if (intType == 1){
87 HomeNicknamesList.insert(std::make_pair(intValueSeek, wxT("")));
88 HomeNicknamesListAltID.insert(std::make_pair(intValueSeek, wxT("")));
89 HomeNicknamesListPID.insert(std::make_pair(intValueSeek, wxT("")));
90 HomeNicknamesListPref.insert(std::make_pair(intValueSeek, 0));
91 HomeNicknamesListTokens.insert(std::make_pair(intValueSeek, wxT("")));
92 HomeNicknamesListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
94 } else if (intType == 2){
96 BusinessNicknamesList.insert(std::make_pair(intValueSeek, wxT("")));
97 BusinessNicknamesListAltID.insert(std::make_pair(intValueSeek, wxT("")));
98 BusinessNicknamesListPID.insert(std::make_pair(intValueSeek, wxT("")));
99 BusinessNicknamesListPref.insert(std::make_pair(intValueSeek, 0));
100 BusinessNicknamesListTokens.insert(std::make_pair(intValueSeek, wxT("")));
101 BusinessNicknamesListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
107 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
108 intiter != SplitPoints.end(); ++intiter){
110 SLiter = SplitLength.find(intiter->first);
112 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
114 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
115 PropertyName = PropertyElement.GetNextToken();
116 PropertyValue = PropertyElement.GetNextToken();
118 intPrevValue = intiter->second;
120 ProcessCaptureStrings(&PropertyValue);
122 // Process properties.
124 size_t intPropertyValueLen = PropertyValue.Len();
126 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
128 PropertyValue.Trim();
129 PropertyValue.RemoveLast();
133 if (PropertyValue.Mid(0, 1) == wxT("\"")){
135 PropertyValue.Remove(0, 1);
139 if (PropertyName == wxT("ALTID")){
141 if (intType == 0){ GeneralNicknamesListAltID.erase(intValueSeek); GeneralNicknamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
142 else if (intType == 1){ HomeNicknamesListAltID.erase(intValueSeek); HomeNicknamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
143 else if (intType == 2){ BusinessNicknamesListAltID.erase(intValueSeek); BusinessNicknamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
145 } else if (PropertyName == wxT("PID")){
147 if (intType == 0){ GeneralNicknamesListPID.erase(intValueSeek); GeneralNicknamesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
148 else if (intType == 1){ HomeNicknamesListPID.erase(intValueSeek); HomeNicknamesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
149 else if (intType == 2){ BusinessNicknamesListPID.erase(intValueSeek); BusinessNicknamesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
151 } else if (PropertyName == wxT("PREF")){
153 intPref = wxAtoi(PropertyValue);
155 if (intType == 0){ GeneralNicknamesListPref.erase(intValueSeek); GeneralNicknamesListPref.insert(std::make_pair(intValueSeek, intPref)); }
156 else if (intType == 1){ HomeNicknamesListPref.erase(intValueSeek); HomeNicknamesListPref.insert(std::make_pair(intValueSeek, intPref)); }
157 else if (intType == 2){ BusinessNicknamesListPref.erase(intValueSeek); BusinessNicknamesListPref.insert(std::make_pair(intValueSeek, intPref)); }
159 } else if (PropertyName == wxT("LANGUAGE")){
161 if (intType == 0){ GeneralNicknamesListLanguage.erase(intValueSeek); GeneralNicknamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
162 else if (intType == 1){ HomeNicknamesListLanguage.erase(intValueSeek); HomeNicknamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
163 else if (intType == 2){ BusinessNicknamesListLanguage.erase(intValueSeek); BusinessNicknamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
167 // Something else we don't know about so append
168 // to the tokens variable.
170 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
172 if (FirstToken == TRUE){
174 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
179 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
189 // Add the data to the General/Home/Work address variables.
191 ProcessCaptureStrings(&wxSPropertySeg2);
195 coldata.SetId(intValueSeek);
196 coldata.SetData(intValueSeek);
197 coldata.SetText(wxSPropertySeg2);
201 ListCtrlIndex = lboNicknames->InsertItem(coldata);
203 if (intPref > 0 && intPref < 101){
205 lboNicknames->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
209 GeneralNicknamesList.erase(intValueSeek);
210 GeneralNicknamesListType.erase(intValueSeek);
211 GeneralNicknamesListTokens.erase(intValueSeek);
212 GeneralNicknamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
213 GeneralNicknamesListType.insert(std::make_pair(intValueSeek, wxT("")));
214 GeneralNicknamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
216 } else if (intType == 1){
218 ListCtrlIndex = lboHomeNicknames->InsertItem(coldata);
220 if (intPref > 0 && intPref < 101){
222 lboHomeNicknames->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
226 HomeNicknamesList.erase(intValueSeek);
227 HomeNicknamesListType.erase(intValueSeek);
228 HomeNicknamesListTokens.erase(intValueSeek);
229 HomeNicknamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
230 HomeNicknamesListType.insert(std::make_pair(intValueSeek, wxT("home")));
231 HomeNicknamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
233 } else if (intType == 2){
235 ListCtrlIndex = lboBusinessNicknames->InsertItem(coldata);
237 if (intPref > 0 && intPref < 101){
239 lboBusinessNicknames->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
243 BusinessNicknamesList.erase(intValueSeek);
244 BusinessNicknamesListType.erase(intValueSeek);
245 BusinessNicknamesListTokens.erase(intValueSeek);
246 BusinessNicknamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
247 BusinessNicknamesListType.insert(std::make_pair(intValueSeek, wxT("work")));
248 BusinessNicknamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));