Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ source and header files in the contacte...
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadLanguage.cpp
1 // frmContactEditor-LoadLanguages.cpp - frmContactEditor load languages subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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;
31         int intPrevValue = 6;
32         int intPref = 0;                        
33         int intType = 0;
34         long ListCtrlIndex;
35         
36         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
37         
38         intPrevValue = 5;
39         
40         // Look for type before continuing.
41         
42         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
43         intiter != SplitPoints.end(); ++intiter){
44         
45                 SLiter = SplitLength.find(intiter->first);
46         
47                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
48                 
49                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
50                 PropertyName = PropertyElement.GetNextToken();                          
51                 PropertyValue = PropertyElement.GetNextToken();
52                 
53                 intPrevValue = intiter->second;
54                 
55                 if (PropertyName == wxT("TYPE")){
56                 
57                         if (PropertyValue == wxT("work")){
58                         
59                                 intType = 2;                                    
60                         
61                         } else if (PropertyValue == wxT("home")){
63                                 intType = 1;
64                         
65                         } else {
66                         
67                                 intType = 0;
68                         
69                         }
70                 
71                 }
72         
73         }
74         
75         // Setup blank lines for later on.
76         
77         if (intType == 0){
78         
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){
86         
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("")));
92         
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("")));
100         
101         }
102         
103         intPrevValue = 5;                       
104         
105         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
106         intiter != SplitPoints.end(); ++intiter){
107         
108                 SLiter = SplitLength.find(intiter->first);
109         
110                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
111                 
112                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
113                 PropertyName = PropertyElement.GetNextToken();                          
114                 PropertyValue = PropertyElement.GetNextToken();
115                 
116                 intPrevValue = intiter->second;
117                 
118                 // Process properties.
119                 
120                 size_t intPropertyValueLen = PropertyValue.Len();
121                 
122                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
123                         
124                         PropertyValue.Trim();
125                         PropertyValue.RemoveLast();
126                         
127                 }                               
128                 
129                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
130                         
131                         PropertyValue.Remove(0, 1);
132                         
133                 }
134                 
135                 ProcessCaptureStrings(&PropertyValue);                          
136                 
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)); }
142                 
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)); }
148                 
149                 } else if (PropertyName == wxT("PREF")){
150                         
151                         intPref = wxAtoi(PropertyValue);
152                 
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)); }
156                 
157                 } else {
158                 
159                         // Something else we don't know about so append
160                         // to the tokens variable.
161                 
162                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
163                 
164                                 if (FirstToken == TRUE){
165                         
166                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
167                                         FirstToken = FALSE;
168                         
169                                 } else {
170                         
171                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
172                         
173                                 }
174                 
175                         }
176                 
177                 }
178         
179         }       
180         
181         // Add the data to the General/Home/Work address variables.
182         
183         ProcessCaptureStrings(&wxSPropertySeg2);
184         
185         wxListItem coldata;
187         coldata.SetId(intValueSeek);
188         coldata.SetData(intValueSeek);
189         coldata.SetText(wxSPropertySeg2);
190         
191         if (intType == 0){
192         
193                 ListCtrlIndex = lboLanguages->InsertItem(coldata);
194                 
195                 if (intPref > 0 && intPref < 101){
196                 
197                         lboLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
198                         
199                 }
200                 
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));
207         
208         } else if (intType == 1){ 
209         
210                 ListCtrlIndex = lboHomeLanguages->InsertItem(coldata);
212                 if (intPref > 0 && intPref < 101){
213                 
214                         lboHomeLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
215                         
216                 }
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));
224         
225         } else if (intType == 2){ 
226         
227                 ListCtrlIndex = lboBusinessLanguages->InsertItem(coldata);
229                 if (intPref > 0 && intPref < 101){
230                 
231                         lboBusinessLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
232                         
233                 }
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));                                
241         
242         }
243         
244         LangCount++;
245         intValueSeek++;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy