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 // Show message to user that the contact information is loading.
43 wxFileSystem::AddHandler(new wxMemoryFSHandler);
44 //wxMemoryFSHandler::AddFile();
46 PageData.append(wxT("<html>"));
47 PageData.append(wxT("<head>"));
48 PageData.append(wxT("<title>Page Loading</title>"));
49 PageData.append(wxT("</head>"));
50 PageData.append(wxT("<body>"));
51 PageData.append(wxT("<h2>"));
52 PageData.append(_("Loading contact information..."));
53 PageData.append(wxT("</h2>"));
54 PageData.append(wxT("</body>"));
55 PageData.append(wxT("</html>"));
57 HTMLObj->SetPage(PageData);
61 // Delete the information from the old session.
63 if (!OldSID.IsEmpty()){
65 if (MemoryFSList->find(OldSID) == MemoryFSList->end()){
70 std::map<wxString, wxString>::iterator striter;
72 for (striter = MemoryFSList->begin(); striter != MemoryFSList->end(); striter++){
74 if (OldSID == striter->second){
76 // Delete the references from the wxMemoryFSHandler
77 // and the entry from the map.
79 wxMemoryFSHandler::RemoveFile(striter->first);
86 MemoryFSList->erase(striter);
92 // MAke sure new session ID doesn't conflict with existing
93 // data. If there is a match, generate a new one and check again.
95 bool SIDMatch = FALSE;
98 for (std::map<wxString, wxString>::iterator striter = MemoryFSList->begin();
99 striter != MemoryFSList->end(); striter++){
101 SIDTemp = striter->second;
105 // Generate a new random number.
107 SID = wxString::Format(wxT("%i"), rand() % 32768);
109 // Rewind the seek process back to the start.
111 striter = MemoryFSList->begin();
119 // Setup the HTML document.
121 PageData.append(wxT("<html>"));
122 PageData.append(wxT("<head>"));
123 PageData.append(wxT("<title>Contact Information</title>"));
124 PageData.append(wxT("</head>"));
125 PageData.append(wxT("<body>"));
127 // Process the data in the vCard object.
131 PageData.append(wxT("<table>"));
132 PageData.append(wxT("<tr>"));
133 PageData.append(wxT("<td>"));
134 PageData.append(wxT("<h2>"));
135 PageData.append(vCardObj->Get(wxT("FN")));
136 PageData.append(wxT("</h2>"));
137 PageData.append(wxT("</td>"));
138 PageData.append(wxT("<td>"));
140 // Define common variables for ADR.
142 std::map<int,int> SplitPoints;
143 std::map<int,int> SplitLength;
144 std::map<int,int>::iterator SLiter;
151 wxString AddressPOBox;
152 wxString AddressStreet;
153 wxString AddressLocality;
154 wxString AddressRegion;
155 wxString AddressPostalCode;
156 wxString AddressCountry;
157 wxString AddressExtended;
159 wxString FinalAddressLine;
160 bool AddressFirst = TRUE;
162 // Define common variables for PHOTO and LOGO.
164 std::string PhotoDataBin;
165 std::string PhotoDataIn;
166 wxString PhotoSplitData;
167 wxString PhotoMIMEType;
168 wxString PhotoEncType;
169 wxString PhotoEncData;
170 bool LoadPicture = FALSE;
171 bool DataDisplay = FALSE;
172 bool RectData = FALSE;
173 wxRect PhotoRectPoints;
174 wxString SIDFilename;
180 ArrayvCardOutData ContactData = vCardObj->GetByPartial(wxT("PHOTO"));
182 if (ContactData.PropCount > 0){
188 /*std::map<int,int> SplitPts;
189 std::map<int,int> SplitLen;
190 std::map<wxString,wxString> SplitData;
193 SplitPropertyData(&ContactData.PropData[0],
199 for (std::map<wxString, wxString>::iterator striter = SplitData.begin();
200 striter != SplitData.end(); striter++){
206 // Look for the X-ABCROP-RECTANGLE.
208 wxStringTokenizer PhotoSplit(ContactData.PropData[0], wxT(":"));
209 wxString PhotoPropertyDataString = PhotoSplit.GetNextToken();
210 wxStringTokenizer PhotoPropertyData(PhotoPropertyDataString, wxT(";"));
211 wxString PropertyLineData;
212 wxString PropertyName;
213 wxString PropertyValue;
215 wxStringTokenizer DataSplit(ContactData.PropValues[0], wxT(";"));
216 PhotoSplitData = DataSplit.GetNextToken();
217 wxStringTokenizer MIMESplit(PhotoSplitData, wxT(":"));
218 MIMESplit.GetNextToken();
219 PhotoMIMEType = MIMESplit.GetNextToken();
220 PhotoSplitData = DataSplit.GetNextToken();
221 wxStringTokenizer EncSplit(PhotoSplitData, wxT(","));
222 PhotoEncType = EncSplit.GetNextToken();
223 PhotoEncData = EncSplit.GetNextToken();
225 // Convert the picture data from base64 to binary.
227 PhotoDataIn = std::string(PhotoEncData.mb_str());
228 PhotoDataBin = base64_decode(PhotoDataIn);
229 wxMemoryInputStream istream(PhotoDataBin.c_str(), (size_t)PhotoDataBin.size());
232 if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
234 // Photo failed to load so do nothing.
240 while (PhotoPropertyData.HasMoreTokens()){
242 PropertyLineData = PhotoPropertyData.GetNextToken();
244 wxStringTokenizer PhotoPropPair(PropertyLineData, wxT("="));
245 wxString PhotoPropName = PhotoPropPair.GetNextToken();
246 wxString PhotoPropValue = PhotoPropPair.GetNextToken();
248 if (PhotoPropName == wxT("X-ABCROP-RECTANGLE")){
250 wxStringTokenizer PhotoRectData(PhotoPropValue, wxT("&"));
252 PhotoRectData.GetNextToken();
254 //PhotoRectPoints.SetX(wxAtoi(PhotoRectData.GetNextToken()));
255 //PhotoRectPoints.SetY(wxAtoi(PhotoRectData.GetNextToken()) - 100);
257 int PointXBase = wxAtoi(PhotoRectData.GetNextToken());
258 int PointYBase = wxAtoi(PhotoRectData.GetNextToken());
259 int PointWBase = wxAtoi(PhotoRectData.GetNextToken());
260 int PointHBase = wxAtoi(PhotoRectData.GetNextToken());
262 int PointX = PointXBase;
263 int PointY = PointYBase;
264 int PointW = PointWBase;
265 int PointH = PointHBase;
269 if (PointYBase > PointHBase){
271 PointX = photo.GetWidth() - PointXBase - 140;
272 PointY = photo.GetHeight() - PointYBase - 140;
276 } else if (PointXBase > PointWBase){
278 PointX = photo.GetWidth() - PointXBase;
279 PointY = PointYBase - 50;
287 /*int PointX = PointXBase;
288 int PointY = PointYBase;
289 int PointW = PointWBase;
290 int PointH = PointHBase;*/
292 // Bottom Left Method
294 /*int PointX = wxAtoi(PhotoRectData.GetNextToken());
295 int PointY = photo.GetHeight() - wxAtoi(PhotoRectData.GetNextToken()) - 340;
296 int PointW = wxAtoi(PhotoRectData.GetNextToken());
297 int PointH = wxAtoi(PhotoRectData.GetNextToken());*/
299 // Bottom Right Method
301 /*int PointXRemain = photo.GetWidth() - PointX - 140;
302 int PointYRemain = photo.GetHeight() - PointY - 140;*/
304 PhotoRectPoints.SetX(PointX);
305 PhotoRectPoints.SetY(PointY);
306 PhotoRectPoints.SetWidth(PointW);
307 PhotoRectPoints.SetHeight(PointH);
316 // Resize the picture to 125x125.
318 // Add to the wxMemnoryFSHandler.
320 SIDFilename = SID + wxT("-photo");
322 if (RectData == TRUE){
324 wxImage rectphoto = photo.GetSubImage(PhotoRectPoints);
325 rectphoto = rectphoto.Scale(75, 75, wxIMAGE_QUALITY_HIGH);
326 wxMemoryFSHandler::AddFile(SIDFilename, rectphoto, wxBITMAP_TYPE_PNG);
330 photo = photo.Scale(50, 50, wxIMAGE_QUALITY_HIGH);
331 wxMemoryFSHandler::AddFile(SIDFilename, photo, wxBITMAP_TYPE_PNG);
335 // Add the filename to the MemoryFSList map.
337 MemoryFSList->insert(std::make_pair(SIDFilename, SID));
343 if (LoadPicture == TRUE){
345 PageData.append(wxT("<img src=\"memory:") + SIDFilename + wxT("\">"));
353 ContactData = vCardObj->GetByPartial(wxT("LOGO"));
355 if (ContactData.PropCount > 0){
359 wxStringTokenizer DataSplit(ContactData.PropValues[0], wxT(";"));
360 PhotoSplitData = DataSplit.GetNextToken();
361 wxStringTokenizer MIMESplit(PhotoSplitData, wxT(":"));
362 MIMESplit.GetNextToken();
363 PhotoMIMEType = MIMESplit.GetNextToken();
364 PhotoSplitData = DataSplit.GetNextToken();
365 wxStringTokenizer EncSplit(PhotoSplitData, wxT(","));
366 PhotoEncType = EncSplit.GetNextToken();
367 PhotoEncData = EncSplit.GetNextToken();
369 // Convert the picture data from base64 to binary.
371 PhotoDataIn = std::string(PhotoEncData.mb_str());
372 PhotoDataBin = base64_decode(PhotoDataIn);
373 wxMemoryInputStream istream(PhotoDataBin.c_str(), (size_t)PhotoDataBin.size());
376 if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
378 // Photo failed to load so do nothing.
386 photo = photo.Scale(50, 50, wxIMAGE_QUALITY_HIGH);
388 // Resize the picture to 125x125.
390 // Add to the wxMemnoryFSHandler.
392 SIDFilename = SID + wxT("-logo");
394 wxMemoryFSHandler::AddFile(SIDFilename, photo, wxBITMAP_TYPE_PNG);
396 // Add the filename to the MemoryFSList map.
398 MemoryFSList->insert(std::make_pair(SIDFilename, SID));
404 if (LoadPicture == TRUE){
406 PageData.append(wxT("<img src=\"memory:") + SIDFilename + wxT("\">"));
410 PageData.append(wxT("</td>"));
411 PageData.append(wxT("</tr>"));
412 PageData.append(wxT("</table>"));
414 // Process LOGO, PHOTO, SOUND, KEY, VND-* and X-*
415 // lines and display icons for each accordingly.
417 ContactData = vCardObj->GetByPartial(wxT("PHOTO"));
419 bool AddBreak = FALSE;
421 if (ContactData.PropCount > 1){
423 PageData.append(wxT("<img src=\"memory:cipto.png\" alt=\""));
424 PageData.append(_("This contact has multiple photos."));
425 PageData.append(wxT("\">"));
430 ContactData = vCardObj->GetByPartial(wxT("LOGO"));
432 if (ContactData.PropCount > 1){
434 PageData.append(wxT("<img src=\"memory:cilog.png\" alt=\""));
435 PageData.append(_("This contact has multiple logos."));
436 PageData.append(wxT("\">"));
441 ContactData = vCardObj->GetByPartial(wxT("SOUND"));
443 if (ContactData.PropCount >= 1){
445 PageData.append(wxT("<img src=\"memory:cisnd.png\" alt=\""));
446 PageData.append(_("This contact has audio information."));
447 PageData.append(wxT("\">"));
452 ContactData = vCardObj->GetByPartial(wxT("KEY"));
454 if (ContactData.PropCount >= 1){
456 PageData.append(wxT("<img src=\"memory:cikey.png\" alt=\""));
457 PageData.append(_("This contact has crytographic keys."));
458 PageData.append(wxT("\">"));
463 ContactData = vCardObj->GetByPartial(wxT("VND-"));
465 if (ContactData.PropCount >= 1){
467 PageData.append(wxT("<img src=\"memory:civen.png\" alt=\""));
468 PageData.append(_("This contact has vendor-specific information."));
469 PageData.append(wxT("\">"));
474 ContactData = vCardObj->GetByPartial(wxT("X-"));
476 if (ContactData.PropCount >= 1){
478 PageData.append(wxT("<img src=\"memory:ciext.png\" alt=\""));
479 PageData.append(_("This contact has extended information."));
480 PageData.append(wxT("\">"));
485 if (AddBreak == TRUE){
487 PageData.append(wxT("<br><br>"));
491 bool MultiLogoIcon = FALSE;
492 bool MultiPhotoIcon = FALSE;
493 bool SoundIcon = FALSE;
494 bool KeyIcon = FALSE;
495 bool VendorIcon = FALSE;
496 bool XTokenIcon = FALSE;
500 ContactData = vCardObj->GetByPartial(wxT("BDAY"));
505 if (ContactData.PropCount > 0){
509 for (int i = 0; i < ContactData.PropCount; i++){
511 // Grab the first birthday only.
513 BDayLine = ContactData.PropValues[i];
516 CaptureString(&BDayLine, FALSE);
517 ConvertToHTML(&BDayLine);
519 DataLines.append(BDayLine);
529 if (DataDisplay == TRUE){
532 PageData.append(wxT("<b>"));
533 PageData.append(_("Birthday:"));
534 PageData.append(wxT("</b> "));
535 PageData.append(DataLines);
536 PageData.append(wxT("<br>"));
540 // Process Anniversary
542 ContactData = vCardObj->GetByPartial(wxT("ANNIVERSARY"));
547 if (ContactData.PropCount > 0){
551 for (int i = 0; i < ContactData.PropCount; i++){
553 // Grab the first anniversary only.
555 AnniLine = ContactData.PropValues[i];
558 CaptureString(&AnniLine, FALSE);
559 ConvertToHTML(&AnniLine);
561 DataLines.append(AnniLine);
571 if (DataDisplay == TRUE){
574 PageData.append(wxT("<b>"));
575 PageData.append(_("Anniversary:"));
576 PageData.append(wxT("</b> "));
577 PageData.append(DataLines);
578 PageData.append(wxT("<br>"));
584 ContactData = vCardObj->GetByPartial(wxT("NICKNAME"));
589 if (ContactData.PropCount > 0){
591 wxString NicknameLine;
593 for (int i = 0; i < ContactData.PropCount; i++){
595 NicknameLine = ContactData.PropValues[i];
598 CaptureString(&NicknameLine, FALSE);
599 ConvertToHTML(&NicknameLine);
601 DataLines.append(wxT("<tr><td><b>"));
602 DataLines.append(_("Nickname:"));
603 DataLines.append(wxT(" </b></td><td>"));
604 DataLines.append(NicknameLine);
605 DataLines.append(wxT("</td></tr>"));
613 if (DataDisplay == TRUE){
616 PageData.append(wxT("<h4>"));
617 PageData.append(_("Nicknames"));
618 PageData.append(wxT("</h4>"));
619 PageData.append(wxT("<br>"));
620 PageData.append(wxT("<table>"));
621 PageData.append(DataLines);
622 PageData.append(wxT("</table>"));
628 ContactData = vCardObj->GetByPartial(wxT("ADR"));
633 if (ContactData.PropCount > 0){
635 wxString AddressLine;
637 for (int i = 0; i < ContactData.PropCount; i++){
639 AddressLine = ContactData.PropValues[i];
641 intPropertyLen = AddressLine.Len();
648 AddressPOBox.clear();
649 AddressStreet.clear();
650 AddressLocality.clear();
651 AddressRegion.clear();
652 AddressPostalCode.clear();
653 AddressCountry.clear();
654 AddressExtended.clear();
655 FinalAddressLine.clear();
658 for (int i = 0; i <= intPropertyLen; i++){
662 if (AddressLine.Mid(i, 1) == wxT(";") && AddressLine.Mid((i - 1), 1) != wxT("\\")){
665 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
667 if (intSplitsFound == 6){
669 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
674 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
684 // Split the data into several parts.
686 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
687 intiter != SplitPoints.end(); ++intiter){
689 if (intiter->first == 1){
693 SLiter = SplitLength.find(1);
695 //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
696 AddressPOBox = AddressLine.Mid(0, SLiter->second);
697 intPrevValue = intiter->second;
699 } else if (intiter->first == 2){
701 // Deal with extended address.
703 SLiter = SplitLength.find(2);
705 AddressExtended = AddressLine.Mid(intPrevValue, SLiter->second);
706 //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
707 intPrevValue = intiter->second;
709 } else if (intiter->first == 3){
711 // Deal with street address.
713 SLiter = SplitLength.find(3);
715 AddressStreet = AddressLine.Mid(intPrevValue, SLiter->second);
716 //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
717 intPrevValue = intiter->second;
719 } else if (intiter->first == 4){
721 // Deal with locality
723 SLiter = SplitLength.find(4);
725 AddressLocality = AddressLine.Mid(intPrevValue, SLiter->second);
726 //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
727 intPrevValue = intiter->second;
729 //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, wxSTRING_MAXLEN), TRUE));
731 } else if (intiter->first == 5){
735 SLiter = SplitLength.find(5);
737 AddressRegion = AddressLine.Mid(intPrevValue, SLiter->second);
738 //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
739 intPrevValue = intiter->second;
741 //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, wxSTRING_MAXLEN), TRUE));
743 } else if (intiter->first == 6){
745 // Deal with post code.
747 SLiter = SplitLength.find(6);
749 AddressPostalCode = AddressLine.Mid(intPrevValue, SLiter->second);
750 //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
751 intPrevValue = intiter->second;
753 // Deal with country.
755 AddressCountry = AddressLine.Mid(intPrevValue);
756 //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, wxSTRING_MAXLEN), TRUE));
762 if (!AddressStreet.IsEmpty()){
764 AddressStreet.Trim();
765 ConvertToHTML(&AddressStreet);
767 FinalAddressLine.append(AddressStreet);
768 AddressFirst = FALSE;
772 if (!AddressLocality.IsEmpty()){
774 AddressLocality.Trim();
775 ConvertToHTML(&AddressLocality);
777 if (AddressFirst == FALSE){
779 FinalAddressLine.append(wxT(",<br>"));
780 FinalAddressLine.append(AddressLocality);
784 FinalAddressLine.append(AddressLocality);
785 AddressFirst = FALSE;
791 if (!AddressRegion.IsEmpty()){
793 AddressRegion.Trim();
794 ConvertToHTML(&AddressRegion);
796 if (AddressFirst == FALSE){
798 FinalAddressLine.append(wxT(",<br>"));
799 FinalAddressLine.append(AddressRegion);
803 FinalAddressLine.append(AddressRegion);
804 AddressFirst = FALSE;
810 if (!AddressPostalCode.IsEmpty()){
812 AddressPostalCode.Trim();
813 ConvertToHTML(&AddressPostalCode);
815 if (AddressFirst == FALSE){
817 FinalAddressLine.append(wxT(",<br>"));
818 FinalAddressLine.append(AddressPostalCode);
822 FinalAddressLine.append(AddressPostalCode);
823 AddressFirst = FALSE;
829 if (!AddressCountry.IsEmpty()){
831 AddressCountry.Trim();
832 ConvertToHTML(&AddressCountry);
834 if (AddressFirst == FALSE){
836 FinalAddressLine.append(wxT(",<br>"));
837 FinalAddressLine.append(AddressCountry);
841 FinalAddressLine.append(AddressCountry);
842 AddressFirst = FALSE;
848 CaptureString(&FinalAddressLine, FALSE);
850 DataLines.append(wxT("<tr><td><b>"));
851 DataLines.append(_("Address:"));
852 DataLines.append(wxT(" </b></td><td>"));
853 DataLines.append(FinalAddressLine);
854 DataLines.append(wxT("</td></tr>"));
862 if (DataDisplay == TRUE){
865 PageData.append(wxT("<h4>"));
866 PageData.append(_("Addresses"));
867 PageData.append(wxT("</h4>"));
868 PageData.append(wxT("<br>"));
869 PageData.append(wxT("<table>"));
870 PageData.append(DataLines);
871 PageData.append(wxT("</table>"));
877 ContactData = vCardObj->GetByPartial(wxT("EMAIL"));
882 if (ContactData.PropCount > 0){
886 for (int i = 0; i < ContactData.PropCount; i++){
888 EmailLine = ContactData.PropValues[i];
891 CaptureString(&EmailLine, FALSE);
892 ConvertToHTML(&EmailLine);
894 DataLines.append(wxT("<tr><td><b>"));
895 DataLines.append(_("E-mail Address:"));
896 DataLines.append(wxT(" </b></td><td>"));
897 DataLines.append(EmailLine);
898 DataLines.append(wxT("</td></tr>"));
906 if (DataDisplay == TRUE){
909 PageData.append(wxT("<h4>"));
910 PageData.append(_("Email Addresses"));
911 PageData.append(wxT("</h4>"));
912 PageData.append(wxT("<br>"));
913 PageData.append(wxT("<table>"));
914 PageData.append(DataLines);
915 PageData.append(wxT("</table>"));
921 ContactData = vCardObj->GetByPartial(wxT("TEL"));
926 if (ContactData.PropCount > 0){
930 for (int i = 0; i < ContactData.PropCount; i++){
932 TelLine = ContactData.PropValues[i];
934 wxStringTokenizer TelSplit(TelLine, wxT(":"));
936 TelLine = TelSplit.GetNextToken();
938 if (TelSplit.HasMoreTokens()){
940 TelLine = TelSplit.GetNextToken();
945 CaptureString(&TelLine, FALSE);
946 ConvertToHTML(&TelLine);
948 DataLines.append(wxT("<tr><td><b>"));
949 DataLines.append(_("Telephone:"));
950 DataLines.append(wxT(" </b></td><td>"));
951 DataLines.append(TelLine);
952 DataLines.append(wxT("</td></tr>"));
960 if (DataDisplay == TRUE){
963 PageData.append(wxT("<h4>"));
964 PageData.append(_("Telephones"));
965 PageData.append(wxT("</h4>"));
966 PageData.append(wxT("<br>"));
967 PageData.append(wxT("<table>"));
968 PageData.append(DataLines);
969 PageData.append(wxT("</table>"));
975 ContactData = vCardObj->GetByPartial(wxT("IMPP"));
980 if (ContactData.PropCount > 0){
983 wxString IMTypeFriendly;
986 for (int i = 0; i < ContactData.PropCount; i++){
988 IMLine = ContactData.PropValues[i];
990 wxStringTokenizer IMSplit(IMLine, wxT(":"));
992 IMType = IMSplit.GetNextToken();
993 IMLine = IMSplit.GetNextToken();
995 // Process skype, gg, icq, yahoo etc into
996 // something meaningful.
998 if (IMType == wxT("aim")){
1002 IMTypeFriendly = _("AIM");
1004 } else if (IMType == wxT("xmpp")){
1008 IMTypeFriendly = _("XMPP");
1010 } else if (IMType == wxT("icq")){
1014 IMTypeFriendly = _("ICQ");
1016 } else if (IMType == wxT("skype")){
1020 IMTypeFriendly = _("Skype");
1022 } else if (IMType == wxT("gg")){
1026 IMTypeFriendly = _("Gadu-Gadu");
1028 } else if (IMType == wxT("yahoo")){
1032 IMTypeFriendly = _("Yahoo");
1036 // Other. Use IM type that was split.
1038 IMTypeFriendly = IMType;
1043 CaptureString(&IMLine, FALSE);
1044 ConvertToHTML(&IMLine);
1046 DataLines.append(wxT("<tr><td><b>"));
1047 DataLines.append(_("IM Address"));
1048 DataLines.append(_(" ("));
1049 DataLines.append(IMTypeFriendly);
1050 DataLines.append(_("):"));
1051 DataLines.append(wxT(" </b></td><td>"));
1052 DataLines.append(IMLine);
1053 DataLines.append(wxT("</td></tr>"));
1055 IMTypeFriendly.clear();
1065 if (DataDisplay == TRUE){
1068 PageData.append(wxT("<h4>"));
1069 PageData.append(_("Instant Messaging Addresses"));
1070 PageData.append(wxT("</h4>"));
1071 PageData.append(wxT("<br>"));
1072 PageData.append(wxT("<table>"));
1073 PageData.append(DataLines);
1074 PageData.append(wxT("</table>"));
1080 ContactData = vCardObj->GetByPartial(wxT("URL"));
1082 DataDisplay = FALSE;
1085 if (ContactData.PropCount > 0){
1089 for (int i = 0; i < ContactData.PropCount; i++){
1091 URLLine = ContactData.PropValues[i];
1094 CaptureString(&URLLine, FALSE);
1095 ConvertToHTML(&URLLine);
1097 DataLines.append(wxT("<tr><td><b>"));
1098 DataLines.append(_("Website:"));
1099 DataLines.append(wxT(" </b></td><td>"));
1100 DataLines.append(URLLine);
1101 DataLines.append(wxT("</td></tr>"));
1109 if (DataDisplay == TRUE){
1112 PageData.append(wxT("<h4>"));
1113 PageData.append(_("Website Addresses"));
1114 PageData.append(wxT("</h4>"));
1115 PageData.append(wxT("<br>"));
1116 PageData.append(wxT("<table>"));
1117 PageData.append(DataLines);
1118 PageData.append(wxT("</table>"));
1124 ContactData = vCardObj->GetByPartial(wxT("LANG"));
1126 DataDisplay = FALSE;
1129 if (ContactData.PropCount > 0){
1131 wxString NicknameLine;
1133 for (int i = 0; i < ContactData.PropCount; i++){
1135 NicknameLine = ContactData.PropValues[i];
1137 NicknameLine.Trim();
1138 CaptureString(&NicknameLine, FALSE);
1139 ConvertToHTML(&NicknameLine);
1141 DataLines.append(wxT("<tr><td><b>"));
1142 DataLines.append(_("Language:"));
1143 DataLines.append(wxT(" </b></td><td>"));
1144 DataLines.append(NicknameLine);
1145 DataLines.append(wxT("</td></tr>"));
1153 if (DataDisplay == TRUE){
1156 PageData.append(wxT("<h4>"));
1157 PageData.append(_("Languages"));
1158 PageData.append(wxT("</h4>"));
1159 PageData.append(wxT("<br>"));
1160 PageData.append(wxT("<table>"));
1161 PageData.append(DataLines);
1162 PageData.append(wxT("</table>"));
1168 ContactData = vCardObj->GetByPartial(wxT("TZ"));
1170 DataDisplay = FALSE;
1173 if (ContactData.PropCount > 0){
1175 wxString NicknameLine;
1177 for (int i = 0; i < ContactData.PropCount; i++){
1179 NicknameLine = ContactData.PropValues[i];
1181 NicknameLine.Trim();
1182 CaptureString(&NicknameLine, FALSE);
1183 ConvertToHTML(&NicknameLine);
1185 DataLines.append(wxT("<tr><td><b>"));
1186 DataLines.append(_("Timezone:"));
1187 DataLines.append(wxT(" </b></td><td>"));
1188 DataLines.append(NicknameLine);
1189 DataLines.append(wxT("</td></tr>"));
1197 if (DataDisplay == TRUE){
1200 PageData.append(wxT("<h4>"));
1201 PageData.append(_("Timezones"));
1202 PageData.append(wxT("</h4>"));
1203 PageData.append(wxT("<br>"));
1204 PageData.append(wxT("<table>"));
1205 PageData.append(DataLines);
1206 PageData.append(wxT("</table>"));
1212 ContactData = vCardObj->GetByPartial(wxT("GEO"));
1214 DataDisplay = FALSE;
1217 if (ContactData.PropCount > 0){
1221 for (int i = 0; i < ContactData.PropCount; i++){
1223 GeoLine = ContactData.PropValues[i];
1225 wxStringTokenizer GeoSplit(GeoLine, wxT(":"));
1227 GeoLine = GeoSplit.GetNextToken();
1229 if (GeoSplit.HasMoreTokens()){
1231 GeoLine = GeoSplit.GetNextToken();
1236 CaptureString(&GeoLine, FALSE);
1237 ConvertToHTML(&GeoLine);
1239 DataLines.append(wxT("<tr><td><b>"));
1240 DataLines.append(_("Geoposition:"));
1241 DataLines.append(wxT(" </b></td><td>"));
1242 DataLines.append(GeoLine);
1243 DataLines.append(wxT("</td></tr>"));
1251 if (DataDisplay == TRUE){
1254 PageData.append(wxT("<h4>"));
1255 PageData.append(_("Geopositioning"));
1256 PageData.append(wxT("</h4>"));
1257 PageData.append(wxT("<br>"));
1258 PageData.append(wxT("<table>"));
1259 PageData.append(DataLines);
1260 PageData.append(wxT("</table>"));
1266 ContactData = vCardObj->GetByPartial(wxT("TITLE"));
1268 DataDisplay = FALSE;
1271 if (ContactData.PropCount > 0){
1275 for (int i = 0; i < ContactData.PropCount; i++){
1277 TitleLine = ContactData.PropValues[i];
1280 CaptureString(&TitleLine, FALSE);
1281 ConvertToHTML(&TitleLine);
1283 DataLines.append(wxT("<tr><td><b>"));
1284 DataLines.append(_("Title:"));
1285 DataLines.append(wxT(" </b></td><td>"));
1286 DataLines.append(TitleLine);
1287 DataLines.append(wxT("</td></tr>"));
1295 if (DataDisplay == TRUE){
1298 PageData.append(wxT("<h4>"));
1299 PageData.append(_("Titles"));
1300 PageData.append(wxT("</h4>"));
1301 PageData.append(wxT("<br>"));
1302 PageData.append(wxT("<table>"));
1303 PageData.append(DataLines);
1304 PageData.append(wxT("</table>"));
1310 ContactData = vCardObj->GetByPartial(wxT("ROLE"));
1312 DataDisplay = FALSE;
1315 if (ContactData.PropCount > 0){
1319 for (int i = 0; i < ContactData.PropCount; i++){
1321 RoleLine = ContactData.PropValues[i];
1324 CaptureString(&RoleLine, FALSE);
1325 ConvertToHTML(&RoleLine);
1327 DataLines.append(wxT("<tr><td><b>"));
1328 DataLines.append(_("Role:"));
1329 DataLines.append(wxT(" </b></td><td>"));
1330 DataLines.append(RoleLine);
1331 DataLines.append(wxT("</td></tr>"));
1339 if (DataDisplay == TRUE){
1342 PageData.append(wxT("<h4>"));
1343 PageData.append(_("Roles"));
1344 PageData.append(wxT("</h4>"));
1345 PageData.append(wxT("<br>"));
1346 PageData.append(wxT("<table>"));
1347 PageData.append(DataLines);
1348 PageData.append(wxT("</table>"));
1354 ContactData = vCardObj->GetByPartial(wxT("ORG"));
1356 DataDisplay = FALSE;
1359 if (ContactData.PropCount > 0){
1363 for (int i = 0; i < ContactData.PropCount; i++){
1365 OrgLine = ContactData.PropValues[i];
1368 CaptureString(&OrgLine, FALSE);
1369 ConvertToHTML(&OrgLine);
1371 DataLines.append(wxT("<tr><td><b>"));
1372 DataLines.append(_("Organisation:"));
1373 DataLines.append(wxT(" </b></td><td>"));
1374 DataLines.append(OrgLine);
1375 DataLines.append(wxT("</td></tr>"));
1383 if (DataDisplay == TRUE){
1386 PageData.append(wxT("<h4>"));
1387 PageData.append(_("Organisations"));
1388 PageData.append(wxT("</h4>"));
1389 PageData.append(wxT("<br>"));
1390 PageData.append(wxT("<table>"));
1391 PageData.append(DataLines);
1392 PageData.append(wxT("</table>"));
1398 ContactData = vCardObj->GetByPartial(wxT("CATEGORIES"));
1400 DataDisplay = FALSE;
1403 if (ContactData.PropCount > 0){
1407 for (int i = 0; i < ContactData.PropCount; i++){
1409 CatLine = ContactData.PropValues[i];
1412 CaptureString(&CatLine, FALSE);
1413 ConvertToHTML(&CatLine);
1415 DataLines.append(wxT("<tr><td><b>"));
1416 DataLines.append(_("Category:"));
1417 DataLines.append(wxT(" </b></td><td>"));
1418 DataLines.append(CatLine);
1419 DataLines.append(wxT("</td></tr>"));
1427 if (DataDisplay == TRUE){
1430 PageData.append(wxT("<h4>"));
1431 PageData.append(_("Categories"));
1432 PageData.append(wxT("</h4>"));
1433 PageData.append(wxT("<br>"));
1434 PageData.append(wxT("<table>"));
1435 PageData.append(DataLines);
1436 PageData.append(wxT("</table>"));
1444 // Calendar Addresses
1446 ContactData = vCardObj->GetByPartial(wxT("CALURI"));
1448 DataDisplay = FALSE;
1451 if (ContactData.PropCount > 0){
1453 wxString CalURILine;
1455 for (int i = 0; i < ContactData.PropCount; i++){
1457 CalURILine = ContactData.PropValues[i];
1460 CaptureString(&CalURILine, FALSE);
1461 ConvertToHTML(&CalURILine);
1463 DataLines.append(wxT("<tr><td><b>"));
1464 DataLines.append(_("Calendar Address:"));
1465 DataLines.append(wxT(" </b></td><td>"));
1466 DataLines.append(CalURILine);
1467 DataLines.append(wxT("</td></tr>"));
1475 if (DataDisplay == TRUE){
1478 PageData.append(wxT("<h4>"));
1479 PageData.append(_("Calendar Addresses"));
1480 PageData.append(wxT("</h4>"));
1481 PageData.append(wxT("<br>"));
1482 PageData.append(wxT("<table>"));
1483 PageData.append(DataLines);
1484 PageData.append(wxT("</table>"));
1488 // Calendar Request Addresses
1490 ContactData = vCardObj->GetByPartial(wxT("CALADRURI"));
1492 DataDisplay = FALSE;
1495 if (ContactData.PropCount > 0){
1497 wxString CalAdrURILine;
1499 for (int i = 0; i < ContactData.PropCount; i++){
1501 CalAdrURILine = ContactData.PropValues[i];
1503 CalAdrURILine.Trim();
1504 CaptureString(&CalAdrURILine, FALSE);
1505 ConvertToHTML(&CalAdrURILine);
1507 DataLines.append(wxT("<tr><td><b>"));
1508 DataLines.append(_("Calendar Request Address:"));
1509 DataLines.append(wxT(" </b></td><td>"));
1510 DataLines.append(CalAdrURILine);
1511 DataLines.append(wxT("</td></tr>"));
1519 if (DataDisplay == TRUE){
1522 PageData.append(wxT("<h4>"));
1523 PageData.append(_("Calendar Request Addresses"));
1524 PageData.append(wxT("</h4>"));
1525 PageData.append(wxT("<br>"));
1526 PageData.append(wxT("<table>"));
1527 PageData.append(DataLines);
1528 PageData.append(wxT("</table>"));
1532 // Free/Busy Addresses
1534 ContactData = vCardObj->GetByPartial(wxT("FBURL"));
1536 DataDisplay = FALSE;
1539 if (ContactData.PropCount > 0){
1543 for (int i = 0; i < ContactData.PropCount; i++){
1545 FBURLLine = ContactData.PropValues[i];
1548 CaptureString(&FBURLLine, FALSE);
1549 ConvertToHTML(&FBURLLine);
1551 DataLines.append(wxT("<tr><td><b>"));
1552 DataLines.append(_("Free/Busy Address:"));
1553 DataLines.append(wxT(" </b></td><td>"));
1554 DataLines.append(FBURLLine);
1555 DataLines.append(wxT("</td></tr>"));
1563 if (DataDisplay == TRUE){
1566 PageData.append(wxT("<h4>"));
1567 PageData.append(_("Free/Busy Addresses"));
1568 PageData.append(wxT("</h4>"));
1569 PageData.append(wxT("<br>"));
1570 PageData.append(wxT("<table>"));
1571 PageData.append(DataLines);
1572 PageData.append(wxT("</table>"));
1578 ContactData = vCardObj->GetByPartial(wxT("NOTE"));
1580 DataDisplay = FALSE;
1583 if (ContactData.PropCount > 0){
1587 for (int i = 0; i < ContactData.PropCount; i++){
1589 NoteLine = ContactData.PropValues[i];
1592 CaptureString(&NoteLine, FALSE);
1593 ConvertToHTML(&NoteLine);
1595 DataLines.append(wxT("<tr><td><b>"));
1596 DataLines.append(_("Note:"));
1597 DataLines.append(wxT(" </b></td><td>"));
1598 DataLines.append(NoteLine);
1599 DataLines.append(wxT("</td></tr>"));
1607 if (DataDisplay == TRUE){
1609 PageData.append(wxT("<h4>"));
1610 PageData.append(_("Notes"));
1611 PageData.append(wxT("</h4>"));
1612 PageData.append(wxT("<br>"));
1613 PageData.append(wxT("<table>"));
1614 PageData.append(DataLines);
1615 PageData.append(wxT("</table>"));
1619 // Display the HTML document on the screen.
1621 PageData.append(wxT("</body>"));
1622 PageData.append(wxT("</html>"));
1624 HTMLObj->SetPage(PageData);
1628 void SplitPropertyData(wxString *PropertyLine,
1629 std::map<int,int> *SplitPoints,
1630 std::map<int,int> *SplitLength,
1632 std::map<wxString,wxString> *SplitData){
1635 wxStringTokenizer PropertyElement;
1636 wxString PropertyName;
1637 wxString PropertyValue;
1638 int intPropertyLen = PropertyLine->Len();
1639 int intSplitsFound = 0;
1640 int intSplitSize = 0;
1641 int intSplitSeek = (intSize - 1);
1643 for (int i = intSize; i <= intPropertyLen; i++){
1647 if (PropertyLine->Mid(i, 1) == wxT(";") &&
1648 PropertyLine->Mid((i - 1), 1) != wxT("\\")){
1650 if (intSplitsFound == 0){
1652 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize));
1653 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
1657 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize - 1));
1658 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1662 SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
1665 intSplitSeek = (i + 1);
1668 if (!DataStr.IsEmpty()){
1670 PropertyElement.SetString(DataStr, wxT("="));
1671 PropertyName = PropertyElement.GetNextToken();
1672 PropertyValue = PropertyElement.GetNextToken();
1673 SplitData->insert(std::make_pair(PropertyName, PropertyValue));
1678 PropertyName.clear();
1679 PropertyValue.clear();
1685 if (intSplitsFound == 0){
1687 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize));
1689 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
1690 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1694 DataStr = PropertyLine->Mid(intSplitSeek, (intSplitSize - 1));
1696 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
1697 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1701 if (!DataStr.IsEmpty()){
1703 PropertyElement.SetString(DataStr, wxT("="));
1704 PropertyName = PropertyElement.GetNextToken();
1705 PropertyValue = PropertyElement.GetNextToken();
1706 SplitData->insert(std::make_pair(PropertyName, PropertyValue));