1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  RawTherapee 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
17  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 #include "splash.h"
20 
21 #include <glib/gstdio.h>
22 
23 #include "multilangmgr.h"
24 #include "rtimage.h"
25 
26 extern Glib::ustring creditsPath;
27 extern Glib::ustring licensePath;
28 extern Glib::ustring versionString;
29 
SplashImage()30 SplashImage::SplashImage () : surface(RTImage::createImgSurfFromFile("splash.png"))
31 {
32 }
33 
on_draw(const::Cairo::RefPtr<Cairo::Context> & cr)34 bool SplashImage::on_draw(const ::Cairo::RefPtr< Cairo::Context> &cr)
35 {
36 
37     cr->set_source(surface, 0., 0.);
38     cr->rectangle(0, 0, surface->get_width(), surface->get_height());
39     cr->fill();
40 
41     Cairo::FontOptions cfo;
42     cfo.set_antialias (Cairo::ANTIALIAS_SUBPIXEL);
43     Glib::RefPtr<Pango::Context> context = get_pango_context ();
44     context->set_cairo_font_options (cfo);
45     Pango::FontDescription fontd = context->get_font_description ();
46     fontd.set_weight (Pango::WEIGHT_LIGHT);
47     fontd.set_absolute_size (12 * Pango::SCALE);
48     context->set_font_description (fontd);
49 
50     int w, h;
51     Glib::ustring versionStr(versionString);
52 
53     version = create_pango_layout (versionStr);
54     version->set_text(versionStr);
55     version->get_pixel_size (w, h);
56     cr->set_source_rgb (0., 0., 0.);
57     cr->set_line_width(3.);
58     cr->set_line_join(Cairo::LINE_JOIN_ROUND);
59     cr->move_to (surface->get_width() - w - 32, surface->get_height() - h - 20);
60     version->add_to_cairo_context (cr);
61     cr->stroke_preserve();
62     cr->set_source_rgb (1., 1., 1.);
63     cr->set_line_width(0.5);
64     cr->stroke_preserve();
65     cr->fill();
66 
67     return true;
68 }
69 
get_request_mode_vfunc() const70 Gtk::SizeRequestMode SplashImage::get_request_mode_vfunc () const
71 {
72     return Gtk::SIZE_REQUEST_CONSTANT_SIZE;
73 }
74 
get_preferred_height_vfunc(int & minimum_height,int & natural_height) const75 void SplashImage::get_preferred_height_vfunc (int &minimum_height, int &natural_height) const
76 {
77     minimum_height = natural_height = surface ? surface->get_height() : 100 * RTScalable::getScale();
78 }
79 
get_preferred_width_vfunc(int & minimum_width,int & natural_width) const80 void SplashImage::get_preferred_width_vfunc (int &minimum_width, int &natural_width) const
81 {
82     minimum_width = natural_width = surface ? surface->get_width() : 100 * RTScalable::getScale();
83 }
84 
get_preferred_height_for_width_vfunc(int width,int & minimum_height,int & natural_height) const85 void SplashImage::get_preferred_height_for_width_vfunc (int width, int &minimum_height, int &natural_height) const
86 {
87     get_preferred_height_vfunc (minimum_height, natural_height);
88 }
89 
get_preferred_width_for_height_vfunc(int height,int & minimum_width,int & natural_width) const90 void SplashImage::get_preferred_width_for_height_vfunc (int height, int &minimum_width, int &natural_width) const
91 {
92     get_preferred_width_vfunc (minimum_width, natural_width);
93 }
94 
Splash(Gtk::Window & parent)95 Splash::Splash (Gtk::Window& parent) : Gtk::Dialog(M("GENERAL_ABOUT"), parent, true)
96 {
97 
98     releaseNotesSW = nullptr;
99 
100     nb = Gtk::manage (new Gtk::Notebook ());
101     nb->set_name ("AboutNotebook");
102     get_content_area()->pack_start (*nb);
103 
104     // Add close button to bottom of the notebook
105     Gtk::Button* closeButton = Gtk::manage (new Gtk::Button (M("GENERAL_CLOSE")));
106     closeButton->signal_clicked().connect( sigc::mem_fun(*this, &Splash::closePressed) );
107     get_action_area()->pack_start (*closeButton, Gtk::PACK_SHRINK, 0);
108 
109     Glib::RefPtr<Gtk::CssProvider> localCSS = Gtk::CssProvider::create();
110     localCSS->load_from_data ("textview { font-family: monospace; }");
111 
112     // Tab 1: the image
113     splashImage = Gtk::manage(new SplashImage ());
114     nb->append_page (*splashImage,  M("ABOUT_TAB_SPLASH"));
115     splashImage->show ();
116 
117     // Tab 2: the information about the current version
118     std::string buildFileName = Glib::build_filename (creditsPath, "AboutThisBuild.txt");
119 
120     if ( Glib::file_test(buildFileName, (Glib::FILE_TEST_EXISTS)) ) {
121         FILE *f = g_fopen (buildFileName.c_str (), "rt");
122 
123         if (f != nullptr) {
124             char* buffer = new char[1024];
125             std::ostringstream ostr;
126 
127             while (fgets (buffer, 1024, f)) {
128                 ostr << buffer;
129             }
130 
131             delete [] buffer;
132             fclose (f);
133 
134             Glib::RefPtr<Gtk::TextBuffer> textBuffer = Gtk::TextBuffer::create();
135             textBuffer->set_text((Glib::ustring)(ostr.str()));
136 
137             Gtk::ScrolledWindow *buildSW = Gtk::manage (new Gtk::ScrolledWindow());
138             Gtk::TextView *buildTV = Gtk::manage (new Gtk::TextView (textBuffer));
139             buildTV->get_style_context()->add_provider(localCSS, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
140             buildTV->set_editable(false);
141             buildTV->set_left_margin (10);
142             buildTV->set_right_margin (5);
143             buildSW->add(*buildTV);
144             nb->append_page (*buildSW, M("ABOUT_TAB_BUILD"));
145         }
146     }
147 
148     // Tab 3: the credits
149     std::string creditsFileName = Glib::build_filename (creditsPath, "AUTHORS.txt");
150 
151     if ( Glib::file_test(creditsFileName, (Glib::FILE_TEST_EXISTS)) ) {
152         FILE *f = g_fopen (creditsFileName.c_str (), "rt");
153 
154         if (f != nullptr) {
155             char* buffer = new char[1024];
156             std::ostringstream ostr;
157 
158             while (fgets (buffer, 1024, f)) {
159                 ostr << buffer;
160             }
161 
162             delete [] buffer;
163             fclose (f);
164 
165             Glib::RefPtr<Gtk::TextBuffer> textBuffer = Gtk::TextBuffer::create();
166             textBuffer->set_text((Glib::ustring)(ostr.str()));
167 
168             Gtk::ScrolledWindow *creditsSW = Gtk::manage (new Gtk::ScrolledWindow());
169             Gtk::TextView *creditsTV = Gtk::manage (new Gtk::TextView (textBuffer));
170             //creditsTV->get_style_context()->add_provider(localCSS, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
171             creditsTV->set_left_margin (10);
172             creditsTV->set_right_margin (5);
173             creditsTV->set_wrap_mode(Gtk::WRAP_WORD);
174             creditsTV->set_editable(false);
175             creditsSW->add(*creditsTV);
176             nb->append_page (*creditsSW, M("ABOUT_TAB_CREDITS"));
177         }
178     }
179 
180     // Tab 4: the license
181     std::string licenseFileName = Glib::build_filename (licensePath, "LICENSE.txt");
182 
183     if ( Glib::file_test(licenseFileName, (Glib::FILE_TEST_EXISTS)) ) {
184         FILE *f = g_fopen (licenseFileName.c_str (), "rt");
185 
186         if (f != nullptr) {
187             char* buffer = new char[1024];
188             std::ostringstream ostr;
189 
190             while (fgets (buffer, 1024, f)) {
191                 ostr << buffer;
192             }
193 
194             delete [] buffer;
195             fclose (f);
196 
197             Glib::RefPtr<Gtk::TextBuffer> textBuffer = Gtk::TextBuffer::create();
198             textBuffer->set_text((Glib::ustring)(ostr.str()));
199 
200             Gtk::ScrolledWindow *licenseSW = Gtk::manage (new Gtk::ScrolledWindow());
201             Gtk::TextView *licenseTV = Gtk::manage (new Gtk::TextView (textBuffer));
202             //licenseTV->get_style_context()->add_provider(localCSS, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
203 
204             // set monospace font to enhance readability of formatted text
205             licenseTV->set_left_margin (10);
206             licenseTV->set_right_margin (5);
207             licenseTV->set_editable(false);
208             licenseSW->add(*licenseTV);
209             nb->append_page (*licenseSW, M("ABOUT_TAB_LICENSE"));
210         }
211     }
212 
213     // Tab 5: the Release Notes
214     std::string releaseNotesFileName = Glib::build_filename (creditsPath, "RELEASE_NOTES.txt");
215 
216     if ( Glib::file_test(releaseNotesFileName, (Glib::FILE_TEST_EXISTS)) ) {
217         FILE *f = g_fopen (releaseNotesFileName.c_str (), "rt");
218 
219         if (f != nullptr) {
220             char* buffer = new char[1024];
221             std::ostringstream ostr;
222 
223             while (fgets (buffer, 1024, f)) {
224                 ostr << buffer;
225             }
226 
227             delete [] buffer;
228             fclose (f);
229 
230             Glib::RefPtr<Gtk::TextBuffer> textBuffer = Gtk::TextBuffer::create();
231             textBuffer->set_text((Glib::ustring)(ostr.str()));
232 
233             releaseNotesSW = Gtk::manage (new Gtk::ScrolledWindow());
234             Gtk::TextView *releaseNotesTV = Gtk::manage (new Gtk::TextView (textBuffer));
235 
236             releaseNotesTV->set_left_margin (10);
237             releaseNotesTV->set_right_margin (3);
238             releaseNotesTV->set_editable(false);
239             releaseNotesTV->set_wrap_mode(Gtk::WRAP_WORD);
240             releaseNotesSW->add(*releaseNotesTV);
241             nb->append_page (*releaseNotesSW, M("ABOUT_TAB_RELEASENOTES"));
242         }
243     }
244 
245 
246     set_position (Gtk::WIN_POS_CENTER);
247     //add_events(Gdk::BUTTON_RELEASE_MASK);
248     set_resizable (true);
249 
250     nb->set_current_page (0);
251 
252     show_all_children ();
253     set_keep_above (true);
254 }
255 
on_timer()256 bool Splash::on_timer ()
257 {
258 
259     hide ();
260     return false;
261 }
262 
263 /*
264  * removed as it seem to be too sensitive in some OS
265 bool Splash::on_button_release_event (GdkEventButton* event) {
266 
267     hide ();
268     return true;
269 }
270 */
271 
showReleaseNotes()272 void Splash::showReleaseNotes()
273 {
274     if (releaseNotesSW) {
275         nb->set_current_page(nb->page_num(*releaseNotesSW));
276     }
277 }
278 
closePressed()279 void Splash::closePressed()
280 {
281     hide();
282     close();
283 }
284