Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Property idented 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         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                                 \r
137                                         vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonData));\r
138                                 \r
139                                 } else {\r
140                                 \r
141                                         vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonData));\r
142                                 \r
143                                 }\r
144                 \r
145                         } else {\r
146         \r
147                         }\r
148             \r
149                 }\r
150         \r
151                 vCardFilename.Clear();\r
152                 vCardFilenameFull.Clear();\r
153                 vCardDataString.Clear();\r
154                 ProcFiles = vcardaccdir.GetNext(&vCardFilename);\r
155         \r
156         }\r
157     \r
158         if (XVMData.AscendingMode == TRUE){\r
159              \r
160                 for (std::map<wxString,ContactData>::iterator iter = vCardNamesAsc.begin(); \r
161                         iter != vCardNamesAsc.end(); ++iter){\r
162 \r
163                         chkContacts->InsertItems(1, &iter->first, 0);\r
164         \r
165                         ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));            \r
166         \r
167                         ContactIndex++;\r
168                         \r
169                 }\r
170                 \r
171                 \r
172         } else {\r
173                 \r
174                 ContactIndex = (int)(vCardNamesDsc.size() - 1);\r
175                 \r
176                 for (std::map<wxString,ContactData>::iterator iter = vCardNamesDsc.begin();\r
177                         iter != vCardNamesDsc.end(); ++iter){\r
178 \r
179                         chkContacts->InsertItems(1, &iter->first, 0);\r
180 \r
181                         ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));\r
182                 \r
183                         ContactIndex--;\r
184 \r
185                 }\r
186         \r
187         }\r
188 \r
189 }\r
190 \r
191 void frmContactEditorGroup::ProcessData( wxCommandEvent& event )\r
192 {\r
193         \r
194         for (int i = 0; i < chkContacts->GetCount(); i++){\r
195         \r
196                 if (chkContacts->IsChecked(i) == TRUE){\r
197                 \r
198                         // Get the UID and Name data from the struct\r
199                         // via GetData.\r
200                         \r
201                         wxString ContactName;\r
202                         wxString ContactUID;\r
203                         \r
204                         for (std::map<int, ContactData>::iterator iter = ContactNamesData.begin(); \r
205                         iter != ContactNamesData.end(); ++iter){\r
206                         \r
207                                 if (i == iter->first){\r
208                                 \r
209                                         ContactName = iter->second.ContactName;\r
210                                         ContactUID = iter->second.ContactUID;\r
211                                                 \r
212                                 }\r
213                         \r
214                         }\r
215                         \r
216                         wxListItem ItemData;\r
217                         ItemData.SetId(0);\r
218                         ItemData.SetText(chkContacts->GetString(i));\r
219                         \r
220                         // Check if UID already exists before adding again. If already there\r
221                         // then don't bother adding again.\r
222                         \r
223                         bool ItemExists = FALSE;\r
224                         \r
225                         for (std::map<int, wxString>::iterator itemiter = GroupsListPtr->begin();\r
226                         itemiter != GroupsListPtr->end(); ++itemiter){\r
227                         \r
228                                 if (itemiter->second == ContactUID){\r
229                                 \r
230                                         ItemExists = TRUE;\r
231                                         break;\r
232                                 \r
233                                 }\r
234                         \r
235                         }\r
236                         \r
237                         if (ItemExists == TRUE){\r
238                         \r
239                                 continue;\r
240                         \r
241                         }\r
242                         \r
243                         GroupsListCtrlPtr->InsertItem(ItemData);\r
244                         GroupsListPtr->insert(std::make_pair(GroupsListIndex, ContactUID));\r
245                 \r
246                 }\r
247         \r
248         }\r
249         \r
250         this->Close();\r
251         \r
252 }\r
253 \r
254 void frmContactEditorGroup::SetupPointers(std::map<int, wxString> *GroupsList,\r
255         wxListCtrl *GroupsListCtrl, \r
256         wxString AccountName, \r
257         int GroupIndex)\r
258 {\r
259 \r
260         GroupsListCtrlPtr = GroupsListCtrl;\r
261         GroupsListPtr = GroupsList;\r
262         AccName = AccountName;\r
263         GroupsListIndex = GroupIndex;\r
264 \r
265 }\r
266 \r
267 void frmContactEditorGroup::SetEditorMode(bool EditMode, XABViewMode XVMIn)\r
268 {\r
269 \r
270         EditorMode = EditMode;\r
271         XVMData = XVMIn;\r
272 \r
273         btnAction->SetLabel(_("Add"));\r
274         this->SetTitle(_("Add Member(s)"));\r
275 \r
276 }\r
277 \r
278 void frmContactEditorGroup::CloseWindow( wxCommandEvent& event )\r
279 {\r
280         this->Close();\r
281 }\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