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     }
132 frmImportContacts::~frmImportContacts()
134         
135         /*delete AccControl;
136         AccControl = NULL;
137         delete treAccounts;
138         treAccounts = NULL;
139         delete AccImgList;
140         AccImgList = NULL;*/
141         
144 void frmImportContacts::GetResult()
149 void frmImportContacts::GetContacts()
154 void frmImportContacts::CloseWindow( wxCommandEvent& event )
156         this->Close();
159 void frmImportContacts::ImportContacts( wxCommandEvent& event )
161         this->Close();
164 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
166          
167          // Go through the list and setup each contact for the list.
168          
169          int Seek = 0;
170          
171          for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
172                 iter != ContactDataInc->end(); iter++){
174                 ImportDataContact *Moo = &iter->second;
175          
176                 vCard ContactLoad;
177                 ContactLoad.LoadString(Moo->ContactData);
179                 // Alter the data on this. (FN instead of Name?)
181                 wxString ContactName = ContactLoad.Get(wxT("FN"));
182                 iter->second.FriendlyName = ContactName;
184                 lstContacts->InsertItems(1, &ContactName, Seek);
185          
186                 Seek++;
187          
188          }
190         for (int i = 0; i < lstContacts->GetCount(); i++){
191         
192                 lstContacts->Check(i, TRUE);
193         
194         }
195          
198 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
200         
201         int ItemIndex = 0;
202                 
203         for (std::map<int, ImportDataContact>::iterator DataIter = ContactDataInc->begin(); 
204                 DataIter != ContactDataInc->end(); ++DataIter){
206                 if (lstContacts->IsChecked(ItemIndex) == FALSE){
208                         DataIter->second.ContactSelected = FALSE;
210                 }
211                 
212                 ItemIndex++;
213         
214         }
218 wxString frmImportContacts::GetAccount()
221         wxString preffilename = GetUserPrefDir();
223         XABPreferences preferences(preffilename);
225         wxString AccountName;
226         
227         //XABPrefAccounts prefaccounts;
228         
229         wxTreeItemIdValue cookie;
230         wxTreeItemId next = treAccounts->GetRootItem();
232         wxTreeItemId selectedChild = treAccounts->GetSelection();
233         wxTreeItemId nextChild;
235         for (int i = 0; i < preferences.accounts.GetCount(); i++){
237                 if (!nextChild){
238                         nextChild = treAccounts->GetFirstChild(next, cookie);
239                 } else {
240                         nextChild = treAccounts->GetNextSibling(nextChild);
241                 }
242                 
243                 if (nextChild == selectedChild){
244         
245                         std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
246                         
247                         AccountName = AccNameIter->second;
248         
249                 }
250         
252         }
253         
254         return AccountName;
258 wxString frmImportContacts::GetAccountType()
261         wxString preffilename = GetUserPrefDir();
263         XABPreferences preferences(preffilename);
265         wxString AccountType;
266         
267         //XABPrefAccounts prefaccounts;
268         
269         wxTreeItemIdValue cookie;
270         wxTreeItemId next = treAccounts->GetRootItem();
272         wxTreeItemId selectedChild = treAccounts->GetSelection();
273         wxTreeItemId nextChild;
275         for (int i = 0; i < preferences.accounts.GetCount(); i++){
277                 if (!nextChild){
278                         nextChild = treAccounts->GetFirstChild(next, cookie);
279                 } else {
280                         nextChild = treAccounts->GetNextSibling(nextChild);
281                 }
282                 
283                 if (nextChild == selectedChild){
284         
285                         std::map<int, wxString>::iterator AccTypeIter = AccountAccTypeList.find(i);
286                         
287                         AccountType = AccTypeIter->second;
288         
289                 }
290         
292         }
293         
294         return AccountType;
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