aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-08-11 09:27:46 -0500
committerTed Gould <ted@gould.cx>2011-08-11 09:27:46 -0500
commit6deeec596bef04ffaf469dfcf5197b36b41813cf (patch)
tree2266572ee35c31d2b2cff06fd36742f49f80a4d2 /src
parente4522e407e617103d5f4af75ddcc3f9cf726bedc (diff)
parent3e347a0dba56074bcd4023450afb1982e16e1684 (diff)
downloadayatana-indicator-messages-6deeec596bef04ffaf469dfcf5197b36b41813cf.tar.gz
ayatana-indicator-messages-6deeec596bef04ffaf469dfcf5197b36b41813cf.tar.bz2
ayatana-indicator-messages-6deeec596bef04ffaf469dfcf5197b36b41813cf.zip
Import upstream version 0.4.93
Diffstat (limited to 'src')
-rw-r--r--src/default-applications.c43
-rw-r--r--src/gen-messages-service.xml.c4
-rw-r--r--src/indicator-messages.c27
-rw-r--r--src/messages-service-dbus.c9
-rw-r--r--src/messages-service.c41
-rw-r--r--src/messages-service.xml4
6 files changed, 103 insertions, 25 deletions
diff --git a/src/default-applications.c b/src/default-applications.c
index afb5025..0382e4d 100644
--- a/src/default-applications.c
+++ b/src/default-applications.c
@@ -21,20 +21,22 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <glib.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gio/gdesktopappinfo.h>
#include "default-applications.h"
struct default_db_t {
const gchar * desktop_file;
+ const gchar * uri_scheme;
const gchar * name;
const gchar * setupname;
const gchar * icon;
};
struct default_db_t default_db[] = {
- {"evolution.desktop", N_("Mail"), N_("Set Up Mail..."), "applications-email-panel"},
- {"empathy.desktop", N_("Chat"), N_("Set Up Chat..."), "applications-chat-panel"},
- {"gwibber.desktop", N_("Broadcast"), N_("Set Up Broadcast Account..."), "applications-microblogging-panel"},
- {NULL, NULL}
+ {NULL, "mailto", N_("Mail"), N_("Set Up Mail..."), "applications-email-panel"},
+ {"empathy.desktop", NULL, N_("Chat"), N_("Set Up Chat..."), "applications-chat-panel"},
+ {"gwibber.desktop", NULL, N_("Broadcast"), N_("Set Up Broadcast Account..."), "applications-microblogging-panel"},
};
static struct default_db_t *
@@ -44,17 +46,40 @@ get_default_helper (const gchar * desktop_path)
gchar * basename = g_path_get_basename(desktop_path);
g_return_val_if_fail(basename != NULL, NULL);
+ gboolean found = FALSE;
gint i;
- for (i = 0; default_db[i].desktop_file != NULL; i++) {
- if (g_strcmp0(default_db[i].desktop_file, basename) == 0) {
- break;
+ gint length = G_N_ELEMENTS(default_db);
+ for (i = 0; i < length && !found; i++) {
+ if (default_db[i].desktop_file) {
+ if (g_strcmp0(default_db[i].desktop_file, basename) == 0) {
+ found = TRUE;
+ }
+ } else if (default_db[i].uri_scheme) {
+ GAppInfo *info = g_app_info_get_default_for_uri_scheme(default_db[i].uri_scheme);
+ if (!info) {
+ continue;
+ }
+
+ const gchar * filename = g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(info));
+ if (!filename) {
+ g_object_unref(info);
+ continue;
+ }
+
+ gchar * default_basename = g_path_get_basename(filename);
+ g_object_unref(info);
+ if (g_strcmp0(default_basename, basename) == 0) {
+ found = TRUE;
+ }
+
+ g_free(default_basename);
}
}
g_free(basename);
- if (default_db[i].desktop_file != NULL) {
- return &default_db[i];
+ if (found) {
+ return &default_db[i - 1];
}
return NULL;
diff --git a/src/gen-messages-service.xml.c b/src/gen-messages-service.xml.c
index 0a1c0d1..4e94dc3 100644
--- a/src/gen-messages-service.xml.c
+++ b/src/gen-messages-service.xml.c
@@ -4,15 +4,13 @@ const char * _messages_service =
" <interface name=\"com.canonical.indicator.messages.service\">\n"
"\n"
"<!-- Methods -->\n"
-" <method name=\"Watch\">\n"
-" <annotation name=\"org.freedesktop.DBus.GLib.Async\" value=\"true\" />\n"
-" </method>\n"
" <method name=\"AttentionRequested\">\n"
" <arg type=\"b\" name=\"dot\" direction=\"out\" />\n"
" </method>\n"
" <method name=\"IconShown\">\n"
" <arg type=\"b\" name=\"hidden\" direction=\"out\" />\n"
" </method>\n"
+" <method name=\"ClearAttention\" />\n"
"\n"
"<!-- Signals -->\n"
" <signal name=\"AttentionChanged\">\n"
diff --git a/src/indicator-messages.c b/src/indicator-messages.c
index bb88c57..82a9315 100644
--- a/src/indicator-messages.c
+++ b/src/indicator-messages.c
@@ -89,7 +89,10 @@ static void indicator_messages_dispose (GObject *object);
static void indicator_messages_finalize (GObject *object);
static GtkImage * get_icon (IndicatorObject * io);
static GtkMenu * get_menu (IndicatorObject * io);
-static const gchar * get_accessible_desc (IndicatorObject * io);
+static void indicator_messages_middle_click (IndicatorObject * io,
+ IndicatorObjectEntry * entry,
+ guint time, gpointer data);
+static const gchar * get_accessible_desc (IndicatorObject * io);
static void connection_change (IndicatorServiceManager * sm,
gboolean connected,
gpointer user_data);
@@ -131,6 +134,7 @@ indicator_messages_class_init (IndicatorMessagesClass *klass)
io_class->get_image = get_icon;
io_class->get_menu = get_menu;
io_class->get_accessible_desc = get_accessible_desc;
+ io_class->secondary_activate = indicator_messages_middle_click;
if (bus_node_info == NULL) {
GError * error = NULL;
@@ -755,3 +759,24 @@ get_accessible_desc (IndicatorObject * io)
{
return accessible_desc;
}
+
+/* Hide the notifications on middle-click over the indicator-messages */
+static void
+indicator_messages_middle_click (IndicatorObject * io, IndicatorObjectEntry * entry,
+ guint time, gpointer data)
+{
+ if (icon_proxy == NULL) {
+ return;
+ }
+
+ g_dbus_proxy_call(icon_proxy,
+ "ClearAttention",
+ NULL, /* params */
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout */
+ NULL, /* cancel */
+ NULL,
+ NULL);
+
+ return;
+}
diff --git a/src/messages-service-dbus.c b/src/messages-service-dbus.c
index 6cc33e0..1585ac0 100644
--- a/src/messages-service-dbus.c
+++ b/src/messages-service-dbus.c
@@ -200,7 +200,10 @@ message_service_dbus_new (void)
static void
bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data)
{
- MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data);
+ MessageServiceDbus * ms = MESSAGE_SERVICE_DBUS(user_data);
+ if (ms == NULL) { return; }
+
+ MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(ms);
if (g_strcmp0("AttentionRequested", method) == 0) {
g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", priv->dot));
@@ -208,6 +211,10 @@ bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar
} else if (g_strcmp0("IconShown", method) == 0) {
g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", priv->hidden));
return;
+ } else if (g_strcmp0("ClearAttention", method) == 0) {
+ message_service_dbus_set_attention(ms, FALSE);
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ return;
} else {
g_warning("Unknown function call '%s'", method);
}
diff --git a/src/messages-service.c b/src/messages-service.c
index 63549e3..43e79d3 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -28,6 +28,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libindicate/listener.h>
#include <libindicator/indicator-service.h>
#include <gio/gio.h>
+#include <glib/gi18n.h>
#include <libdbusmenu-glib/client.h>
#include <libdbusmenu-glib/server.h>
@@ -49,6 +50,7 @@ static GList * launcherList = NULL;
static DbusmenuMenuitem * root_menuitem = NULL;
static DbusmenuMenuitem * status_separator = NULL;
+static DbusmenuMenuitem * clear_attention = NULL;
static GMainLoop * mainloop = NULL;
static MessageServiceDbus * dbus_interface = NULL;
@@ -799,6 +801,8 @@ menushell_foreach_cb (DbusmenuMenuitem * data_mi, gpointer data_ms) {
AppMenuItem * appmenu = APP_MENU_ITEM(data_mi);
if (!g_strcmp0(INDICATE_LISTENER_SERVER_DBUS_NAME((IndicateListenerServer*)msl->server), INDICATE_LISTENER_SERVER_DBUS_NAME(app_menu_item_get_server(appmenu)))) {
msl->found = TRUE;
+ /* Return a position at the end of our shortcuts */
+ msl->position += g_list_length(app_menu_item_get_items(appmenu));
} else {
msl->position++;
}
@@ -835,7 +839,6 @@ resort_menu (DbusmenuMenuitem * menushell)
guint position = 0;
GList * serverentry;
GList * launcherentry = launcherList;
- DbusmenuMenuitem * last_separator = NULL;
g_debug("Reordering Menu:");
@@ -872,7 +875,6 @@ resort_menu (DbusmenuMenuitem * menushell)
if (!launcher_menu_item_get_eclipsed(li->menuitem)) {
/* Only clear the visiblity if we're not eclipsed */
dbusmenu_menuitem_property_set_bool(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
- last_separator = li->separator;
}
position++;
@@ -928,7 +930,6 @@ resort_menu (DbusmenuMenuitem * menushell)
/* Note, this isn't the last if we can't see it */
} else {
dbusmenu_menuitem_property_set_bool(si->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
- last_separator = si->separator;
}
dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->separator), position);
@@ -960,17 +961,15 @@ resort_menu (DbusmenuMenuitem * menushell)
if (!launcher_menu_item_get_eclipsed(li->menuitem)) {
/* Only clear the visiblity if we're not eclipsed */
dbusmenu_menuitem_property_set_bool(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
- last_separator = li->separator;
}
position++;
launcherentry = launcherentry->next;
}
- if (last_separator != NULL) {
- dbusmenu_menuitem_property_set_bool(last_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- } else {
- g_warning("No last separator on resort");
+ if (clear_attention != NULL) {
+ dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), clear_attention, position);
+ position++; /* Not needed, but reduce bugs on code tacked on here, compiler will remove */
}
return;
@@ -1439,12 +1438,31 @@ service_shutdown (IndicatorService * service, gpointer user_data)
return;
}
+/* Respond to changing status by updating the icon that
+ is on the panel */
static void
status_update_callback (void)
{
return;
}
+/* The clear attention item has been clicked on, what to do? */
+static void
+clear_attention_activate (DbusmenuMenuitem * mi, guint timestamp, MessageServiceDbus * dbus)
+{
+ message_service_dbus_set_attention(dbus, FALSE);
+ return;
+}
+
+/* Handle an update of the active state to ensure that we're
+ only enabled when we could do something. */
+static void
+clear_attention_handler (MessageServiceDbus * msd, gboolean attention, DbusmenuMenuitem * clearitem)
+{
+ dbusmenu_menuitem_property_set_bool(clearitem, DBUSMENU_MENUITEM_PROP_ENABLED, attention);
+ return;
+}
+
/* Oh, if you don't know what main() is for
we really shouldn't be talking. */
int
@@ -1484,6 +1502,13 @@ main (int argc, char ** argv)
dbusmenu_menuitem_property_set(status_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
dbusmenu_menuitem_child_append(root_menuitem, status_separator);
+ /* Add in the clear attention item */
+ clear_attention = dbusmenu_menuitem_new();
+ dbusmenu_menuitem_property_set(clear_attention, DBUSMENU_MENUITEM_PROP_LABEL, _("Clear Attention"));
+ dbusmenu_menuitem_child_append(root_menuitem, clear_attention);
+ g_signal_connect(G_OBJECT(dbus_interface), MESSAGE_SERVICE_DBUS_SIGNAL_ATTENTION_CHANGED, G_CALLBACK(clear_attention_handler), clear_attention);
+ g_signal_connect(G_OBJECT(clear_attention), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(clear_attention_activate), dbus_interface);
+
/* Start up the libindicate listener */
listener = indicate_listener_ref_default();
serverList = NULL;
diff --git a/src/messages-service.xml b/src/messages-service.xml
index 8a592db..d79049e 100644
--- a/src/messages-service.xml
+++ b/src/messages-service.xml
@@ -3,15 +3,13 @@
<interface name="com.canonical.indicator.messages.service">
<!-- Methods -->
- <method name="Watch">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="true" />
- </method>
<method name="AttentionRequested">
<arg type="b" name="dot" direction="out" />
</method>
<method name="IconShown">
<arg type="b" name="hidden" direction="out" />
</method>
+ <method name="ClearAttention" />
<!-- Signals -->
<signal name="AttentionChanged">