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