Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[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 AccDirFinal;
81     wxTreeItemId AccountTreeId;
82     wxTreeItemId GroupTreeId;
83     int intGroupID = 0;
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         AccountAccDirList.insert(std::make_pair(i, AccDirFull));
105         
106         if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
107         preferences.accounts.GetAccountType(i) == wxT("carddav")){
108         
109                 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
110         
111         } else {
112                 
113                 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
114         
115         }
116         
117         // Clearup for next account.
118         
119         AccDir.clear();
120         AccDirFull.clear();
121         AccDirFullSfx.clear();
122         AccDirFinal.clear();
123         AccName.clear();
124         
125     }
129 void frmImportContacts::GetResult()
134 void frmImportContacts::GetContacts()
139 void frmImportContacts::CloseWindow( wxCommandEvent& event )
141         this->Close();
144 void frmImportContacts::ImportContacts( wxCommandEvent& event )
146         this->Close();
149 void frmImportContacts::SetupList(std::map<int,ImportDataContact>* ContactDataInc)
151          
152          // Go through the list and setup each contact for the list.
153          
154          int Seek = 0;
155          
156          for (std::map<int,ImportDataContact>::iterator iter = ContactDataInc->begin();
157                 iter != ContactDataInc->end(); iter++){
159                 ImportDataContact *Moo = &iter->second;
160          
161                 vCard ContactLoad;
162                 ContactLoad.LoadString(Moo->ContactData);
164                 // Alter the data on this. (FN instead of Name?)
166                 wxString ContactName = ContactLoad.Get(wxT("FN"));
167                 iter->second.FriendlyName = ContactName;
169                 lstContacts->InsertItems(1, &ContactName, Seek);
170          
171                 Seek++;
172          
173          }
175         for (int i = 0; i < lstContacts->GetCount(); i++){
176         
177                 lstContacts->Check(i, TRUE);
178         
179         }
180          
183 void frmImportContacts::GetResults(std::map<int,ImportDataContact>* ContactDataInc)
185         
186         int ItemIndex = 0;
187                 
188         for (std::map<int, ImportDataContact>::iterator DataIter = ContactDataInc->begin(); 
189                 DataIter != ContactDataInc->end(); ++DataIter){
191                 if (lstContacts->IsChecked(ItemIndex) == FALSE){
193                         DataIter->second.ContactSelected = FALSE;
195                 }
196                 
197                 ItemIndex++;
198         
199         }
203 wxString frmImportContacts::GetAccount()
206         wxString preffilename = GetUserPrefDir();
208         XABPreferences preferences(preffilename);
210         wxString AccountName;
211         
212         //XABPrefAccounts prefaccounts;
213         
214         wxTreeItemIdValue cookie;
215         wxTreeItemId next = treAccounts->GetRootItem();
217         wxTreeItemId selectedChild = treAccounts->GetSelection();
218         wxTreeItemId nextChild;
220         for (int i = 0; i < preferences.accounts.GetCount(); i++){
222                 if (!nextChild){
223                         nextChild = treAccounts->GetFirstChild(next, cookie);
224                 } else {
225                         nextChild = treAccounts->GetNextSibling(nextChild);
226                 }
227                 
228                 if (nextChild == selectedChild){
229         
230                         std::map<int, wxString>::iterator AccNameIter = AccountAccDirList.find(i);
231                         
232                         AccountName = AccNameIter->second;
233         
234                 }
235         
237         }
238         
239         return AccountName;
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