Add actions (add to group, ,remove from group, export, un-export, set layer descripti...
[synfig.git] / synfig-studio / 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 (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 <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                 imagepath+=ETL_DIRECTORY_SEPARATOR;
175                 imagepath+="synfigstudio";
176         }
177         imagepath+=ETL_DIRECTORY_SEPARATOR;
178
179         // Create the splash image
180         Gtk::Image* splash_image = manage(new class Gtk::Image());
181         splash_image->set(imagepath+"splash_screen."IMAGE_EXT);
182         splash_image->set_alignment(0.5,0.5);
183         splash_image->set_padding(0,0);
184
185         // Get the image size
186         int image_w = 350; int image_h = 0;
187         Glib::RefPtr<Gdk::Pixbuf> pixbuf = splash_image->get_pixbuf();
188         if( pixbuf ){
189                 image_w = pixbuf->get_width();
190                 image_h = pixbuf->get_height();
191         }
192
193         // Create the progress bar
194         progressbar = manage(new class Gtk::ProgressBar());
195         progressbar->set_size_request(image_w,24);
196
197         // Create the current task label
198         tasklabel = manage(new class Gtk::Label());
199         tasklabel->set_size_request(image_w,24);
200         tasklabel->set_use_underline(false);
201
202         // Create the Gtk::Fixed container and put all of the widgets into it
203         Gtk::Fixed* fixed = manage(new class Gtk::Fixed());
204         if( pixbuf ) fixed->put(*splash_image, 0, 0);
205         fixed->put(*progressbar, 0, image_h+24);
206         fixed->put(*tasklabel, 0, image_h);
207
208         // Create shadow around the outside of the window
209         Gtk::Frame* frame = manage(new class Gtk::Frame());
210         frame->set_shadow_type(Gtk::SHADOW_OUT);
211         frame->add(*fixed);
212
213         // Set up the parameters for this pop-up window
214         set_title("Synfig Studio "VERSION);
215         set_modal(false);
216         property_window_position().set_value(Gtk::WIN_POS_CENTER);
217         set_resizable(false);
218         set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
219         set_auto_startup_notification(false);
220         try {
221                 set_icon_from_file(imagepath+"synfig_icon."+IMAGE_EXT);
222         } catch(...) {
223                 synfig::warning("Unable to open "+imagepath+"synfig_icon."+IMAGE_EXT);
224         }
225         add(*frame);
226
227         // show everything off
228         if( pixbuf ) splash_image->show();
229         fixed->show();
230         frame->show();
231
232         // Once the splash is shown, we want startup stuff to continue as normal
233         signal_map().connect(sigc::mem_fun(*this, &Splash::enable_startup_notification));
234
235         cb=new SplashProgress(*this);
236 }
237
238 Splash::~Splash()
239 {
240         delete cb;
241 }
242
243 synfig::ProgressCallback *
244 Splash::get_callback()
245 {
246         return cb;
247 }
248
249 void
250 Splash::enable_startup_notification(){
251         set_auto_startup_notification(true);
252 }