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"));
90 wxString AccDirFullSfx;
94 wxTreeItemId AccountTreeId;
95 wxTreeItemId GroupTreeId;
97 for (int i = 0; i < preferences.accounts.GetCount(); i++){
99 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
100 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
105 AccDir = preferences.accounts.GetAccountDirectory(i);
106 AccDirFull = preferences.accounts.GetAccountDirectory(i);
108 AccDirFull.Append(wxT("."));
109 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
110 AccDirFullSfx.LowerCase();
111 AccDirFullSfx.Trim();
112 AccDirFull.Append(AccDirFullSfx);
113 AccName = preferences.accounts.GetAccountName(i);
115 AccType = preferences.accounts.GetAccountType(i);
117 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
118 AccountAccTypeList.insert(std::make_pair(i, AccType));
120 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
121 preferences.accounts.GetAccountType(i) == wxT("carddav")){
123 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
127 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
131 // Clearup for next account.
135 AccDirFullSfx.clear();
141 DialogResult = FALSE;
145 frmImportContacts::~frmImportContacts()
150 void frmImportContacts::GetResult()
155 void frmImportContacts::GetContacts()
160 void frmImportContacts::CloseWindow( wxCommandEvent& event )
162 DialogResult = FALSE;
166 void frmImportContacts::ImportContacts( wxCommandEvent& event )
172 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
175 // Go through the list and setup each contact for the list.
179 for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
180 iter != ContactDataInc->end(); iter++){
182 ImportDataContact *Moo = &iter->second;
185 ContactLoad.LoadString(Moo->ContactData);
187 // Alter the data on this. (FN instead of Name?)
189 wxString ContactName = ContactLoad.Get(wxT("FN"));
190 iter->second.FriendlyName = ContactName;
192 lstContacts->InsertItems(1, &ContactName, Seek);
198 for (int i = 0; i < lstContacts->GetCount(); i++){
200 lstContacts->Check(i, TRUE);
206 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
211 for (std::map<int, ImportDataContact>::iterator DataIter = ContactDataInc->begin();
212 DataIter != ContactDataInc->end(); ++DataIter){
214 if (lstContacts->IsChecked(ItemIndex) == FALSE){
216 DataIter->second.ContactSelected = FALSE;
226 wxString frmImportContacts::GetAccount()
229 wxString preffilename = GetUserPrefDir();
231 XABPreferences preferences(preffilename);
233 wxString AccountName;
235 wxTreeItemIdValue cookie;
236 wxTreeItemId next = treAccounts->GetRootItem();
238 wxTreeItemId selectedChild = treAccounts->GetSelection();
239 wxTreeItemId nextChild;
241 for (int i = 0; i < preferences.accounts.GetCount(); i++){
245 nextChild = treAccounts->GetFirstChild(next, cookie);
249 nextChild = treAccounts->GetNextSibling(nextChild);
253 if (nextChild == selectedChild){
255 std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
257 AccountName = AccNameIter->second;
267 wxString frmImportContacts::GetAccountType()
270 wxString preffilename = GetUserPrefDir();
272 XABPreferences preferences(preffilename);
274 wxString AccountType;
276 wxTreeItemIdValue cookie;
277 wxTreeItemId next = treAccounts->GetRootItem();
279 wxTreeItemId selectedChild = treAccounts->GetSelection();
280 wxTreeItemId nextChild;
282 for (int i = 0; i < preferences.accounts.GetCount(); i++){
286 nextChild = treAccounts->GetFirstChild(next, cookie);
290 nextChild = treAccounts->GetNextSibling(nextChild);
294 if (nextChild == selectedChild){
296 std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
298 AccountType = AccTypeIter->second;
309 bool frmImportContacts::GetDialogResult(){