Get rid of all references to the bootstrap script since it was removed
[synfig.git] / synfig-studio / trunk / 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 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 **
22 ** === N O T E S ===========================================================
23 **
24 ** ========================================================================= */
25
26 /* === H E A D E R S ======================================================= */
27
28 #ifdef USING_PCH
29 #       include "pch.h"
30 #else
31 #ifdef HAVE_CONFIG_H
32 #       include <config.h>
33 #endif
34
35 #include <iostream>
36 #include <string>
37
38 #include <ETL/stringf>
39
40 #include <gtkmm/image.h>
41 #include <gdkmm/pixbufloader.h>
42 #include <gtkmm/button.h>
43 #include <gtkmm/label.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 extern      const guint gtk_major_version;
83 extern      const guint gtk_minor_version;
84 extern      const guint gtk_micro_version;
85 extern      const guint gtk_binary_age;
86 extern      const guint gtk_interface_age;
87
88 /* === P R O C E D U R E S ================================================= */
89
90 class studio::SplashProgress : public synfig::ProgressCallback
91 {
92         Splash &splash;
93
94 public:
95
96         SplashProgress(Splash &splash):splash(splash) { }
97
98         virtual bool task(const std::string &task)
99         {
100                 if(splash.tasklabel)
101                 {
102                         splash.tasklabel->set_label(task);
103                         splash.tasklabel->show();
104                 }
105                 else
106                 {
107                         cerr<<task<<endl;
108                 }
109
110                 while(studio::App::events_pending())studio::App::iteration(false);
111                 return true;
112         }
113
114         virtual bool error(const std::string &task)
115         {
116                 if(splash.tasklabel)
117                 {
118                         splash.tasklabel->set_label(_("ERROR:")+task);
119                         splash.tasklabel->show();
120                 }
121                 else
122                 {
123                         cerr<<task<<endl;
124                 }
125
126                 while(studio::App::events_pending())studio::App::iteration(false);
127                 return true;
128         }
129
130         virtual bool warning(const std::string &task)
131         {
132                 if(splash.tasklabel)
133                 {
134                         splash.tasklabel->set_label(_("WARNING:")+task);
135                         splash.tasklabel->show();
136                 }
137                 else
138                 {
139                         cerr<<task<<endl;
140                 }
141
142                 while(studio::App::events_pending())studio::App::iteration(false);
143                 return true;
144         }
145
146         virtual bool amount_complete(int current, int total)
147         {
148                 if(splash.progressbar)
149                 {
150                         splash.progressbar->set_fraction((float)current/(float)total);
151                         splash.progressbar->show();
152                 }
153                 else
154                         cerr<<current<<'/'<<total<<endl;
155
156                 while(studio::App::events_pending())studio::App::iteration(false);
157                 return true;
158         }
159 }; // END of class SplashProgress
160
161 /* === M E T H O D S ======================================================= */
162
163 Splash::Splash():
164         Gtk::Window(getenv("SYNFIG_DISABLE_POPUP_WINDOWS") ? Gtk::WINDOW_TOPLEVEL : Gtk::WINDOW_POPUP),
165         can_self_destruct(true)
166 {
167         int image_w=300,image_h=350;
168
169         std::string imagepath;
170 #ifdef WIN32
171         imagepath=App::get_base_path()+ETL_DIRECTORY_SEPARATOR+IMAGE_DIR;
172 #else
173         imagepath=IMAGE_DIR;
174 #endif
175         char* synfig_root=getenv("SYNFIG_ROOT");
176         if(synfig_root) {
177                 imagepath=synfig_root;
178                 imagepath+=ETL_DIRECTORY_SEPARATOR;
179
180                 imagepath+="share/pixmaps";
181         }
182         imagepath+=ETL_DIRECTORY_SEPARATOR;
183
184
185         // Create the Logo
186         Gtk::Image *Logo = manage(new class Gtk::Image());
187         Logo->set(imagepath+"splash_screen."IMAGE_EXT);
188         Logo->set_size_request(image_w,image_h);
189         Logo->set_alignment(0.5,0.5);
190         Logo->set_padding(0,0);
191
192         // Create the Copyright Label
193         Gtk::Label *CopyrightLabel = manage(new class Gtk::Label(SYNFIG_COPYRIGHT));
194         CopyrightLabel->set_size_request(image_w,24);
195         CopyrightLabel->set_alignment(0.5,0.5);
196         CopyrightLabel->set_padding(0,0);
197         CopyrightLabel->set_justify(Gtk::JUSTIFY_CENTER);
198         CopyrightLabel->set_line_wrap(false);
199         CopyrightLabel->modify_fg(Gtk::STATE_NORMAL,Gdk::Color("black"));
200
201         /* Scale the text to fit */
202         int width = 0;
203         int height = 0;
204         float size=11;
205         Glib::RefPtr<Pango::Layout> l = CopyrightLabel->get_layout();
206         Pango::FontDescription fd = Pango::FontDescription("Sans, 11");
207         l->set_font_description(fd);
208         l->set_justify(Pango::ALIGN_CENTER);
209         fd.set_size(int(size*Pango::SCALE));
210         l->set_font_description(fd);
211         l->get_pixel_size(width,height);
212         while( width >= image_w-6 ){
213                 size-=0.5;
214                 fd.set_size((int)(size*Pango::SCALE));
215                 l->set_font_description(fd);
216                 l->get_pixel_size(width,height);
217         }
218         CopyrightLabel->modify_font(fd);
219
220         // Create the Version information label
221         Gtk::Label *VersionLabel = manage(new class Gtk::Label(_("Version")));
222         VersionLabel->set_size_request(image_w,80);
223         VersionLabel->set_flags(Gtk::CAN_FOCUS);
224         VersionLabel->set_alignment(0.5,0.5);
225         VersionLabel->set_padding(0,0);
226         VersionLabel->set_justify(Gtk::JUSTIFY_CENTER);
227         VersionLabel->set_line_wrap(false);
228         VersionLabel->modify_fg(Gtk::STATE_NORMAL,Gdk::Color("black"));
229
230         // Set the version label to contain the correct information
231         string ver;
232         ver+="Version "VERSION" ("__DATE__" "__TIME__")\n";
233         ver+="Using Synfig ";
234         ver+=synfig::get_version();
235         #ifdef __GNUC__
236                 ver+=strprintf(" and GNU G++ %d.%d.%d",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
237         #endif
238
239         ver+=strprintf("\nGtk+ %d.%d.%d",gtk_major_version,gtk_minor_version,gtk_micro_version);
240
241         #ifdef _DEBUG
242                 ver+="\nDEBUG BUILD";
243         #endif
244         VersionLabel->set_text(ver);
245
246         /* Scale the text to fit */
247         width = 0;
248         height = 0;
249         size=11;
250         l = VersionLabel->get_layout();
251         fd = Pango::FontDescription("Sans, 11");
252         l->set_font_description(fd);
253         l->set_justify(Pango::ALIGN_CENTER);
254         fd.set_size(int(size*Pango::SCALE));
255         l->set_font_description(fd);
256         l->get_pixel_size(width,height);
257         while( width >= image_w-6 ){
258                 size-=0.5;
259                 fd.set_size((int)(size*Pango::SCALE));
260                 l->set_font_description(fd);
261                 l->get_pixel_size(width,height);
262         }
263         VersionLabel->modify_font(fd);
264
265         // Create the image that will be used on the close button
266         Gtk::Image *image2 = manage(new class Gtk::Image(Gtk::StockID("gtk-close"), Gtk::IconSize(4)));
267         image2->set_alignment(0.5,0.5);
268         image2->set_padding(0,0);
269
270         // Create the close button, and attach the image to it
271         CloseButton = manage(new class Gtk::Button());
272         CloseButton->set_size_request(24,24);
273         CloseButton->set_flags(Gtk::CAN_FOCUS);
274         _tooltips.set_tip(*CloseButton, _("Close"), "");
275         CloseButton->set_relief(Gtk::RELIEF_NONE);
276         CloseButton->add(*image2);
277
278         // Create the progress bar
279         progressbar = manage(new class Gtk::ProgressBar());
280         progressbar->set_size_request(image_w,24);
281
282         // Create the current task label
283         tasklabel = manage(new class Gtk::Label());
284         tasklabel->set_size_request(image_w,24);
285         tasklabel->set_use_underline(false);
286
287         // Create the Gtk::Fixed container and put all of the widgets into it
288         Gtk::Fixed *fixed1 = manage(new class Gtk::Fixed());
289         fixed1->put(*Logo, 0, 0);
290         fixed1->put(*CopyrightLabel, 0, image_h-25);
291         fixed1->put(*CloseButton, image_w-24, 0);
292         fixed1->put(*VersionLabel, 0, image_h-90);
293         fixed1->put(*progressbar, 0, image_h+24);
294         fixed1->put(*tasklabel, 0, image_h);
295
296         // Set up the parameters for this pop-up window
297         set_title("Synfig Studio "VERSION);
298         set_modal(false);
299         property_window_position().set_value(Gtk::WIN_POS_CENTER);
300         set_resizable(false);
301         add(*fixed1);
302
303         // show everything off
304         Logo->show();
305         CopyrightLabel->show();
306         image2->show();
307         CloseButton->show();
308         VersionLabel->show();
309         fixed1->show();
310
311         // Connect relevant signals
312         CloseButton->signal_clicked().connect(sigc::mem_fun(*this, &Splash::close));
313
314         cb=new SplashProgress(*this);
315 }
316
317 Splash::~Splash()
318 {
319         delete cb;
320 }
321
322 void Splash::close()
323 {
324         hide();
325         if(can_self_destruct)
326                 delete this;
327 }
328
329 void
330 Splash::set_can_self_destruct(bool x)
331 {
332         can_self_destruct=x;
333         if(x==true)
334                 CloseButton->show();
335         else
336                 CloseButton->hide();
337 }
338
339 synfig::ProgressCallback *
340 Splash::get_callback()
341 {
342         return cb;
343 }