[gedit/wip/gsv-metadata] GeditDocument: use GtkSourceFile API for metadata
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/gsv-metadata] GeditDocument: use GtkSourceFile API for metadata
- Date: Fri, 29 Apr 2016 17:05:42 +0000 (UTC)
commit 80d8e5ba09ae9d3ddf42af412644cb8334993150
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Apr 29 18:32:38 2016 +0200
GeditDocument: use GtkSourceFile API for metadata
gedit/gedit-document-private.h | 12 +--
gedit/gedit-document.c | 225 +++-------------------------------------
gedit/gedit-document.h | 2 +
3 files changed, 22 insertions(+), 217 deletions(-)
---
diff --git a/gedit/gedit-document-private.h b/gedit/gedit-document-private.h
index dabb2a8..2cec9e3 100644
--- a/gedit/gedit-document-private.h
+++ b/gedit/gedit-document-private.h
@@ -28,15 +28,9 @@
G_BEGIN_DECLS
-#ifdef G_OS_WIN32
-#define GEDIT_METADATA_ATTRIBUTE_POSITION "position"
-#define GEDIT_METADATA_ATTRIBUTE_ENCODING "encoding"
-#define GEDIT_METADATA_ATTRIBUTE_LANGUAGE "language"
-#else
-#define GEDIT_METADATA_ATTRIBUTE_POSITION "metadata::gedit-position"
-#define GEDIT_METADATA_ATTRIBUTE_ENCODING "metadata::gedit-encoding"
-#define GEDIT_METADATA_ATTRIBUTE_LANGUAGE "metadata::gedit-language"
-#endif
+#define GEDIT_METADATA_ATTRIBUTE_POSITION "gedit-position"
+#define GEDIT_METADATA_ATTRIBUTE_ENCODING "gedit-encoding"
+#define GEDIT_METADATA_ATTRIBUTE_LANGUAGE "gedit-language"
glong _gedit_document_get_seconds_since_last_save_or_load (GeditDocument *doc);
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 5f1a6ae..4121799 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -5,7 +5,7 @@
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
* Copyright (C) 2002-2005 Paolo Maggi
- * Copyright (C) 2014-2015 Sébastien Wilmet
+ * Copyright (C) 2014-2016 Sébastien Wilmet
*
* 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
@@ -34,9 +34,6 @@
#include "gedit-settings.h"
#include "gedit-debug.h"
#include "gedit-utils.h"
-#include "gedit-metadata-manager.h"
-
-#define METADATA_QUERY "metadata::*"
#define NO_LANGUAGE_NAME "_NORMAL_"
@@ -56,8 +53,6 @@ typedef struct
gint untitled_number;
gchar *short_name;
- GFileInfo *metadata_info;
-
gchar *content_type;
GTimeVal time_of_last_save_or_load;
@@ -70,7 +65,6 @@ typedef struct
guint user_action;
guint language_set_by_user : 1;
- guint use_gvfs_metadata : 1;
/* The search is empty if there is no search context, or if the
* search text is empty. It is used for the sensitivity of some menu
@@ -92,7 +86,6 @@ enum
PROP_MIME_TYPE,
PROP_READ_ONLY,
PROP_EMPTY_SEARCH,
- PROP_USE_GVFS_METADATA,
LAST_PROP
};
@@ -212,7 +205,6 @@ gedit_document_dispose (GObject *object)
}
g_clear_object (&priv->editor_settings);
- g_clear_object (&priv->metadata_info);
g_clear_object (&priv->search_context);
G_OBJECT_CLASS (gedit_document_parent_class)->dispose (object);
@@ -271,10 +263,6 @@ gedit_document_get_property (GObject *object,
g_value_set_boolean (value, priv->empty_search);
break;
- case PROP_USE_GVFS_METADATA:
- g_value_set_boolean (value, priv->use_gvfs_metadata);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -302,10 +290,6 @@ gedit_document_set_property (GObject *object,
set_content_type (doc, g_value_get_string (value));
break;
- case PROP_USE_GVFS_METADATA:
- priv->use_gvfs_metadata = g_value_get_boolean (value);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -474,25 +458,6 @@ gedit_document_class_init (GeditDocumentClass *klass)
TRUE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
- /**
- * GeditDocument:use-gvfs-metadata:
- *
- * Whether to use GVFS metadata. If %FALSE, use the gedit metadata
- * manager that stores the metadata in an XML file in the user cache
- * directory.
- *
- * <warning>
- * The property is used internally by gedit. It must not be used in a
- * gedit plugin. The property can be modified or removed at any time.
- * </warning>
- */
- properties[PROP_USE_GVFS_METADATA] =
- g_param_spec_boolean ("use-gvfs-metadata",
- "Use GVFS metadata",
- "",
- TRUE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
g_object_class_install_properties (object_class, LAST_PROP, properties);
/* This signal is used to update the cursor position in the statusbar,
@@ -778,47 +743,6 @@ on_location_changed (GtkSourceFile *file,
{
g_object_notify_by_pspec (G_OBJECT (doc), properties[PROP_SHORTNAME]);
}
-
- /* Load metadata for this location: we load sync since metadata is
- * always local so it should be fast and we need the information
- * right after the location was set.
- */
- if (priv->use_gvfs_metadata && location != NULL)
- {
- GError *error = NULL;
-
- if (priv->metadata_info != NULL)
- {
- g_object_unref (priv->metadata_info);
- }
-
- priv->metadata_info = g_file_query_info (location,
- METADATA_QUERY,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- &error);
-
- if (error != NULL)
- {
- /* Do not complain about metadata if we are opening a
- * non existing file.
- */
- if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) &&
- !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) &&
- !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) &&
- !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
- {
- g_warning ("%s", error->message);
- }
-
- g_error_free (error);
- }
-
- if (priv->metadata_info == NULL)
- {
- priv->metadata_info = g_file_info_new ();
- }
- }
}
static void
@@ -848,7 +772,6 @@ gedit_document_init (GeditDocument *doc)
g_get_current_time (&priv->time_of_last_save_or_load);
priv->file = gtk_source_file_new ();
- priv->metadata_info = g_file_info_new ();
g_signal_connect_object (priv->file,
"notify::location",
@@ -895,17 +818,7 @@ gedit_document_init (GeditDocument *doc)
GeditDocument *
gedit_document_new (void)
{
- gboolean use_gvfs_metadata;
-
-#ifdef ENABLE_GVFS_METADATA
- use_gvfs_metadata = TRUE;
-#else
- use_gvfs_metadata = FALSE;
-#endif
-
- return g_object_new (GEDIT_TYPE_DOCUMENT,
- "use-gvfs-metadata", use_gvfs_metadata,
- NULL);
+ return g_object_new (GEDIT_TYPE_DOCUMENT, NULL);
}
static gchar *
@@ -1610,62 +1523,18 @@ gedit_document_get_compression_type (GeditDocument *doc)
return gtk_source_file_get_compression_type (priv->file);
}
-static gchar *
-get_metadata_from_metadata_manager (GeditDocument *doc,
- const gchar *key)
-{
- GeditDocumentPrivate *priv;
- GFile *location;
-
- priv = gedit_document_get_instance_private (doc);
-
- location = gtk_source_file_get_location (priv->file);
+#define METADATA_PREFIX "metadata::"
- if (location != NULL)
- {
- return gedit_metadata_manager_get (location, key);
- }
-
- return NULL;
-}
-
-static gchar *
-get_metadata_from_gvfs (GeditDocument *doc,
- const gchar *key)
+/* For backward compatibility */
+static const gchar *
+get_metadata_key_without_prefix (const gchar *key)
{
- GeditDocumentPrivate *priv;
-
- priv = gedit_document_get_instance_private (doc);
-
- if (priv->metadata_info != NULL &&
- g_file_info_has_attribute (priv->metadata_info, key) &&
- g_file_info_get_attribute_type (priv->metadata_info, key) == G_FILE_ATTRIBUTE_TYPE_STRING)
+ if (g_str_has_prefix (key, METADATA_PREFIX))
{
- return g_strdup (g_file_info_get_attribute_string (priv->metadata_info, key));
+ return key + strlen (METADATA_PREFIX);
}
- return NULL;
-}
-
-static void
-set_gvfs_metadata (GFileInfo *info,
- const gchar *key,
- const gchar *value)
-{
- g_return_if_fail (G_IS_FILE_INFO (info));
-
- if (value != NULL)
- {
- g_file_info_set_attribute_string (info, key, value);
- }
- else
- {
- /* Unset the key */
- g_file_info_set_attribute (info,
- key,
- G_FILE_ATTRIBUTE_TYPE_INVALID,
- NULL);
- }
+ return key;
}
/**
@@ -1676,6 +1545,7 @@ set_gvfs_metadata (GFileInfo *info,
* Gets the metadata assigned to @key.
*
* Returns: the value assigned to @key. Free with g_free().
+ * Deprecated: 3.22: use gtk_source_file_get_metadata() instead.
*/
gchar *
gedit_document_get_metadata (GeditDocument *doc,
@@ -1688,12 +1558,8 @@ gedit_document_get_metadata (GeditDocument *doc,
priv = gedit_document_get_instance_private (doc);
- if (priv->use_gvfs_metadata)
- {
- return get_metadata_from_gvfs (doc, key);
- }
-
- return get_metadata_from_metadata_manager (doc, key);
+ return gtk_source_file_get_metadata (priv->file,
+ get_metadata_key_without_prefix (key));
}
/**
@@ -1704,6 +1570,7 @@ gedit_document_get_metadata (GeditDocument *doc,
* followed by %NULL.
*
* Sets metadata on a document.
+ * Deprecated: 3.22: use gtk_source_file_set_metadata() instead.
*/
void
gedit_document_set_metadata (GeditDocument *doc,
@@ -1711,84 +1578,26 @@ gedit_document_set_metadata (GeditDocument *doc,
...)
{
GeditDocumentPrivate *priv;
- GFile *location;
const gchar *key;
va_list var_args;
- GFileInfo *info = NULL;
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
g_return_if_fail (first_key != NULL);
priv = gedit_document_get_instance_private (doc);
- location = gtk_source_file_get_location (priv->file);
-
- /* With the metadata manager, can't set metadata for untitled documents.
- * With GVFS metadata, if the location is NULL the metadata is stored in
- * priv->metadata_info, so that it can be saved later if the document is
- * saved.
- */
- if (!priv->use_gvfs_metadata && location == NULL)
- {
- return;
- }
-
- if (priv->use_gvfs_metadata)
- {
- info = g_file_info_new ();
- }
-
va_start (var_args, first_key);
- for (key = first_key; key; key = va_arg (var_args, const gchar *))
+ for (key = first_key; key != NULL; key = va_arg (var_args, const gchar *))
{
const gchar *value = va_arg (var_args, const gchar *);
- if (priv->use_gvfs_metadata)
- {
- set_gvfs_metadata (info, key, value);
- set_gvfs_metadata (priv->metadata_info, key, value);
- }
- else
- {
- gedit_metadata_manager_set (location, key, value);
- }
+ gtk_source_file_set_metadata (priv->file,
+ get_metadata_key_without_prefix (key),
+ value);
}
va_end (var_args);
-
- if (priv->use_gvfs_metadata && location != NULL)
- {
- GError *error = NULL;
-
- /* We save synchronously since metadata is always local so it
- * should be fast. Moreover this function can be called on
- * application shutdown, when the main loop has already exited,
- * so an async operation would not terminate.
- * https://bugzilla.gnome.org/show_bug.cgi?id=736591
- */
- g_file_set_attributes_from_info (location,
- info,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- &error);
-
- if (error != NULL)
- {
- /* Do not complain about metadata if we are closing a
- * document for a non existing file.
- */
- if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) &&
- !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
- {
- g_warning ("Set document metadata failed: %s", error->message);
- }
-
- g_error_free (error);
- }
- }
-
- g_clear_object (&info);
}
static void
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index ac05261..3a562e3 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -112,9 +112,11 @@ G_DEPRECATED_FOR (gtk_source_file_get_compression_type)
GtkSourceCompressionType
gedit_document_get_compression_type (GeditDocument *doc);
+G_DEPRECATED_FOR (gtk_source_file_get_metadata)
gchar *gedit_document_get_metadata (GeditDocument *doc,
const gchar *key);
+G_DEPRECATED_FOR (gtk_source_file_set_metadata)
void gedit_document_set_metadata (GeditDocument *doc,
const gchar *first_key,
...);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]