1 // frmContactEditor-LoadIM.cpp - frmContactEditor load IM 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::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;
34 bool FirstToken = TRUE;
35 int intSplitsFound = 0;
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")){
67 } else if (PropertyValue == wxT("home")){
81 // Setup blank lines for later on.
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){
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("")));
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("")));
114 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
115 intiter != SplitPoints.end(); ++intiter){
117 SLiter = SplitLength.find(intiter->first);
119 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
121 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
122 PropertyName = PropertyElement.GetNextToken();
123 PropertyValue = PropertyElement.GetNextToken();
125 ProcessCaptureStrings(&PropertyValue);
127 intPrevValue = intiter->second;
129 // Process properties.
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)); }
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)); }
143 } else if (PropertyName == wxT("PREF")){
145 intPref = wxAtoi(PropertyValue);
147 if (intPref > 0 && intPref < 101){
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)); }
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)); }
163 // Something else we don't know about so append
164 // to the tokens variable.
166 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
168 if (FirstToken == TRUE){
170 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
175 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
185 // Split the address.
187 //std::map<int, int>::iterator SLiter;
188 intPropertyLen = wxSPropertySeg2.Len();
195 for (int i = 0; i <= intPropertyLen; i++){
199 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
202 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
204 if (intSplitsFound == 1){
206 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
217 // Split the data into several parts.
219 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
220 intiter != SplitPoints.end(); ++intiter){
222 if (intiter->first == 1){
226 SLiter = SplitLength.find(1);
228 //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
229 IMPPType = wxSPropertySeg2.Mid(0, SLiter->second);
230 intPrevValue = intiter->second;
232 IMPPAddress = wxSPropertySeg2.Mid(intPrevValue);
238 // Check what IM type it is.
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");
270 // Add the data to the General/Home/Work address variables.
272 ProcessCaptureStrings(&wxSPropertySeg2);
276 coldata.SetId(intValueSeek);
277 coldata.SetData(intValueSeek);
278 coldata.SetText(IMPPType);
282 ListCtrlIndex = lboIM->InsertItem(coldata);
284 lboIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
286 if (intPref > 0 && intPref < 101){
288 lboIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
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));
299 } else if (intType == 1){
301 ListCtrlIndex = lboHomeIM->InsertItem(coldata);
303 lboHomeIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
305 if (intPref > 0 && intPref < 101){
307 lboHomeIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
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));
318 } else if (intType == 2){
320 ListCtrlIndex = lboBusinessIM->InsertItem(coldata);
322 lboBusinessIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
324 if (intPref > 0 && intPref < 101){
326 lboBusinessIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
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));