minor fix
[synfig.git] / synfig-studio / trunk / src / gtkmm / about.cpp
1 /*! ========================================================================
2 ** Synfig
3 ** Template File
4 ** $Id: about.cpp,v 1.2 2005/01/13 21:11:16 darco Exp $
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 **
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
11 **
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
16 **
17 ** === N O T E S ===========================================================
18 **
19 ** ========================================================================= */
20
21 /* === H E A D E R S ======================================================= */
22
23 #ifdef USING_PCH
24 #       include "pch.h"
25 #else
26 #ifdef HAVE_CONFIG_H
27 #       include <config.h>
28 #endif
29
30 #include <iostream>
31 #include <string>
32
33 #include <ETL/stringf>
34
35 #include <gtkmm/image.h>
36 #include <gdkmm/pixbufloader.h>
37 #include <gtkmm/button.h>
38 #include <gtkmm/label.h>
39 #include <gtkmm/fixed.h>
40
41 #include <synfig/general.h>
42
43 #include "about.h"
44 #include "app.h"
45
46 #endif
47
48 using namespace std;
49 using namespace etl;
50 using namespace studio;
51
52 /* === M A C R O S ========================================================= */
53
54 #ifndef VERSION
55 #define VERSION "unknown"
56 #define PACKAGE "synfigstudio"
57 #endif
58
59 #ifdef WIN32
60 #       ifdef IMAGE_DIR
61 #               undef IMAGE_DIR
62 #               define IMAGE_DIR "share\\pixmaps"
63 #       endif
64 #endif
65
66 #ifndef IMAGE_DIR
67 #       define IMAGE_DIR "/usr/local/share/pixmaps"
68 #endif
69
70 #ifndef IMAGE_EXT
71 #       define IMAGE_EXT        "png"
72 #endif
73
74 /* === G L O B A L S ======================================================= */
75 extern      const guint gtk_major_version;
76 extern      const guint gtk_minor_version;
77 extern      const guint gtk_micro_version;
78 extern      const guint gtk_binary_age;
79 extern      const guint gtk_interface_age;
80
81 /* === P R O C E D U R E S ================================================= */
82
83 class studio::AboutProgress : public synfig::ProgressCallback
84 {
85         About &about;
86         
87 public:
88
89         AboutProgress(About &about):about(about) { }
90         
91         virtual bool task(const std::string &task)
92         {
93                 if(about.tasklabel)
94                 {
95                         about.tasklabel->set_label(task);
96                         about.tasklabel->show();
97                 }
98                 else
99                 {
100                         cerr<<task<<endl;
101                 }
102
103                 while(studio::App::events_pending())studio::App::iteration(false);
104                 return true;
105         }
106
107         virtual bool error(const std::string &task)
108         {
109                 if(about.tasklabel)
110                 {
111                         about.tasklabel->set_label(_("ERROR:")+task);
112                         about.tasklabel->show();
113                 }
114                 else
115                 {
116                         cerr<<task<<endl;
117                 }
118
119                 while(studio::App::events_pending())studio::App::iteration(false);
120                 return true;
121         }
122
123         virtual bool warning(const std::string &task)
124         {
125                 if(about.tasklabel)
126                 {
127                         about.tasklabel->set_label(_("WARNING:")+task);
128                         about.tasklabel->show();
129                 }
130                 else
131                 {
132                         cerr<<task<<endl;
133                 }
134
135                 while(studio::App::events_pending())studio::App::iteration(false);
136                 return true;
137         }
138
139         virtual bool amount_complete(int current, int total)
140         {
141                 if(about.progressbar)
142                 {
143                         about.progressbar->set_fraction((float)current/(float)total);
144                         about.progressbar->show();
145                 }
146                 else
147                         cerr<<current<<'/'<<total<<endl;
148
149                 while(studio::App::events_pending())studio::App::iteration(false);
150                 return true;
151         }
152 }; // END of class AboutProgress
153
154 /* === M E T H O D S ======================================================= */
155
156 About::About():
157         Gtk::Window(Gtk::WINDOW_POPUP),
158         can_self_destruct(true)
159 {
160         int image_w=300,image_h=350;
161
162         std::string imagepath;
163 #ifdef WIN32
164         imagepath=App::get_base_path()+ETL_DIRECTORY_SEPERATOR+IMAGE_DIR;
165 #else
166         imagepath=IMAGE_DIR;
167 #endif
168         imagepath+=ETL_DIRECTORY_SEPERATOR;
169         
170         
171         // Create the Logo
172         Gtk::Image *Logo = manage(new class Gtk::Image());
173         Logo->set(imagepath+"about_dialog."IMAGE_EXT);
174         Logo->set_size_request(image_w,image_h);
175         Logo->set_alignment(0.5,0.5);
176         Logo->set_padding(0,0);
177         
178         // Create the Copyright Label
179         Gtk::Label *CopyrightLabel = manage(new class Gtk::Label(SYNFIG_COPYRIGHT));
180         CopyrightLabel->set_size_request(image_w,24);
181         CopyrightLabel->set_alignment(0.5,0.5);
182         CopyrightLabel->set_padding(0,0);
183         CopyrightLabel->set_justify(Gtk::JUSTIFY_CENTER);
184         CopyrightLabel->set_line_wrap(false);
185
186         // Create the Version information label
187         Gtk::Label *VersionLabel = manage(new class Gtk::Label("Version"));
188         VersionLabel->set_size_request(image_w,80);
189         VersionLabel->set_flags(Gtk::CAN_FOCUS);
190         VersionLabel->set_alignment(0.5,0.5);
191         VersionLabel->set_padding(0,0);
192         VersionLabel->set_justify(Gtk::JUSTIFY_CENTER);
193         VersionLabel->set_line_wrap(false);
194         
195         // Set the version label to contain the correct information
196         string ver;
197         ver+="Version "VERSION" ("__DATE__" "__TIME__")\n";
198         ver+="Using SYNFIG ";
199         ver+=synfig::get_version();
200         #ifdef __GNUC__
201                 ver+=strprintf(" and GNU G++ %d.%d.%d",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
202         #endif
203
204         ver+=strprintf("\nGtk+ %d.%d.%d",gtk_major_version,gtk_minor_version,gtk_micro_version);
205
206         #ifdef _DEBUG
207                 ver+="\nDEBUG BUILD";
208         #endif
209         VersionLabel->set_text(ver);
210
211         // Create the image that will be used on the close button
212         Gtk::Image *image2 = manage(new class Gtk::Image(Gtk::StockID("gtk-close"), Gtk::IconSize(4)));
213         image2->set_alignment(0.5,0.5);
214         image2->set_padding(0,0);
215         
216         // Create the close button, and attach the image to it
217         CloseButton = manage(new class Gtk::Button());
218         CloseButton->set_size_request(24,24);
219         CloseButton->set_flags(Gtk::CAN_FOCUS);
220         _tooltips.set_tip(*CloseButton, "Close", "");
221         CloseButton->set_relief(Gtk::RELIEF_NONE);
222         CloseButton->add(*image2);
223
224         // Create the progress bar
225         progressbar = manage(new class Gtk::ProgressBar());
226         progressbar->set_size_request(image_w,24);
227
228         // Create the current task label
229         tasklabel = manage(new class Gtk::Label());
230         tasklabel->set_size_request(image_w,24);
231         tasklabel->set_use_underline(false);
232         
233         // Create the Gtk::Fixed container and put all of the widgets into it
234         Gtk::Fixed *fixed1 = manage(new class Gtk::Fixed());
235         fixed1->put(*Logo, 0, 0);
236         fixed1->put(*CopyrightLabel, 0, image_h-25);
237         fixed1->put(*CloseButton, image_w-24, 0);
238         fixed1->put(*VersionLabel, 0, image_h-90);
239         fixed1->put(*progressbar, 0, image_h+24);
240         fixed1->put(*tasklabel, 0, image_h);
241
242         // Set up the parameters for this pop-up window
243         set_title("Synfig Studio "VERSION);
244         set_modal(false);
245         property_window_position().set_value(Gtk::WIN_POS_CENTER);
246         set_resizable(false);
247         add(*fixed1);
248
249         // show everything off
250         Logo->show();
251         CopyrightLabel->show();
252         image2->show();
253         CloseButton->show();
254         VersionLabel->show();
255         fixed1->show();
256
257         // Connect relevant signals
258         CloseButton->signal_clicked().connect(sigc::mem_fun(*this, &About::close));
259
260         cb=new AboutProgress(*this);
261 }
262
263 About::~About()
264 {
265         delete cb;
266 }
267
268 void About::close()
269 {
270         hide();
271         if(can_self_destruct)
272                 delete this;
273 }
274
275 void
276 About::set_can_self_destruct(bool x)
277 {
278         can_self_destruct=x;
279         if(x==true)
280                 CloseButton->show();
281         else
282                 CloseButton->hide();            
283 }
284
285 synfig::ProgressCallback *
286 About::get_callback()
287 {
288         return cb;
289 }