c++-gtk-utils
application.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 and 2013 Chris Vine
2 
3 The library comprised in this file or of which this file is part is
4 distributed by Chris Vine under the GNU Lesser General Public
5 License as follows:
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public License
9  as published by the Free Software Foundation; either version 2.1 of
10  the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License, version 2.1, for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License, version 2.1, along with this library (see the file LGPL.TXT
19  which came with this source code package in the c++-gtk-utils
20  sub-directory); if not, write to the Free Software Foundation, Inc.,
21  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 
23 */
24 
25 #ifndef CGU_APPLICATION_H
26 #define CGU_APPLICATION_H
27 
28 #include <list>
29 #include <exception>
30 #include <utility>
31 
33 
34 #ifdef CGU_USE_GTK
35 #include <gtk/gtk.h>
36 #endif
37 
38 #include <gio/gio.h>
39 
41 #include <c++-gtk-utils/window.h>
42 #include <c++-gtk-utils/emitter.h>
43 
44 namespace Cgu {
45 
46 #if defined(DOXYGEN_PARSING) || defined(CGU_USE_GTK)
47 #if defined(DOXYGEN_PARSING) || GTK_CHECK_VERSION(2,99,0)
48 
49 /**
50  * @class Cgu::ApplicationNameError application.h c++-gtk-utils/application.h
51  * @brief This class is thrown when the program id name passed to the
52  * constructor of Cgu::Application is invalid.
53  */
54 struct ApplicationNameError: public std::exception {
55  virtual const char* what() const throw() {return "ApplicationNameError\n";}
56 };
57 
58 /**
59  * @class Cgu::Application application.h c++-gtk-utils/application.h
60  * @brief This is a class for constructing and managing GtkApplication
61  * objects.
62  *
63  * @details It is available since version 2.0.0-rc2. It is only
64  * compiled in with a GTK+3 installation, and if the library is not
65  * configured with the \--without-gtk option.
66  *
67  * In typical usage, a Cgu::Application object is created in main(),
68  * and then a callback is attached to the 'activate', 'command_line'
69  * or 'open' emitter, depending on the flag passed to the Application
70  * object's constructor. The run() method of the Application object
71  * is then called, and a window deriving from Cgu::WinBase is
72  * constructed in the callback and added to the Application object or,
73  * if the program is a single instance program with only one main
74  * window and an instance is already running, a function is called to
75  * present that window.
76  *
77  * The gio/gtk+ documentation at the time of writing does not explain
78  * key concepts, and in particular how the GtkApplication sub-class
79  * interacts with GApplication's g_application_run(). Here is an
80  * explanation:
81  *
82  * @par
83  * (a) If a Cgu::Application object is constructed with the
84  * G_APPLICATION_FLAGS_NONE flag set, then calling the
85  * Cgu::Application::run() method (which hands off to
86  * g_application_run()) will cause the 'activate' emitter to emit. No
87  * command line parameter should be passed to the run method (argc
88  * should be 0 or 1), otherwise GtkApplication will cause the start-up
89  * to abort. Unlike with gtk_main(), g_application_run() (and so
90  * Cgu::Application::run()) does not consume any recognised glib/gtk+
91  * options, such as \--display, but regards these as application
92  * parameters. Such stripping out can be achieved by calling
93  * gtk_init() before constructing the Cgu::Application object (but
94  * gtk_init() does not need to be called for any other purpose), or by
95  * using the GOptionGroup/GOptionEntry interface.
96  * g_application_run(), and so Cgu::Application::run(), can be called
97  * with argc and argv set to 0, and that is generally the best
98  * approach if the G_APPLICATION_FLAGS_NONE flag is set.
99  * @par
100  * (b) If a Cgu::Application object is constructed with the
101  * G_APPLICATION_HANDLES_OPEN flag set, then calling the
102  * Cgu::Application::run() method will cause the 'activate' emitter to
103  * emit if no command line parameters were provided when the program
104  * was started (that is, if argc is 0 or 1), or cause the 'open'
105  * emitter to emit if parameters are passed (argc > 1). Such
106  * parameters will be construed as files/uris, and will be passed to
107  * the 'open' emitter by array of GFile*'s. Unlike with gtk_main(),
108  * g_application_run() (and so Cgu::Application::run()) does not
109  * consume any recognised glib/gtk+ options, such as \--display, but
110  * regards these as application parameters and so as file/uri names.
111  * Such stripping out can be achieved by calling gtk_init() before
112  * constructing the Cgu::Application object (but gtk_init() does not
113  * need to be called for any other purpose), or by using the
114  * GOptionGroup/GOptionEntry interface.
115  * @par
116  * (c) If a Cgu::Application object is constructed with the
117  * G_APPLICATION_HANDLES_COMMAND_LINE flag set, then calling the
118  * Cgu::Application::run() method will cause the 'command_line'
119  * emitter to emit. All the command line parameters will be passed
120  * on, and they can be obtained via the GApplicationCommandLine
121  * argument of the 'command_line' emitter. Unlike with gtk_main(),
122  * g_application_run() (and so Cgu::Application::run()) does not
123  * consume any recognised glib/gtk+ options, such as \--display, but
124  * regards these as command line parameters. Such stripping out can
125  * be achieved by calling gtk_init() before constructing the
126  * Cgu::Application object (but gtk_init() does not need to be called
127  * for any other purpose), or by using the GOptionGroup/GOptionEntry
128  * interface.
129  *
130  * There is little in this class that cannot also be done using the
131  * @ref prog_presenterAnchor "Cgu::prog_present" interface, which has
132  * the advantage of being more portable (@ref prog_presenterAnchor
133  * "Cgu::prog_present" does not depend on GTK+3), but this class is
134  * more convenient to use where a program requires multiple main
135  * application windows which can be independently opened and any of
136  * which are to keep the program alive until the last one is closed.
137  *
138  * Cgu::Application objects are not singletons. It is possible to
139  * drop an Application object out of scope or destroy it in some other
140  * way after closing or removing all its windows, then construct
141  * another with a different flag and then call run() on the second one
142  * (although it would be a curious application that wanted to do so).
143  * It is also possible, but even more off-the-wall, to have two
144  * Application objects in existence in the same process at the same
145  * time provided different dbus identifiers are supplied to the
146  * constructor for each, although run() may only be called on one of
147  * them at any one time. However, this is something of a curiosity:
148  * in nearly all cases an application will only have one
149  * Cgu::Application object, since the main purpose of Cgu::Application
150  * is to facilitate single instance programs.
151  *
152  * Cgu::WinBase objects, and so Cgu::Application, can be used with
153  * widget heirarchies or top level windows created using GtkBuilder.
154  * See @ref GtkBuilder for particulars about that.
155  *
156  * Here is a compilable example, demonstrating the use of the
157  * GApplicationFlags options:
158  *
159  * @code
160  * #include <iostream>
161  * #include <ostream>
162  * #include <string>
163  *
164  * #include <gtk/gtk.h>
165  *
166  * #include <c++-gtk-utils/callback.h>
167  * #include <c++-gtk-utils/application.h>
168  * #include <c++-gtk-utils/window.h>
169  * #include <c++-gtk-utils/shared_handle.h>
170  *
171  * // SETUP HERE: uncomment the flag to be tested:
172  *
173  * //const GApplicationFlags app_flag = G_APPLICATION_FLAGS_NONE;
174  * const GApplicationFlags app_flag = G_APPLICATION_HANDLES_OPEN;
175  * //const GApplicationFlags app_flag = G_APPLICATION_HANDLES_COMMAND_LINE;
176  *
177  * using namespace Cgu;
178  *
179  * // *** Demonstration message class ***
180  *
181  * extern "C" void message_button_clicked(GtkWidget*, void*);
182  *
183  * class Message: public Cgu::WinBase {
184  * public:
185  * friend void message_button_clicked(GtkWidget*, void*);
186  * Message(const char* text);
187  * };
188  *
189  * void message_button_clicked(GtkWidget* w, void*) {
190  * std::cout << "Clicked" << std::endl;
191  * }
192  *
193  * Message::Message(const char* text): WinBase{"Message", 0, false} {
194  * GtkWidget* box = gtk_vbox_new(false, 2);
195  * gtk_container_add(GTK_CONTAINER(get_win()), box);
196  * GtkWidget* label = gtk_label_new(text);
197  * gtk_box_pack_start(GTK_BOX(box), label,
198  * true, false, 0);
199  * GtkWidget* button_box = gtk_hbutton_box_new();
200  * gtk_box_pack_start(GTK_BOX(box), button_box,
201  * false, false, 0);
202  * GtkWidget* button = gtk_button_new_from_stock(GTK_STOCK_OK);
203  * gtk_container_add(GTK_CONTAINER(button_box), button);
204  * g_signal_connect(G_OBJECT(button), "clicked",
205  * G_CALLBACK(message_button_clicked), 0);
206  * gtk_widget_set_can_default(button, true);
207  * }
208  *
209  * // *** callbacks ***
210  *
211  * void activate(Cgu::Application* app) {
212  * std::cout << "activate() called" << std::endl;
213  *
214  * // probably if no arguments are passed, only one window is wanted,
215  * // which is now to present itself if it already exists: comment this
216  * // 'if' block out if a new window is to be added on each occasion
217  * // the program is started
218  * if (app->get_win_count() > 0) {
219  * gtk_window_present(app->get_windows().front()->get_win());
220  * return;
221  * }
222  * WinBase* dialog = new Message("This is a message");
223  * app->add(dialog);
224  * dialog->show_all();
225  * }
226  *
227  * void startup(Cgu::Application*) {
228  * std::cout << "startup() called" << std::endl;
229  * }
230  *
231  * void command_line(Cgu::Application* app, GApplicationCommandLine* cl, gint&) {
232  * std::cout << "command_line() called" << std::endl;
233  *
234  * // probably if the G_APPLICATION_HANDLES_COMMAND_LINE flag is set,
235  * // only one window is wanted, which is now to present itself if it
236  * // already exists: comment this 'if' block out if a new window is to
237  * // be added on each occasion the program is started
238  * if (app->get_win_count() > 0) {
239  * gtk_window_present(app->get_windows().front()->get_win());
240  * return;
241  * }
242  * std::string text("Command line options are:\n");
243  * int argc = 0;
244  * gchar** argv = g_application_command_line_get_arguments(cl, &argc);
245  * for (int count = 0; count < argc; ++count) {
246  * try {
247  * text += argv[count];
248  * text += '\n';
249  * }
250  * catch (...) {
251  * g_strfreev(argv);
252  * throw; // exceptions will be consumed by the callback handler and
253  * // a g_critical warning issued, but let's not leak memory
254  * }
255  * }
256  * g_strfreev(argv);
257  * WinBase* dialog = new Message(text.c_str());
258  * app->add(dialog);
259  * dialog->show_all();
260  * }
261  *
262  * void open(Cgu::Application* app, std::pair<GFile**, gint> files, gchar*) {
263  * std::cout << "open() called" << std::endl;
264  *
265  * // probably if the G_APPLICATION_HANDLES_OPEN flag is set and an
266  * // argument is passed, the adding of a new window is wanted on each
267  * // occasion the program is started
268  * std::string text("Files are:\n");
269  * for (int count = 0; count < files.second; ++count) {
270  * GcharScopedHandle uri(g_file_get_uri(files.first[count]));
271  * text += uri;
272  * text += '\n';
273  * }
274  * WinBase* dialog = new Message(text.c_str());
275  * app->add(dialog);
276  * dialog->show_all();
277  * }
278  *
279  * // *** main() ***
280  *
281  * int main(int argc, char* argv[]) {
282  *
283  * // gtk_init() is only relevant for the purposes of stripping out
284  * // glib/gtk+ recognised options - gtk_application_new() (and so the
285  * // Cgu::Application constructor) will call g_type_init() if the type
286  * // system needs initialization
287  * gtk_init(&argc, &argv);
288  *
289  * Application app{"my_prog", app_flag};
290  * app.activate.connect(Callback::make(activate));
291  * app.startup.connect(Callback::make(startup));
292  * app.command_line.connect(Callback::make(command_line));
293  * app.open.connect(Callback::make(open));
294  * if (app_flag == G_APPLICATION_FLAGS_NONE)
295  * app.run(0, 0);
296  * else
297  * app.run(argc, argv);
298  *
299  * return 0;
300  * }
301  * @endcode
302  *
303  * One thing to note about this example is that the callbacks
304  * connected to the Cgu::Application object always execute in the
305  * first instance of the program to be started (the instance in which
306  * Cgu::Application::run() blocks). If the program is then restarted,
307  * Cgu::Application::run() returns in the new program instance as soon
308  * as it has invoked the existing instance via dbus, following which
309  * the new program instance exits, so immediately disposing of the
310  * Cgu::Application object and callbacks which were constructed on the
311  * restart. This is a feature of GApplication/GtkApplication: given
312  * the overhead of starting a new process, and that restarting a
313  * single-instance program is in any event an exceptional event, any
314  * additional overhead created by constructing and then destroying the
315  * Cgu::Application object and callbacks in the new instance is
316  * trivial.
317  */
318 
319 class Application {
320 
321  std::list<WinBase*> win_list;
323 
324  void* reserved; // for future use
325 public:
326 
327  typedef std::list<WinBase*>::size_type size_type;
328 
329 /**
330  * This class cannot be copied. The copy constructor is deleted.
331  */
332  Application(const Application&) = delete;
333 
334 /**
335  * This class cannot be copied. The assignment operator is deleted.
336  */
337  Application& operator=(const Application&) = delete;
338 
339 /**
340  * This SafeEmitterArg object emits (and so executes any connected
341  * callback) when the underlying GApplication object emits its
342  * @a activate signal. The argument passed to the emitter's
343  * callback(s) is a pointer to the Cgu::Application object.
344  * @note When the callback executes, thread cancellation is blocked,
345  * and any exceptions are consumed with a g_critical message issued.
346  * The callback will always execute in the main GUI thread when
347  * executed in response to the run() method. Because a SafeEmitterArg
348  * object is used, the emitter object itself is thread safe.
349  *
350  * Since 2.0.0-rc2
351  */
353 
354 /**
355  * This SafeEmitterArg object emits (and so executes any connected
356  * callback) when the underlying GApplication object emits its
357  * @a startup signal. The argument passed to the emitter's callback(s)
358  * is a pointer to the Cgu::Application object. However, you usually
359  * won't need to do anything in response to the @a startup signal.
360  * @note When the callback executes, thread cancellation is blocked,
361  * and any exceptions are consumed with a g_critical message issued.
362  * The callback will always execute in the main GUI thread when
363  * executed in response to the run() method. Because a SafeEmitterArg
364  * object is used, the emitter object itself is thread safe.
365  *
366  * Since 2.0.0-rc2
367  */
369 
370 /**
371  * This SafeEmitterArg object emits (and so executes any connected
372  * callback) when the underlying GApplication object emits its
373  * @a command-line signal. The second argument passed to the
374  * emitter's callback(s) is the one passed by that signal, that is to
375  * say the arguments are:
376  *
377  * first: a pointer to the Cgu::Application object.
378  *
379  * second: a pointer to a GApplicationCommandLine object representing
380  * the passed command line (this is owned by gio and should not be
381  * unref'ed).
382  *
383  * third: a gint& reference to which the value to be returned to the
384  * GApplication's command-line signal can be passed: if no value is
385  * assigned to it or no callback has been attached to the signal, 0
386  * will be returned, except that if an exception from a callback is
387  * consumed, -1 will be returned. If more than one callback is
388  * attached to the signal and no exception is consumed, the last one
389  * to assign a value will be have its value returned.
390  *
391  * @note When the callback executes, thread cancellation is blocked,
392  * and any exceptions are consumed with a g_critical message issued
393  * and a return value of -1 set. The callback will always execute in
394  * the main GUI thread when executed in response to the run() method.
395  * Because a SafeEmitterArg object is used, the emitter object itself
396  * is thread safe.
397  *
398  * Since 2.0.0-rc2
399  */
401 
402 /**
403  * This SafeEmitterArg object emits (and so executes any connected
404  * callback) when the underlying GApplication object emits its @a open
405  * signal. The second and third arguments passed to the emitter's
406  * callback(s) are those passed by that signal, that is to say the
407  * arguments are:
408  *
409  * first: a pointer to the Cgu::Application object.
410  *
411  * second: a std::pair object where the first member is an array of
412  * GFile*'s representing the files/uris passed as arguments, and the
413  * second member is the length of that array (the array is owned by
414  * gio and should not be freed).
415  *
416  * third: a gchar* argument comprising the text of the "hint" (this is
417  * owned by gio and should not be freed).
418  *
419  * @note When the callback executes, thread cancellation is blocked,
420  * and any exceptions are consumed with a g_critical message issued.
421  * The callback will always execute in the main GUI thread when
422  * executed in response to the run() method. Because a SafeEmitterArg
423  * object is used, the emitter object itself is thread safe.
424  *
425  * Since 2.0.0-rc2
426  */
428 
429 /**
430  * Add a Cgu::WinBase object to the Cgu::Application object, and so
431  * also add its managed GtkWindow object to the GtkApplication object.
432  * Any Cgu::WinBase object passed to this method should not normally
433  * be modal and must have been constructed on free store with the new
434  * expression, and will be self owning, although if it is removed from
435  * this Cgu::Application object with remove(), the delete expression
436  * can (and normally should) be called on it. If a delete event
437  * occurs on the WinBase object so that the WinBase object destroys
438  * itself (say, by clicking on the window's close/delete button), or
439  * it destroys itself in some other way (say, by calling the
440  * WinBase::close() method), it will automatically be removed from
441  * this Application object without further action being necessary.
442  * The WinBase::exec() method should never be called on a WinBase
443  * object which has been added to an Application object. The
444  * Cgu::Application class, and thus this method, does not employ
445  * mutexes to make it thread safe, as there should never be a reason
446  * to call Cgu::Application methods in other than the main GUI thread.
447  * @param win The Cgu::WinBase object to be added.
448  * @exception std::bad_alloc This method might throw std::bad_alloc if
449  * memory is exhausted and the system throws in that case.
450  * @note As well as this method only being called in the main GUI
451  * thread, if the program by which it is called calls GTK+ directly in
452  * more than one thread and thus employs
453  * gdk_threads_enter()/gdk_threads_leave() (rather than, say,
454  * Cgu::Notifier or Cgu::Callback::post()), it must be surrounded by
455  * gdk_threads_enter()/gdk_threads_leave() if called otherwise than in
456  * a GTK+ signal handler. (The best approach however is for a program
457  * only to address GTK+/GDK in the main program thread, for which
458  * purpose this library provides various functions and classes for
459  * inter-thread communication, such as Cgu::Notifier and
460  * Cgu::Callback::post(): see @ref Threading for particulars about
461  * GTK+ thread safety.)
462  *
463  * Since 2.0.0-rc2
464  */
465  void add(Cgu::WinBase* win);
466 
467 /**
468  * Remove a Cgu::WinBase object from the Cgu::Application object, and
469  * so also remove its managed GtkWindow object from the GtkApplication
470  * object. This method will not throw assuming that merely iterating
471  * through a list does not throw (as it would not on any sane
472  * implementation). The Cgu::Application class, and thus this method,
473  * does not employ mutexes to make it thread safe, as there should
474  * never be a reason to call Cgu::Application methods in other than
475  * the main GUI thread. Calling this method does not destroy the
476  * WinBase object.
477  * @param win The Cgu::WinBase object to be removed.
478  * @return true if the Cgu::WinBase object was found in the
479  * Cgu::Application object and so removed, otherwise false.
480  * @note As well as this method only being called in the main GUI
481  * thread, if the program by which it is called calls GTK+ directly in
482  * more than one thread and thus employs
483  * gdk_threads_enter()/gdk_threads_leave() (rather than, say,
484  * Cgu::Notifier or Cgu::Callback::post()), it must be surrounded by
485  * gdk_threads_enter()/gdk_threads_leave() if called otherwise than in
486  * a GTK+ signal handler. (The best approach however is for a program
487  * only to address GTK+/GDK in the main program thread, for which
488  * purpose this library provides various functions and classes for
489  * inter-thread communication, such as Cgu::Notifier and
490  * Cgu::Callback::post(): see @ref Threading for particulars about
491  * GTK+ thread safety.)
492  *
493  * Since 2.0.0-rc2
494  */
495  bool remove(Cgu::WinBase* win);
496 
497 /**
498  * Calls g_application_run() in respect of the underlying
499  * GtkApplication object, so invoking one of this Cgu::Application
500  * class's emitters (the exact behaviour depends on the GApplication
501  * flags passed to the constructor and is explained in the
502  * introductory remarks above). This method is thread safe (although
503  * that is irrelevant to its purpose) and will not throw. In
504  * addition, if a callback connected to an emitter throws, the
505  * exception is consumed and a g_critical warning issued. This
506  * function blocks until the last WinBase object associated with this
507  * Application object is destroyed or removed.
508  * @param argc The argc from main() or 0.
509  * @param argv The argv from main() or 0.
510  * @return The exit status from g_application_run().
511  *
512  * Since 2.0.0-rc2
513  */
514  int run(int argc, char** argv) {
515  return g_application_run((GApplication*)app.get(), argc, argv);
516  }
517 
518 /**
519  * Get the underlying GApplication object (note, not the
520  * GtkApplication object, although the GApplication object can be cast
521  * to GtkApplication), so allowing any of gio's g_application_*()
522  * functions to be applied to it. In normal usage it will not be
523  * necessary to call this method. This method is thread safe and will
524  * not throw.
525  * @return The underlying GApplication object.
526  *
527  * Since 2.0.0-rc2
528  */
529  GApplication* get_g_app() const {return (GApplication*)app.get();}
530 
531 /**
532  * Get the list of Cgu::WinBase objects associated with the
533  * application. The Cgu::Application class, and thus this method,
534  * does not employ mutexes to make it thread safe, as there should
535  * never be a reason to call Cgu::Application methods in other than
536  * the main GUI thread.
537  * @return A list of the top level Cgu::WinBase objects associated
538  * with the application, which will appear in the order in which they
539  * were added. If you need to access these, you will probably want to
540  * do a dynamic_cast or static_cast to the child type.
541  * @exception std::bad_alloc This method might throw std::bad_alloc if
542  * memory is exhausted and the system throws in that case.
543  *
544  * Since 2.0.0-rc2
545  */
546  std::list<Cgu::WinBase*> get_windows() const {return win_list;}
547 
548 /**
549  * Gets the current count of Cgu::WinBase objects associated with this
550  * Cgu::Application object. When it reaches 0, the application will
551  * normally end (but this can be prevented by calling
552  * g_application_hold()/g_application_release() on the GApplication
553  * object returned by get_g_app()). This method can be used in the
554  * callback of one of this class's emitters to determine whether this
555  * is the first instance of a program to be started (assuming the
556  * first instance calls add() to bring up a window), because in that
557  * case it will return 0 until add() is called. Calling
558  * get_windows().size() will give the same result, but using this
559  * method is more efficient as it will avoid a copy of the list of
560  * windows. This method will not throw assuming that calling
561  * std::list::size() does not throw (as it would not on any sane
562  * implementation). The Cgu::Application class, and thus this method,
563  * does not employ mutexes to make it thread safe, as there should
564  * never be a reason to call Cgu::Application methods in other than
565  * the main GUI thread.
566  * @return The number of Cgu::WinBase objects currently associated
567  * with this Cgu::Application object.
568  *
569  * Since 2.0.0-rc2
570  */
571  size_type get_win_count() const {return win_list.size();}
572 
573 /**
574  * This constructor will, via gtk_application_new(), cause
575  * g_type_init() to be called. If any GTK+ functions are to be called
576  * before an Application object is constructed, g_type_init() (or
577  * gtk_init()) must be called explicitly.
578  * @param prog_name An identifier name. This can comprise any valid
579  * ASCII characters "[A-Z][a-z][0-9]_-", although it is usually best
580  * to pass the program name. Unlike with gtk_application_new(), it
581  * does not need to comprise a full dbus bus name: this method will
582  * construct its own valid dbus bus name from prog_name in the org.cgu
583  * domain.
584  * @param flags The GApplicationFlags to be passed to the
585  * Cgu::Application object. This class does not contain its own
586  * sub-class of GApplication to customize this, but adopts the
587  * behaviour of GtkApplication. That behaviour is explained in the
588  * introductory remarks.
589  * @exception Cgu::ApplicationNameError This exception will be thrown
590  * if the prog_name parameter does not meet the requirements referred
591  * to above.
592  * @exception std::bad_alloc This method might throw std::bad_alloc if
593  * memory is exhausted and the system throws in that case.
594  *
595  * Since 2.0.0-rc2
596  */
597  Application(const char* prog_name, GApplicationFlags flags);
598 
599 /**
600  * From version 2.0.0-rc3, as a safety feature the destructor removes
601  * any remaining WinBase objects associated with this Application
602  * object (this would only be relevant if the user constructs the
603  * Application object on free store, and then deletes it while the
604  * run() method is still blocking for the purpose of constructing a
605  * different Application object, but does not call the remove() method
606  * on all associated WinBase objects before doing so: constructing an
607  * Application object on free store in this way would be highly
608  * unusual however).
609  *
610  * Since 2.0.0-rc3
611  */
612  ~Application() {while (!win_list.empty()) remove(win_list.front());}
613 
614 /* Only has effect if --with-glib-memory-slices-compat or
615  * --with-glib-memory-slices-no-compat option picked */
617 };
618 
619 #endif // GTK_CHECK_VERSION
620 #endif // CGU_USE_GTK
621 
622 } // namespace Cgu
623 
624 #endif // CGU_APPLICATION_H