[gedit/wip/reusable-code] Create the GeditDocument:auto-detected-encodings property
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/reusable-code] Create the GeditDocument:auto-detected-encodings property
- Date: Tue, 12 Mar 2013 23:37:33 +0000 (UTC)
commit 590c267f79519bbe9fc633997318d81c64523458
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Mar 13 00:16:04 2013 +0100
Create the GeditDocument:auto-detected-encodings property
The purpose is to make the code of the DocumentLoader reusable. The
DocumentLoader used the "auto-detected" setting from GSettings, located
at org.gnome.gedit.preferences.encodings.
By creating the new property in GeditDocument, the GeditDocumentLoader
can use the value of this property instead of having the dependency on
the settings of gedit.
The property and the setting are bound in GeditDocument for now, in
constructed().
gedit/gedit-document-loader.c | 8 ++----
gedit/gedit-document.c | 48 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index 9a2f20e..140796a 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -96,7 +96,6 @@ static void open_async_read (AsyncData *async);
struct _GeditDocumentLoaderPrivate
{
- GSettings *enc_settings;
GSettings *editor_settings;
GeditDocument *document;
@@ -215,7 +214,6 @@ gedit_document_loader_dispose (GObject *object)
g_clear_object (&priv->output);
g_clear_object (&priv->info);
g_clear_object (&priv->location);
- g_clear_object (&priv->enc_settings);
g_clear_object (&priv->editor_settings);
G_OBJECT_CLASS (gedit_document_loader_parent_class)->dispose (object);
@@ -310,7 +308,6 @@ gedit_document_loader_init (GeditDocumentLoader *loader)
{
loader->priv = GEDIT_DOCUMENT_LOADER_GET_PRIVATE (loader);
- loader->priv->enc_settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
loader->priv->editor_settings = g_settings_new ("org.gnome.gedit.preferences.editor");
}
@@ -636,8 +633,9 @@ get_candidate_encodings (GeditDocumentLoader *loader)
GSList *encodings;
gchar **enc_strv;
- enc_strv = g_settings_get_strv (loader->priv->enc_settings,
- GEDIT_SETTINGS_ENCODING_AUTO_DETECTED);
+ g_object_get (loader->priv->document,
+ "auto-detected-encodings", &enc_strv,
+ NULL);
encodings = _gedit_encoding_strv_to_list ((const gchar * const *)enc_strv);
g_strfreev (enc_strv);
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index ce43c77..eab7e9e 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -108,7 +108,8 @@ struct _GeditDocumentPrivate
GFileInfo *metadata_info;
- const GeditEncoding *encoding;
+ const GeditEncoding *encoding;
+ gchar **auto_detected_encodings;
gchar *content_type;
@@ -161,6 +162,7 @@ enum {
PROP_MIME_TYPE,
PROP_READ_ONLY,
PROP_ENCODING,
+ PROP_AUTO_DETECTED_ENCODINGS,
PROP_CAN_SEARCH_AGAIN,
PROP_ENABLE_SEARCH_HIGHLIGHTING,
PROP_NEWLINE_TYPE,
@@ -254,6 +256,16 @@ set_compression_type (GeditDocument *doc,
}
static void
+set_auto_detected_encodings (GeditDocument *doc,
+ gchar **auto_detected_encodings)
+{
+ g_strfreev (doc->priv->auto_detected_encodings);
+ doc->priv->auto_detected_encodings = g_strdupv (auto_detected_encodings);
+
+ g_object_notify (G_OBJECT (doc), "auto-detected-encodings");
+}
+
+static void
gedit_document_dispose (GObject *object)
{
GeditDocument *doc = GEDIT_DOCUMENT (object);
@@ -340,6 +352,23 @@ gedit_document_finalize (GObject *object)
}
static void
+gedit_document_constructed (GObject *object)
+{
+ GeditDocument *doc = GEDIT_DOCUMENT (object);
+ GSettings *settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
+
+ g_settings_bind (settings,
+ GEDIT_SETTINGS_ENCODING_AUTO_DETECTED,
+ doc,
+ "auto-detected-encodings",
+ G_SETTINGS_BIND_GET);
+
+ g_object_unref (settings);
+
+ G_OBJECT_CLASS (gedit_document_parent_class)->constructed (object);
+}
+
+static void
gedit_document_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -367,6 +396,9 @@ gedit_document_get_property (GObject *object,
case PROP_ENCODING:
g_value_set_boxed (value, doc->priv->encoding);
break;
+ case PROP_AUTO_DETECTED_ENCODINGS:
+ g_value_set_boxed (value, doc->priv->auto_detected_encodings);
+ break;
case PROP_CAN_SEARCH_AGAIN:
g_value_set_boolean (value, gedit_document_get_can_search_again (doc));
break;
@@ -428,6 +460,10 @@ gedit_document_set_property (GObject *object,
set_compression_type (doc,
g_value_get_enum (value));
break;
+ case PROP_AUTO_DETECTED_ENCODINGS:
+ set_auto_detected_encodings (doc,
+ g_value_get_boxed (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -481,6 +517,7 @@ gedit_document_class_init (GeditDocumentClass *klass)
object_class->dispose = gedit_document_dispose;
object_class->finalize = gedit_document_finalize;
+ object_class->constructed = gedit_document_constructed;
object_class->get_property = gedit_document_get_property;
object_class->set_property = gedit_document_set_property;
@@ -538,6 +575,15 @@ gedit_document_class_init (GeditDocumentClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_AUTO_DETECTED_ENCODINGS,
+ g_param_spec_boxed ("auto-detected-encodings",
+ "Automatically Detected Encodings",
+ "List of encodings used for automatically
detecting the encoding of a file.",
+ G_TYPE_STRV,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (object_class, PROP_CAN_SEARCH_AGAIN,
g_param_spec_boolean ("can-search-again",
"Can search again",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]