Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Indented code properly in contacteditor/frmImportContacts.cpp
[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         /*    
89         for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
90                 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
91         }
92         */
94         wxString AccDir;
95         wxString AccDirFull;
96         wxString AccDirFullSfx;
97         wxString AccName;
98         wxString AccType;
99         wxString AccDirFinal;
100         wxTreeItemId AccountTreeId;
101         wxTreeItemId GroupTreeId;
103         for (int i = 0; i < preferences.accounts.GetCount(); i++){
104     
105                 if ((preferences.accounts.GetAccountType(i) == wxT("Local") || 
106                         preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
107                         continue;
108                 
109                 }
110     
111                 AccDir = preferences.accounts.GetAccountDirectory(i);
112                 AccDirFull = preferences.accounts.GetAccountDirectory(i);
113                 AccDirFull.Trim();
114                 AccDirFull.Append(wxT("."));
115                 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
116                 AccDirFullSfx.LowerCase();
117                 AccDirFullSfx.Trim();
118                 AccDirFull.Append(AccDirFullSfx);
119                 AccName = preferences.accounts.GetAccountName(i);
120                 AccName.Trim();
121                 AccType = preferences.accounts.GetAccountType(i);
122                 AccType.Trim();
123                 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
124                 AccountAccTypeList.insert(std::make_pair(i, AccType));
125         
126                 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
127                         preferences.accounts.GetAccountType(i) == wxT("carddav")){
128         
129                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
130         
131                 } else {
132                 
133                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
134         
135                 }
136         
137                 // Clearup for next account.
138         
139                 AccDir.clear();
140                 AccDirFull.clear();
141                 AccDirFullSfx.clear();
142                 AccDirFinal.clear();
143                 AccName.clear();
144         
145         }
146     
147         DialogResult = FALSE;
151 frmImportContacts::~frmImportContacts()
153         
154         /*delete AccControl;
155         AccControl = NULL;
156         delete treAccounts;
157         treAccounts = NULL;
158         delete AccImgList;
159         AccImgList = NULL;*/
160         
163 void frmImportContacts::GetResult()
168 void frmImportContacts::GetContacts()
173 void frmImportContacts::CloseWindow( wxCommandEvent& event )
175         DialogResult = FALSE;
176         this->Close();
179 void frmImportContacts::ImportContacts( wxCommandEvent& event )
181         DialogResult = TRUE;
182         this->Close();
185 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
187          
188         // Go through the list and setup each contact for the list.
189          
190         int Seek = 0;
191          
192         for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
193                 iter != ContactDataInc->end(); iter++){
195                 ImportDataContact *Moo = &iter->second;
196          
197                 vCard ContactLoad;
198                 ContactLoad.LoadString(Moo->ContactData);
200                 // Alter the data on this. (FN instead of Name?)
202                 wxString ContactName = ContactLoad.Get(wxT("FN"));
203                 iter->second.FriendlyName = ContactName;
205                 lstContacts->InsertItems(1, &ContactName, Seek);
206          
207                 Seek++;
208          
209         }
211         for (int i = 0; i < lstContacts->GetCount(); i++){
212         
213                 lstContacts->Check(i, TRUE);
214         
215         }
216          
219 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
221         
222         int ItemIndex = 0;
223                 
224         for (std::map<int, ImportDataContact>::iterator DataIter = ContactDataInc->begin(); 
225                 DataIter != ContactDataInc->end(); ++DataIter){
227                 if (lstContacts->IsChecked(ItemIndex) == FALSE){
229                         DataIter->second.ContactSelected = FALSE;
231                 }
232                 
233                 ItemIndex++;
234         
235         }
239 wxString frmImportContacts::GetAccount()
242         wxString preffilename = GetUserPrefDir();
244         XABPreferences preferences(preffilename);
246         wxString AccountName;
247         
248         //XABPrefAccounts prefaccounts;
249         
250         wxTreeItemIdValue cookie;
251         wxTreeItemId next = treAccounts->GetRootItem();
252         
253         wxTreeItemId selectedChild = treAccounts->GetSelection();
254         wxTreeItemId nextChild;
256         for (int i = 0; i < preferences.accounts.GetCount(); i++){
258                 if (!nextChild){
259                         
260                         nextChild = treAccounts->GetFirstChild(next, cookie);
261                         
262                 } else {
263                         
264                         nextChild = treAccounts->GetNextSibling(nextChild);
265                         
266                 }
267                 
268                 if (nextChild == selectedChild){
269         
270                         std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
271                         
272                         AccountName = AccNameIter->second;
273         
274                 }
275         
276         }
277         
278         return AccountName;
282 wxString frmImportContacts::GetAccountType()
285         wxString preffilename = GetUserPrefDir();
287         XABPreferences preferences(preffilename);
289         wxString AccountType;
290         
291         //XABPrefAccounts prefaccounts;
292         
293         wxTreeItemIdValue cookie;
294         wxTreeItemId next = treAccounts->GetRootItem();
296         wxTreeItemId selectedChild = treAccounts->GetSelection();
297         wxTreeItemId nextChild;
299         for (int i = 0; i < preferences.accounts.GetCount(); i++){
301                 if (!nextChild){
302                         
303                         nextChild = treAccounts->GetFirstChild(next, cookie);
304                         
305                 } else {
306                         
307                         nextChild = treAccounts->GetNextSibling(nextChild);
308                         
309                 }
310                 
311                 if (nextChild == selectedChild){
312         
313                         std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
314                         
315                         AccountType = AccTypeIter->second;
316         
317                 }
318         
320         }
321         
322         return AccountType;
326 bool frmImportContacts::GetDialogResult(){
328         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