Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorPicture.cpp
1 #include "frmContactEditorPicture.h"
3 #include <wx/wx.h>
4 #include <wx/tokenzr.h>
5 #include <wx/icon.h>
6 #include <wx/mstream.h>
7 #include <wx/fs_mem.h>
8 #include <SFML/Audio.hpp>
10 #include "../common/textprocessing.h"
11 #include "../common/base64.h"
12 #include "../common/mime.h"
15 frmContactEditorPicture::frmContactEditorPicture( wxWindow* parent )
16 :
17 frmContactEditorPictureADT( parent )
18 {
19         EditorMode = FALSE;
20         sliPriority->Disable();
21         
22         cmbType->Append(wxT(""));
23         cmbType->Append(_("Home"));
24         cmbType->Append(_("Work"));
25 }
27 void frmContactEditorPicture::EnablePriority( wxCommandEvent& event )
28 {
29         if (chkUsePref->IsChecked()){
30                 sliPriority->Enable();
31         } else {
32                 sliPriority->Disable();
33         }
34 }
36 void frmContactEditorPicture::ProcessData( wxCommandEvent& event )
37 {
38         long ListCtrlIndex;
39         
40         if (EditorMode == FALSE){
42                 // Load the file into memory.
43                 
44                 wxFile PictureFile;
45                 wxString wxSPictureFilename;
46                 wxString wxSPictureMIMEType;
47                 size_t len;
48                 std::string b64enc;             
49                 
50                 wxSPictureFilename = fipPicture->GetPath();
52 /*              
53 #if wxABI_VERSION < 20900
54                 if (AudioFile.Open(wxSAudioFilename.c_str(), wxT("rb"))){
55 #else
56                 if (AudioFile.Open(wxSAudioFilename, wxT("rb"))){
57 #endif
59 */
60                 if (PictureFile.Open(wxSPictureFilename, wxFile::read)){
61                         size_t flen;
62                         len = PictureFile.Length();
63                         
64                         unsigned char* PictureFileData = new unsigned char[len];
65                         flen = PictureFile.Read(PictureFileData, len);                  
66                         
67                         // Check to make sure it is an audio file.
68                         
69                         wxMemoryInputStream istream(PictureFileData, flen);
70                         wxImage photo;                  
71                         
72                         //wxBitmap (bigimgs_contactpersonicon48i, -1);
73                         
74                         //Get MIME data.
75                         
76                         /*const char *MIMEType;
77                         magic_t MagicCookie = magic_open(MAGIC_MIME);                   
78                         magic_setflags(MagicCookie, MAGIC_MIME_TYPE);
79                         
80                         if (!MagicCookie){
82                                 wxMessageBox(_("An error occured with the support library for getting the picture type."), _("Error opening picture file"), wxICON_ERROR);                      
83                                 return;
84                                 
85                         }
86                         
87                         if (magic_load(MagicCookie, NULL) != 0) {
88                         
89                                 wxMessageBox(_("An error occured whilst determining the picture type."), _("Error opening picture file"), wxICON_ERROR);
90                                 return;
91                         
92                         }
93                         
94                         MIMEType = magic_file(MagicCookie, wxSPictureFilename.mb_str());
95                         wxSPictureMIMEType = wxString::FromUTF8(MIMEType);
96                         magic_close(MagicCookie);*/
97                         
98                         wxSPictureMIMEType = GetMIME(wxSPictureFilename);
99                         
100                         if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
102                                 wxMessageBox(_("This file is in an picture format that is unsupported or is not a picture file."), _("Error opening picture file"), wxICON_ERROR);
103                                 return;                 
104                                                         
105                         
106                         }
107                         
108                         // Covert the file into base64.
109                 
110                         b64enc = base64_encode(PictureFileData, (int)len);                      
111                         
112                         delete[] PictureFileData;
113         
114                 } else {
115         
116                         wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
117         
118                         return;
119         
120                 }               
122                 PictureListPtr->insert(std::make_pair(PictureListIndex, b64enc));
124                 wxString strValue;              
125                 strValue.Clear();
126                 
127                 strValue = cmbType->GetString(cmbType->GetSelection());
129                 // Setup Picture Type.
131                 if (strValue == _("Home")) {
132                 
133                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("home")));
134                 
135                 } else if (strValue == _("Work")) {
136                 
137                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("work")));
138                 
139                 } else {
140                 
141                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("")));
142                 
143                 }
144                 
145                 // Setup Organisation Priority.
146                 
147                 if (chkUsePref->IsChecked()){
148                 
149                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, sliPriority->GetValue()));
150                 
151                 } else {
152                 
153                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, 0));
154                 
155                 }
156                 
157                 // Setup MIME Type.
158                 
159                 PictureListPictureTypePtr->insert(std::make_pair(PictureListIndex, wxSPictureMIMEType));
160                 
161                 // Setup encoding type.
162                 
163                 PictureListPicEncTypePtr->insert(std::make_pair(PictureListIndex, wxT("base64")));
164                 
165                 // Add to form.
166                 
167                 wxListItem coldata;
168                 
169                 coldata.SetId(PictureListIndex);
170                 coldata.SetData(PictureListIndex);
171                 coldata.SetText(_("Picture"));
172                 ListCtrlIndex = PictureListCtrlPtr->InsertItem(coldata);
173                 
174                 if (strValue == _("Home")) {
175                 
176                         PictureListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
177                 
178                 } else if (strValue == _("Work")) {
179                 
180                         PictureListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
181                 
182                 } else {
183                 
185                 
186                 }               
187                 
188                 if (chkUsePref->IsChecked()){
189                 
190                         PictureListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
191                 
192                 }
193                 
194                 this->Close();
195                 
196         } else if (EditorMode == TRUE) {
197         
198                 // Do not touch the audio file but update the settings
199                 // associated with the audio file.
200         
201                 long longSelected = -1;
202                 wxString strValue;      
203                 
204                 // Update Picture Type.
205                 
206                 PictureListTypePtr->erase(PictureListIndex);
207                 strValue = cmbType->GetString(cmbType->GetSelection());         
208                 
209                 if (strValue == _("Home")) {
210                 
211                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("home")));
212                 
213                 } else if (strValue == _("Work")) {
214                 
215                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("work")));
216                 
217                 }               
218                 
219                 // Update Category Priority.
220                 
221                 PictureListPrefPtr->erase(PictureListIndex);
222                 
223                 if (chkUsePref->IsChecked()){
224                 
225                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, sliPriority->GetValue()));
226                 
227                 } else {
228                 
229                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, 0));
230                 
231                 }
232                 
233                 // Update form.
234                 
235                 longSelected = PictureListCtrlPtr->GetNextItem(longSelected, 
236                         wxLIST_NEXT_ALL,
237                         wxLIST_STATE_SELECTED);
238                         
239                 if (longSelected == -1){
240                         return;
241                 }               
242                 
243                 PictureListCtrlPtr->SetItem(longSelected, 0, wxT("Picture"));
244                 PictureListCtrlPtr->SetItem(longSelected, 1, strValue);
245                 
246                 if (chkUsePref->IsChecked()){
247                 
248                         PictureListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
249                 
250                 } else {
251                 
252                         PictureListCtrlPtr->SetItem(longSelected, 2, wxT(""));
253                 
254                 }
255                 
256                 this->Close();  
257         
258         }
261 void frmContactEditorPicture::CloseWindow( wxCommandEvent& event )
263         this->Close();
266 void frmContactEditorPicture::SetEditorMode(bool EditMode)
268         // Set if the editor is adding or editing an address.
269         // FALSE = Add
270         // TRUE = Edit
271         
272         if (EditMode == FALSE){
273         
274                 EditorMode = FALSE;
275                 btnAction->SetLabel(_("Add"));
276                 this->SetTitle(_("Add Picture"));
277         
278         } else if (EditMode == TRUE){
279         
280                 EditorMode = TRUE;
281                 btnAction->SetLabel(_("Modify"));
282                 this->SetTitle(_("Modify Picture"));
283                 fipPicture->Disable();
284                 
285                 std::map<int,int>::iterator intiter;
286                 std::map<int,wxString>::iterator striter;               
287                 wxString strValue;
288                 
289                 // Load the data into the form. Get the website.
290                 
291                 striter = PictureListTypePtr->find(PictureListIndex);
292                  
293                 if (striter->first == PictureListIndex){
294                 
295                         strValue = striter->second;
296                 
297                 }
298                 
299                 if (strValue == wxT("home")){
300                 
301                         cmbType->SetSelection(1);
302                 
303                 } else if (strValue == wxT("work")){ 
304                 
305                         cmbType->SetSelection(2);
306                 
307                 } else {
308                 
309                         cmbType->SetSelection(0);
310                 
311                 }
312                 
313                 //strValue.Clear();
314                 
315                 // Get the website priority.
316                 
317                 intiter = PictureListPrefPtr->find(PictureListIndex);
318                 
319                 if (intiter->first == PictureListIndex && intiter->second > 0){
320                 
321                         sliPriority->SetValue(intiter->second);
322                         sliPriority->Enable();
323                         chkUsePref->SetValue(TRUE);
324                 
325                 }       
326                 
327         }
328                 
331 void frmContactEditorPicture::SetupPointers(std::map<int, std::string> *PictureList,                    
332         std::map<int, wxString> *PictureListAltID,
333         std::map<int, wxString> *PictureListPID,
334         std::map<int, wxString> *PictureListType,
335         std::map<int, wxString> *PictureListPicEncType, 
336         std::map<int, wxString> *PictureListPictureType,        
337         std::map<int, wxString> *PictureListTokens,
338         std::map<int, wxString> *PictureListMediatype,  
339         std::map<int, int> *PictureListPref,
340         wxListCtrl *PictureListCtrl,
341         int PictureIndex )
344         PictureListPtr = PictureList;
345         PictureListAltIDPtr = PictureListAltID;
346         PictureListPIDPtr = PictureListPID;
347         PictureListPicEncTypePtr = PictureListPicEncType;       
348         PictureListPictureTypePtr = PictureListPictureType;
349         PictureListTypePtr = PictureListType;
350         PictureListTokensPtr = PictureListTokens;
351         PictureListMediatypePtr = PictureListMediatype; 
352         PictureListPrefPtr = PictureListPref;
353         PictureListCtrlPtr = PictureListCtrl;
354         PictureListIndex = PictureIndex;
355         
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