1 // frmContactEditor-LoadLanguages.cpp - frmContactEditor load languages 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::LoadLanguage(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *LangCount){
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 GeneralLanguageList.insert(std::make_pair(intValueSeek, wxT("")));
80 GeneralLanguageListAltID.insert(std::make_pair(intValueSeek, wxT("")));
81 GeneralLanguageListPID.insert(std::make_pair(intValueSeek, wxT("")));
82 GeneralLanguageListPref.insert(std::make_pair(intValueSeek, 0));
83 GeneralLanguageListTokens.insert(std::make_pair(intValueSeek, wxT("")));
85 } else if (intType == 1){
87 HomeLanguageList.insert(std::make_pair(intValueSeek, wxT("")));
88 HomeLanguageListAltID.insert(std::make_pair(intValueSeek, wxT("")));
89 HomeLanguageListPID.insert(std::make_pair(intValueSeek, wxT("")));
90 HomeLanguageListPref.insert(std::make_pair(intValueSeek, 0));
91 HomeLanguageListTokens.insert(std::make_pair(intValueSeek, wxT("")));
93 } else if (intType == 2){
95 BusinessLanguageList.insert(std::make_pair(intValueSeek, wxT("")));
96 BusinessLanguageListAltID.insert(std::make_pair(intValueSeek, wxT("")));
97 BusinessLanguageListPID.insert(std::make_pair(intValueSeek, wxT("")));
98 BusinessLanguageListPref.insert(std::make_pair(intValueSeek, 0));
99 BusinessLanguageListTokens.insert(std::make_pair(intValueSeek, wxT("")));
105 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
106 intiter != SplitPoints.end(); ++intiter){
108 SLiter = SplitLength.find(intiter->first);
110 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
112 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
113 PropertyName = PropertyElement.GetNextToken();
114 PropertyValue = PropertyElement.GetNextToken();
116 intPrevValue = intiter->second;
118 // Process properties.
120 size_t intPropertyValueLen = PropertyValue.Len();
122 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
124 PropertyValue.Trim();
125 PropertyValue.RemoveLast();
129 if (PropertyValue.Mid(0, 1) == wxT("\"")){
131 PropertyValue.Remove(0, 1);
135 ProcessCaptureStrings(&PropertyValue);
137 if (PropertyName == wxT("ALTID")){
139 if (intType == 0){ GeneralLanguageListAltID.erase(intValueSeek); GeneralLanguageListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
140 else if (intType == 1){ HomeLanguageListAltID.erase(intValueSeek); HomeLanguageListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
141 else if (intType == 2){ BusinessLanguageListAltID.erase(intValueSeek); BusinessLanguageListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
143 } else if (PropertyName == wxT("PID")){
145 if (intType == 0){ GeneralLanguageListPID.erase(intValueSeek); GeneralLanguageListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
146 else if (intType == 1){ HomeLanguageListPID.erase(intValueSeek); HomeLanguageListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
147 else if (intType == 2){ BusinessLanguageListPID.erase(intValueSeek); BusinessLanguageListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
149 } else if (PropertyName == wxT("PREF")){
151 intPref = wxAtoi(PropertyValue);
153 if (intType == 0){ GeneralLanguageListPref.erase(intValueSeek); GeneralLanguageListPref.insert(std::make_pair(intValueSeek, intPref)); }
154 else if (intType == 1){ HomeLanguageListPref.erase(intValueSeek); HomeLanguageListPref.insert(std::make_pair(intValueSeek, intPref)); }
155 else if (intType == 2){ BusinessLanguageListPref.erase(intValueSeek); BusinessLanguageListPref.insert(std::make_pair(intValueSeek, intPref)); }
159 // Something else we don't know about so append
160 // to the tokens variable.
162 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
164 if (FirstToken == TRUE){
166 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
171 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
181 // Add the data to the General/Home/Work address variables.
183 ProcessCaptureStrings(&wxSPropertySeg2);
187 coldata.SetId(intValueSeek);
188 coldata.SetData(intValueSeek);
189 coldata.SetText(wxSPropertySeg2);
193 ListCtrlIndex = lboLanguages->InsertItem(coldata);
195 if (intPref > 0 && intPref < 101){
197 lboLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
201 GeneralLanguageList.erase(intValueSeek);
202 GeneralLanguageListType.erase(intValueSeek);
203 GeneralLanguageListTokens.erase(intValueSeek);
204 GeneralLanguageList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
205 GeneralLanguageListType.insert(std::make_pair(intValueSeek, wxT("")));
206 GeneralLanguageListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
208 } else if (intType == 1){
210 ListCtrlIndex = lboHomeLanguages->InsertItem(coldata);
212 if (intPref > 0 && intPref < 101){
214 lboHomeLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
218 HomeLanguageList.erase(intValueSeek);
219 HomeLanguageListType.erase(intValueSeek);
220 HomeLanguageListTokens.erase(intValueSeek);
221 HomeLanguageList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
222 HomeLanguageListType.insert(std::make_pair(intValueSeek, wxT("home")));
223 HomeLanguageListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
225 } else if (intType == 2){
227 ListCtrlIndex = lboBusinessLanguages->InsertItem(coldata);
229 if (intPref > 0 && intPref < 101){
231 lboBusinessLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
235 BusinessLanguageList.erase(intValueSeek);
236 BusinessLanguageListType.erase(intValueSeek);
237 BusinessLanguageListTokens.erase(intValueSeek);
238 BusinessLanguageList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
239 BusinessLanguageListType.insert(std::make_pair(intValueSeek, wxT("work")));
240 BusinessLanguageListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));