diff options
author | Ted Gould <ted@gould.cx> | 2010-03-25 10:50:13 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-03-25 10:50:13 -0500 |
commit | 272215246b7ddd8beb7ba622cef73e2c0c27ccfa (patch) | |
tree | 38cb6cb8f3cb919edb5cc39d7ac842335ea3b504 | |
parent | 28d358c7b459ef636800f253c362819773b91850 (diff) | |
parent | 791ebdf697b50b6a54e4d7dc4e1524e7f6c30b12 (diff) | |
download | ayatana-indicator-messages-272215246b7ddd8beb7ba622cef73e2c0c27ccfa.tar.gz ayatana-indicator-messages-272215246b7ddd8beb7ba622cef73e2c0c27ccfa.tar.bz2 ayatana-indicator-messages-272215246b7ddd8beb7ba622cef73e2c0c27ccfa.zip |
* Upstream release 0.3.5
* Shift command items to line up with application names.
(LP: #537312)
* Track applications we've seen so that we can show "Set Up"
text if we've not seen the app before.
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | debian/changelog | 16 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/app-menu-item.c | 5 | ||||
-rw-r--r-- | src/indicator-messages.c | 15 | ||||
-rw-r--r-- | src/launcher-menu-item.c | 53 | ||||
-rw-r--r-- | src/messages-service.c | 3 | ||||
-rw-r--r-- | src/seen-db.c | 177 | ||||
-rw-r--r-- | src/seen-db.h | 31 |
9 files changed, 283 insertions, 23 deletions
diff --git a/configure.ac b/configure.ac index 98fc5a5..e768823 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(src/indicator-messages.c) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-messages, 0.3.4) +AM_INIT_AUTOMAKE(indicator-messages, 0.3.5) AM_MAINTAINER_MODE @@ -31,7 +31,7 @@ GIO_UNIX_REQUIRED_VERSION=2.18 PANEL_REQUIRED_VERSION=2.0.0 INDICATE_REQUIRED_VERSION=0.3.0 INDICATOR_REQUIRED_VERSION=0.3.5 -DBUSMENUGTK_REQUIRED_VERSION=0.2.5 +DBUSMENUGTK_REQUIRED_VERSION=0.2.8 PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION diff --git a/debian/changelog b/debian/changelog index 1ac1922..ad2732b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,16 +1,14 @@ -indicator-messages (0.3.4-0ubuntu1~ppa3) lucid; urgency=low +indicator-messages (0.3.5-0ubuntu1~ppa1) UNRELEASED; urgency=low - * debian/changlog: Adding bug number to previous entry. - - -- Ted Gould <ted@ubuntu.com> Wed, 24 Mar 2010 10:30:37 -0500 - -indicator-messages (0.3.4-0ubuntu1~ppa2) lucid; urgency=low - - * Upstream merge + * Upstream release 0.3.5 * Show which applications are running with a small icon next to their entry. (LP: #438526) + * Shift command items to line up with application names. + (LP: #537312) + * Track applications we've seen so that we can show "Set Up" + text if we've not seen the app before. - -- Ted Gould <ted@ubuntu.com> Wed, 24 Mar 2010 10:07:24 -0500 + -- Ted Gould <ted@ubuntu.com> Thu, 25 Mar 2010 10:48:10 -0500 indicator-messages (0.3.4-0ubuntu1~ppa1) lucid; urgency=low diff --git a/src/Makefile.am b/src/Makefile.am index c96ef2d..7c9842a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,6 +32,8 @@ indicator_messages_service_SOURCES = \ app-menu-item.h \ launcher-menu-item.c \ launcher-menu-item.h \ + seen-db.c \ + seen-db.h \ dirs.h \ dbus-data.h indicator_messages_service_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror diff --git a/src/app-menu-item.c b/src/app-menu-item.c index a47c073..87423c0 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -31,6 +31,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "app-menu-item.h" #include "dbus-data.h" #include "default-applications.h" +#include "seen-db.h" enum { COUNT_CHANGED, @@ -309,6 +310,8 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar return; } + seen_db_add(value); + priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value)); g_return_if_fail(priv->appinfo != NULL); @@ -340,6 +343,7 @@ child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint positio AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(child); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(mip), DBUSMENU_MENUITEM_PROP_ICON_NAME, DBUSMENU_MENUITEM_ICON_NAME_BLANK); priv->shortcuts = g_list_insert(priv->shortcuts, mip, position); @@ -441,6 +445,7 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data 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); } diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 99e303b..988d9d6 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -207,6 +207,20 @@ setup_icon_proxy (gpointer userdata) return FALSE; } +/* Sets the icon when it changes. */ +static void +application_icon_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, gpointer user_data) +{ + if (!g_strcmp0(prop, APPLICATION_MENUITEM_PROP_ICON)) { + /* Set the main icon */ + if (GTK_IS_IMAGE(user_data)) { + gtk_image_set_from_icon_name(GTK_IMAGE(user_data), g_value_get_string(value), GTK_ICON_SIZE_MENU); + } + } + + return; +} + /* Sets the label when it changes. */ static void application_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, gpointer user_data) @@ -266,6 +280,7 @@ new_application_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu /* 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); return TRUE; } diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index 279d167..63e5594 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -31,6 +31,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "launcher-menu-item.h" #include "dbus-data.h" #include "default-applications.h" +#include "seen-db.h" enum { NAME_CHANGED, @@ -163,7 +164,14 @@ launcher_menu_item_new (const gchar * desktop_file) app info that we've parsed */ g_debug("\tName: %s", launcher_menu_item_get_name(self)); - const gchar * default_name = get_default_name(desktop_file); + const gchar * default_name = NULL; + + if (seen_db_seen(desktop_file)) { + default_name = get_default_name(desktop_file); + } else { + default_name = get_default_setup(desktop_file); + } + if (default_name == NULL) { dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, launcher_menu_item_get_name(self)); } else { @@ -183,17 +191,20 @@ launcher_menu_item_new (const gchar * desktop_file) g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL); /* Start to build static shortcuts */ - priv->ids = indicator_desktop_shortcuts_new(priv->desktop, "Messaging Menu"); - const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(priv->ids); - gint i; - for (i = 0; nicks[i] != NULL; i++) { - DbusmenuMenuitem * mi = dbusmenu_menuitem_new(); - g_object_set_data(G_OBJECT(mi), NICK_DATA, (gpointer)nicks[i]); - - dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, indicator_desktop_shortcuts_nick_get_name(priv->ids, nicks[i])); - g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(nick_activate_cb), self); - - priv->shortcuts = g_list_append(priv->shortcuts, mi); + if (seen_db_seen(desktop_file)) { + priv->ids = indicator_desktop_shortcuts_new(priv->desktop, "Messaging Menu"); + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(priv->ids); + gint i; + for (i = 0; nicks[i] != NULL; i++) { + DbusmenuMenuitem * mi = dbusmenu_menuitem_new(); + g_object_set_data(G_OBJECT(mi), NICK_DATA, (gpointer)nicks[i]); + + dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_ICON_NAME, DBUSMENU_MENUITEM_ICON_NAME_BLANK); + dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, indicator_desktop_shortcuts_nick_get_name(priv->ids, nicks[i])); + g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(nick_activate_cb), self); + + priv->shortcuts = g_list_append(priv->shortcuts, mi); + } } /* Check to see if we should be eclipsed */ @@ -311,6 +322,24 @@ launcher_menu_item_set_eclipsed (LauncherMenuItem * li, gboolean eclipsed) dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_VISIBLE, !eclipsed); g_list_foreach(priv->shortcuts, eclipse_shortcuts_cb, GINT_TO_POINTER(eclipsed)); + + /* If we're being reshown let's re-evaluate how we should be + showing the label */ + if (!eclipsed) { + const gchar * default_name = NULL; + + if (seen_db_seen(priv->desktop)) { + default_name = get_default_name(priv->desktop); + } else { + default_name = get_default_setup(priv->desktop); + } + + if (default_name == NULL) { + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_LABEL, launcher_menu_item_get_name(li)); + } else { + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_LABEL, _(default_name)); + } + } return; } diff --git a/src/messages-service.c b/src/messages-service.c index 0ebab0b..bc3e9e8 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -39,6 +39,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "dbus-data.h" #include "dirs.h" #include "messages-service-dbus.h" +#include "seen-db.h" static IndicateListener * listener; static GList * serverList = NULL; @@ -1422,6 +1423,8 @@ main (int argc, char ** argv) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); + seen_db_init(); + dbus_interface = message_service_dbus_new(); listener = indicate_listener_ref_default(); diff --git a/src/seen-db.c b/src/seen-db.c new file mode 100644 index 0000000..57765cc --- /dev/null +++ b/src/seen-db.c @@ -0,0 +1,177 @@ +/* +A small database of which desktop files we've seen. + +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 "seen-db.h" + +#define GROUP_NAME "Seen Database" +#define KEY_NAME "DesktopFiles" + +GHashTable * seendb = NULL; +gchar * filename = NULL; +gchar * dirname = NULL; +guint write_process = 0; + +/* Build the hashtable and then see if we have a keyfile that + we can get the history of desktop files we've seen. */ +void +seen_db_init(void) +{ + g_return_if_fail(seendb == NULL); + + seendb = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + + /* Build the filename for the seen database. We're putting + it in the cache directory because it could get deleted and + it really wouldn't be a big deal. */ + if (dirname == NULL) { + dirname = g_build_filename(g_get_user_cache_dir(), "indicators", "messages", NULL); + } + if (filename == NULL) { + filename = g_build_filename(dirname, "seen-db.keyfile", NULL); + } + + if (g_file_test(filename, G_FILE_TEST_EXISTS)) { + GKeyFile * keyfile = g_key_file_new(); + + /* Load from file */ + if (!g_key_file_load_from_file(keyfile, filename, G_KEY_FILE_NONE, NULL)) { + g_key_file_free(keyfile); + keyfile = NULL; + } + + /* Check for keys */ + if (keyfile != NULL && !g_key_file_has_key(keyfile, GROUP_NAME, KEY_NAME, NULL)) { + g_warning("Seen DB '%s' does not have key '%s' in group '%s'", filename, KEY_NAME, GROUP_NAME); + g_key_file_free(keyfile); + keyfile = NULL; + } + + /* Grab them and put in DB */ + if (keyfile != NULL) { + gchar ** desktops = g_key_file_get_string_list(keyfile, GROUP_NAME, KEY_NAME, NULL, NULL); + gint i = 0; + + while (desktops[i] != NULL) { + g_hash_table_insert(seendb, + g_strdup(desktops[i]), + GINT_TO_POINTER(TRUE)); + i++; + } + + g_strfreev(desktops); + } + + /* Clean up our file */ + if (keyfile != NULL) { + g_key_file_free(keyfile); + } + } + + return; +} + +/* A function to write out the seen database after it's been + modified for a while. */ +static gboolean +write_seen_db (gpointer user_data) +{ + write_process = 0; + + /* Build up the key file */ + GKeyFile * keyfile = g_key_file_new(); + GArray * desktops = g_array_new(FALSE, FALSE, sizeof(gchar *)); + + /* Get the keys from the hashtable and make them + into an array */ + if (keyfile != NULL) { + GList * desktop_keys = g_hash_table_get_keys(seendb); + GList * head = NULL; + + for (head = desktop_keys; head != NULL; head = g_list_next(head)) { + g_array_append_val(desktops, head->data); + } + + g_list_free(desktop_keys); + } + + /* Use the array to dump the strings into the keyfile */ + g_key_file_set_string_list(keyfile, + GROUP_NAME, + KEY_NAME, + (const gchar * const *)desktops->data, + desktops->len); + g_array_free(desktops, TRUE); + + /* Dump the key file to string */ + gchar * keydump = NULL; + gsize keydumplen = 0; + keydump = g_key_file_to_data(keyfile, &keydumplen, NULL); + g_key_file_free(keyfile); + + /* Ensure the directory exists */ + if (g_mkdir_with_parents(dirname, 0700) != 0) { + g_warning("Unable to make directory: %s", dirname); + g_free(keydump); + return FALSE; + } + + /* Dump out the file */ + GError * error = NULL; + if (!g_file_set_contents(filename, keydump, keydumplen, &error)) { + g_warning("Unable to write out file '%s': %s", filename, error->message); + g_error_free(error); + } + + /* Clean up */ + g_free(keydump); + + return FALSE; +} + +/* Add a new desktop file to the seen database. Also sets up a timer + to do the write out. */ +void +seen_db_add (const gchar * desktop) +{ + /* If this is a new one, let's set up the timer. If + there's already one clear it. */ + if (!seen_db_seen(desktop)) { + if (write_process != 0) { + g_source_remove(write_process); + write_process = 0; + } + + write_process = g_timeout_add_seconds(60, write_seen_db, NULL); + } + + g_hash_table_insert(seendb, + g_strdup(desktop), + GINT_TO_POINTER(TRUE)); + + return; +} + +/* Checks to see if a desktop file has been seen. */ +gboolean +seen_db_seen (const gchar * desktop) +{ + return GPOINTER_TO_INT(g_hash_table_lookup(seendb, desktop)); +} diff --git a/src/seen-db.h b/src/seen-db.h new file mode 100644 index 0000000..a998ff0 --- /dev/null +++ b/src/seen-db.h @@ -0,0 +1,31 @@ +/* +A small database of which desktop files we've seen. + +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 SEEN_DB_H__ +#define SEEN_DB_H__ 1 + +#include <glib.h> + +void seen_db_init(void); +void seen_db_add (const gchar * desktop); +gboolean seen_db_seen (const gchar * desktop); + +#endif /* SEEN_DB_H__ */ |