1 // frmContactEditor-Load.cpp - frmContactEditor load contact 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/>
22 #include <wx/tokenzr.h>
23 #include <wx/datetime.h>
26 #include "frmContactEditor.h"
29 #include "../version.h"
30 #include "../vcard/vcard.h"
31 #include "../common/textprocessing.h"
32 #include "../common/dirs.h"
33 #include "cdo/ContactDataObject.h"
35 bool frmContactEditor::LoadContact(wxString Filename){
37 // Load the contact into the contact editor.
40 wxString wxSContactString;
44 if (StartupEditMode == FALSE){
45 XVMData = MainPtr->GetViewMode();
48 wxSContactFilename = Filename;
50 ContactLoadStatus LoadResult = ContactEditorData.LoadFile(Filename);
56 case CONTACTLOAD_FILEMISSING:
57 wxMessageBox(_("The file with the filename given does not exist."),
58 _("Contact not found"), wxICON_ERROR);
62 case CONTACTLOAD_FILEERROR:
63 wxMessageBox(_("The file with the filename given cannot be opened due to an error while trying open it."),
64 _("Error loading contact"), wxICON_ERROR);
68 case CONTACTLOAD_FILEINVALIDFORMAT:
69 wxMessageBox(_("This file is not a vCard 4.0 contact and is not supported under Xestia Address Book."),
70 _("Contact not supported"), wxICON_ERROR);
74 case CONTACTLOAD_FILEBASESPECFAIL:
75 wxMessageBox(_("This file is not a vCard 4.0 contact and is not supported under Xestia Address Book."),
76 _("Contact not supported"), wxICON_ERROR);
86 wxString wxSPropertySeg1;
87 wxString wxSPropertySeg2;
88 wxString wxSPropertyNextLine;
89 int NicknameCount = 0;
103 int CategoryCount = 0;
108 int CalReqAdrCount = 0;
109 int FreeBusyCount = 0;
114 // Process the unique ID (UID)
116 // Do nothing at the moment.
118 // Process the contact type (KIND) (frmContactEditor-LoadGroup.cpp)
120 LoadKind(&ContactEditorData.ContactKind);
122 // Process the Birthday (BDAY) (frmContactEditor-LoadBADays.cpp)
124 LoadBirthday(&ContactEditorData.Birthday, &ContactEditorData.BirthdayText);
126 // Process the Anniversary (ANNIVERSARY) (frmContactEditor-LoadBADays.cpp)
128 LoadAnniversary(&ContactEditorData.Anniversary, &ContactEditorData.AnniversaryText);
130 // Process the Gender (GENDER) (frmContactEditor-LoadGender.cpp)
132 LoadGender(&ContactEditorData.Gender, &ContactEditorData.GenderDetails);
134 // Process the Name (N) (frmContactEditor-LoadName.cpp)
136 LoadName(&ContactEditorData.NameTitle, &ContactEditorData.NameForename,
137 &ContactEditorData.NameSurname, &ContactEditorData.NameOtherNames,
138 &ContactEditorData.NameSuffix);
140 // Process the group members (MEMBER) (frmContactEditor-LoadGroup.cpp)
142 LoadMember(&ContactEditorData.GroupsList);
144 // Process the addresses (ADR) (frmContactEditor-LoadAddress.cpp)
146 LoadAddress(&ContactEditorData.GeneralAddressList,
147 &ContactEditorData.GeneralAddressListTown,
148 &ContactEditorData.GeneralAddressListCounty,
149 &ContactEditorData.GeneralAddressListPostCode,
150 &ContactEditorData.GeneralAddressListPref,
151 &ContactEditorData.HomeAddressList,
152 &ContactEditorData.HomeAddressListTown,
153 &ContactEditorData.HomeAddressListCounty,
154 &ContactEditorData.HomeAddressListPostCode,
155 &ContactEditorData.HomeAddressListPref,
156 &ContactEditorData.BusinessAddressList,
157 &ContactEditorData.BusinessAddressListTown,
158 &ContactEditorData.BusinessAddressListCounty,
159 &ContactEditorData.BusinessAddressListPostCode,
160 &ContactEditorData.BusinessAddressListPref,
163 // Process the timezones (TZ).
165 LoadData(&ContactEditorData.GeneralTZList,
166 &ContactEditorData.GeneralTZListPref,
168 &ContactEditorData.HomeTZList,
169 &ContactEditorData.HomeTZListPref,
171 &ContactEditorData.BusinessTZList,
172 &ContactEditorData.BusinessTZListPref,
173 lboBusinessTimezones,
176 // Process the emails (EMAIL).
178 LoadData(&ContactEditorData.GeneralEmailList,
179 &ContactEditorData.GeneralEmailListPref,
181 &ContactEditorData.HomeEmailList,
182 &ContactEditorData.HomeEmailListPref,
184 &ContactEditorData.BusinessEmailList,
185 &ContactEditorData.BusinessEmailListPref,
189 // Process the nicknames (NICKNAME).
191 LoadData(&ContactEditorData.GeneralNicknamesList,
192 &ContactEditorData.GeneralNicknamesListPref,
194 &ContactEditorData.HomeNicknamesList,
195 &ContactEditorData.HomeNicknamesListPref,
197 &ContactEditorData.BusinessNicknamesList,
198 &ContactEditorData.BusinessNicknamesListPref,
199 lboBusinessNicknames,
202 // Process the languages (LANG).
204 LoadData(&ContactEditorData.GeneralLanguageList,
205 &ContactEditorData.GeneralLanguageListPref,
207 &ContactEditorData.HomeLanguageList,
208 &ContactEditorData.HomeLanguageListPref,
210 &ContactEditorData.BusinessLanguageList,
211 &ContactEditorData.BusinessLanguageListPref,
212 lboBusinessLanguages,
215 // Process the geopositiosn (GEO).
217 LoadData(&ContactEditorData.GeneralGeographyList,
218 &ContactEditorData.GeneralGeographyListPref,
220 &ContactEditorData.HomeGeographyList,
221 &ContactEditorData.HomeGeographyListPref,
223 &ContactEditorData.BusinessGeographyList,
224 &ContactEditorData.BusinessGeographyListPref,
225 lboBusinessGeoposition,
228 // Process the websites (URL).
230 LoadData(&ContactEditorData.GeneralWebsiteList,
231 &ContactEditorData.GeneralWebsiteListPref,
233 &ContactEditorData.HomeWebsiteList,
234 &ContactEditorData.HomeWebsiteListPref,
236 &ContactEditorData.BusinessWebsiteList,
237 &ContactEditorData.BusinessWebsiteListPref,
241 // Process the titles (TITLE).
243 LoadData(&ContactEditorData.GeneralTitleList,
244 &ContactEditorData.GeneralTitleListPref,
246 &ContactEditorData.HomeTitleList,
247 &ContactEditorData.HomeTitleListPref,
249 &ContactEditorData.BusinessTitleList,
250 &ContactEditorData.BusinessTitleListPref,
254 // Process the roles (ROLE).
256 LoadData(&ContactEditorData.GeneralRoleList,
257 &ContactEditorData.GeneralRoleListPref,
259 &ContactEditorData.HomeRoleList,
260 &ContactEditorData.HomeRoleListPref,
262 &ContactEditorData.BusinessRoleList,
263 &ContactEditorData.BusinessRoleListPref,
267 // Process the roles (ORG).
269 LoadData(&ContactEditorData.GeneralOrganisationsList,
270 &ContactEditorData.GeneralOrganisationsListPref,
272 &ContactEditorData.HomeOrganisationsList,
273 &ContactEditorData.HomeOrganisationsListPref,
274 lboHomeOrganisations,
275 &ContactEditorData.BusinessOrganisationsList,
276 &ContactEditorData.BusinessOrganisationsListPref,
277 lboBusinessOrganisations,
280 // Process the notes (NOTE).
282 LoadData(&ContactEditorData.GeneralNoteList,
283 &ContactEditorData.GeneralNoteListPref,
285 &ContactEditorData.HomeNoteList,
286 &ContactEditorData.HomeNoteListPref,
288 &ContactEditorData.BusinessNoteList,
289 &ContactEditorData.BusinessNoteListPref,
293 // Process the categories (CATEGORIES).
295 LoadData(&ContactEditorData.CategoriesList,
296 &ContactEditorData.CategoriesListPref,
300 // Process the telephone numbers (TEL).
302 LoadData(&ContactEditorData.GeneralTelephoneList,
303 &ContactEditorData.GeneralTelephoneListPref,
304 &ContactEditorData.GeneralTelephoneListTypeInfo,
306 &ContactEditorData.HomeTelephoneList,
307 &ContactEditorData.HomeTelephoneListPref,
308 &ContactEditorData.HomeTelephoneListTypeInfo,
310 &ContactEditorData.BusinessTelephoneList,
311 &ContactEditorData.BusinessTelephoneListPref,
312 &ContactEditorData.BusinessTelephoneListTypeInfo,
313 lboBusinessTelephone,
316 // Process the instant messaging (IMPP).
318 LoadData(&ContactEditorData.GeneralIMListTypeInfo,
319 &ContactEditorData.GeneralIMListPref,
320 &ContactEditorData.GeneralIMList,
322 &ContactEditorData.HomeIMListTypeInfo,
323 &ContactEditorData.HomeIMListPref,
324 &ContactEditorData.HomeIMList,
326 &ContactEditorData.BusinessIMListTypeInfo,
327 &ContactEditorData.BusinessIMListPref,
328 &ContactEditorData.BusinessIMList,
332 // Process the photos (PHOTO).
334 LoadPictureData("PHOTO",
335 &ContactEditorData.PicturesList,
336 &ContactEditorData.PicturesListPref,
337 &ContactEditorData.PicturesListType,
341 // Process the logos (LOGO).
343 LoadPictureData("LOGO",
344 &ContactEditorData.LogosList,
345 &ContactEditorData.LogosListPref,
346 &ContactEditorData.LogosListType,
350 // Process the sounds (SOUND).
352 LoadPictureData("SOUND",
353 &ContactEditorData.SoundsList,
354 &ContactEditorData.SoundsListPref,
355 &ContactEditorData.SoundsListType,
359 // Process the calendar addresses (CALURI).
362 &ContactEditorData.CalendarList,
363 &ContactEditorData.CalendarListPref,
364 &ContactEditorData.CalendarListType,
366 lboCalendarAddresses,
369 // Process the calendar request addresses (CALADRURI).
371 LoadData("CALADRURI",
372 &ContactEditorData.CalendarRequestList,
373 &ContactEditorData.CalendarRequestListPref,
374 &ContactEditorData.CalendarRequestListType,
376 lboCalendarRequestAddress,
379 // Process the free busy addresses (FBURL).
382 &ContactEditorData.FreeBusyList,
383 &ContactEditorData.FreeBusyListPref,
384 &ContactEditorData.FreeBusyListType,
386 lboFreeBusyAddresses,
389 // Process the keys. (KEY)
392 &ContactEditorData.KeyList,
393 &ContactEditorData.KeyListPref,
394 &ContactEditorData.KeyListType,
395 &ContactEditorData.KeyListDataType,
399 // Process the vendor specific information (VND-*).
401 LoadVendorData(&ContactEditorData.VendorListPEN,
402 &ContactEditorData.VendorListElement,
406 // Process the X-Tokens (X-*).
408 LoadXTokenData(&ContactEditorData.XTokenListTokens,
412 // Process the related people (RELATED).
414 LoadRelatedData(&ContactEditorData.GeneralRelatedList,
415 &ContactEditorData.GeneralRelatedListPref,
416 &ContactEditorData.GeneralRelatedListType,
420 // Process the full name (FN).
422 LoadData(&ContactEditorData.FullNamesList,
425 FMTimer.SetFilename(Filename);
426 FMTimer.Start(10000, FALSE);
433 void frmContactEditor::SplitValues(wxString *PropertyLine,
434 std::map<int,int> *SplitPoints,
435 std::map<int,int> *SplitLength,
440 size_t intPropertyLen = PropertyLine->Len();
441 int intSplitsFound = 0;
442 int intSplitSize = 0;
443 int intSplitSeek = 0;
445 for (int i = intSize; i <= intPropertyLen; i++){
449 if (PropertyLine->Mid(i, 1) == wxT(";") &&
450 PropertyLine->Mid((i - 1), 1) != wxT("\\")){
452 if (intSplitsFound == 0){
454 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
458 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
462 SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
472 if (intSplitsFound == 0){
474 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
475 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
479 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
480 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
486 void frmContactEditor::LoadData(std::map<int, wxString> *GeneralList,
487 std::map<int, int> *GeneralListPref,
488 wxListCtrl *GeneralListCtrl,
489 std::map<int, wxString> *HomeList,
490 std::map<int, int> *HomeListPref,
491 wxListCtrl *HomeListCtrl,
492 std::map<int, wxString> *BusinessList,
493 std::map<int, int> *BusinessListPref,
494 wxListCtrl *BusinessListCtrl,
497 // Load data into the controls (first section of data and preference
500 long ListCtrlIndex = -1;
502 // Deal with the general items.
504 for (std::map<int,wxString>::iterator Iter = GeneralList->begin();
505 Iter != GeneralList->end();
510 coldata.SetId(*DataCount);
511 coldata.SetData(*DataCount);
512 coldata.SetText(Iter->second);
514 ListCtrlIndex = GeneralListCtrl->InsertItem(coldata);
516 if (MapDataExists(DataCount, GeneralListPref)){
518 GeneralListCtrl->SetItem(ListCtrlIndex, 1, wxString::Format("%i", GeneralListPref->find(*DataCount)->second));
526 // Deal with the home items.
528 for (std::map<int,wxString>::iterator Iter = HomeList->begin();
529 Iter != HomeList->end();
534 coldata.SetId(*DataCount);
535 coldata.SetData(*DataCount);
536 coldata.SetText(Iter->second);
538 ListCtrlIndex = HomeListCtrl->InsertItem(coldata);
540 if (MapDataExists(DataCount, HomeListPref)){
542 HomeListCtrl->SetItem(ListCtrlIndex, 1, wxString::Format("%i", HomeListPref->find(*DataCount)->second));
550 // Deal with the work items.
552 for (std::map<int,wxString>::iterator Iter = BusinessList->begin();
553 Iter != BusinessList->end();
558 coldata.SetId(*DataCount);
559 coldata.SetData(*DataCount);
560 coldata.SetText(Iter->second);
562 ListCtrlIndex = BusinessListCtrl->InsertItem(coldata);
564 if (MapDataExists(DataCount, BusinessListPref)){
566 BusinessListCtrl->SetItem(ListCtrlIndex, 1, wxString::Format("%i", BusinessListPref->find(*DataCount)->second));
576 void frmContactEditor::LoadData(std::map<int, wxString> *GeneralList,
577 std::map<int, int> *GeneralListPref,
578 std::map<int, wxString> *GeneralListType,
579 wxListCtrl *GeneralListCtrl,
580 std::map<int, wxString> *HomeList,
581 std::map<int, int> *HomeListPref,
582 std::map<int, wxString> *HomeListType,
583 wxListCtrl *HomeListCtrl,
584 std::map<int, wxString> *BusinessList,
585 std::map<int, int> *BusinessListPref,
586 std::map<int, wxString> *BusinessListType,
587 wxListCtrl *BusinessListCtrl,
590 // Load data into the controls (first section of data,
591 // type and preference).
593 long ListCtrlIndex = -1;
595 // Deal with the general items.
597 for (std::map<int,wxString>::iterator Iter = GeneralList->begin();
598 Iter != GeneralList->end();
603 coldata.SetId(*DataCount);
604 coldata.SetData(*DataCount);
605 coldata.SetText(Iter->second);
607 ListCtrlIndex = GeneralListCtrl->InsertItem(coldata);
609 if (MapDataExists(DataCount, GeneralListPref)){
611 GeneralListCtrl->SetItem(ListCtrlIndex, 2, wxString::Format("%i", GeneralListPref->find(*DataCount)->second));
615 if (MapDataExists(DataCount, GeneralListType)){
617 GeneralListCtrl->SetItem(ListCtrlIndex, 1, GeneralListType->find(*DataCount)->second);
625 // Deal with the home items.
627 for (std::map<int,wxString>::iterator Iter = HomeList->begin();
628 Iter != HomeList->end();
633 coldata.SetId(*DataCount);
634 coldata.SetData(*DataCount);
635 coldata.SetText(Iter->second);
637 ListCtrlIndex = HomeListCtrl->InsertItem(coldata);
639 if (MapDataExists(DataCount, HomeListPref)){
641 HomeListCtrl->SetItem(ListCtrlIndex, 2, wxString::Format("%i", HomeListPref->find(*DataCount)->second));
645 if (MapDataExists(DataCount, HomeListType)){
647 HomeListCtrl->SetItem(ListCtrlIndex, 1, HomeListType->find(*DataCount)->second);
655 // Deal with the work items.
657 for (std::map<int,wxString>::iterator Iter = BusinessList->begin();
658 Iter != BusinessList->end();
663 coldata.SetId(*DataCount);
664 coldata.SetData(*DataCount);
665 coldata.SetText(Iter->second);
667 ListCtrlIndex = BusinessListCtrl->InsertItem(coldata);
669 if (MapDataExists(DataCount, BusinessListPref)){
671 BusinessListCtrl->SetItem(ListCtrlIndex, 2, wxString::Format("%i", BusinessListPref->find(*DataCount)->second));
675 if (MapDataExists(DataCount, BusinessListType)){
677 BusinessListCtrl->SetItem(ListCtrlIndex, 1, BusinessListType->find(*DataCount)->second);
688 void frmContactEditor::LoadData(std::map<int,wxString> *ItemList,
689 std::map<int,int> *ItemListPref,
690 wxListCtrl *ItemCtrl,
693 // Load the data (name and preference only).
695 long ListCtrlIndex = -1;
697 for (std::map<int,wxString>::iterator Iter = ItemList->begin();
698 Iter != ItemList->end();
703 coldata.SetId(*DataCount);
704 coldata.SetData(*DataCount);
705 coldata.SetText(Iter->second);
707 ListCtrlIndex = ItemCtrl->InsertItem(coldata);
709 if (MapDataExists(DataCount, ItemListPref)){
711 ItemCtrl->SetItem(ListCtrlIndex, 1, wxString::Format("%i", ItemListPref->find(*DataCount)->second));
721 void frmContactEditor::LoadData(std::map<int,wxString> *ItemList,
722 std::map<int,int> *ItemListPref,
723 std::map<int,wxString> *ItemListType,
724 wxListCtrl *ItemCtrl,
727 // Load the data (name, preference and type).
729 long ListCtrlIndex = -1;
731 for (std::map<int,wxString>::iterator Iter = ItemList->begin();
732 Iter != ItemList->end();
737 coldata.SetId(*DataCount);
738 coldata.SetData(*DataCount);
739 coldata.SetText(Iter->second);
741 ListCtrlIndex = ItemCtrl->InsertItem(coldata);
743 if (MapDataExists(DataCount, ItemListType)){
745 ItemCtrl->SetItem(ListCtrlIndex, 1, ItemListType->find(*DataCount)->second);
749 if (MapDataExists(DataCount, ItemListPref)){
751 ItemCtrl->SetItem(ListCtrlIndex, 2, wxString::Format("%i", ItemListPref->find(*DataCount)->second));
761 void frmContactEditor::LoadData(wxString ItemName,
762 std::map<int,wxString> *ItemList,
763 std::map<int,int> *ItemListPref,
764 std::map<int,wxString> *ItemListType,
765 std::map<int,wxString> *ItemListDataType,
766 wxListCtrl *ItemCtrl,
769 // Load data (name, preference, type and data type).
771 long ListCtrlIndex = -1;
773 for (std::map<int,wxString>::iterator Iter = ItemList->begin();
774 Iter != ItemList->end();
779 coldata.SetId(*DataCount);
780 coldata.SetData(*DataCount);
781 coldata.SetText(Iter->second);
783 if (ItemName == "KEY"){
785 // Get the key type, if any.
787 if (MapDataExists(DataCount, ItemListDataType)){
789 if (ItemListDataType->find(*DataCount)->second == "application/pgp-keys"){
791 coldata.SetText(_("PGP Key"));
797 coldata.SetText(_("Key"));
804 ListCtrlIndex = ItemCtrl->InsertItem(coldata);
806 if (MapDataExists(DataCount, ItemListType)){
808 if (ItemListType->find(*DataCount)->second == "home"){
810 ItemCtrl->SetItem(ListCtrlIndex, 1, _("Home"));
812 } else if (ItemListType->find(*DataCount)->second == "work"){
814 ItemCtrl->SetItem(ListCtrlIndex, 1, _("Work"));
820 if (MapDataExists(DataCount, ItemListPref)){
822 ItemCtrl->SetItem(ListCtrlIndex, 2, wxString::Format("%i", ItemListPref->find(*DataCount)->second));
832 void frmContactEditor::LoadPictureData(wxString ItemName,
833 std::map<int,std::string> *ItemList,
834 std::map<int,int> *ItemListPref,
835 std::map<int,wxString> *ItemListType,
836 wxListCtrl *ItemCtrl,
839 // Load the picture data.
841 long ListCtrlIndex = -1;
843 for (std::map<int,std::string>::iterator Iter = ItemList->begin();
844 Iter != ItemList->end();
849 coldata.SetId(*DataCount);
850 coldata.SetData(*DataCount);
852 if (ItemName == "PHOTO"){
854 coldata.SetText("Picture");
856 } else if (ItemName == "LOGO"){
858 coldata.SetText("Logo");
860 } else if (ItemName == "SOUND"){
862 coldata.SetText("Sound");
866 coldata.SetText("Object");
870 ListCtrlIndex = ItemCtrl->InsertItem(coldata);
872 if (MapDataExists(DataCount, ItemListType)){
874 if (ItemListType->find(*DataCount)->second == "home"){
876 ItemCtrl->SetItem(ListCtrlIndex, 1, _("Home"));
878 } else if (ItemListType->find(*DataCount)->second == "work"){
880 ItemCtrl->SetItem(ListCtrlIndex, 1, _("Work"));
886 if (MapDataExists(DataCount, ItemListPref)){
888 ItemCtrl->SetItem(ListCtrlIndex, 2, wxString::Format("%i", ItemListPref->find(*DataCount)->second));
898 void frmContactEditor::LoadVendorData(std::map<int,wxString> *ItemListPEN,
899 std::map<int,wxString> *ItemListElement,
900 wxListCtrl *ItemCtrl,
903 // Load the vendor data.
905 long ListCtrlIndex = -1;
908 for (std::map<int,wxString>::iterator Iter = ItemListPEN->begin();
909 Iter != ItemListPEN->end();
916 coldata.SetId(*DataCount);
917 coldata.SetData(*DataCount);
919 ItemValue.Append(ItemListPEN->find(*DataCount)->second);
920 ItemValue.Append("-");
921 ItemValue.Append(ItemListElement->find(*DataCount)->second);
923 coldata.SetText(ItemValue);
925 ListCtrlIndex = ItemCtrl->InsertItem(coldata);
933 void frmContactEditor::LoadXTokenData(std::map<int,wxString> *ItemListTokens,
934 wxListCtrl *ItemCtrl,
937 // Load the X-Token data.
939 long ListCtrlIndex = -1;
942 for (std::map<int,wxString>::iterator Iter = ItemListTokens->begin();
943 Iter != ItemListTokens->end();
950 coldata.SetId(*DataCount);
951 coldata.SetData(*DataCount);
953 ItemValue.Append(ItemListTokens->find(*DataCount)->second);
955 coldata.SetText(ItemValue);
957 ListCtrlIndex = ItemCtrl->InsertItem(coldata);
965 void frmContactEditor::LoadData(std::map<int,wxString> *ItemList,
966 wxComboBox *ItemCtrl){
968 // Load data into a wxComboBox.
972 if (MapDataExists(&ItemIndex, ItemList)){
974 cmbDisplayAs->SetValue(ItemList->find(0)->second);
980 void frmContactEditor::LoadRelatedData(std::map<int,wxString> *ItemList,
981 std::map<int,int> *ItemListPref,
982 std::map<int,wxString> *ItemListType,
983 wxListCtrl *ItemCtrl,
986 // Load related data (name, preference and type).
988 long ListCtrlIndex = -1;
989 wxString RelatedType;
991 for (std::map<int,wxString>::iterator Iter = ItemList->begin();
992 Iter != ItemList->end();
999 coldata.SetId(*DataCount);
1000 coldata.SetData(*DataCount);
1002 if (MapDataExists(DataCount, ItemListType)){
1004 std::map<int,wxString>::iterator TypeIter = ItemListType->find(*DataCount);
1006 if (TypeIter->second == wxT("contact")){
1008 RelatedType = _("Contact");
1010 } else if (TypeIter->second == wxT("acquaintance")){
1012 RelatedType = _("Acquaintance");
1014 } else if (TypeIter->second == wxT("friend")){
1016 RelatedType = _("Friend");
1018 } else if (TypeIter->second == wxT("met")){
1020 RelatedType = _("Met");
1022 } else if (TypeIter->second == wxT("co-worker")){
1024 RelatedType = _("Co-worker");
1026 } else if (TypeIter->second == wxT("colleague")){
1028 RelatedType = _("Colleague");
1030 } else if (TypeIter->second == wxT("co-resident")){
1032 RelatedType = _("Co-resident");
1034 } else if (TypeIter->second == wxT("neighbor")){
1036 RelatedType = _("Neighbour");
1038 } else if (TypeIter->second == wxT("child")){
1040 RelatedType = _("Child");
1042 } else if (TypeIter->second == wxT("parent")){
1044 RelatedType = _("Parent");
1046 } else if (TypeIter->second == wxT("sibling")){
1048 RelatedType = _("Sibling");
1050 } else if (TypeIter->second == wxT("spouse")){
1052 RelatedType = _("Spouse");
1054 } else if (TypeIter->second == wxT("kin")){
1056 RelatedType = _("Kin");
1058 } else if (TypeIter->second == wxT("muse")){
1060 RelatedType = _("Muse");
1062 } else if (TypeIter->second == wxT("crush")){
1064 RelatedType = _("Crush");
1066 } else if (TypeIter->second == wxT("date")){
1068 RelatedType = _("Date");
1070 } else if (TypeIter->second == wxT("sweetheart")){
1072 RelatedType = _("Sweetheart");
1074 } else if (TypeIter->second == wxT("me")){
1076 RelatedType = _("Me");
1078 } else if (TypeIter->second == wxT("agent")){
1080 RelatedType = _("Agent");
1082 } else if (TypeIter->second == wxT("emergency")){
1084 RelatedType = _("Emergency");
1088 RelatedType = TypeIter->second;
1094 coldata.SetText(RelatedType);
1096 ListCtrlIndex = ItemCtrl->InsertItem(coldata);
1098 if (MapDataExists(DataCount, ItemList)){
1100 ItemCtrl->SetItem(ListCtrlIndex, 1, ItemList->find(*DataCount)->second);
1104 if (MapDataExists(DataCount, ItemListPref)){
1106 ItemCtrl->SetItem(ListCtrlIndex, 2, wxString::Format("%i", ItemListPref->find(*DataCount)->second));
1116 void frmContactEditor::LoadKind(ContactKindType *KindType){
1118 // Load contact kind.
1121 case CONTACTKIND_INDIVIDUAL:
1122 cmbType->SetSelection(1);
1124 case CONTACTKIND_GROUP:
1125 cmbType->SetSelection(2);
1127 case CONTACTKIND_ORGANISATION:
1128 cmbType->SetSelection(3);
1130 case CONTACTKIND_LOCATION:
1131 cmbType->SetSelection(4);
1133 case CONTACTKIND_NONE:
1134 cmbType->SetSelection(0);
1138 wxCommandEvent nullevent;
1140 UpdateMembersTab(nullevent);
1144 void frmContactEditor::LoadBirthday(wxString *BirthdayData, bool *BirthdayText){
1148 if (BirthdayData->IsEmpty()){
1152 if (*BirthdayText == FALSE){
1155 wxDateTime::Month DateMonth;
1156 unsigned int DateDay;
1160 if (BirthdayData->Mid(0, 2) == wxT("--")){
1166 DateYear = wxAtoi(BirthdayData->Mid(0,4));
1170 DateMonth = (wxDateTime::Month)(wxAtoi(BirthdayData->Mid(4,2)) - 1);
1171 DateDay = wxAtoi(BirthdayData->Mid(6,2));
1173 wxDateTime BDayDate(DateDay,DateMonth,DateYear);
1175 dapBirthday->SetValue(BDayDate);
1179 txtBirthday->SetValue(*BirthdayData);
1185 void frmContactEditor::LoadAnniversary(wxString *AnniversaryData, bool *AnniversaryText){
1187 // Load Anniversary.
1189 if (AnniversaryData->IsEmpty()){
1193 if (*AnniversaryText == FALSE){
1196 wxDateTime::Month DateMonth;
1201 if (AnniversaryData->Mid(0, 2) == wxT("--")){
1207 DateYear = wxAtoi(AnniversaryData->Mid(0,4));
1211 DateMonth = (wxDateTime::Month)(wxAtoi(AnniversaryData->Mid(4,2)) - 1);
1212 DateDay = wxAtoi(AnniversaryData->Mid(6,2));
1214 wxDateTime ADayDate(DateDay,DateMonth,DateYear);
1216 dapAnniversary->SetValue(ADayDate);
1220 txtAnniversary->SetValue(*AnniversaryData);
1226 void frmContactEditor::LoadGender(wxString *GenderComponent, wxString *GenderIdentity){
1230 // Deal with the Gender Component.
1232 if (*GenderComponent == wxT("M")){
1236 cmbGender->SetSelection(1);
1238 } else if (*GenderComponent == wxT("F")){
1240 // Gender is Female.
1242 cmbGender->SetSelection(2);
1244 } else if (*GenderComponent == wxT("O")){
1248 cmbGender->SetSelection(3);
1250 } else if (*GenderComponent == wxT("N")){
1252 // Gender is None/Not Applicable.
1254 cmbGender->SetSelection(4);
1256 } else if (*GenderComponent == wxT("U")){
1258 // Gender is Unknown.
1260 cmbGender->SetSelection(5);
1264 // Deal with the Gender Identity.
1266 txtGenderDescription->SetValue(*GenderIdentity);
1270 void frmContactEditor::LoadName(wxString *NameTitle, wxString *NameForename,
1271 wxString *NameSurname, wxString *NameOtherNames,
1272 wxString *NameSuffix){
1276 txtTitle->SetValue(*NameTitle);
1277 txtForename->SetValue(*NameForename);
1278 txtSurname->SetValue(*NameSurname);
1279 txtOtherNames->SetValue(*NameOtherNames);
1280 txtSuffix->SetValue(*NameSuffix);
1284 void frmContactEditor::LoadMember(std::map<int,wxString> *GroupList){
1288 // Go through the list of contacts for the account and find the matching UID.
1289 // If contact with UID doesn't match then say (unknown contact).
1291 XABViewMode XVMData;
1292 if (StartupEditMode == FALSE){
1293 XVMData = MainPtr->GetViewMode();
1296 wxString AccountDirFinal = GetAccountDir(wxSContactAccount, FALSE);
1298 wxString vCardFilename;
1299 wxString vCardFilenameFull;
1300 wxString vCardDataString;
1302 wxString setname, setvalue;
1303 wxString MemberData;
1304 bool FoundContact = FALSE;
1305 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
1306 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
1308 wxDir vcardaccdir(AccountDirFinal);
1310 for (std::map<int,wxString>::iterator MemberIter = GroupList->begin();
1311 MemberIter != GroupList->end();
1314 MemberData = MemberIter->second;
1316 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1319 if (vCardFilename.Right(4) == wxT(".vcf") ||
1320 vCardFilename.Right(4) == wxT(".VCF") ||
1321 vCardFilename.Right(5) == wxT(".vcard") ||
1322 vCardFilename.Right(5) == wxT(".VCARD")){
1326 vCardFilenameFull.Append(AccountDirFinal);
1327 vCardFilenameFull.Append(wxT("/"));
1328 vCardFilenameFull.Append(vCardFilename);
1330 Person.LoadFile(vCardFilenameFull);
1332 if (MemberData.Left(9) == wxT("urn:uuid:")){
1334 wxString NewPropValue;
1335 NewPropValue = MemberData.Mid(9, wxString::npos);
1336 MemberData = NewPropValue;
1340 if (Person.MeetBaseSpecification()){
1342 wxString KindStatus = Person.Get(wxT("KIND"));
1344 if (KindStatus == wxT("group")){
1346 vCardFilename.Clear();
1347 vCardFilenameFull.Clear();
1348 vCardDataString.Clear();
1349 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1354 wxString PersonName = Person.Get(wxT("N"));
1355 wxString PersonUID = Person.Get(wxT("UID"));
1356 wxString PersonFilename = vCardFilenameFull;
1358 if (PersonUID != MemberData){
1360 vCardFilename.Clear();
1361 vCardFilenameFull.Clear();
1362 vCardDataString.Clear();
1363 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1368 FoundContact = TRUE;
1372 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));
1373 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));
1375 if (XVMData.SortMode == 1){
1377 // Split the name into sections.
1379 vCardDataString = Person.Get(wxT("N"));
1381 vCardName NameData = Person.GetName();
1383 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
1385 } else if (XVMData.SortMode == 2){
1387 // Split the name into sections.
1389 vCardName NameData = Person.GetName();
1391 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
1393 } else if (XVMData.SortMode == 3){
1395 // Check and make sure that the top most nickname is used.
1397 vCardDataString = Person.Get(wxT("NICKNAME"));
1399 if (vCardDataString.IsEmpty()){
1401 vCardDataString = wxT("(no nickname)");
1405 } else if (XVMData.SortMode == 4){
1407 vCardDataString = Person.Get(wxT("FN"));
1411 if (XVMData.AscendingMode == TRUE){
1413 vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonUID));
1417 vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonUID));
1427 vCardFilename.Clear();
1428 vCardFilenameFull.Clear();
1429 vCardDataString.Clear();
1430 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1434 if (FoundContact == FALSE){
1436 if (XVMData.AscendingMode == TRUE){
1438 vCardNamesAsc.insert(std::make_pair(MemberIter->second, MemberIter->second));
1442 vCardNamesDsc.insert(std::make_pair(MemberIter->second, MemberIter->second));
1448 if (XVMData.AscendingMode == TRUE){
1450 for (std::map<wxString,wxString>::iterator iter = vCardNamesAsc.begin();
1451 iter != vCardNamesAsc.end(); ++iter){
1453 wxListItem ItemData;
1456 ItemData.SetText(iter->first);
1457 lboGroups->InsertItem(ItemData);
1463 for (std::map<wxString,wxString>::iterator iter = vCardNamesDsc.begin();
1464 iter != vCardNamesDsc.end(); ++iter){
1466 wxListItem ItemData;
1469 ItemData.SetText(iter->first);
1471 lboGroups->InsertItem(ItemData);
1481 void frmContactEditor::LoadAddress(std::map<int, wxString> *GeneralAddressList,
1482 std::map<int, wxString> *GeneralAddressListTown,
1483 std::map<int, wxString> *GeneralAddressListCounty,
1484 std::map<int, wxString> *GeneralAddressListPostCode,
1485 std::map<int, int> *GeneralAddressListPref,
1486 std::map<int, wxString> *HomeAddressList,
1487 std::map<int, wxString> *HomeAddressListTown,
1488 std::map<int, wxString> *HomeAddressListCounty,
1489 std::map<int, wxString> *HomeAddressListPostCode,
1490 std::map<int, int> *HomeAddressListPref,
1491 std::map<int, wxString> *BusinessAddressList,
1492 std::map<int, wxString> *BusinessAddressListTown,
1493 std::map<int, wxString> *BusinessAddressListCounty,
1494 std::map<int, wxString> *BusinessAddressListPostCode,
1495 std::map<int, int> *BusinessAddressListPref,
1500 long ListCtrlIndex = -1;
1502 // Deal with the general addresses.
1504 for (std::map<int,wxString>::iterator Iter = GeneralAddressList->begin();
1505 Iter != GeneralAddressList->end();
1510 coldata.SetId(*AddressCount);
1511 coldata.SetData(*AddressCount);
1512 coldata.SetText(Iter->second);
1514 ListCtrlIndex = lboAddresses->InsertItem(coldata);
1516 if (MapDataExists(AddressCount, GeneralAddressListTown)){
1518 lboAddresses->SetItem(ListCtrlIndex, 1, GeneralAddressListTown->find(*AddressCount)->second);
1522 if (MapDataExists(AddressCount, GeneralAddressListCounty)){
1524 lboAddresses->SetItem(ListCtrlIndex, 2, GeneralAddressListCounty->find(*AddressCount)->second);
1528 if (MapDataExists(AddressCount, GeneralAddressListPostCode)){
1530 lboAddresses->SetItem(ListCtrlIndex, 3, GeneralAddressListPostCode->find(*AddressCount)->second);
1534 if (MapDataExists(AddressCount, GeneralAddressListPref)){
1536 lboAddresses->SetItem(ListCtrlIndex, 4, wxString::Format("%i", GeneralAddressListPref->find(*AddressCount)->second));
1544 // Deal with the home addresses.
1546 for (std::map<int,wxString>::iterator Iter = HomeAddressList->begin();
1547 Iter != HomeAddressList->end();
1552 coldata.SetId(*AddressCount);
1553 coldata.SetData(*AddressCount);
1554 coldata.SetText(Iter->second);
1556 ListCtrlIndex = lboHomeAddresses->InsertItem(coldata);
1558 if (MapDataExists(AddressCount, HomeAddressListTown)){
1560 lboHomeAddresses->SetItem(ListCtrlIndex, 1, HomeAddressListTown->find(*AddressCount)->second);
1564 if (MapDataExists(AddressCount, HomeAddressListCounty)){
1566 lboHomeAddresses->SetItem(ListCtrlIndex, 2, HomeAddressListCounty->find(*AddressCount)->second);
1570 if (MapDataExists(AddressCount, HomeAddressListPostCode)){
1572 lboHomeAddresses->SetItem(ListCtrlIndex, 3, HomeAddressListPostCode->find(*AddressCount)->second);
1576 if (MapDataExists(AddressCount, HomeAddressListPref)){
1578 lboHomeAddresses->SetItem(ListCtrlIndex, 4, wxString::Format("%i", HomeAddressListPref->find(*AddressCount)->second));
1586 // Deal with the work addresses.
1588 for (std::map<int,wxString>::iterator Iter = BusinessAddressList->begin();
1589 Iter != BusinessAddressList->end();
1594 coldata.SetId(*AddressCount);
1595 coldata.SetData(*AddressCount);
1596 coldata.SetText(Iter->second);
1598 ListCtrlIndex = lboBusinessAddresses->InsertItem(coldata);
1600 if (MapDataExists(AddressCount, BusinessAddressListTown)){
1602 lboBusinessAddresses->SetItem(ListCtrlIndex, 1, BusinessAddressListTown->find(*AddressCount)->second);
1606 if (MapDataExists(AddressCount, BusinessAddressListCounty)){
1608 lboBusinessAddresses->SetItem(ListCtrlIndex, 2, BusinessAddressListCounty->find(*AddressCount)->second);
1612 if (MapDataExists(AddressCount, BusinessAddressListPostCode)){
1614 lboBusinessAddresses->SetItem(ListCtrlIndex, 3, BusinessAddressListPostCode->find(*AddressCount)->second);
1618 if (MapDataExists(AddressCount, BusinessAddressListPref)){
1620 lboBusinessAddresses->SetItem(ListCtrlIndex, 4, wxString::Format("%i", BusinessAddressListPref->find(*AddressCount)->second));