+// frmContactEditor-Load.cpp - frmContactEditor load contact subroutines.
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
#include <map>
#include <wx/ffile.h>
#include "../vcard/vcard.h"
#include "../common/textprocessing.h"
#include "../common/dirs.h"
+#include "cdo/ContactDataObject.h"
bool frmContactEditor::LoadContact(wxString Filename){
wxString wxSContactString;
wxString ContactLine;
vCard ContactData;
- XABViewMode XVMData = MainPtr->GetViewMode();
+ XABViewMode XVMData;
+ if (StartupEditMode == FALSE){
+ XVMData = MainPtr->GetViewMode();
+ }
wxSContactFilename = Filename;
}
+ ContactEditorData.LoadFile(Filename);
+
ContactFile.ReadAll(&wxSContactString, wxConvAuto());
// Split the lines.
bool HasExtraNicknames = FALSE;
bool IgnoreGender = FALSE;
bool ExtraLineSeek = TRUE;
- bool BirthdayProcessed = FALSE;
- bool AnniversaryProcessed = FALSE;
+ //bool BirthdayProcessed = FALSE;
+ //bool AnniversaryProcessed = FALSE;
bool FNProcessed = FALSE;
bool GenderProcessed = FALSE;
bool NameProcessed = FALSE;
- bool UIDProcessed = FALSE;
- bool KindProcessed = FALSE;
+ //bool UIDProcessed = FALSE;
+ //bool KindProcessed = FALSE;
bool ETagFound = FALSE;
bool ETagOrigFound = FALSE;
+ bool VersionProcessed = FALSE;
int intExtraNickname = 0;
wxString wxSProperty;
wxString wxSPropertySeg1;
int XTokenCount = 0;
//int intValueSeek = 1;
+ // Process the unique ID (UID)
+
+ UIDToken = ContactEditorData.UIDToken;
+
+ // Process the contact type (KIND) (frmContactEditor-LoadGroup.cpp)
+
+ LoadKind(&ContactEditorData.ContactKind);
+
+ // Process the Birthday (BDAY) (frmContactEditor-LoadBADays.cpp)
+
+ LoadBirthday(&ContactEditorData.Birthday, &ContactEditorData.BirthdayText);
+
+ // Process the Anniversary (ANNIVERSARY) (frmContactEditor-LoadBADays.cpp)
+
+ LoadAnniversary(&ContactEditorData.Anniversary, &ContactEditorData.AnniversaryText);
+
+ // Process the Gender (GENDER) (frmContactEditor-LoadGender.cpp)
+
+ LoadGender(&ContactEditorData.Gender, &ContactEditorData.GenderDetails);
+
+ // Process the Name (N) (frmContactEditor-LoadName.cpp)
+
+ LoadName(&ContactEditorData.NameTitle, &ContactEditorData.NameForename,
+ &ContactEditorData.NameSurname, &ContactEditorData.NameOtherNames,
+ &ContactEditorData.NameSuffix);
+
+ // Process the group members (MEMBER) (frmContactEditor-LoadGroup.cpp)
+
+ LoadMember(&ContactEditorData.GroupsList);
+
+ // Process the addresses (ADR) (frmContactEditor-LoadAddress.cpp)
+
+ LoadAddress(&ContactEditorData.GeneralAddressList,
+ &ContactEditorData.GeneralAddressListTown,
+ &ContactEditorData.GeneralAddressListCounty,
+ &ContactEditorData.GeneralAddressListPostCode,
+ &ContactEditorData.GeneralAddressListPref,
+ &ContactEditorData.HomeAddressList,
+ &ContactEditorData.HomeAddressListTown,
+ &ContactEditorData.HomeAddressListCounty,
+ &ContactEditorData.HomeAddressListPostCode,
+ &ContactEditorData.HomeAddressListPref,
+ &ContactEditorData.BusinessAddressList,
+ &ContactEditorData.BusinessAddressListTown,
+ &ContactEditorData.BusinessAddressListCounty,
+ &ContactEditorData.BusinessAddressListPostCode,
+ &ContactEditorData.BusinessAddressListPref,
+ &ADRCount);
+
+ // Process the timezones (TZ).
+
+ LoadData(&ContactEditorData.GeneralTZList,
+ &ContactEditorData.GeneralTZListPref,
+ lboTimezones,
+ &ContactEditorData.HomeTZList,
+ &ContactEditorData.HomeTZListPref,
+ lboHomeTimezones,
+ &ContactEditorData.BusinessTZList,
+ &ContactEditorData.BusinessTZListPref,
+ lboBusinessTimezones,
+ &TZCount);
+
+ // Process the emails (EMAIL).
+
+ LoadData(&ContactEditorData.GeneralEmailList,
+ &ContactEditorData.GeneralEmailListPref,
+ lboEmails,
+ &ContactEditorData.HomeEmailList,
+ &ContactEditorData.HomeEmailListPref,
+ lboHomeEmails,
+ &ContactEditorData.BusinessEmailList,
+ &ContactEditorData.BusinessEmailListPref,
+ lboBusinessEmail,
+ &EmailCount);
+
+ // Process the nicknames (NICKNAME).
+
+ LoadData(&ContactEditorData.GeneralNicknamesList,
+ &ContactEditorData.GeneralNicknamesListPref,
+ lboNicknames,
+ &ContactEditorData.HomeNicknamesList,
+ &ContactEditorData.HomeNicknamesListPref,
+ lboHomeNicknames,
+ &ContactEditorData.BusinessNicknamesList,
+ &ContactEditorData.BusinessNicknamesListPref,
+ lboBusinessNicknames,
+ &NicknameCount);
+
+ // Process the languages (LANG).
+
+ LoadData(&ContactEditorData.GeneralLanguageList,
+ &ContactEditorData.GeneralLanguageListPref,
+ lboLanguages,
+ &ContactEditorData.HomeLanguageList,
+ &ContactEditorData.HomeLanguageListPref,
+ lboHomeLanguages,
+ &ContactEditorData.BusinessLanguageList,
+ &ContactEditorData.BusinessLanguageListPref,
+ lboBusinessLanguages,
+ &LangCount);
+
+ // Process the geopositiosn (GEO).
+
+ LoadData(&ContactEditorData.GeneralGeographyList,
+ &ContactEditorData.GeneralGeographyListPref,
+ lboGeoposition,
+ &ContactEditorData.HomeGeographyList,
+ &ContactEditorData.HomeGeographyListPref,
+ lboHomeGeoposition,
+ &ContactEditorData.BusinessGeographyList,
+ &ContactEditorData.BusinessGeographyListPref,
+ lboBusinessGeoposition,
+ &GeoCount);
+
+ // Process the websites (URL).
+
+ LoadData(&ContactEditorData.GeneralWebsiteList,
+ &ContactEditorData.GeneralWebsiteListPref,
+ lboWebsites,
+ &ContactEditorData.HomeWebsiteList,
+ &ContactEditorData.HomeWebsiteListPref,
+ lboHomeWebsites,
+ &ContactEditorData.BusinessWebsiteList,
+ &ContactEditorData.BusinessWebsiteListPref,
+ lboBusinessWebsites,
+ &URLCount);
+
+ // Process the titles (TITLE).
+
+ LoadData(&ContactEditorData.GeneralTitleList,
+ &ContactEditorData.GeneralTitleListPref,
+ lboTitles,
+ &ContactEditorData.HomeTitleList,
+ &ContactEditorData.HomeTitleListPref,
+ lboHomeTitles,
+ &ContactEditorData.BusinessTitleList,
+ &ContactEditorData.BusinessTitleListPref,
+ lboBusinessTitles,
+ &TitleCount);
+
for (std::map<int,wxString>::iterator iter = ContactFileLines.begin();
iter != ContactFileLines.end(); ++iter){
// Add the data into the contact editor depending on what it is.
- if (wxSProperty == wxT("KIND") && KindProcessed == FALSE){
+ if (wxSProperty == wxT("VERSION") && VersionProcessed == FALSE){
+
+ // Check if version is 4.0, otherwise don't
+ // load.
+
+ if (wxSPropertySeg2 != wxT("4.0")){
+ wxMessageBox(_("This file is not a vCard 4.0 contact and is not supported under Xestia Address Book."),
+ _("Contact not supported"), wxICON_ERROR);
+ this->Close();
+ return FALSE;
+ }
+
+ VersionProcessed = TRUE;
+
+ }/* if (wxSProperty == wxT("KIND") && KindProcessed == FALSE){
// See frmContactEditor-LoadGroup.cpp
LoadKind(wxSPropertySeg2);
- } else if (wxSProperty == wxT("MEMBER")){
+ }/* else if (wxSProperty == wxT("MEMBER")){
// See frmContactEditor-LoadGroup.cpp
LoadMember(wxSPropertySeg2, &GroupCount);
- } else if (wxSProperty == wxT("FN")){
+ }*/ else if (wxSProperty == wxT("FN")){
// See frmContactEditor-LoadName.cpp
LoadFN(wxSPropertySeg1, wxSPropertySeg2, &FNCount, &FNProcessed, &ContactData);
- } else if (wxSProperty == wxT("N") && NameProcessed == FALSE){
+ }/* else if (wxSProperty == wxT("N") && NameProcessed == FALSE){
// See frmContactEditor-LoadName.cpp
LoadTimeZone(wxSPropertySeg1, wxSPropertySeg2, &TZCount);
- } else if (wxSProperty == wxT("ADR")){
+ } else if (wxSProperty == wxT("ADR")){
// See frmContactEditor-LoadAddress.cpp
LoadEmail(wxSPropertySeg1, wxSPropertySeg2, &EmailCount);
- } else if (wxSProperty == wxT("IMPP")){
+ }*/ else if (wxSProperty == wxT("IMPP")){
// See frmContactEditor-LoadIM.cpp
LoadTelephone(wxSPropertySeg1, wxSPropertySeg2, &TelCount);
- } else if (wxSProperty == wxT("LANG")){
+ }/* else if (wxSProperty == wxT("LANG")){
// See frmContactEditor-LoadLanguage.cpp
LoadGeo(wxSPropertySeg1, wxSPropertySeg2, &GeoCount);
- } else if (wxSProperty == wxT("RELATED")){
+ }*/ else if (wxSProperty == wxT("RELATED")){
// See fromContactEditor-LoadRelated.cpp
LoadRelated(wxSPropertySeg1, wxSPropertySeg2, &RelatedCount);
- } else if (wxSProperty == wxT("URL")){
+ }/* else if (wxSProperty == wxT("URL")){
// See frmContactEditor-LoadURL.cpp
LoadTitle(wxSPropertySeg1, wxSPropertySeg2, &TitleCount);
- } else if (wxSProperty == wxT("ROLE")) {
+ }*/ else if (wxSProperty == wxT("ROLE")) {
// See frmContactEditor-LoadRole.cpp
LoadKey(wxSPropertySeg1, wxSPropertySeg2, &KeyCount);
- } else if (wxSProperty == wxT("UID") && UIDProcessed == FALSE){
+ }/* else if (wxSProperty == wxT("UID") && UIDProcessed == FALSE){
UIDToken = wxSPropertySeg2;
UIDProcessed = TRUE;
- } else if (wxSProperty.Mid(0, 3) == wxT("VND")){
+ }*/ else if (wxSProperty.Mid(0, 3) == wxT("VND")){
// Split the Vendor three ways.
}
+}
+
+void frmContactEditor::LoadData(std::map<int, wxString> *GeneralList,
+ std::map<int, int> *GeneralListPref,
+ wxListCtrl *GeneralListCtrl,
+ std::map<int, wxString> *HomeList,
+ std::map<int, int> *HomeListPref,
+ wxListCtrl *HomeListCtrl,
+ std::map<int, wxString> *BusinessList,
+ std::map<int, int> *BusinessListPref,
+ wxListCtrl *BusinessListCtrl,
+ int *DataCount){
+
+ long ListCtrlIndex = -1;
+
+ // Deal with the general addresses.
+
+ for (std::map<int,wxString>::iterator Iter = GeneralList->begin();
+ Iter != GeneralList->end();
+ Iter++){
+
+ wxListItem coldata;
+
+ coldata.SetId(*DataCount);
+ coldata.SetData(*DataCount);
+ coldata.SetText(Iter->second);
+
+ ListCtrlIndex = GeneralListCtrl->InsertItem(coldata);
+
+ if (MapDataExists(DataCount, GeneralListPref)){
+
+ GeneralListCtrl->SetItem(ListCtrlIndex, 1, wxString::Format("%i", GeneralListPref->find(*DataCount)->second));
+
+ }
+
+ (*DataCount)++;
+
+ }
+
+ // Deal with the home addresses.
+
+ for (std::map<int,wxString>::iterator Iter = HomeList->begin();
+ Iter != HomeList->end();
+ Iter++){
+
+ wxListItem coldata;
+
+ coldata.SetId(*DataCount);
+ coldata.SetData(*DataCount);
+ coldata.SetText(Iter->second);
+
+ ListCtrlIndex = HomeListCtrl->InsertItem(coldata);
+
+ if (MapDataExists(DataCount, HomeListPref)){
+
+ HomeListCtrl->SetItem(ListCtrlIndex, 1, wxString::Format("%i", HomeListPref->find(*DataCount)->second));
+
+ }
+
+ (*DataCount)++;
+
+ }
+
+ // Deal with the work addresses.
+
+ for (std::map<int,wxString>::iterator Iter = BusinessList->begin();
+ Iter != BusinessList->end();
+ Iter++){
+
+ wxListItem coldata;
+
+ coldata.SetId(*DataCount);
+ coldata.SetData(*DataCount);
+ coldata.SetText(Iter->second);
+
+ ListCtrlIndex = BusinessListCtrl->InsertItem(coldata);
+
+ if (MapDataExists(DataCount, BusinessListPref)){
+
+ BusinessListCtrl->SetItem(ListCtrlIndex, 1, wxString::Format("%i", BusinessListPref->find(*DataCount)->second));
+
+ }
+
+ (*DataCount)++;
+
+ }
+
}
\ No newline at end of file