Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented MEMBER in frmContactEditor through ContactDataObject.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadGroup.cpp
1 // frmContactEditor-LoadGroup.cpp - frmContactEditor load group subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
21 #include <wx/dir.h>
23 void frmContactEditor::LoadKind(ContactKindType *KindType){
25         switch (*KindType){
26                 case CONTACTKIND_INDIVIDUAL:
27                         cmbType->SetSelection(1);
28                         break;
29                 case CONTACTKIND_GROUP:
30                         cmbType->SetSelection(2);
31                         break;
32                 case CONTACTKIND_ORGANISATION:
33                         cmbType->SetSelection(3);
34                         break;
35                 case CONTACTKIND_LOCATION:
36                         cmbType->SetSelection(4);
37                         break;
38                 case CONTACTKIND_NONE:
39                         cmbType->SetSelection(0);
40                         break;
41         }
42                         
43         wxCommandEvent nullevent;
44                         
45         UpdateMembersTab(nullevent);
47 }
49 void frmContactEditor::LoadKind(wxString KindType){
51         if (KindType == wxT("individual")){
52                         
53                 cmbType->SetSelection(1);
54                         
55         } else if (KindType == wxT("group")){
56                         
57                 cmbType->SetSelection(2);
58                 IsGroup = TRUE;
59                         
60         } else if (KindType == wxT("org")){
61                         
62                 cmbType->SetSelection(3);
63                         
64         } else if (KindType == wxT("location")){
65                         
66                 cmbType->SetSelection(4);
67                         
68         } else {
69                         
70                 cmbType->SetSelection(0);
71                         
72         }
73                         
74         wxCommandEvent nullevent;
75                         
76         UpdateMembersTab(nullevent);
78 }
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).
85         XABViewMode XVMData;
86         if (StartupEditMode == FALSE){
87                 XVMData = MainPtr->GetViewMode();
88         }
89         
90         wxString AccountDirFinal = GetAccountDir(wxSContactAccount, FALSE);
92         //wxString vcardfilenamewxs;
93         wxString vCardFilename;
94         wxString vCardFilenameFull;
95         wxString vCardDataString;
96         //wxStringTokenizer vcardfileline;
97         wxString lwxs;
98         wxString setname, setvalue;
99         wxString MemberData;
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();
109                 MemberIter++){
110                 
111                 MemberData = MemberIter->second;
112                 
113                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
114                 while(ProcFiles){
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")){
121                             vCard Person;
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;
135                             }
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);
147                                         continue;
149                                 }
151                                 wxString PersonName = Person.Get(wxT("N"));
152                                 wxString PersonUID = Person.Get(wxT("UID"));
153                                 wxString PersonFilename = vCardFilenameFull;
154                         
155                                 if (PersonUID != MemberData){
156                         
157                                         vCardFilename.Clear();
158                                         vCardFilenameFull.Clear();
159                                         vCardDataString.Clear();
160                                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
161                                         continue;
162                         
163                                 } else {
164                                         FoundContact = TRUE;
165                                 }
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.
173         
174                                     vCardDataString = Person.Get(wxT("N"));
176                                     vCardName NameData = Person.GetName();
177     
178                                     vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
179     
180                                 } else if (XVMData.SortMode == 2){
181     
182                                     // Split the name into sections.
183     
184                                     vCardName NameData = Person.GetName();    
185     
186                                     vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
187     
188                                 } else if (XVMData.SortMode == 3){
189     
190                                     // Check and make sure that the top most nickname is used.
191     
192                                     vCardDataString = Person.Get(wxT("NICKNAME"));
193     
194                                     if (vCardDataString.IsEmpty()){
195         
196                                         vCardDataString = wxT("(no nickname)");
197         
198                                     }
199     
200                                 } else if (XVMData.SortMode == 4){
201     
202                                     vCardDataString = Person.Get(wxT("FN"));
203     
204                                 }
206                                 if (XVMData.AscendingMode == TRUE){
207                                     vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonUID));
208                                 } else {
209                                     vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonUID));
210                                 }
212                             } else {
214                             }
218                         }
220                         vCardFilename.Clear();
221                         vCardFilenameFull.Clear();
222                         vCardDataString.Clear();
223                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
225                     }
226                     
227                     if (FoundContact == FALSE){
228                         if (XVMData.AscendingMode == TRUE){
229                             vCardNamesAsc.insert(std::make_pair(MemberIter->second, MemberIter->second));
230                         } else {
231                             vCardNamesDsc.insert(std::make_pair(MemberIter->second, MemberIter->second));
232                         }
233                     }
235                     if (XVMData.AscendingMode == TRUE){
237                         for (std::map<wxString,wxString>::iterator iter = vCardNamesAsc.begin(); 
238                         iter != vCardNamesAsc.end(); ++iter){
240                                 wxListItem ItemData;
241                         
242                                 ItemData.SetId(0);
243                                 ItemData.SetText(iter->first);
244         
245                                 lboGroups->InsertItem(ItemData);
247                         }
250                     } else {
252                         for (std::map<wxString,wxString>::iterator iter = vCardNamesDsc.begin(); 
253                         iter != vCardNamesDsc.end(); ++iter){
255                                 wxListItem ItemData;
256                         
257                                 ItemData.SetId(0);
258                                 ItemData.SetText(iter->first);
259         
260                                 lboGroups->InsertItem(ItemData);
262                     }
264                 }
265         
266         }
267         
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).
275         XABViewMode XVMData;
276         if (StartupEditMode == FALSE){
277                 XVMData = MainPtr->GetViewMode();
278         }
279         
280         wxString AccountDirFinal = GetAccountDir(wxSContactAccount, FALSE);
282         //wxString vcardfilenamewxs;
283         wxString vCardFilename;
284         wxString vCardFilenameFull;
285         wxString vCardDataString;
286         //wxStringTokenizer vcardfileline;
287         wxString lwxs;
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);
296         while(ProcFiles){
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")){
303                     vCard Person;
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;
317                     }
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);
329                                 continue;
331                         }
333                         wxString PersonName = Person.Get(wxT("N"));
334                         wxString PersonUID = Person.Get(wxT("UID"));
335                         wxString PersonFilename = vCardFilenameFull;
336                         
337                         if (PersonUID != MemberData){
338                         
339                                 vCardFilename.Clear();
340                                 vCardFilenameFull.Clear();
341                                 vCardDataString.Clear();
342                                 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
343                                 continue;
344                         
345                         }
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.
353         
354                             vCardDataString = Person.Get(wxT("N"));
356                             vCardName NameData = Person.GetName();
357     
358                             vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
359     
360                         } else if (XVMData.SortMode == 2){
361     
362                             // Split the name into sections.
363     
364                             vCardName NameData = Person.GetName();    
365     
366                             vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
367     
368                         } else if (XVMData.SortMode == 3){
369     
370                             // Check and make sure that the top most nickname is used.
371     
372                             vCardDataString = Person.Get(wxT("NICKNAME"));
373     
374                             if (vCardDataString.IsEmpty()){
375         
376                                 vCardDataString = wxT("(no nickname)");
377         
378                             }
379     
380                         } else if (XVMData.SortMode == 4){
381     
382                             vCardDataString = Person.Get(wxT("FN"));
383     
384                         }
386                         if (XVMData.AscendingMode == TRUE){
387                             vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonUID));
388                         } else {
389                             vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonUID));
390                         }
392                     } else {
394                     }
398                 }
400                 vCardFilename.Clear();
401                 vCardFilenameFull.Clear();
402                 vCardDataString.Clear();
403                 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
405             }
407             if (XVMData.AscendingMode == TRUE){
409                 for (std::map<wxString,wxString>::iterator iter = vCardNamesAsc.begin(); 
410                 iter != vCardNamesAsc.end(); ++iter){
412                         wxListItem ItemData;
413                         
414                         ItemData.SetId(0);
415                         ItemData.SetText(iter->first);
416         
417                         lboGroups->InsertItem(ItemData);
418                         
419                         GroupsList.insert(std::make_pair(intValueSeek, iter->second));
420         
421                 }
424             } else {
426                 for (std::map<wxString,wxString>::iterator iter = vCardNamesDsc.begin(); 
427                 iter != vCardNamesDsc.end(); ++iter){
429                         wxListItem ItemData;
430                         
431                         ItemData.SetId(0);
432                         ItemData.SetText(iter->first);
433         
434                         lboGroups->InsertItem(ItemData);
436                         GroupsList.insert(std::make_pair(intValueSeek, iter->second));
438             }
440         }
441         
442         GroupCount++;
443         intValueSeek++;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy