Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.08 / src / gtkmm / splash.cpp
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 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 <iostream>
37 #include <string>
38
39 #include <ETL/stringf>
40
41 #include <gtkmm/image.h>
42 #include <gtkmm/label.h>
43 #include <gtkmm/frame.h>
44 #include <gtkmm/fixed.h>
45
46 #include <synfig/general.h>
47
48 #include "splash.h"
49 #include "app.h"
50
51 #include "general.h"
52
53 #endif
54
55 using namespace std;
56 using namespace etl;
57 using namespace studio;
58
59 /* === M A C R O S ========================================================= */
60
61 #ifndef VERSION
62 #define VERSION "unknown"
63 #define PACKAGE "synfigstudio"
64 #endif
65
66 #ifdef WIN32
67 #       ifdef IMAGE_DIR
68 #               undef IMAGE_DIR
69 #               define IMAGE_DIR "share\\pixmaps"
70 #       endif
71 #endif
72
73 #ifndef IMAGE_DIR
74 #       define IMAGE_DIR "/usr/local/share/pixmaps"
75 #endif
76
77 #ifndef IMAGE_EXT
78 #       define IMAGE_EXT        "png"
79 #endif
80
81 /* === G L O B A L S ======================================================= */
82
83 /* === P R O C E D U R E S ================================================= */
84
85 class studio::SplashProgress : public synfig::ProgressCallback
86 {
87         Splash &splash;
88
89 public:
90
91         SplashProgress(Splash &splash):splash(splash) { }
92
93         virtual bool task(const std::string &task)
94         {
95                 if(splash.tasklabel)
96                 {
97                         splash.tasklabel->set_label(task);
98                         splash.tasklabel->show();
99                 }
100                 else
101                 {
102                         cerr<<task<<endl;
103                 }
104
105                 while(studio::App::events_pending())studio::App::iteration(false);
106                 return true;
107         }
108
109         virtual bool error(const std::string &task)
110         {
111                 if(splash.tasklabel)
112                 {
113                         splash.tasklabel->set_label(_("ERROR:")+task);
114                         splash.tasklabel->show();
115                 }
116                 else
117                 {
118                         cerr<<task<<endl;
119                 }
120
121                 while(studio::App::events_pending())studio::App::iteration(false);
122                 return true;
123         }
124
125         virtual bool warning(const std::string &task)
126         {
127                 if(splash.tasklabel)
128                 {
129                         splash.tasklabel->set_label(_("WARNING:")+task);
130                         splash.tasklabel->show();
131                 }
132                 else
133                 {
134                         cerr<<task<<endl;
135                 }
136
137                 while(studio::App::events_pending())studio::App::iteration(false);
138                 return true;
139         }
140
141         virtual bool amount_complete(int current, int total)
142         {
143                 if(splash.progressbar)
144                 {
145                         splash.progressbar->set_fraction((float)current/(float)total);
146                         splash.progressbar->show();
147                 }
148                 else
149                         cerr<<current<<'/'<<total<<endl;
150
151                 while(studio::App::events_pending())studio::App::iteration(false);
152                 return true;
153         }
154 }; // END of class SplashProgress
155
156 /* === M E T H O D S ======================================================= */
157
158 Splash::Splash():
159         Gtk::Window(getenv("SYNFIG_DISABLE_POPUP_WINDOWS") ? Gtk::WINDOW_TOPLEVEL : Gtk::WINDOW_POPUP)
160 {
161         std::string imagepath;
162 #ifdef WIN32
163         imagepath=App::get_base_path()+ETL_DIRECTORY_SEPARATOR+IMAGE_DIR;
164 #else
165         imagepath=IMAGE_DIR;
166 #endif
167         char* synfig_root=getenv("SYNFIG_ROOT");
168         if(synfig_root) {
169                 imagepath=synfig_root;
170                 imagepath+=ETL_DIRECTORY_SEPARATOR;
171                 imagepath+="share";
172                 imagepath+=ETL_DIRECTORY_SEPARATOR;
173                 imagepath+="pixmaps";
174         }
175         imagepath+=ETL_DIRECTORY_SEPARATOR;
176
177         // Create the splash image
178         Gtk::Image* splash_image = manage(new class Gtk::Image());
179         splash_image->set(imagepath+"splash_screen."IMAGE_EXT);
180         splash_image->set_alignment(0.5,0.5);
181         splash_image->set_padding(0,0);
182
183         // Get the image size
184         int image_w = splash_image->get_pixbuf()->get_width();
185         int image_h = splash_image->get_pixbuf()->get_height();
186
187         // Create the progress bar
188         progressbar = manage(new class Gtk::ProgressBar());
189         progressbar->set_size_request(image_w,24);
190
191         // Create the current task label
192         tasklabel = manage(new class Gtk::Label());
193         tasklabel->set_size_request(image_w,24);
194         tasklabel->set_use_underline(false);
195
196         // Create the Gtk::Fixed container and put all of the widgets into it
197         Gtk::Fixed* fixed = manage(new class Gtk::Fixed());
198         fixed->put(*splash_image, 0, 0);
199         fixed->put(*progressbar, 0, image_h+24);
200         fixed->put(*tasklabel, 0, image_h);
201
202         // Create shadow around the outside of the window
203         Gtk::Frame* frame = manage(new class Gtk::Frame());
204         frame->set_shadow_type(Gtk::SHADOW_OUT);
205         frame->add(*fixed);
206
207         // Set up the parameters for this pop-up window
208         set_title("Synfig Studio "VERSION);
209         set_modal(false);
210         property_window_position().set_value(Gtk::WIN_POS_CENTER);
211         set_resizable(false);
212         set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
213         set_auto_startup_notification(false);
214         set_icon_from_file(imagepath+"synfig_icon."+IMAGE_EXT);
215         add(*frame);
216
217         // show everything off
218         splash_image->show();
219         fixed->show();
220         frame->show();
221
222         // Once the splash is shown, we want startup stuff to continue as normal
223         signal_map().connect(sigc::mem_fun(*this, &Splash::enable_startup_notification));
224
225         cb=new SplashProgress(*this);
226 }
227
228 Splash::~Splash()
229 {
230         delete cb;
231 }
232
233 synfig::ProgressCallback *
234 Splash::get_callback()
235 {
236         return cb;
237 }
238
239 void
240 Splash::enable_startup_notification(){
241         set_auto_startup_notification(true);
242 }