aboutsummaryrefslogtreecommitdiffstats
path: root/embed/ephy-encoding.c
diff options
context:
space:
mode:
authorXan Lopez <xan@igalia.com>2012-07-31 19:02:54 +0800
committerXan Lopez <xan@igalia.com>2012-07-31 19:05:46 +0800
commit3ffcaee1656e55de26030f9c9a0c14518cfce048 (patch)
tree51f49c58acb42e47c37568dabd0d793ff0437acb /embed/ephy-encoding.c
parentc4824507c2216c665dab58fce03afd67e9e9ec7d (diff)
downloadgsoc2013-epiphany-3ffcaee1656e55de26030f9c9a0c14518cfce048.tar
gsoc2013-epiphany-3ffcaee1656e55de26030f9c9a0c14518cfce048.tar.gz
gsoc2013-epiphany-3ffcaee1656e55de26030f9c9a0c14518cfce048.tar.bz2
gsoc2013-epiphany-3ffcaee1656e55de26030f9c9a0c14518cfce048.tar.lz
gsoc2013-epiphany-3ffcaee1656e55de26030f9c9a0c14518cfce048.tar.xz
gsoc2013-epiphany-3ffcaee1656e55de26030f9c9a0c14518cfce048.tar.zst
gsoc2013-epiphany-3ffcaee1656e55de26030f9c9a0c14518cfce048.zip
ephy-encodings: rewrite to drop usage of EphyNode
We have a new 'EphyEncoding' object holding the encoding data, and the EphyEncodings object is now just a hash table holding a bunch of these. Change all the UI code to use the new APIs. https://bugzilla.gnome.org/show_bug.cgi?id=680735
Diffstat (limited to 'embed/ephy-encoding.c')
-rw-r--r--embed/ephy-encoding.c233
1 files changed, 233 insertions, 0 deletions
diff --git a/embed/ephy-encoding.c b/embed/ephy-encoding.c
new file mode 100644
index 000000000..ad5614002
--- /dev/null
+++ b/embed/ephy-encoding.c
@@ -0,0 +1,233 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2012 Igalia S.L.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "ephy-encoding.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))
+
+enum {
+ PROP_0,
+
+ PROP_TITLE,
+ PROP_TITLE_ELIDED,
+ PROP_COLLATION_KEY,
+ PROP_ENCODING,
+ PROP_LANGUAGE_GROUPS
+};
+
+struct _EphyEncodingPrivate {
+ char *title;
+ char *title_elided;
+ char *collation_key;
+ char *encoding;
+ int language_groups;
+};
+
+static void
+ephy_encoding_finalize (GObject *object)
+{
+ EphyEncodingPrivate *priv = EPHY_ENCODING (object)->priv;
+
+ g_free (priv->title);
+ g_free (priv->title_elided);
+ g_free (priv->collation_key);
+ g_free (priv->encoding);
+
+ G_OBJECT_CLASS (ephy_encoding_parent_class)->finalize (object);
+}
+
+static void
+ephy_encoding_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyEncodingPrivate *priv = EPHY_ENCODING (object)->priv;
+
+ switch (prop_id) {
+ case PROP_TITLE:
+ g_value_set_string (value, priv->title);
+ break;
+ case PROP_TITLE_ELIDED:
+ g_value_set_string (value, priv->title_elided);
+ break;
+ case PROP_COLLATION_KEY:
+ g_value_set_string (value, priv->collation_key);
+ break;
+ case PROP_ENCODING:
+ g_value_set_string (value, priv->encoding);
+ break;
+ case PROP_LANGUAGE_GROUPS:
+ g_value_set_int (value, priv->language_groups);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ephy_encoding_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyEncodingPrivate *priv = EPHY_ENCODING (object)->priv;
+
+ switch (prop_id) {
+ case PROP_TITLE:
+ g_free (priv->title);
+ priv->title = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_TITLE_ELIDED:
+ g_free (priv->title_elided);
+ priv->title_elided = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_COLLATION_KEY:
+ g_free (priv->collation_key);
+ priv->collation_key = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_ENCODING:
+ g_free (priv->encoding);
+ priv->encoding = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_LANGUAGE_GROUPS:
+ priv->language_groups = g_value_get_int (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ephy_encoding_class_init (EphyEncodingClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = ephy_encoding_finalize;
+ gobject_class->get_property = ephy_encoding_get_property;
+ gobject_class->set_property = ephy_encoding_set_property;
+
+ g_object_class_install_property (gobject_class,
+ PROP_TITLE,
+ g_param_spec_string ("title",
+ "Title",
+ "The encoding's title",
+ "",
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (gobject_class,
+ PROP_TITLE_ELIDED,
+ g_param_spec_string ("title-elided",
+ "Title Elided",
+ "The encoding's elided title",
+ "",
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (gobject_class,
+ PROP_COLLATION_KEY,
+ g_param_spec_string ("collation-key",
+ "Collation Key",
+ "The encoding's collation key",
+ "",
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (gobject_class,
+ PROP_ENCODING,
+ g_param_spec_string ("encoding",
+ "Encoding",
+ "The encoding's encoding",
+ "",
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (gobject_class,
+ PROP_LANGUAGE_GROUPS,
+ g_param_spec_int ("language-groups",
+ "Language Groups",
+ "The encoding's language groups",
+ LG_NONE, LG_ALL,
+ LG_NONE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+ g_type_class_add_private (gobject_class, sizeof (EphyEncodingPrivate));
+}
+
+static void
+ephy_encoding_init (EphyEncoding *encoding)
+{
+ encoding->priv = EPHY_ENCODING_GET_PRIVATE (encoding);
+}
+
+const char *
+ephy_encoding_get_title (EphyEncoding *encoding)
+{
+ g_return_val_if_fail (EPHY_IS_ENCODING (encoding), NULL);
+
+ return encoding->priv->title;
+}
+
+const char *
+ephy_encoding_get_title_elided (EphyEncoding *encoding)
+{
+ g_return_val_if_fail (EPHY_IS_ENCODING (encoding), NULL);
+
+ return encoding->priv->title_elided;
+}
+
+const char *
+ephy_encoding_get_collation_key (EphyEncoding *encoding)
+{
+ g_return_val_if_fail (EPHY_IS_ENCODING (encoding), NULL);
+
+ return encoding->priv->collation_key;
+}
+
+const char *
+ephy_encoding_get_encoding (EphyEncoding *encoding)
+{
+ g_return_val_if_fail (EPHY_IS_ENCODING (encoding), NULL);
+
+ return encoding->priv->encoding;
+}
+
+int
+ephy_encoding_get_language_groups (EphyEncoding *encoding)
+{
+ g_return_val_if_fail (EPHY_IS_ENCODING (encoding), LG_NONE);
+
+ return encoding->priv->language_groups;
+}
+
+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);
+}