aboutsummaryrefslogtreecommitdiff
path: root/src/app-menu-item.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/app-menu-item.c')
-rw-r--r--src/app-menu-item.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/app-menu-item.c b/src/app-menu-item.c
index c769d47..f973e33 100644
--- a/src/app-menu-item.c
+++ b/src/app-menu-item.c
@@ -25,7 +25,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#include <glib/gi18n.h>
-#include <gtk/gtk.h>
#include <gio/gdesktopappinfo.h>
#include "app-menu-item.h"
@@ -48,8 +47,6 @@ struct _AppMenuItemPrivate
GAppInfo * appinfo;
guint unreadcount;
gboolean count_on_label;
-
- GtkWidget * name;
};
#define APP_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_MENU_ITEM_TYPE, AppMenuItemPrivate))
@@ -68,7 +65,7 @@ static void update_label (AppMenuItem * self);
-G_DEFINE_TYPE (AppMenuItem, app_menu_item, GTK_TYPE_MENU_ITEM);
+G_DEFINE_TYPE (AppMenuItem, app_menu_item, DBUSMENU_TYPE_MENUITEM);
static void
app_menu_item_class_init (AppMenuItemClass *klass)
@@ -106,7 +103,6 @@ app_menu_item_init (AppMenuItem *self)
priv->listener = NULL;
priv->server = NULL;
- priv->name = NULL;
priv->type = NULL;
priv->appinfo = NULL;
priv->unreadcount = 0;
@@ -119,6 +115,14 @@ app_menu_item_init (AppMenuItem *self)
static void
app_menu_item_dispose (GObject *object)
{
+ AppMenuItem * self = APP_MENU_ITEM(object);
+ AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self);
+
+ g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), G_CALLBACK(indicator_added_cb), self);
+ g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), G_CALLBACK(indicator_removed_cb), self);
+
+ g_object_unref(priv->listener);
+
G_OBJECT_CLASS (app_menu_item_parent_class)->dispose (object);
}
@@ -128,8 +132,13 @@ app_menu_item_finalize (GObject *object)
AppMenuItem * self = APP_MENU_ITEM(object);
AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self);
- g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), G_CALLBACK(indicator_added_cb), self);
- g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), G_CALLBACK(indicator_removed_cb), self);
+ if (priv->type != NULL) {
+ g_free(priv->type);
+ }
+
+ if (priv->appinfo != NULL) {
+ g_object_unref(priv->appinfo);
+ }
G_OBJECT_CLASS (app_menu_item_parent_class)->finalize (object);
@@ -144,21 +153,17 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server)
AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self);
priv->listener = listener;
+ g_object_ref(G_OBJECT(listener));
priv->server = server;
+ /* Can not ref as not real GObject */
g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added_cb), self);
g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed_cb), self);
- priv->name = gtk_label_new(INDICATE_LISTENER_SERVER_DBUS_NAME(server));
- gtk_misc_set_alignment(GTK_MISC(priv->name), 0.0, 0.5);
- gtk_widget_show(GTK_WIDGET(priv->name));
-
- gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(priv->name));
-
indicate_listener_server_get_type(listener, server, type_cb, self);
indicate_listener_server_get_desktop(listener, server, desktop_cb, self);
- g_signal_connect(G_OBJECT(self), "activate", G_CALLBACK(activate_cb), NULL);
+ g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL);
indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_DISPLAY);
indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_SIGNAL);
@@ -174,8 +179,14 @@ type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * v
if (priv->type != NULL) {
g_free(priv->type);
+ priv->type = NULL;
}
+ if (value == NULL) {
+ g_warning("Type value is NULL, that shouldn't really happen");
+ return;
+ }
+
priv->type = g_strdup(value);
if (!(!g_strcmp0(priv->type, "message.instant") || !g_strcmp0(priv->type, "message.micro") || !g_strcmp0(priv->type, "message.im"))) {
@@ -200,11 +211,11 @@ update_label (AppMenuItem * self)
if (priv->count_on_label && !priv->unreadcount < 1) {
/* TRANSLATORS: This is the name of the program and the number of indicators. So it
would read something like "Mail Client (5)" */
- gchar * label = g_strdup_printf(_("%s (%d)"), g_app_info_get_name(priv->appinfo), priv->unreadcount);
- gtk_label_set_text(GTK_LABEL(priv->name), label);
+ gchar * label = g_strdup_printf(_("%s (%d)"), app_menu_item_get_name(self), priv->unreadcount);
+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", label);
g_free(label);
} else {
- gtk_label_set_text(GTK_LABEL(priv->name), g_app_info_get_name(priv->appinfo));
+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", app_menu_item_get_name(self));
}
return;
@@ -228,7 +239,7 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar
g_return_if_fail(priv->appinfo != NULL);
update_label(self);
- g_signal_emit(G_OBJECT(self), signals[NAME_CHANGED], 0, g_app_info_get_name(priv->appinfo), TRUE);
+ g_signal_emit(G_OBJECT(self), signals[NAME_CHANGED], 0, app_menu_item_get_name(self), TRUE);
return;
}