// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*- /* Copyright (C) 2007 The gtkmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #m4 _PUSH(SECTION_CC_PRE_INCLUDES) #undef G_DISABLE_DEPRECATED #define GLIB_DISABLE_DEPRECATION_WARNINGS 1 #m4 _POP() #include #include #include #include #include #include #include #include #include #include _DEFS(giomm,gio) _PINCLUDE(glibmm/private/object_p.h) namespace Gio { _WRAP_ENUM(ApplicationFlags, GApplicationFlags, NO_GTYPE) /** Application - Core application class. * An Application is the foundation of an application, unique for a given * application identifier. The Application class wraps some low-level * platform-specific services and is intended to act as the foundation for * higher-level application classes such as Gtk::Application or MxApplication. * In general, you should not use this class outside of a higher level * framework. * * One of the core features that Application provides is process uniqueness, * in the context of a "session". The session concept is platform-dependent, * but corresponds roughly to a graphical desktop login. When your application * is launched again, its arguments are passed through platform communication * to the already running program. The already running instance of the program * is called the primary instance. * * Before using Application, you must choose an "application identifier". The * expected form of an application identifier is very close to that of of a * DBus * bus name. Examples include: "com.example.MyApp", * "org.example.internal-apps.Calculator". For details on valid application * identifiers, see id_is_valid(). * * Application provides convenient life cycle management by maintaining a * use count for the primary application instance. The use count can be * changed using hold() and release(). If it drops to zero, the application * exits. * * Application also implements the ActionGroup interface and lets you easily * export actions by adding them with set_action_group(). When * invoking an action by calling Gio::ActionGroup::activate_action() on the * application, it is always invoked in the primary instance. * * There is a number of different entry points into an Application: * * - via 'Activate' (i.e. just starting the application) * - via 'Open' (i.e. opening some files) * - via activating an action * * The signal_startup() signal lets you handle the application initialization * for all of these in a single place. * * See the C API docs for an example. * * @newin{2,32} */ class Application : public Glib::Object, public ActionGroup, public ActionMap { _CLASS_GOBJECT(Application, GApplication, G_APPLICATION, Glib::Object, GObject) _IMPLEMENTS_INTERFACE(ActionGroup) _IMPLEMENTS_INTERFACE(ActionMap) protected: /** Constructs an application instance. * If no application ID is given then some features (most notably application uniqueness) will be disabled. * * @param application_id The application ID. * @param flags The application flags. */ explicit Application(const Glib::ustring& application_id = Glib::ustring(), ApplicationFlags flags = APPLICATION_FLAGS_NONE); _IGNORE(g_application_new) public: /** Creates an application instance. * If no application ID is given then some features (most notably application uniqueness) will be disabled. * * @param application_id The application ID. * @param flags The application flags. */ _WRAP_CREATE(const Glib::ustring& application_id = Glib::ustring(), ApplicationFlags flags = APPLICATION_FLAGS_NONE) _WRAP_METHOD(static bool id_is_valid(const Glib::ustring& application_id), g_application_id_is_valid) _WRAP_METHOD(Glib::ustring get_id() const, g_application_get_application_id) _WRAP_METHOD(void set_id(const Glib::ustring& application_id), g_application_set_application_id) _WRAP_METHOD(Glib::RefPtr get_dbus_connection(), g_application_get_dbus_connection, refreturn) _WRAP_METHOD(Glib::RefPtr get_dbus_connection() const, g_application_get_dbus_connection, refreturn, constversion) _WRAP_METHOD(Glib::ustring get_dbus_object_path() const, g_application_get_dbus_object_path) _WRAP_METHOD(guint get_inactivity_timeout() const, g_application_get_inactivity_timeout) _WRAP_METHOD(void set_inactivity_timeout(guint inactivity_timeout), g_application_set_inactivity_timeout) _WRAP_METHOD(ApplicationFlags get_flags() const, g_application_get_flags) _WRAP_METHOD(void set_flags(ApplicationFlags flags), g_application_set_flags) _WRAP_METHOD(void set_action_group(const Glib::RefPtr& action_group), g_application_set_action_group) //TODO: Custom write the documentation for this method? _WRAP_METHOD_DOCS_ONLY(g_application_add_main_option_entries) void add_main_option_entry(Glib::OptionEntry& entry); _IGNORE(g_application_add_main_option_entries) _WRAP_METHOD(void add_option_group(Glib::OptionGroup& group), g_application_add_option_group) _WRAP_METHOD(bool is_registered() const, g_application_get_is_registered) _WRAP_METHOD(bool is_remote() const, g_application_get_is_remote) //Renamed from register() because that is a C++ keyword. _WRAP_METHOD(bool register_application(const Glib::RefPtr& cancellable{?}), g_application_register, errthrow) _IGNORE(g_application_impl_register) _WRAP_METHOD(void hold(), g_application_hold) _WRAP_METHOD(void release(), g_application_release) _WRAP_METHOD(void activate(), g_application_activate) typedef std::vector< Glib::RefPtr > type_vec_files; /* Opens the given files. * * In essence, this results in the open signal being emitted * in the primary instance. * * @a hint is simply passed through to the open signal. It is * intended to be used by applications that have multiple modes for * opening files (eg: "view" vs "edit", etc). * * The application must be registered before calling this mwethod * and it must have the APPLICATION_HANDLES_OPEN flag set. * * @param files The files to open. This must be non-empty. * @param hint A hint. * * @newin{2,32} */ void open(const type_vec_files& files, const Glib::ustring& hint = Glib::ustring()); _IGNORE(g_application_open) /* Opens the given file. * * In essence, this results in the open signal being emitted * in the primary instance. * * @a hint is simply passed through to the open signal. It is * intended to be used by applications that have multiple modes for * opening files (eg: "view" vs "edit", etc). * * The application must be registered before calling this mwethod * and it must have the APPLICATION_HANDLES_OPEN flag set. * * @param file The file to open. This must be non-empty. * @param hint A hint. * * @newin{2,32} */ void open(const Glib::RefPtr& file, const Glib::ustring& hint = Glib::ustring()); _WRAP_METHOD(int run(int argc, char** argv), g_application_run) _WRAP_METHOD(void quit(), g_application_quit) _WRAP_METHOD(static void set_default(const Glib::RefPtr& application), g_application_set_default) /// Unsets any existing default application. static void unset_default(); _WRAP_METHOD(static Glib::RefPtr get_default(), g_application_get_default) _WRAP_METHOD(void mark_busy(), g_application_mark_busy) _WRAP_METHOD(void unmark_busy(), g_application_unmark_busy) _WRAP_METHOD(void send_notification(const Glib::ustring& id{?}, const Glib::RefPtr& notification), g_application_send_notification) _WRAP_METHOD(void withdraw_notification(const Glib::ustring& id), g_application_withdraw_notification) _WRAP_PROPERTY("action-group", Glib::RefPtr) _WRAP_PROPERTY("application-id", Glib::ustring) _WRAP_PROPERTY("flags", ApplicationFlags) _WRAP_PROPERTY("inactivity-timeout", guint) _WRAP_PROPERTY("is-registered", bool) _WRAP_PROPERTY("is-remote", bool) //#m4 _CONVERSION(`const gchar*', `const Glib::ustring&', `Glib::ustring($3)') //#m4 _CONVERSION(`GVariant*', `const Glib::VariantBase&', `Glib::wrap($3, true)') _WRAP_SIGNAL(void startup(), "startup") _WRAP_SIGNAL(void activate(), "activate") //We wrap the open signal without _WRAP_SIGNAL(), because we need to change its parameters. //See bug https://bugzilla.gnome.org/show_bug.cgi?id=637457 Glib::SignalProxy2< void, const type_vec_files&, const Glib::ustring& > signal_open(); _IGNORE_SIGNAL(open) #m4 _CONVERSION(`GApplicationCommandLine*', `const Glib::RefPtr&',`Glib::wrap($3, true)') _WRAP_SIGNAL(int command_line(const Glib::RefPtr& command_line), "command-line") //TODO: Remove no_default_handler when we can break ABI //TODO: Avoid the use of the Variants in the VariantDict? //TODO: Should options definitely be non-const? Confirm that the handler is meant to modify it. #m4 _CONVERSION(`GVariantDict*',`const Glib::RefPtr&',`Glib::wrap($3, true)') _WRAP_SIGNAL(int handle_local_options(const Glib::RefPtr& options), "handle-local-options", no_default_handler) protected: virtual void on_open(const type_vec_files& files, const Glib::ustring& hint); #m4begin _PUSH(SECTION_PCC_CLASS_INIT_DEFAULT_SIGNAL_HANDLERS) klass->open = &open_callback; _SECTION(SECTION_PH_DEFAULT_SIGNAL_HANDLERS) static void open_callback(GApplication* self, GFile** files, gint n_files, const gchar* hint); _POP() #m4end #m4 _CONVERSION(`char**&', `gchar***',`&($3)') #m4 _CONVERSION(`gchar***', `char**&',`*($3)') _WRAP_VFUNC(bool local_command_line(char**& arguments, int& exit_status), local_command_line) #m4 _CONVERSION(`GVariant*',`const Glib::VariantBase&',`Glib::wrap($3,true)') _WRAP_VFUNC(void before_emit(const Glib::VariantBase& platform_data), "before_emit") _WRAP_VFUNC(void after_emit(const Glib::VariantBase& platform_data), "after_emit") //TODO: File a bug about GVariantBuilder not being registered with the GType system first: //_WRAP_VFUNC(void add_platform_data(Glib::VariantBuilder* builder), "add_platform_data") _WRAP_VFUNC(void quit_mainloop(), "quit_mainloop") _WRAP_VFUNC(void run_mainloop(), "run_mainloop") private: /** This is just a way to call Glib::init() (which calls g_type_init()) before * calling application_class_.init(), so that * g_application_get_type() will always succeed. * See https://bugzilla.gnome.org/show_bug.cgi?id=639925 */ const Glib::Class& custom_class_init(); }; } // namespace Gio