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-LoadNote.cpp
1 // frmContactEditor-LoadNote.cpp - frmContactEditor load note 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::LoadNote(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *NoteCount){
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                 GeneralNoteList.insert(std::make_pair(intValueSeek, wxT("")));
80                 GeneralNoteListAltID.insert(std::make_pair(intValueSeek, wxT("")));
81                 GeneralNoteListPID.insert(std::make_pair(intValueSeek, wxT("")));
82                 GeneralNoteListPref.insert(std::make_pair(intValueSeek, 0));
83                 GeneralNoteListTokens.insert(std::make_pair(intValueSeek, wxT("")));
84                 GeneralNoteListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
86         } else if (intType == 1){
87         
88                 HomeNoteList.insert(std::make_pair(intValueSeek, wxT("")));
89                 HomeNoteListAltID.insert(std::make_pair(intValueSeek, wxT("")));
90                 HomeNoteListPID.insert(std::make_pair(intValueSeek, wxT("")));
91                 HomeNoteListPref.insert(std::make_pair(intValueSeek, 0));
92                 HomeNoteListTokens.insert(std::make_pair(intValueSeek, wxT("")));
93                 HomeNoteListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
94         
95         } else if (intType == 2){
97                 BusinessNoteList.insert(std::make_pair(intValueSeek, wxT("")));
98                 BusinessNoteListAltID.insert(std::make_pair(intValueSeek, wxT("")));
99                 BusinessNoteListPID.insert(std::make_pair(intValueSeek, wxT("")));
100                 BusinessNoteListPref.insert(std::make_pair(intValueSeek, 0));
101                 BusinessNoteListTokens.insert(std::make_pair(intValueSeek, wxT("")));
102                 BusinessNoteListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
103         
104         }
105         
106         intPrevValue = 5;                       
107         
108         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
109         intiter != SplitPoints.end(); ++intiter){
110         
111                 SLiter = SplitLength.find(intiter->first);
112         
113                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
114                 
115                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
116                 PropertyName = PropertyElement.GetNextToken();                          
117                 PropertyValue = PropertyElement.GetNextToken();
118                 
119                 intPrevValue = intiter->second;
120                 
121                 // Process properties.
122                 
123                 size_t intPropertyValueLen = PropertyValue.Len();
124                 
125                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
126                         
127                         PropertyValue.Trim();
128                         PropertyValue.RemoveLast();
129                         
130                 }                               
131                 
132                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
133                         
134                         PropertyValue.Remove(0, 1);
135                         
136                 }
137                 
138                 ProcessCaptureStrings(&PropertyValue);                          
139                 
140                 if (PropertyName == wxT("ALTID")){
142                         if (intType == 0){ GeneralNoteListAltID.erase(intValueSeek); GeneralNoteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
143                         else if (intType == 1){ HomeNoteListAltID.erase(intValueSeek); HomeNoteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
144                         else if (intType == 2){ BusinessNoteListAltID.erase(intValueSeek); BusinessNoteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
145                 
146                 } else if (PropertyName == wxT("PID")){
148                         if (intType == 0){ GeneralNoteListPID.erase(intValueSeek); GeneralNoteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
149                         else if (intType == 1){ HomeNoteListPID.erase(intValueSeek); HomeNoteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
150                         else if (intType == 2){ BusinessNoteListPID.erase(intValueSeek); BusinessNoteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
151                 
152                 } else if (PropertyName == wxT("PREF")){
153                         
154                         intPref = wxAtoi(PropertyValue);
155                 
156                         if (intType == 0){ GeneralNoteListPref.erase(intValueSeek); GeneralNoteListPref.insert(std::make_pair(intValueSeek, intPref)); }
157                         else if (intType == 1){ HomeNoteListPref.erase(intValueSeek); HomeNoteListPref.insert(std::make_pair(intValueSeek, intPref)); }
158                         else if (intType == 2){ BusinessNoteListPref.erase(intValueSeek); BusinessNoteListPref.insert(std::make_pair(intValueSeek, intPref)); }
159                 
160                 } else if (PropertyName == wxT("LANGUAGE")){
161                 
162                         if (intType == 0){ GeneralNoteListLanguage.erase(intValueSeek); GeneralNoteListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
163                         else if (intType == 1){ HomeNoteListLanguage.erase(intValueSeek); HomeNoteListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
164                         else if (intType == 2){ BusinessNoteListLanguage.erase(intValueSeek); BusinessNoteListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
165                 
166                 } else {
167                 
168                         // Something else we don't know about so append
169                         // to the tokens variable.
170                 
171                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
172                 
173                                 if (FirstToken == TRUE){
174                         
175                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
176                                         FirstToken = FALSE;
177                         
178                                 } else {
179                         
180                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
181                         
182                                 }
183                 
184                         }
185                 
186                 }
187         
188         }
189         
190         // Add the data to the General/Home/Work address variables.
191         
192         ProcessCaptureStrings(&wxSPropertySeg2);
193         
194         wxListItem coldata;
196         coldata.SetId(intValueSeek);
197         coldata.SetData(intValueSeek);
198         
199         if (intType == 0){
200         
201                 GeneralNoteList.erase(intValueSeek);
202                 GeneralNoteListType.erase(intValueSeek);
203                 GeneralNoteListTokens.erase(intValueSeek);
204                 GeneralNoteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
205                 GeneralNoteListType.insert(std::make_pair(intValueSeek, wxT("")));
206                 GeneralNoteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                     
207         
208                 //CaptureString(&wxSPropertySeg2, FALSE);
210                 coldata.SetText(wxSPropertySeg2);
211         
212                 ListCtrlIndex = lboNotes->InsertItem(coldata);
213                 
214                 if (intPref > 0 && intPref < 101){
215                 
216                         lboNotes->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
217                         
218                 }
219         
220         } else if (intType == 1){ 
221         
222                 HomeNoteList.erase(intValueSeek);
223                 HomeNoteListType.erase(intValueSeek);
224                 HomeNoteListTokens.erase(intValueSeek);                         
225                 HomeNoteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
226                 HomeNoteListType.insert(std::make_pair(intValueSeek, wxT("home")));
227                 HomeNoteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                        
228         
229                 CaptureString(&wxSPropertySeg2, FALSE);
231                 coldata.SetText(wxSPropertySeg2);                       
232         
233                 ListCtrlIndex = lboHomeNotes->InsertItem(coldata);
235                 if (intPref > 0 && intPref < 101){
236                 
237                         lboHomeNotes->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
238                         
239                 }
240         
241         } else if (intType == 2){ 
242         
243                 BusinessNoteList.erase(intValueSeek);
244                 BusinessNoteListType.erase(intValueSeek);
245                 BusinessNoteListTokens.erase(intValueSeek);                             
246                 BusinessNoteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
247                 BusinessNoteListType.insert(std::make_pair(intValueSeek, wxT("work")));
248                 BusinessNoteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                    
249         
250                 CaptureString(&wxSPropertySeg2, FALSE);
252                 coldata.SetText(wxSPropertySeg2);
253         
254                 ListCtrlIndex = lboBusinessNotes->InsertItem(coldata);
256                 if (intPref > 0 && intPref < 101){
257                 
258                         lboBusinessNotes->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
259                         
260                 }                               
261         
262         }
263         
264         NoteCount++;
265         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