Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Improved importing support.
[xestiaab/.git] / source / import / frmImportContacts.cpp
1 #include <wx/icon.h>
2 #include <wx/mstream.h>
4 #include "frmImportContacts.h"
5 #include "import-struct.h"
6 #include "../common/preferences.h"
7 #include "../bitmaps.h"
8 #include "../vcard/vcard.h"
9 #include "../common/dirs.h"
11 frmImportContacts::frmImportContacts( wxWindow* parent )
12 :
13 frmImportContactsADT( parent )
14 {
16         // Setup the account selection control.
17         
18         AccControl->SetPopupMaxHeight(175);
19         AccControl->SetPopupControl(treAccounts);
20         
21         szrAccount->Insert(1, AccControl, 1, wxEXPAND, 5);
22         szrAccount->Layout();
24         wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
25         wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
26         wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
28         wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
29         wxBitmap AccInet(icons_accinet_png, -1);
30         wxIcon wxIAccInet;
31         wxIAccInet.CopyFromBitmap(AccInet);
33         wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
34         wxBitmap AccNIcon(icons_acclocal_png, -1);
35         wxIcon wxIAccNIcon;
36         wxIAccNIcon.CopyFromBitmap(AccNIcon);
38         wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
39         wxBitmap AccGrp(icons_accgroup_png, -1);
40         wxIcon wxIAccGrp;
41         wxIAccGrp.CopyFromBitmap(AccGrp);
42         
43         AccountID = AccImgList->Add(wxIAccNIcon);
44         AccountNetID = AccImgList->Add(wxIAccInet);
45         AccountGrpID = AccImgList->Add(wxIAccGrp);
46         
47         treAccounts->AssignImageList(AccImgList);
49     // Load the preferences.
50     
51         wxString preffilename = GetUserPrefDir();
52     
53     XABPreferences preferences(preffilename);
55     // Setup the main window position (if needed).
56     
57     bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
58     bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
59     
60     if (SaveWindowPos == TRUE){
61     
62         this->SetSize(preferences.GetMainWindowData());
63     
64     }
65     
66     treAccounts->DeleteAllItems();
67     
68     wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"));
70     /*    
71     for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
72         treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
73     }
74     */
76     wxString AccDir;
77     wxString AccDirFull;
78     wxString AccDirFullSfx;
79     wxString AccName;
80     wxString AccType;
81     wxString AccDirFinal;
82     wxTreeItemId AccountTreeId;
83     wxTreeItemId GroupTreeId;
85     for (int i = 0; i < preferences.accounts.GetCount(); i++){
86     
87         if ((preferences.accounts.GetAccountType(i) == wxT("Local") || 
88                 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
89                 
90                 continue;
91                 
92         }
93     
94         AccDir = preferences.accounts.GetAccountDirectory(i);
95         AccDirFull = preferences.accounts.GetAccountDirectory(i);
96         AccDirFull.Trim();
97         AccDirFull.Append(wxT("."));
98         AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
99         AccDirFullSfx.LowerCase();
100         AccDirFullSfx.Trim();
101         AccDirFull.Append(AccDirFullSfx);
102         AccName = preferences.accounts.GetAccountName(i);
103         AccName.Trim();
104         AccType = preferences.accounts.GetAccountType(i);
105         AccType.Trim();
106         AccountAccDirList.insert(std::make_pair(i, AccDirFull));
107         AccountAccTypeList.insert(std::make_pair(i, AccType));
108         
109         if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
110         preferences.accounts.GetAccountType(i) == wxT("carddav")){
111         
112                 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
113         
114         } else {
115                 
116                 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
117         
118         }
119         
120         // Clearup for next account.
121         
122         AccDir.clear();
123         AccDirFull.clear();
124         AccDirFullSfx.clear();
125         AccDirFinal.clear();
126         AccName.clear();
127         
128     }
129     
130     DialogResult = FALSE;
134 frmImportContacts::~frmImportContacts()
136         
137         /*delete AccControl;
138         AccControl = NULL;
139         delete treAccounts;
140         treAccounts = NULL;
141         delete AccImgList;
142         AccImgList = NULL;*/
143         
146 void frmImportContacts::GetResult()
151 void frmImportContacts::GetContacts()
156 void frmImportContacts::CloseWindow( wxCommandEvent& event )
158         DialogResult = FALSE;
159         this->Close();
162 void frmImportContacts::ImportContacts( wxCommandEvent& event )
164         DialogResult = TRUE;
165         this->Close();
168 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
170          
171          // Go through the list and setup each contact for the list.
172          
173          int Seek = 0;
174          
175          for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
176                 iter != ContactDataInc->end(); iter++){
178                 ImportDataContact *Moo = &iter->second;
179          
180                 vCard ContactLoad;
181                 ContactLoad.LoadString(Moo->ContactData);
183                 // Alter the data on this. (FN instead of Name?)
185                 wxString ContactName = ContactLoad.Get(wxT("FN"));
186                 iter->second.FriendlyName = ContactName;
188                 lstContacts->InsertItems(1, &ContactName, Seek);
189          
190                 Seek++;
191          
192          }
194         for (int i = 0; i < lstContacts->GetCount(); i++){
195         
196                 lstContacts->Check(i, TRUE);
197         
198         }
199          
202 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
204         
205         int ItemIndex = 0;
206                 
207         for (std::map<int, ImportDataContact>::iterator DataIter = ContactDataInc->begin(); 
208                 DataIter != ContactDataInc->end(); ++DataIter){
210                 if (lstContacts->IsChecked(ItemIndex) == FALSE){
212                         DataIter->second.ContactSelected = FALSE;
214                 }
215                 
216                 ItemIndex++;
217         
218         }
222 wxString frmImportContacts::GetAccount()
225         wxString preffilename = GetUserPrefDir();
227         XABPreferences preferences(preffilename);
229         wxString AccountName;
230         
231         //XABPrefAccounts prefaccounts;
232         
233         wxTreeItemIdValue cookie;
234         wxTreeItemId next = treAccounts->GetRootItem();
236         wxTreeItemId selectedChild = treAccounts->GetSelection();
237         wxTreeItemId nextChild;
239         for (int i = 0; i < preferences.accounts.GetCount(); i++){
241                 if (!nextChild){
242                         nextChild = treAccounts->GetFirstChild(next, cookie);
243                 } else {
244                         nextChild = treAccounts->GetNextSibling(nextChild);
245                 }
246                 
247                 if (nextChild == selectedChild){
248         
249                         std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
250                         
251                         AccountName = AccNameIter->second;
252         
253                 }
254         
256         }
257         
258         return AccountName;
262 wxString frmImportContacts::GetAccountType()
265         wxString preffilename = GetUserPrefDir();
267         XABPreferences preferences(preffilename);
269         wxString AccountType;
270         
271         //XABPrefAccounts prefaccounts;
272         
273         wxTreeItemIdValue cookie;
274         wxTreeItemId next = treAccounts->GetRootItem();
276         wxTreeItemId selectedChild = treAccounts->GetSelection();
277         wxTreeItemId nextChild;
279         for (int i = 0; i < preferences.accounts.GetCount(); i++){
281                 if (!nextChild){
282                         nextChild = treAccounts->GetFirstChild(next, cookie);
283                 } else {
284                         nextChild = treAccounts->GetNextSibling(nextChild);
285                 }
286                 
287                 if (nextChild == selectedChild){
288         
289                         std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
290                         
291                         AccountType = AccTypeIter->second;
292         
293                 }
294         
296         }
297         
298         return AccountType;
302 bool frmImportContacts::GetDialogResult(){
304         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