Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license to the C++ source and header files in the import directory.
[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                 
108                 continue;
109                 
110         }
111     
112         AccDir = preferences.accounts.GetAccountDirectory(i);
113         AccDirFull = preferences.accounts.GetAccountDirectory(i);
114         AccDirFull.Trim();
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);
121         AccName.Trim();
122         AccType = preferences.accounts.GetAccountType(i);
123         AccType.Trim();
124         AccountAccDirList.insert(std::make_pair(i, AccDirFull));
125         AccountAccTypeList.insert(std::make_pair(i, AccType));
126         
127         if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
128         preferences.accounts.GetAccountType(i) == wxT("carddav")){
129         
130                 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
131         
132         } else {
133                 
134                 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
135         
136         }
137         
138         // Clearup for next account.
139         
140         AccDir.clear();
141         AccDirFull.clear();
142         AccDirFullSfx.clear();
143         AccDirFinal.clear();
144         AccName.clear();
145         
146     }
147     
148     DialogResult = FALSE;
152 frmImportContacts::~frmImportContacts()
154         
155         /*delete AccControl;
156         AccControl = NULL;
157         delete treAccounts;
158         treAccounts = NULL;
159         delete AccImgList;
160         AccImgList = NULL;*/
161         
164 void frmImportContacts::GetResult()
169 void frmImportContacts::GetContacts()
174 void frmImportContacts::CloseWindow( wxCommandEvent& event )
176         DialogResult = FALSE;
177         this->Close();
180 void frmImportContacts::ImportContacts( wxCommandEvent& event )
182         DialogResult = TRUE;
183         this->Close();
186 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
188          
189          // Go through the list and setup each contact for the list.
190          
191          int Seek = 0;
192          
193          for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
194                 iter != ContactDataInc->end(); iter++){
196                 ImportDataContact *Moo = &iter->second;
197          
198                 vCard ContactLoad;
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);
207          
208                 Seek++;
209          
210          }
212         for (int i = 0; i < lstContacts->GetCount(); i++){
213         
214                 lstContacts->Check(i, TRUE);
215         
216         }
217          
220 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
222         
223         int ItemIndex = 0;
224                 
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;
232                 }
233                 
234                 ItemIndex++;
235         
236         }
240 wxString frmImportContacts::GetAccount()
243         wxString preffilename = GetUserPrefDir();
245         XABPreferences preferences(preffilename);
247         wxString AccountName;
248         
249         //XABPrefAccounts prefaccounts;
250         
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++){
259                 if (!nextChild){
260                         nextChild = treAccounts->GetFirstChild(next, cookie);
261                 } else {
262                         nextChild = treAccounts->GetNextSibling(nextChild);
263                 }
264                 
265                 if (nextChild == selectedChild){
266         
267                         std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
268                         
269                         AccountName = AccNameIter->second;
270         
271                 }
272         
274         }
275         
276         return AccountName;
280 wxString frmImportContacts::GetAccountType()
283         wxString preffilename = GetUserPrefDir();
285         XABPreferences preferences(preffilename);
287         wxString AccountType;
288         
289         //XABPrefAccounts prefaccounts;
290         
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++){
299                 if (!nextChild){
300                         nextChild = treAccounts->GetFirstChild(next, cookie);
301                 } else {
302                         nextChild = treAccounts->GetNextSibling(nextChild);
303                 }
304                 
305                 if (nextChild == selectedChild){
306         
307                         std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
308                         
309                         AccountType = AccTypeIter->second;
310         
311                 }
312         
314         }
315         
316         return AccountType;
320 bool frmImportContacts::GetDialogResult(){
322         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