// frmContactEditorGroups.cpp - frmContactEditorGroups form. // // (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 #include "frmContactEditorGroups.h" #include #include #include "../vcard/vcard.h" #include "../common/dirs.h" #include "../frmMain.h" frmContactEditorGroup::frmContactEditorGroup( wxWindow* parent ) : frmContactEditorGroupsADT( parent ) { // Setup the window. EditorMode = FALSE; } void frmContactEditorGroup::FetchContacts( wxInitDialogEvent& event ) { // Load up the directory and get the list of contacts and UIDs. // Ignore contacts which have KIND:group set. wxString AccountDirFinal = GetAccountDir(AccName, FALSE); wxString vCardFilename; wxString vCardFilenameFull; wxString vCardDataString; wxString lwxs; wxString setname, setvalue; std::multimap> vCardNamesAsc; std::multimap> vCardNamesDsc; int ContactIndex = 0; wxDir vcardaccdir(AccountDirFinal); bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES); while(ProcFiles){ if (vCardFilename.Right(4) == wxT(".vcf") || vCardFilename.Right(4) == wxT(".VCF") || vCardFilename.Right(5) == wxT(".vcard") || vCardFilename.Right(5) == wxT(".VCARD")){ vCard Person; vCardFilenameFull.Append(AccountDirFinal); vCardFilenameFull.Append(wxT("/")); vCardFilenameFull.Append(vCardFilename); Person.LoadFile(vCardFilenameFull); if (Person.MeetBaseSpecification()){ wxString KindStatus = Person.Get(wxT("KIND")); if (KindStatus == wxT("group")){ vCardFilename.Clear(); vCardFilenameFull.Clear(); vCardDataString.Clear(); ProcFiles = vcardaccdir.GetNext(&vCardFilename); continue; } wxString PersonName = Person.Get(wxT("N")); wxString PersonUID = Person.Get(wxT("UID")); wxString PersonFilename = vCardFilenameFull; ContactData PersonData; PersonData.ContactName = PersonName; PersonData.ContactUID = PersonUID; PersonData.ContactFilename = PersonFilename; if (XVMData.SortMode == 1){ // Split the name into sections. vCardDataString = Person.Get(wxT("N")); vCardName NameData = Person.GetName(); vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname; } else if (XVMData.SortMode == 2){ // Split the name into sections. vCardName NameData = Person.GetName(); vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename; } else if (XVMData.SortMode == 3){ // Check and make sure that the top most nickname is used. vCardDataString = Person.Get(wxT("NICKNAME")); if (vCardDataString.IsEmpty()){ vCardDataString = wxT("(no nickname)"); } } else if (XVMData.SortMode == 4){ vCardDataString = Person.Get(wxT("FN")); } if (XVMData.AscendingMode == TRUE){ vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonData)); } else { vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonData)); } } else { } } vCardFilename.Clear(); vCardFilenameFull.Clear(); vCardDataString.Clear(); ProcFiles = vcardaccdir.GetNext(&vCardFilename); } if (XVMData.AscendingMode == TRUE){ for (std::map::iterator iter = vCardNamesAsc.begin(); iter != vCardNamesAsc.end(); ++iter){ chkContacts->InsertItems(1, &iter->first, 0); ContactNamesData.insert(std::make_pair(ContactIndex, iter->second)); ContactIndex++; } } else { ContactIndex = (int)(vCardNamesDsc.size() - 1); for (std::map::iterator iter = vCardNamesDsc.begin(); iter != vCardNamesDsc.end(); ++iter){ chkContacts->InsertItems(1, &iter->first, 0); ContactNamesData.insert(std::make_pair(ContactIndex, iter->second)); ContactIndex--; } } } void frmContactEditorGroup::ProcessData( wxCommandEvent& event ) { // Process action. for (int i = 0; i < chkContacts->GetCount(); i++){ if (chkContacts->IsChecked(i) == TRUE){ // Get the UID and Name data from the struct // via GetData. wxString ContactName; wxString ContactUID; for (std::map::iterator iter = ContactNamesData.begin(); iter != ContactNamesData.end(); ++iter){ if (i == iter->first){ ContactName = iter->second.ContactName; ContactUID = iter->second.ContactUID; } } wxListItem ItemData; ItemData.SetId(0); ItemData.SetText(chkContacts->GetString(i)); // Check if UID already exists before adding again. If already there // then don't bother adding again. bool ItemExists = FALSE; for (std::map::iterator itemiter = GroupsListPtr->begin(); itemiter != GroupsListPtr->end(); ++itemiter){ if (itemiter->second == ContactUID){ ItemExists = TRUE; break; } } if (ItemExists == TRUE){ continue; } GroupsListCtrlPtr->InsertItem(ItemData); GroupsListPtr->insert(std::make_pair(GroupsListIndex, ContactUID)); } } this->Close(); } void frmContactEditorGroup::SetupPointers(std::map *GroupsList, wxListCtrl *GroupsListCtrl, wxString AccountName, int GroupIndex) { // Setup the pointers. GroupsListCtrlPtr = GroupsListCtrl; GroupsListPtr = GroupsList; AccName = AccountName; GroupsListIndex = GroupIndex; } void frmContactEditorGroup::SetEditorMode(bool EditMode, XABViewMode XVMIn) { // Setup the editor mode. EditorMode = EditMode; XVMData = XVMIn; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Member(s)")); } void frmContactEditorGroup::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); }