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-LoadCategory.cpp
1 // frmContactEditor-LoadCategory.cpp - frmContactEditor load category 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::LoadCategory(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *CategoryCount){
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;
31         wxString PropertyType;
32         bool AfterFirstToken = FALSE;
33         bool FirstToken = TRUE;                 
34         int intSplitsFound = 0;
35         int intSplitSize = 0;
36         int intPrevValue = 12;
37         int intPref = 0;                        
38         int intType = 0;
39         int intSplitSeek = 0;
40         long ListCtrlIndex;
41         
42         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
43         
44         intPrevValue = 11;
45         
46         // Look for type before continuing.
47         
48         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
49         intiter != SplitPoints.end(); ++intiter){
50         
51                 SLiter = SplitLength.find(intiter->first);
52         
53                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
54                 
55                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
56                 PropertyName = PropertyElement.GetNextToken();                          
57                 PropertyValue = PropertyElement.GetNextToken();
58                 
59                 intPrevValue = intiter->second;
60                 
61                 if (PropertyName == wxT("TYPE")){
62                 
63                         if (PropertyValue == wxT("work")){
64                         
65                                 intType = 2;
66                                 PropertyType = wxT("work");                             
67                         
68                         } else if (PropertyValue == wxT("home")){
70                                 intType = 1;
71                                 PropertyType = wxT("home");                                             
72                         
73                         } else {
74                         
75                                 intType = 0;
76                         
77                         }
78                 
79                 }
80         
81         }
82         
83         // Setup blank lines for later on.
84         
85         CategoriesList.insert(std::make_pair(intValueSeek, wxT("")));
86         CategoriesListAltID.insert(std::make_pair(intValueSeek, wxT("")));
87         CategoriesListPID.insert(std::make_pair(intValueSeek, wxT("")));
88         CategoriesListPref.insert(std::make_pair(intValueSeek, 0));
89         CategoriesListTokens.insert(std::make_pair(intValueSeek, wxT("")));
90         
91         intPrevValue = 11;
92         
93         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
94         intiter != SplitPoints.end(); ++intiter){
95         
96                 SLiter = SplitLength.find(intiter->first);
97         
98                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
99                 
100                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
101                 PropertyName = PropertyElement.GetNextToken();                          
102                 PropertyValue = PropertyElement.GetNextToken();
103                 
104                 intPrevValue = intiter->second;
105                 
106                 // Process properties.
107                 
108                 size_t intPropertyValueLen = PropertyValue.Len();
109                 
110                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
111                         
112                         PropertyValue.Trim();
113                         PropertyValue.RemoveLast();
114                         
115                 }                               
116                 
117                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
118                         
119                         PropertyValue.Remove(0, 1);
120                         
121                 }
122                 
123                 ProcessCaptureStrings(&PropertyValue);
124                 
125                 if (PropertyName == wxT("ALTID")){
127                         if (intType == 0){ CategoriesListAltID.erase(intValueSeek); CategoriesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
128                         else if (intType == 1){ CategoriesListAltID.erase(intValueSeek); CategoriesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
129                         else if (intType == 2){ CategoriesListAltID.erase(intValueSeek); CategoriesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
130                 
131                 } else if (PropertyName == wxT("PID")){
133                         if (intType == 0){ CategoriesListPID.erase(intValueSeek); CategoriesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
134                         else if (intType == 1){ CategoriesListPID.erase(intValueSeek); CategoriesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
135                         else if (intType == 2){ CategoriesListPID.erase(intValueSeek); CategoriesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
136                 
137                 } else if (PropertyName == wxT("PREF")){
138                         
139                         intPref = wxAtoi(PropertyValue);
140                 
141                         if (intType == 0){ CategoriesListPref.erase(intValueSeek); CategoriesListPref.insert(std::make_pair(intValueSeek, intPref)); }
142                         else if (intType == 1){ CategoriesListPref.erase(intValueSeek); CategoriesListPref.insert(std::make_pair(intValueSeek, intPref)); }
143                         else if (intType == 2){ CategoriesListPref.erase(intValueSeek); CategoriesListPref.insert(std::make_pair(intValueSeek, intPref)); }
144                 
145                 } else {
146                 
147                         // Something else we don't know about so append
148                         // to the tokens variable.
149                 
150                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
151                 
152                                 if (FirstToken == TRUE){
153                         
154                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
155                                         FirstToken = FALSE;
156                         
157                                 } else {
158                         
159                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
160                         
161                                 }
162                 
163                         }
164                 
165                 }
166         
167         }                       
168         
169         // Deal with multiple categories.
170         
171         SplitPoints.clear();
172         SplitLength.clear();
173         intSplitSize = 0;
174         intSplitsFound = 0;
175         intSplitSeek = 0;
176         intPrevValue = 0;
177         intPropertyLen = wxSPropertySeg2.Len(); 
178         
179         for (int i = 0; i <= intPropertyLen; i++){
180         
181                 if (intSplitSize == 0 && wxSPropertySeg2.Mid(i, 1) == wxT(" ")){
182         
183                         continue;
184                 
185                 }
186         
187                 intSplitSize++;
188         
189                 if (wxSPropertySeg2.Mid(i, 1) == wxT(",") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
190         
191                         if (AfterFirstToken == TRUE){
192         
193                                 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
194                                 SplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
195                         
196                         } else {
197                         
198                                 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
199                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));                                 
200                                 AfterFirstToken = TRUE;
201                         
202                         }
204                         intSplitsFound++;
205                         intSplitSeek = i;
206                         intSplitSize = 0;                                       
207         
208                 }                       
209         
210         }
211         
212         SplitPoints.insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
213         SplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                       
214         
215         intPrevValue = 0;
216         
217         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
218         intiter != SplitPoints.end(); ++intiter){
219         
220                 SLiter = SplitLength.find(intiter->first);
221         
222                 PropertyData = wxSPropertySeg2.Mid(intPrevValue, (SLiter->second + 1));
223                 
224                 intPrevValue = intiter->second;
225                 
226                 // Process properties.
227                 
228                 /*
229                 
230                 int intPropertyValueLen = PropertyValue.Len();                          
231                 
232                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
233                         
234                         PropertyValue.Trim();
235                         PropertyValue.RemoveLast();
236                         
237                 }
238                 
239                 */
240                 
241                 // Add the data to the General/Home/Work address variables.
242         
243                 // Trim any whitespace from the start and end.
244         
245                 PropertyData = PropertyData.Trim(FALSE);
246                 PropertyData = PropertyData.Trim(TRUE);                         
247         
248                 ProcessCaptureStrings(&PropertyData);
249         
250                 wxListItem coldata;
252                 coldata.SetId(intValueSeek);
253                 coldata.SetData(intValueSeek);
254                 coldata.SetText(PropertyData);
255         
256                 ListCtrlIndex = lboCategories->InsertItem(coldata);
257                 
258                 if (intPref > 0 && intPref < 101){
259                 
260                         lboCategories->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
261                         
262                 }
263                 
264                 CategoriesList.erase(intValueSeek);
265                 CategoriesListType.erase(intValueSeek);
266                 CategoriesListTokens.erase(intValueSeek);
267                 CategoriesList.insert(std::make_pair(intValueSeek, PropertyData));
268                 CategoriesListType.insert(std::make_pair(intValueSeek, PropertyType));
269                 CategoriesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
270         
271                 CategoryCount++;
272                 intValueSeek++;                         
273         
274         }
278 void frmContactEditor::LoadCalFreeBusy(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *FreeBusyCount){
280         std::map<int, int> SplitPoints;
281         std::map<int, int> SplitLength;
282         std::map<int, int>::iterator SLiter;                    
283         wxString PropertyData;
284         wxString PropertyName;
285         wxString PropertyValue;
286         wxString PropertyTokens;
287         bool FirstToken = TRUE;
288         int intPrevValue = 7;
289         int intPref = 0;                        
290         int intType = 0;
291         long ListCtrlIndex;
292         
293         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
294         
295         intPrevValue = 6;
296         
297         // Look for type before continuing.
298         
299         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
300         intiter != SplitPoints.end(); ++intiter){
301         
302                 SLiter = SplitLength.find(intiter->first);
303         
304                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
305                 
306                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
307                 PropertyName = PropertyElement.GetNextToken();                          
308                 PropertyValue = PropertyElement.GetNextToken();
309                 
310                 intPrevValue = intiter->second;
311                 
312                 if (PropertyName == wxT("TYPE")){
313                 
314                         if (PropertyValue == wxT("work")){
315                         
316                                 intType = 2;                                    
317                         
318                         } else if (PropertyValue == wxT("home")){
320                                 intType = 1;
321                         
322                         } else {
323                         
324                                 intType = 0;
325                         
326                         }
327                 
328                 }
329         
330         }
331         
332         // Setup blank lines for later on.
333         
334         FreeBusyList.insert(std::make_pair(intValueSeek, wxT("")));
335         FreeBusyListAltID.insert(std::make_pair(intValueSeek, wxT("")));
336         FreeBusyListPID.insert(std::make_pair(intValueSeek, wxT("")));
337         FreeBusyListPref.insert(std::make_pair(intValueSeek, 0));
338         FreeBusyListTokens.insert(std::make_pair(intValueSeek, wxT("")));
339         
340         intPrevValue = 6;
341         
342         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
343         intiter != SplitPoints.end(); ++intiter){
344         
345                 SLiter = SplitLength.find(intiter->first);
346         
347                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
348                 
349                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
350                 PropertyName = PropertyElement.GetNextToken();                          
351                 PropertyValue = PropertyElement.GetNextToken();
352                 
353                 intPrevValue = intiter->second;
354                 
355                 // Process properties.
356                 
357                 size_t intPropertyValueLen = PropertyValue.Len();
358                 
359                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
360                         
361                         PropertyValue.Trim();
362                         PropertyValue.RemoveLast();
363                         
364                 }                               
365                 
366                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
367                         
368                         PropertyValue.Remove(0, 1);
369                         
370                 }                               
371                 
372                 if (PropertyName == wxT("ALTID")){
374                         FreeBusyListAltID.erase(intValueSeek); FreeBusyListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
375                 
376                 } else if (PropertyName == wxT("PID")){
378                         FreeBusyListPID.erase(intValueSeek); FreeBusyListPID.insert(std::make_pair(intValueSeek, PropertyValue));
379                 
380                 } else if (PropertyName == wxT("PREF")){
381                         
382                         intPref = wxAtoi(PropertyValue);
383                 
384                         FreeBusyListPref.erase(intValueSeek); FreeBusyListPref.insert(std::make_pair(intValueSeek, intPref));
385                 
386                 } else if (PropertyName == wxT("MEDIATYPE")){
387                 
388                         FreeBusyListMediatype.erase(intValueSeek); FreeBusyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue));
389                 
390                 } else {
391                 
392                         // Something else we don't know about so append
393                         // to the tokens variable.
394                 
395                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
396                 
397                                 if (FirstToken == TRUE){
398                         
399                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
400                                         FirstToken = FALSE;
401                         
402                                 } else {
403                         
404                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
405                         
406                                 }
407                 
408                         }
409                 
410                 }
411         
412         }       
413         
414         // Add the data to the General/Home/Work address variables.
415         
416         wxListItem coldata;
418         coldata.SetId(intValueSeek);
419         coldata.SetData(intValueSeek);
420         coldata.SetText(wxSPropertySeg2);
422         ListCtrlIndex = lboFreeBusyAddresses->InsertItem(coldata);
423                 
424         if (intPref > 0 && intPref < 101){
425                 
426                 lboFreeBusyAddresses->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
427                         
428         }
429         
430         CaptureString(&wxSPropertySeg2, FALSE);                 
431                 
432         FreeBusyList.erase(intValueSeek);
433         FreeBusyListType.erase(intValueSeek);
434         FreeBusyListTokens.erase(intValueSeek);
435         FreeBusyList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
436         
437         if (intType == 0){
438         
439                 FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("")));                         
440         
441         } else if (intType == 1){
442         
443                 FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("home")));
444                 lboFreeBusyAddresses->SetItem(ListCtrlIndex, 1, _("Home"), intPref);
445         
446         } else if (intType == 2){
447         
448                 FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("work")));
449                 lboFreeBusyAddresses->SetItem(ListCtrlIndex, 1, _("Work"), intPref);
450         
451         }
452         
453         FreeBusyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
454         
455         FreeBusyCount++;
456         intValueSeek++;
457         
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