[glib/wip/menus: 60/61] Add g_application_set_menu
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/menus: 60/61] Add g_application_set_menu
- Date: Thu, 17 Nov 2011 23:39:45 +0000 (UTC)
commit bc619534e0dcf120177ff73b34d3cdd78de554d7
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Nov 6 12:50:13 2011 -0500
Add g_application_set_menu
This gives a very easy way to export menu information alongside
the actions that are already exported by GApplication.
gio/gapplication.c | 53 ++++++++++++++++++++++++++++++++++++++++++-
gio/gapplication.h | 4 +++
gio/gapplicationimpl-dbus.c | 39 +++++++++++++++++++++++++++++++
gio/gio.symbols | 2 +
gio/giotypes.h | 2 +
gio/gmenumodel.h | 3 +-
6 files changed, 101 insertions(+), 2 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 9eaba61..17d39b9 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -27,6 +27,7 @@
#include "gapplicationcommandline.h"
#include "gapplicationimpl.h"
#include "gactiongroup.h"
+#include "gmenumodel.h"
#include "gsettings.h"
#include "gioenumtypes.h"
@@ -149,6 +150,7 @@ struct _GApplicationPrivate
gchar *id;
GActionGroup *actions;
+ GMenuModel *menu;
guint inactivity_timeout_id;
guint inactivity_timeout;
@@ -171,7 +173,8 @@ enum
PROP_IS_REGISTERED,
PROP_IS_REMOTE,
PROP_INACTIVITY_TIMEOUT,
- PROP_ACTION_GROUP
+ PROP_ACTION_GROUP,
+ PROP_MENU
};
enum
@@ -393,6 +396,11 @@ g_application_set_property (GObject *object,
g_value_get_object (value));
break;
+ case PROP_MENU:
+ g_application_set_menu (application,
+ g_value_get_object (value));
+ break;
+
default:
g_assert_not_reached ();
}
@@ -428,6 +436,42 @@ g_application_set_action_group (GApplication *application,
g_object_ref (application->priv->actions);
}
+/**
+ * g_application_set_menu:
+ * @application: a #GApplication
+ * @menu: (allow-none): a #GMenuModel, or %NULL
+ *
+ * Sets or unsets the menu associated with the application.
+ *
+ * It is an error to call this function after the application has been
+ * registered.
+ *
+ * Since: 2.32
+ */
+void
+g_application_set_menu (GApplication *application,
+ GMenuModel *menu)
+{
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (!application->priv->is_registered);
+
+ if (application->priv->menu != NULL)
+ g_object_unref (application->priv->menu);
+
+ application->priv->menu = menu;
+
+ if (application->priv->menu != NULL)
+ g_object_ref (application->priv->menu);
+}
+
+GMenuModel *
+g_application_get_menu (GApplication *application)
+{
+ g_return_if_fail (G_IS_APPLICATION (application));
+
+ return application->priv->menu;
+}
+
static void
g_application_get_property (GObject *object,
guint prop_id,
@@ -563,6 +607,13 @@ g_application_class_init (GApplicationClass *class)
G_TYPE_ACTION_GROUP,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_MENU,
+ g_param_spec_object ("menu",
+ P_("Menu model"),
+ P_("The menu that the application exports"),
+ G_TYPE_MENU_MODEL,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+
/**
* GApplication::startup:
* @application: the application
diff --git a/gio/gapplication.h b/gio/gapplication.h
index ce68220..3beb330 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -148,6 +148,10 @@ void g_application_set_flags (GApplic
void g_application_set_action_group (GApplication *application,
GActionGroup *action_group);
+void g_application_set_menu (GApplication *application,
+ GMenuModel *menu);
+GMenuModel *g_application_get_menu (GApplication *application);
+
gboolean g_application_get_is_registered (GApplication *application);
gboolean g_application_get_is_remote (GApplication *application);
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
index 57f1aa9..e32c8ff 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -29,6 +29,7 @@
#include "gdbusconnection.h"
#include "gdbusintrospection.h"
#include "gdbuserror.h"
+#include "gmenuexporter.h"
#include <string.h>
#include <stdio.h>
@@ -118,6 +119,7 @@ struct _GApplicationImpl
gchar *object_path;
guint object_id;
gboolean actions_exported;
+ gboolean menu_exported;
gpointer app;
};
@@ -238,6 +240,8 @@ g_application_impl_destroy (GApplicationImpl *impl)
impl->object_id);
if (impl->actions_exported)
g_action_group_exporter_stop (impl->app);
+ if (impl->menu_exported)
+ g_menu_exporter_stop (g_application_get_menu (impl->app));
g_object_unref (impl->session_bus);
g_free (impl->object_path);
@@ -324,6 +328,30 @@ g_application_impl_register (GApplication *application,
}
impl->actions_exported = TRUE;
+ if (g_application_get_menu (impl->app))
+ {
+ if (!g_menu_exporter_export (impl->session_bus,
+ impl->object_path,
+ g_application_get_menu (impl->app),
+ error))
+ {
+ g_action_group_exporter_stop (impl->app);
+ impl->actions_exported = FALSE;
+
+ g_dbus_connection_unregister_object (impl->session_bus,
+ impl->object_id);
+
+ g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
+ impl->session_bus = NULL;
+ impl->object_path = NULL;
+
+ g_slice_free (GApplicationImpl, impl);
+ return NULL;
+ }
+ impl->menu_exported = TRUE;
+ }
+
/* DBUS_NAME_FLAG_DO_NOT_QUEUE: 0x4 */
reply = g_dbus_connection_call_sync (impl->session_bus,
"org.freedesktop.DBus",
@@ -345,6 +373,12 @@ g_application_impl_register (GApplication *application,
g_action_group_exporter_stop (impl->app);
impl->actions_exported = FALSE;
+ if (impl->menu_exported)
+ {
+ g_menu_exporter_stop (g_application_get_menu (impl->app));
+ impl->menu_exported = FALSE;
+ }
+
g_object_unref (impl->session_bus);
g_free (impl->object_path);
impl->session_bus = NULL;
@@ -379,6 +413,11 @@ g_application_impl_register (GApplication *application,
impl->object_id = 0;
g_action_group_exporter_stop (impl->app);
impl->actions_exported = FALSE;
+ if (impl->menu_exported)
+ {
+ g_menu_exporter_stop (g_application_get_menu (impl->app));
+ impl->menu_exported = FALSE;
+ }
if (flags & G_APPLICATION_IS_SERVICE)
{
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 2bae0de..113b1e4 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -19,6 +19,7 @@ g_application_get_flags
g_application_get_inactivity_timeout
g_application_get_is_registered
g_application_get_is_remote
+g_application_get_menu
g_application_hold
g_application_id_is_valid
g_application_new
@@ -27,6 +28,7 @@ g_application_register
g_application_release
g_application_run
g_application_set_action_group
+g_application_set_menu
g_application_set_application_id
g_application_set_default
g_application_set_flags
diff --git a/gio/giotypes.h b/gio/giotypes.h
index 8db258c..c417ea8 100644
--- a/gio/giotypes.h
+++ b/gio/giotypes.h
@@ -58,6 +58,8 @@ typedef struct _GSettingsBackend GSettingsBackend;
typedef struct _GSettings GSettings;
typedef struct _GPermission GPermission;
+typedef struct _GMenuModel GMenuModel;
+
/**
* GDrive:
*
diff --git a/gio/gmenumodel.h b/gio/gmenumodel.h
index 3574cd1..154cc69 100644
--- a/gio/gmenumodel.h
+++ b/gio/gmenumodel.h
@@ -24,6 +24,8 @@
#include <glib-object.h>
+#include <gio/giotypes.h>
+
G_BEGIN_DECLS
#define G_MENU_ATTRIBUTE_ACTION (g_menu_model_get_action_quark ())
@@ -53,7 +55,6 @@ GQuark g_menu_model_get_section_quark (void) G
typedef struct _GMenuModelPrivate GMenuModelPrivate;
typedef struct _GMenuModelClass GMenuModelClass;
-typedef struct _GMenuModel GMenuModel;
typedef struct _GMenuAttributeIterPrivate GMenuAttributeIterPrivate;
typedef struct _GMenuAttributeIterClass GMenuAttributeIterClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]