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