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
This commit is contained in:
Florian Müllner 2016-07-06 19:56:47 +02:00
parent 9202309bed
commit 2f0039e7dd

View File

@ -96,7 +96,8 @@ enum {
PROP_ID, PROP_ID,
PROP_DBUS_ID, PROP_DBUS_ID,
PROP_ACTION_GROUP, PROP_ACTION_GROUP,
PROP_MENU PROP_MENU,
PROP_APP_INFO
}; };
enum { enum {
@ -138,6 +139,29 @@ shell_app_get_property (GObject *gobject,
if (app->running_state) if (app->running_state)
g_value_set_object (value, app->running_state->remote_menu); g_value_set_object (value, app->running_state->remote_menu);
break; 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: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break; break;
@ -806,9 +830,9 @@ _shell_app_new (GDesktopAppInfo *info)
{ {
ShellApp *app; ShellApp *app;
app = g_object_new (SHELL_TYPE_APP, NULL); app = g_object_new (SHELL_TYPE_APP,
"app-info", info,
_shell_app_set_app_info (app, info); NULL);
return app; return app;
} }
@ -817,11 +841,10 @@ void
_shell_app_set_app_info (ShellApp *app, _shell_app_set_app_info (ShellApp *app,
GDesktopAppInfo *info) GDesktopAppInfo *info)
{ {
g_clear_object (&app->info); g_set_object (&app->info, info);
app->info = g_object_ref (info);
if (app->name_collation_key != NULL) g_clear_pointer (&app->name_collation_key, g_free);
g_free (app->name_collation_key); if (app->info)
app->name_collation_key = g_utf8_collate_key (shell_app_get_name (app), -1); app->name_collation_key = g_utf8_collate_key (shell_app_get_name (app), -1);
} }
@ -1405,6 +1428,7 @@ shell_app_class_init(ShellAppClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = shell_app_get_property; gobject_class->get_property = shell_app_get_property;
gobject_class->set_property = shell_app_set_property;
gobject_class->dispose = shell_app_dispose; gobject_class->dispose = shell_app_dispose;
gobject_class->finalize = shell_app_finalize; gobject_class->finalize = shell_app_finalize;
@ -1483,5 +1507,17 @@ shell_app_class_init(ShellAppClass *klass)
"The primary menu exported by the remote application", "The primary menu exported by the remote application",
G_TYPE_MENU_MODEL, G_TYPE_MENU_MODEL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); 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));
} }