From 2f0039e7dd11e86ecd4c66ee9ca52d05fa3fe296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 6 Jul 2016 19:56:47 +0200 Subject: [PATCH] app: Add a construct-only app-info property This will allow us to create a ShellApp from JS code, for instance for .desktop files that aren't known to the AppSystem. https://bugzilla.gnome.org/show_bug.cgi?id=762206 --- src/shell-app.c | 54 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/shell-app.c b/src/shell-app.c index 1593c8915..7f61dc369 100644 --- a/src/shell-app.c +++ b/src/shell-app.c @@ -96,7 +96,8 @@ enum { PROP_ID, PROP_DBUS_ID, PROP_ACTION_GROUP, - PROP_MENU + PROP_MENU, + PROP_APP_INFO }; enum { @@ -138,6 +139,29 @@ shell_app_get_property (GObject *gobject, if (app->running_state) g_value_set_object (value, app->running_state->remote_menu); break; + case PROP_APP_INFO: + if (app->info) + g_value_set_object (value, app->info); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); + break; + } +} + +static void +shell_app_set_property (GObject *gobject, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + ShellApp *app = SHELL_APP (gobject); + + switch (prop_id) + { + case PROP_APP_INFO: + _shell_app_set_app_info (app, g_value_get_object (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; @@ -806,9 +830,9 @@ _shell_app_new (GDesktopAppInfo *info) { ShellApp *app; - app = g_object_new (SHELL_TYPE_APP, NULL); - - _shell_app_set_app_info (app, info); + app = g_object_new (SHELL_TYPE_APP, + "app-info", info, + NULL); return app; } @@ -817,12 +841,11 @@ void _shell_app_set_app_info (ShellApp *app, GDesktopAppInfo *info) { - g_clear_object (&app->info); - app->info = g_object_ref (info); + g_set_object (&app->info, info); - if (app->name_collation_key != NULL) - g_free (app->name_collation_key); - app->name_collation_key = g_utf8_collate_key (shell_app_get_name (app), -1); + g_clear_pointer (&app->name_collation_key, g_free); + if (app->info) + app->name_collation_key = g_utf8_collate_key (shell_app_get_name (app), -1); } static void @@ -1405,6 +1428,7 @@ shell_app_class_init(ShellAppClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->get_property = shell_app_get_property; + gobject_class->set_property = shell_app_set_property; gobject_class->dispose = shell_app_dispose; gobject_class->finalize = shell_app_finalize; @@ -1483,5 +1507,17 @@ shell_app_class_init(ShellAppClass *klass) "The primary menu exported by the remote application", G_TYPE_MENU_MODEL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + /** + * ShellApp:app-info: + * + * The #GDesktopAppInfo associated with this ShellApp, if any. + */ + g_object_class_install_property (gobject_class, + PROP_APP_INFO, + g_param_spec_object ("app-info", + "DesktopAppInfo", + "The DesktopAppInfo associated with this app", + G_TYPE_DESKTOP_APP_INFO, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); }