Fixing warnings from doxygen:
[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 **      \legal
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 **      \endlegal
18 **
19 ** === N O T E S ===========================================================
20 **
21 ** ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include <iostream>
33 #include <string>
34
35 #include <ETL/stringf>
36
37 #include <gtkmm/image.h>
38 #include <gdkmm/pixbufloader.h>
39 #include <gtkmm/button.h>
40 #include <gtkmm/label.h>
41 #include <gtkmm/fixed.h>
42
43 #include <synfig/general.h>
44
45 #include "about.h"
46 #include "app.h"
47
48 #endif
49
50 using namespace std;
51 using namespace etl;
52 using namespace studio;
53
54 /* === M A C R O S ========================================================= */
55
56 #ifndef VERSION
57 #define VERSION "unknown"
58 #define PACKAGE "synfigstudio"
59 #endif
60
61 #ifdef WIN32
62 #       ifdef IMAGE_DIR
63 #               undef IMAGE_DIR
64 #               define IMAGE_DIR "share\\pixmaps"
65 #       endif
66 #endif
67
68 #ifndef IMAGE_DIR
69 #       define IMAGE_DIR "/usr/local/share/pixmaps"
70 #endif
71
72 #ifndef IMAGE_EXT
73 #       define IMAGE_EXT        "png"
74 #endif
75
76 /* === G L O B A L S ======================================================= */
77 extern      const guint gtk_major_version;
78 extern      const guint gtk_minor_version;
79 extern      const guint gtk_micro_version;
80 extern      const guint gtk_binary_age;
81 extern      const guint gtk_interface_age;
82
83 /* === P R O C E D U R E S ================================================= */
84
85 class studio::AboutProgress : public synfig::ProgressCallback
86 {
87         About &about;
88
89 public:
90
91         AboutProgress(About &about):about(about) { }
92
93         virtual bool task(const std::string &task)
94         {
95                 if(about.tasklabel)
96                 {
97                         about.tasklabel->set_label(task);
98                         about.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(about.tasklabel)
112                 {
113                         about.tasklabel->set_label(_("ERROR:")+task);
114                         about.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(about.tasklabel)
128                 {
129                         about.tasklabel->set_label(_("WARNING:")+task);
130                         about.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(about.progressbar)
144                 {
145                         about.progressbar->set_fraction((float)current/(float)total);
146                         about.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 AboutProgress
155
156 /* === M E T H O D S ======================================================= */
157
158 About::About():
159         Gtk::Window(Gtk::WINDOW_POPUP),
160         can_self_destruct(true)
161 {
162         int image_w=300,image_h=350;
163
164         std::string imagepath;
165 #ifdef WIN32
166         imagepath=App::get_base_path()+ETL_DIRECTORY_SEPERATOR+IMAGE_DIR;
167 #else
168         imagepath=IMAGE_DIR;
169 #endif
170         char* synfig_root=getenv("SYNFIG_ROOT");
171         if(synfig_root) {
172                 imagepath=synfig_root;
173                 imagepath+=ETL_DIRECTORY_SEPERATOR;
174
175                 imagepath+="share/pixmaps";
176         }
177         imagepath+=ETL_DIRECTORY_SEPERATOR;
178
179
180         // Create the Logo
181         Gtk::Image *Logo = manage(new class Gtk::Image());
182         Logo->set(imagepath+"about_dialog."IMAGE_EXT);
183         Logo->set_size_request(image_w,image_h);
184         Logo->set_alignment(0.5,0.5);
185         Logo->set_padding(0,0);
186
187         // Create the Copyright Label
188         Gtk::Label *CopyrightLabel = manage(new class Gtk::Label(SYNFIG_COPYRIGHT));
189         CopyrightLabel->set_size_request(image_w,24);
190         CopyrightLabel->set_alignment(0.5,0.5);
191         CopyrightLabel->set_padding(0,0);
192         CopyrightLabel->set_justify(Gtk::JUSTIFY_CENTER);
193         CopyrightLabel->set_line_wrap(false);
194
195         // Create the Version information label
196         Gtk::Label *VersionLabel = manage(new class Gtk::Label("Version"));
197         VersionLabel->set_size_request(image_w,80);
198         VersionLabel->set_flags(Gtk::CAN_FOCUS);
199         VersionLabel->set_alignment(0.5,0.5);
200         VersionLabel->set_padding(0,0);
201         VersionLabel->set_justify(Gtk::JUSTIFY_CENTER);
202         VersionLabel->set_line_wrap(false);
203
204         // Set the version label to contain the correct information
205         string ver;
206         ver+="Version "VERSION" ("__DATE__" "__TIME__")\n";
207         ver+="Using Synfig ";
208         ver+=synfig::get_version();
209         #ifdef __GNUC__
210                 ver+=strprintf(" and GNU G++ %d.%d.%d",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
211         #endif
212
213         ver+=strprintf("\nGtk+ %d.%d.%d",gtk_major_version,gtk_minor_version,gtk_micro_version);
214
215         #ifdef _DEBUG
216                 ver+="\nDEBUG BUILD";
217         #endif
218         VersionLabel->set_text(ver);
219
220         // Create the image that will be used on the close button
221         Gtk::Image *image2 = manage(new class Gtk::Image(Gtk::StockID("gtk-close"), Gtk::IconSize(4)));
222         image2->set_alignment(0.5,0.5);
223         image2->set_padding(0,0);
224
225         // Create the close button, and attach the image to it
226         CloseButton = manage(new class Gtk::Button());
227         CloseButton->set_size_request(24,24);
228         CloseButton->set_flags(Gtk::CAN_FOCUS);
229         _tooltips.set_tip(*CloseButton, "Close", "");
230         CloseButton->set_relief(Gtk::RELIEF_NONE);
231         CloseButton->add(*image2);
232
233         // Create the progress bar
234         progressbar = manage(new class Gtk::ProgressBar());
235         progressbar->set_size_request(image_w,24);
236
237         // Create the current task label
238         tasklabel = manage(new class Gtk::Label());
239         tasklabel->set_size_request(image_w,24);
240         tasklabel->set_use_underline(false);
241
242         // Create the Gtk::Fixed container and put all of the widgets into it
243         Gtk::Fixed *fixed1 = manage(new class Gtk::Fixed());
244         fixed1->put(*Logo, 0, 0);
245         fixed1->put(*CopyrightLabel, 0, image_h-25);
246         fixed1->put(*CloseButton, image_w-24, 0);
247         fixed1->put(*VersionLabel, 0, image_h-90);
248         fixed1->put(*progressbar, 0, image_h+24);
249         fixed1->put(*tasklabel, 0, image_h);
250
251         // Set up the parameters for this pop-up window
252         set_title("Synfig Studio "VERSION);
253         set_modal(false);
254         property_window_position().set_value(Gtk::WIN_POS_CENTER);
255         set_resizable(false);
256         add(*fixed1);
257
258         // show everything off
259         Logo->show();
260         CopyrightLabel->show();
261         image2->show();
262         CloseButton->show();
263         VersionLabel->show();
264         fixed1->show();
265
266         // Connect relevant signals
267         CloseButton->signal_clicked().connect(sigc::mem_fun(*this, &About::close));
268
269         cb=new AboutProgress(*this);
270 }
271
272 About::~About()
273 {
274         delete cb;
275 }
276
277 void About::close()
278 {
279         hide();
280         if(can_self_destruct)
281                 delete this;
282 }
283
284 void
285 About::set_can_self_destruct(bool x)
286 {
287         can_self_destruct=x;
288         if(x==true)
289                 CloseButton->show();
290         else
291                 CloseButton->hide();
292 }
293
294 synfig::ProgressCallback *
295 About::get_callback()
296 {
297         return cb;
298 }