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