1 // frmContactEditorGroups.cpp - frmContactEditorGroups form.
\r
3 // (c) 2012-2015 Xestia Software Development.
\r
5 // This file is part of Xestia Address Book.
\r
7 // Xestia Address Book is free software: you can redistribute it and/or modify
\r
8 // it under the terms of the GNU General Public License as published by the
\r
9 // Free Software Foundation, version 3 of the license.
\r
11 // Xestia Address Book is distributed in the hope that it will be useful,
\r
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 // GNU General Public License for more details.
\r
16 // You should have received a copy of the GNU General Public License along
\r
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
\r
19 #include "frmContactEditorGroups.h"
\r
22 #include "../vcard/vcard.h"
\r
23 #include "../common/dirs.h"
\r
24 #include "../frmMain.h"
\r
26 frmContactEditorGroup::frmContactEditorGroup( wxWindow* parent )
\r
28 frmContactEditorGroupsADT( parent )
\r
33 void frmContactEditorGroup::FetchContacts( wxInitDialogEvent& event )
\r
36 // Load up the directory and get the list of contacts and UIDs.
\r
38 // Ignore contacts which have KIND:group set.
\r
40 wxString AccountDirFinal = GetAccountDir(AccName, FALSE);
\r
42 //wxString vcardfilenamewxs;
\r
43 wxString vCardFilename;
\r
44 wxString vCardFilenameFull;
\r
45 wxString vCardDataString;
\r
46 //wxStringTokenizer vcardfileline;
\r
48 wxString setname, setvalue;
\r
49 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
\r
50 std::multimap<wxString, ContactData, std::greater<wxString>> vCardNamesAsc;
\r
51 std::multimap<wxString, ContactData, std::less<wxString>> vCardNamesDsc;
\r
52 int ContactIndex = 0;
\r
54 wxDir vcardaccdir(AccountDirFinal);
\r
56 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
\r
59 if (vCardFilename.Right(4) == wxT(".vcf") ||
\r
60 vCardFilename.Right(4) == wxT(".VCF") ||
\r
61 vCardFilename.Right(5) == wxT(".vcard") ||
\r
62 vCardFilename.Right(5) == wxT(".VCARD")){
\r
66 vCardFilenameFull.Append(AccountDirFinal);
\r
67 vCardFilenameFull.Append(wxT("/"));
\r
68 vCardFilenameFull.Append(vCardFilename);
\r
70 Person.LoadFile(vCardFilenameFull);
\r
72 if (Person.MeetBaseSpecification()){
\r
74 wxString KindStatus = Person.Get(wxT("KIND"));
\r
76 if (KindStatus == wxT("group")){
\r
78 vCardFilename.Clear();
\r
79 vCardFilenameFull.Clear();
\r
80 vCardDataString.Clear();
\r
81 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
\r
86 wxString PersonName = Person.Get(wxT("N"));
\r
87 wxString PersonUID = Person.Get(wxT("UID"));
\r
88 wxString PersonFilename = vCardFilenameFull;
\r
90 ContactData PersonData;
\r
92 PersonData.ContactName = PersonName;
\r
93 PersonData.ContactUID = PersonUID;
\r
94 PersonData.ContactFilename = PersonFilename;
\r
96 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));
\r
97 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));
\r
99 if (XVMData.SortMode == 1){
\r
101 // Split the name into sections.
\r
103 vCardDataString = Person.Get(wxT("N"));
\r
105 vCardName NameData = Person.GetName();
\r
107 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
\r
109 } else if (XVMData.SortMode == 2){
\r
111 // Split the name into sections.
\r
113 vCardName NameData = Person.GetName();
\r
115 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
\r
117 } else if (XVMData.SortMode == 3){
\r
119 // Check and make sure that the top most nickname is used.
\r
121 vCardDataString = Person.Get(wxT("NICKNAME"));
\r
123 if (vCardDataString.IsEmpty()){
\r
125 vCardDataString = wxT("(no nickname)");
\r
129 } else if (XVMData.SortMode == 4){
\r
131 vCardDataString = Person.Get(wxT("FN"));
\r
135 if (XVMData.AscendingMode == TRUE){
\r
136 vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonData));
\r
138 vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonData));
\r
149 vCardFilename.Clear();
\r
150 vCardFilenameFull.Clear();
\r
151 vCardDataString.Clear();
\r
152 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
\r
156 if (XVMData.AscendingMode == TRUE){
\r
158 for (std::map<wxString,ContactData>::iterator iter = vCardNamesAsc.begin();
\r
159 iter != vCardNamesAsc.end(); ++iter){
\r
161 chkContacts->InsertItems(1, &iter->first, 0);
\r
163 ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));
\r
172 ContactIndex = (int)(vCardNamesDsc.size() - 1);
\r
174 for (std::map<wxString,ContactData>::iterator iter = vCardNamesDsc.begin();
\r
175 iter != vCardNamesDsc.end(); ++iter){
\r
177 chkContacts->InsertItems(1, &iter->first, 0);
\r
179 ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));
\r
189 void frmContactEditorGroup::ProcessData( wxCommandEvent& event )
\r
192 for (int i = 0; i < chkContacts->GetCount(); i++){
\r
194 if (chkContacts->IsChecked(i) == TRUE){
\r
196 // Get the UID and Name data from the struct
\r
199 wxString ContactName;
\r
200 wxString ContactUID;
\r
202 for (std::map<int, ContactData>::iterator iter = ContactNamesData.begin();
\r
203 iter != ContactNamesData.end(); ++iter){
\r
205 if (i == iter->first){
\r
207 ContactName = iter->second.ContactName;
\r
208 ContactUID = iter->second.ContactUID;
\r
214 wxListItem ItemData;
\r
216 ItemData.SetText(chkContacts->GetString(i));
\r
218 // Check if UID already exists before adding again. If already there
\r
219 // then don't bother adding again.
\r
221 bool ItemExists = FALSE;
\r
223 for (std::map<int, wxString>::iterator itemiter = GroupsListPtr->begin();
\r
224 itemiter != GroupsListPtr->end(); ++itemiter){
\r
226 if (itemiter->second == ContactUID){
\r
235 if (ItemExists == TRUE){
\r
241 GroupsListCtrlPtr->InsertItem(ItemData);
\r
242 GroupsListPtr->insert(std::make_pair(GroupsListIndex, ContactUID));
\r
252 void frmContactEditorGroup::SetupPointers(std::map<int, wxString> *GroupsList,
\r
253 wxListCtrl *GroupsListCtrl,
\r
254 wxString AccountName,
\r
258 GroupsListCtrlPtr = GroupsListCtrl;
\r
259 GroupsListPtr = GroupsList;
\r
260 AccName = AccountName;
\r
261 GroupsListIndex = GroupIndex;
\r
265 void frmContactEditorGroup::SetEditorMode(bool EditMode, XABViewMode XVMIn)
\r
268 EditorMode = EditMode;
\r
271 btnAction->SetLabel(_("Add"));
\r
272 this->SetTitle(_("Add Member(s)"));
\r
276 void frmContactEditorGroup::CloseWindow( wxCommandEvent& event )
\r