From: Mark D. <the...@us...> - 2006-01-03 05:23:10
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12809/src Modified Files: savedstatuses.h savedstatuses.c Log Message: 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. Index: savedstatuses.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/savedstatuses.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -p -r1.12 -r1.13 --- savedstatuses.h 3 Jan 2006 01:25:06 -0000 1.12 +++ savedstatuses.h 3 Jan 2006 05:23:01 -0000 1.13 @@ -191,6 +191,16 @@ GaimSavedStatus *gaim_savedstatus_get_id 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 @@ gboolean gaim_savedstatus_is_transient(c * * @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); Index: savedstatuses.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/savedstatuses.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -p -r1.31 -r1.32 --- savedstatuses.c 3 Jan 2006 01:25:06 -0000 1.31 +++ savedstatuses.c 3 Jan 2006 05:23:01 -0000 1.32 @@ -788,6 +788,22 @@ gaim_savedstatus_find(const char *title) 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 @@ gaim_savedstatus_is_transient(const Gaim 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; - if (message == NULL) - { - GaimStatusPrimitive primitive; - primitive = gaim_savedstatus_get_type(saved_status); - return gaim_primitive_get_id_from_type(primitive); - } - else + /* 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 + { + 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 |