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){
25 std::cerr << *KindType << std::endl;
28 case CONTACTKIND_INDIVIDUAL:
29 cmbType->SetSelection(1);
31 case CONTACTKIND_GROUP:
32 cmbType->SetSelection(2);
34 case CONTACTKIND_ORGANISATION:
35 cmbType->SetSelection(3);
37 case CONTACTKIND_LOCATION:
38 cmbType->SetSelection(4);
40 case CONTACTKIND_NONE:
41 cmbType->SetSelection(0);
45 wxCommandEvent nullevent;
47 UpdateMembersTab(nullevent);
51 void frmContactEditor::LoadKind(wxString KindType){
53 if (KindType == wxT("individual")){
55 cmbType->SetSelection(1);
57 } else if (KindType == wxT("group")){
59 cmbType->SetSelection(2);
62 } else if (KindType == wxT("org")){
64 cmbType->SetSelection(3);
66 } else if (KindType == wxT("location")){
68 cmbType->SetSelection(4);
72 cmbType->SetSelection(0);
76 wxCommandEvent nullevent;
78 UpdateMembersTab(nullevent);
82 void frmContactEditor::LoadMember(wxString MemberData, int *GroupCount){
84 // Go through the list of contacts for the account and find the matching UID.
85 // If contact with UID doesn't match then say (unknown contact).
88 if (StartupEditMode == FALSE){
89 XVMData = MainPtr->GetViewMode();
92 wxString AccountDirFinal = GetAccountDir(wxSContactAccount, FALSE);
94 //wxString vcardfilenamewxs;
95 wxString vCardFilename;
96 wxString vCardFilenameFull;
97 wxString vCardDataString;
98 //wxStringTokenizer vcardfileline;
100 wxString setname, setvalue;
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 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
110 if (vCardFilename.Right(4) == wxT(".vcf") ||
111 vCardFilename.Right(4) == wxT(".VCF") ||
112 vCardFilename.Right(5) == wxT(".vcard") ||
113 vCardFilename.Right(5) == wxT(".VCARD")){
117 vCardFilenameFull.Append(AccountDirFinal);
118 vCardFilenameFull.Append(wxT("/"));
119 vCardFilenameFull.Append(vCardFilename);
121 Person.LoadFile(vCardFilenameFull);
123 if (MemberData.Left(9) == wxT("urn:uuid:")){
125 wxString NewPropValue;
126 NewPropValue = MemberData.Mid(9, wxString::npos);
127 MemberData = NewPropValue;
131 if (Person.MeetBaseSpecification()){
133 wxString KindStatus = Person.Get(wxT("KIND"));
135 if (KindStatus == wxT("group")){
137 vCardFilename.Clear();
138 vCardFilenameFull.Clear();
139 vCardDataString.Clear();
140 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
145 wxString PersonName = Person.Get(wxT("N"));
146 wxString PersonUID = Person.Get(wxT("UID"));
147 wxString PersonFilename = vCardFilenameFull;
149 if (PersonUID != MemberData){
151 vCardFilename.Clear();
152 vCardFilenameFull.Clear();
153 vCardDataString.Clear();
154 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
159 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));
160 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));
162 if (XVMData.SortMode == 1){
164 // Split the name into sections.
166 vCardDataString = Person.Get(wxT("N"));
168 vCardName NameData = Person.GetName();
170 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
172 } else if (XVMData.SortMode == 2){
174 // Split the name into sections.
176 vCardName NameData = Person.GetName();
178 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
180 } else if (XVMData.SortMode == 3){
182 // Check and make sure that the top most nickname is used.
184 vCardDataString = Person.Get(wxT("NICKNAME"));
186 if (vCardDataString.IsEmpty()){
188 vCardDataString = wxT("(no nickname)");
192 } else if (XVMData.SortMode == 4){
194 vCardDataString = Person.Get(wxT("FN"));
198 if (XVMData.AscendingMode == TRUE){
199 vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonUID));
201 vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonUID));
212 vCardFilename.Clear();
213 vCardFilenameFull.Clear();
214 vCardDataString.Clear();
215 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
219 if (XVMData.AscendingMode == TRUE){
221 for (std::map<wxString,wxString>::iterator iter = vCardNamesAsc.begin();
222 iter != vCardNamesAsc.end(); ++iter){
227 ItemData.SetText(iter->first);
229 lboGroups->InsertItem(ItemData);
231 GroupsList.insert(std::make_pair(intValueSeek, iter->second));
238 for (std::map<wxString,wxString>::iterator iter = vCardNamesDsc.begin();
239 iter != vCardNamesDsc.end(); ++iter){
244 ItemData.SetText(iter->first);
246 lboGroups->InsertItem(ItemData);
248 GroupsList.insert(std::make_pair(intValueSeek, iter->second));