Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out form code from ADR in ContactDataObject.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadIM.cpp
1 // frmContactEditor-LoadIM.cpp - frmContactEditor load IM 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::LoadIM(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *IMPPCount){
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         std::map<int, int>::iterator SPoint;
28         wxString PropertyData;
29         wxString PropertyName;
30         wxString PropertyValue;
31         wxString PropertyTokens;
32         wxString IMPPType;
33         wxString IMPPAddress;
34         bool FirstToken = TRUE;
35         int intSplitsFound = 0;
36         int intSplitSize = 0;
37         int intPrevValue = 6;
38         int intPref = 0;
39         int intType = 0;
40         long ListCtrlIndex;
41         
42         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
43         
44         intPrevValue = 5;
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                         
67                         } else if (PropertyValue == wxT("home")){
69                                 intType = 1;
70                         
71                         } else {
72                         
73                                 intType = 0;
74                         
75                         }
76                 
77                 }
78         
79         }
80         
81         // Setup blank lines for later on.
82         
83         if (intType == 0){
84         
85                 GeneralIMList.insert(std::make_pair(intValueSeek, wxT("")));
86                 GeneralIMListAltID.insert(std::make_pair(intValueSeek, wxT("")));
87                 GeneralIMListPID.insert(std::make_pair(intValueSeek, wxT("")));
88                 GeneralIMListPref.insert(std::make_pair(intValueSeek, 0));
89                 GeneralIMListTokens.insert(std::make_pair(intValueSeek, wxT("")));
90                 GeneralIMListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
92         } else if (intType == 1){
93         
94                 HomeIMList.insert(std::make_pair(intValueSeek, wxT("")));
95                 HomeIMListAltID.insert(std::make_pair(intValueSeek, wxT("")));
96                 HomeIMListPID.insert(std::make_pair(intValueSeek, wxT("")));
97                 HomeIMListPref.insert(std::make_pair(intValueSeek, 0));
98                 HomeIMListTokens.insert(std::make_pair(intValueSeek, wxT("")));
99                 HomeIMListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
100         
101         } else if (intType == 2){
103                 BusinessIMList.insert(std::make_pair(intValueSeek, wxT("")));
104                 BusinessIMListAltID.insert(std::make_pair(intValueSeek, wxT("")));
105                 BusinessIMListPID.insert(std::make_pair(intValueSeek, wxT("")));
106                 BusinessIMListPref.insert(std::make_pair(intValueSeek, 0));
107                 BusinessIMListTokens.insert(std::make_pair(intValueSeek, wxT("")));
108                 BusinessIMListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
109         
110         }
111         
112         intPrevValue = 5;
113         
114         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
115         intiter != SplitPoints.end(); ++intiter){
116         
117                 SLiter = SplitLength.find(intiter->first);
118         
119                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
120                 
121                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
122                 PropertyName = PropertyElement.GetNextToken();                          
123                 PropertyValue = PropertyElement.GetNextToken();
124                 
125                 ProcessCaptureStrings(&PropertyValue);
126                 
127                 intPrevValue = intiter->second;
128                 
129                 // Process properties.
130                 
131                 if (PropertyName == wxT("ALTID")){
133                         if (intType == 0){ GeneralIMListAltID.erase(intValueSeek); GeneralIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
134                         else if (intType == 1){ HomeIMListAltID.erase(intValueSeek); HomeIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
135                         else if (intType == 2){ BusinessIMListAltID.erase(intValueSeek); BusinessIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
136                 
137                 } else if (PropertyName == wxT("PID")){
139                         if (intType == 0){ GeneralIMListPID.erase(intValueSeek); GeneralIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
140                         else if (intType == 1){ HomeIMListPID.erase(intValueSeek); HomeIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
141                         else if (intType == 2){ BusinessIMListPID.erase(intValueSeek); BusinessIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
142                 
143                 } else if (PropertyName == wxT("PREF")){
144                         
145                         intPref = wxAtoi(PropertyValue);
146                         
147                         if (intPref > 0 && intPref < 101){
148                 
149                                 if (intType == 0){ GeneralIMListPref.erase(intValueSeek); GeneralIMListPref.insert(std::make_pair(intValueSeek, intPref)); }
150                                 else if (intType == 1){ HomeIMListPref.erase(intValueSeek); HomeIMListPref.insert(std::make_pair(intValueSeek, intPref)); }
151                                 else if (intType == 2){ BusinessIMListPref.erase(intValueSeek); BusinessIMListPref.insert(std::make_pair(intValueSeek, intPref)); }
152                                 
153                         }
154                 
155                 } else if (PropertyName == wxT("MEDIATYPE")){
157                         if (intType == 0){ GeneralIMListMediatype.erase(intValueSeek); GeneralIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
158                         else if (intType == 1){ HomeIMListMediatype.erase(intValueSeek); HomeIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
159                         else if (intType == 2){ BusinessIMListMediatype.erase(intValueSeek); BusinessIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
160                 
161                 } else {
162                 
163                         // Something else we don't know about so append
164                         // to the tokens variable.
165                         
166                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
167                         
168                                 if (FirstToken == TRUE){
169                                 
170                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
171                                         FirstToken = FALSE;
172                                 
173                                 } else {
174                                 
175                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
176                                 
177                                 }
178                         
179                         }
180                 
181                 }
182         
183         }                       
184         
185         // Split the address. 
187         //std::map<int, int>::iterator SLiter;
188         intPropertyLen = wxSPropertySeg2.Len();
189         SplitPoints.clear();
190         SplitLength.clear();
191         intSplitsFound = 0;
192         intSplitSize = 0;
193         intPrevValue = 0;
194         
195         for (int i = 0; i <= intPropertyLen; i++){
197                 intSplitSize++;
198         
199                 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
200         
201                         intSplitsFound++;
202                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
203                         
204                         if (intSplitsFound == 1){ 
205                         
206                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
207                                 break; 
208                                 
209                         }
210                         
211                         intSplitSize = 0;                                       
212         
213                 }
215         }
216         
217         // Split the data into several parts.                   
218         
219         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
220         intiter != SplitPoints.end(); ++intiter){
221         
222                 if (intiter->first == 1){
223                 
224                         // Deal with PO Box.
225                         
226                         SLiter = SplitLength.find(1);
227                                                                 
228                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
229                         IMPPType = wxSPropertySeg2.Mid(0, SLiter->second);
230                         intPrevValue = intiter->second;
231                         
232                         IMPPAddress = wxSPropertySeg2.Mid(intPrevValue);                                        
233                 
234                 }
235         
236         }       
237         
238         // Check what IM type it is.
239         
240         if (IMPPType == wxT("aim")){
242                 IMPPType = wxT("AIM");
244         } else if (IMPPType == wxT("gg")){
246                 IMPPType = wxT("Gadu-Gadu");
248         } else if (IMPPType == wxT("icq")){
250                 IMPPType = wxT("ICQ");
252         } else if (IMPPType == wxT("skype")){
254                 IMPPType = wxT("Skype");
256         } else if (IMPPType == wxT("xmpp")){
258                 IMPPType = wxT("XMPP");
260         } else if (IMPPType == wxT("yahoo")){
262                 IMPPType = wxT("Yahoo");
264         } else {
266                 // Do nothing.
268         }                       
269         
270         // Add the data to the General/Home/Work address variables.
271         
272         ProcessCaptureStrings(&wxSPropertySeg2);
273         
274         wxListItem coldata;
276         coldata.SetId(intValueSeek);
277         coldata.SetData(intValueSeek);
278         coldata.SetText(IMPPType);
280         if (intType == 0){
281         
282                 ListCtrlIndex = lboIM->InsertItem(coldata);
283                 
284                 lboIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
285                 
286                 if (intPref > 0 && intPref < 101){
287                 
288                         lboIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
289                         
290                 }                               
291                 
292                 GeneralIMList.erase(intValueSeek);
293                 GeneralIMListType.erase(intValueSeek);
294                 GeneralIMListTokens.erase(intValueSeek);
295                 GeneralIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
296                 GeneralIMListType.insert(std::make_pair(intValueSeek, wxT("")));
297                 GeneralIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
298         
299         } else if (intType == 1){ 
300         
301                 ListCtrlIndex = lboHomeIM->InsertItem(coldata);
303                 lboHomeIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
305                 if (intPref > 0 && intPref < 101){
306                 
307                         lboHomeIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
308                         
309                 }
311                 HomeIMList.erase(intValueSeek);
312                 HomeIMListType.erase(intValueSeek);
313                 HomeIMListTokens.erase(intValueSeek);                           
314                 HomeIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
315                 HomeIMListType.insert(std::make_pair(intValueSeek, wxT("home")));
316                 HomeIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
317         
318         } else if (intType == 2){ 
319         
320                 ListCtrlIndex = lboBusinessIM->InsertItem(coldata);
322                 lboBusinessIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
324                 if (intPref > 0 && intPref < 101){
325                 
326                         lboBusinessIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
327                         
328                 }
330                 BusinessIMList.erase(intValueSeek);
331                 BusinessIMListType.erase(intValueSeek);
332                 BusinessIMListTokens.erase(intValueSeek);                               
333                 BusinessIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
334                 BusinessIMListType.insert(std::make_pair(intValueSeek, wxT("work")));
335                 BusinessIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                              
336         
337         }
338         
339         *IMPPCount++;
340         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