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