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