mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
Add a StatusIcon property to org.gtk.Application
This property can contain a serialized GIcon for use as a status icon.
This commit is contained in:
parent
16d00d2453
commit
d6294655ab
@ -36,6 +36,7 @@
|
||||
#include "gioenumtypes.h"
|
||||
#include "gioenums.h"
|
||||
#include "gfile.h"
|
||||
#include "gicon.h"
|
||||
|
||||
#include "glibintl.h"
|
||||
|
||||
@ -240,6 +241,7 @@ struct _GApplicationPrivate
|
||||
GApplicationImpl *impl;
|
||||
|
||||
GNotificationBackend *notifications;
|
||||
GIcon *status_icon;
|
||||
|
||||
/* GOptionContext support */
|
||||
GOptionGroup *main_options;
|
||||
@ -261,7 +263,8 @@ enum
|
||||
PROP_IS_REMOTE,
|
||||
PROP_INACTIVITY_TIMEOUT,
|
||||
PROP_ACTION_GROUP,
|
||||
PROP_IS_BUSY
|
||||
PROP_IS_BUSY,
|
||||
PROP_STATUS_ICON
|
||||
};
|
||||
|
||||
enum
|
||||
@ -1125,8 +1128,7 @@ g_application_set_property (GObject *object,
|
||||
break;
|
||||
|
||||
case PROP_INACTIVITY_TIMEOUT:
|
||||
g_application_set_inactivity_timeout (application,
|
||||
g_value_get_uint (value));
|
||||
g_application_set_inactivity_timeout (application, g_value_get_uint (value));
|
||||
break;
|
||||
|
||||
case PROP_ACTION_GROUP:
|
||||
@ -1134,6 +1136,10 @@ g_application_set_property (GObject *object,
|
||||
application->priv->actions = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_STATUS_ICON:
|
||||
g_application_set_status_icon (application, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
@ -1214,6 +1220,10 @@ g_application_get_property (GObject *object,
|
||||
g_value_set_boolean (value, g_application_get_is_busy (application));
|
||||
break;
|
||||
|
||||
case PROP_STATUS_ICON:
|
||||
g_value_set_object (value, g_application_get_status_icon (application));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
@ -1270,8 +1280,9 @@ g_application_finalize (GObject *object)
|
||||
|
||||
g_free (application->priv->resource_path);
|
||||
|
||||
G_OBJECT_CLASS (g_application_parent_class)
|
||||
->finalize (object);
|
||||
g_clear_object (&application->priv->status_icon);
|
||||
|
||||
G_OBJECT_CLASS (g_application_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1391,6 +1402,13 @@ g_application_class_init (GApplicationClass *class)
|
||||
P_("If this application is currently marked busy"),
|
||||
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_STATUS_ICON,
|
||||
g_param_spec_object ("status-icon",
|
||||
P_("Status icon"),
|
||||
P_("The status icon for the application"),
|
||||
G_TYPE_ICON,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* GApplication::startup:
|
||||
* @application: the application
|
||||
@ -2927,5 +2945,29 @@ g_application_unbind_busy_property (GApplication *application,
|
||||
g_signal_handler_disconnect (object, handler_id);
|
||||
}
|
||||
|
||||
/* Status icon {{{1 */
|
||||
|
||||
void
|
||||
g_application_set_status_icon (GApplication *application,
|
||||
GIcon *icon)
|
||||
{
|
||||
g_return_if_fail (G_IS_APPLICATION (application));
|
||||
g_return_if_fail (icon == NULL || G_IS_ICON (icon));
|
||||
|
||||
if (g_set_object (&application->priv->status_icon, icon))
|
||||
{
|
||||
g_application_impl_set_status_icon (application->priv->impl, icon);
|
||||
g_object_notify (G_OBJECT (application), "status-icon");
|
||||
}
|
||||
}
|
||||
|
||||
GIcon *
|
||||
g_application_get_status_icon (GApplication *application)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
|
||||
|
||||
return application->priv->status_icon;
|
||||
}
|
||||
|
||||
/* Epilogue {{{1 */
|
||||
/* vim:set foldmethod=marker: */
|
||||
|
@ -238,6 +238,13 @@ void g_application_unbind_busy_property (GApplic
|
||||
gpointer object,
|
||||
const gchar *property);
|
||||
|
||||
GLIB_AVAILABLE_IN_2_54
|
||||
void g_application_set_status_icon (GApplication *application,
|
||||
GIcon *icon);
|
||||
|
||||
GLIB_AVAILABLE_IN_2_54
|
||||
GIcon * g_application_get_status_icon (GApplication *application);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_APPLICATION_H__ */
|
||||
|
@ -66,6 +66,7 @@ static const gchar org_gtk_Application_xml[] =
|
||||
"<arg type='i' name='exit-status' direction='out'/>"
|
||||
"</method>"
|
||||
"<property name='Busy' type='b' access='read'/>"
|
||||
"<property name='StatusIcon' type='v' access='read'/>"
|
||||
"</interface>"
|
||||
"</node>";
|
||||
|
||||
@ -121,6 +122,8 @@ struct _GApplicationImpl
|
||||
gboolean primary;
|
||||
gboolean busy;
|
||||
GApplication *app;
|
||||
|
||||
GIcon *status_icon;
|
||||
};
|
||||
|
||||
|
||||
@ -140,6 +143,8 @@ g_application_impl_get_property (GDBusConnection *connection,
|
||||
|
||||
if (strcmp (property_name, "Busy") == 0)
|
||||
return g_variant_new_boolean (impl->busy);
|
||||
else if (strcmp (property_name, "StatusIcon") == 0)
|
||||
return impl->status_icon ? g_icon_serialize (impl->status_icon) : g_variant_new_boolean (FALSE);
|
||||
|
||||
g_assert_not_reached ();
|
||||
|
||||
@ -152,9 +157,9 @@ send_property_change (GApplicationImpl *impl)
|
||||
GVariantBuilder builder;
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
||||
g_variant_builder_add (&builder,
|
||||
"{sv}",
|
||||
"Busy", g_variant_new_boolean (impl->busy));
|
||||
g_variant_builder_add (&builder, "{sv}", "Busy", g_variant_new_boolean (impl->busy));
|
||||
if (impl->status_icon)
|
||||
g_variant_builder_add (&builder, "{sv}", "StatusIcon", g_icon_serialize (impl->status_icon));
|
||||
|
||||
g_dbus_connection_emit_signal (impl->session_bus,
|
||||
NULL,
|
||||
@ -498,6 +503,13 @@ g_application_impl_set_busy_state (GApplicationImpl *impl,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_application_impl_set_status_icon (GApplicationImpl *impl,
|
||||
GIcon *icon)
|
||||
{
|
||||
if (g_set_object (&impl->status_icon, icon))
|
||||
send_property_change (impl);
|
||||
}
|
||||
void
|
||||
g_application_impl_destroy (GApplicationImpl *impl)
|
||||
{
|
||||
@ -508,6 +520,10 @@ g_application_impl_destroy (GApplicationImpl *impl)
|
||||
|
||||
g_free (impl->object_path);
|
||||
|
||||
g_clear_object (&impl->status_icon);
|
||||
|
||||
g_clear_object (&impl->status_icon);
|
||||
|
||||
g_slice_free (GApplicationImpl, impl);
|
||||
}
|
||||
|
||||
|
@ -42,3 +42,5 @@ const gchar * g_application_impl_get_dbus_object_path (GApplic
|
||||
|
||||
void g_application_impl_set_busy_state (GApplicationImpl *impl,
|
||||
gboolean busy);
|
||||
void g_application_impl_set_status_icon (GApplicationImpl *impl,
|
||||
GIcon *icon);
|
||||
|
Loading…
x
Reference in New Issue
Block a user