1 // frmContactEditor-LoadRelated.cpp - frmContactEditor load related 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::LoadRelated(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *RelatedCount){
23 size_t intPropertyLen = wxSPropertySeg1.Len();
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;
32 wxString RelatedTypeOriginal;
34 bool FirstToken = TRUE;
35 int intSplitsFound = 0;
41 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
45 // Look for type before continuing.
47 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
48 intiter != SplitPoints.end(); ++intiter){
50 SLiter = SplitLength.find(intiter->first);
52 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
54 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
55 PropertyName = PropertyElement.GetNextToken();
56 PropertyValue = PropertyElement.GetNextToken();
58 intPrevValue = intiter->second;
62 RelatedTypeOriginal = PropertyValue;
64 if (PropertyName == wxT("TYPE")){
66 if (PropertyValue == wxT("contact")){
68 RelatedType = _("Contact");
70 } else if (PropertyValue == wxT("acquaintance")){
72 RelatedType = _("Acquaintance");
74 } else if (PropertyValue == wxT("friend")){
76 RelatedType = _("Friend");
78 } else if (PropertyValue == wxT("met")){
80 RelatedType = _("Met");
82 } else if (PropertyValue == wxT("co-worker")){
84 RelatedType = _("Co-worker");
86 } else if (PropertyValue == wxT("colleague")){
88 RelatedType = _("Colleague");
90 } else if (PropertyValue == wxT("co-resident")){
92 RelatedType = _("Co-resident");
94 } else if (PropertyValue == wxT("neighbor")){
96 RelatedType = _("Neighbour");
98 } else if (PropertyValue == wxT("child")){
100 RelatedType = _("Child");
102 } else if (PropertyValue == wxT("parent")){
104 RelatedType = _("Parent");
106 } else if (PropertyValue == wxT("sibling")){
108 RelatedType = _("Sibling");
110 } else if (PropertyValue == wxT("spouse")){
112 RelatedType = _("Spouse");
114 } else if (PropertyValue == wxT("kin")){
116 RelatedType = _("Kin");
118 } else if (PropertyValue == wxT("muse")){
120 RelatedType = _("Muse");
122 } else if (PropertyValue == wxT("crush")){
124 RelatedType = _("Crush");
126 } else if (PropertyValue == wxT("date")){
128 RelatedType = _("Date");
130 } else if (PropertyValue == wxT("sweetheart")){
132 RelatedType = _("Sweetheart");
134 } else if (PropertyValue == wxT("me")){
136 RelatedType = _("Me");
138 } else if (PropertyValue == wxT("agent")){
140 RelatedType = _("Agent");
142 } else if (PropertyValue == wxT("emergency")){
144 RelatedType = _("Emergency");
148 RelatedType = PropertyValue;
158 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
159 intiter != SplitPoints.end(); ++intiter){
161 SLiter = SplitLength.find(intiter->first);
163 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
165 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
166 PropertyName = PropertyElement.GetNextToken();
167 PropertyValue = PropertyElement.GetNextToken();
169 intPrevValue = intiter->second;
171 // Process properties.
173 size_t intPropertyValueLen = PropertyValue.Len();
175 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
177 PropertyValue.Trim();
178 PropertyValue.RemoveLast();
182 if (PropertyValue.Mid(0, 1) == wxT("\"")){
184 PropertyValue.Remove(0, 1);
188 ProcessCaptureStrings(&PropertyValue);
190 if (PropertyName == wxT("ALTID")){
192 GeneralRelatedListAltID.erase(intValueSeek);
193 GeneralRelatedListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
195 } else if (PropertyName == wxT("PID")){
197 GeneralRelatedListPID.erase(intValueSeek);
198 GeneralRelatedListPID.insert(std::make_pair(intValueSeek, PropertyValue));
200 } else if (PropertyName == wxT("PREF")){
202 intPref = wxAtoi(PropertyValue);
204 if (intPref > 0 && intPref < 101){
206 GeneralRelatedListPref.erase(intValueSeek);
207 GeneralRelatedListPref.insert(std::make_pair(intValueSeek, intPref));
212 } else if (PropertyName == wxT("LANGUAGE")){
214 GeneralRelatedListLanguage.erase(intValueSeek);
215 GeneralRelatedListLanguage.insert(std::make_pair(intValueSeek, PropertyValue));
219 // Something else we don't know about so append
220 // to the tokens variable.
222 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
224 if (FirstToken == TRUE){
226 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
231 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
241 // Split the address.
243 //std::map<int, int>::iterator SLiter;
244 intPropertyLen = wxSPropertySeg2.Len();
251 // Add the data to the General/Home/Work address variables.
255 coldata.SetId(intValueSeek);
256 coldata.SetData(intValueSeek);
257 coldata.SetText(RelatedType);
259 ProcessCaptureStrings(&wxSPropertySeg2);
261 ListCtrlIndex = lboRelated->InsertItem(coldata);
263 lboRelated->SetItem(ListCtrlIndex, 1, wxSPropertySeg2);
265 if (intPref > 0 && intPref < 101){
267 lboRelated->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
271 GeneralRelatedList.erase(intValueSeek);
272 GeneralRelatedListRelType.erase(intValueSeek);
273 GeneralRelatedListType.erase(intValueSeek);
274 GeneralRelatedListTokens.erase(intValueSeek);
275 GeneralRelatedList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
276 GeneralRelatedListRelType.insert(std::make_pair(intValueSeek, RelatedTypeOriginal));
277 GeneralRelatedListType.insert(std::make_pair(intValueSeek, RelatedTypeOriginal));
278 GeneralRelatedListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));