1 #include "frmContactEditorGroups.h"
\r
4 #include "../vcard/vcard.h"
\r
5 #include "../common/dirs.h"
\r
7 frmContactEditorGroup::frmContactEditorGroup( wxWindow* parent )
\r
9 frmContactEditorGroupsADT( parent )
\r
14 void frmContactEditorGroup::FetchContacts( wxInitDialogEvent& event )
\r
17 // Load up the directory and get the list of contacts and UIDs.
\r
19 // Ignore contacts which have KIND:group set.
\r
21 wxString AccountDirFinal = GetAccountDir(AccName, FALSE);
\r
23 //wxString vcardfilenamewxs;
\r
24 wxString vCardFilename;
\r
25 wxString vCardFilenameFull;
\r
26 wxString vCardDataString;
\r
27 //wxStringTokenizer vcardfileline;
\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
35 wxDir vcardaccdir(AccountDirFinal);
\r
37 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
\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
47 vCardFilenameFull.Append(AccountDirFinal);
\r
48 vCardFilenameFull.Append(wxT("/"));
\r
49 vCardFilenameFull.Append(vCardFilename);
\r
51 Person.LoadFile(vCardFilenameFull);
\r
53 if (Person.MeetBaseSpecification()){
\r
55 wxString KindStatus = Person.Get(wxT("KIND"));
\r
57 if (KindStatus == wxT("group")){
\r
59 vCardFilename.Clear();
\r
60 vCardFilenameFull.Clear();
\r
61 vCardDataString.Clear();
\r
62 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
\r
67 wxString PersonName = Person.Get(wxT("N"));
\r
68 wxString PersonUID = Person.Get(wxT("UID"));
\r
69 wxString PersonFilename = vCardFilenameFull;
\r
71 ContactData PersonData;
\r
73 PersonData.ContactName = PersonName;
\r
74 PersonData.ContactUID = PersonUID;
\r
75 PersonData.ContactFilename = PersonFilename;
\r
77 //ContactsNames.insert(std::make_pair(PersonName, ContactIndex));
\r
78 //ContactsUIDs.insert(std::make_pair(ContactIndex, PersonUID));
\r
80 if (XVMData.SortMode == 1){
\r
82 // Split the name into sections.
\r
84 vCardDataString = Person.Get(wxT("N"));
\r
86 vCardName NameData = Person.GetName();
\r
88 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
\r
90 } else if (XVMData.SortMode == 2){
\r
92 // Split the name into sections.
\r
94 vCardName NameData = Person.GetName();
\r
96 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
\r
98 } else if (XVMData.SortMode == 3){
\r
100 // Check and make sure that the top most nickname is used.
\r
102 vCardDataString = Person.Get(wxT("NICKNAME"));
\r
104 if (vCardDataString.IsEmpty()){
\r
106 vCardDataString = wxT("(no nickname)");
\r
110 } else if (XVMData.SortMode == 4){
\r
112 vCardDataString = Person.Get(wxT("FN"));
\r
116 if (XVMData.AscendingMode == TRUE){
\r
117 vCardNamesAsc.insert(std::make_pair(vCardDataString, PersonData));
\r
119 vCardNamesDsc.insert(std::make_pair(vCardDataString, PersonData));
\r
130 vCardFilename.Clear();
\r
131 vCardFilenameFull.Clear();
\r
132 vCardDataString.Clear();
\r
133 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
\r
137 if (XVMData.AscendingMode == TRUE){
\r
139 for (std::map<wxString,ContactData>::iterator iter = vCardNamesAsc.begin();
\r
140 iter != vCardNamesAsc.end(); ++iter){
\r
142 chkContacts->InsertItems(1, &iter->first, 0);
\r
144 ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));
\r
153 ContactIndex = (int)(vCardNamesDsc.size() - 1);
\r
155 for (std::map<wxString,ContactData>::iterator iter = vCardNamesDsc.begin();
\r
156 iter != vCardNamesDsc.end(); ++iter){
\r
158 chkContacts->InsertItems(1, &iter->first, 0);
\r
160 ContactNamesData.insert(std::make_pair(ContactIndex, iter->second));
\r
170 void frmContactEditorGroup::ProcessData( wxCommandEvent& event )
\r
173 for (int i = 0; i < chkContacts->GetCount(); i++){
\r
175 if (chkContacts->IsChecked(i) == TRUE){
\r
177 // Get the UID and Name data from the struct
\r
180 wxString ContactName;
\r
181 wxString ContactUID;
\r
183 for (std::map<int, ContactData>::iterator iter = ContactNamesData.begin();
\r
184 iter != ContactNamesData.end(); ++iter){
\r
186 if (i == iter->first){
\r
188 ContactName = iter->second.ContactName;
\r
189 ContactUID = iter->second.ContactUID;
\r
195 wxListItem ItemData;
\r
197 ItemData.SetText(chkContacts->GetString(i));
\r
199 // Check if UID already exists before adding again. If already there
\r
200 // then don't bother adding again.
\r
202 bool ItemExists = FALSE;
\r
204 for (std::map<int, wxString>::iterator itemiter = GroupsListPtr->begin();
\r
205 itemiter != GroupsListPtr->end(); ++itemiter){
\r
207 if (itemiter->second == ContactUID){
\r
216 if (ItemExists == TRUE){
\r
222 GroupsListCtrlPtr->InsertItem(ItemData);
\r
223 GroupsListPtr->insert(std::make_pair(GroupsListIndex, ContactUID));
\r
233 void frmContactEditorGroup::SetupPointers(std::map<int, wxString> *GroupsList,
\r
234 wxListCtrl *GroupsListCtrl,
\r
235 wxString AccountName,
\r
239 GroupsListCtrlPtr = GroupsListCtrl;
\r
240 GroupsListPtr = GroupsList;
\r
241 AccName = AccountName;
\r
242 GroupsListIndex = GroupIndex;
\r
246 void frmContactEditorGroup::SetEditorMode(bool EditMode, XABViewMode XVMIn)
\r
249 EditorMode = EditMode;
\r
252 btnAction->SetLabel(_("Add"));
\r
253 this->SetTitle(_("Add Member(s)"));
\r
257 void frmContactEditorGroup::CloseWindow( wxCommandEvent& event )
\r