1 // frmContactEditor-LoadURL.cpp - frmContactEditor load URL 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::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;
36 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
40 // Look for type before continuing.
42 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
43 intiter != SplitPoints.end(); ++intiter){
45 SLiter = SplitLength.find(intiter->first);
47 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
49 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
50 PropertyName = PropertyElement.GetNextToken();
51 PropertyValue = PropertyElement.GetNextToken();
53 intPrevValue = intiter->second;
55 if (PropertyName == wxT("TYPE")){
57 if (PropertyValue == wxT("work")){
61 } else if (PropertyValue == wxT("home")){
75 // Setup blank lines for later on.
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){
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("")));
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("")));
105 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
106 intiter != SplitPoints.end(); ++intiter){
108 SLiter = SplitLength.find(intiter->first);
110 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
112 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
113 PropertyName = PropertyElement.GetNextToken();
114 PropertyValue = PropertyElement.GetNextToken();
116 intPrevValue = intiter->second;
118 // Process properties.
120 size_t intPropertyValueLen = PropertyValue.Len();
122 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
124 PropertyValue.Trim();
125 PropertyValue.RemoveLast();
129 if (PropertyValue.Mid(0, 1) == wxT("\"")){
131 PropertyValue.Remove(0, 1);
135 ProcessCaptureStrings(&PropertyValue);
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)); }
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)); }
149 } else if (PropertyName == wxT("PREF")){
151 intPref = wxAtoi(PropertyValue);
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)); }
157 } else if (PropertyName == wxT("MEDIATYPE")){
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)); }
165 // Something else we don't know about so append
166 // to the tokens variable.
168 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
170 if (FirstToken == TRUE){
172 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
177 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
187 // Add the data to the General/Home/Work address variables.
189 ProcessCaptureStrings(&wxSPropertySeg2);
193 coldata.SetId(intValueSeek);
194 coldata.SetData(intValueSeek);
195 coldata.SetText(wxSPropertySeg2);
199 ListCtrlIndex = lboWebsites->InsertItem(coldata);
201 if (intPref > 0 && intPref < 101){
203 lboWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));
214 } else if (intType == 1){
216 ListCtrlIndex = lboHomeWebsites->InsertItem(coldata);
218 if (intPref > 0 && intPref < 101){
220 lboHomeWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));
231 } else if (intType == 2){
233 ListCtrlIndex = lboBusinessWebsites->InsertItem(coldata);
235 if (intPref > 0 && intPref < 101){
237 lboBusinessWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));