1 // getcontactinfo.cpp - Contact Information 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/>
23 #include <wx/tokenzr.h>
24 #include <wx/fs_mem.h>
25 #include <wx/mstream.h>
26 #include <wx/filesys.h>
27 #include <wx/datetime.h>
28 //#include <b64/decode.h>
31 #include "getcontactinfo.h"
33 #include "textprocessing.h"
34 #include "../vcard/vcard34conv.h"
36 void LoadContactData(vCard *vCardObj, wxHtmlWindow *HTMLObj, wxString SID,
37 wxString OldSID, std::map<wxString, wxString> *MemoryFSList){
39 // Load the vCard contact data into the wxHTMLWindow given.
41 // Show message to user that the contact information is loading.
43 HTMLObj->SetBorders(0);
47 wxFileSystem::AddHandler(new wxMemoryFSHandler);
49 PageData.append(wxT("<html>"));
50 PageData.append(wxT("<head>"));
51 PageData.append(wxT("<title>Page Loading</title>"));
52 PageData.append(wxT("</head>"));
53 PageData.append(wxT("<body>"));
54 PageData.append(wxT("<h2>"));
55 PageData.append(_("Loading contact information..."));
56 PageData.append(wxT("</h2>"));
57 PageData.append(wxT("</body>"));
58 PageData.append(wxT("</html>"));
60 HTMLObj->SetPage(PageData);
64 // Delete the information from the old session.
66 if (!OldSID.IsEmpty()){
68 if (MemoryFSList->find(OldSID) == MemoryFSList->end()){
73 std::map<wxString, wxString>::iterator striter;
75 for (striter = MemoryFSList->begin(); striter != MemoryFSList->end(); striter++){
77 if (OldSID == striter->second){
79 // Delete the references from the wxMemoryFSHandler
80 // and the entry from the map.
82 wxMemoryFSHandler::RemoveFile(striter->first);
89 MemoryFSList->erase(striter);
95 // MAke sure new session ID doesn't conflict with existing
96 // data. If there is a match, generate a new one and check again.
100 for (std::map<wxString, wxString>::iterator striter = MemoryFSList->begin();
101 striter != MemoryFSList->end(); striter++){
103 SIDTemp = striter->second;
107 // Generate a new random number.
109 SID = wxString::Format(wxT("%i"), rand() % 32768);
111 // Rewind the seek process back to the start.
113 striter = MemoryFSList->begin();
121 // Setup the HTML document.
123 PageData.append(wxT("<html>"));
124 PageData.append(wxT("<head>"));
125 PageData.append(wxT("<title>Contact Information</title>"));
126 PageData.append(wxT("</head>"));
128 // Process the CSS section.
130 PageData.append(wxT("<body>"));
132 // Process the data in the vCard object.
136 ArrayvCardOutData FNList;
137 FNList = vCardObj->GetByPartial(wxT("FN"));
139 PageData.append(wxT("<table style=\"background: #cccccc; width: 100%\">"));
140 PageData.append(wxT("<tr>"));
141 PageData.append(wxT("<td style=\"width:100%\">"));
142 PageData.append(wxT("<h2>"));
144 if (FNList.PropCount > 0){
145 FNList.PropValues[0].Trim();
146 CaptureString(&FNList.PropValues[0], false);
147 PageData.append(FNList.PropValues[0]);
150 PageData.append(wxT("</h2>"));
151 PageData.append(wxT("</td>"));
152 PageData.append(wxT("<td style=\"width: 200px;\">"));
154 // Define common variables for ADR.
156 std::map<int,int> SplitPoints;
157 std::map<int,int> SplitLength;
158 std::map<int,int>::iterator SLiter;
165 wxString AddressPOBox;
166 wxString AddressStreet;
167 wxString AddressLocality;
168 wxString AddressRegion;
169 wxString AddressPostalCode;
170 wxString AddressCountry;
171 wxString AddressExtended;
173 wxString FinalAddressLine;
174 bool AddressFirst = TRUE;
176 // Define common variables for PHOTO and LOGO.
178 std::string PhotoDataBin;
179 std::string PhotoDataIn;
180 wxString PhotoSplitData;
181 wxString PhotoMIMEType;
182 wxString PhotoEncType;
183 wxString PhotoEncData;
184 bool LoadPicture = FALSE;
185 bool DataDisplay = FALSE;
186 bool RectData = FALSE;
187 wxRect PhotoRectPoints;
188 wxString SIDFilename;
194 ArrayvCardOutData ContactData = vCardObj->GetByPartial(wxT("PHOTO"));
196 if (ContactData.PropCount > 0){
202 /*std::map<int,int> SplitPts;
203 std::map<int,int> SplitLen;
204 std::map<wxString,wxString> SplitData;
207 SplitPropertyData(&ContactData.PropData[0],
213 for (std::map<wxString, wxString>::iterator striter = SplitData.begin();
214 striter != SplitData.end(); striter++){
220 // Look for the X-ABCROP-RECTANGLE.
222 wxStringTokenizer PhotoSplit(ContactData.PropData[0], wxT(":"));
223 wxString PhotoPropertyDataString = PhotoSplit.GetNextToken();
224 wxStringTokenizer PhotoPropertyData(PhotoPropertyDataString, wxT(";"));
225 wxString PropertyLineData;
226 wxString PropertyName;
227 wxString PropertyValue;
229 wxStringTokenizer DataSplit(ContactData.PropValues[0], wxT(";"));
230 PhotoSplitData = DataSplit.GetNextToken();
231 wxStringTokenizer MIMESplit(PhotoSplitData, wxT(":"));
232 MIMESplit.GetNextToken();
233 PhotoMIMEType = MIMESplit.GetNextToken();
234 PhotoSplitData = DataSplit.GetNextToken();
235 wxStringTokenizer EncSplit(PhotoSplitData, wxT(","));
236 PhotoEncType = EncSplit.GetNextToken();
237 PhotoEncData = EncSplit.GetNextToken();
239 // Convert the picture data from base64 to binary.
241 PhotoDataIn = std::string(PhotoEncData.mb_str());
242 PhotoDataBin = base64_decode(PhotoDataIn);
243 wxMemoryInputStream istream(PhotoDataBin.c_str(), (size_t)PhotoDataBin.size());
246 if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
248 // Photo failed to load so do nothing.
254 while (PhotoPropertyData.HasMoreTokens()){
256 PropertyLineData = PhotoPropertyData.GetNextToken();
258 wxStringTokenizer PhotoPropPair(PropertyLineData, wxT("="));
259 wxString PhotoPropName = PhotoPropPair.GetNextToken();
260 wxString PhotoPropValue = PhotoPropPair.GetNextToken();
262 if (PhotoPropName == wxT("X-ABCROP-RECTANGLE")){
264 wxStringTokenizer PhotoRectData(PhotoPropValue, wxT("&"));
266 PhotoRectData.GetNextToken();
268 //PhotoRectPoints.SetX(wxAtoi(PhotoRectData.GetNextToken()));
269 //PhotoRectPoints.SetY(wxAtoi(PhotoRectData.GetNextToken()) - 100);
271 int PointXBase = wxAtoi(PhotoRectData.GetNextToken());
272 int PointYBase = wxAtoi(PhotoRectData.GetNextToken());
273 int PointWBase = wxAtoi(PhotoRectData.GetNextToken());
274 int PointHBase = wxAtoi(PhotoRectData.GetNextToken());
276 int PointX = PointXBase;
277 int PointY = PointYBase;
278 int PointW = PointWBase;
279 int PointH = PointHBase;
283 if (PointYBase > PointHBase){
285 PointX = photo.GetWidth() - PointXBase - 140;
286 PointY = photo.GetHeight() - PointYBase - 140;
290 } else if (PointXBase > PointWBase){
292 PointX = photo.GetWidth() - PointXBase;
293 PointY = PointYBase - 50;
301 PhotoRectPoints.SetX(PointX);
302 PhotoRectPoints.SetY(PointY);
303 PhotoRectPoints.SetWidth(PointW);
304 PhotoRectPoints.SetHeight(PointH);
313 // Resize the picture to 125x125.
315 // Add to the wxMemnoryFSHandler.
317 SIDFilename = SID + wxT("-photo");
319 if (RectData == TRUE){
321 wxImage rectphoto = photo.GetSubImage(PhotoRectPoints);
322 rectphoto = rectphoto.Scale(75, 75, wxIMAGE_QUALITY_HIGH);
323 wxMemoryFSHandler::AddFile(SIDFilename, rectphoto, wxBITMAP_TYPE_PNG);
327 photo = photo.Scale(50, 50, wxIMAGE_QUALITY_HIGH);
328 wxMemoryFSHandler::AddFile(SIDFilename, photo, wxBITMAP_TYPE_PNG);
332 // Add the filename to the MemoryFSList map.
334 MemoryFSList->insert(std::make_pair(SIDFilename, SID));
340 if (LoadPicture == TRUE){
342 PageData.append(wxT("<img src=\"memory:") + SIDFilename + wxT("\">"));
350 ContactData = vCardObj->GetByPartial(wxT("LOGO"));
352 if (ContactData.PropCount > 0){
356 wxStringTokenizer DataSplit(ContactData.PropValues[0], wxT(";"));
357 PhotoSplitData = DataSplit.GetNextToken();
358 wxStringTokenizer MIMESplit(PhotoSplitData, wxT(":"));
359 MIMESplit.GetNextToken();
360 PhotoMIMEType = MIMESplit.GetNextToken();
361 PhotoSplitData = DataSplit.GetNextToken();
362 wxStringTokenizer EncSplit(PhotoSplitData, wxT(","));
363 PhotoEncType = EncSplit.GetNextToken();
364 PhotoEncData = EncSplit.GetNextToken();
366 // Convert the picture data from base64 to binary.
368 PhotoDataIn = std::string(PhotoEncData.mb_str());
369 PhotoDataBin = base64_decode(PhotoDataIn);
370 wxMemoryInputStream istream(PhotoDataBin.c_str(), (size_t)PhotoDataBin.size());
373 if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
375 // Photo failed to load so do nothing.
383 photo = photo.Scale(50, 50, wxIMAGE_QUALITY_HIGH);
385 // Resize the picture to 125x125.
387 // Add to the wxMemnoryFSHandler.
389 SIDFilename = SID + wxT("-logo");
391 wxMemoryFSHandler::AddFile(SIDFilename, photo, wxBITMAP_TYPE_PNG);
393 // Add the filename to the MemoryFSList map.
395 MemoryFSList->insert(std::make_pair(SIDFilename, SID));
401 if (LoadPicture == TRUE){
403 PageData.append(wxT("<img src=\"memory:") + SIDFilename + wxT("\">"));
407 PageData.append(wxT("</td>"));
408 PageData.append(wxT("</tr>"));
409 PageData.append(wxT("</table>"));
411 // Process LOGO, PHOTO, SOUND, KEY, VND-* and X-*
412 // lines and display icons for each accordingly.
414 ContactData = vCardObj->GetByPartial(wxT("PHOTO"));
416 bool AddBreak = FALSE;
417 wxString TypePageData;
419 if (ContactData.PropCount > 1){
421 TypePageData.append(wxT("<img src=\"memory:cipto.png\" alt=\""));
422 TypePageData.append(_("This contact has multiple photos."));
423 TypePageData.append(wxT("\">"));
428 ContactData = vCardObj->GetByPartial(wxT("LOGO"));
430 if (ContactData.PropCount > 1){
432 TypePageData.append(wxT("<img src=\"memory:cilog.png\" alt=\""));
433 TypePageData.append(_("This contact has multiple logos."));
434 TypePageData.append(wxT("\">"));
439 ContactData = vCardObj->GetByPartial(wxT("SOUND"));
441 if (ContactData.PropCount >= 1){
443 TypePageData.append(wxT("<img src=\"memory:cisnd.png\" alt=\""));
444 TypePageData.append(_("This contact has audio information."));
445 TypePageData.append(wxT("\">"));
450 ContactData = vCardObj->GetByPartial(wxT("KEY"));
452 if (ContactData.PropCount >= 1){
454 TypePageData.append(wxT("<img src=\"memory:cikey.png\" alt=\""));
455 TypePageData.append(_("This contact has crytographic keys."));
456 TypePageData.append(wxT("\">"));
461 ContactData = vCardObj->GetByPartial(wxT("VND-"));
463 if (ContactData.PropCount >= 1){
465 TypePageData.append(wxT("<img src=\"memory:civen.png\" alt=\""));
466 TypePageData.append(_("This contact has vendor-specific information."));
467 TypePageData.append(wxT("\">"));
472 ContactData = vCardObj->GetByPartial(wxT("X-"));
474 if (ContactData.PropCount >= 1){
476 TypePageData.append(wxT("<img src=\"memory:ciext.png\" alt=\""));
477 TypePageData.append(_("This contact has extended information."));
478 TypePageData.append(wxT("\">"));
483 if (!TypePageData.IsEmpty()){
485 PageData.append("<table style=\"{background: #dddddd; width:100%}\"><tr><td>");
486 PageData.append(TypePageData);
487 PageData.append("</tr></td></table>");
491 if (AddBreak == TRUE){
493 PageData.append(wxT("<br><br>"));
499 ContactData = vCardObj->GetByPartial(wxT("BDAY"));
504 if (ContactData.PropCount > 0){
508 for (int i = 0; i < ContactData.PropCount; i++){
510 // Grab the first birthday only.
512 BDayLine = ContactData.PropValues[i];
515 CaptureString(&BDayLine, FALSE);
516 ConvertToHTML(&BDayLine);
518 DataLines.append(BDayLine);
528 PageData.append("<table CELLPADDING=4 style=\"{width: 100%;}\"><tr><td>");
530 if (DataDisplay == TRUE){
533 PageData.append(wxT("<b>"));
534 PageData.append(_("Birthday:"));
535 PageData.append(wxT("</b> "));
536 PageData.append(DataLines);
537 PageData.append(wxT("<br>"));
541 // Process Anniversary
543 ContactData = vCardObj->GetByPartial(wxT("ANNIVERSARY"));
548 if (ContactData.PropCount > 0){
552 for (int i = 0; i < ContactData.PropCount; i++){
554 // Grab the first anniversary only.
556 AnniLine = ContactData.PropValues[i];
559 CaptureString(&AnniLine, FALSE);
560 ConvertToHTML(&AnniLine);
562 DataLines.append(AnniLine);
572 if (DataDisplay == TRUE){
575 PageData.append(wxT("<b>"));
576 PageData.append(_("Anniversary:"));
577 PageData.append(wxT("</b> "));
578 PageData.append(DataLines);
579 PageData.append(wxT("<br>"));
585 ContactData = vCardObj->GetByPartial(wxT("NICKNAME"));
590 if (ContactData.PropCount > 0){
592 wxString NicknameLine;
594 for (int i = 0; i < ContactData.PropCount; i++){
596 NicknameLine = ContactData.PropValues[i];
599 CaptureString(&NicknameLine, FALSE);
600 ConvertToHTML(&NicknameLine);
602 DataLines.append(wxT("<tr><td><b>"));
603 DataLines.append(_("Nickname:"));
604 DataLines.append(wxT(" </b></td><td>"));
605 DataLines.append(NicknameLine);
606 DataLines.append(wxT("</td></tr>"));
614 if (DataDisplay == TRUE){
617 PageData.append(wxT("<h4>"));
618 PageData.append(_("Nicknames"));
619 PageData.append(wxT("</h4>"));
620 PageData.append(wxT("<br>"));
621 PageData.append(wxT("<table>"));
622 PageData.append(DataLines);
623 PageData.append(wxT("</table>"));
629 ContactData = vCardObj->GetByPartial(wxT("ADR"));
634 if (ContactData.PropCount > 0){
636 wxString AddressLine;
638 for (int i = 0; i < ContactData.PropCount; i++){
640 AddressLine = ContactData.PropValues[i];
642 intPropertyLen = AddressLine.Len();
649 AddressPOBox.clear();
650 AddressStreet.clear();
651 AddressLocality.clear();
652 AddressRegion.clear();
653 AddressPostalCode.clear();
654 AddressCountry.clear();
655 AddressExtended.clear();
656 FinalAddressLine.clear();
659 for (int i = 0; i <= intPropertyLen; i++){
663 if (AddressLine.Mid(i, 1) == wxT(";") && AddressLine.Mid((i - 1), 1) != wxT("\\")){
666 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
668 if (intSplitsFound == 6){
670 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
675 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
685 // Split the data into several parts.
687 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
688 intiter != SplitPoints.end(); ++intiter){
690 if (intiter->first == 1){
694 SLiter = SplitLength.find(1);
696 //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
697 AddressPOBox = AddressLine.Mid(0, SLiter->second);
698 intPrevValue = intiter->second;
700 } else if (intiter->first == 2){
702 // Deal with extended address.
704 SLiter = SplitLength.find(2);
706 AddressExtended = AddressLine.Mid(intPrevValue, SLiter->second);
707 //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
708 intPrevValue = intiter->second;
710 } else if (intiter->first == 3){
712 // Deal with street address.
714 SLiter = SplitLength.find(3);
716 AddressStreet = AddressLine.Mid(intPrevValue, SLiter->second);
717 //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
718 intPrevValue = intiter->second;
720 } else if (intiter->first == 4){
722 // Deal with locality
724 SLiter = SplitLength.find(4);
726 AddressLocality = AddressLine.Mid(intPrevValue, SLiter->second);
727 //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
728 intPrevValue = intiter->second;
730 //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, wxSTRING_MAXLEN), TRUE));
732 } else if (intiter->first == 5){
736 SLiter = SplitLength.find(5);
738 AddressRegion = AddressLine.Mid(intPrevValue, SLiter->second);
739 //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
740 intPrevValue = intiter->second;
742 //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, wxSTRING_MAXLEN), TRUE));
744 } else if (intiter->first == 6){
746 // Deal with post code.
748 SLiter = SplitLength.find(6);
750 AddressPostalCode = AddressLine.Mid(intPrevValue, SLiter->second);
751 //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
752 intPrevValue = intiter->second;
754 // Deal with country.
756 AddressCountry = AddressLine.Mid(intPrevValue);
757 //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, wxSTRING_MAXLEN), TRUE));
763 if (!AddressStreet.IsEmpty()){
765 AddressStreet.Trim();
766 ConvertToHTML(&AddressStreet);
768 FinalAddressLine.append(AddressStreet);
769 AddressFirst = FALSE;
773 if (!AddressLocality.IsEmpty()){
775 AddressLocality.Trim();
776 ConvertToHTML(&AddressLocality);
778 if (AddressFirst == FALSE){
780 FinalAddressLine.append(wxT(",<br>"));
781 FinalAddressLine.append(AddressLocality);
785 FinalAddressLine.append(AddressLocality);
786 AddressFirst = FALSE;
792 if (!AddressRegion.IsEmpty()){
794 AddressRegion.Trim();
795 ConvertToHTML(&AddressRegion);
797 if (AddressFirst == FALSE){
799 FinalAddressLine.append(wxT(",<br>"));
800 FinalAddressLine.append(AddressRegion);
804 FinalAddressLine.append(AddressRegion);
805 AddressFirst = FALSE;
811 if (!AddressPostalCode.IsEmpty()){
813 AddressPostalCode.Trim();
814 ConvertToHTML(&AddressPostalCode);
816 if (AddressFirst == FALSE){
818 FinalAddressLine.append(wxT(",<br>"));
819 FinalAddressLine.append(AddressPostalCode);
823 FinalAddressLine.append(AddressPostalCode);
824 AddressFirst = FALSE;
830 if (!AddressCountry.IsEmpty()){
832 AddressCountry.Trim();
833 ConvertToHTML(&AddressCountry);
835 if (AddressFirst == FALSE){
837 FinalAddressLine.append(wxT(",<br>"));
838 FinalAddressLine.append(AddressCountry);
842 FinalAddressLine.append(AddressCountry);
843 AddressFirst = FALSE;
849 CaptureString(&FinalAddressLine, FALSE);
851 DataLines.append(wxT("<tr><td><b>"));
852 DataLines.append(_("Address:"));
853 DataLines.append(wxT(" </b></td><td>"));
854 DataLines.append(FinalAddressLine);
855 DataLines.append(wxT("</td></tr>"));
863 if (DataDisplay == TRUE){
866 PageData.append(wxT("<h4>"));
867 PageData.append(_("Addresses"));
868 PageData.append(wxT("</h4>"));
869 PageData.append(wxT("<br>"));
870 PageData.append(wxT("<table>"));
871 PageData.append(DataLines);
872 PageData.append(wxT("</table>"));
878 ContactData = vCardObj->GetByPartial(wxT("EMAIL"));
883 if (ContactData.PropCount > 0){
887 for (int i = 0; i < ContactData.PropCount; i++){
889 EmailLine = ContactData.PropValues[i];
892 CaptureString(&EmailLine, FALSE);
893 ConvertToHTML(&EmailLine);
895 DataLines.append(wxT("<tr><td><b>"));
896 DataLines.append(_("E-mail Address:"));
897 DataLines.append(wxT(" </b></td><td>"));
898 DataLines.append(EmailLine);
899 DataLines.append(wxT("</td></tr>"));
907 if (DataDisplay == TRUE){
910 PageData.append(wxT("<h4>"));
911 PageData.append(_("Email Addresses"));
912 PageData.append(wxT("</h4>"));
913 PageData.append(wxT("<br>"));
914 PageData.append(wxT("<table>"));
915 PageData.append(DataLines);
916 PageData.append(wxT("</table>"));
922 ContactData = vCardObj->GetByPartial(wxT("TEL"));
927 if (ContactData.PropCount > 0){
931 for (int i = 0; i < ContactData.PropCount; i++){
933 TelLine = ContactData.PropValues[i];
935 wxStringTokenizer TelSplit(TelLine, wxT(":"));
937 TelLine = TelSplit.GetNextToken();
939 if (TelSplit.HasMoreTokens()){
941 TelLine = TelSplit.GetNextToken();
946 CaptureString(&TelLine, FALSE);
947 ConvertToHTML(&TelLine);
949 DataLines.append(wxT("<tr><td><b>"));
950 DataLines.append(_("Telephone:"));
951 DataLines.append(wxT(" </b></td><td>"));
952 DataLines.append(TelLine);
953 DataLines.append(wxT("</td></tr>"));
961 if (DataDisplay == TRUE){
964 PageData.append(wxT("<h4>"));
965 PageData.append(_("Telephones"));
966 PageData.append(wxT("</h4>"));
967 PageData.append(wxT("<br>"));
968 PageData.append(wxT("<table>"));
969 PageData.append(DataLines);
970 PageData.append(wxT("</table>"));
976 ContactData = vCardObj->GetByPartial(wxT("IMPP"));
981 if (ContactData.PropCount > 0){
984 wxString IMTypeFriendly;
987 for (int i = 0; i < ContactData.PropCount; i++){
989 IMLine = ContactData.PropValues[i];
991 wxStringTokenizer IMSplit(IMLine, wxT(":"));
993 IMType = IMSplit.GetNextToken();
994 IMLine = IMSplit.GetNextToken();
996 // Process skype, gg, icq, yahoo etc into
997 // something meaningful.
999 if (IMType == wxT("aim")){
1003 IMTypeFriendly = _("AIM");
1005 } else if (IMType == wxT("xmpp")){
1009 IMTypeFriendly = _("XMPP");
1011 } else if (IMType == wxT("icq")){
1015 IMTypeFriendly = _("ICQ");
1017 } else if (IMType == wxT("skype")){
1021 IMTypeFriendly = _("Skype");
1023 } else if (IMType == wxT("gg")){
1027 IMTypeFriendly = _("Gadu-Gadu");
1029 } else if (IMType == wxT("yahoo")){
1033 IMTypeFriendly = _("Yahoo");
1037 // Other. Use IM type that was split.
1039 IMTypeFriendly = IMType;
1044 CaptureString(&IMLine, FALSE);
1045 ConvertToHTML(&IMLine);
1047 DataLines.append(wxT("<tr><td><b>"));
1048 DataLines.append(_("IM Address"));
1049 DataLines.append(_(" ("));
1050 DataLines.append(IMTypeFriendly);
1051 DataLines.append(_("):"));
1052 DataLines.append(wxT(" </b></td><td>"));
1053 DataLines.append(IMLine);
1054 DataLines.append(wxT("</td></tr>"));
1056 IMTypeFriendly.clear();
1066 if (DataDisplay == TRUE){
1069 PageData.append(wxT("<h4>"));
1070 PageData.append(_("Instant Messaging Addresses"));
1071 PageData.append(wxT("</h4>"));
1072 PageData.append(wxT("<br>"));
1073 PageData.append(wxT("<table>"));
1074 PageData.append(DataLines);
1075 PageData.append(wxT("</table>"));
1081 ContactData = vCardObj->GetByPartial(wxT("URL"));
1083 DataDisplay = FALSE;
1086 if (ContactData.PropCount > 0){
1090 for (int i = 0; i < ContactData.PropCount; i++){
1092 URLLine = ContactData.PropValues[i];
1095 CaptureString(&URLLine, FALSE);
1096 ConvertToHTML(&URLLine);
1098 DataLines.append(wxT("<tr><td><b>"));
1099 DataLines.append(_("Website:"));
1100 DataLines.append(wxT(" </b></td><td>"));
1101 DataLines.append(URLLine);
1102 DataLines.append(wxT("</td></tr>"));
1110 if (DataDisplay == TRUE){
1113 PageData.append(wxT("<h4>"));
1114 PageData.append(_("Website Addresses"));
1115 PageData.append(wxT("</h4>"));
1116 PageData.append(wxT("<br>"));
1117 PageData.append(wxT("<table>"));
1118 PageData.append(DataLines);
1119 PageData.append(wxT("</table>"));
1125 ContactData = vCardObj->GetByPartial(wxT("LANG"));
1127 DataDisplay = FALSE;
1130 if (ContactData.PropCount > 0){
1132 wxString NicknameLine;
1134 for (int i = 0; i < ContactData.PropCount; i++){
1136 NicknameLine = ContactData.PropValues[i];
1138 NicknameLine.Trim();
1139 CaptureString(&NicknameLine, FALSE);
1140 ConvertToHTML(&NicknameLine);
1142 DataLines.append(wxT("<tr><td><b>"));
1143 DataLines.append(_("Language:"));
1144 DataLines.append(wxT(" </b></td><td>"));
1145 DataLines.append(NicknameLine);
1146 DataLines.append(wxT("</td></tr>"));
1154 if (DataDisplay == TRUE){
1157 PageData.append(wxT("<h4>"));
1158 PageData.append(_("Languages"));
1159 PageData.append(wxT("</h4>"));
1160 PageData.append(wxT("<br>"));
1161 PageData.append(wxT("<table>"));
1162 PageData.append(DataLines);
1163 PageData.append(wxT("</table>"));
1169 ContactData = vCardObj->GetByPartial(wxT("TZ"));
1171 DataDisplay = FALSE;
1174 if (ContactData.PropCount > 0){
1176 wxString NicknameLine;
1178 for (int i = 0; i < ContactData.PropCount; i++){
1180 NicknameLine = ContactData.PropValues[i];
1182 NicknameLine.Trim();
1183 CaptureString(&NicknameLine, FALSE);
1184 ConvertToHTML(&NicknameLine);
1186 DataLines.append(wxT("<tr><td><b>"));
1187 DataLines.append(_("Timezone:"));
1188 DataLines.append(wxT(" </b></td><td>"));
1189 DataLines.append(NicknameLine);
1190 DataLines.append(wxT("</td></tr>"));
1198 if (DataDisplay == TRUE){
1201 PageData.append(wxT("<h4>"));
1202 PageData.append(_("Timezones"));
1203 PageData.append(wxT("</h4>"));
1204 PageData.append(wxT("<br>"));
1205 PageData.append(wxT("<table>"));
1206 PageData.append(DataLines);
1207 PageData.append(wxT("</table>"));
1213 ContactData = vCardObj->GetByPartial(wxT("GEO"));
1215 DataDisplay = FALSE;
1218 if (ContactData.PropCount > 0){
1222 for (int i = 0; i < ContactData.PropCount; i++){
1224 GeoLine = ContactData.PropValues[i];
1226 wxStringTokenizer GeoSplit(GeoLine, wxT(":"));
1228 GeoLine = GeoSplit.GetNextToken();
1230 if (GeoSplit.HasMoreTokens()){
1232 GeoLine = GeoSplit.GetNextToken();
1237 CaptureString(&GeoLine, FALSE);
1238 ConvertToHTML(&GeoLine);
1240 DataLines.append(wxT("<tr><td><b>"));
1241 DataLines.append(_("Geoposition:"));
1242 DataLines.append(wxT(" </b></td><td>"));
1243 DataLines.append(GeoLine);
1244 DataLines.append(wxT("</td></tr>"));
1252 if (DataDisplay == TRUE){
1255 PageData.append(wxT("<h4>"));
1256 PageData.append(_("Geopositioning"));
1257 PageData.append(wxT("</h4>"));
1258 PageData.append(wxT("<br>"));
1259 PageData.append(wxT("<table>"));
1260 PageData.append(DataLines);
1261 PageData.append(wxT("</table>"));
1267 ContactData = vCardObj->GetByPartial(wxT("TITLE"));
1269 DataDisplay = FALSE;
1272 if (ContactData.PropCount > 0){
1276 for (int i = 0; i < ContactData.PropCount; i++){
1278 TitleLine = ContactData.PropValues[i];
1281 CaptureString(&TitleLine, FALSE);
1282 ConvertToHTML(&TitleLine);
1284 DataLines.append(wxT("<tr><td><b>"));
1285 DataLines.append(_("Title:"));
1286 DataLines.append(wxT(" </b></td><td>"));
1287 DataLines.append(TitleLine);
1288 DataLines.append(wxT("</td></tr>"));
1296 if (DataDisplay == TRUE){
1299 PageData.append(wxT("<h4>"));
1300 PageData.append(_("Titles"));
1301 PageData.append(wxT("</h4>"));
1302 PageData.append(wxT("<br>"));
1303 PageData.append(wxT("<table>"));
1304 PageData.append(DataLines);
1305 PageData.append(wxT("</table>"));
1311 ContactData = vCardObj->GetByPartial(wxT("ROLE"));
1313 DataDisplay = FALSE;
1316 if (ContactData.PropCount > 0){
1320 for (int i = 0; i < ContactData.PropCount; i++){
1322 RoleLine = ContactData.PropValues[i];
1325 CaptureString(&RoleLine, FALSE);
1326 ConvertToHTML(&RoleLine);
1328 DataLines.append(wxT("<tr><td><b>"));
1329 DataLines.append(_("Role:"));
1330 DataLines.append(wxT(" </b></td><td>"));
1331 DataLines.append(RoleLine);
1332 DataLines.append(wxT("</td></tr>"));
1340 if (DataDisplay == TRUE){
1343 PageData.append(wxT("<h4>"));
1344 PageData.append(_("Roles"));
1345 PageData.append(wxT("</h4>"));
1346 PageData.append(wxT("<br>"));
1347 PageData.append(wxT("<table>"));
1348 PageData.append(DataLines);
1349 PageData.append(wxT("</table>"));
1355 ContactData = vCardObj->GetByPartial(wxT("ORG"));
1357 DataDisplay = FALSE;
1360 if (ContactData.PropCount > 0){
1364 for (int i = 0; i < ContactData.PropCount; i++){
1366 OrgLine = ContactData.PropValues[i];
1369 CaptureString(&OrgLine, FALSE);
1370 ConvertToHTML(&OrgLine);
1372 DataLines.append(wxT("<tr><td><b>"));
1373 DataLines.append(_("Organisation:"));
1374 DataLines.append(wxT(" </b></td><td>"));
1375 DataLines.append(OrgLine);
1376 DataLines.append(wxT("</td></tr>"));
1384 if (DataDisplay == TRUE){
1387 PageData.append(wxT("<h4>"));
1388 PageData.append(_("Organisations"));
1389 PageData.append(wxT("</h4>"));
1390 PageData.append(wxT("<br>"));
1391 PageData.append(wxT("<table>"));
1392 PageData.append(DataLines);
1393 PageData.append(wxT("</table>"));
1399 ContactData = vCardObj->GetByPartial(wxT("CATEGORIES"));
1401 DataDisplay = FALSE;
1404 if (ContactData.PropCount > 0){
1408 for (int i = 0; i < ContactData.PropCount; i++){
1410 CatLine = ContactData.PropValues[i];
1413 CaptureString(&CatLine, FALSE);
1414 ConvertToHTML(&CatLine);
1416 DataLines.append(wxT("<tr><td><b>"));
1417 DataLines.append(_("Category:"));
1418 DataLines.append(wxT(" </b></td><td>"));
1419 DataLines.append(CatLine);
1420 DataLines.append(wxT("</td></tr>"));
1428 if (DataDisplay == TRUE){
1431 PageData.append(wxT("<h4>"));
1432 PageData.append(_("Categories"));
1433 PageData.append(wxT("</h4>"));
1434 PageData.append(wxT("<br>"));
1435 PageData.append(wxT("<table>"));
1436 PageData.append(DataLines);
1437 PageData.append(wxT("</table>"));
1445 // Calendar Addresses
1447 ContactData = vCardObj->GetByPartial(wxT("CALURI"));
1449 DataDisplay = FALSE;
1452 if (ContactData.PropCount > 0){
1454 wxString CalURILine;
1456 for (int i = 0; i < ContactData.PropCount; i++){
1458 CalURILine = ContactData.PropValues[i];
1461 CaptureString(&CalURILine, FALSE);
1462 ConvertToHTML(&CalURILine);
1464 DataLines.append(wxT("<tr><td><b>"));
1465 DataLines.append(_("Calendar Address:"));
1466 DataLines.append(wxT(" </b></td><td>"));
1467 DataLines.append(CalURILine);
1468 DataLines.append(wxT("</td></tr>"));
1476 if (DataDisplay == TRUE){
1479 PageData.append(wxT("<h4>"));
1480 PageData.append(_("Calendar Addresses"));
1481 PageData.append(wxT("</h4>"));
1482 PageData.append(wxT("<br>"));
1483 PageData.append(wxT("<table>"));
1484 PageData.append(DataLines);
1485 PageData.append(wxT("</table>"));
1489 // Calendar Request Addresses
1491 ContactData = vCardObj->GetByPartial(wxT("CALADRURI"));
1493 DataDisplay = FALSE;
1496 if (ContactData.PropCount > 0){
1498 wxString CalAdrURILine;
1500 for (int i = 0; i < ContactData.PropCount; i++){
1502 CalAdrURILine = ContactData.PropValues[i];
1504 CalAdrURILine.Trim();
1505 CaptureString(&CalAdrURILine, FALSE);
1506 ConvertToHTML(&CalAdrURILine);
1508 DataLines.append(wxT("<tr><td><b>"));
1509 DataLines.append(_("Calendar Request Address:"));
1510 DataLines.append(wxT(" </b></td><td>"));
1511 DataLines.append(CalAdrURILine);
1512 DataLines.append(wxT("</td></tr>"));
1520 if (DataDisplay == TRUE){
1523 PageData.append(wxT("<h4>"));
1524 PageData.append(_("Calendar Request Addresses"));
1525 PageData.append(wxT("</h4>"));
1526 PageData.append(wxT("<br>"));
1527 PageData.append(wxT("<table>"));
1528 PageData.append(DataLines);
1529 PageData.append(wxT("</table>"));
1533 // Free/Busy Addresses
1535 ContactData = vCardObj->GetByPartial(wxT("FBURL"));
1537 DataDisplay = FALSE;
1540 if (ContactData.PropCount > 0){
1544 for (int i = 0; i < ContactData.PropCount; i++){
1546 FBURLLine = ContactData.PropValues[i];
1549 CaptureString(&FBURLLine, FALSE);
1550 ConvertToHTML(&FBURLLine);
1552 DataLines.append(wxT("<tr><td><b>"));
1553 DataLines.append(_("Free/Busy Address:"));
1554 DataLines.append(wxT(" </b></td><td>"));
1555 DataLines.append(FBURLLine);
1556 DataLines.append(wxT("</td></tr>"));
1564 if (DataDisplay == TRUE){
1567 PageData.append(wxT("<h4>"));
1568 PageData.append(_("Free/Busy Addresses"));
1569 PageData.append(wxT("</h4>"));
1570 PageData.append(wxT("<br>"));
1571 PageData.append(wxT("<table>"));
1572 PageData.append(DataLines);
1573 PageData.append(wxT("</table>"));
1579 ContactData = vCardObj->GetByPartial(wxT("NOTE"));
1581 DataDisplay = FALSE;
1584 if (ContactData.PropCount > 0){
1588 for (int i = 0; i < ContactData.PropCount; i++){
1590 NoteLine = ContactData.PropValues[i];
1593 CaptureString(&NoteLine, FALSE);
1594 ConvertToHTML(&NoteLine);
1596 DataLines.append(wxT("<tr><td><b>"));
1597 DataLines.append(_("Note:"));
1598 DataLines.append(wxT(" </b></td><td>"));
1599 DataLines.append(NoteLine);
1600 DataLines.append(wxT("</td></tr>"));
1608 if (DataDisplay == TRUE){
1610 PageData.append(wxT("<h4>"));
1611 PageData.append(_("Notes"));
1612 PageData.append(wxT("</h4>"));
1613 PageData.append(wxT("<br>"));
1614 PageData.append(wxT("<table>"));
1615 PageData.append(DataLines);
1616 PageData.append(wxT("</table>"));
1620 // Display the HTML document on the screen.
1622 PageData.append("</td></tr></table>");
1624 PageData.append(wxT("</body>"));
1625 PageData.append(wxT("</html>"));
1627 HTMLObj->SetPage(PageData);
1631 void SplitPropertyData(wxString *PropertyLine,
1632 std::map<int,int> *SplitPoints,
1633 std::map<int,int> *SplitLength,
1635 std::map<wxString,wxString> *SplitData){
1637 // Split the property data into SplitData.
1640 wxStringTokenizer PropertyElement;
1641 wxString PropertyName;
1642 wxString PropertyValue;
1643 int intPropertyLen = PropertyLine->Len();
1644 int intSplitsFound = 0;
1645 int intSplitSize = 0;
1646 int intSplitSeek = (intSize - 1);
1648 for (int i = intSize; i <= intPropertyLen; i++){
1652 if (PropertyLine->Mid(i, 1) == wxT(";") &&
1653 PropertyLine->Mid((i - 1), 1) != wxT("\\")){
1655 if (intSplitsFound == 0){
1657 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize));
1658 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
1662 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize - 1));
1663 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1667 SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
1670 intSplitSeek = (i + 1);
1673 if (!DataStr.IsEmpty()){
1675 PropertyElement.SetString(DataStr, wxT("="));
1676 PropertyName = PropertyElement.GetNextToken();
1677 PropertyValue = PropertyElement.GetNextToken();
1678 SplitData->insert(std::make_pair(PropertyName, PropertyValue));
1683 PropertyName.clear();
1684 PropertyValue.clear();
1690 if (intSplitsFound == 0){
1692 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize));
1694 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
1695 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1699 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize - 1));
1701 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
1702 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1706 if (!DataStr.IsEmpty()){
1708 PropertyElement.SetString(DataStr, wxT("="));
1709 PropertyName = PropertyElement.GetNextToken();
1710 PropertyValue = PropertyElement.GetNextToken();
1711 SplitData->insert(std::make_pair(PropertyName, PropertyValue));