aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app-section.c19
-rw-r--r--src/im-application-list.c14
-rw-r--r--src/im-desktop-menu.c123
3 files changed, 109 insertions, 47 deletions
diff --git a/src/app-section.c b/src/app-section.c
index a741172..1a475f4 100644
--- a/src/app-section.c
+++ b/src/app-section.c
@@ -25,11 +25,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
#endif
-#include <gdk/gdk.h>
#include <glib/gi18n.h>
#include <gio/gdesktopappinfo.h>
#include <gio/gio.h>
-#include <libindicator/indicator-desktop-shortcuts.h>
+#include "indicator-desktop-shortcuts.h"
#include "app-section.h"
#include "dbus-data.h"
#include "gmenuutils.h"
@@ -290,17 +289,6 @@ app_section_finalize (GObject *object)
G_OBJECT_CLASS (app_section_parent_class)->dispose (object);
}
-static GAppLaunchContext *
-get_launch_context (guint32 timestamp)
-{
- GdkDisplay *display = gdk_display_get_default();
- GdkAppLaunchContext *launch_context = gdk_display_get_app_launch_context (display);
-
- gdk_app_launch_context_set_timestamp (launch_context, timestamp);
-
- return G_APP_LAUNCH_CONTEXT (launch_context);
-}
-
/* Respond to one of the shortcuts getting clicked on. */
static void
nick_activate_cb (GSimpleAction *action,
@@ -526,16 +514,13 @@ activate_cb (GSimpleAction *action,
AppSection * mi = APP_SECTION (userdata);
AppSectionPrivate * priv = mi->priv;
GError *error = NULL;
- GAppLaunchContext *launch_context = get_launch_context (g_variant_get_uint32 (param));
- if (!g_app_info_launch (G_APP_INFO (priv->appinfo), NULL, launch_context, &error)) {
+ if (!g_app_info_launch (G_APP_INFO (priv->appinfo), NULL, NULL, &error)) {
g_warning("Unable to execute application for desktop file '%s': %s",
g_desktop_app_info_get_filename (priv->appinfo),
error->message);
g_error_free (error);
}
-
- g_object_unref (launch_context);
}
static void
diff --git a/src/im-application-list.c b/src/im-application-list.c
index 1493adf..17fffdc 100644
--- a/src/im-application-list.c
+++ b/src/im-application-list.c
@@ -476,11 +476,12 @@ im_application_list_class_init (ImApplicationListClass *klass)
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
- 4,
+ 5,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
- G_TYPE_STRING);
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN);
signals[SOURCE_REMOVED] = g_signal_new ("source-removed",
IM_TYPE_APPLICATION_LIST,
@@ -539,7 +540,7 @@ im_application_list_class_init (ImApplicationListClass *klass)
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
+ g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE,
1,
G_TYPE_STRING);
@@ -806,6 +807,7 @@ im_application_list_source_changed (Application *app,
const gchar *string;
gboolean draws_attention;
gboolean old_draw;
+ gboolean visible;
g_variant_get (source, "(&s&s&sux&sb)",
&id, &label, &iconstr, &count, &time, &string, &draws_attention);
@@ -815,9 +817,11 @@ im_application_list_source_changed (Application *app,
g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), id,
g_variant_new ("(uxsb)", count, time, string, draws_attention));
- g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr);
+ visible = count > 0;
+
+ g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr, visible);
- if (!old_draw && draws_attention)
+ if (visible && !old_draw && draws_attention)
app->draws_attention = TRUE;
im_application_list_update_draws_attention (app->list);
diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c
index 834a8c9..5707390 100644
--- a/src/im-desktop-menu.c
+++ b/src/im-desktop-menu.c
@@ -106,49 +106,39 @@ im_desktop_menu_app_added (ImApplicationList *applist,
}
static void
-im_desktop_menu_source_added (ImApplicationList *applist,
- const gchar *app_id,
- const gchar *source_id,
- const gchar *label,
- const gchar *icon,
- gpointer user_data)
+im_desktop_menu_source_section_insert_source (GMenu *source_section,
+ const gchar *source_id,
+ const gchar *label,
+ const gchar *icon,
+ gint pos)
{
- ImDesktopMenu *menu = user_data;
- GMenu *source_section;
GMenuItem *item;
gchar *action;
- source_section = g_hash_table_lookup (menu->source_sections, app_id);
- g_return_if_fail (source_section != NULL);
-
action = g_strconcat ("src.", source_id, NULL);
item = g_menu_item_new (label, NULL);
- g_menu_item_set_action_and_target_value(item, action, NULL);
+ g_menu_item_set_action_and_target_value (item, action, NULL);
g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.source");
if (icon && *icon)
g_menu_item_set_attribute (item, "icon", "s", icon);
- g_menu_append_item (source_section, item);
+ if (pos >= 0)
+ g_menu_insert_item (source_section, pos, item);
+ else
+ g_menu_append_item (source_section, item);
g_free (action);
g_object_unref (item);
}
-static void
-im_desktop_menu_source_removed (ImApplicationList *applist,
- const gchar *app_id,
- const gchar *source_id,
- gpointer user_data)
+static gint
+im_desktop_menu_source_section_find_source (GMenu *source_section,
+ const gchar *source_id)
{
- ImDesktopMenu *menu = user_data;
- GMenu *source_section;
gint n_items;
gchar *action;
gint i;
- source_section = g_hash_table_lookup (menu->source_sections, app_id);
- g_return_if_fail (source_section != NULL);
-
n_items = g_menu_model_get_n_items (G_MENU_MODEL (source_section));
action = g_strconcat ("src.", source_id, NULL);
@@ -158,14 +148,80 @@ im_desktop_menu_source_removed (ImApplicationList *applist,
if (g_menu_model_get_item_attribute (G_MENU_MODEL (source_section), i, "action", "s", &item_action))
{
- if (g_str_equal (action, item_action))
- g_menu_remove (source_section, i);
+ gboolean equal;
+ equal = g_str_equal (action, item_action);
g_free (item_action);
+
+ if (equal)
+ break;
}
}
g_free (action);
+
+ return i < n_items ? i : -1;
+}
+
+
+static void
+im_desktop_menu_source_added (ImApplicationList *applist,
+ const gchar *app_id,
+ const gchar *source_id,
+ const gchar *label,
+ const gchar *icon,
+ gpointer user_data)
+{
+ ImDesktopMenu *menu = user_data;
+ GMenu *source_section;
+
+ source_section = g_hash_table_lookup (menu->source_sections, app_id);
+ g_return_if_fail (source_section != NULL);
+
+ im_desktop_menu_source_section_insert_source (source_section, source_id, label, icon, -1);
+}
+
+static void
+im_desktop_menu_source_removed (ImApplicationList *applist,
+ const gchar *app_id,
+ const gchar *source_id,
+ gpointer user_data)
+{
+ ImDesktopMenu *menu = user_data;
+ GMenu *source_section;
+ gint pos;
+
+ source_section = g_hash_table_lookup (menu->source_sections, app_id);
+ g_return_if_fail (source_section != NULL);
+
+ pos = im_desktop_menu_source_section_find_source (source_section, source_id);
+ if (pos >= 0)
+ g_menu_remove (source_section, pos);
+}
+
+static void
+im_desktop_menu_source_changed (ImApplicationList *applist,
+ const gchar *app_id,
+ const gchar *source_id,
+ const gchar *label,
+ const gchar *icon,
+ gboolean visible,
+ gpointer user_data)
+{
+ ImDesktopMenu *menu = user_data;
+ GMenu *section;
+ gint pos;
+
+ section = g_hash_table_lookup (menu->source_sections, app_id);
+ g_return_if_fail (section != NULL);
+
+ pos = im_desktop_menu_source_section_find_source (section, source_id);
+
+ if (pos >= 0)
+ g_menu_remove (section, pos);
+
+ if (visible)
+ im_desktop_menu_source_section_insert_source (section, source_id, label, icon, pos);
}
static void
@@ -184,6 +240,21 @@ im_desktop_menu_remove_all (ImApplicationList *applist,
}
}
+static void
+im_desktop_menu_app_stopped (ImApplicationList *applist,
+ const gchar *app_id,
+ gpointer user_data)
+{
+ ImDesktopMenu *menu = user_data;
+ GMenu *section;
+
+ section = g_hash_table_lookup (menu->source_sections, app_id);
+ g_return_if_fail (section != NULL);
+
+ while (g_menu_model_get_n_items (G_MENU_MODEL (section)) > 0)
+ g_menu_remove (section, 0);
+}
+
static GMenu *
create_status_section (void)
{
@@ -262,7 +333,9 @@ im_desktop_menu_constructed (GObject *object)
g_signal_connect (applist, "app-added", G_CALLBACK (im_desktop_menu_app_added), menu);
g_signal_connect (applist, "source-added", G_CALLBACK (im_desktop_menu_source_added), menu);
g_signal_connect (applist, "source-removed", G_CALLBACK (im_desktop_menu_source_removed), menu);
+ g_signal_connect (applist, "source-changed", G_CALLBACK (im_desktop_menu_source_changed), menu);
g_signal_connect (applist, "remove-all", G_CALLBACK (im_desktop_menu_remove_all), menu);
+ g_signal_connect (applist, "app-stopped", G_CALLBACK (im_desktop_menu_app_stopped), menu);
G_OBJECT_CLASS (im_desktop_menu_parent_class)->constructed (object);
}