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