aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--lib/ephy-string.c49
-rw-r--r--lib/ephy-string.h9
-rw-r--r--src/ephy-tab.c15
4 files changed, 79 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index e4953725c..5ab6a7c6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-10-10 Christian Persch <chpe@cvs.gnome.org>
+
+ * lib/ephy-string.c: (ephy_string_blank_chr),
+ (ephy_string_shorten):
+ * lib/ephy-string.h:
+
+ Bring back ephy_string_shorten.
+
+ * src/ephy-tab.c: (ephy_tab_file_monitor_cb), (ephy_tab_set_title):
+
+ Shorten overlong tab titles, hard. Increase reload delay slightly.
+ Strip whitespace from tab title before determining if it's empty.
+
2005-10-09 Christian Persch <chpe@cvs.gnome.org>
* lib/ephy-debug.c:
diff --git a/lib/ephy-string.c b/lib/ephy-string.c
index 2d53c25b5..f996a7fe3 100644
--- a/lib/ephy-string.c
+++ b/lib/ephy-string.c
@@ -27,6 +27,8 @@
#include <stdlib.h>
#include <glib.h>
+#define ELLIPSIS "\xe2\x80\xa6"
+
gboolean
ephy_string_to_int (const char *string, gulong *integer)
{
@@ -85,3 +87,50 @@ ephy_string_blank_chr (char *source)
return source;
}
+
+/**
+ * ephy_string_shorten: shortens a string
+ * @str: the string to shorten, in UTF-8
+ * @target_length: the length of the shortened string (in characters)
+ *
+ * If @str is already short enough, it is returned. Otherwise a new string
+ * is allocated and @str is consumed.
+ *
+ * Return value: a newly allocated string, not longer than target_length
+ * characters.
+ */
+char *
+ephy_string_shorten (const char *str,
+ gsize target_length)
+{
+ char *new_str;
+ glong actual_length;
+ gulong bytes;
+
+ g_return_val_if_fail (target_length > 0, NULL);
+
+ if (!str) return NULL;
+
+ /* FIXME: this function is a big mess. While it is utf-8 safe now,
+ * it can still split a sequence of combining characters.
+ */
+
+ actual_length = g_utf8_strlen (str, -1);
+
+ /* if the string is already short enough, or if it's too short for
+ * us to shorten it, return a new copy */
+ if (actual_length <= target_length) return g_strdup (str);
+
+ /* create string */
+ bytes = GPOINTER_TO_UINT (g_utf8_offset_to_pointer (str, target_length - 1) - str);
+
+ new_str = g_new (gchar, bytes + strlen(ELLIPSIS) + 1);
+
+ strncpy (new_str, str, bytes);
+ strncpy (new_str + bytes, ELLIPSIS, strlen (ELLIPSIS));
+ new_str[bytes + strlen (ELLIPSIS)] = '\0';
+
+ g_free (str);
+
+ return new_str;
+}
diff --git a/lib/ephy-string.h b/lib/ephy-string.h
index 36e23d1c3..86ab9eafc 100644
--- a/lib/ephy-string.h
+++ b/lib/ephy-string.h
@@ -25,10 +25,13 @@
G_BEGIN_DECLS
-gboolean ephy_string_to_int (const char *string,
- gulong *integer);
+gboolean ephy_string_to_int (const char *string,
+ gulong *integer);
-char *ephy_string_blank_chr (char *source);
+char *ephy_string_blank_chr (char *source);
+
+char *ephy_string_shorten (const char *str,
+ gsize target_length);
G_END_DECLS
diff --git a/src/ephy-tab.c b/src/ephy-tab.c
index 4d7faeff4..b18f971bc 100644
--- a/src/ephy-tab.c
+++ b/src/ephy-tab.c
@@ -70,7 +70,9 @@
#define EPHY_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TAB, EphyTabPrivate))
-#define MAX_HIDDEN_POPUPS 5
+#define MAX_HIDDEN_POPUPS 5
+#define RELOAD_DELAY 250 /* ms */
+#define MAX_TITLE_LENGTH 512 /* characters */
struct _EphyTabPrivate
{
@@ -1312,7 +1314,7 @@ ephy_tab_file_monitor_cb (GnomeVFSMonitorHandle *handle,
}
priv->reload_scheduled_id =
- g_timeout_add (100 /* ms */,
+ g_timeout_add (RELOAD_DELAY,
(GSourceFunc) ephy_file_monitor_reload_cb,
tab);
break;
@@ -2175,7 +2177,7 @@ ephy_tab_set_title (EphyTab *tab,
{
EphyTabPrivate *priv = tab->priv;
- if (!priv->is_blank && (title == NULL || title[0] == '\0'))
+ if (!priv->is_blank && (title == NULL || g_strstrip (title)[0] == '\0'))
{
g_free (title);
@@ -2189,9 +2191,14 @@ ephy_tab_set_title (EphyTab *tab,
priv->is_blank = TRUE;
}
}
+ else if (priv->is_blank && title != NULL)
+ {
+ g_free (title);
+ title = NULL;
+ }
g_free (priv->title);
- priv->title = title;
+ priv->title = ephy_string_shorten (title, MAX_TITLE_LENGTH);
g_object_notify (G_OBJECT (tab), "title");
}