1 // frmContactEditor-LoadOrg.cpp - frmContactEditor load organisation 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::LoadOrg(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *OrgCount){
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 GeneralOrganisationsList.insert(std::make_pair(intValueSeek, wxT("")));
80 GeneralOrganisationsListAltID.insert(std::make_pair(intValueSeek, wxT("")));
81 GeneralOrganisationsListPID.insert(std::make_pair(intValueSeek, wxT("")));
82 GeneralOrganisationsListPref.insert(std::make_pair(intValueSeek, 0));
83 GeneralOrganisationsListTokens.insert(std::make_pair(intValueSeek, wxT("")));
84 GeneralOrganisationsListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
85 GeneralOrganisationsListSortAs.insert(std::make_pair(intValueSeek, wxT("")));
87 } else if (intType == 1){
89 HomeOrganisationsList.insert(std::make_pair(intValueSeek, wxT("")));
90 HomeOrganisationsListAltID.insert(std::make_pair(intValueSeek, wxT("")));
91 HomeOrganisationsListPID.insert(std::make_pair(intValueSeek, wxT("")));
92 HomeOrganisationsListPref.insert(std::make_pair(intValueSeek, 0));
93 HomeOrganisationsListTokens.insert(std::make_pair(intValueSeek, wxT("")));
94 HomeOrganisationsListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
95 HomeOrganisationsListSortAs.insert(std::make_pair(intValueSeek, wxT("")));
97 } else if (intType == 2){
99 BusinessOrganisationsList.insert(std::make_pair(intValueSeek, wxT("")));
100 BusinessOrganisationsListAltID.insert(std::make_pair(intValueSeek, wxT("")));
101 BusinessOrganisationsListPID.insert(std::make_pair(intValueSeek, wxT("")));
102 BusinessOrganisationsListPref.insert(std::make_pair(intValueSeek, 0));
103 BusinessOrganisationsListTokens.insert(std::make_pair(intValueSeek, wxT("")));
104 BusinessOrganisationsListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
105 BusinessOrganisationsListSortAs.insert(std::make_pair(intValueSeek, wxT("")));
111 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
112 intiter != SplitPoints.end(); ++intiter){
114 SLiter = SplitLength.find(intiter->first);
116 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
118 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
119 PropertyName = PropertyElement.GetNextToken();
120 PropertyValue = PropertyElement.GetNextToken();
122 intPrevValue = intiter->second;
124 // Process properties.
126 size_t intPropertyValueLen = PropertyValue.Len();
128 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
130 PropertyValue.Trim();
131 PropertyValue.RemoveLast();
135 if (PropertyValue.Mid(0, 1) == wxT("\"")){
137 PropertyValue.Remove(0, 1);
141 ProcessCaptureStrings(&PropertyValue);
143 if (PropertyName == wxT("ALTID")){
145 if (intType == 0){ GeneralOrganisationsListAltID.erase(intValueSeek); GeneralOrganisationsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
146 else if (intType == 1){ HomeOrganisationsListAltID.erase(intValueSeek); HomeOrganisationsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
147 else if (intType == 2){ BusinessOrganisationsListAltID.erase(intValueSeek); BusinessOrganisationsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
149 } else if (PropertyName == wxT("PID")){
151 if (intType == 0){ GeneralOrganisationsListPID.erase(intValueSeek); GeneralOrganisationsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
152 else if (intType == 1){ HomeOrganisationsListPID.erase(intValueSeek); HomeOrganisationsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
153 else if (intType == 2){ BusinessOrganisationsListPID.erase(intValueSeek); BusinessOrganisationsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
155 } else if (PropertyName == wxT("PREF")){
157 intPref = wxAtoi(PropertyValue);
159 if (intType == 0){ GeneralOrganisationsListPref.erase(intValueSeek); GeneralOrganisationsListPref.insert(std::make_pair(intValueSeek, intPref)); }
160 else if (intType == 1){ HomeOrganisationsListPref.erase(intValueSeek); HomeOrganisationsListPref.insert(std::make_pair(intValueSeek, intPref)); }
161 else if (intType == 2){ BusinessOrganisationsListPref.erase(intValueSeek); BusinessOrganisationsListPref.insert(std::make_pair(intValueSeek, intPref)); }
163 } else if (PropertyName == wxT("LANGUAGE")){
165 if (intType == 0){ GeneralOrganisationsListLanguage.erase(intValueSeek); GeneralOrganisationsListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
166 else if (intType == 1){ HomeOrganisationsListLanguage.erase(intValueSeek); HomeOrganisationsListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
167 else if (intType == 2){ BusinessOrganisationsListLanguage.erase(intValueSeek); BusinessOrganisationsListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
169 } else if (PropertyName == wxT("SORT-AS")){
171 if (intType == 0){ GeneralOrganisationsListSortAs.erase(intValueSeek); GeneralOrganisationsListSortAs.insert(std::make_pair(intValueSeek, PropertyValue)); }
172 else if (intType == 1){ HomeOrganisationsListSortAs.erase(intValueSeek); HomeOrganisationsListSortAs.insert(std::make_pair(intValueSeek, PropertyValue)); }
173 else if (intType == 2){ BusinessOrganisationsListSortAs.erase(intValueSeek); BusinessOrganisationsListSortAs.insert(std::make_pair(intValueSeek, PropertyValue)); }
177 // Something else we don't know about so append
178 // to the tokens variable.
180 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
182 if (FirstToken == TRUE){
184 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
189 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
199 // Add the data to the General/Home/Work address variables.
203 ProcessCaptureStrings(&wxSPropertySeg2);
205 coldata.SetId(intValueSeek);
206 coldata.SetData(intValueSeek);
207 coldata.SetText(wxSPropertySeg2);
211 ListCtrlIndex = lboOrganisations->InsertItem(coldata);
213 if (intPref > 0 && intPref < 101){
215 lboOrganisations->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
219 GeneralOrganisationsList.erase(intValueSeek);
220 GeneralOrganisationsListType.erase(intValueSeek);
221 GeneralOrganisationsListTokens.erase(intValueSeek);
222 GeneralOrganisationsList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
223 GeneralOrganisationsListType.insert(std::make_pair(intValueSeek, wxT("")));
224 GeneralOrganisationsListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
226 } else if (intType == 1){
228 ListCtrlIndex = lboHomeOrganisations->InsertItem(coldata);
230 if (intPref > 0 && intPref < 101){
232 lboHomeOrganisations->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
236 HomeOrganisationsList.erase(intValueSeek);
237 HomeOrganisationsListType.erase(intValueSeek);
238 HomeOrganisationsListTokens.erase(intValueSeek);
239 HomeOrganisationsList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
240 HomeOrganisationsListType.insert(std::make_pair(intValueSeek, wxT("home")));
241 HomeOrganisationsListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
243 } else if (intType == 2){
245 ListCtrlIndex = lboBusinessOrganisations->InsertItem(coldata);
247 if (intPref > 0 && intPref < 101){
249 lboBusinessOrganisations->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
253 BusinessOrganisationsList.erase(intValueSeek);
254 BusinessOrganisationsListType.erase(intValueSeek);
255 BusinessOrganisationsListTokens.erase(intValueSeek);
256 BusinessOrganisationsList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
257 BusinessOrganisationsListType.insert(std::make_pair(intValueSeek, wxT("work")));
258 BusinessOrganisationsListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));