aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXan Lopez <xan@igalia.com>2012-07-31 21:34:28 +0800
committerXan Lopez <xan@igalia.com>2012-07-31 21:34:28 +0800
commitd46dbdabfb2f3b1885b0eb30bde4cc7652475292 (patch)
tree357996ecacdac23511fe01eff47655e1222482f9
parenta9b77ec4948dd2db2b3aef808e29c97aaa782589 (diff)
downloadgsoc2013-epiphany-d46dbdabfb2f3b1885b0eb30bde4cc7652475292.tar
gsoc2013-epiphany-d46dbdabfb2f3b1885b0eb30bde4cc7652475292.tar.gz
gsoc2013-epiphany-d46dbdabfb2f3b1885b0eb30bde4cc7652475292.tar.bz2
gsoc2013-epiphany-d46dbdabfb2f3b1885b0eb30bde4cc7652475292.tar.lz
gsoc2013-epiphany-d46dbdabfb2f3b1885b0eb30bde4cc7652475292.tar.xz
gsoc2013-epiphany-d46dbdabfb2f3b1885b0eb30bde4cc7652475292.tar.zst
gsoc2013-epiphany-d46dbdabfb2f3b1885b0eb30bde4cc7652475292.zip
ephy-encoding: auto-calculate 'title-elided' and 'collation-key'
They are derived from 'title', no need to pass them as parameters.
-rw-r--r--embed/ephy-encoding.c50
-rw-r--r--embed/ephy-encoding.h2
-rw-r--r--embed/ephy-encodings.c40
-rw-r--r--tests/ephy-encodings-test.c5
4 files changed, 49 insertions, 48 deletions
diff --git a/embed/ephy-encoding.c b/embed/ephy-encoding.c
index ad5614002..0319bc9ff 100644
--- a/embed/ephy-encoding.c
+++ b/embed/ephy-encoding.c
@@ -21,6 +21,8 @@
#include "config.h"
#include "ephy-encoding.h"
+#include <string.h>
+
G_DEFINE_TYPE (EphyEncoding, ephy_encoding, G_TYPE_OBJECT)
#define EPHY_ENCODING_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ENCODING, EphyEncodingPrivate))
@@ -86,6 +88,32 @@ ephy_encoding_get_property (GObject *object,
}
}
+/* Copied from egg-toolbar-editor.c */
+static char *
+elide_underscores (const char *original)
+{
+ char *q, *result;
+ const char *p;
+ gboolean last_underscore;
+
+ q = result = g_malloc (strlen (original) + 1);
+ last_underscore = FALSE;
+
+ for (p = original; *p; p++) {
+ if (!last_underscore && *p == '_') {
+ last_underscore = TRUE;
+ }
+ else {
+ last_underscore = FALSE;
+ *q++ = *p;
+ }
+ }
+
+ *q = '\0';
+
+ return result;
+}
+
static void
ephy_encoding_set_property (GObject *object,
guint prop_id,
@@ -95,10 +123,27 @@ ephy_encoding_set_property (GObject *object,
EphyEncodingPrivate *priv = EPHY_ENCODING (object)->priv;
switch (prop_id) {
- case PROP_TITLE:
+ case PROP_TITLE: {
+ char *elided, *collate_key, *normalised;
+
g_free (priv->title);
priv->title = g_strdup (g_value_get_string (value));
+
+ elided = elide_underscores (priv->title);
+ normalised = g_utf8_normalize (elided, -1, G_NORMALIZE_DEFAULT);
+ collate_key = g_utf8_collate_key (normalised, -1);
+
+ g_object_set (object,
+ "title-elided", elided,
+ "collation-key", collate_key,
+ NULL);
+
+ g_free (collate_key);
+ g_free (normalised);
+ g_free (elided);
+
break;
+ }
case PROP_TITLE_ELIDED:
g_free (priv->title_elided);
priv->title_elided = g_strdup (g_value_get_string (value));
@@ -220,14 +265,11 @@ ephy_encoding_get_language_groups (EphyEncoding *encoding)
EphyEncoding *
ephy_encoding_new (const char *encoding, const char *title,
- const char *title_elided, const char *collation_key,
int language_groups)
{
return g_object_new (EPHY_TYPE_ENCODING,
"encoding", encoding,
"title", title,
- "title-elided", title_elided,
- "collation-key", collation_key,
"language-groups", language_groups,
NULL);
}
diff --git a/embed/ephy-encoding.h b/embed/ephy-encoding.h
index 92d0addf4..bed8d05f1 100644
--- a/embed/ephy-encoding.h
+++ b/embed/ephy-encoding.h
@@ -84,8 +84,6 @@ typedef enum
GType ephy_encoding_get_type (void);
EphyEncoding * ephy_encoding_new (const char *encoding,
const char *title,
- const char *title_elided,
- const char *collation_key,
int language_groups);
const char * ephy_encoding_get_title (EphyEncoding *encoding);
const char * ephy_encoding_get_title_elided (EphyEncoding *encoding);
diff --git a/embed/ephy-encodings.c b/embed/ephy-encodings.c
index abe765951..f6465bf4e 100644
--- a/embed/ephy-encodings.c
+++ b/embed/ephy-encodings.c
@@ -28,7 +28,6 @@
#include "ephy-settings.h"
#include <glib/gi18n.h>
-#include <string.h>
#define EPHY_ENCODINGS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ENCODINGS, EphyEncodingsPrivate))
@@ -180,32 +179,6 @@ ephy_encodings_class_init (EphyEncodingsClass *klass)
g_type_class_add_private (object_class, sizeof (EphyEncodingsPrivate));
}
-/* Copied from egg-toolbar-editor.c */
-static char *
-elide_underscores (const char *original)
-{
- char *q, *result;
- const char *p;
- gboolean last_underscore;
-
- q = result = g_malloc (strlen (original) + 1);
- last_underscore = FALSE;
-
- for (p = original; *p; p++) {
- if (!last_underscore && *p == '_') {
- last_underscore = TRUE;
- }
- else {
- last_underscore = FALSE;
- *q++ = *p;
- }
- }
-
- *q = '\0';
-
- return result;
-}
-
static EphyEncoding *
add_encoding (EphyEncodings *encodings,
const char *title,
@@ -213,25 +186,14 @@ add_encoding (EphyEncodings *encodings,
EphyLanguageGroup groups)
{
EphyEncoding *encoding;
- char *elided, *collate_key, *normalised;
/* Create node. */
- elided = elide_underscores (title);
- normalised = g_utf8_normalize (elided, -1, G_NORMALIZE_DEFAULT);
- collate_key = g_utf8_collate_key (normalised, -1);
-
- encoding = ephy_encoding_new (code, title,
- normalised, collate_key,
- groups);
+ encoding = ephy_encoding_new (code, title, groups);
/* Add it. */
g_hash_table_insert (encodings->priv->hash, g_strdup (code), encoding);
g_signal_emit_by_name (encodings, "encoding-added", encoding);
- g_free (collate_key);
- g_free (normalised);
- g_free (elided);
-
return encoding;
}
diff --git a/tests/ephy-encodings-test.c b/tests/ephy-encodings-test.c
index 791b99066..209aeb3cb 100644
--- a/tests/ephy-encodings-test.c
+++ b/tests/ephy-encodings-test.c
@@ -38,13 +38,12 @@ test_ephy_encodings_create ()
EphyEncoding *encoding;
encoding = ephy_encoding_new ("UTF-8", "Unicode (UTF-8)",
- "0xDEADBEEF", "0xDEADBEEF",
LG_UNICODE);
g_assert (encoding);
g_assert_cmpstr (ephy_encoding_get_encoding (encoding), ==, "UTF-8");
g_assert_cmpstr (ephy_encoding_get_title (encoding), ==, "Unicode (UTF-8)");
- g_assert_cmpstr (ephy_encoding_get_title_elided (encoding), ==, "0xDEADBEEF");
- g_assert_cmpstr (ephy_encoding_get_collation_key (encoding), ==, "0xDEADBEEF");
+ g_assert_cmpstr (ephy_encoding_get_title_elided (encoding), ==, "Unicode (UTF-8)");
+ g_assert_cmpstr (ephy_encoding_get_collation_key (encoding), ==, "Unicode (UTF-8)");
g_assert_cmpint (ephy_encoding_get_language_groups (encoding), ==, LG_UNICODE);
g_object_unref (encoding);