2 #include <wx/mstream.h>
4 #include "frmImportContacts.h"
5 #include "import-struct.h"
6 #include "../common/preferences.h"
7 #include "../bitmaps.h"
8 #include "../vcard/vcard.h"
9 #include "../common/dirs.h"
11 frmImportContacts::frmImportContacts( wxWindow* parent )
13 frmImportContactsADT( parent )
16 // Setup the account selection control.
18 AccControl->SetPopupMaxHeight(175);
19 AccControl->SetPopupControl(treAccounts);
21 szrAccount->Insert(1, AccControl, 1, wxEXPAND, 5);
24 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
25 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
26 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
28 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
29 wxBitmap AccInet(icons_accinet_png, -1);
31 wxIAccInet.CopyFromBitmap(AccInet);
33 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
34 wxBitmap AccNIcon(icons_acclocal_png, -1);
36 wxIAccNIcon.CopyFromBitmap(AccNIcon);
38 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
39 wxBitmap AccGrp(icons_accgroup_png, -1);
41 wxIAccGrp.CopyFromBitmap(AccGrp);
43 AccountID = AccImgList->Add(wxIAccNIcon);
44 AccountNetID = AccImgList->Add(wxIAccInet);
45 AccountGrpID = AccImgList->Add(wxIAccGrp);
47 treAccounts->AssignImageList(AccImgList);
49 // Load the preferences.
51 wxString preffilename = GetUserPrefDir();
53 XABPreferences preferences(preffilename);
55 // Setup the main window position (if needed).
57 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
58 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
60 if (SaveWindowPos == TRUE){
62 this->SetSize(preferences.GetMainWindowData());
66 treAccounts->DeleteAllItems();
68 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"));
71 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
72 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
78 wxString AccDirFullSfx;
82 wxTreeItemId AccountTreeId;
83 wxTreeItemId GroupTreeId;
85 for (int i = 0; i < preferences.accounts.GetCount(); i++){
87 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
88 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
94 AccDir = preferences.accounts.GetAccountDirectory(i);
95 AccDirFull = preferences.accounts.GetAccountDirectory(i);
97 AccDirFull.Append(wxT("."));
98 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
99 AccDirFullSfx.LowerCase();
100 AccDirFullSfx.Trim();
101 AccDirFull.Append(AccDirFullSfx);
102 AccName = preferences.accounts.GetAccountName(i);
104 AccType = preferences.accounts.GetAccountType(i);
106 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
107 AccountAccTypeList.insert(std::make_pair(i, AccType));
109 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
110 preferences.accounts.GetAccountType(i) == wxT("carddav")){
112 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
116 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
120 // Clearup for next account.
124 AccDirFullSfx.clear();
132 frmImportContacts::~frmImportContacts()
144 void frmImportContacts::GetResult()
149 void frmImportContacts::GetContacts()
154 void frmImportContacts::CloseWindow( wxCommandEvent& event )
159 void frmImportContacts::ImportContacts( wxCommandEvent& event )
164 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
167 // Go through the list and setup each contact for the list.
171 for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
172 iter != ContactDataInc->end(); iter++){
174 ImportDataContact *Moo = &iter->second;
177 ContactLoad.LoadString(Moo->ContactData);
179 // Alter the data on this. (FN instead of Name?)
181 wxString ContactName = ContactLoad.Get(wxT("FN"));
182 iter->second.FriendlyName = ContactName;
184 lstContacts->InsertItems(1, &ContactName, Seek);
190 for (int i = 0; i < lstContacts->GetCount(); i++){
192 lstContacts->Check(i, TRUE);
198 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
203 for (std::map<int, ImportDataContact>::iterator DataIter = ContactDataInc->begin();
204 DataIter != ContactDataInc->end(); ++DataIter){
206 if (lstContacts->IsChecked(ItemIndex) == FALSE){
208 DataIter->second.ContactSelected = FALSE;
218 wxString frmImportContacts::GetAccount()
221 wxString preffilename = GetUserPrefDir();
223 XABPreferences preferences(preffilename);
225 wxString AccountName;
227 //XABPrefAccounts prefaccounts;
229 wxTreeItemIdValue cookie;
230 wxTreeItemId next = treAccounts->GetRootItem();
232 wxTreeItemId selectedChild = treAccounts->GetSelection();
233 wxTreeItemId nextChild;
235 for (int i = 0; i < preferences.accounts.GetCount(); i++){
238 nextChild = treAccounts->GetFirstChild(next, cookie);
240 nextChild = treAccounts->GetNextSibling(nextChild);
243 if (nextChild == selectedChild){
245 std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
247 AccountName = AccNameIter->second;
258 wxString frmImportContacts::GetAccountType()
261 wxString preffilename = GetUserPrefDir();
263 XABPreferences preferences(preffilename);
265 wxString AccountType;
267 //XABPrefAccounts prefaccounts;
269 wxTreeItemIdValue cookie;
270 wxTreeItemId next = treAccounts->GetRootItem();
272 wxTreeItemId selectedChild = treAccounts->GetSelection();
273 wxTreeItemId nextChild;
275 for (int i = 0; i < preferences.accounts.GetCount(); i++){
278 nextChild = treAccounts->GetFirstChild(next, cookie);
280 nextChild = treAccounts->GetNextSibling(nextChild);
283 if (nextChild == selectedChild){
285 std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
287 AccountType = AccTypeIter->second;