diff options
author | Ken VanDine <ken.vandine@canonical.com> | 2010-07-29 13:33:14 -0400 |
---|---|---|
committer | Ken VanDine <ken.vandine@canonical.com> | 2010-07-29 13:33:14 -0400 |
commit | 1fa02756377589c14a80c0f96426f5b902bede03 (patch) | |
tree | 1c4706f77c5449a39b24170f013dcd9b150e30c2 /src | |
parent | e6b0746782acf425a1033cbddf00c13b3dae39c3 (diff) | |
parent | 657571f91da4aa7ce96309a0fd234a2a30878140 (diff) | |
download | ayatana-indicator-messages-1fa02756377589c14a80c0f96426f5b902bede03.tar.gz ayatana-indicator-messages-1fa02756377589c14a80c0f96426f5b902bede03.tar.bz2 ayatana-indicator-messages-1fa02756377589c14a80c0f96426f5b902bede03.zip |
Import upstream version 0.3.8
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.in | 5 | ||||
-rw-r--r-- | src/app-menu-item.c | 73 | ||||
-rw-r--r-- | src/app-menu-item.h | 6 | ||||
-rw-r--r-- | src/indicator-messages.c | 132 | ||||
-rw-r--r-- | src/messages-service-server.h | 6 | ||||
-rw-r--r-- | src/messages-service.c | 92 |
6 files changed, 224 insertions, 90 deletions
diff --git a/src/Makefile.in b/src/Makefile.in index 756fbc9..6e6cc22 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -39,7 +39,10 @@ libexec_PROGRAMS = indicator-messages-service$(EXEEXT) subdir = src DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__aclocal_m4_deps = $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs diff --git a/src/app-menu-item.c b/src/app-menu-item.c index ef30333..c276a90 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -36,7 +36,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>. enum { COUNT_CHANGED, NAME_CHANGED, - SHORTCUTS_CHANGED, + SHORTCUT_ADDED, + SHORTCUT_REMOVED, LAST_SIGNAL }; @@ -100,13 +101,20 @@ app_menu_item_class_init (AppMenuItemClass *klass) NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); - signals[SHORTCUTS_CHANGED] = g_signal_new(APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, + signals[SHORTCUT_ADDED] = g_signal_new(APP_MENU_ITEM_SIGNAL_SHORTCUT_ADDED, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AppMenuItemClass, shortcuts_changed), + G_STRUCT_OFFSET (AppMenuItemClass, shortcut_added), NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0, G_TYPE_NONE); + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, G_TYPE_OBJECT); + signals[SHORTCUT_REMOVED] = g_signal_new(APP_MENU_ITEM_SIGNAL_SHORTCUT_REMOVED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (AppMenuItemClass, shortcut_removed), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, G_TYPE_OBJECT); return; } @@ -137,6 +145,7 @@ app_menu_item_init (AppMenuItem *self) static void func_unref (gpointer data, gpointer user_data) { + g_signal_emit(user_data, signals[SHORTCUT_REMOVED], 0, data, TRUE); g_object_unref(G_OBJECT(data)); return; } @@ -155,10 +164,9 @@ app_menu_item_dispose (GObject *object) } if (priv->shortcuts != NULL) { - g_list_foreach(priv->shortcuts, func_unref, NULL); + g_list_foreach(priv->shortcuts, func_unref, object); g_list_free(priv->shortcuts); priv->shortcuts = NULL; - g_signal_emit(object, signals[SHORTCUTS_CHANGED], 0, TRUE); } if (priv->root != NULL) { @@ -351,7 +359,7 @@ child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint positio priv->shortcuts = g_list_insert(priv->shortcuts, mip, position); - g_signal_emit(G_OBJECT(data), signals[SHORTCUTS_CHANGED], 0, TRUE); + g_signal_emit(G_OBJECT(data), signals[SHORTCUT_ADDED], 0, mip, TRUE); return; } @@ -377,10 +385,10 @@ child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer da if (pitems != NULL) { DbusmenuMenuitemProxy * mip = DBUSMENU_MENUITEM_PROXY(pitems->data); - g_object_unref(mip); priv->shortcuts = g_list_remove(priv->shortcuts, mip); - g_signal_emit(G_OBJECT(data), signals[SHORTCUTS_CHANGED], 0, TRUE); + g_signal_emit(G_OBJECT(data), signals[SHORTCUT_REMOVED], 0, mip, TRUE); + g_object_unref(mip); } return; @@ -406,7 +414,7 @@ child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, if (mip != NULL) { priv->shortcuts = g_list_remove(priv->shortcuts, mip); priv->shortcuts = g_list_insert(priv->shortcuts, mip, newpos); - g_signal_emit(G_OBJECT(data), signals[SHORTCUTS_CHANGED], 0, TRUE); + g_signal_emit(G_OBJECT(data), signals[SHORTCUT_ADDED], 0, NULL, TRUE); } return; @@ -420,12 +428,10 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data g_debug("Root Changed"); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); - gboolean change_time = FALSE; if (priv->root != NULL) { if (dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)) != NULL) { - change_time = TRUE; - g_list_foreach(priv->shortcuts, func_unref, NULL); + g_list_foreach(priv->shortcuts, func_unref, data); g_list_free(priv->shortcuts); priv->shortcuts = NULL; } @@ -436,27 +442,26 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data /* We need to proxy the new root across to the old world of indicator land. */ priv->root = newroot; - g_object_ref(priv->root); - g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(child_added_cb), self); - g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(child_removed_cb), self); - g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(child_moved_cb), self); - - /* See if we have any menuitems to worry about, - otherwise we'll just move along. */ - GList * children = dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)); - if (children != NULL) { - change_time = TRUE; - g_debug("\tProcessing %d children", g_list_length(children)); - while (children != NULL) { - DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(DBUSMENU_MENUITEM(children->data)); - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(mip), DBUSMENU_MENUITEM_PROP_ICON_NAME, DBUSMENU_MENUITEM_ICON_NAME_BLANK); - priv->shortcuts = g_list_append(priv->shortcuts, mip); - children = g_list_next(children); - } - } - if (change_time) { - g_signal_emit(G_OBJECT(self), signals[SHORTCUTS_CHANGED], 0, TRUE); + if (priv->root != NULL) { + g_object_ref(priv->root); + g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(child_added_cb), self); + g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(child_removed_cb), self); + g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(child_moved_cb), self); + + /* See if we have any menuitems to worry about, + otherwise we'll just move along. */ + GList * children = dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)); + if (children != NULL) { + g_debug("\tProcessing %d children", g_list_length(children)); + while (children != NULL) { + DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(DBUSMENU_MENUITEM(children->data)); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(mip), DBUSMENU_MENUITEM_PROP_ICON_NAME, DBUSMENU_MENUITEM_ICON_NAME_BLANK); + priv->shortcuts = g_list_append(priv->shortcuts, mip); + g_signal_emit(G_OBJECT(self), signals[SHORTCUT_ADDED], 0, mip, TRUE); + children = g_list_next(children); + } + } } return; diff --git a/src/app-menu-item.h b/src/app-menu-item.h index 48a7cfa..d616856 100644 --- a/src/app-menu-item.h +++ b/src/app-menu-item.h @@ -39,7 +39,8 @@ G_BEGIN_DECLS #define APP_MENU_ITEM_SIGNAL_COUNT_CHANGED "count-changed" #define APP_MENU_ITEM_SIGNAL_NAME_CHANGED "name-changed" -#define APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED "shortcuts-changed" +#define APP_MENU_ITEM_SIGNAL_SHORTCUT_ADDED "shortcut-added" +#define APP_MENU_ITEM_SIGNAL_SHORTCUT_REMOVED "shortcut-removed" typedef struct _AppMenuItem AppMenuItem; typedef struct _AppMenuItemClass AppMenuItemClass; @@ -49,7 +50,8 @@ struct _AppMenuItemClass { void (* count_changed) (guint count); void (* name_changed) (gchar * name); - void (* shortcuts_changed) (void); + void (* shortcut_added) (DbusmenuMenuitem * mi); + void (* shortcut_removed) (DbusmenuMenuitem * mi); }; struct _AppMenuItem { diff --git a/src/indicator-messages.c b/src/indicator-messages.c index f47eccd..df2d972 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -44,6 +44,11 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define IS_INDICATOR_MESSAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_MESSAGES_TYPE)) #define INDICATOR_MESSAGES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_MESSAGES_TYPE, IndicatorMessagesClass)) +#define M_PI 3.1415926535897932384626433832795028841971693993751 + +#define RIGHT_LABEL_FONT_SIZE 12 +#define RIGHT_LABEL_RADIUS 20 + typedef struct _IndicatorMessages IndicatorMessages; typedef struct _IndicatorMessagesClass IndicatorMessagesClass; @@ -285,6 +290,115 @@ application_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, return; } +/* Draws a triangle on the left, using fg[STATE_TYPE] color. */ +static gboolean +application_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + GtkStyle *style; + cairo_t *cr; + int x, y, arrow_width, arrow_height; + + if (!GTK_IS_WIDGET (widget)) return FALSE; + + /* get style */ + style = gtk_widget_get_style (widget); + + /* set arrow position / dimensions */ + arrow_width = (int) ((double)widget->allocation.height * 0.25f); + arrow_height = (int) ((double)widget->allocation.height * 0.50f); + x = widget->allocation.x; + y = widget->allocation.y + widget->allocation.height/2.0 - (double)arrow_height/2.0; + + /* initialize cairo drawing area */ + cr = (cairo_t*) gdk_cairo_create (widget->window); + + /* set line width */ + cairo_set_line_width (cr, 1.0); + + /* cairo drawing code */ + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + arrow_height); + cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); + cairo_close_path (cr); + cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0); + cairo_fill (cr); + + /* remember to destroy cairo context to avoid leaks */ + cairo_destroy (cr); + + return FALSE; +} + +/* Custom function to draw rounded rectangle with max radius */ +static void +custom_cairo_rounded_rectangle (cairo_t *cr, + double x, double y, double w, double h) +{ + double radius = MIN (w/2.0, h/2.0); + + cairo_move_to (cr, x+radius, y); + cairo_arc (cr, x+w-radius, y+radius, radius, M_PI*1.5, M_PI*2); + cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, M_PI*0.5); + cairo_arc (cr, x+radius, y+h-radius, radius, M_PI*0.5, M_PI); + cairo_arc (cr, x+radius, y+radius, radius, M_PI, M_PI*1.5); +} + +/* Draws a rounded rectangle with text inside. */ +static gboolean +numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + GtkStyle *style; + cairo_t *cr; + double x, y, w, h; + PangoLayout * layout; + gint font_size = RIGHT_LABEL_FONT_SIZE; + + if (!GTK_IS_WIDGET (widget)) return FALSE; + + /* get style */ + style = gtk_widget_get_style (widget); + + /* set arrow position / dimensions */ + w = widget->allocation.width; + h = widget->allocation.height; + x = widget->allocation.x; + y = widget->allocation.y; + + layout = gtk_label_get_layout (GTK_LABEL(widget)); + + /* This does not work, don't ask me why but font_size is 0. + * I wanted to use a dynamic font size to adjust the padding on left/right edges + * of the rounded rectangle. Andrea Cimitan */ + /* const PangoFontDescription * font_description = pango_layout_get_font_description (layout); + font_size = pango_font_description_get_size (font_description); */ + + /* initialize cairo drawing area */ + cr = (cairo_t*) gdk_cairo_create (widget->window); + + /* set line width */ + cairo_set_line_width (cr, 1.0); + + cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); + + /* cairo drawing code */ + custom_cairo_rounded_rectangle (cr, x - font_size/2.0, y, w + font_size, h); + + cairo_set_source_rgba (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0, 0.5); + + cairo_move_to (cr, x, y); + pango_cairo_layout_path (cr, layout); + cairo_fill (cr); + + /* remember to destroy cairo context to avoid leaks */ + cairo_destroy (cr); + + return TRUE; +} + /* Builds a menu item representing a running application in the messaging menu */ static gboolean @@ -317,25 +431,17 @@ new_application_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu gtk_container_add(GTK_CONTAINER(gmi), hbox); gtk_widget_show(hbox); - /* Build up the running icon */ - GtkWidget * running_icon = gtk_image_new_from_icon_name("application-running", GTK_ICON_SIZE_MENU); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gmi), running_icon); - gtk_widget_show(running_icon); - - /* Make sure it always appears */ - gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(gmi), TRUE); - /* Attach some of the standard GTK stuff */ dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); /* Make sure we can handle the label changing */ g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_prop_change_cb), label); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_icon_change_cb), icon); + g_signal_connect_after(G_OBJECT (gmi), "expose_event", G_CALLBACK (application_triangle_draw_cb), NULL); return TRUE; } - typedef struct _indicator_item_t indicator_item_t; struct _indicator_item_t { GtkWidget * icon; @@ -405,6 +511,7 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); gint padding = 4; + gint font_size = RIGHT_LABEL_FONT_SIZE; gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL); GtkWidget * hbox = gtk_hbox_new(FALSE, 0); @@ -455,8 +562,12 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm item. */ mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT)); gtk_size_group_add_widget(indicator_right_group, mi_data->right); + /* install extra decoration overlay */ + g_signal_connect (G_OBJECT (mi_data->right), "expose_event", + G_CALLBACK (numbers_draw_cb), NULL); + gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding); + gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding + font_size/2.0); gtk_widget_show(mi_data->right); gtk_container_add(GTK_CONTAINER(gmi), hbox); @@ -494,4 +605,3 @@ get_menu (IndicatorObject * io) return GTK_MENU(menu); } - diff --git a/src/messages-service-server.h b/src/messages-service-server.h index 5b862f6..51420b1 100644 --- a/src/messages-service-server.h +++ b/src/messages-service-server.h @@ -27,6 +27,7 @@ G_BEGIN_DECLS #define g_marshal_value_peek_boxed(v) g_value_get_boxed (v) #define g_marshal_value_peek_pointer(v) g_value_get_pointer (v) #define g_marshal_value_peek_object(v) g_value_get_object (v) +#define g_marshal_value_peek_variant(v) g_value_get_variant (v) #else /* !G_ENABLE_DEBUG */ /* WARNING: This code accesses GValues directly, which is UNSUPPORTED API. * Do not access GValues directly in your code. Instead, use the @@ -50,14 +51,15 @@ G_BEGIN_DECLS #define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer #define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer #define g_marshal_value_peek_object(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_variant(v) (v)->data[0].v_pointer #endif /* !G_ENABLE_DEBUG */ -/* NONE:POINTER (/tmp/dbus-binding-tool-c-marshallers.CACX2U:1) */ +/* NONE:POINTER */ #define dbus_glib_marshal__messages_service_server_VOID__POINTER g_cclosure_marshal_VOID__POINTER #define dbus_glib_marshal__messages_service_server_NONE__POINTER dbus_glib_marshal__messages_service_server_VOID__POINTER -/* BOOLEAN:POINTER,POINTER (/tmp/dbus-binding-tool-c-marshallers.CACX2U:2) */ +/* BOOLEAN:POINTER,POINTER */ extern void dbus_glib_marshal__messages_service_server_BOOLEAN__POINTER_POINTER (GClosure *closure, GValue *return_value, guint n_param_values, diff --git a/src/messages-service.c b/src/messages-service.c index 88da0e0..0783d91 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -55,7 +55,8 @@ static MessageServiceDbus * dbus_interface = NULL; #define DESKTOP_FILE_GROUP "Messaging Menu" #define DESKTOP_FILE_KEY_DESKTOP "DesktopFile" -static void server_shortcuts_changed (AppMenuItem * appitem, gpointer data); +static void server_shortcut_added (AppMenuItem * appitem, DbusmenuMenuitem * mi, gpointer data); +static void server_shortcut_removed (AppMenuItem * appitem, DbusmenuMenuitem * mi, gpointer data); static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); @@ -314,7 +315,7 @@ desktop_file_from_keyfile (const gchar * definition_file) } /* Add a definition file into the black list and eclipse - and launchers that have the same file. */ + any launchers that have the same file. */ static gboolean blacklist_add (gpointer udata) { @@ -358,7 +359,7 @@ blacklist_add_core (gchar * desktop, gchar * definition) } /* Actually blacklist this thing */ - g_hash_table_insert(blacklist, desktop, definition); + g_hash_table_insert(blacklist, g_strdup(desktop), g_strdup(definition)); g_debug("Adding Blacklist item '%s' for desktop '%s'", definition, desktop); /* Go through and eclipse folks */ @@ -582,7 +583,8 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha /* Connect the signals up to the menu item */ g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_COUNT_CHANGED, G_CALLBACK(server_count_changed), sl_item); g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_NAME_CHANGED, G_CALLBACK(server_name_changed), menushell); - g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, G_CALLBACK(server_shortcuts_changed), menushell); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_SHORTCUT_ADDED, G_CALLBACK(server_shortcut_added), menushell); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_SHORTCUT_REMOVED, G_CALLBACK(server_shortcut_removed), menushell); /* Put our new menu item in, with the separator behind it. resort_menu will take care of whether it should be hidden @@ -605,47 +607,26 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha return; } -/* The shortcuts have changed, let's just remove them and put - the back. */ +/* Server shortcut has been added */ static void -server_shortcuts_changed (AppMenuItem * appitem, gpointer data) +server_shortcut_added (AppMenuItem * appitem, DbusmenuMenuitem * mi, gpointer data) { - g_debug("Application Shortcuts changed"); + g_debug("Application Shortcut added: %s", mi != NULL ? dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL) : "none"); DbusmenuMenuitem * shell = DBUSMENU_MENUITEM(data); - gboolean appitemfound = FALSE; - GList * children = dbusmenu_menuitem_get_children(shell); - GList * removelist = NULL; - - while (children != NULL) { - if (!appitemfound && children->data != appitem) { - children = g_list_next(children); - continue; - } - appitemfound = TRUE; - - if (!DBUSMENU_IS_MENUITEM_PROXY(children->data)) { - break; - } - - removelist = g_list_prepend(removelist, children->data); - } - - GList * removeitem; - for (removeitem = removelist; removeitem != NULL; removeitem = g_list_next(removeitem)) { - dbusmenu_menuitem_child_delete(shell, DBUSMENU_MENUITEM(removeitem->data)); - } - g_list_free(removeitem); - - GList * shortcuts = app_menu_item_get_items(appitem); - while (shortcuts != NULL) { - DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(shortcuts->data); - g_debug("\tAdding shortcut: %s", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL)); + if (mi != NULL) { dbusmenu_menuitem_child_append(shell, mi); - shortcuts = g_list_next(shortcuts); } - resort_menu(shell); + return; +} +/* Server shortcut has been removed */ +static void +server_shortcut_removed (AppMenuItem * appitem, DbusmenuMenuitem * mi, gpointer data) +{ + g_debug("Application Shortcut removed: %s", mi != NULL ? dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL) : "none"); + DbusmenuMenuitem * shell = DBUSMENU_MENUITEM(data); + dbusmenu_menuitem_child_delete(shell, mi); return; } @@ -756,16 +737,31 @@ server_removed (IndicateListener * listener, IndicateListenerServer * server, gc /* If there is a menu item, let's get rid of it. */ if (sltp->menuitem != NULL) { - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(sltp->menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + /* If there are shortcuts remove them */ + GList * shortcuts = app_menu_item_get_items(sltp->menuitem); + while (shortcuts != NULL) { + g_debug("\tRemoving shortcut: %s", dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(shortcuts->data), DBUSMENU_MENUITEM_PROP_LABEL)); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(shortcuts->data), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(shortcuts->data)); + shortcuts = g_list_next(shortcuts); + } + + g_debug("\tRemoving item"); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(sltp->menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(sltp->menuitem)); g_object_unref(G_OBJECT(sltp->menuitem)); + } else { + g_debug("\tNo menuitem"); } - + /* If there is a separator, let's get rid of it. */ if (sltp->separator != NULL) { + g_debug("\tRemoving separator"); dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(sltp->separator), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(sltp->separator)); g_object_unref(G_OBJECT(sltp->separator)); + } else { + g_debug("\tNo separator"); } if (sltp->attention) { @@ -1263,6 +1259,14 @@ destroy_launcher (gpointer data) g_list_free(li->appdiritems); if (li->menuitem != NULL) { + /* If there are shortcuts remove them */ + GList * shortcuts = launcher_menu_item_get_items(li->menuitem); + while (shortcuts != NULL) { + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(shortcuts->data), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(shortcuts->data)); + shortcuts = g_list_next(shortcuts); + } + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(li->menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_child_delete(root_menuitem, DBUSMENU_MENUITEM(li->menuitem)); g_object_unref(G_OBJECT(li->menuitem)); @@ -1358,6 +1362,14 @@ build_launcher_core (const gchar * desktop) dbusmenu_menuitem_property_set_bool(ll->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } + /* Check to see if any of the current applications should + be eclipsing us. */ + GList * server; + for (server = serverList; server != NULL; server = g_list_next(server)) { + serverList_t * slt = (serverList_t *)server->data; + check_eclipses(slt->menuitem); + } + resort_menu(root_menuitem); check_hidden(); } else { |