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