1 // frmContactEditor-LoadCategory.cpp - frmContactEditor load category 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::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;
36 int intPrevValue = 12;
42 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
46 // Look for type before continuing.
48 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
49 intiter != SplitPoints.end(); ++intiter){
51 SLiter = SplitLength.find(intiter->first);
53 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
55 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
56 PropertyName = PropertyElement.GetNextToken();
57 PropertyValue = PropertyElement.GetNextToken();
59 intPrevValue = intiter->second;
61 if (PropertyName == wxT("TYPE")){
63 if (PropertyValue == wxT("work")){
66 PropertyType = wxT("work");
68 } else if (PropertyValue == wxT("home")){
71 PropertyType = wxT("home");
83 // Setup blank lines for later on.
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("")));
93 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
94 intiter != SplitPoints.end(); ++intiter){
96 SLiter = SplitLength.find(intiter->first);
98 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
100 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
101 PropertyName = PropertyElement.GetNextToken();
102 PropertyValue = PropertyElement.GetNextToken();
104 intPrevValue = intiter->second;
106 // Process properties.
108 size_t intPropertyValueLen = PropertyValue.Len();
110 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
112 PropertyValue.Trim();
113 PropertyValue.RemoveLast();
117 if (PropertyValue.Mid(0, 1) == wxT("\"")){
119 PropertyValue.Remove(0, 1);
123 ProcessCaptureStrings(&PropertyValue);
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)); }
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)); }
137 } else if (PropertyName == wxT("PREF")){
139 intPref = wxAtoi(PropertyValue);
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)); }
147 // Something else we don't know about so append
148 // to the tokens variable.
150 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
152 if (FirstToken == TRUE){
154 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
159 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
169 // Deal with multiple categories.
177 intPropertyLen = wxSPropertySeg2.Len();
179 for (int i = 0; i <= intPropertyLen; i++){
181 if (intSplitSize == 0 && wxSPropertySeg2.Mid(i, 1) == wxT(" ")){
189 if (wxSPropertySeg2.Mid(i, 1) == wxT(",") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
191 if (AfterFirstToken == TRUE){
193 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
194 SplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
198 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
199 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
200 AfterFirstToken = TRUE;
212 SplitPoints.insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
213 SplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
217 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
218 intiter != SplitPoints.end(); ++intiter){
220 SLiter = SplitLength.find(intiter->first);
222 PropertyData = wxSPropertySeg2.Mid(intPrevValue, (SLiter->second + 1));
224 intPrevValue = intiter->second;
226 // Process properties.
230 int intPropertyValueLen = PropertyValue.Len();
232 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
234 PropertyValue.Trim();
235 PropertyValue.RemoveLast();
241 // Add the data to the General/Home/Work address variables.
243 // Trim any whitespace from the start and end.
245 PropertyData = PropertyData.Trim(FALSE);
246 PropertyData = PropertyData.Trim(TRUE);
248 ProcessCaptureStrings(&PropertyData);
252 coldata.SetId(intValueSeek);
253 coldata.SetData(intValueSeek);
254 coldata.SetText(PropertyData);
256 ListCtrlIndex = lboCategories->InsertItem(coldata);
258 if (intPref > 0 && intPref < 101){
260 lboCategories->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));
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;
293 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
297 // Look for type before continuing.
299 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
300 intiter != SplitPoints.end(); ++intiter){
302 SLiter = SplitLength.find(intiter->first);
304 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
306 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
307 PropertyName = PropertyElement.GetNextToken();
308 PropertyValue = PropertyElement.GetNextToken();
310 intPrevValue = intiter->second;
312 if (PropertyName == wxT("TYPE")){
314 if (PropertyValue == wxT("work")){
318 } else if (PropertyValue == wxT("home")){
332 // Setup blank lines for later on.
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("")));
342 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
343 intiter != SplitPoints.end(); ++intiter){
345 SLiter = SplitLength.find(intiter->first);
347 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
349 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
350 PropertyName = PropertyElement.GetNextToken();
351 PropertyValue = PropertyElement.GetNextToken();
353 intPrevValue = intiter->second;
355 // Process properties.
357 size_t intPropertyValueLen = PropertyValue.Len();
359 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
361 PropertyValue.Trim();
362 PropertyValue.RemoveLast();
366 if (PropertyValue.Mid(0, 1) == wxT("\"")){
368 PropertyValue.Remove(0, 1);
372 if (PropertyName == wxT("ALTID")){
374 FreeBusyListAltID.erase(intValueSeek); FreeBusyListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
376 } else if (PropertyName == wxT("PID")){
378 FreeBusyListPID.erase(intValueSeek); FreeBusyListPID.insert(std::make_pair(intValueSeek, PropertyValue));
380 } else if (PropertyName == wxT("PREF")){
382 intPref = wxAtoi(PropertyValue);
384 FreeBusyListPref.erase(intValueSeek); FreeBusyListPref.insert(std::make_pair(intValueSeek, intPref));
386 } else if (PropertyName == wxT("MEDIATYPE")){
388 FreeBusyListMediatype.erase(intValueSeek); FreeBusyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue));
392 // Something else we don't know about so append
393 // to the tokens variable.
395 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
397 if (FirstToken == TRUE){
399 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
404 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
414 // Add the data to the General/Home/Work address variables.
418 coldata.SetId(intValueSeek);
419 coldata.SetData(intValueSeek);
420 coldata.SetText(wxSPropertySeg2);
422 ListCtrlIndex = lboFreeBusyAddresses->InsertItem(coldata);
424 if (intPref > 0 && intPref < 101){
426 lboFreeBusyAddresses->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
430 CaptureString(&wxSPropertySeg2, FALSE);
432 FreeBusyList.erase(intValueSeek);
433 FreeBusyListType.erase(intValueSeek);
434 FreeBusyListTokens.erase(intValueSeek);
435 FreeBusyList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
439 FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("")));
441 } else if (intType == 1){
443 FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("home")));
444 lboFreeBusyAddresses->SetItem(ListCtrlIndex, 1, _("Home"), intPref);
446 } else if (intType == 2){
448 FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("work")));
449 lboFreeBusyAddresses->SetItem(ListCtrlIndex, 1, _("Work"), intPref);
453 FreeBusyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));