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:
Matthias Clasen 2017-05-24 21:57:24 -04:00
parent 16d00d2453
commit d6294655ab
4 changed files with 75 additions and 8 deletions

View File

@ -36,6 +36,7 @@
#include "gioenumtypes.h" #include "gioenumtypes.h"
#include "gioenums.h" #include "gioenums.h"
#include "gfile.h" #include "gfile.h"
#include "gicon.h"
#include "glibintl.h" #include "glibintl.h"
@ -240,6 +241,7 @@ struct _GApplicationPrivate
GApplicationImpl *impl; GApplicationImpl *impl;
GNotificationBackend *notifications; GNotificationBackend *notifications;
GIcon *status_icon;
/* GOptionContext support */ /* GOptionContext support */
GOptionGroup *main_options; GOptionGroup *main_options;
@ -261,7 +263,8 @@ enum
PROP_IS_REMOTE, PROP_IS_REMOTE,
PROP_INACTIVITY_TIMEOUT, PROP_INACTIVITY_TIMEOUT,
PROP_ACTION_GROUP, PROP_ACTION_GROUP,
PROP_IS_BUSY PROP_IS_BUSY,
PROP_STATUS_ICON
}; };
enum enum
@ -1125,8 +1128,7 @@ g_application_set_property (GObject *object,
break; break;
case PROP_INACTIVITY_TIMEOUT: case PROP_INACTIVITY_TIMEOUT:
g_application_set_inactivity_timeout (application, g_application_set_inactivity_timeout (application, g_value_get_uint (value));
g_value_get_uint (value));
break; break;
case PROP_ACTION_GROUP: case PROP_ACTION_GROUP:
@ -1134,6 +1136,10 @@ g_application_set_property (GObject *object,
application->priv->actions = g_value_dup_object (value); application->priv->actions = g_value_dup_object (value);
break; break;
case PROP_STATUS_ICON:
g_application_set_status_icon (application, g_value_get_object (value));
break;
default: default:
g_assert_not_reached (); 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)); g_value_set_boolean (value, g_application_get_is_busy (application));
break; break;
case PROP_STATUS_ICON:
g_value_set_object (value, g_application_get_status_icon (application));
break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
} }
@ -1270,8 +1280,9 @@ g_application_finalize (GObject *object)
g_free (application->priv->resource_path); g_free (application->priv->resource_path);
G_OBJECT_CLASS (g_application_parent_class) g_clear_object (&application->priv->status_icon);
->finalize (object);
G_OBJECT_CLASS (g_application_parent_class)->finalize (object);
} }
static void static void
@ -1391,6 +1402,13 @@ g_application_class_init (GApplicationClass *class)
P_("If this application is currently marked busy"), P_("If this application is currently marked busy"),
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); 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: * GApplication::startup:
* @application: the application * @application: the application
@ -2927,5 +2945,29 @@ g_application_unbind_busy_property (GApplication *application,
g_signal_handler_disconnect (object, handler_id); 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 */ /* Epilogue {{{1 */
/* vim:set foldmethod=marker: */ /* vim:set foldmethod=marker: */

View File

@ -238,6 +238,13 @@ void g_application_unbind_busy_property (GApplic
gpointer object, gpointer object,
const gchar *property); 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 G_END_DECLS
#endif /* __G_APPLICATION_H__ */ #endif /* __G_APPLICATION_H__ */

View File

@ -66,6 +66,7 @@ static const gchar org_gtk_Application_xml[] =
"<arg type='i' name='exit-status' direction='out'/>" "<arg type='i' name='exit-status' direction='out'/>"
"</method>" "</method>"
"<property name='Busy' type='b' access='read'/>" "<property name='Busy' type='b' access='read'/>"
"<property name='StatusIcon' type='v' access='read'/>"
"</interface>" "</interface>"
"</node>"; "</node>";
@ -121,6 +122,8 @@ struct _GApplicationImpl
gboolean primary; gboolean primary;
gboolean busy; gboolean busy;
GApplication *app; GApplication *app;
GIcon *status_icon;
}; };
@ -140,6 +143,8 @@ g_application_impl_get_property (GDBusConnection *connection,
if (strcmp (property_name, "Busy") == 0) if (strcmp (property_name, "Busy") == 0)
return g_variant_new_boolean (impl->busy); 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 (); g_assert_not_reached ();
@ -152,9 +157,9 @@ send_property_change (GApplicationImpl *impl)
GVariantBuilder builder; GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
g_variant_builder_add (&builder, g_variant_builder_add (&builder, "{sv}", "Busy", g_variant_new_boolean (impl->busy));
"{sv}", if (impl->status_icon)
"Busy", g_variant_new_boolean (impl->busy)); g_variant_builder_add (&builder, "{sv}", "StatusIcon", g_icon_serialize (impl->status_icon));
g_dbus_connection_emit_signal (impl->session_bus, g_dbus_connection_emit_signal (impl->session_bus,
NULL, 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 void
g_application_impl_destroy (GApplicationImpl *impl) g_application_impl_destroy (GApplicationImpl *impl)
{ {
@ -508,6 +520,10 @@ g_application_impl_destroy (GApplicationImpl *impl)
g_free (impl->object_path); g_free (impl->object_path);
g_clear_object (&impl->status_icon);
g_clear_object (&impl->status_icon);
g_slice_free (GApplicationImpl, impl); g_slice_free (GApplicationImpl, impl);
} }

View File

@ -42,3 +42,5 @@ const gchar * g_application_impl_get_dbus_object_path (GApplic
void g_application_impl_set_busy_state (GApplicationImpl *impl, void g_application_impl_set_busy_state (GApplicationImpl *impl,
gboolean busy); gboolean busy);
void g_application_impl_set_status_icon (GApplicationImpl *impl,
GIcon *icon);