1 // frmContactEditor-LoadGroup.cpp - frmContactEditor load group 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/>
19 #include "frmContactEditor.h"
20 #include "../common/dirs.h"
23 void frmContactEditor::LoadKind(ContactKindType *KindType){
26 case CONTACTKIND_INDIVIDUAL:
27 cmbType->SetSelection(1);
29 case CONTACTKIND_GROUP:
30 cmbType->SetSelection(2);
32 case CONTACTKIND_ORGANISATION:
33 cmbType->SetSelection(3);
35 case CONTACTKIND_LOCATION:
36 cmbType->SetSelection(4);
38 case CONTACTKIND_NONE:
39 cmbType->SetSelection(0);
43 wxCommandEvent nullevent;
45 UpdateMembersTab(nullevent);
49 void frmContactEditor::LoadKind(wxString KindType){
51 if (KindType == wxT("individual")){
53 cmbType->SetSelection(1);
55 } else if (KindType == wxT("group")){
57 cmbType->SetSelection(2);
60 } else if (KindType == wxT("org")){
62 cmbType->SetSelection(3);
64 } else if (KindType == wxT("location")){
66 cmbType->SetSelection(4);
70 cmbType->SetSelection(0);
74 wxCommandEvent nullevent;
76 UpdateMembersTab(nullevent);
80 void frmContactEditor::LoadMember(std::map<int,wxString> *GroupList){
82 // Go through the list of contacts for the account and find the matching UID.
83 // If contact with UID doesn't match then say (unknown contact).
86 if (StartupEditMode == FALSE){
87 XVMData = MainPtr->GetViewMode();
90 wxString AccountDirFinal = GetAccountDir(wxSContactAccount, FALSE);
92 //wxString vcardfilenamewxs;
93 wxString vCardFilename;
94 wxString vCardFilenameFull;
95 wxString vCardDataString;
96 //wxStringTokenizer vcardfileline;
98 wxString setname, setvalue;
100 bool FoundContact = FALSE;
101 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
102 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
103 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
105 wxDir vcardaccdir(AccountDirFinal);
107 for (std::map<int,wxString>::iterator MemberIter = GroupList->begin();
108 MemberIter != GroupList->end();
111 MemberData = MemberIter->second;
113 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
116 if (vCardFilename.Right(4) == wxT(".vcf") ||
117 vCardFilename.Right(4) == wxT(".VCF") ||
118 vCardFilename.Right(5) == wxT(".vcard") ||
119 vCardFilename.Right(5) == wxT(".VCARD")){
123 vCardFilenameFull.Append(AccountDirFinal);
124 vCardFilenameFull.Append(wxT("/"));
125 vCardFilenameFull.Append(vCardFilename);
127 Person.LoadFile(vCardFilenameFull);
129 if (MemberData.Left(9) == wxT("urn:uuid:")){
131 wxString NewPropValue;
132 NewPropValue = MemberData.Mid(9, wxString::npos);
133 MemberData = NewPropValue;
137 if (Person.MeetBaseSpecification()){
139 wxString KindStatus = Person.Get(wxT("KIND"));
141 if (KindStatus == wxT("group")){
143 vCardFilename.Clear();
144 vCardFilenameFull.Clear();
145 vCardDataString.Clear();
146 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
151 wxString PersonName = Person.Get(wxT("N"));
152 wxString PersonUID = Person.Get(wxT("UID"));
153 wxString PersonFilename = vCardFilenameFull;
155 if (PersonUID != MemberData){
157 vCardFilename.Clear();
158 vCardFilenameFull.Clear();
159 vCardDataString.Clear();
160 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
167 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));
168 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));
170 if (XVMData.SortMode == 1){
172 // Split the name into sections.
174 vCardDataString = Person.Get(wxT("N"));
176 vCardName NameData = Person.GetName();
178 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
180 } else if (XVMData.SortMode == 2){
182 // Split the name into sections.
184 vCardName NameData = Person.GetName();
186 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
188 } else if (XVMData.SortMode == 3){
190 // Check and make sure that the top most nickname is used.
192 vCardDataString = Person.Get(wxT("NICKNAME"));
194 if (vCardDataString.IsEmpty()){
196 vCardDataString = wxT("(no nickname)");
200 } else if (XVMData.SortMode == 4){
202 vCardDataString = Person.Get(wxT("FN"));
206 if (XVMData.AscendingMode == TRUE){
207 vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonUID));
209 vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonUID));
220 vCardFilename.Clear();
221 vCardFilenameFull.Clear();
222 vCardDataString.Clear();
223 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
227 if (FoundContact == FALSE){
228 if (XVMData.AscendingMode == TRUE){
229 vCardNamesAsc.insert(std::make_pair(MemberIter->second, MemberIter->second));
231 vCardNamesDsc.insert(std::make_pair(MemberIter->second, MemberIter->second));
235 if (XVMData.AscendingMode == TRUE){
237 for (std::map<wxString,wxString>::iterator iter = vCardNamesAsc.begin();
238 iter != vCardNamesAsc.end(); ++iter){
243 ItemData.SetText(iter->first);
245 lboGroups->InsertItem(ItemData);
252 for (std::map<wxString,wxString>::iterator iter = vCardNamesDsc.begin();
253 iter != vCardNamesDsc.end(); ++iter){
258 ItemData.SetText(iter->first);
260 lboGroups->InsertItem(ItemData);
270 void frmContactEditor::LoadMember(wxString MemberData, int *GroupCount){
272 // Go through the list of contacts for the account and find the matching UID.
273 // If contact with UID doesn't match then say (unknown contact).
276 if (StartupEditMode == FALSE){
277 XVMData = MainPtr->GetViewMode();
280 wxString AccountDirFinal = GetAccountDir(wxSContactAccount, FALSE);
282 //wxString vcardfilenamewxs;
283 wxString vCardFilename;
284 wxString vCardFilenameFull;
285 wxString vCardDataString;
286 //wxStringTokenizer vcardfileline;
288 wxString setname, setvalue;
289 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
290 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
291 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
293 wxDir vcardaccdir(AccountDirFinal);
295 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
298 if (vCardFilename.Right(4) == wxT(".vcf") ||
299 vCardFilename.Right(4) == wxT(".VCF") ||
300 vCardFilename.Right(5) == wxT(".vcard") ||
301 vCardFilename.Right(5) == wxT(".VCARD")){
305 vCardFilenameFull.Append(AccountDirFinal);
306 vCardFilenameFull.Append(wxT("/"));
307 vCardFilenameFull.Append(vCardFilename);
309 Person.LoadFile(vCardFilenameFull);
311 if (MemberData.Left(9) == wxT("urn:uuid:")){
313 wxString NewPropValue;
314 NewPropValue = MemberData.Mid(9, wxString::npos);
315 MemberData = NewPropValue;
319 if (Person.MeetBaseSpecification()){
321 wxString KindStatus = Person.Get(wxT("KIND"));
323 if (KindStatus == wxT("group")){
325 vCardFilename.Clear();
326 vCardFilenameFull.Clear();
327 vCardDataString.Clear();
328 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
333 wxString PersonName = Person.Get(wxT("N"));
334 wxString PersonUID = Person.Get(wxT("UID"));
335 wxString PersonFilename = vCardFilenameFull;
337 if (PersonUID != MemberData){
339 vCardFilename.Clear();
340 vCardFilenameFull.Clear();
341 vCardDataString.Clear();
342 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
347 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));
348 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));
350 if (XVMData.SortMode == 1){
352 // Split the name into sections.
354 vCardDataString = Person.Get(wxT("N"));
356 vCardName NameData = Person.GetName();
358 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
360 } else if (XVMData.SortMode == 2){
362 // Split the name into sections.
364 vCardName NameData = Person.GetName();
366 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
368 } else if (XVMData.SortMode == 3){
370 // Check and make sure that the top most nickname is used.
372 vCardDataString = Person.Get(wxT("NICKNAME"));
374 if (vCardDataString.IsEmpty()){
376 vCardDataString = wxT("(no nickname)");
380 } else if (XVMData.SortMode == 4){
382 vCardDataString = Person.Get(wxT("FN"));
386 if (XVMData.AscendingMode == TRUE){
387 vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonUID));
389 vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonUID));
400 vCardFilename.Clear();
401 vCardFilenameFull.Clear();
402 vCardDataString.Clear();
403 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
407 if (XVMData.AscendingMode == TRUE){
409 for (std::map<wxString,wxString>::iterator iter = vCardNamesAsc.begin();
410 iter != vCardNamesAsc.end(); ++iter){
415 ItemData.SetText(iter->first);
417 lboGroups->InsertItem(ItemData);
419 GroupsList.insert(std::make_pair(intValueSeek, iter->second));
426 for (std::map<wxString,wxString>::iterator iter = vCardNamesDsc.begin();
427 iter != vCardNamesDsc.end(); ++iter){
432 ItemData.SetText(iter->first);
434 lboGroups->InsertItem(ItemData);
436 GroupsList.insert(std::make_pair(intValueSeek, iter->second));