Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented option to save photos, logos and sounds.
[xestiaab/.git] / source / contacteditor / frmContactEditor-Logo.cpp
1 // frmContactEditor-Logo.cpp - frmContactEditor Logo tab subroutines.
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 "frmContactEditor.h"
20 #include "frmContactEditorPicture.h"
21 #include "../common/base64.h"
23 void frmContactEditor::LoadLogo( wxListEvent& event )
24 {
25     
26     long longSelected = -1;
27     int intSelectedData = 0;
28     
29     if (!GetSelectedItem(lboLogos,
30                          &longSelected,
31                          &intSelectedData)){
32         return;
33     }
34     
35     std::string base64dec;
36     
37     std::map<int,std::string>::iterator initier;
38     
39     initier = LogosList.find(intSelectedData);
40     
41     base64dec = base64_decode(initier->second);
42     
43     
44     wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
45     wxImage photo;
46     //wxMemoryInputStream istream(base64dec, (size_t)base64dec.size());
47     
48     if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
49         
50         return;
51         
52     }
53     
54     
55     LogoImage = (wxBitmap)photo;
56     imgLogo->SetBitmap(LogoImage);
57     
58 }
60 void frmContactEditor::AddLogo( wxCommandEvent& event )
61 {
62     int intResult = 0;
63     
64     frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
65     frameCELogo->SetEditorMode(FALSE);
66     intResult = GetLastInt(&LogosList);
67     frameCELogo->SetupPointers(&LogosList,
68                                &LogosListAltID,
69                                &LogosListPID,
70                                &LogosListType,
71                                &LogosListPicEncType,
72                                &LogosListPictureType,
73                                &LogosListTokens,
74                                &LogosListMediatype,
75                                &LogosListPref,
76                                lboLogos,
77                                (intValueSeek));
78     frameCELogo->ShowModal();
79     delete frameCELogo;
80     frameCELogo = NULL;
81 }
83 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
84 {
85     long longSelected = -1;
86     int intSelectedData = 0;
87     
88     if (!GetSelectedItem(lboLogos,
89                          &longSelected,
90                          &intSelectedData)){
91         return;
92     }
93     
94     frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
95     frameCELogo->SetupPointers(&LogosList,
96                                &LogosListAltID,
97                                &LogosListPID,
98                                &LogosListType,
99                                &LogosListPicEncType,
100                                &LogosListPictureType,
101                                &LogosListTokens,
102                                &LogosListMediatype,
103                                &LogosListPref,
104                                lboLogos,
105                                intSelectedData);
106     frameCELogo->SetEditorMode(TRUE);
107     frameCELogo->ShowModal();
108     delete frameCELogo;
109     frameCELogo = NULL;
112 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
114     long longSelected = -1;
115     int intSelectedData = 0;
116     
117     if (!GetSelectedItem(lboLogos,
118                          &longSelected,
119                          &intSelectedData)){
120         return;
121     }
122     
123     lboLogos->DeleteItem(longSelected);
124     
125     DeleteMapData(intSelectedData,
126                   &LogosList, &LogosListAltID, &LogosListPID, &LogosListType,
127                   &LogosListPicEncType, &LogosListPictureType, &LogosListTokens,
128                   &LogosListMediatype, &LogosListPref);
129     
130     wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
131     wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
132     LogoImage = (wxBitmap)misc_emptyimage_png;
133     
134     imgLogo->SetBitmap(LogoImage);
137 void frmContactEditor::SaveLogo( wxCommandEvent &event )
139         
140         long longSelected = -1;
141         int intSelectedData = 0;
142     
143         if (!GetSelectedItem(lboLogos,
144                          &longSelected,
145                          &intSelectedData)){
146                 
147                 return;
148                 
149         }
150         
151         wxString FileTypes;
152         
153         wxString FinalFilename;
154         
155         std::map<int,std::string>::iterator initier;
156         std::map<int,wxString>::iterator logotypeiter;
157     
158         initier = LogosList.find(intSelectedData);
159         logotypeiter = LogosListPictureType.find(intSelectedData);
160         
161         if (logotypeiter->second == wxT("image/jpeg")){
162     
163                 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
164         
165         } else if (logotypeiter->second == wxT("image/png")){
167                 FileTypes.Append("PNG Image (*.png)|*.png");        
168         
169         } else if (logotypeiter->second == wxT("image/gif")){
170         
171                 FileTypes.Append("GIF Image (*.gif)|*.gif"); 
172         
173         } else {
175                 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
176                 return;
178         }
179         
180         // Open up the dialog to save the picture.
181         
182         wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
183                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
184         
185         if (ExportDlg.ShowModal() == wxID_CANCEL){
186         
187                 return;
188         
189         }
190         
191         // Write out the picture to the file.
192         
193         wxFile LogoFile;
194         
195         if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
196         
197                 std::string base64dec;
198                 
199                 initier = LogosList.find(intSelectedData);
200                 base64dec = base64_decode(initier->second);
201                 
202                 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
204                 LogoFile.Close();
205         
206         } else {
207         
208                 wxMessageBox(_("An error occured whilst saving the logo. Check that you have free space and permissions to write the picture at this location."), _("Logo save error"), wxOK, this);
209                 return;
210         
211         }
212         
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