1 #include "frmContactEditor.h"
2 #include "../common/base64.h"
4 void frmContactEditor::LoadPhoto(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *PhotoCount){
6 size_t intPropertyLen = wxSPropertySeg1.Len();
7 std::map<int, int> SplitPoints;
8 std::map<int, int> SplitLength;
9 std::map<int, int>::iterator SLiter;
10 wxString PropertyData;
11 wxString PropertyName;
12 wxString PropertyValue;
13 wxString PropertyTokens;
14 bool FirstToken = TRUE;
15 int intSplitsFound = 0;
22 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
26 // Look for type before continuing.
28 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
29 intiter != SplitPoints.end(); ++intiter){
31 SLiter = SplitLength.find(intiter->first);
33 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
35 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
36 PropertyName = PropertyElement.GetNextToken();
37 PropertyValue = PropertyElement.GetNextToken();
39 intPrevValue = intiter->second;
41 if (PropertyName == wxT("TYPE")){
43 if (PropertyValue == wxT("work")){
47 } else if (PropertyValue == wxT("home")){
61 // Setup blank lines for later on.
63 PicturesList.insert(std::make_pair(intValueSeek, ""));
64 PicturesListType.insert(std::make_pair(intValueSeek, wxT("")));
65 PicturesListAltID.insert(std::make_pair(intValueSeek, wxT("")));
66 PicturesListPID.insert(std::make_pair(intValueSeek, wxT("")));
67 PicturesListPref.insert(std::make_pair(intValueSeek, 0));
68 PicturesListPicEncType.insert(std::make_pair(intValueSeek, wxT("")));
69 PicturesListPictureType.insert(std::make_pair(intValueSeek, wxT("")));
70 PicturesListTokens.insert(std::make_pair(intValueSeek, wxT("")));
71 PicturesListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
75 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
76 intiter != SplitPoints.end(); ++intiter){
78 SLiter = SplitLength.find(intiter->first);
80 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
82 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
83 PropertyName = PropertyElement.GetNextToken();
84 PropertyValue = PropertyElement.GetNextToken();
86 intPrevValue = intiter->second;
88 // Process properties.
90 size_t intPropertyValueLen = PropertyValue.Len();
92 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
95 PropertyValue.RemoveLast();
99 if (PropertyValue.Mid(0, 1) == wxT("\"")){
101 PropertyValue.Remove(0, 1);
105 ProcessCaptureStrings(&PropertyValue);
107 if (PropertyName == wxT("ALTID")){
109 if (intType == 0){ PicturesListAltID.erase(intValueSeek); PicturesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
110 else if (intType == 1){ PicturesListAltID.erase(intValueSeek); PicturesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
111 else if (intType == 2){ PicturesListAltID.erase(intValueSeek); PicturesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
113 } else if (PropertyName == wxT("PID")){
115 if (intType == 0){ PicturesListPID.erase(intValueSeek); PicturesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
116 else if (intType == 1){ PicturesListPID.erase(intValueSeek); PicturesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
117 else if (intType == 2){ PicturesListPID.erase(intValueSeek); PicturesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
119 } else if (PropertyName == wxT("PREF")){
121 intPref = wxAtoi(PropertyValue);
123 if (intType == 0){ PicturesListPref.erase(intValueSeek); PicturesListPref.insert(std::make_pair(intValueSeek, intPref)); }
124 else if (intType == 1){ PicturesListPref.erase(intValueSeek); PicturesListPref.insert(std::make_pair(intValueSeek, intPref)); }
125 else if (intType == 2){ PicturesListPref.erase(intValueSeek); PicturesListPref.insert(std::make_pair(intValueSeek, intPref)); }
127 } else if (PropertyName == wxT("MEDIATYPE")){
129 if (intType == 0){ PicturesListMediatype.erase(intValueSeek); PicturesListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
130 else if (intType == 1){ PicturesListMediatype.erase(intValueSeek); PicturesListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
131 else if (intType == 2){ PicturesListMediatype.erase(intValueSeek); PicturesListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
135 // Something else we don't know about so append
136 // to the tokens variable.
138 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
140 if (FirstToken == TRUE){
142 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
147 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
157 intPropertyLen = wxSPropertySeg2.Len();
164 ProcessCaptureStrings(&wxSPropertySeg2);
166 for (int i = 0; i <= intPropertyLen; i++){
170 if (wxSPropertySeg2.Mid(i, 1) == wxT(";")){
173 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
175 if (intSplitsFound == 6){
177 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
182 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
192 wxString wxSPhotoURI;
193 wxString wxSPhotoMIME;
194 wxString wxSPhotoEncoding;
195 wxString wxSPhotoData;
196 std::string base64enc;
198 if (intSplitsFound == 0){
202 std::map<int, int>::iterator striter;
204 striter = SplitLength.find(1);
206 wxStringTokenizer wSTDataType(wxSPropertySeg2.Mid(0, striter->second), wxT(":"));
208 while (wSTDataType.HasMoreTokens() == TRUE){
210 wxSPhotoURI = wSTDataType.GetNextToken();
211 wxSPhotoMIME = wSTDataType.GetNextToken();
216 wxStringTokenizer wSTDataInfo(wxSPropertySeg2.Mid((striter->second + 1)), wxT(","));
218 while (wSTDataInfo.HasMoreTokens() == TRUE){
220 wxSPhotoEncoding = wSTDataInfo.GetNextToken();
221 wxSPhotoData = wSTDataInfo.GetNextToken();
222 base64enc = wxSPhotoData.mb_str();
229 // Add the data to the General/Home/Work address variables.
233 coldata.SetId(intValueSeek);
234 coldata.SetData(intValueSeek);
235 coldata.SetText(_("Picture"));
237 ListCtrlIndex = lboPictures->InsertItem(coldata);
239 if (intPref > 0 && intPref < 101){
241 lboPictures->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
245 PicturesList.erase(intValueSeek);
246 PicturesListType.erase(intValueSeek);
247 PicturesListTokens.erase(intValueSeek);
248 PicturesListPictureType.erase(intValueSeek);
249 PicturesListPicEncType.erase(intValueSeek);
250 PicturesList.insert(std::make_pair(intValueSeek, base64enc));
251 PicturesListPictureType.insert(std::make_pair(intValueSeek, wxSPhotoMIME));
252 PicturesListPicEncType.insert(std::make_pair(intValueSeek, wxSPhotoEncoding));
256 PicturesListType.insert(std::make_pair(intValueSeek, wxT("")));
258 } else if (intType == 1){
260 PicturesListType.insert(std::make_pair(intValueSeek, wxT("home")));
261 lboPictures->SetItem(ListCtrlIndex, 1, _("Home"));
263 } else if (intType == 2){
265 PicturesListType.insert(std::make_pair(intValueSeek, wxT("work")));
266 lboPictures->SetItem(ListCtrlIndex, 1, _("Work"));
270 PicturesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));