1 #include "frmContactEditorGroups.h"
\r
4 #include "../vcard/vcard.h"
\r
5 #include "../common/dirs.h"
\r
6 #include "../frmMain.h"
\r
8 frmContactEditorGroup::frmContactEditorGroup( wxWindow* parent )
\r
10 frmContactEditorGroupsADT( parent )
\r
15 void frmContactEditorGroup::FetchContacts( wxInitDialogEvent& event )
\r
18 // Load up the directory and get the list of contacts and UIDs.
\r
20 // Ignore contacts which have KIND:group set.
\r
22 wxString AccountDirFinal = GetAccountDir(AccName, FALSE);
\r
24 //wxString vcardfilenamewxs;
\r
25 wxString vCardFilename;
\r
26 wxString vCardFilenameFull;
\r
27 wxString vCardDataString;
\r
28 //wxStringTokenizer vcardfileline;
\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
36 wxDir vcardaccdir(AccountDirFinal);
\r
38 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
\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
48 vCardFilenameFull.Append(AccountDirFinal);
\r
49 vCardFilenameFull.Append(wxT("/"));
\r
50 vCardFilenameFull.Append(vCardFilename);
\r
52 Person.LoadFile(vCardFilenameFull);
\r
54 if (Person.MeetBaseSpecification()){
\r
56 wxString KindStatus = Person.Get(wxT("KIND"));
\r
58 if (KindStatus == wxT("group")){
\r
60 vCardFilename.Clear();
\r
61 vCardFilenameFull.Clear();
\r
62 vCardDataString.Clear();
\r
63 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
\r
68 wxString PersonName = Person.Get(wxT("N"));
\r
69 wxString PersonUID = Person.Get(wxT("UID"));
\r
70 wxString PersonFilename = vCardFilenameFull;
\r
72 ContactData PersonData;
\r
74 PersonData.ContactName = PersonName;
\r
75 PersonData.ContactUID = PersonUID;
\r
76 PersonData.ContactFilename = PersonFilename;
\r
78 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));
\r
79 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));
\r
81 if (XVMData.SortMode == 1){
\r
83 // Split the name into sections.
\r
85 vCardDataString = Person.Get(wxT("N"));
\r
87 vCardName NameData = Person.GetName();
\r
89 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
\r
91 } else if (XVMData.SortMode == 2){
\r
93 // Split the name into sections.
\r
95 vCardName NameData = Person.GetName();
\r
97 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
\r
99 } else if (XVMData.SortMode == 3){
\r
101 // Check and make sure that the top most nickname is used.
\r
103 vCardDataString = Person.Get(wxT("NICKNAME"));
\r
105 if (vCardDataString.IsEmpty()){
\r
107 vCardDataString = wxT("(no nickname)");
\r
111 } else if (XVMData.SortMode == 4){
\r
113 vCardDataString = Person.Get(wxT("FN"));
\r
117 if (XVMData.AscendingMode == TRUE){
\r
118 vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonData));
\r
120 vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonData));
\r
131 vCardFilename.Clear();
\r
132 vCardFilenameFull.Clear();
\r
133 vCardDataString.Clear();
\r
134 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
\r
138 if (XVMData.AscendingMode == TRUE){
\r
140 for (std::map<wxString,ContactData>::iterator iter = vCardNamesAsc.begin();
\r
141 iter != vCardNamesAsc.end(); ++iter){
\r
143 chkContacts->InsertItems(1, &iter->first, 0);
\r
145 ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));
\r
154 ContactIndex = (int)(vCardNamesDsc.size() - 1);
\r
156 for (std::map<wxString,ContactData>::iterator iter = vCardNamesDsc.begin();
\r
157 iter != vCardNamesDsc.end(); ++iter){
\r
159 chkContacts->InsertItems(1, &iter->first, 0);
\r
161 ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));
\r
171 void frmContactEditorGroup::ProcessData( wxCommandEvent& event )
\r
174 for (int i = 0; i < chkContacts->GetCount(); i++){
\r
176 if (chkContacts->IsChecked(i) == TRUE){
\r
178 // Get the UID and Name data from the struct
\r
181 wxString ContactName;
\r
182 wxString ContactUID;
\r
184 for (std::map<int, ContactData>::iterator iter = ContactNamesData.begin();
\r
185 iter != ContactNamesData.end(); ++iter){
\r
187 if (i == iter->first){
\r
189 ContactName = iter->second.ContactName;
\r
190 ContactUID = iter->second.ContactUID;
\r
196 wxListItem ItemData;
\r
198 ItemData.SetText(chkContacts->GetString(i));
\r
200 // Check if UID already exists before adding again. If already there
\r
201 // then don't bother adding again.
\r
203 bool ItemExists = FALSE;
\r
205 for (std::map<int, wxString>::iterator itemiter = GroupsListPtr->begin();
\r
206 itemiter != GroupsListPtr->end(); ++itemiter){
\r
208 if (itemiter->second == ContactUID){
\r
217 if (ItemExists == TRUE){
\r
223 GroupsListCtrlPtr->InsertItem(ItemData);
\r
224 GroupsListPtr->insert(std::make_pair(GroupsListIndex, ContactUID));
\r
234 void frmContactEditorGroup::SetupPointers(std::map<int, wxString> *GroupsList,
\r
235 wxListCtrl *GroupsListCtrl,
\r
236 wxString AccountName,
\r
240 GroupsListCtrlPtr = GroupsListCtrl;
\r
241 GroupsListPtr = GroupsList;
\r
242 AccName = AccountName;
\r
243 GroupsListIndex = GroupIndex;
\r
247 void frmContactEditorGroup::SetEditorMode(bool EditMode, XABViewMode XVMIn)
\r
250 EditorMode = EditMode;
\r
253 btnAction->SetLabel(_("Add"));
\r
254 this->SetTitle(_("Add Member(s)"));
\r
258 void frmContactEditorGroup::CloseWindow( wxCommandEvent& event )
\r