Enable $Id$ expansion.
[synfig.git] / synfig-studio / trunk / 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
197         // Create the Version information label
198         Gtk::Label *VersionLabel = manage(new class Gtk::Label("Version"));
199         VersionLabel->set_size_request(image_w,80);
200         VersionLabel->set_flags(Gtk::CAN_FOCUS);
201         VersionLabel->set_alignment(0.5,0.5);
202         VersionLabel->set_padding(0,0);
203         VersionLabel->set_justify(Gtk::JUSTIFY_CENTER);
204         VersionLabel->set_line_wrap(false);
205
206         // Set the version label to contain the correct information
207         string ver;
208         ver+="Version "VERSION" ("__DATE__" "__TIME__")\n";
209         ver+="Using Synfig ";
210         ver+=synfig::get_version();
211         #ifdef __GNUC__
212                 ver+=strprintf(" and GNU G++ %d.%d.%d",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
213         #endif
214
215         ver+=strprintf("\nGtk+ %d.%d.%d",gtk_major_version,gtk_minor_version,gtk_micro_version);
216
217         #ifdef _DEBUG
218                 ver+="\nDEBUG BUILD";
219         #endif
220         VersionLabel->set_text(ver);
221
222         // Create the image that will be used on the close button
223         Gtk::Image *image2 = manage(new class Gtk::Image(Gtk::StockID("gtk-close"), Gtk::IconSize(4)));
224         image2->set_alignment(0.5,0.5);
225         image2->set_padding(0,0);
226
227         // Create the close button, and attach the image to it
228         CloseButton = manage(new class Gtk::Button());
229         CloseButton->set_size_request(24,24);
230         CloseButton->set_flags(Gtk::CAN_FOCUS);
231         _tooltips.set_tip(*CloseButton, "Close", "");
232         CloseButton->set_relief(Gtk::RELIEF_NONE);
233         CloseButton->add(*image2);
234
235         // Create the progress bar
236         progressbar = manage(new class Gtk::ProgressBar());
237         progressbar->set_size_request(image_w,24);
238
239         // Create the current task label
240         tasklabel = manage(new class Gtk::Label());
241         tasklabel->set_size_request(image_w,24);
242         tasklabel->set_use_underline(false);
243
244         // Create the Gtk::Fixed container and put all of the widgets into it
245         Gtk::Fixed *fixed1 = manage(new class Gtk::Fixed());
246         fixed1->put(*Logo, 0, 0);
247         fixed1->put(*CopyrightLabel, 0, image_h-25);
248         fixed1->put(*CloseButton, image_w-24, 0);
249         fixed1->put(*VersionLabel, 0, image_h-90);
250         fixed1->put(*progressbar, 0, image_h+24);
251         fixed1->put(*tasklabel, 0, image_h);
252
253         // Set up the parameters for this pop-up window
254         set_title("Synfig Studio "VERSION);
255         set_modal(false);
256         property_window_position().set_value(Gtk::WIN_POS_CENTER);
257         set_resizable(false);
258         add(*fixed1);
259
260         // show everything off
261         Logo->show();
262         CopyrightLabel->show();
263         image2->show();
264         CloseButton->show();
265         VersionLabel->show();
266         fixed1->show();
267
268         // Connect relevant signals
269         CloseButton->signal_clicked().connect(sigc::mem_fun(*this, &About::close));
270
271         cb=new AboutProgress(*this);
272 }
273
274 About::~About()
275 {
276         delete cb;
277 }
278
279 void About::close()
280 {
281         hide();
282         if(can_self_destruct)
283                 delete this;
284 }
285
286 void
287 About::set_can_self_destruct(bool x)
288 {
289         can_self_destruct=x;
290         if(x==true)
291                 CloseButton->show();
292         else
293                 CloseButton->hide();
294 }
295
296 synfig::ProgressCallback *
297 About::get_callback()
298 {
299         return cb;
300 }