diff options
author | Ted Gould <ted@gould.cx> | 2010-03-23 15:01:56 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-03-23 15:01:56 -0500 |
commit | 69cdd18f4308cdaa19159c199a667d36c9f19bcf (patch) | |
tree | 4943c89b17b77691ffdbb337d972794b59817ab0 /src | |
parent | c02292c7020477df40431dbbadfa30e79ed6a79a (diff) | |
parent | bf2af66c70b116d0abd483b82b5a1e43a0dedd5f (diff) | |
download | ayatana-indicator-messages-69cdd18f4308cdaa19159c199a667d36c9f19bcf.tar.gz ayatana-indicator-messages-69cdd18f4308cdaa19159c199a667d36c9f19bcf.tar.bz2 ayatana-indicator-messages-69cdd18f4308cdaa19159c199a667d36c9f19bcf.zip |
updating to trunk
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/app-menu-item.c | 23 | ||||
-rw-r--r-- | src/default-applications.c | 91 | ||||
-rw-r--r-- | src/default-applications.h | 30 | ||||
-rw-r--r-- | src/im-menu-item.c | 21 | ||||
-rw-r--r-- | src/indicator-messages.c | 30 | ||||
-rw-r--r-- | src/launcher-menu-item.c | 17 |
7 files changed, 187 insertions, 27 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7a325c5..32f0b38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,6 +22,8 @@ libmessaging_la_LDFLAGS = -module -avoid-version ###################################### indicator_messages_service_SOURCES = \ + default-applications.h \ + default-applications.c \ messages-service.c \ messages-service-server.h \ messages-service-dbus.c \ diff --git a/src/app-menu-item.c b/src/app-menu-item.c index a37daf4..7db72bf 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -30,6 +30,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libdbusmenu-glib/menuitem-proxy.h> #include "app-menu-item.h" #include "dbus-data.h" +#include "default-applications.h" enum { COUNT_CHANGED, @@ -233,15 +234,20 @@ static void update_label (AppMenuItem * self) { AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + const gchar * name = get_default_name(priv->desktop); + + if (name == NULL) { + name = app_menu_item_get_name(self); + } if (priv->unreadcount > 0) { /* 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)"), app_menu_item_get_name(self), priv->unreadcount); + gchar * label = g_strdup_printf(_("%s (%d)"), _(name), priv->unreadcount); dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, label); g_free(label); } else { - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, app_menu_item_get_name(self)); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, _(name)); } return; @@ -308,10 +314,15 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar update_label(self); - GIcon * icon = g_app_info_get_icon(priv->appinfo); - gchar * iconstr = g_icon_to_string(icon); - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ICON_NAME, iconstr); - g_free(iconstr); + const gchar * def_icon = get_default_icon(priv->desktop); + if (def_icon == NULL) { + GIcon * icon = g_app_info_get_icon(priv->appinfo); + gchar * iconstr = g_icon_to_string(icon); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ICON_NAME, iconstr); + g_free(iconstr); + } else { + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ICON_NAME, def_icon); + } g_signal_emit(G_OBJECT(self), signals[NAME_CHANGED], 0, app_menu_item_get_name(self), TRUE); diff --git a/src/default-applications.c b/src/default-applications.c new file mode 100644 index 0000000..afb5025 --- /dev/null +++ b/src/default-applications.c @@ -0,0 +1,91 @@ +/* +Looking for the default applications. A quick lookup. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <glib.h> +#include <glib/gi18n.h> +#include "default-applications.h" + +struct default_db_t { + const gchar * desktop_file; + 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} +}; + +static struct default_db_t * +get_default_helper (const gchar * desktop_path) +{ + g_return_val_if_fail(desktop_path != NULL, NULL); + gchar * basename = g_path_get_basename(desktop_path); + g_return_val_if_fail(basename != NULL, NULL); + + gint i; + for (i = 0; default_db[i].desktop_file != NULL; i++) { + if (g_strcmp0(default_db[i].desktop_file, basename) == 0) { + break; + } + } + + g_free(basename); + + if (default_db[i].desktop_file != NULL) { + return &default_db[i]; + } + + return NULL; +} + +const gchar * +get_default_name (const gchar * desktop_path) +{ + struct default_db_t * db = get_default_helper(desktop_path); + + if (db == NULL) + return NULL; + return db->name; +} + +const gchar * +get_default_setup (const gchar * desktop_path) +{ + struct default_db_t * db = get_default_helper(desktop_path); + + if (db == NULL) + return NULL; + return db->setupname; +} + +const gchar * +get_default_icon (const gchar * desktop_path) +{ + struct default_db_t * db = get_default_helper(desktop_path); + + if (db == NULL) + return NULL; + return db->icon; +} diff --git a/src/default-applications.h b/src/default-applications.h new file mode 100644 index 0000000..0a32e7c --- /dev/null +++ b/src/default-applications.h @@ -0,0 +1,30 @@ +/* +Looking for the default applications. A quick lookup. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef DEFAULT_APPLICATIONS_H__ +#define DEFAULT_APPLICATIONS_H__ 1 + +const gchar * get_default_name (const gchar * desktop_path); +const gchar * get_default_setup (const gchar * desktop_path); +const gchar * get_default_icon (const gchar * desktop_path); + +#endif /* DEFAULT_APPLICATIONS_H__ */ + diff --git a/src/im-menu-item.c b/src/im-menu-item.c index ea9190a..5841d81 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -358,7 +358,7 @@ count_cb (IndicateListener * listener, IndicateListenerServer * server, Indicate this indicator should be calling for attention or not. If we are, we need to signal that. */ static void -attention_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data) +attention_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const GValue * propertydata, gpointer data) { g_debug("Got Attention Information"); ImMenuItem * self = IM_MENU_ITEM(data); @@ -373,10 +373,19 @@ attention_cb (IndicateListener * listener, IndicateListenerServer * server, Indi ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self); gboolean wantit; - if (propertydata == NULL || propertydata[0] == '\0' || !g_strcmp0(propertydata, "false")) { - wantit = FALSE; + if (G_VALUE_HOLDS_BOOLEAN(propertydata)) { + wantit = g_value_get_boolean(propertydata); + } else if (G_VALUE_HOLDS_STRING(propertydata)) { + const gchar * propstring = g_value_get_string(propertydata); + + if (propstring == NULL || propstring[0] == '\0' || !g_strcmp0(propstring, "false")) { + wantit = FALSE; + } else { + wantit = TRUE; + } } else { - wantit = TRUE; + g_warning("Got property '%s' of an unknown type.", property); + return; } if (priv->attention != wantit) { @@ -418,7 +427,7 @@ indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * ser } else if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_COUNT)) { indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_COUNT, count_cb, self); } else if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION)) { - indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, attention_cb, self); + indicate_listener_get_property_value(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, attention_cb, self); } else if (!g_strcmp0(property, "sender")) { /* This is a compatibility string with v1 and should be removed */ g_debug("Indicator is using 'sender' property which is a v1 string."); @@ -451,7 +460,7 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_property_time(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_TIME, time_cb, self); indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ICON, icon_cb, self); indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_COUNT, count_cb, self); - indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, attention_cb, self); + indicate_listener_get_property_value(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, attention_cb, self); indicate_listener_get_property(listener, server, indicator, "sender", sender_cb, self); g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL); diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 3f533a5..f6b2084 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -31,6 +31,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libindicator/indicator.h> #include <libindicator/indicator-object.h> +#include <libindicator/indicator-image-helper.h> #include "dbus-data.h" #include "messages-service-client.h" @@ -61,8 +62,6 @@ INDICATOR_SET_TYPE(INDICATOR_MESSAGES_TYPE) /* Globals */ static GtkWidget * main_image = NULL; -#define DESIGN_TEAM_SIZE design_team_size -static GtkIconSize design_team_size; static DBusGProxy * icon_proxy = NULL; static GtkSizeGroup * indicator_right_group = NULL; @@ -116,9 +115,9 @@ static void attention_changed_cb (DBusGProxy * proxy, gboolean dot, gpointer userdata) { if (dot) { - gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages-new", DESIGN_TEAM_SIZE); + indicator_image_helper_update(GTK_IMAGE(main_image), "indicator-messages-new"); } else { - gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages", DESIGN_TEAM_SIZE); + indicator_image_helper_update(GTK_IMAGE(main_image), "indicator-messages"); } return; } @@ -278,17 +277,24 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); - GtkWidget * hbox = gtk_hbox_new(FALSE, 4); + gint padding = 4; + gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL); + + GtkWidget * hbox = gtk_hbox_new(FALSE, 0); /* Icon, probably someone's face or avatar on an IM */ mi_data->icon = gtk_image_new(); + + /* Set the minimum size, we always want it to take space */ + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + gtk_widget_set_size_request(mi_data->icon, width, height); + GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(newitem, INDICATOR_MENUITEM_PROP_ICON); if (pixbuf != NULL) { /* If we've got a pixbuf we need to make sure it's of a reasonable size to fit in the menu. If not, rescale it. */ GdkPixbuf * resized_pixbuf; - gint width, height; - gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); if (gdk_pixbuf_get_width(pixbuf) > width || gdk_pixbuf_get_height(pixbuf) > height) { g_debug("Resizing icon from %dx%d to %dx%d", gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), width, height); @@ -309,13 +315,13 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm } } gtk_misc_set_alignment(GTK_MISC(mi_data->icon), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), mi_data->icon, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), mi_data->icon, FALSE, FALSE, padding); gtk_widget_show(mi_data->icon); /* Label, probably a username, chat room or mailbox name */ mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_LABEL)); gtk_misc_set_alignment(GTK_MISC(mi_data->label), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), mi_data->label, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox), mi_data->label, TRUE, TRUE, padding); gtk_widget_show(mi_data->label); /* Usually either the time or the count on the individual @@ -323,7 +329,7 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm 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); 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, 0); + gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding); gtk_widget_show(mi_data->right); gtk_container_add(GTK_CONTAINER(gmi), hbox); @@ -340,9 +346,7 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm static GtkImage * get_icon (IndicatorObject * io) { - design_team_size = gtk_icon_size_register("design-team-size", 22, 22); - - main_image = gtk_image_new_from_icon_name("indicator-messages", DESIGN_TEAM_SIZE); + main_image = GTK_WIDGET(indicator_image_helper("indicator-messages")); gtk_widget_show(main_image); return GTK_IMAGE(main_image); diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index 07b0546..279d167 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -30,6 +30,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libindicator/indicator-desktop-shortcuts.h> #include "launcher-menu-item.h" #include "dbus-data.h" +#include "default-applications.h" enum { NAME_CHANGED, @@ -161,8 +162,20 @@ launcher_menu_item_new (const gchar * desktop_file) /* Set the appropriate values on this menu item based on the app info that we've parsed */ g_debug("\tName: %s", launcher_menu_item_get_name(self)); - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, launcher_menu_item_get_name(self)); - gchar * iconstr = launcher_menu_item_get_icon(self); + + const gchar * default_name = get_default_name(desktop_file); + if (default_name == NULL) { + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, launcher_menu_item_get_name(self)); + } else { + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, _(default_name)); + } + + gchar * iconstr; + if (default_name == NULL) { + iconstr = launcher_menu_item_get_icon(self); + } else { + iconstr = g_strdup(get_default_icon(desktop_file)); + } dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ICON_NAME, iconstr); g_free(iconstr); dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); |