Mercurial > pidgin.yaz
changeset 25508:e0add2aafeaf
- merge nosuke's tab width patch.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 11 Jun 2007 13:08:55 +0000 |
parents | abc46fd562bd |
children | cf708cbcbc04 |
files | pidgin/gtkconv.c pidgin/gtkprefs.c pidgin/gtkutils.c pidgin/gtkutils.h |
diffstat | 4 files changed, 117 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkconv.c Mon Jun 11 13:05:14 2007 +0000 +++ b/pidgin/gtkconv.c Mon Jun 11 13:08:55 2007 +0000 @@ -6180,10 +6180,11 @@ if ((fields & PIDGIN_CONV_COLORIZE_TITLE) || (fields & PIDGIN_CONV_SET_TITLE)) { - char *title; + char *title, *title_tmp; PurpleConvIm *im = NULL; PurpleAccount *account = purple_conversation_get_account(conv); AtkObject *accessibility_obj; + gboolean ellipsis = FALSE; /* I think this is a little longer than it needs to be but I'm lazy. */ char style[51]; @@ -6232,11 +6233,23 @@ strncpy(style, "color=\"#888a85\" style=\"italic\"", sizeof(style)); } + // nosuke's tab width patch + if ((purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/tab_side") == (GTK_POS_LEFT|8) + || purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/tab_side") == (GTK_POS_RIGHT|8)) + && purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/trim_vertical_tabs")) + ellipsis = TRUE; + + if (ellipsis) + title_tmp = pidgin_gtk_ellipsis_text(gtkconv->tab_label, title, 60, "..."); + else + title_tmp = title; + + if (*style != '\0') { char *html_title,*label; - html_title = g_markup_escape_text(title, -1); + html_title = g_markup_escape_text(title_tmp, -1); label = g_strdup_printf("<span %s>%s</span>", style, html_title); @@ -6245,7 +6258,7 @@ g_free(label); } else - gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); + gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title_tmp); if (pidgin_conv_window_is_active_conversation(conv)) update_typing_icon(gtkconv); @@ -6596,6 +6609,24 @@ return page_num; } +//nosuke +static void +trim_vertical_tabs_pref_cb(const char *name, PurplePrefType type, + gconstpointer value, gpointer data) +{ + GList *l; + PurpleConversation *conv; + + for (l = purple_get_conversations(); l != NULL; l = l->next) { + conv = (PurpleConversation *)l->data; + + if (!PIDGIN_IS_PIDGIN_CONVERSATION(conv)) + continue; + + pidgin_conv_update_fields(conv, PIDGIN_CONV_SET_TITLE); + } +} + static void close_on_tabs_pref_cb(const char *name, PurplePrefType type, gconstpointer value, gpointer data) @@ -6665,6 +6696,7 @@ pidgin_conv_tab_pack(gtkwin, gtkconvs->data); } } + trim_vertical_tabs_pref_cb(name, type, value, data); } static void @@ -7034,6 +7066,7 @@ purple_prefs_add_none(PIDGIN_PREFS_ROOT "/conversations"); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/use_smooth_scrolling", TRUE); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/close_on_tabs", TRUE); + purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/trim_vertical_tabs", FALSE); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold", FALSE); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic", FALSE); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline", FALSE); @@ -7077,6 +7110,8 @@ /* Connect callbacks. */ purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/conversations/close_on_tabs", close_on_tabs_pref_cb, NULL); + purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/conversations/trim_vertical_tabs", + trim_vertical_tabs_pref_cb, NULL); purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/conversations/show_timestamps", show_timestamps_pref_cb, NULL); purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/conversations/show_formatting_toolbar",
--- a/pidgin/gtkprefs.c Mon Jun 11 13:05:14 2007 +0000 +++ b/pidgin/gtkprefs.c Mon Jun 11 13:08:55 2007 +0000 @@ -854,6 +854,9 @@ pidgin_prefs_checkbox(_("Show close b_utton on tabs"), PIDGIN_PREFS_ROOT "/conversations/close_on_tabs", vbox2); + pidgin_prefs_checkbox(_("Trim names on vertical tabs"), + PIDGIN_PREFS_ROOT "/conversations/trim_vertical_tabs", vbox2); + label = pidgin_prefs_dropdown(vbox2, _("_Placement:"), PURPLE_PREF_INT, PIDGIN_PREFS_ROOT "/conversations/tab_side", _("Top"), GTK_POS_TOP,
--- a/pidgin/gtkutils.c Mon Jun 11 13:05:14 2007 +0000 +++ b/pidgin/gtkutils.c Mon Jun 11 13:08:55 2007 +0000 @@ -3078,3 +3078,77 @@ return path; } #endif + +gchar * +pidgin_gtk_ellipsis_text(GtkWidget *widget, const char *text, gint min_width, gchar *ellipsis) +{ + PangoLayout *layout; + gint width, height; + glong len0, len1, len2; + static gchar buf[1024], buf_tmp[1024]; + gint ewidth; + gboolean with_ellipsis = FALSE; + + g_strlcpy(buf_tmp, text, sizeof(buf_tmp)); + + if (strlen(text) >= sizeof(buf)) { + /* cutting off */ + if (! g_utf8_validate(buf_tmp, -1, NULL)) { + buf_tmp[sizeof(buf_tmp) - 1] = '\0'; + if (! g_utf8_validate(buf_tmp, -1, NULL)) { + buf_tmp[sizeof(buf_tmp) - 2] = '\0'; + if (! g_utf8_validate(buf_tmp, -1, NULL)) { + return NULL; /* failed */ + } + } + } + } + + buf[0] = '\0'; + +#define ELLIPSIS "..." + + layout = gtk_widget_create_pango_layout(widget, + ellipsis ? ellipsis : ELLIPSIS); + + pango_layout_get_pixel_size(layout, &width, &height); + ewidth = width; + + len0 = 0; + len1 = g_utf8_strlen(buf_tmp, -1); + len2 = len1; + + while (1) { + + if (len2 == len0) + break; + + g_utf8_strncpy (buf, buf_tmp, len2); + pango_layout_set_text(layout, buf, -1); + pango_layout_get_pixel_size(layout, &width, &height); + + if (! with_ellipsis && width <= min_width) + break; + else + with_ellipsis = TRUE; + + if (width + ewidth > min_width) + len1 = len2; + else + len0 = len2; + + len2 = (len0 + len1) / 2; + } + + g_utf8_strncpy (buf, buf_tmp, len2); + g_object_unref(layout); + + + if (with_ellipsis) + g_strlcat (buf, ellipsis ? ellipsis : ELLIPSIS, sizeof(buf)); + +#undef ELLIPSIS + + return buf; +} +
--- a/pidgin/gtkutils.h Mon Jun 11 13:05:14 2007 +0000 +++ b/pidgin/gtkutils.h Mon Jun 11 13:08:55 2007 +0000 @@ -541,5 +541,7 @@ GtkTreePath *gtk_tree_path_new_from_indices (gint first_index, ...); #endif +gchar *pidgin_gtk_ellipsis_text(GtkWidget *widget, const char *text, gint min_width, gchar *ellipsis); + #endif /* _PIDGINUTILS_H_ */