Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Version 0.18 release
[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 vCardFilename;\r
46         wxString vCardFilenameFull;\r
47         wxString vCardDataString;\r
48         wxString lwxs;\r
49         wxString setname, setvalue;\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                                 if (XVMData.SortMode == 1){\r
97 \r
98                                         // Split the name into sections.\r
99                         \r
100                                         vCardDataString = Person.Get(wxT("N"));\r
101 \r
102                                         vCardName NameData = Person.GetName();\r
103                     \r
104                                         vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;\r
105                     \r
106                                 } else if (XVMData.SortMode == 2){\r
107                     \r
108                                         // Split the name into sections.\r
109                     \r
110                                         vCardName NameData = Person.GetName();    \r
111                     \r
112                                         vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;\r
113                     \r
114                                 } else if (XVMData.SortMode == 3){\r
115                     \r
116                                         // Check and make sure that the top most nickname is used.\r
117                     \r
118                                         vCardDataString = Person.Get(wxT("NICKNAME"));\r
119                     \r
120                                         if (vCardDataString.IsEmpty()){\r
121                         \r
122                                                 vCardDataString = wxT("(no nickname)");\r
123                         \r
124                                         }\r
125                     \r
126                                 } else if (XVMData.SortMode == 4){\r
127                     \r
128                                         vCardDataString = Person.Get(wxT("FN"));\r
129                     \r
130                                 }\r
131         \r
132                                 if (XVMData.AscendingMode == TRUE){\r
133                                 \r
134                                         vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonData));\r
135                                 \r
136                                 } else {\r
137                                 \r
138                                         vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonData));\r
139                                 \r
140                                 }\r
141                 \r
142                         } else {\r
143         \r
144                         }\r
145             \r
146                 }\r
147         \r
148                 vCardFilename.Clear();\r
149                 vCardFilenameFull.Clear();\r
150                 vCardDataString.Clear();\r
151                 ProcFiles = vcardaccdir.GetNext(&vCardFilename);\r
152         \r
153         }\r
154     \r
155         if (XVMData.AscendingMode == TRUE){\r
156              \r
157                 for (std::map<wxString,ContactData>::iterator iter = vCardNamesAsc.begin(); \r
158                         iter != vCardNamesAsc.end(); ++iter){\r
159 \r
160                         chkContacts->InsertItems(1, &iter->first, 0);\r
161         \r
162                         ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));            \r
163         \r
164                         ContactIndex++;\r
165                         \r
166                 }\r
167                 \r
168                 \r
169         } else {\r
170                 \r
171                 ContactIndex = (int)(vCardNamesDsc.size() - 1);\r
172                 \r
173                 for (std::map<wxString,ContactData>::iterator iter = vCardNamesDsc.begin();\r
174                         iter != vCardNamesDsc.end(); ++iter){\r
175 \r
176                         chkContacts->InsertItems(1, &iter->first, 0);\r
177 \r
178                         ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));\r
179                 \r
180                         ContactIndex--;\r
181 \r
182                 }\r
183         \r
184         }\r
185 \r
186 }\r
187 \r
188 void frmContactEditorGroup::ProcessData( wxCommandEvent& event )\r
189 {\r
190         \r
191         // Process action.\r
192         \r
193         for (int i = 0; i < chkContacts->GetCount(); i++){\r
194         \r
195                 if (chkContacts->IsChecked(i) == TRUE){\r
196                 \r
197                         // Get the UID and Name data from the struct\r
198                         // via GetData.\r
199                         \r
200                         wxString ContactName;\r
201                         wxString ContactUID;\r
202                         \r
203                         for (std::map<int, ContactData>::iterator iter = ContactNamesData.begin(); \r
204                         iter != ContactNamesData.end(); ++iter){\r
205                         \r
206                                 if (i == iter->first){\r
207                                 \r
208                                         ContactName = iter->second.ContactName;\r
209                                         ContactUID = iter->second.ContactUID;\r
210                                                 \r
211                                 }\r
212                         \r
213                         }\r
214                         \r
215                         wxListItem ItemData;\r
216                         ItemData.SetId(0);\r
217                         ItemData.SetText(chkContacts->GetString(i));\r
218                         \r
219                         // Check if UID already exists before adding again. If already there\r
220                         // then don't bother adding again.\r
221                         \r
222                         bool ItemExists = FALSE;\r
223                         \r
224                         for (std::map<int, wxString>::iterator itemiter = GroupsListPtr->begin();\r
225                         itemiter != GroupsListPtr->end(); ++itemiter){\r
226                         \r
227                                 if (itemiter->second == ContactUID){\r
228                                 \r
229                                         ItemExists = TRUE;\r
230                                         break;\r
231                                 \r
232                                 }\r
233                         \r
234                         }\r
235                         \r
236                         if (ItemExists == TRUE){\r
237                         \r
238                                 continue;\r
239                         \r
240                         }\r
241                         \r
242                         GroupsListCtrlPtr->InsertItem(ItemData);\r
243                         GroupsListPtr->insert(std::make_pair(GroupsListIndex, ContactUID));\r
244                 \r
245                 }\r
246         \r
247         }\r
248         \r
249         this->Close();\r
250         \r
251 }\r
252 \r
253 void frmContactEditorGroup::SetupPointers(std::map<int, wxString> *GroupsList,\r
254         wxListCtrl *GroupsListCtrl, \r
255         wxString AccountName, \r
256         int GroupIndex)\r
257 {\r
258 \r
259         // Setup the pointers.\r
260         \r
261         GroupsListCtrlPtr = GroupsListCtrl;\r
262         GroupsListPtr = GroupsList;\r
263         AccName = AccountName;\r
264         GroupsListIndex = GroupIndex;\r
265 \r
266 }\r
267 \r
268 void frmContactEditorGroup::SetEditorMode(bool EditMode, XABViewMode XVMIn)\r
269 {\r
270 \r
271         // Setup the editor mode.\r
272         \r
273         EditorMode = EditMode;\r
274         XVMData = XVMIn;\r
275 \r
276         btnAction->SetLabel(_("Add"));\r
277         this->SetTitle(_("Add Member(s)"));\r
278 \r
279 }\r
280 \r
281 void frmContactEditorGroup::CloseWindow( wxCommandEvent& event )\r
282 {\r
283         \r
284         // Close this window.\r
285         \r
286         this->Close();\r
287         \r
288 }\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