Mercurial > pidgin.yaz
changeset 12690:d03afaccd41c
[gaim-migrate @ 15033]
Make the popular status docklet menu items actually do something.
Strip html and newlines from the titles of saved-statuses when
displaying them in the docklet menu.
Add a 'gaim_savedstatus_find_by_creation_time()' function. Sadrul:
you'll probably want to use this when you add popular statuses to
the status box.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 03 Jan 2006 05:23:01 +0000 |
parents | e893563d965d |
children | 4e1d44bad3c4 |
files | plugins/docklet/docklet.c src/savedstatuses.c src/savedstatuses.h |
diffstat | 3 files changed, 74 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/docklet/docklet.c Tue Jan 03 04:44:08 2006 +0000 +++ b/plugins/docklet/docklet.c Tue Jan 03 05:23:01 2006 +0000 @@ -358,12 +358,24 @@ #endif static void -show_custom_status_editor_cb() +show_custom_status_editor_cb(GtkMenuItem *menuitem, gpointer user_data) { gaim_gtk_status_editor_show(NULL); } static void +activate_saved_status_cb(GtkMenuItem *menuitem, gpointer user_data) +{ + time_t creation_time; + GaimSavedStatus *saved_status; + + creation_time = GPOINTER_TO_INT(user_data); + saved_status = gaim_savedstatus_find_by_creation_time(creation_time); + if (saved_status != NULL) + gaim_savedstatus_activate(saved_status); +} + +static void docklet_menu() { static GtkWidget *menu = NULL; GtkWidget *menuitem; @@ -414,9 +426,11 @@ for (cur = popular_statuses; cur != NULL; cur = cur->next) { GaimSavedStatus *saved_status = cur->data; + time_t creation_time = gaim_savedstatus_get_creation_time(saved_status); gaim_new_item_from_stock(menu, gaim_savedstatus_get_title(saved_status), - GAIM_STOCK_ICON_AWAY, NULL /* TODO */, NULL, 0, 0, NULL); + GAIM_STOCK_ICON_AWAY, G_CALLBACK(activate_saved_status_cb), + GINT_TO_POINTER(creation_time), 0, 0, NULL); } g_list_free(popular_statuses);
--- a/src/savedstatuses.c Tue Jan 03 04:44:08 2006 +0000 +++ b/src/savedstatuses.c Tue Jan 03 05:23:01 2006 +0000 @@ -788,6 +788,22 @@ return NULL; } +GaimSavedStatus * +gaim_savedstatus_find_by_creation_time(time_t creation_time) +{ + GList *iter; + GaimSavedStatus *status; + + for (iter = saved_statuses; iter != NULL; iter = iter->next) + { + status = (GaimSavedStatus *)iter->data; + if (status->creation_time == creation_time) + return status; + } + + return NULL; +} + gboolean gaim_savedstatus_is_transient(const GaimSavedStatus *saved_status) { @@ -799,35 +815,40 @@ const char * gaim_savedstatus_get_title(const GaimSavedStatus *saved_status) { + const char *message; + g_return_val_if_fail(saved_status != NULL, NULL); - /* If transient then make up a title on the fly */ - if (saved_status->title == NULL) - { - const char *message = gaim_savedstatus_get_message(saved_status); + /* If we have a title then return it */ + if (saved_status->title != NULL) + return saved_status->title; + + /* Otherwise, this is a transient status and we make up a title on the fly */ + message = gaim_savedstatus_get_message(saved_status); - if (message == NULL) - { - GaimStatusPrimitive primitive; - primitive = gaim_savedstatus_get_type(saved_status); - return gaim_primitive_get_id_from_type(primitive); - } - else + if (message == NULL) + { + GaimStatusPrimitive primitive; + primitive = gaim_savedstatus_get_type(saved_status); + return gaim_primitive_get_id_from_type(primitive); + } + else + { + char *stripped; + static char buf[64]; + stripped = gaim_markup_strip_html(message); + gaim_util_chrreplace(stripped, '\n', ' '); + strncpy(buf, stripped, sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + if ((strlen(stripped) + 1) > sizeof(buf)) { - static char buf[64]; - strncpy(buf, message, sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - if ((strlen(message) + 1) > sizeof(buf)) - { - /* Truncate and ellipsize */ - char *tmp = g_utf8_find_prev_char(buf, &buf[sizeof(buf) - 4]); - strcpy(tmp, "..."); - } - return buf; + /* Truncate and ellipsize */ + char *tmp = g_utf8_find_prev_char(buf, &buf[sizeof(buf) - 4]); + strcpy(tmp, "..."); } + g_free(stripped); + return buf; } - - return saved_status->title; } GaimStatusPrimitive
--- a/src/savedstatuses.h Tue Jan 03 04:44:08 2006 +0000 +++ b/src/savedstatuses.h Tue Jan 03 05:23:01 2006 +0000 @@ -191,6 +191,16 @@ GaimSavedStatus *gaim_savedstatus_find(const char *title); /** + * Finds a saved status with the specified creation time. + * + * @param creation_time The timestamp when the saved + * status was created. + * + * @return The saved status if found, or NULL. + */ +GaimSavedStatus *gaim_savedstatus_find_by_creation_time(time_t creation_time); + +/** * Determines if a given saved status is "transient." * A transient saved status is one that was not * explicitly added by the user. Transient statuses @@ -214,7 +224,10 @@ * * @param saved_status The saved status. * - * @return The title. + * @return The title. This value may be a static buffer which may + * be overwritten on subsequent calls to this function. If + * you need a reference to the title for prolonged use then + * you should make a copy of it. */ const char *gaim_savedstatus_get_title(const GaimSavedStatus *saved_status);