1 #include "frmContactEditor.h"
3 void frmContactEditor::LoadIM(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *IMPPCount){
5 size_t intPropertyLen = wxSPropertySeg1.Len();
6 std::map<int, int> SplitPoints;
7 std::map<int, int> SplitLength;
8 std::map<int, int>::iterator SLiter;
9 std::map<int, int>::iterator SPoint;
10 wxString PropertyData;
11 wxString PropertyName;
12 wxString PropertyValue;
13 wxString PropertyTokens;
16 bool FirstToken = TRUE;
17 int intSplitsFound = 0;
24 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
28 // Look for type before continuing.
30 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
31 intiter != SplitPoints.end(); ++intiter){
33 SLiter = SplitLength.find(intiter->first);
35 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
37 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
38 PropertyName = PropertyElement.GetNextToken();
39 PropertyValue = PropertyElement.GetNextToken();
41 intPrevValue = intiter->second;
43 if (PropertyName == wxT("TYPE")){
45 if (PropertyValue == wxT("work")){
49 } else if (PropertyValue == wxT("home")){
63 // Setup blank lines for later on.
67 GeneralIMList.insert(std::make_pair(intValueSeek, wxT("")));
68 GeneralIMListAltID.insert(std::make_pair(intValueSeek, wxT("")));
69 GeneralIMListPID.insert(std::make_pair(intValueSeek, wxT("")));
70 GeneralIMListPref.insert(std::make_pair(intValueSeek, 0));
71 GeneralIMListTokens.insert(std::make_pair(intValueSeek, wxT("")));
72 GeneralIMListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
74 } else if (intType == 1){
76 HomeIMList.insert(std::make_pair(intValueSeek, wxT("")));
77 HomeIMListAltID.insert(std::make_pair(intValueSeek, wxT("")));
78 HomeIMListPID.insert(std::make_pair(intValueSeek, wxT("")));
79 HomeIMListPref.insert(std::make_pair(intValueSeek, 0));
80 HomeIMListTokens.insert(std::make_pair(intValueSeek, wxT("")));
81 HomeIMListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
83 } else if (intType == 2){
85 BusinessIMList.insert(std::make_pair(intValueSeek, wxT("")));
86 BusinessIMListAltID.insert(std::make_pair(intValueSeek, wxT("")));
87 BusinessIMListPID.insert(std::make_pair(intValueSeek, wxT("")));
88 BusinessIMListPref.insert(std::make_pair(intValueSeek, 0));
89 BusinessIMListTokens.insert(std::make_pair(intValueSeek, wxT("")));
90 BusinessIMListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
96 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
97 intiter != SplitPoints.end(); ++intiter){
99 SLiter = SplitLength.find(intiter->first);
101 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
103 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
104 PropertyName = PropertyElement.GetNextToken();
105 PropertyValue = PropertyElement.GetNextToken();
107 ProcessCaptureStrings(&PropertyValue);
109 intPrevValue = intiter->second;
111 // Process properties.
113 if (PropertyName == wxT("ALTID")){
115 if (intType == 0){ GeneralIMListAltID.erase(intValueSeek); GeneralIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
116 else if (intType == 1){ HomeIMListAltID.erase(intValueSeek); HomeIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
117 else if (intType == 2){ BusinessIMListAltID.erase(intValueSeek); BusinessIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
119 } else if (PropertyName == wxT("PID")){
121 if (intType == 0){ GeneralIMListPID.erase(intValueSeek); GeneralIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
122 else if (intType == 1){ HomeIMListPID.erase(intValueSeek); HomeIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
123 else if (intType == 2){ BusinessIMListPID.erase(intValueSeek); BusinessIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
125 } else if (PropertyName == wxT("PREF")){
127 intPref = wxAtoi(PropertyValue);
129 if (intPref > 0 && intPref < 101){
131 if (intType == 0){ GeneralIMListPref.erase(intValueSeek); GeneralIMListPref.insert(std::make_pair(intValueSeek, intPref)); }
132 else if (intType == 1){ HomeIMListPref.erase(intValueSeek); HomeIMListPref.insert(std::make_pair(intValueSeek, intPref)); }
133 else if (intType == 2){ BusinessIMListPref.erase(intValueSeek); BusinessIMListPref.insert(std::make_pair(intValueSeek, intPref)); }
137 } else if (PropertyName == wxT("MEDIATYPE")){
139 if (intType == 0){ GeneralIMListMediatype.erase(intValueSeek); GeneralIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
140 else if (intType == 1){ HomeIMListMediatype.erase(intValueSeek); HomeIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
141 else if (intType == 2){ BusinessIMListMediatype.erase(intValueSeek); BusinessIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
145 // Something else we don't know about so append
146 // to the tokens variable.
148 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
150 if (FirstToken == TRUE){
152 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
157 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
167 // Split the address.
169 //std::map<int, int>::iterator SLiter;
170 intPropertyLen = wxSPropertySeg2.Len();
177 for (int i = 0; i <= intPropertyLen; i++){
181 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
184 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
186 if (intSplitsFound == 1){
188 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
199 // Split the data into several parts.
201 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
202 intiter != SplitPoints.end(); ++intiter){
204 if (intiter->first == 1){
208 SLiter = SplitLength.find(1);
210 //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
211 IMPPType = wxSPropertySeg2.Mid(0, SLiter->second);
212 intPrevValue = intiter->second;
214 IMPPAddress = wxSPropertySeg2.Mid(intPrevValue);
220 // Check what IM type it is.
222 if (IMPPType == wxT("aim")){
224 IMPPType = wxT("AIM");
226 } else if (IMPPType == wxT("gg")){
228 IMPPType = wxT("Gadu-Gadu");
230 } else if (IMPPType == wxT("icq")){
232 IMPPType = wxT("ICQ");
234 } else if (IMPPType == wxT("skype")){
236 IMPPType = wxT("Skype");
238 } else if (IMPPType == wxT("xmpp")){
240 IMPPType = wxT("XMPP");
242 } else if (IMPPType == wxT("yahoo")){
244 IMPPType = wxT("Yahoo");
252 // Add the data to the General/Home/Work address variables.
254 ProcessCaptureStrings(&wxSPropertySeg2);
258 coldata.SetId(intValueSeek);
259 coldata.SetData(intValueSeek);
260 coldata.SetText(IMPPType);
264 ListCtrlIndex = lboIM->InsertItem(coldata);
266 lboIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
268 if (intPref > 0 && intPref < 101){
270 lboIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
274 GeneralIMList.erase(intValueSeek);
275 GeneralIMListType.erase(intValueSeek);
276 GeneralIMListTokens.erase(intValueSeek);
277 GeneralIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
278 GeneralIMListType.insert(std::make_pair(intValueSeek, wxT("")));
279 GeneralIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
281 } else if (intType == 1){
283 ListCtrlIndex = lboHomeIM->InsertItem(coldata);
285 lboHomeIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
287 if (intPref > 0 && intPref < 101){
289 lboHomeIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
293 HomeIMList.erase(intValueSeek);
294 HomeIMListType.erase(intValueSeek);
295 HomeIMListTokens.erase(intValueSeek);
296 HomeIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
297 HomeIMListType.insert(std::make_pair(intValueSeek, wxT("home")));
298 HomeIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
300 } else if (intType == 2){
302 ListCtrlIndex = lboBusinessIM->InsertItem(coldata);
304 lboBusinessIM->SetItem(ListCtrlIndex, 1, IMPPAddress);
306 if (intPref > 0 && intPref < 101){
308 lboBusinessIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
312 BusinessIMList.erase(intValueSeek);
313 BusinessIMListType.erase(intValueSeek);
314 BusinessIMListTokens.erase(intValueSeek);
315 BusinessIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
316 BusinessIMListType.insert(std::make_pair(intValueSeek, wxT("work")));
317 BusinessIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));