1 // frmImportContacts.cpp - frmImportContacts form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
20 #include <wx/mstream.h>
22 #include "frmImportContacts.h"
23 #include "import-struct.h"
24 #include "../common/preferences.h"
25 #include "../bitmaps.h"
26 #include "../vcard/vcard.h"
27 #include "../common/dirs.h"
29 frmImportContacts::frmImportContacts( wxWindow* parent )
31 frmImportContactsADT( parent )
34 // Setup the account selection control.
36 AccControl->SetPopupMaxHeight(175);
37 AccControl->SetPopupControl(treAccounts);
39 szrAccount->Insert(1, AccControl, 1, wxEXPAND, 5);
42 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
43 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
44 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
46 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
47 wxBitmap AccInet(icons_accinet_png, -1);
49 wxIAccInet.CopyFromBitmap(AccInet);
51 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
52 wxBitmap AccNIcon(icons_acclocal_png, -1);
54 wxIAccNIcon.CopyFromBitmap(AccNIcon);
56 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
57 wxBitmap AccGrp(icons_accgroup_png, -1);
59 wxIAccGrp.CopyFromBitmap(AccGrp);
61 AccountID = AccImgList->Add(wxIAccNIcon);
62 AccountNetID = AccImgList->Add(wxIAccInet);
63 AccountGrpID = AccImgList->Add(wxIAccGrp);
65 treAccounts->AssignImageList(AccImgList);
67 // Load the preferences.
69 wxString preffilename = GetUserPrefDir();
71 XABPreferences preferences(preffilename);
73 // Setup the main window position (if needed).
75 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
76 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
78 if (SaveWindowPos == TRUE){
80 this->SetSize(preferences.GetMainWindowData());
84 treAccounts->DeleteAllItems();
86 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"));
89 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
90 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
96 wxString AccDirFullSfx;
100 wxTreeItemId AccountTreeId;
101 wxTreeItemId GroupTreeId;
103 for (int i = 0; i < preferences.accounts.GetCount(); i++){
105 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
106 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
112 AccDir = preferences.accounts.GetAccountDirectory(i);
113 AccDirFull = preferences.accounts.GetAccountDirectory(i);
115 AccDirFull.Append(wxT("."));
116 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
117 AccDirFullSfx.LowerCase();
118 AccDirFullSfx.Trim();
119 AccDirFull.Append(AccDirFullSfx);
120 AccName = preferences.accounts.GetAccountName(i);
122 AccType = preferences.accounts.GetAccountType(i);
124 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
125 AccountAccTypeList.insert(std::make_pair(i, AccType));
127 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
128 preferences.accounts.GetAccountType(i) == wxT("carddav")){
130 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
134 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
138 // Clearup for next account.
142 AccDirFullSfx.clear();
148 DialogResult = FALSE;
152 frmImportContacts::~frmImportContacts()
164 void frmImportContacts::GetResult()
169 void frmImportContacts::GetContacts()
174 void frmImportContacts::CloseWindow( wxCommandEvent& event )
176 DialogResult = FALSE;
180 void frmImportContacts::ImportContacts( wxCommandEvent& event )
186 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
189 // Go through the list and setup each contact for the list.
193 for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
194 iter != ContactDataInc->end(); iter++){
196 ImportDataContact *Moo = &iter->second;
199 ContactLoad.LoadString(Moo->ContactData);
201 // Alter the data on this. (FN instead of Name?)
203 wxString ContactName = ContactLoad.Get(wxT("FN"));
204 iter->second.FriendlyName = ContactName;
206 lstContacts->InsertItems(1, &ContactName, Seek);
212 for (int i = 0; i < lstContacts->GetCount(); i++){
214 lstContacts->Check(i, TRUE);
220 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
225 for (std::map<int, ImportDataContact>::iterator DataIter = ContactDataInc->begin();
226 DataIter != ContactDataInc->end(); ++DataIter){
228 if (lstContacts->IsChecked(ItemIndex) == FALSE){
230 DataIter->second.ContactSelected = FALSE;
240 wxString frmImportContacts::GetAccount()
243 wxString preffilename = GetUserPrefDir();
245 XABPreferences preferences(preffilename);
247 wxString AccountName;
249 //XABPrefAccounts prefaccounts;
251 wxTreeItemIdValue cookie;
252 wxTreeItemId next = treAccounts->GetRootItem();
254 wxTreeItemId selectedChild = treAccounts->GetSelection();
255 wxTreeItemId nextChild;
257 for (int i = 0; i < preferences.accounts.GetCount(); i++){
260 nextChild = treAccounts->GetFirstChild(next, cookie);
262 nextChild = treAccounts->GetNextSibling(nextChild);
265 if (nextChild == selectedChild){
267 std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
269 AccountName = AccNameIter->second;
280 wxString frmImportContacts::GetAccountType()
283 wxString preffilename = GetUserPrefDir();
285 XABPreferences preferences(preffilename);
287 wxString AccountType;
289 //XABPrefAccounts prefaccounts;
291 wxTreeItemIdValue cookie;
292 wxTreeItemId next = treAccounts->GetRootItem();
294 wxTreeItemId selectedChild = treAccounts->GetSelection();
295 wxTreeItemId nextChild;
297 for (int i = 0; i < preferences.accounts.GetCount(); i++){
300 nextChild = treAccounts->GetFirstChild(next, cookie);
302 nextChild = treAccounts->GetNextSibling(nextChild);
305 if (nextChild == selectedChild){
307 std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
309 AccountType = AccTypeIter->second;
320 bool frmImportContacts::GetDialogResult(){