Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Capitalise Bitmaps and Tools directories
[xestiaab/.git] / source / import / frmImportContacts.cpp
1 // frmImportContacts.cpp - frmImportContacts form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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/>
19 #include <wx/icon.h>
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 )
30 :
31 frmImportContactsADT( parent )
32 {
34         // Setup the account selection control.
35         
36         AccControl->SetPopupMaxHeight(175);
37         AccControl->SetPopupControl(treAccounts);
38         
39         szrAccount->Insert(1, AccControl, 1, wxEXPAND, 5);
40         szrAccount->Layout();
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);
48         wxIcon wxIAccInet;
49         wxIAccInet.CopyFromBitmap(AccInet);
51         wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
52         wxBitmap AccNIcon(icons_acclocal_png, -1);
53         wxIcon wxIAccNIcon;
54         wxIAccNIcon.CopyFromBitmap(AccNIcon);
56         wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
57         wxBitmap AccGrp(icons_accgroup_png, -1);
58         wxIcon wxIAccGrp;
59         wxIAccGrp.CopyFromBitmap(AccGrp);
60         
61         AccountID = AccImgList->Add(wxIAccNIcon);
62         AccountNetID = AccImgList->Add(wxIAccInet);
63         AccountGrpID = AccImgList->Add(wxIAccGrp);
64         
65         treAccounts->AssignImageList(AccImgList);
67         // Load the preferences.
68     
69         wxString preffilename = GetUserPrefDir();
70     
71         XABPreferences preferences(preffilename);
73         // Setup the main window position (if needed).
74     
75         bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
76         bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
77     
78         if (SaveWindowPos == TRUE){
79     
80                 this->SetSize(preferences.GetMainWindowData());
81     
82         }
83     
84         treAccounts->DeleteAllItems();
85     
86         wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"));
88         wxString AccDir;
89         wxString AccDirFull;
90         wxString AccDirFullSfx;
91         wxString AccName;
92         wxString AccType;
93         wxString AccDirFinal;
94         wxTreeItemId AccountTreeId;
95         wxTreeItemId GroupTreeId;
97         for (int i = 0; i < preferences.accounts.GetCount(); i++){
98     
99                 if ((preferences.accounts.GetAccountType(i) == wxT("Local") || 
100                         preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
101                         continue;
102                 
103                 }
104     
105                 AccDir = preferences.accounts.GetAccountDirectory(i);
106                 AccDirFull = preferences.accounts.GetAccountDirectory(i);
107                 AccDirFull.Trim();
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);
114                 AccName.Trim();
115                 AccType = preferences.accounts.GetAccountType(i);
116                 AccType.Trim();
117                 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
118                 AccountAccTypeList.insert(std::make_pair(i, AccType));
119         
120                 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
121                         preferences.accounts.GetAccountType(i) == wxT("carddav")){
122         
123                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
124         
125                 } else {
126                 
127                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
128         
129                 }
130         
131                 // Clearup for next account.
132         
133                 AccDir.clear();
134                 AccDirFull.clear();
135                 AccDirFullSfx.clear();
136                 AccDirFinal.clear();
137                 AccName.clear();
138         
139         }
140     
141         DialogResult = FALSE;
145 frmImportContacts::~frmImportContacts()
147         
150 void frmImportContacts::GetResult()
155 void frmImportContacts::GetContacts()
160 void frmImportContacts::CloseWindow( wxCommandEvent& event )
162         DialogResult = FALSE;
163         this->Close();
166 void frmImportContacts::ImportContacts( wxCommandEvent& event )
168         DialogResult = TRUE;
169         this->Close();
172 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
174          
175         // Go through the list and setup each contact for the list.
176          
177         int Seek = 0;
178          
179         for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
180                 iter != ContactDataInc->end(); iter++){
182                 ImportDataContact *Moo = &iter->second;
183          
184                 vCard ContactLoad;
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);
193          
194                 Seek++;
195          
196         }
198         for (int i = 0; i < lstContacts->GetCount(); i++){
199         
200                 lstContacts->Check(i, TRUE);
201         
202         }
203          
206 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
208         
209         int ItemIndex = 0;
210                 
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;
218                 }
219                 
220                 ItemIndex++;
221         
222         }
226 wxString frmImportContacts::GetAccount()
229         wxString preffilename = GetUserPrefDir();
231         XABPreferences preferences(preffilename);
233         wxString AccountName;
234         
235         wxTreeItemIdValue cookie;
236         wxTreeItemId next = treAccounts->GetRootItem();
237         
238         wxTreeItemId selectedChild = treAccounts->GetSelection();
239         wxTreeItemId nextChild;
241         for (int i = 0; i < preferences.accounts.GetCount(); i++){
243                 if (!nextChild){
244                         
245                         nextChild = treAccounts->GetFirstChild(next, cookie);
246                         
247                 } else {
248                         
249                         nextChild = treAccounts->GetNextSibling(nextChild);
250                         
251                 }
252                 
253                 if (nextChild == selectedChild){
254         
255                         std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
256                         
257                         AccountName = AccNameIter->second;
258         
259                 }
260         
261         }
262         
263         return AccountName;
267 wxString frmImportContacts::GetAccountType()
270         wxString preffilename = GetUserPrefDir();
272         XABPreferences preferences(preffilename);
274         wxString AccountType;
275         
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++){
284                 if (!nextChild){
285                         
286                         nextChild = treAccounts->GetFirstChild(next, cookie);
287                         
288                 } else {
289                         
290                         nextChild = treAccounts->GetNextSibling(nextChild);
291                         
292                 }
293                 
294                 if (nextChild == selectedChild){
295         
296                         std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
297                         
298                         AccountType = AccTypeIter->second;
299         
300                 }
301         
303         }
304         
305         return AccountType;
309 bool frmImportContacts::GetDialogResult(){
311         return DialogResult;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy