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