aboutsummaryrefslogtreecommitdiff
path: root/libmessaging-menu
diff options
context:
space:
mode:
Diffstat (limited to 'libmessaging-menu')
-rw-r--r--libmessaging-menu/messaging-menu-app.c182
-rw-r--r--libmessaging-menu/messaging-menu-app.h3
2 files changed, 120 insertions, 65 deletions
diff --git a/libmessaging-menu/messaging-menu-app.c b/libmessaging-menu/messaging-menu-app.c
index 5e14d65..377aea0 100644
--- a/libmessaging-menu/messaging-menu-app.c
+++ b/libmessaging-menu/messaging-menu-app.c
@@ -19,7 +19,6 @@
#include "messaging-menu-app.h"
#include "indicator-messages-service.h"
-#include "gtupleaction.h"
#include <gio/gdesktopappinfo.h>
@@ -105,23 +104,18 @@ struct _MessagingMenuApp
gboolean status_set;
GSimpleActionGroup *source_actions;
GMenu *menu;
+ GDBusConnection *bus;
IndicatorMessagesService *messages_service;
guint watch_id;
+ guint action_export_id;
+ guint menu_export_id;
GCancellable *cancellable;
};
G_DEFINE_TYPE (MessagingMenuApp, messaging_menu_app, G_TYPE_OBJECT);
-enum
-{
- INDEX_COUNT,
- INDEX_TIME,
- INDEX_STRING,
- INDEX_DRAWS_ATTENTION
-};
-
enum {
PROP_0,
PROP_DESKTOP_ID,
@@ -166,44 +160,41 @@ export_menus_and_actions (GObject *source,
gpointer user_data)
{
MessagingMenuApp *app = user_data;
- GDBusConnection *bus;
GError *error = NULL;
- guint id;
gchar *object_path;
object_path = messaging_menu_app_get_dbus_object_path (app);
if (!object_path)
return;
- bus = g_bus_get_finish (res, &error);
- if (bus == NULL)
+ app->bus = g_bus_get_finish (res, &error);
+ if (app->bus == NULL)
{
g_warning ("unable to connect to session bus: %s", error->message);
g_error_free (error);
return;
}
- id = g_dbus_connection_export_action_group (bus,
- object_path,
- G_ACTION_GROUP (app->source_actions),
- &error);
- if (!id)
+ app->action_export_id = g_dbus_connection_export_action_group (app->bus,
+ object_path,
+ G_ACTION_GROUP (app->source_actions),
+ &error);
+ if (!app->action_export_id)
{
g_warning ("unable to export action group: %s", error->message);
- g_error_free (error);
+ g_clear_error (&error);
}
- id = g_dbus_connection_export_menu_model (bus,
- object_path,
- G_MENU_MODEL (app->menu),
- &error);
- if (!id)
+ app->menu_export_id = g_dbus_connection_export_menu_model (app->bus,
+ object_path,
+ G_MENU_MODEL (app->menu),
+ &error);
+ if (!app->menu_export_id)
{
g_warning ("unable to export menu: %s", error->message);
- g_error_free (error);
+ g_clear_error (&error);
}
- g_object_unref (bus);
g_free (object_path);
}
@@ -257,6 +248,20 @@ messaging_menu_app_dispose (GObject *object)
{
MessagingMenuApp *app = MESSAGING_MENU_APP (object);
+ if (app->bus)
+ {
+ if (app->action_export_id > 0)
+ g_dbus_connection_unexport_action_group (app->bus, app->action_export_id);
+
+ if (app->menu_export_id > 0)
+ g_dbus_connection_unexport_menu_model (app->bus, app->menu_export_id);
+
+ app->action_export_id = 0;
+ app->menu_export_id = 0;
+ g_object_unref (app->bus);
+ app->bus = NULL;
+ }
+
if (app->watch_id > 0)
{
g_bus_unwatch_name (app->watch_id);
@@ -416,6 +421,10 @@ messaging_menu_app_init (MessagingMenuApp *app)
{
app->registered = -1;
app->status_set = FALSE;
+ app->bus = NULL;
+
+ app->action_export_id = 0;
+ app->menu_export_id = 0;
app->cancellable = g_cancellable_new ();
@@ -596,9 +605,9 @@ global_status_changed (IndicatorMessagesService *service,
}
static void
-source_action_activated (GTupleAction *action,
- GVariant *parameter,
- gpointer user_data)
+source_action_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
MessagingMenuApp *app = user_data;
const gchar *name = g_action_get_name (G_ACTION (action));
@@ -617,7 +626,7 @@ messaging_menu_app_insert_source_action (MessagingMenuApp *app,
const gchar *label,
GVariant *state)
{
- GTupleAction *action;
+ GSimpleAction *action;
GMenuItem *menuitem;
g_return_if_fail (MESSAGING_MENU_IS_APP (app));
@@ -629,7 +638,7 @@ messaging_menu_app_insert_source_action (MessagingMenuApp *app,
return;
}
- action = g_tuple_action_new (id, state);
+ action = g_simple_action_new_stateful (id, NULL, state);
g_signal_connect (action, "activate",
G_CALLBACK (source_action_activated), app);
g_simple_action_group_insert (app->source_actions, G_ACTION (action));
@@ -647,25 +656,71 @@ messaging_menu_app_insert_source_action (MessagingMenuApp *app,
g_object_unref (menuitem);
}
-static void
-messaging_menu_app_set_source_action (MessagingMenuApp *app,
- const gchar *source_id,
- gsize index,
- GVariant *child)
+static GSimpleAction *
+messaging_menu_app_get_source_action (MessagingMenuApp *app,
+ const gchar *source_id)
+
{
GAction *action;
- g_return_if_fail (MESSAGING_MENU_IS_APP (app));
- g_return_if_fail (source_id != NULL);
+ g_return_val_if_fail (MESSAGING_MENU_IS_APP (app), NULL);
+ g_return_val_if_fail (source_id != NULL, NULL);
action = g_simple_action_group_lookup (app->source_actions, source_id);
if (action == NULL)
- {
- g_warning ("a source with id '%s' doesn't exist", source_id);
- return;
- }
+ g_warning ("a source with id '%s' doesn't exist", source_id);
+
+ return G_SIMPLE_ACTION (action);
+}
+
+static void
+messaging_menu_app_set_source_action (MessagingMenuApp *app,
+ const gchar *source_id,
+ guint count,
+ gint64 time,
+ const gchar *string)
+{
+ GSimpleAction *action;
+ GVariant *state;
+ gboolean draws_attention;
+ GVariant *new_state;
+
+ action = messaging_menu_app_get_source_action (app, source_id);
+ if (!action)
+ return;
+
+ state = g_action_get_state (G_ACTION (action));
+ g_variant_get_child (state, 3, "b", &draws_attention);
+
+ new_state = g_variant_new ("(uxsb)", count, time, string, draws_attention);
+ g_simple_action_set_state (action, new_state);
+
+ g_variant_unref (state);
+}
+
+static void
+messaging_menu_app_set_draws_attention (MessagingMenuApp *app,
+ const gchar *source_id,
+ gboolean draws_attention)
+{
+ GSimpleAction *action;
+ GVariant *state;
+ guint count;
+ gint64 time;
+ const gchar *string;
+ GVariant *new_state;
+
+ action = messaging_menu_app_get_source_action (app, source_id);
+ if (!action)
+ return;
- g_tuple_action_set_child (G_TUPLE_ACTION (action), index, child);
+ state = g_action_get_state (G_ACTION (action));
+ g_variant_get (state, "(ux&sb)", &count, &time, &string);
+
+ new_state = g_variant_new ("(uxsb)", count, time, string, TRUE);
+ g_simple_action_set_state (action, new_state);
+
+ g_variant_unref (state);
}
/**
@@ -1015,7 +1070,7 @@ messaging_menu_app_set_source_label (MessagingMenuApp *app,
* messaging_menu_app_set_source_icon:
* @app: a #MessagingMenuApp
* @source_id: a source id
- * @icon: the new icon for the source
+ * @icon: (allow-none): the new icon for the source
*
* Changes the icon of @source_id to @icon.
*/
@@ -1026,7 +1081,6 @@ messaging_menu_app_set_source_icon (MessagingMenuApp *app,
{
gint pos;
GMenuItem *item;
- gchar *iconstr;
g_return_if_fail (MESSAGING_MENU_IS_APP (app));
g_return_if_fail (source_id != NULL);
@@ -1035,11 +1089,22 @@ messaging_menu_app_set_source_icon (MessagingMenuApp *app,
if (item == NULL)
return;
- iconstr = icon ? g_icon_to_string (icon) : NULL;
- g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr);
+ if (icon)
+ {
+ gchar *iconstr;
+
+ iconstr = g_icon_to_string (icon);
+ g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr);
+
+ g_free (iconstr);
+ }
+ else
+ {
+ g_menu_item_set_attribute_value (item, "x-canonical-icon", NULL);
+ }
+
g_menu_replace_item (app->menu, pos, item);
- g_free (iconstr);
g_object_unref (item);
}
@@ -1055,8 +1120,7 @@ void messaging_menu_app_set_source_count (MessagingMenuApp *app,
const gchar *source_id,
guint count)
{
- messaging_menu_app_set_source_action (app, source_id, INDEX_COUNT,
- g_variant_new_uint32 (count));
+ messaging_menu_app_set_source_action (app, source_id, count, 0, "");
}
/**
@@ -1066,17 +1130,13 @@ void messaging_menu_app_set_source_count (MessagingMenuApp *app,
* @time: the new time for the source, in microseconds
*
* Updates the time of @source_id to @time.
- *
- * Note that the time is only displayed if the source does not also have a
- * count associated with it.
*/
void
messaging_menu_app_set_source_time (MessagingMenuApp *app,
const gchar *source_id,
gint64 time)
{
- messaging_menu_app_set_source_action (app, source_id, INDEX_TIME,
- g_variant_new_int64 (time));
+ messaging_menu_app_set_source_action (app, source_id, 0, time, "");
}
/**
@@ -1086,17 +1146,13 @@ messaging_menu_app_set_source_time (MessagingMenuApp *app,
* @str: the new string for the source
*
* Updates the string displayed next to @source_id to @str.
- *
- * Note that the string is only displayed if the source does not also have a
- * count or time associated with it.
*/
void
messaging_menu_app_set_source_string (MessagingMenuApp *app,
const gchar *source_id,
const gchar *str)
{
- messaging_menu_app_set_source_action (app, source_id, INDEX_STRING,
- g_variant_new_string (str));
+ messaging_menu_app_set_source_action (app, source_id, 0, 0, str);
}
/**
@@ -1114,8 +1170,7 @@ void
messaging_menu_app_draw_attention (MessagingMenuApp *app,
const gchar *source_id)
{
- messaging_menu_app_set_source_action (app, source_id, INDEX_DRAWS_ATTENTION,
- g_variant_new_boolean (TRUE));
+ messaging_menu_app_set_draws_attention (app, source_id, TRUE);
}
/**
@@ -1136,8 +1191,7 @@ void
messaging_menu_app_remove_attention (MessagingMenuApp *app,
const gchar *source_id)
{
- messaging_menu_app_set_source_action (app, source_id, INDEX_DRAWS_ATTENTION,
- g_variant_new_boolean (FALSE));
+ messaging_menu_app_set_draws_attention (app, source_id, TRUE);
}
/**
diff --git a/libmessaging-menu/messaging-menu-app.h b/libmessaging-menu/messaging-menu-app.h
index aca46ec..a2d27bc 100644
--- a/libmessaging-menu/messaging-menu-app.h
+++ b/libmessaging-menu/messaging-menu-app.h
@@ -146,7 +146,8 @@ void messaging_menu_app_remove_attention (MessagingMenuA
void messaging_menu_app_append_message (MessagingMenuApp *app,
MessagingMenuMessage *msg,
- const gchar *source_id);
+ const gchar *source_id,
+ gboolean notify);
void messaging_menu_app_remove_message (MessagingMenuApp *app,
MessagingMenuMessage *msg);