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-LoadURL.cpp
1 // frmContactEditor-LoadURL.cpp - frmContactEditor load URL 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::LoadURL(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *URLCount){
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 = 5;
32         int intPref = 0;                        
33         int intType = 0;
34         long ListCtrlIndex;
35         
36         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
37         
38         intPrevValue = 4;
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                 GeneralWebsiteList.insert(std::make_pair(intValueSeek, wxT("")));
80                 GeneralWebsiteListAltID.insert(std::make_pair(intValueSeek, wxT("")));
81                 GeneralWebsiteListPID.insert(std::make_pair(intValueSeek, wxT("")));
82                 GeneralWebsiteListPref.insert(std::make_pair(intValueSeek, 0));
83                 GeneralWebsiteListTokens.insert(std::make_pair(intValueSeek, wxT("")));
85         } else if (intType == 1){
86         
87                 HomeWebsiteList.insert(std::make_pair(intValueSeek, wxT("")));
88                 HomeWebsiteListAltID.insert(std::make_pair(intValueSeek, wxT("")));
89                 HomeWebsiteListPID.insert(std::make_pair(intValueSeek, wxT("")));
90                 HomeWebsiteListPref.insert(std::make_pair(intValueSeek, 0));
91                 HomeWebsiteListTokens.insert(std::make_pair(intValueSeek, wxT("")));
92         
93         } else if (intType == 2){
95                 BusinessWebsiteList.insert(std::make_pair(intValueSeek, wxT("")));
96                 BusinessWebsiteListAltID.insert(std::make_pair(intValueSeek, wxT("")));
97                 BusinessWebsiteListPID.insert(std::make_pair(intValueSeek, wxT("")));
98                 BusinessWebsiteListPref.insert(std::make_pair(intValueSeek, 0));
99                 BusinessWebsiteListTokens.insert(std::make_pair(intValueSeek, wxT("")));
100         
101         }
102         
103         intPrevValue = 4;
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){ GeneralWebsiteListAltID.erase(intValueSeek); GeneralWebsiteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
140                         else if (intType == 1){ HomeWebsiteListAltID.erase(intValueSeek); HomeWebsiteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
141                         else if (intType == 2){ BusinessWebsiteListAltID.erase(intValueSeek); BusinessWebsiteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
142                 
143                 } else if (PropertyName == wxT("PID")){
145                         if (intType == 0){ GeneralWebsiteListPID.erase(intValueSeek); GeneralWebsiteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
146                         else if (intType == 1){ HomeWebsiteListPID.erase(intValueSeek); HomeWebsiteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
147                         else if (intType == 2){ BusinessWebsiteListPID.erase(intValueSeek); BusinessWebsiteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
148                 
149                 } else if (PropertyName == wxT("PREF")){
150                         
151                         intPref = wxAtoi(PropertyValue);
152                 
153                         if (intType == 0){ GeneralWebsiteListPref.erase(intValueSeek); GeneralWebsiteListPref.insert(std::make_pair(intValueSeek, intPref)); }
154                         else if (intType == 1){ HomeWebsiteListPref.erase(intValueSeek); HomeWebsiteListPref.insert(std::make_pair(intValueSeek, intPref)); }
155                         else if (intType == 2){ BusinessWebsiteListPref.erase(intValueSeek); BusinessWebsiteListPref.insert(std::make_pair(intValueSeek, intPref)); }
156                 
157                 } else if (PropertyName == wxT("MEDIATYPE")){
158                 
159                         if (intType == 0){ GeneralWebsiteListMediatype.erase(intValueSeek); GeneralWebsiteListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
160                         else if (intType == 1){ HomeWebsiteListMediatype.erase(intValueSeek); HomeWebsiteListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
161                         else if (intType == 2){ BusinessWebsiteListMediatype.erase(intValueSeek); BusinessWebsiteListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
162                 
163                 } else {
164                 
165                         // Something else we don't know about so append
166                         // to the tokens variable.
167                 
168                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
169                 
170                                 if (FirstToken == TRUE){
171                         
172                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
173                                         FirstToken = FALSE;
174                         
175                                 } else {
176                         
177                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
178                         
179                                 }
180                 
181                         }
182                 
183                 }
184         
185         }
186         
187         // Add the data to the General/Home/Work address variables.
188         
189         ProcessCaptureStrings(&wxSPropertySeg2);
190         
191         wxListItem coldata;
193         coldata.SetId(intValueSeek);
194         coldata.SetData(intValueSeek);
195         coldata.SetText(wxSPropertySeg2);
196         
197         if (intType == 0){
198         
199                 ListCtrlIndex = lboWebsites->InsertItem(coldata);
200                 
201                 if (intPref > 0 && intPref < 101){
202                 
203                         lboWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
204                         
205                 }
206                 
207                 GeneralWebsiteList.erase(intValueSeek);
208                 GeneralWebsiteListType.erase(intValueSeek);
209                 GeneralWebsiteListTokens.erase(intValueSeek);
210                 GeneralWebsiteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
211                 GeneralWebsiteListType.insert(std::make_pair(intValueSeek, wxT("")));
212                 GeneralWebsiteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
213         
214         } else if (intType == 1){ 
215         
216                 ListCtrlIndex = lboHomeWebsites->InsertItem(coldata);
218                 if (intPref > 0 && intPref < 101){
219                 
220                         lboHomeWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
221                         
222                 }
224                 HomeWebsiteList.erase(intValueSeek);
225                 HomeWebsiteListType.erase(intValueSeek);
226                 HomeWebsiteListTokens.erase(intValueSeek);                              
227                 HomeWebsiteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
228                 HomeWebsiteListType.insert(std::make_pair(intValueSeek, wxT("home")));
229                 HomeWebsiteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
230         
231         } else if (intType == 2){ 
232         
233                 ListCtrlIndex = lboBusinessWebsites->InsertItem(coldata);
235                 if (intPref > 0 && intPref < 101){
236                 
237                         lboBusinessWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
238                         
239                 }
241                 BusinessWebsiteList.erase(intValueSeek);
242                 BusinessWebsiteListType.erase(intValueSeek);
243                 BusinessWebsiteListTokens.erase(intValueSeek);                          
244                 BusinessWebsiteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
245                 BusinessWebsiteListType.insert(std::make_pair(intValueSeek, wxT("work")));
246                 BusinessWebsiteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                         
247         
248         }
249         
250         URLCount++;
251         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