Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Fixed crash in frmContactEditorOrganisations in Edit mode.
[xestiaab/.git] / source / contacteditor / frmContactEditorGroups.cpp
1 // frmContactEditorGroups.cpp - frmContactEditorGroups form.\r
2 //\r
3 // (c) 2012-2015 Xestia Software Development.\r
4 //\r
5 // This file is part of Xestia Address Book.\r
6 //\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
10 //\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
15 //\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
18 \r
19 #include "frmContactEditorGroups.h"\r
20 #include <wx/wx.h>\r
21 #include <wx/dir.h>\r
22 #include "../vcard/vcard.h"\r
23 #include "../common/dirs.h"\r
24 #include "../frmMain.h"\r
25 \r
26 frmContactEditorGroup::frmContactEditorGroup( wxWindow* parent )\r
27 :\r
28 frmContactEditorGroupsADT( parent )\r
29 {\r
30         EditorMode = FALSE;\r
31 }\r
32 \r
33 void frmContactEditorGroup::FetchContacts( wxInitDialogEvent& event )\r
34 {\r
35 \r
36         // Load up the directory and get the list of contacts and UIDs.\r
37 \r
38         // Ignore contacts which have KIND:group set.\r
39         \r
40     wxString AccountDirFinal = GetAccountDir(AccName, FALSE);\r
41 \r
42     //wxString vcardfilenamewxs;\r
43     wxString vCardFilename;\r
44     wxString vCardFilenameFull;\r
45     wxString vCardDataString;\r
46     //wxStringTokenizer vcardfileline;\r
47     wxString lwxs;\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
53     \r
54     wxDir vcardaccdir(AccountDirFinal);\r
55     \r
56     bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);\r
57     while(ProcFiles){\r
58     \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
63         \r
64             vCard Person;\r
65                 \r
66             vCardFilenameFull.Append(AccountDirFinal);\r
67             vCardFilenameFull.Append(wxT("/"));\r
68             vCardFilenameFull.Append(vCardFilename);\r
69                 \r
70             Person.LoadFile(vCardFilenameFull);\r
71                 \r
72             if (Person.MeetBaseSpecification()){\r
73         \r
74                 wxString KindStatus = Person.Get(wxT("KIND"));\r
75                 \r
76                 if (KindStatus == wxT("group")){\r
77                 \r
78                         vCardFilename.Clear();\r
79                         vCardFilenameFull.Clear();\r
80                         vCardDataString.Clear();\r
81                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);\r
82                         continue;\r
83                 \r
84                 }\r
85                 \r
86                 wxString PersonName = Person.Get(wxT("N"));\r
87                 wxString PersonUID = Person.Get(wxT("UID"));\r
88                 wxString PersonFilename = vCardFilenameFull;\r
89                 \r
90                 ContactData PersonData;\r
91                 \r
92                 PersonData.ContactName = PersonName;\r
93                 PersonData.ContactUID = PersonUID;\r
94                 PersonData.ContactFilename = PersonFilename;\r
95                 \r
96                 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));\r
97                 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));\r
98         \r
99                 if (XVMData.SortMode == 1){\r
100 \r
101                     // Split the name into sections.\r
102                         \r
103                     vCardDataString = Person.Get(wxT("N"));\r
104 \r
105                     vCardName NameData = Person.GetName();\r
106                     \r
107                     vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;\r
108                     \r
109                 } else if (XVMData.SortMode == 2){\r
110                     \r
111                     // Split the name into sections.\r
112                     \r
113                     vCardName NameData = Person.GetName();    \r
114                     \r
115                     vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;\r
116                     \r
117                 } else if (XVMData.SortMode == 3){\r
118                     \r
119                     // Check and make sure that the top most nickname is used.\r
120                     \r
121                     vCardDataString = Person.Get(wxT("NICKNAME"));\r
122                     \r
123                     if (vCardDataString.IsEmpty()){\r
124                         \r
125                         vCardDataString = wxT("(no nickname)");\r
126                         \r
127                     }\r
128                     \r
129                 } else if (XVMData.SortMode == 4){\r
130                     \r
131                     vCardDataString = Person.Get(wxT("FN"));\r
132                     \r
133                 }\r
134         \r
135                 if (XVMData.AscendingMode == TRUE){\r
136                     vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonData));\r
137                 } else {\r
138                     vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonData));\r
139                 }\r
140                 \r
141             } else {\r
142         \r
143             }\r
144             \r
145             \r
146         \r
147         }\r
148         \r
149         vCardFilename.Clear();\r
150         vCardFilenameFull.Clear();\r
151         vCardDataString.Clear();\r
152         ProcFiles = vcardaccdir.GetNext(&vCardFilename);\r
153         \r
154     }\r
155     \r
156     if (XVMData.AscendingMode == TRUE){\r
157              \r
158         for (std::map<wxString,ContactData>::iterator iter = vCardNamesAsc.begin(); \r
159         iter != vCardNamesAsc.end(); ++iter){\r
160 \r
161            chkContacts->InsertItems(1, &iter->first, 0);\r
162         \r
163            ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));         \r
164         \r
165            ContactIndex++;\r
166                         \r
167         }\r
168                 \r
169                 \r
170     } else {\r
171                 \r
172         ContactIndex = (int)(vCardNamesDsc.size() - 1);\r
173                 \r
174         for (std::map<wxString,ContactData>::iterator iter = vCardNamesDsc.begin();\r
175              iter != vCardNamesDsc.end(); ++iter){\r
176 \r
177             chkContacts->InsertItems(1, &iter->first, 0);\r
178 \r
179             ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));\r
180         \r
181             ContactIndex--;\r
182 \r
183         }\r
184         \r
185     }\r
186 \r
187 }\r
188 \r
189 void frmContactEditorGroup::ProcessData( wxCommandEvent& event )\r
190 {\r
191         \r
192         for (int i = 0; i < chkContacts->GetCount(); i++){\r
193         \r
194                 if (chkContacts->IsChecked(i) == TRUE){\r
195                 \r
196                         // Get the UID and Name data from the struct\r
197                         // via GetData.\r
198                         \r
199                         wxString ContactName;\r
200                         wxString ContactUID;\r
201                         \r
202                         for (std::map<int, ContactData>::iterator iter = ContactNamesData.begin(); \r
203                         iter != ContactNamesData.end(); ++iter){\r
204                         \r
205                                 if (i == iter->first){\r
206                                 \r
207                                         ContactName = iter->second.ContactName;\r
208                                         ContactUID = iter->second.ContactUID;\r
209                                                 \r
210                                 }\r
211                         \r
212                         }\r
213                         \r
214                         wxListItem ItemData;\r
215                         ItemData.SetId(0);\r
216                         ItemData.SetText(chkContacts->GetString(i));\r
217                         \r
218                         // Check if UID already exists before adding again. If already there\r
219                         // then don't bother adding again.\r
220                         \r
221                         bool ItemExists = FALSE;\r
222                         \r
223                         for (std::map<int, wxString>::iterator itemiter = GroupsListPtr->begin();\r
224                         itemiter != GroupsListPtr->end(); ++itemiter){\r
225                         \r
226                                 if (itemiter->second == ContactUID){\r
227                                 \r
228                                         ItemExists = TRUE;\r
229                                         break;\r
230                                 \r
231                                 }\r
232                         \r
233                         }\r
234                         \r
235                         if (ItemExists == TRUE){\r
236                         \r
237                                 continue;\r
238                         \r
239                         }\r
240                         \r
241                         GroupsListCtrlPtr->InsertItem(ItemData);\r
242                         GroupsListPtr->insert(std::make_pair(GroupsListIndex, ContactUID));\r
243                 \r
244                 }\r
245         \r
246         }\r
247         \r
248         this->Close();\r
249         \r
250 }\r
251 \r
252 void frmContactEditorGroup::SetupPointers(std::map<int, wxString> *GroupsList,\r
253         wxListCtrl *GroupsListCtrl, \r
254         wxString AccountName, \r
255         int GroupIndex)\r
256 {\r
257 \r
258         GroupsListCtrlPtr = GroupsListCtrl;\r
259         GroupsListPtr = GroupsList;\r
260         AccName = AccountName;\r
261         GroupsListIndex = GroupIndex;\r
262 \r
263 }\r
264 \r
265 void frmContactEditorGroup::SetEditorMode(bool EditMode, XABViewMode XVMIn)\r
266 {\r
267 \r
268         EditorMode = EditMode;\r
269         XVMData = XVMIn;\r
270 \r
271         btnAction->SetLabel(_("Add"));\r
272         this->SetTitle(_("Add Member(s)"));\r
273 \r
274 }\r
275 \r
276 void frmContactEditorGroup::CloseWindow( wxCommandEvent& event )\r
277 {\r
278         this->Close();\r
279 }\r
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