1 /* === S Y N F I G ========================================================= */
2 /*! \file splash.cpp
3 ** \brief writeme
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
10 ** Copyright (c) 2008 Paul Wise
11 **
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
16 **
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
21 ** \endlegal
22 **
23 ** === N O T E S ===========================================================
24 **
25 ** ========================================================================= */
26
27 /* === H E A D E R S ======================================================= */
28
29 #ifdef USING_PCH
30 # include "pch.h"
31 #else
32 #ifdef HAVE_CONFIG_H
33 # include <config.h>
34 #endif
35
36 #include <synfig/general.h>
37
38 #include <iostream>
39 #include <string>
40
41 #include <ETL/stringf>
42
43 #include <gtkmm/image.h>
44 #include <gtkmm/label.h>
45 #include <gtkmm/frame.h>
46 #include <gtkmm/fixed.h>
47 #include <gdkmm/rgba.h>
48
49 #include "splash.h"
50 #include "app.h"
51
52 #include <gui/localization.h>
53
54 #endif
55
56 using namespace std;
57 using namespace etl;
58 using namespace studio;
59
60 /* === M A C R O S ========================================================= */
61
62 #ifndef VERSION
63 #define VERSION "unknown"
64 #define PACKAGE "synfigstudio"
65 #endif
66
67 #ifdef _WIN32
68 # ifdef IMAGE_DIR
69 # undef IMAGE_DIR
70 # define IMAGE_DIR "share\\pixmaps"
71 # endif
72 #endif
73
74 #ifndef IMAGE_DIR
75 # define IMAGE_DIR "/usr/local/share/pixmaps"
76 #endif
77
78 #ifndef IMAGE_EXT
79 # define IMAGE_EXT "png"
80 #endif
81
82 /* === G L O B A L S ======================================================= */
83
84 /* === P R O C E D U R E S ================================================= */
85
86 class studio::SplashProgress : public synfig::ProgressCallback
87 {
88 Splash &splash;
89
90 public:
91
SplashProgress(Splash & splash)92 SplashProgress(Splash &splash):splash(splash) { }
93
task(const std::string & task)94 virtual bool task(const std::string &task)
95 {
96 if(splash.tasklabel)
97 {
98 splash.tasklabel->set_label(task);
99 splash.tasklabel->show();
100 }
101
102 synfig::info(task);
103
104 studio::App::process_all_events();
105 return true;
106 }
107
error(const std::string & task)108 virtual bool error(const std::string &task)
109 {
110 if(splash.tasklabel)
111 {
112 splash.tasklabel->set_label(_("ERROR:")+task);
113 splash.tasklabel->show();
114 }
115
116 synfig::error(task);
117
118 studio::App::process_all_events();
119 return true;
120 }
121
warning(const std::string & task)122 virtual bool warning(const std::string &task)
123 {
124 if(splash.tasklabel)
125 {
126 splash.tasklabel->set_label(_("WARNING:")+task);
127 splash.tasklabel->show();
128 }
129
130 synfig::warning(task);
131
132 studio::App::process_all_events();
133 return true;
134 }
135
amount_complete(int current,int total)136 virtual bool amount_complete(int current, int total)
137 {
138 if(splash.progressbar)
139 {
140 splash.progressbar->set_fraction((float)current/(float)total);
141 splash.progressbar->show();
142 }
143
144 studio::App::process_all_events();
145 return true;
146 }
147 }; // END of class SplashProgress
148
149 /* === M E T H O D S ======================================================= */
150
Splash()151 Splash::Splash():
152 Gtk::Window(Gtk::WINDOW_TOPLEVEL)
153 {
154 std::string imagepath;
155 #ifdef _WIN32
156 imagepath=App::get_base_path()+ETL_DIRECTORY_SEPARATOR+IMAGE_DIR;
157 #else
158 imagepath=IMAGE_DIR;
159 #endif
160 char* synfig_root=getenv("SYNFIG_ROOT");
161 if(synfig_root) {
162 imagepath=synfig_root;
163 imagepath+=ETL_DIRECTORY_SEPARATOR;
164 imagepath+="share";
165 imagepath+=ETL_DIRECTORY_SEPARATOR;
166 imagepath+="pixmaps";
167 imagepath+=ETL_DIRECTORY_SEPARATOR;
168 imagepath+="synfigstudio";
169 }
170 imagepath+=ETL_DIRECTORY_SEPARATOR;
171
172 // Create the splash image
173 Gtk::Image* splash_image = manage(new class Gtk::Image());
174 /* Dual-splash code:
175 srand(time(NULL));
176 const float ran = rand()/float(RAND_MAX);
177 int number = 1;
178 if(ran >0.499999)
179 number = 2;
180 //synfig::info("%s", strprintf("%d",number).c_str());
181 splash_image->set(imagepath+"splash_screen"+strprintf("%d",number)+"." IMAGE_EXT);
182 */
183 splash_image->set(imagepath+"splash_screen." IMAGE_EXT);
184 splash_image->set_alignment(0.5,0.5);
185 splash_image->set_padding(0,0);
186
187 // Get the image size
188 int image_w = 350; int image_h = 0;
189 Glib::RefPtr<Gdk::Pixbuf> pixbuf = splash_image->get_pixbuf();
190 if( pixbuf ){
191 image_w = pixbuf->get_width();
192 image_h = pixbuf->get_height();
193 }
194
195 // Create the progress bar
196 progressbar = manage(new class Gtk::ProgressBar());
197 progressbar->set_size_request(image_w,24);
198
199 // Create the current task label
200 tasklabel = manage(new class Gtk::Label());
201 tasklabel->set_size_request(image_w,24);
202 tasklabel->set_use_underline(false);
203
204 // Create the current task label
205 versionlabel = manage(new class Gtk::Label());
206 versionlabel->set_label("" VERSION);
207 versionlabel->set_size_request(image_w,24);
208 versionlabel->set_use_underline(false);
209 versionlabel->override_color(Gdk::RGBA("#FFFFFF"));
210 versionlabel->show();
211
212 // Create the Gtk::Fixed container and put all of the widgets into it
213 Gtk::Fixed* fixed = manage(new class Gtk::Fixed());
214 if( pixbuf ) fixed->put(*splash_image, 0, 0);
215 fixed->put(*progressbar, 0, image_h+24);
216 fixed->put(*tasklabel, 0, image_h);
217 fixed->put(*versionlabel, 0, image_h-24);
218
219 // Create shadow around the outside of the window
220 Gtk::Frame* frame = manage(new class Gtk::Frame());
221 frame->set_shadow_type(Gtk::SHADOW_OUT);
222 frame->add(*fixed);
223
224 // Set up the parameters for this pop-up window
225 set_title("Synfig Studio " VERSION);
226 set_modal(false);
227 property_window_position().set_value(Gtk::WIN_POS_CENTER);
228 set_resizable(false);
229 set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
230 set_auto_startup_notification(false);
231 try {
232 set_icon_from_file(imagepath+"synfig_icon."+IMAGE_EXT);
233 } catch(...) {
234 synfig::warning("Unable to open "+imagepath+"synfig_icon."+IMAGE_EXT);
235 }
236 add(*frame);
237
238 // show everything off
239 if( pixbuf ) splash_image->show();
240 fixed->show();
241 frame->show();
242
243 // Once the splash is shown, we want startup stuff to continue as normal
244 signal_map().connect(sigc::mem_fun(*this, &Splash::enable_startup_notification));
245
246 cb=new SplashProgress(*this);
247 }
248
~Splash()249 Splash::~Splash()
250 {
251 delete cb;
252 }
253
254 synfig::ProgressCallback *
get_callback()255 Splash::get_callback()
256 {
257 return cb;
258 }
259
260 void
enable_startup_notification()261 Splash::enable_startup_notification(){
262 set_auto_startup_notification(true);
263 }
264