[gedit] Get rid of URIs and use GFile instead.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Get rid of URIs and use GFile instead.
- Date: Tue, 27 Apr 2010 11:38:12 +0000 (UTC)
commit faf32c3a98c6fa87bbbb1bfdf294a11bf5ca734c
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Mar 31 16:09:04 2010 +0200
Get rid of URIs and use GFile instead.
gedit/gedit-commands-file.c | 132 ++++++---------------
gedit/gedit-commands.h | 8 +-
gedit/gedit-document-loader.c | 47 ++++----
gedit/gedit-document-loader.h | 6 +-
gedit/gedit-document-saver.c | 60 +++++-----
gedit/gedit-document-saver.h | 6 +-
gedit/gedit-document.c | 221 ++++++++++++++++------------------
gedit/gedit-document.h | 21 +---
gedit/gedit-gio-document-loader.c | 39 +++----
gedit/gedit-gio-document-saver.c | 20 +--
gedit/gedit-io-error-message-area.c | 93 ++++++++-------
gedit/gedit-io-error-message-area.h | 16 ++--
gedit/gedit-marshal.list | 4 +-
gedit/gedit-metadata-manager.c | 18 +++-
gedit/gedit-metadata-manager.h | 4 +-
gedit/gedit-session.c | 65 +++++++----
gedit/gedit-tab.c | 216 ++++++++++++++++++----------------
gedit/gedit-tab.h | 8 +-
gedit/gedit-utils.c | 136 +++++++++-------------
gedit/gedit-utils.h | 11 +-
gedit/gedit-window.c | 88 +++++++++-----
gedit/gedit-window.h | 8 +-
22 files changed, 589 insertions(+), 638 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index d0420c4..039f6ea 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -120,7 +120,7 @@ is_duplicated_file (GSList *files, GFile *file)
/* File loading */
static gint
load_file_list (GeditWindow *window,
- GSList *files,
+ const GSList *files,
const GeditEncoding *encoding,
gint line_pos,
gboolean create)
@@ -130,7 +130,7 @@ load_file_list (GeditWindow *window,
gboolean jump_to = TRUE; /* Whether to jump to the new tab */
GList *win_docs;
GSList *files_to_load = NULL;
- GSList *l;
+ const GSList *l;
gedit_debug (DEBUG_COMMANDS);
@@ -192,16 +192,11 @@ load_file_list (GeditWindow *window,
if (gedit_document_is_untouched (doc) &&
(gedit_tab_get_state (tab) == GEDIT_TAB_STATE_NORMAL))
{
- gchar *uri;
-
- // FIXME: pass the GFile to tab when api is there
- uri = g_file_get_uri (l->data);
_gedit_tab_load (tab,
- uri,
+ l->data,
encoding,
line_pos,
create);
- g_free (uri);
l = g_slist_next (l);
jump_to = FALSE;
@@ -212,19 +207,14 @@ load_file_list (GeditWindow *window,
while (l != NULL)
{
- gchar *uri;
-
g_return_val_if_fail (l->data != NULL, 0);
- // FIXME: pass the GFile to tab when api is there
- uri = g_file_get_uri (l->data);
- tab = gedit_window_create_tab_from_uri (window,
- uri,
- encoding,
- line_pos,
- create,
- jump_to);
- g_free (uri);
+ tab = gedit_window_create_tab_from_location (window,
+ l->data,
+ encoding,
+ line_pos,
+ create,
+ jump_to);
if (tab != NULL)
{
@@ -268,100 +258,52 @@ load_file_list (GeditWindow *window,
return loaded_files;
}
-
-// FIXME: we should expose API with GFile and just make the uri
-// variants backward compat wrappers
-
-static gint
-load_uri_list (GeditWindow *window,
- const GSList *uris,
- const GeditEncoding *encoding,
- gint line_pos,
- gboolean create)
-{
- GSList *files = NULL;
- const GSList *u;
- gint ret;
-
- for (u = uris; u != NULL; u = u->next)
- {
- gchar *uri = u->data;
-
- if (gedit_utils_is_valid_uri (uri))
- files = g_slist_prepend (files, g_file_new_for_uri (uri));
- else
- g_warning ("invalid uri: %s", uri);
- }
- files = g_slist_reverse (files);
-
- ret = load_file_list (window, files, encoding, line_pos, create);
-
- g_slist_foreach (files, (GFunc) g_object_unref, NULL);
- g_slist_free (files);
-
- return ret;
-}
-
/**
* gedit_commands_load_uri:
*
- * Do nothing if URI does not exist
+ * Do nothing if location does not exist
*/
void
-gedit_commands_load_uri (GeditWindow *window,
- const gchar *uri,
- const GeditEncoding *encoding,
- gint line_pos)
+gedit_commands_load_location (GeditWindow *window,
+ GFile *location,
+ const GeditEncoding *encoding,
+ gint line_pos)
{
- GSList *uris = NULL;
+ GSList *locations = NULL;
+ gchar *uri;
g_return_if_fail (GEDIT_IS_WINDOW (window));
- g_return_if_fail (uri != NULL);
- g_return_if_fail (gedit_utils_is_valid_uri (uri));
+ g_return_if_fail (G_IS_FILE (location));
+ g_return_if_fail (gedit_utils_is_valid_location (location));
+ uri = g_file_get_uri (location);
gedit_debug_message (DEBUG_COMMANDS, "Loading URI '%s'", uri);
+ g_free (uri);
- uris = g_slist_prepend (uris, (gchar *)uri);
+ locations = g_slist_prepend (locations, location);
- load_uri_list (window, uris, encoding, line_pos, FALSE);
+ load_file_list (window, locations, encoding, line_pos, FALSE);
- g_slist_free (uris);
+ g_slist_free (locations);
}
/**
* gedit_commands_load_uris:
*
- * Ignore non-existing URIs
+ * Ignore non-existing locations
*/
gint
-gedit_commands_load_uris (GeditWindow *window,
- const GSList *uris,
- const GeditEncoding *encoding,
- gint line_pos)
+gedit_commands_load_locations (GeditWindow *window,
+ const GSList *locations,
+ const GeditEncoding *encoding,
+ gint line_pos)
{
g_return_val_if_fail (GEDIT_IS_WINDOW (window), 0);
- g_return_val_if_fail ((uris != NULL) && (uris->data != NULL), 0);
+ g_return_val_if_fail ((locations != NULL) && (locations->data != NULL), 0);
gedit_debug (DEBUG_COMMANDS);
- return load_uri_list (window, uris, encoding, line_pos, FALSE);
-}
-
-/*
- * This should become public once we convert all api to GFile:
- */
-static gint
-gedit_commands_load_files (GeditWindow *window,
- GSList *files,
- const GeditEncoding *encoding,
- gint line_pos)
-{
- g_return_val_if_fail (GEDIT_IS_WINDOW (window), 0);
- g_return_val_if_fail ((files != NULL) && (files->data != NULL), 0);
-
- gedit_debug (DEBUG_COMMANDS);
-
- return load_file_list (window, files, encoding, line_pos, FALSE);
+ return load_file_list (window, locations, encoding, line_pos, FALSE);
}
/*
@@ -418,10 +360,10 @@ open_dialog_response_cb (GeditFileChooserDialog *dialog,
/* Remember the folder we navigated to */
_gedit_window_set_default_location (window, files->data);
- gedit_commands_load_files (window,
- files,
- encoding,
- 0);
+ gedit_commands_load_locations (window,
+ files,
+ encoding,
+ 0);
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
g_slist_free (files);
@@ -626,7 +568,6 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
{
GeditDocument *doc;
gchar *parse_name;
- gchar *uri;
doc = gedit_tab_get_document (tab);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
@@ -644,10 +585,7 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
* even if the saving fails... */
_gedit_window_set_default_location (window, file);
- // FIXME: pass the GFile to tab when api is there
- uri = g_file_get_uri (file);
- _gedit_tab_save_as (tab, uri, encoding, newline_type);
- g_free (uri);
+ _gedit_tab_save_as (tab, file, encoding, newline_type);
}
g_object_unref (file);
diff --git a/gedit/gedit-commands.h b/gedit/gedit-commands.h
index 08e7088..7bb06fb 100644
--- a/gedit/gedit-commands.h
+++ b/gedit/gedit-commands.h
@@ -40,14 +40,14 @@
G_BEGIN_DECLS
/* Do nothing if URI does not exist */
-void gedit_commands_load_uri (GeditWindow *window,
- const gchar *uri,
+void gedit_commands_load_location (GeditWindow *window,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos);
/* Ignore non-existing URIs */
-gint gedit_commands_load_uris (GeditWindow *window,
- const GSList *uris,
+gint gedit_commands_load_locations (GeditWindow *window,
+ const GSList *locations,
const GeditEncoding *encoding,
gint line_pos);
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index 05368c8..917ed5e 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -62,7 +62,7 @@ enum
{
PROP_0,
PROP_DOCUMENT,
- PROP_URI,
+ PROP_LOCATION,
PROP_ENCODING,
PROP_NEWLINE_TYPE
};
@@ -81,9 +81,9 @@ gedit_document_loader_set_property (GObject *object,
g_return_if_fail (loader->document == NULL);
loader->document = g_value_get_object (value);
break;
- case PROP_URI:
- g_return_if_fail (loader->uri == NULL);
- loader->uri = g_value_dup_string (value);
+ case PROP_LOCATION:
+ g_return_if_fail (loader->location == NULL);
+ loader->location = g_value_dup_object (value);
break;
case PROP_ENCODING:
g_return_if_fail (loader->encoding == NULL);
@@ -111,8 +111,8 @@ gedit_document_loader_get_property (GObject *object,
case PROP_DOCUMENT:
g_value_set_object (value, loader->document);
break;
- case PROP_URI:
- g_value_set_string (value, loader->uri);
+ case PROP_LOCATION:
+ g_value_set_object (value, loader->location);
break;
case PROP_ENCODING:
g_value_set_boxed (value, gedit_document_loader_get_encoding (loader));
@@ -129,13 +129,6 @@ gedit_document_loader_get_property (GObject *object,
static void
gedit_document_loader_finalize (GObject *object)
{
- GeditDocumentLoader *loader = GEDIT_DOCUMENT_LOADER (object);
-
- g_free (loader->uri);
-
- if (loader->info)
- g_object_unref (loader->info);
-
G_OBJECT_CLASS (gedit_document_loader_parent_class)->finalize (object);
}
@@ -149,6 +142,12 @@ gedit_document_loader_dispose (GObject *object)
g_object_unref (loader->info);
loader->info = NULL;
}
+
+ if (loader->location != NULL)
+ {
+ g_object_unref (loader->location);
+ loader->location = NULL;
+ }
G_OBJECT_CLASS (gedit_document_loader_parent_class)->dispose (object);
}
@@ -174,11 +173,11 @@ gedit_document_loader_class_init (GeditDocumentLoaderClass *klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
- PROP_URI,
- g_param_spec_string ("uri",
- "URI",
- "The URI this GeditDocumentLoader loads the document from",
- "",
+ PROP_LOCATION,
+ g_param_spec_object ("location",
+ "LOCATION",
+ "The LOCATION this GeditDocumentLoader loads the document from",
+ G_TYPE_FILE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
@@ -249,11 +248,11 @@ gedit_document_loader_loading (GeditDocumentLoader *loader,
}
/* This is a factory method that returns an appopriate loader
- * for the given uri.
+ * for the given location.
*/
GeditDocumentLoader *
gedit_document_loader_new (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding)
{
GeditDocumentLoader *loader;
@@ -268,7 +267,7 @@ gedit_document_loader_new (GeditDocument *doc,
loader = GEDIT_DOCUMENT_LOADER (g_object_new (loader_type,
"document", doc,
- "uri", uri,
+ "location", location,
"encoding", encoding,
NULL));
@@ -309,12 +308,12 @@ gedit_document_loader_get_document (GeditDocumentLoader *loader)
}
/* Returns STDIN_URI if loading from stdin */
-const gchar *
-gedit_document_loader_get_uri (GeditDocumentLoader *loader)
+GFile *
+gedit_document_loader_get_location (GeditDocumentLoader *loader)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader), NULL);
- return loader->uri;
+ return g_file_dup (loader->location);
}
goffset
diff --git a/gedit/gedit-document-loader.h b/gedit/gedit-document-loader.h
index a627fba..c3cc176 100644
--- a/gedit/gedit-document-loader.h
+++ b/gedit/gedit-document-loader.h
@@ -63,7 +63,7 @@ struct _GeditDocumentLoader
/* Info on the current file */
GFileInfo *info;
- gchar *uri;
+ GFile *location;
const GeditEncoding *encoding;
const GeditEncoding *auto_detected_encoding;
GeditDocumentNewlineType auto_detected_newline_type;
@@ -96,7 +96,7 @@ GType gedit_document_loader_get_type (void) G_GNUC_CONST;
/* If enconding == NULL, the encoding will be autodetected */
GeditDocumentLoader *gedit_document_loader_new (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding);
void gedit_document_loader_loading (GeditDocumentLoader *loader,
@@ -113,7 +113,7 @@ GeditDocument *gedit_document_loader_get_document (GeditDocumentLoader *loader)
/* Returns STDIN_URI if loading from stdin */
#define STDIN_URI "stdin:"
-const gchar *gedit_document_loader_get_uri (GeditDocumentLoader *loader);
+GFile *gedit_document_loader_get_location (GeditDocumentLoader *loader);
const GeditEncoding *gedit_document_loader_get_encoding (GeditDocumentLoader *loader);
diff --git a/gedit/gedit-document-saver.c b/gedit/gedit-document-saver.c
index 1a064da..53b2a5b 100644
--- a/gedit/gedit-document-saver.c
+++ b/gedit/gedit-document-saver.c
@@ -61,7 +61,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
enum {
PROP_0,
PROP_DOCUMENT,
- PROP_URI,
+ PROP_LOCATION,
PROP_ENCODING,
PROP_NEWLINE_TYPE,
PROP_FLAGS
@@ -81,9 +81,9 @@ gedit_document_saver_set_property (GObject *object,
g_return_if_fail (saver->document == NULL);
saver->document = g_value_get_object (value);
break;
- case PROP_URI:
- g_return_if_fail (saver->uri == NULL);
- saver->uri = g_value_dup_string (value);
+ case PROP_LOCATION:
+ g_return_if_fail (saver->location == NULL);
+ saver->location = g_value_dup_object (value);
break;
case PROP_ENCODING:
g_return_if_fail (saver->encoding == NULL);
@@ -114,8 +114,8 @@ gedit_document_saver_get_property (GObject *object,
case PROP_DOCUMENT:
g_value_set_object (value, saver->document);
break;
- case PROP_URI:
- g_value_set_string (value, saver->uri);
+ case PROP_LOCATION:
+ g_value_set_object (value, saver->location);
break;
case PROP_ENCODING:
g_value_set_boxed (value, saver->encoding);
@@ -133,16 +133,6 @@ gedit_document_saver_get_property (GObject *object,
}
static void
-gedit_document_saver_finalize (GObject *object)
-{
- GeditDocumentSaver *saver = GEDIT_DOCUMENT_SAVER (object);
-
- g_free (saver->uri);
-
- G_OBJECT_CLASS (gedit_document_saver_parent_class)->finalize (object);
-}
-
-static void
gedit_document_saver_dispose (GObject *object)
{
GeditDocumentSaver *saver = GEDIT_DOCUMENT_SAVER (object);
@@ -152,6 +142,12 @@ gedit_document_saver_dispose (GObject *object)
g_object_unref (saver->info);
saver->info = NULL;
}
+
+ if (saver->location != NULL)
+ {
+ g_object_unref (saver->location);
+ saver->location = NULL;
+ }
G_OBJECT_CLASS (gedit_document_saver_parent_class)->dispose (object);
}
@@ -161,7 +157,6 @@ gedit_document_saver_class_init (GeditDocumentSaverClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = gedit_document_saver_finalize;
object_class->dispose = gedit_document_saver_dispose;
object_class->set_property = gedit_document_saver_set_property;
object_class->get_property = gedit_document_saver_get_property;
@@ -177,11 +172,11 @@ gedit_document_saver_class_init (GeditDocumentSaverClass *klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
- PROP_URI,
- g_param_spec_string ("uri",
- "URI",
- "The URI this GeditDocumentSaver saves the document to",
- "",
+ PROP_LOCATION,
+ g_param_spec_object ("location",
+ "LOCATION",
+ "The LOCATION this GeditDocumentSaver saves the document to",
+ G_TYPE_FILE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
@@ -189,7 +184,7 @@ gedit_document_saver_class_init (GeditDocumentSaverClass *klass)
g_object_class_install_property (object_class,
PROP_ENCODING,
g_param_spec_boxed ("encoding",
- "URI",
+ "ENCODING",
"The encoding of the saved file",
GEDIT_TYPE_ENCODING,
G_PARAM_READWRITE |
@@ -239,7 +234,7 @@ gedit_document_saver_init (GeditDocumentSaver *saver)
GeditDocumentSaver *
gedit_document_saver_new (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentNewlineType newline_type,
GeditDocumentSaveFlags flags)
@@ -256,7 +251,7 @@ gedit_document_saver_new (GeditDocument *doc,
saver = GEDIT_DOCUMENT_SAVER (g_object_new (saver_type,
"document", doc,
- "uri", uri,
+ "location", location,
"encoding", encoding,
"newline_type", newline_type,
"flags", flags,
@@ -298,15 +293,14 @@ gedit_document_saver_save (GeditDocumentSaver *saver,
gedit_debug (DEBUG_SAVER);
g_return_if_fail (GEDIT_IS_DOCUMENT_SAVER (saver));
- g_return_if_fail (saver->uri != NULL && strlen (saver->uri) > 0);
+ g_return_if_fail (saver->location != NULL);
g_return_if_fail (saver->used == FALSE);
saver->used = TRUE;
- // CHECK:
- // - sanity check a max len for the uri?
- // report async (in an idle handler) or sync (bool ret)
- // async is extra work here, sync is special casing in the caller
+ /* CHECK:
+ report async (in an idle handler) or sync (bool ret)
+ async is extra work here, sync is special casing in the caller */
/* never keep backup of autosaves */
if ((saver->flags & GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP) != 0)
@@ -325,12 +319,12 @@ gedit_document_saver_get_document (GeditDocumentSaver *saver)
return saver->document;
}
-const gchar *
-gedit_document_saver_get_uri (GeditDocumentSaver *saver)
+GFile *
+gedit_document_saver_get_location (GeditDocumentSaver *saver)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT_SAVER (saver), NULL);
- return saver->uri;
+ return g_file_dup (saver->location);
}
/* Returns 0 if file size is unknown */
diff --git a/gedit/gedit-document-saver.h b/gedit/gedit-document-saver.h
index ccc0b5c..1f1f4ba 100644
--- a/gedit/gedit-document-saver.h
+++ b/gedit/gedit-document-saver.h
@@ -60,7 +60,7 @@ struct _GeditDocumentSaver
GeditDocument *document;
gboolean used;
- gchar *uri;
+ GFile *location;
const GeditEncoding *encoding;
GeditDocumentNewlineType newline_type;
@@ -97,7 +97,7 @@ GType gedit_document_saver_get_type (void) G_GNUC_CONST;
/* If enconding == NULL, the encoding will be autodetected */
GeditDocumentSaver *gedit_document_saver_new (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentNewlineType newline_type,
GeditDocumentSaveFlags flags);
@@ -114,7 +114,7 @@ void gedit_document_saver_cancel (GeditDocumentSaver *saver);
GeditDocument *gedit_document_saver_get_document (GeditDocumentSaver *saver);
-const gchar *gedit_document_saver_get_uri (GeditDocumentSaver *saver);
+GFile *gedit_document_saver_get_location (GeditDocumentSaver *saver);
/* If backup_uri is NULL no backup will be made */
const gchar *gedit_document_saver_get_backup_uri (GeditDocumentSaver *saver);
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index d961226..ae9c61a 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -79,12 +79,12 @@ PROFILE (static GTimer *timer = NULL)
#define GEDIT_DOCUMENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_DOCUMENT, GeditDocumentPrivate))
static void gedit_document_load_real (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create);
static void gedit_document_save_real (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentSaveFlags flags);
static void to_search_region_range (GeditDocument *doc,
@@ -101,7 +101,7 @@ static void delete_range_cb (GeditDocument *doc,
struct _GeditDocumentPrivate
{
- gchar *uri;
+ GFile *location;
gint untitled_number;
gchar *short_name;
@@ -148,7 +148,7 @@ struct _GeditDocumentPrivate
enum {
PROP_0,
- PROP_URI,
+ PROP_LOCATION,
PROP_SHORTNAME,
PROP_CONTENT_TYPE,
PROP_MIME_TYPE,
@@ -232,7 +232,7 @@ gedit_document_dispose (GObject *object)
* because the language is gone by the time finalize runs.
* beside if some plugin prevents proper finalization by
* holding a ref to the doc, we still save the metadata */
- if ((!doc->priv->dispose_has_run) && (doc->priv->uri != NULL))
+ if ((!doc->priv->dispose_has_run) && (doc->priv->location != NULL))
{
GtkTextIter iter;
gchar *position;
@@ -280,6 +280,12 @@ gedit_document_dispose (GObject *object)
doc->priv->metadata_info = NULL;
}
+ if (doc->priv->location != NULL)
+ {
+ g_object_unref (doc->priv->location);
+ doc->priv->location = NULL;
+ }
+
doc->priv->dispose_has_run = TRUE;
G_OBJECT_CLASS (gedit_document_parent_class)->dispose (object);
@@ -294,11 +300,9 @@ gedit_document_finalize (GObject *object)
if (doc->priv->untitled_number > 0)
{
- g_return_if_fail (doc->priv->uri == NULL);
release_untitled_number (doc->priv->untitled_number);
}
- g_free (doc->priv->uri);
g_free (doc->priv->content_type);
g_free (doc->priv->search_text);
@@ -321,8 +325,8 @@ gedit_document_get_property (GObject *object,
switch (prop_id)
{
- case PROP_URI:
- g_value_set_string (value, doc->priv->uri);
+ case PROP_LOCATION:
+ g_value_set_object (value, doc->priv->location);
break;
case PROP_SHORTNAME:
g_value_take_string (value, gedit_document_get_short_name_for_display (doc));
@@ -440,11 +444,11 @@ gedit_document_class_init (GeditDocumentClass *klass)
klass->load = gedit_document_load_real;
klass->save = gedit_document_save_real;
- g_object_class_install_property (object_class, PROP_URI,
- g_param_spec_string ("uri",
- "URI",
- "The document's URI",
- NULL,
+ g_object_class_install_property (object_class, PROP_LOCATION,
+ g_param_spec_object ("location",
+ "LOCATION",
+ "The document's location",
+ G_TYPE_FILE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
@@ -539,7 +543,7 @@ gedit_document_class_init (GeditDocumentClass *klass)
/**
* GeditDocument::load:
* @document: the #GeditDocument.
- * @uri: the uri where to load the document from.
+ * @location: the location where to load the document from.
* @encoding: the #GeditEncoding to encode the document.
* @line_pos: the line to show.
* @create: whether the document should be created if it doesn't exist.
@@ -554,10 +558,10 @@ gedit_document_class_init (GeditDocumentClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GeditDocumentClass, load),
NULL, NULL,
- gedit_marshal_VOID__STRING_BOXED_INT_BOOLEAN,
+ gedit_marshal_VOID__OBJECT_BOXED_INT_BOOLEAN,
G_TYPE_NONE,
4,
- G_TYPE_STRING,
+ G_TYPE_FILE,
/* we rely on the fact that the GeditEncoding pointer stays
* the same forever */
GEDIT_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE,
@@ -591,7 +595,7 @@ gedit_document_class_init (GeditDocumentClass *klass)
/**
* GeditDocument::save:
* @document: the #GeditDocument.
- * @uri: the uri where the document is about to be saved.
+ * @location: the location where the document is about to be saved.
* @encoding: the #GeditEncoding used to save the document.
* @flags: the #GeditDocumentSaveFlags for the save operation.
*
@@ -605,10 +609,10 @@ gedit_document_class_init (GeditDocumentClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GeditDocumentClass, save),
NULL, NULL,
- gedit_marshal_VOID__STRING_BOXED_FLAGS,
+ gedit_marshal_VOID__OBJECT_BOXED_FLAGS,
G_TYPE_NONE,
3,
- G_TYPE_STRING,
+ G_TYPE_FILE,
/* we rely on the fact that the GeditEncoding pointer stays
* the same forever */
GEDIT_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE,
@@ -675,7 +679,7 @@ set_language (GeditDocument *doc,
gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc),
FALSE);
- if (set_by_user && (doc->priv->uri != NULL))
+ if (set_by_user)
{
gedit_document_set_metadata (doc, GEDIT_METADATA_ATTRIBUTE_LANGUAGE,
(lang == NULL) ? "_NORMAL_" : gtk_source_language_get_id (lang),
@@ -741,18 +745,18 @@ get_default_style_scheme (void)
}
static void
-on_uri_changed (GeditDocument *doc,
- GParamSpec *pspec,
- gpointer useless)
+on_location_changed (GeditDocument *doc,
+ GParamSpec *pspec,
+ gpointer useless)
{
#ifdef ENABLE_GVFS_METADATA
GFile *location;
location = gedit_document_get_location (doc);
- /* load metadata for this uri: we load sync since metadata is
+ /* 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 uri was set.
+ * right after the location was set.
*/
if (location != NULL)
{
@@ -808,15 +812,15 @@ guess_language (GeditDocument *doc,
}
else
{
- GFile *file;
+ GFile *location;
gchar *basename = NULL;
- file = gedit_document_get_location (doc);
+ location = gedit_document_get_location (doc);
gedit_debug_message (DEBUG_DOCUMENT, "Sniffing Language");
- if (file)
+ if (location)
{
- basename = g_file_get_basename (file);
+ basename = g_file_get_basename (location);
}
else if (doc->priv->short_name != NULL)
{
@@ -830,9 +834,9 @@ guess_language (GeditDocument *doc,
g_free (basename);
- if (file != NULL)
+ if (location != NULL)
{
- g_object_unref (file);
+ g_object_unref (location);
}
}
@@ -872,7 +876,7 @@ gedit_document_init (GeditDocument *doc)
doc->priv = GEDIT_DOCUMENT_GET_PRIVATE (doc);
- doc->priv->uri = NULL;
+ doc->priv->location = NULL;
doc->priv->untitled_number = get_untitled_number ();
doc->priv->metadata_info = NULL;
@@ -927,8 +931,8 @@ gedit_document_init (GeditDocument *doc)
NULL);
g_signal_connect (doc,
- "notify::uri",
- G_CALLBACK (on_uri_changed),
+ "notify::location",
+ G_CALLBACK (on_location_changed),
NULL);
}
@@ -968,20 +972,20 @@ set_content_type (GeditDocument *doc,
if (content_type == NULL)
{
- GFile *file;
+ GFile *location;
gchar *guessed_type = NULL;
/* If content type is null, we guess from the filename */
- file = gedit_document_get_location (doc);
- if (file != NULL)
+ location = gedit_document_get_location (doc);
+ if (location != NULL)
{
gchar *basename;
- basename = g_file_get_basename (file);
+ basename = g_file_get_basename (location);
guessed_type = g_content_type_guess (basename, NULL, 0, NULL);
g_free (basename);
- g_object_unref (file);
+ g_object_unref (location);
}
set_content_type_no_guess (doc, guessed_type);
@@ -1004,20 +1008,21 @@ gedit_document_set_content_type (GeditDocument *doc,
}
static void
-set_uri (GeditDocument *doc,
- const gchar *uri)
+set_location (GeditDocument *doc,
+ GFile *location)
{
gedit_debug (DEBUG_DOCUMENT);
- g_return_if_fail ((uri == NULL) || gedit_utils_is_valid_uri (uri));
+ g_return_if_fail ((location == NULL) || gedit_utils_is_valid_location (location));
- if (uri != NULL)
+ if (location != NULL)
{
- if (doc->priv->uri == uri)
+ if (doc->priv->location == location)
return;
- g_free (doc->priv->uri);
- doc->priv->uri = g_strdup (uri);
+ if (doc->priv->location != NULL)
+ g_object_unref (doc->priv->location);
+ doc->priv->location = g_file_dup (location);
if (doc->priv->untitled_number > 0)
{
@@ -1026,7 +1031,7 @@ set_uri (GeditDocument *doc,
}
}
- g_object_notify (G_OBJECT (doc), "uri");
+ g_object_notify (G_OBJECT (doc), "location");
if (doc->priv->short_name == NULL)
{
@@ -1039,25 +1044,17 @@ gedit_document_get_location (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
- return doc->priv->uri == NULL ? NULL : g_file_new_for_uri (doc->priv->uri);
-}
-
-gchar *
-gedit_document_get_uri (GeditDocument *doc)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
-
- return g_strdup (doc->priv->uri);
+ return doc->priv->location == NULL ? NULL : g_file_dup (doc->priv->location);
}
void
-gedit_document_set_uri (GeditDocument *doc,
- const gchar *uri)
+gedit_document_set_location (GeditDocument *doc,
+ GFile *location)
{
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail (uri != NULL);
+ g_return_if_fail (G_IS_FILE (location));
- set_uri (doc, uri);
+ set_location (doc, location);
set_content_type (doc, NULL);
}
@@ -1067,11 +1064,11 @@ gedit_document_get_uri_for_display (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), g_strdup (""));
- if (doc->priv->uri == NULL)
+ if (doc->priv->location == NULL)
return g_strdup_printf (_("Unsaved Document %d"),
doc->priv->untitled_number);
else
- return gedit_utils_uri_for_display (doc->priv->uri);
+ return gedit_utils_uri_for_display (doc->priv->location);
}
/* Never returns NULL */
@@ -1082,11 +1079,11 @@ gedit_document_get_short_name_for_display (GeditDocument *doc)
if (doc->priv->short_name != NULL)
return g_strdup (doc->priv->short_name);
- else if (doc->priv->uri == NULL)
+ else if (doc->priv->location == NULL)
return g_strdup_printf (_("Unsaved Document %d"),
doc->priv->untitled_number);
else
- return gedit_utils_basename_for_display (doc->priv->uri);
+ return gedit_utils_basename_for_display (doc->priv->location);
}
void
@@ -1175,23 +1172,20 @@ gedit_document_get_readonly (GeditDocument *doc)
gboolean
_gedit_document_check_externally_modified (GeditDocument *doc)
{
- GFile *gfile;
GFileInfo *info;
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- if (doc->priv->uri == NULL)
+ if (doc->priv->location == NULL)
{
return FALSE;
}
- gfile = g_file_new_for_uri (doc->priv->uri);
- info = g_file_query_info (gfile,
+ info = g_file_query_info (doc->priv->location,
G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
- g_object_unref (gfile);
if (info != NULL)
{
@@ -1325,7 +1319,7 @@ document_loader_loaded (GeditDocumentLoader *loader,
/* special case creating a named new doc */
else if (doc->priv->create &&
(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND) &&
- (gedit_utils_uri_has_file_scheme (doc->priv->uri)))
+ (gedit_utils_location_has_file_scheme (doc->priv->location)))
{
reset_temp_loading_data (doc);
@@ -1379,17 +1373,21 @@ document_loader_loading (GeditDocumentLoader *loader,
static void
gedit_document_load_real (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create)
{
+ gchar *uri;
+
g_return_if_fail (doc->priv->loader == NULL);
+ uri = g_file_get_uri (location);
gedit_debug_message (DEBUG_DOCUMENT, "load_real: uri = %s", uri);
+ g_free (uri);
/* create a loader. It will be destroyed when loading is completed */
- doc->priv->loader = gedit_document_loader_new (doc, uri, encoding);
+ doc->priv->loader = gedit_document_loader_new (doc, location, encoding);
g_signal_connect (doc->priv->loader,
"loading",
@@ -1400,7 +1398,7 @@ gedit_document_load_real (GeditDocument *doc,
doc->priv->requested_encoding = encoding;
doc->priv->requested_line_pos = line_pos;
- set_uri (doc, uri);
+ set_location (doc, location);
set_content_type (doc, NULL);
gedit_document_loader_load (doc->priv->loader);
@@ -1409,7 +1407,7 @@ gedit_document_load_real (GeditDocument *doc,
/**
* gedit_document_load:
* @doc: the #GeditDocument.
- * @uri: the uri where to load the document from.
+ * @location: the location where to load the document from.
* @encoding: the #GeditEncoding to encode the document.
* @line_pos: the line to show.
* @create: whether the document should be created if it doesn't exist.
@@ -1418,16 +1416,17 @@ gedit_document_load_real (GeditDocument *doc,
*/
void
gedit_document_load (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create)
{
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail (uri != NULL);
- g_return_if_fail (gedit_utils_is_valid_uri (uri));
+ g_return_if_fail (location != NULL);
+ g_return_if_fail (gedit_utils_is_valid_location (location));
- g_signal_emit (doc, document_signals[LOAD], 0, uri, encoding, line_pos, create);
+ g_signal_emit (doc, document_signals[LOAD], 0, location, encoding,
+ line_pos, create);
}
/**
@@ -1460,13 +1459,14 @@ document_saver_saving (GeditDocumentSaver *saver,
/* save was successful */
if (error == NULL)
{
- const gchar *uri;
+ GFile *location;
const gchar *content_type = NULL;
GTimeVal mtime = {0, 0};
GFileInfo *info;
- uri = gedit_document_saver_get_uri (saver);
- set_uri (doc, uri);
+ location = gedit_document_saver_get_location (saver);
+ set_location (doc, location);
+ g_object_unref (location);
info = gedit_document_saver_get_info (saver);
@@ -1524,14 +1524,14 @@ document_saver_saving (GeditDocumentSaver *saver,
static void
gedit_document_save_real (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentSaveFlags flags)
{
g_return_if_fail (doc->priv->saver == NULL);
/* create a saver, it will be destroyed once saving is complete */
- doc->priv->saver = gedit_document_saver_new (doc, uri, encoding,
+ doc->priv->saver = gedit_document_saver_new (doc, location, encoding,
doc->priv->newline_type,
flags);
@@ -1559,12 +1559,12 @@ gedit_document_save (GeditDocument *doc,
GeditDocumentSaveFlags flags)
{
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail (doc->priv->uri != NULL);
+ g_return_if_fail (G_IS_FILE (doc->priv->location));
g_signal_emit (doc,
document_signals[SAVE],
0,
- doc->priv->uri,
+ doc->priv->location,
doc->priv->encoding,
flags);
}
@@ -1572,7 +1572,7 @@ gedit_document_save (GeditDocument *doc,
/**
* gedit_document_save_as:
* @doc: the #GeditDocument.
- * @uri: the uri where to save the document.
+ * @location: the location where to save the document.
* @encoding: the #GeditEncoding to encode the document.
* @flags: optionnal #GeditDocumentSaveFlags.
*
@@ -1581,46 +1581,30 @@ gedit_document_save (GeditDocument *doc,
*/
void
gedit_document_save_as (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentSaveFlags flags)
{
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail (uri != NULL);
+ g_return_if_fail (G_IS_FILE (location));
g_return_if_fail (encoding != NULL);
- /* priv->mtime refers to the the old uri (if any). Thus, it should be
+ /* priv->mtime refers to the the old location (if any). Thus, it should be
* ignored when saving as. */
g_signal_emit (doc,
document_signals[SAVE],
0,
- uri,
+ location,
encoding,
flags | GEDIT_DOCUMENT_SAVE_IGNORE_MTIME);
}
-gboolean
-gedit_document_insert_file (GeditDocument *doc,
- GtkTextIter *iter,
- const gchar *uri,
- const GeditEncoding *encoding)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (gtk_text_iter_get_buffer (iter) ==
- GTK_TEXT_BUFFER (doc), FALSE);
-
- /* TODO */
-
- return FALSE;
-}
-
gboolean
gedit_document_is_untouched (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
- return (doc->priv->uri == NULL) &&
+ return (doc->priv->location == NULL) &&
(!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)));
}
@@ -1629,7 +1613,7 @@ gedit_document_is_untitled (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
- return (doc->priv->uri == NULL);
+ return (doc->priv->location == NULL);
}
gboolean
@@ -1637,12 +1621,12 @@ gedit_document_is_local (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- if (doc->priv->uri == NULL)
+ if (doc->priv->location == NULL)
{
return FALSE;
}
- return gedit_utils_uri_has_file_scheme (doc->priv->uri);
+ return gedit_utils_location_has_file_scheme (doc->priv->location);
}
gboolean
@@ -1650,7 +1634,8 @@ gedit_document_get_deleted (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- return doc->priv->uri && !gedit_utils_uri_exists (doc->priv->uri);
+ /* This is done sync, maybe we should do it async? */
+ return doc->priv->location && !gedit_utils_location_exists (doc->priv->location);
}
/*
@@ -2577,13 +2562,14 @@ gedit_document_get_metadata (GeditDocument *doc,
const gchar *key)
{
gchar *value = NULL;
+ gchar *uri;
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
g_return_val_if_fail (key != NULL, NULL);
if (!gedit_document_is_untitled (doc))
{
- value = gedit_metadata_manager_get (doc->priv->uri, key);
+ value = gedit_metadata_manager_get (doc->priv->location, key);
}
return value;
@@ -2612,10 +2598,11 @@ gedit_document_set_metadata (GeditDocument *doc,
for (key = first_key; key; key = va_arg (var_args, const gchar *))
{
value = va_arg (var_args, const gchar *);
-
- gedit_metadata_manager_set (doc->priv->uri,
- key,
- value);
+
+ if (doc->priv->location != NULL)
+ {
+ gedit_metadata_manager_set (location, key, value);
+ }
}
va_end (var_args);
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index cf966b1..09f0a9a 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -126,7 +126,7 @@ struct _GeditDocumentClass
/* Document load */
void (* load) (GeditDocument *document,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create);
@@ -140,7 +140,7 @@ struct _GeditDocumentClass
/* Document save */
void (* save) (GeditDocument *document,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentSaveFlags flags);
@@ -177,10 +177,8 @@ GType gedit_document_get_type (void) G_GNUC_CONST;
GeditDocument *gedit_document_new (void);
GFile *gedit_document_get_location (GeditDocument *doc);
-
-gchar *gedit_document_get_uri (GeditDocument *doc);
-void gedit_document_set_uri (GeditDocument *doc,
- const gchar *uri);
+void gedit_document_set_location (GeditDocument *doc,
+ GFile *location);
gchar *gedit_document_get_uri_for_display
(GeditDocument *doc);
@@ -203,15 +201,10 @@ gchar *gedit_document_get_mime_type (GeditDocument *doc);
gboolean gedit_document_get_readonly (GeditDocument *doc);
void gedit_document_load (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
- gboolean create);
-
-gboolean gedit_document_insert_file (GeditDocument *doc,
- GtkTextIter *iter,
- const gchar *uri,
- const GeditEncoding *encoding);
+ gboolean create);
gboolean gedit_document_load_cancel (GeditDocument *doc);
@@ -219,7 +212,7 @@ void gedit_document_save (GeditDocument *doc,
GeditDocumentSaveFlags flags);
void gedit_document_save_as (GeditDocument *doc,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentSaveFlags flags);
diff --git a/gedit/gedit-gio-document-loader.c b/gedit/gedit-gio-document-loader.c
index 73cfe11..7ecd3a9 100644
--- a/gedit/gedit-gio-document-loader.c
+++ b/gedit/gedit-gio-document-loader.c
@@ -79,9 +79,6 @@ static void open_async_read (AsyncData *async);
struct _GeditGioDocumentLoaderPrivate
{
- /* Info on the current file */
- GFile *gfile;
-
goffset bytes_read;
/* Handle for remote files */
@@ -129,12 +126,6 @@ gedit_gio_document_loader_dispose (GObject *object)
priv->converter = NULL;
}
- if (priv->gfile != NULL)
- {
- g_object_unref (priv->gfile);
- priv->gfile = NULL;
- }
-
if (priv->error != NULL)
{
g_error_free (priv->error);
@@ -195,11 +186,15 @@ get_metadata_encoding (GeditDocumentLoader *loader)
#ifndef ENABLE_GVFS_METADATA
gchar *charset;
- const gchar *uri;
+ GFile *location;
+ gchar *uri;
- uri = gedit_document_loader_get_uri (loader);
+ location = gedit_document_loader_get_location (loader);
+ uri = g_file_get_uri (location);
+ g_object_unref (location);
charset = gedit_metadata_manager_get (uri, "encoding");
+ g_free (uri);
if (charset == NULL)
return NULL;
@@ -507,7 +502,7 @@ query_info_cb (GFile *source,
GAsyncResult *res,
AsyncData *async)
{
- GeditGioDocumentLoader *gvloader;
+ GeditDocumentLoader *loader;
GFileInfo *info;
GError *error = NULL;
@@ -520,10 +515,10 @@ query_info_cb (GFile *source,
return;
}
- gvloader = async->loader;
+ loader = GEDIT_DOCUMENT_LOADER (async->loader);
/* finish the info query */
- info = g_file_query_info_finish (gvloader->priv->gfile,
+ info = g_file_query_info_finish (loader->location,
res,
&error);
@@ -534,7 +529,7 @@ query_info_cb (GFile *source,
return;
}
- GEDIT_DOCUMENT_LOADER (gvloader)->info = info;
+ loader->info = info;
finish_query_info (async);
}
@@ -574,14 +569,16 @@ recover_not_mounted (AsyncData *async)
{
GeditDocument *doc;
GMountOperation *mount_operation;
+ GeditDocumentLoader *loader;
gedit_debug (DEBUG_LOADER);
- doc = gedit_document_loader_get_document (GEDIT_DOCUMENT_LOADER (async->loader));
+ loader = GEDIT_DOCUMENT_LOADER (async->loader);
+ doc = gedit_document_loader_get_document (loader);
mount_operation = _gedit_document_create_mount_operation (doc);
async->tried_mount = TRUE;
- g_file_mount_enclosing_volume (async->loader->priv->gfile,
+ g_file_mount_enclosing_volume (loader->location,
G_MOUNT_MOUNT_NONE,
mount_operation,
async->cancellable,
@@ -610,7 +607,7 @@ async_read_ready_callback (GObject *source,
gvloader = async->loader;
- gvloader->priv->stream = G_INPUT_STREAM (g_file_read_finish (gvloader->priv->gfile,
+ gvloader->priv->stream = G_INPUT_STREAM (g_file_read_finish (GEDIT_DOCUMENT_LOADER (gvloader)->location,
res, &error));
if (!gvloader->priv->stream)
@@ -638,7 +635,7 @@ async_read_ready_callback (GObject *source,
* Using the file instead of the stream is slightly racy, but for
* loading this is not too bad...
*/
- g_file_query_info_async (gvloader->priv->gfile,
+ g_file_query_info_async (GEDIT_DOCUMENT_LOADER (gvloader)->location,
REMOTE_QUERY_ATTRIBUTES,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_HIGH,
@@ -650,7 +647,7 @@ async_read_ready_callback (GObject *source,
static void
open_async_read (AsyncData *async)
{
- g_file_read_async (async->loader->priv->gfile,
+ g_file_read_async (GEDIT_DOCUMENT_LOADER (async->loader)->location,
G_PRIORITY_HIGH,
async->cancellable,
(GAsyncReadyCallback) async_read_ready_callback,
@@ -668,8 +665,6 @@ gedit_gio_document_loader_load (GeditDocumentLoader *loader)
/* make sure no load operation is currently running */
g_return_if_fail (gvloader->priv->cancellable == NULL);
- gvloader->priv->gfile = g_file_new_for_uri (loader->uri);
-
/* loading start */
gedit_document_loader_loading (GEDIT_DOCUMENT_LOADER (gvloader),
FALSE,
diff --git a/gedit/gedit-gio-document-saver.c b/gedit/gedit-gio-document-saver.c
index 7027ab3..3072c3e 100644
--- a/gedit/gedit-gio-document-saver.c
+++ b/gedit/gedit-gio-document-saver.c
@@ -76,7 +76,6 @@ struct _GeditGioDocumentSaverPrivate
goffset size;
goffset bytes_written;
- GFile *gfile;
GCancellable *cancellable;
GOutputStream *stream;
GInputStream *input;
@@ -98,12 +97,6 @@ gedit_gio_document_saver_dispose (GObject *object)
priv->cancellable = NULL;
}
- if (priv->gfile != NULL)
- {
- g_object_unref (priv->gfile);
- priv->gfile = NULL;
- }
-
if (priv->error != NULL)
{
g_error_free (priv->error);
@@ -350,7 +343,7 @@ close_async_ready_get_info_cb (GOutputStream *stream,
* g_content_type_guess (since we have the file name and the data)
*/
gedit_debug_message (DEBUG_SAVER, "Query info on file");
- g_file_query_info_async (async->saver->priv->gfile,
+ g_file_query_info_async (GEDIT_DOCUMENT_SAVER (async->saver)->location,
REMOTE_QUERY_ATTRIBUTES,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_HIGH,
@@ -576,7 +569,7 @@ begin_write (AsyncData *async)
gedit_debug_message (DEBUG_SAVER, "Calling replace_async");
gedit_debug_message (DEBUG_SAVER, backup ? "Keep backup" : "Discard backup");
- g_file_replace_async (gvsaver->priv->gfile,
+ g_file_replace_async (saver->location,
NULL,
backup,
G_FILE_CREATE_NONE,
@@ -619,16 +612,18 @@ mount_ready_callback (GFile *file,
static void
recover_not_mounted (AsyncData *async)
{
+ GeditDocumentSaver *saver;
GeditDocument *doc;
GMountOperation *mount_operation;
gedit_debug (DEBUG_LOADER);
- doc = gedit_document_saver_get_document (GEDIT_DOCUMENT_SAVER (async->saver));
+ saver = GEDIT_DOCUMENT_SAVER (async->saver);
+ doc = gedit_document_saver_get_document (saver);
mount_operation = _gedit_document_create_mount_operation (doc);
async->tried_mount = TRUE;
- g_file_mount_enclosing_volume (async->saver->priv->gfile,
+ g_file_mount_enclosing_volume (saver->location,
G_MOUNT_MOUNT_NONE,
mount_operation,
async->cancellable,
@@ -716,7 +711,7 @@ check_modified_async (AsyncData *async)
{
gedit_debug_message (DEBUG_SAVER, "Check externally modified");
- g_file_query_info_async (async->saver->priv->gfile,
+ g_file_query_info_async (GEDIT_DOCUMENT_SAVER (async->saver)->location,
G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_HIGH,
@@ -750,7 +745,6 @@ gedit_gio_document_saver_save (GeditDocumentSaver *saver,
GeditGioDocumentSaver *gvsaver = GEDIT_GIO_DOCUMENT_SAVER (saver);
gvsaver->priv->old_mtime = *old_mtime;
- gvsaver->priv->gfile = g_file_new_for_uri (saver->uri);
/* saving start */
gedit_document_saver_saving (saver, FALSE, NULL);
diff --git a/gedit/gedit-io-error-message-area.c b/gedit/gedit-io-error-message-area.c
index e116a15..1760dc6 100644
--- a/gedit/gedit-io-error-message-area.c
+++ b/gedit/gedit-io-error-message-area.c
@@ -211,7 +211,7 @@ static gboolean
parse_gio_error (gint code,
gchar **error_message,
gchar **message_details,
- const gchar *uri,
+ GFile *location,
const gchar *uri_for_display)
{
gboolean ret = TRUE;
@@ -230,7 +230,7 @@ parse_gio_error (gint code,
gchar *scheme_string;
gchar *scheme_markup;
- scheme_string = g_uri_parse_scheme (uri);
+ scheme_string = g_file_get_uri_scheme (location);
if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL))
{
@@ -280,8 +280,11 @@ parse_gio_error (gint code,
*/
{
gchar *hn = NULL;
+ gchar *uri;
- if (gedit_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL))
+ uri = g_file_get_uri (location);
+
+ if (uri && gedit_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL))
{
if (hn != NULL)
{
@@ -304,6 +307,8 @@ parse_gio_error (gint code,
g_free (host_markup);
}
}
+
+ g_free (uri);
if (!*message_details)
{
@@ -337,7 +342,7 @@ static gboolean
parse_gedit_error (gint code,
gchar **error_message,
gchar **message_details,
- const gchar *uri,
+ GFile *location,
const gchar *uri_for_display)
{
gboolean ret = TRUE;
@@ -360,7 +365,7 @@ static void
parse_error (const GError *error,
gchar **error_message,
gchar **message_details,
- const gchar *uri,
+ GFile *location,
const gchar *uri_for_display)
{
gboolean ret = FALSE;
@@ -370,7 +375,7 @@ parse_error (const GError *error,
ret = parse_gio_error (error->code,
error_message,
message_details,
- uri,
+ location,
uri_for_display);
}
else if (error->domain == GEDIT_DOCUMENT_ERROR)
@@ -378,21 +383,21 @@ parse_error (const GError *error,
ret = parse_gedit_error (error->code,
error_message,
message_details,
- uri,
+ location,
uri_for_display);
}
if (!ret)
{
g_warning ("Hit unhandled case %d (%s) in %s.",
- error->code, error->message, G_STRFUNC);
+ error->code, error->message, G_STRFUNC);
*message_details = g_strdup_printf (_("Unexpected error: %s"),
- error->message);
+ error->message);
}
}
GtkWidget *
-gedit_unrecoverable_reverting_error_message_area_new (const gchar *uri,
+gedit_unrecoverable_reverting_error_message_area_new (GFile *location,
const GError *error)
{
gchar *error_message = NULL;
@@ -402,12 +407,12 @@ gedit_unrecoverable_reverting_error_message_area_new (const gchar *uri,
gchar *temp_uri_for_display;
GtkWidget *message_area;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail ((error->domain == GEDIT_DOCUMENT_ERROR) ||
(error->domain == G_IO_ERROR), NULL);
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
@@ -427,7 +432,7 @@ gedit_unrecoverable_reverting_error_message_area_new (const gchar *uri,
}
else
{
- parse_error (error, &error_message, &message_details, uri, uri_for_display);
+ parse_error (error, &error_message, &message_details, location, uri_for_display);
}
if (error_message == NULL)
@@ -595,7 +600,7 @@ create_conversion_error_message_area (const gchar *primary_text,
}
GtkWidget *
-gedit_io_loading_error_message_area_new (const gchar *uri,
+gedit_io_loading_error_message_area_new (GFile *location,
const GeditEncoding *encoding,
const GError *error)
{
@@ -609,13 +614,13 @@ gedit_io_loading_error_message_area_new (const gchar *uri,
gboolean edit_anyway = FALSE;
gboolean convert_error = FALSE;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) ||
(error->domain == GEDIT_DOCUMENT_ERROR) ||
(error->domain == G_IO_ERROR), NULL);
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
@@ -675,7 +680,7 @@ gedit_io_loading_error_message_area_new (const gchar *uri,
}
else
{
- parse_error (error, &error_message, &message_details, uri, uri_for_display);
+ parse_error (error, &error_message, &message_details, location, uri_for_display);
}
if (error_message == NULL)
@@ -707,9 +712,9 @@ gedit_io_loading_error_message_area_new (const gchar *uri,
GtkWidget *
gedit_conversion_error_while_saving_message_area_new (
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
- const GError *error)
+ const GError *error)
{
gchar *error_message = NULL;
gchar *message_details = NULL;
@@ -719,20 +724,20 @@ gedit_conversion_error_while_saving_message_area_new (
gchar *temp_uri_for_display;
GtkWidget *message_area;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail (error->domain == G_CONVERT_ERROR ||
error->domain == G_IO_ERROR, NULL);
g_return_val_if_fail (encoding != NULL, NULL);
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
* white space then the text-wrapping code is too stupid to wrap it.
*/
temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri,
- MAX_URI_IN_DIALOG_LENGTH);
+ MAX_URI_IN_DIALOG_LENGTH);
g_free (full_formatted_uri);
uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
@@ -780,7 +785,7 @@ gedit_conversion_error_message_area_get_encoding (GtkWidget *message_area)
}
GtkWidget *
-gedit_file_already_open_warning_message_area_new (const gchar *uri)
+gedit_file_already_open_warning_message_area_new (GFile *location)
{
GtkWidget *message_area;
GtkWidget *hbox_content;
@@ -795,15 +800,17 @@ gedit_file_already_open_warning_message_area_new (const gchar *uri)
gchar *full_formatted_uri;
gchar *uri_for_display;
gchar *temp_uri_for_display;
-
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
+
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
* white space then the text-wrapping code is too stupid to wrap it.
*/
temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri,
- MAX_URI_IN_DIALOG_LENGTH);
+ MAX_URI_IN_DIALOG_LENGTH);
g_free (full_formatted_uri);
uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
@@ -877,7 +884,7 @@ gedit_file_already_open_warning_message_area_new (const gchar *uri)
GtkWidget *
gedit_externally_modified_saving_error_message_area_new (
- const gchar *uri,
+ GFile *location,
const GError *error)
{
GtkWidget *message_area;
@@ -894,19 +901,19 @@ gedit_externally_modified_saving_error_message_area_new (
gchar *uri_for_display;
gchar *temp_uri_for_display;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
g_return_val_if_fail (error->code == GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, NULL);
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
* white space then the text-wrapping code is too stupid to wrap it.
*/
temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri,
- MAX_URI_IN_DIALOG_LENGTH);
+ MAX_URI_IN_DIALOG_LENGTH);
g_free (full_formatted_uri);
uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
@@ -981,7 +988,7 @@ gedit_externally_modified_saving_error_message_area_new (
}
GtkWidget *
-gedit_no_backup_saving_error_message_area_new (const gchar *uri,
+gedit_no_backup_saving_error_message_area_new (GFile *location,
const GError *error)
{
GtkWidget *message_area;
@@ -998,21 +1005,21 @@ gedit_no_backup_saving_error_message_area_new (const gchar *uri,
gchar *uri_for_display;
gchar *temp_uri_for_display;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail (((error->domain == GEDIT_DOCUMENT_ERROR &&
error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP) ||
(error->domain == G_IO_ERROR &&
error->code == G_IO_ERROR_CANT_CREATE_BACKUP)), NULL);
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
* white space then the text-wrapping code is too stupid to wrap it.
*/
temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri,
- MAX_URI_IN_DIALOG_LENGTH);
+ MAX_URI_IN_DIALOG_LENGTH);
g_free (full_formatted_uri);
uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
@@ -1093,7 +1100,7 @@ gedit_no_backup_saving_error_message_area_new (const gchar *uri,
}
GtkWidget *
-gedit_unrecoverable_saving_error_message_area_new (const gchar *uri,
+gedit_unrecoverable_saving_error_message_area_new (GFile *location,
const GError *error)
{
gchar *error_message = NULL;
@@ -1105,12 +1112,12 @@ gedit_unrecoverable_saving_error_message_area_new (const gchar *uri,
gchar *temp_uri_for_display;
GtkWidget *message_area;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail ((error->domain == GEDIT_DOCUMENT_ERROR) ||
(error->domain == G_IO_ERROR), NULL);
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
@@ -1125,7 +1132,7 @@ gedit_unrecoverable_saving_error_message_area_new (const gchar *uri,
if (is_gio_error (error, G_IO_ERROR_NOT_SUPPORTED))
{
- scheme_string = g_uri_parse_scheme (uri);
+ scheme_string = g_file_get_uri_scheme (location);
if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL))
{
@@ -1194,7 +1201,7 @@ gedit_unrecoverable_saving_error_message_area_new (const gchar *uri,
parse_error (error,
&error_message,
&message_details,
- uri,
+ location,
uri_for_display);
}
@@ -1216,8 +1223,8 @@ gedit_unrecoverable_saving_error_message_area_new (const gchar *uri,
}
GtkWidget *
-gedit_externally_modified_message_area_new (const gchar *uri,
- gboolean document_modified)
+gedit_externally_modified_message_area_new (GFile *location,
+ gboolean document_modified)
{
gchar *full_formatted_uri;
gchar *uri_for_display;
@@ -1226,9 +1233,9 @@ gedit_externally_modified_message_area_new (const gchar *uri,
const gchar *secondary_text;
GtkWidget *message_area;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
- full_formatted_uri = gedit_utils_uri_for_display (uri);
+ full_formatted_uri = gedit_utils_uri_for_display (location);
/* Truncate the URI so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the URI doesn't contain
diff --git a/gedit/gedit-io-error-message-area.h b/gedit/gedit-io-error-message-area.h
index 69a4d90..1f41264 100644
--- a/gedit/gedit-io-error-message-area.h
+++ b/gedit/gedit-io-error-message-area.h
@@ -35,32 +35,32 @@
G_BEGIN_DECLS
-GtkWidget *gedit_io_loading_error_message_area_new (const gchar *uri,
+GtkWidget *gedit_io_loading_error_message_area_new (GFile *location,
const GeditEncoding *encoding,
const GError *error);
-GtkWidget *gedit_unrecoverable_reverting_error_message_area_new (const gchar *uri,
+GtkWidget *gedit_unrecoverable_reverting_error_message_area_new (GFile *location,
const GError *error);
-GtkWidget *gedit_conversion_error_while_saving_message_area_new (const gchar *uri,
+GtkWidget *gedit_conversion_error_while_saving_message_area_new (GFile *location,
const GeditEncoding *encoding,
const GError *error);
const GeditEncoding
*gedit_conversion_error_message_area_get_encoding (GtkWidget *message_area);
-GtkWidget *gedit_file_already_open_warning_message_area_new (const gchar *uri);
+GtkWidget *gedit_file_already_open_warning_message_area_new (GFile *location);
-GtkWidget *gedit_externally_modified_saving_error_message_area_new (const gchar *uri,
+GtkWidget *gedit_externally_modified_saving_error_message_area_new (GFile *location,
const GError *error);
-GtkWidget *gedit_no_backup_saving_error_message_area_new (const gchar *uri,
+GtkWidget *gedit_no_backup_saving_error_message_area_new (GFile *location,
const GError *error);
-GtkWidget *gedit_unrecoverable_saving_error_message_area_new (const gchar *uri,
+GtkWidget *gedit_unrecoverable_saving_error_message_area_new (GFile *location,
const GError *error);
-GtkWidget *gedit_externally_modified_message_area_new (const gchar *uri,
+GtkWidget *gedit_externally_modified_message_area_new (GFile *location,
gboolean document_modified);
G_END_DECLS
diff --git a/gedit/gedit-marshal.list b/gedit/gedit-marshal.list
index d288294..03d7c9e 100644
--- a/gedit/gedit-marshal.list
+++ b/gedit/gedit-marshal.list
@@ -5,8 +5,8 @@ VOID:BOOLEAN,POINTER
VOID:BOXED,BOXED
VOID:OBJECT
VOID:POINTER
-VOID:STRING,BOXED,FLAGS
-VOID:STRING,BOXED,INT,BOOLEAN
+VOID:OBJECT,BOXED,FLAGS
+VOID:OBJECT,BOXED,INT,BOOLEAN
VOID:UINT,POINTER
VOID:UINT64,UINT64
VOID:VOID
diff --git a/gedit/gedit-metadata-manager.c b/gedit/gedit-metadata-manager.c
index bdb00ff..e05b15e 100644
--- a/gedit/gedit-metadata-manager.c
+++ b/gedit/gedit-metadata-manager.c
@@ -301,15 +301,18 @@ load_values (void)
}
gchar *
-gedit_metadata_manager_get (const gchar *uri,
+gedit_metadata_manager_get (GFile *location,
const gchar *key)
{
Item *item;
gchar *value;
+ gchar *uri;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
g_return_val_if_fail (key != NULL, NULL);
+ uri = g_file_get_uri (location);
+
gedit_debug_message (DEBUG_METADATA, "URI: %s --- key: %s", uri, key );
gedit_metadata_manager_init ();
@@ -327,6 +330,8 @@ gedit_metadata_manager_get (const gchar *uri,
item = (Item *)g_hash_table_lookup (gedit_metadata_manager->items,
uri);
+ g_free (uri);
+
if (item == NULL)
return NULL;
@@ -344,15 +349,18 @@ gedit_metadata_manager_get (const gchar *uri,
}
void
-gedit_metadata_manager_set (const gchar *uri,
+gedit_metadata_manager_set (GFile *location,
const gchar *key,
const gchar *value)
{
Item *item;
+ gchar *uri;
- g_return_if_fail (uri != NULL);
+ g_return_if_fail (G_IS_FILE (location));
g_return_if_fail (key != NULL);
+ uri = g_file_get_uri (location);
+
gedit_debug_message (DEBUG_METADATA, "URI: %s --- key: %s --- value: %s", uri, key, value);
gedit_metadata_manager_init ();
@@ -394,6 +402,8 @@ gedit_metadata_manager_set (const gchar *uri,
item->atime = time (NULL);
+ g_free (uri);
+
gedit_metadata_manager_arm_timeout ();
}
diff --git a/gedit/gedit-metadata-manager.h b/gedit/gedit-metadata-manager.h
index 6ee324f..4589d04 100644
--- a/gedit/gedit-metadata-manager.h
+++ b/gedit/gedit-metadata-manager.h
@@ -39,9 +39,9 @@ G_BEGIN_DECLS
void gedit_metadata_manager_shutdown (void);
-gchar *gedit_metadata_manager_get (const gchar *uri,
+gchar *gedit_metadata_manager_get (GFile *location,
const gchar *key);
-void gedit_metadata_manager_set (const gchar *uri,
+void gedit_metadata_manager_set (GFile *location,
const gchar *key,
const gchar *value);
diff --git a/gedit/gedit-session.c b/gedit/gedit-session.c
index 7468664..1bf4d77 100644
--- a/gedit/gedit-session.c
+++ b/gedit/gedit-session.c
@@ -75,7 +75,7 @@ save_window_session (GKeyFile *state_file,
GList *docs, *l;
GPtrArray *doc_array;
GeditDocument *active_document;
- gchar *uri;
+ gchar *uri = NULL;
gedit_debug (DEBUG_SESSION);
@@ -96,9 +96,18 @@ save_window_session (GKeyFile *state_file,
active_document = gedit_window_get_active_document (window);
if (active_document)
{
- uri = gedit_document_get_uri (active_document);
- g_key_file_set_string (state_file, group_name,
+ GFile *location;
+
+ location = gedit_document_get_location (active_document);
+ if (location)
+ {
+ uri = g_file_get_uri (location);
+ g_object_unref (location);
+ }
+
+ g_key_file_set_string (state_file, group_name,
"active-document", uri);
+ g_free (uri);
}
docs = gedit_window_get_documents (window);
@@ -106,24 +115,28 @@ save_window_session (GKeyFile *state_file,
doc_array = g_ptr_array_new ();
for (l = docs; l != NULL; l = g_list_next (l))
{
- uri = gedit_document_get_uri (GEDIT_DOCUMENT (l->data));
+ GFile *location;
+
+ location = gedit_document_get_location (GEDIT_DOCUMENT (l->data));
+ if (location)
+ {
+ uri = g_file_get_uri (location);
+ g_object_unref (location);
+ }
if (uri != NULL)
- g_ptr_array_add (doc_array, uri);
-
+ g_ptr_array_add (doc_array, uri);
}
- g_list_free (docs);
+ g_list_free (docs);
if (doc_array->len)
{
- guint i;
-
g_key_file_set_string_list (state_file, group_name,
"documents",
(const char **)doc_array->pdata,
doc_array->len);
- for (i = 0; i < doc_array->len; i++)
- g_free (doc_array->pdata[i]);
+
+ g_ptr_array_foreach (doc_array, (GFunc) g_free, NULL);
}
g_ptr_array_free (doc_array, TRUE);
}
@@ -537,29 +550,35 @@ parse_window (GKeyFile *state_file, const char *group_name)
"documents", NULL, NULL);
if (documents)
{
- int i;
+ gint i;
gboolean jump_to = FALSE;
-
+
for (i = 0; documents[i]; i++)
{
- if (active_document != NULL)
- jump_to = strcmp (active_document,
+ GFile *location;
+
+ if (active_document != NULL)
+ jump_to = strcmp (active_document,
documents[i]) == 0;
-
+
gedit_debug_message (DEBUG_SESSION,
"URI: %s (%s)",
documents[i],
jump_to ? "active" : "not active");
- gedit_window_create_tab_from_uri (window,
- documents[i],
- NULL,
- 0,
- FALSE,
- jump_to);
+
+ location = g_file_new_for_uri (documents[i]);
+ gedit_window_create_tab_from_location (window,
+ location,
+ NULL,
+ 0,
+ FALSE,
+ jump_to);
+ if (location)
+ g_object_unref (location);
}
g_strfreev (documents);
}
-
+
g_free (active_document);
gtk_widget_show (GTK_WIDGET (window));
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 633f6b1..cd2913a 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -66,7 +66,7 @@ struct _GeditTabPrivate
GeditPrintJob *print_job;
/* tmp data for saving */
- gchar *tmp_save_uri;
+ GFile *tmp_save_location;
/* tmp data for loading */
gint tmp_line_pos;
@@ -225,6 +225,20 @@ gedit_tab_set_property (GObject *object,
}
static void
+gedit_tab_dispose (GObject *object)
+{
+ GeditTab *tab = GEDIT_TAB (object);
+
+ if (tab->priv->tmp_save_location != NULL)
+ {
+ g_object_unref (tab->priv->tmp_save_location);
+ tab->priv->tmp_save_location = NULL;
+ }
+
+ G_OBJECT_CLASS (gedit_tab_parent_class)->dispose (object);
+}
+
+static void
gedit_tab_finalize (GObject *object)
{
GeditTab *tab = GEDIT_TAB (object);
@@ -232,8 +246,6 @@ gedit_tab_finalize (GObject *object)
if (tab->priv->timer != NULL)
g_timer_destroy (tab->priv->timer);
- g_free (tab->priv->tmp_save_uri);
-
if (tab->priv->auto_save_timeout > 0)
remove_auto_save_timeout (tab);
@@ -245,6 +257,7 @@ gedit_tab_class_init (GeditTabClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = gedit_tab_dispose;
object_class->finalize = gedit_tab_finalize;
object_class->get_property = gedit_tab_get_property;
object_class->set_property = gedit_tab_set_property;
@@ -411,13 +424,13 @@ gedit_tab_set_state (GeditTab *tab,
}
static void
-document_uri_notify_handler (GeditDocument *document,
- GParamSpec *pspec,
- GeditTab *tab)
+document_location_notify_handler (GeditDocument *document,
+ GParamSpec *pspec,
+ GeditTab *tab)
{
gedit_debug (DEBUG_TAB);
- /* Notify the change in the URI */
+ /* Notify the change in the location */
g_object_notify (G_OBJECT (tab), "name");
}
@@ -475,13 +488,13 @@ remove_tab (GeditTab *tab)
}
static void
-io_loading_error_message_area_response (GtkWidget *message_area,
- gint response_id,
- GeditTab *tab)
+io_loading_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditTab *tab)
{
GeditDocument *doc;
GeditView *view;
- gchar *uri;
+ GFile *location;
const GeditEncoding *encoding;
doc = gedit_tab_get_document (tab);
@@ -490,8 +503,8 @@ io_loading_error_message_area_response (GtkWidget *message_area,
view = gedit_tab_get_view (tab);
g_return_if_fail (GEDIT_IS_VIEW (view));
- uri = gedit_document_get_uri (doc);
- g_return_if_fail (uri != NULL);
+ location = gedit_document_get_location (doc);
+ g_return_if_fail (location != NULL);
switch (response_id)
{
@@ -510,7 +523,7 @@ io_loading_error_message_area_response (GtkWidget *message_area,
g_return_if_fail (tab->priv->auto_save_timeout <= 0);
gedit_document_load (doc,
- uri,
+ location,
tab->priv->tmp_encoding,
tab->priv->tmp_line_pos,
FALSE);
@@ -525,13 +538,13 @@ io_loading_error_message_area_response (GtkWidget *message_area,
set_message_area (tab, NULL);
break;
default:
- _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri);
+ _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), location);
remove_tab (tab);
break;
}
- g_free (uri);
+ g_object_unref (location);
}
static void
@@ -553,7 +566,7 @@ file_already_open_warning_message_area_response (GtkWidget *message_area,
gtk_widget_destroy (message_area);
- gtk_widget_grab_focus (GTK_WIDGET (view));
+ gtk_widget_grab_focus (GTK_WIDGET (view));
}
static void
@@ -625,15 +638,15 @@ show_loading_message_area (GeditTab *tab)
}
else
{
- GFile *file;
+ GFile *location;
- file = gedit_document_get_location (doc);
- if (file != NULL)
+ location = gedit_document_get_location (doc);
+ if (location != NULL)
{
gchar *str;
- str = gedit_utils_location_get_dirname_for_display (file);
- g_object_unref (file);
+ str = gedit_utils_location_get_dirname_for_display (location);
+ g_object_unref (location);
/* use the remaining space for the dir, but use a min of 20 chars
* so that we do not end up with a dirname like "(a...b)".
@@ -724,7 +737,7 @@ show_saving_message_area (GeditTab *tab)
gchar *msg = NULL;
gint len;
- g_return_if_fail (tab->priv->tmp_save_uri != NULL);
+ g_return_if_fail (tab->priv->tmp_save_location != NULL);
if (tab->priv->message_area != NULL)
return;
@@ -753,7 +766,7 @@ show_saving_message_area (GeditTab *tab)
from = short_name;
- to = gedit_utils_uri_for_display (tab->priv->tmp_save_uri);
+ to = gedit_utils_uri_for_display (tab->priv->tmp_save_location);
str = gedit_utils_str_middle_truncate (to,
MAX (20, MAX_MSG_LENGTH - len));
@@ -876,7 +889,6 @@ document_loaded (GeditDocument *document,
{
GtkWidget *emsg;
GFile *location;
- gchar *uri;
const GeditEncoding *encoding;
g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_LOADING) ||
@@ -893,7 +905,6 @@ document_loaded (GeditDocument *document,
set_message_area (tab, NULL);
location = gedit_document_get_location (document);
- uri = gedit_document_get_uri (document);
/* if the error is CONVERSION FALLBACK don't treat it as a normal error */
if (error != NULL &&
@@ -919,11 +930,11 @@ document_loaded (GeditDocument *document,
}
else
{
- _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri);
+ _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), location);
if (tab->priv->state == GEDIT_TAB_STATE_LOADING_ERROR)
{
- emsg = gedit_io_loading_error_message_area_new (uri,
+ emsg = gedit_io_loading_error_message_area_new (location,
tab->priv->tmp_encoding,
error);
g_signal_connect (emsg,
@@ -935,7 +946,7 @@ document_loaded (GeditDocument *document,
{
g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_REVERTING_ERROR);
- emsg = gedit_unrecoverable_reverting_error_message_area_new (uri,
+ emsg = gedit_unrecoverable_reverting_error_message_area_new (location,
error);
g_signal_connect (emsg,
@@ -958,7 +969,6 @@ document_loaded (GeditDocument *document,
gtk_widget_show (emsg);
g_object_unref (location);
- g_free (uri);
return;
}
@@ -968,11 +978,11 @@ document_loaded (GeditDocument *document,
GList *all_documents;
GList *l;
- g_return_if_fail (uri != NULL);
+ g_return_if_fail (location != NULL);
mime = gedit_document_get_mime_type (document);
_gedit_recent_add (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
- uri,
+ location,
mime);
g_free (mime);
@@ -984,7 +994,7 @@ document_loaded (GeditDocument *document,
_gedit_document_set_readonly (document, TRUE);
- emsg = gedit_io_loading_error_message_area_new (uri,
+ emsg = gedit_io_loading_error_message_area_new (location,
tab->priv->tmp_encoding,
error);
@@ -1031,7 +1041,7 @@ document_loaded (GeditDocument *document,
tab->priv->not_editable = TRUE;
- w = gedit_file_already_open_warning_message_area_new (uri);
+ w = gedit_file_already_open_warning_message_area_new (location);
set_message_area (tab, w);
@@ -1070,17 +1080,16 @@ document_loaded (GeditDocument *document,
end:
g_object_unref (location);
- g_free (uri);
tab->priv->tmp_line_pos = 0;
tab->priv->tmp_encoding = NULL;
}
static void
-document_saving (GeditDocument *document,
- goffset size,
- goffset total_size,
- GeditTab *tab)
+document_saving (GeditDocument *document,
+ goffset size,
+ goffset total_size,
+ GeditTab *tab)
{
gdouble et;
gdouble total_time;
@@ -1115,8 +1124,11 @@ static void
end_saving (GeditTab *tab)
{
/* Reset tmp data for saving */
- g_free (tab->priv->tmp_save_uri);
- tab->priv->tmp_save_uri = NULL;
+ if (tab->priv->tmp_save_location)
+ {
+ g_object_unref (tab->priv->tmp_save_location);
+ tab->priv->tmp_save_location = NULL;
+ }
tab->priv->tmp_encoding = NULL;
install_auto_save_timeout_if_needed (tab);
@@ -1140,13 +1152,13 @@ unrecoverable_saving_error_message_area_response (GtkWidget *message_area
view = gedit_tab_get_view (tab);
- gtk_widget_grab_focus (GTK_WIDGET (view));
+ gtk_widget_grab_focus (GTK_WIDGET (view));
}
static void
-no_backup_error_message_area_response (GtkWidget *message_area,
- gint response_id,
- GeditTab *tab)
+no_backup_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditTab *tab)
{
if (response_id == GTK_RESPONSE_YES)
{
@@ -1157,7 +1169,7 @@ no_backup_error_message_area_response (GtkWidget *message_area,
set_message_area (tab, NULL);
- g_return_if_fail (tab->priv->tmp_save_uri != NULL);
+ g_return_if_fail (tab->priv->tmp_save_location != NULL);
g_return_if_fail (tab->priv->tmp_encoding != NULL);
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SAVING);
@@ -1179,9 +1191,9 @@ no_backup_error_message_area_response (GtkWidget *message_area,
}
static void
-externally_modified_error_message_area_response (GtkWidget *message_area,
- gint response_id,
- GeditTab *tab)
+externally_modified_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditTab *tab)
{
if (response_id == GTK_RESPONSE_YES)
{
@@ -1192,7 +1204,7 @@ externally_modified_error_message_area_response (GtkWidget *message_area,
set_message_area (tab, NULL);
- g_return_if_fail (tab->priv->tmp_save_uri != NULL);
+ g_return_if_fail (tab->priv->tmp_save_location != NULL);
g_return_if_fail (tab->priv->tmp_encoding != NULL);
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SAVING);
@@ -1213,9 +1225,9 @@ externally_modified_error_message_area_response (GtkWidget *message_area,
}
static void
-recoverable_saving_error_message_area_response (GtkWidget *message_area,
- gint response_id,
- GeditTab *tab)
+recoverable_saving_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditTab *tab)
{
GeditDocument *doc;
@@ -1225,6 +1237,7 @@ recoverable_saving_error_message_area_response (GtkWidget *message_area,
if (response_id == GTK_RESPONSE_OK)
{
const GeditEncoding *encoding;
+ gchar *tmp_uri;
encoding = gedit_conversion_error_message_area_get_encoding (
GTK_WIDGET (message_area));
@@ -1233,18 +1246,20 @@ recoverable_saving_error_message_area_response (GtkWidget *message_area,
set_message_area (tab, NULL);
- g_return_if_fail (tab->priv->tmp_save_uri != NULL);
+ g_return_if_fail (tab->priv->tmp_save_location != NULL);
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SAVING);
tab->priv->tmp_encoding = encoding;
- gedit_debug_message (DEBUG_TAB, "Force saving with URI '%s'", tab->priv->tmp_save_uri);
+ tmp_uri = g_file_get_uri (tab->priv->tmp_save_location);
+ gedit_debug_message (DEBUG_TAB, "Force saving with URI '%s'", tmp_uri);
+ g_free (tmp_uri);
g_return_if_fail (tab->priv->auto_save_timeout <= 0);
gedit_document_save_as (doc,
- tab->priv->tmp_save_uri,
+ tab->priv->tmp_save_location,
tab->priv->tmp_encoding,
tab->priv->save_flags);
}
@@ -1265,8 +1280,8 @@ document_saved (GeditDocument *document,
g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_SAVING);
- g_return_if_fail (tab->priv->tmp_save_uri != NULL);
- g_return_if_fail (tab->priv->tmp_encoding != NULL);
+ g_return_if_fail (tab->priv->tmp_save_location != NULL);
+ g_return_if_fail (tab->priv->tmp_encoding != NULL);
g_return_if_fail (tab->priv->auto_save_timeout <= 0);
g_timer_destroy (tab->priv->timer);
@@ -1284,7 +1299,7 @@ document_saved (GeditDocument *document,
{
/* This error is recoverable */
emsg = gedit_externally_modified_saving_error_message_area_new (
- tab->priv->tmp_save_uri,
+ tab->priv->tmp_save_location,
error);
g_return_if_fail (emsg != NULL);
@@ -1302,7 +1317,7 @@ document_saved (GeditDocument *document,
{
/* This error is recoverable */
emsg = gedit_no_backup_saving_error_message_area_new (
- tab->priv->tmp_save_uri,
+ tab->priv->tmp_save_location,
error);
g_return_if_fail (emsg != NULL);
@@ -1320,9 +1335,9 @@ document_saved (GeditDocument *document,
{
/* These errors are _NOT_ recoverable */
_gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
- tab->priv->tmp_save_uri);
+ tab->priv->tmp_save_location);
- emsg = gedit_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_uri,
+ emsg = gedit_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_location,
error);
g_return_if_fail (emsg != NULL);
@@ -1340,7 +1355,7 @@ document_saved (GeditDocument *document,
error->domain == G_IO_ERROR);
emsg = gedit_conversion_error_while_saving_message_area_new (
- tab->priv->tmp_save_uri,
+ tab->priv->tmp_save_location,
tab->priv->tmp_encoding,
error);
@@ -1367,7 +1382,7 @@ document_saved (GeditDocument *document,
gchar *mime = gedit_document_get_mime_type (document);
_gedit_recent_add (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
- tab->priv->tmp_save_uri,
+ tab->priv->tmp_save_location,
mime);
g_free (mime);
@@ -1383,9 +1398,9 @@ document_saved (GeditDocument *document,
}
static void
-externally_modified_notification_message_area_response (GtkWidget *message_area,
- gint response_id,
- GeditTab *tab)
+externally_modified_notification_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditTab *tab)
{
GeditView *view;
@@ -1412,20 +1427,19 @@ display_externally_modified_notification (GeditTab *tab)
{
GtkWidget *message_area;
GeditDocument *doc;
- gchar *uri;
+ GFile *location;
gboolean document_modified;
doc = gedit_tab_get_document (tab);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- /* uri cannot be NULL, we're here because
- * the file we're editing changed on disk */
- uri = gedit_document_get_uri (doc);
- g_return_if_fail (uri != NULL);
+ /* we're here because the file we're editing changed on disk */
+ location = gedit_document_get_location (doc);
+ g_return_if_fail (location != NULL);
document_modified = gtk_text_buffer_get_modified (GTK_TEXT_BUFFER(doc));
- message_area = gedit_externally_modified_message_area_new (uri, document_modified);
- g_free (uri);
+ message_area = gedit_externally_modified_message_area_new (location, document_modified);
+ g_object_unref (location);
tab->priv->message_area = NULL;
set_message_area (tab, message_area);
@@ -1544,8 +1558,8 @@ gedit_tab_init (GeditTab *tab)
gtk_widget_show (sw);
g_signal_connect (doc,
- "notify::uri",
- G_CALLBACK (document_uri_notify_handler),
+ "notify::location",
+ G_CALLBACK (document_location_notify_handler),
tab);
g_signal_connect (doc,
"notify::shortname",
@@ -1590,27 +1604,27 @@ _gedit_tab_new (void)
}
/* Whether create is TRUE, creates a new empty document if location does
- not refer to an existing file */
+ not refer to an existing location */
GtkWidget *
-_gedit_tab_new_from_uri (const gchar *uri,
- const GeditEncoding *encoding,
- gint line_pos,
- gboolean create)
+_gedit_tab_new_from_location (GFile *location,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create)
{
GeditTab *tab;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
tab = GEDIT_TAB (_gedit_tab_new ());
_gedit_tab_load (tab,
- uri,
+ location,
encoding,
line_pos,
create);
return GTK_WIDGET (tab);
-}
+}
/**
* gedit_tab_get_view:
@@ -1835,7 +1849,7 @@ get_icon (GtkIconTheme *theme,
return get_stock_icon (theme, GTK_STOCK_FILE, size);
/* FIXME: Doing a sync stat is bad, this should be fixed */
- info = g_file_query_info (location,
+ info = g_file_query_info (location,
G_FILE_ATTRIBUTE_STANDARD_ICON,
G_FILE_QUERY_INFO_NONE,
NULL,
@@ -1976,7 +1990,7 @@ gedit_tab_get_from_document (GeditDocument *doc)
void
_gedit_tab_load (GeditTab *tab,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create)
@@ -1984,6 +1998,7 @@ _gedit_tab_load (GeditTab *tab,
GeditDocument *doc;
g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (G_IS_FILE (location));
g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_NORMAL);
doc = gedit_tab_get_document (tab);
@@ -1998,7 +2013,7 @@ _gedit_tab_load (GeditTab *tab,
remove_auto_save_timeout (tab);
gedit_document_load (doc,
- uri,
+ location,
encoding,
line_pos,
create);
@@ -2008,7 +2023,7 @@ void
_gedit_tab_revert (GeditTab *tab)
{
GeditDocument *doc;
- gchar *uri;
+ GFile *location;
g_return_if_fail (GEDIT_IS_TAB (tab));
g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_NORMAL) ||
@@ -2024,8 +2039,8 @@ _gedit_tab_revert (GeditTab *tab)
gedit_tab_set_state (tab, GEDIT_TAB_STATE_REVERTING);
- uri = gedit_document_get_uri (doc);
- g_return_if_fail (uri != NULL);
+ location = gedit_document_get_location (doc);
+ g_return_if_fail (location != NULL);
tab->priv->tmp_line_pos = 0;
tab->priv->tmp_encoding = gedit_document_get_encoding (doc);
@@ -2034,12 +2049,12 @@ _gedit_tab_revert (GeditTab *tab)
remove_auto_save_timeout (tab);
gedit_document_load (doc,
- uri,
+ location,
tab->priv->tmp_encoding,
0,
FALSE);
- g_free (uri);
+ g_object_unref (location);
}
void
@@ -2052,7 +2067,7 @@ _gedit_tab_save (GeditTab *tab)
g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_NORMAL) ||
(tab->priv->state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
(tab->priv->state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW));
- g_return_if_fail (tab->priv->tmp_save_uri == NULL);
+ g_return_if_fail (tab->priv->tmp_save_location == NULL);
g_return_if_fail (tab->priv->tmp_encoding == NULL);
doc = gedit_tab_get_document (tab);
@@ -2077,7 +2092,7 @@ _gedit_tab_save (GeditTab *tab)
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SAVING);
/* uri used in error messages, will be freed in document_saved */
- tab->priv->tmp_save_uri = gedit_document_get_uri (doc);
+ tab->priv->tmp_save_location = gedit_document_get_location (doc);
tab->priv->tmp_encoding = gedit_document_get_encoding (doc);
if (tab->priv->auto_save_timeout > 0)
@@ -2093,7 +2108,7 @@ gedit_tab_auto_save (GeditTab *tab)
gedit_debug (DEBUG_TAB);
- g_return_val_if_fail (tab->priv->tmp_save_uri == NULL, FALSE);
+ g_return_val_if_fail (tab->priv->tmp_save_location == NULL, FALSE);
g_return_val_if_fail (tab->priv->tmp_encoding == NULL, FALSE);
doc = gedit_tab_get_document (tab);
@@ -2134,7 +2149,7 @@ gedit_tab_auto_save (GeditTab *tab)
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SAVING);
/* uri used in error messages, will be freed in document_saved */
- tab->priv->tmp_save_uri = gedit_document_get_uri (doc);
+ tab->priv->tmp_save_location = gedit_document_get_location (doc);
tab->priv->tmp_encoding = gedit_document_get_encoding (doc);
/* Set auto_save_timeout to 0 since the timeout is going to be destroyed */
@@ -2154,7 +2169,7 @@ gedit_tab_auto_save (GeditTab *tab)
void
_gedit_tab_save_as (GeditTab *tab,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentNewlineType newline_type)
{
@@ -2165,9 +2180,10 @@ _gedit_tab_save_as (GeditTab *tab,
g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_NORMAL) ||
(tab->priv->state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
(tab->priv->state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW));
+ g_return_if_fail (G_IS_FILE (location));
g_return_if_fail (encoding != NULL);
- g_return_if_fail (tab->priv->tmp_save_uri == NULL);
+ g_return_if_fail (tab->priv->tmp_save_location == NULL);
g_return_if_fail (tab->priv->tmp_encoding == NULL);
doc = gedit_tab_get_document (tab);
@@ -2195,7 +2211,7 @@ _gedit_tab_save_as (GeditTab *tab,
/* uri used in error messages... strdup because errors are async
* and the string can go away, will be freed in document_saved */
- tab->priv->tmp_save_uri = g_strdup (uri);
+ tab->priv->tmp_save_location = g_file_dup (location);
tab->priv->tmp_encoding = encoding;
if (tab->priv->auto_save_timeout > 0)
@@ -2206,7 +2222,7 @@ _gedit_tab_save_as (GeditTab *tab,
a very big deal, but would be nice to have them follow the
same pattern. This can be changed once we break API for 3.0 */
gedit_document_set_newline_type (doc, newline_type);
- gedit_document_save_as (doc, uri, encoding, tab->priv->save_flags);
+ gedit_document_save_as (doc, location, encoding, tab->priv->save_flags);
}
#define GEDIT_PAGE_SETUP_KEY "gedit-page-setup-key"
diff --git a/gedit/gedit-tab.h b/gedit/gedit-tab.h
index 6826208..b3985b9 100644
--- a/gedit/gedit-tab.h
+++ b/gedit/gedit-tab.h
@@ -129,8 +129,8 @@ void gedit_tab_set_info_bar (GeditTab *tab,
GtkWidget *_gedit_tab_new (void);
/* Whether create is TRUE, creates a new empty document if location does
- not refer to an existing file */
-GtkWidget *_gedit_tab_new_from_uri (const gchar *uri,
+ not refer to an existing location */
+GtkWidget *_gedit_tab_new_from_location (GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create);
@@ -138,14 +138,14 @@ gchar *_gedit_tab_get_name (GeditTab *tab);
gchar *_gedit_tab_get_tooltips (GeditTab *tab);
GdkPixbuf *_gedit_tab_get_icon (GeditTab *tab);
void _gedit_tab_load (GeditTab *tab,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create);
void _gedit_tab_revert (GeditTab *tab);
void _gedit_tab_save (GeditTab *tab);
void _gedit_tab_save_as (GeditTab *tab,
- const gchar *uri,
+ GFile *location,
const GeditEncoding *encoding,
GeditDocumentNewlineType newline_type);
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 41a5afd..14f924e 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -61,49 +61,11 @@
#define STDIN_DELAY_MICROSECONDS 100000
-/* Returns true if uri is a file: uri and is not a chained uri */
+/* Returns true if location is a file: uri and is not a chained uri */
gboolean
-gedit_utils_uri_has_file_scheme (const gchar *uri)
+gedit_utils_location_has_file_scheme (GFile *location)
{
- GFile *gfile;
- gboolean res;
-
- gfile = g_file_new_for_uri (uri);
- res = g_file_has_uri_scheme (gfile, "file");
-
- g_object_unref (gfile);
- return res;
-}
-
-/* FIXME: we should check for chained URIs */
-gboolean
-gedit_utils_uri_has_writable_scheme (const gchar *uri)
-{
- GFile *gfile;
- gchar *scheme;
- GSList *writable_schemes;
- gboolean res;
-
- gfile = g_file_new_for_uri (uri);
- scheme = g_file_get_uri_scheme (gfile);
-
- g_return_val_if_fail (scheme != NULL, FALSE);
-
- g_object_unref (gfile);
-
- writable_schemes = gedit_prefs_manager_get_writable_vfs_schemes ();
-
- /* CHECK: should we use g_ascii_strcasecmp? - Paolo (Nov 6, 2005) */
- res = (g_slist_find_custom (writable_schemes,
- scheme,
- (GCompareFunc)strcmp) != NULL);
-
- g_slist_foreach (writable_schemes, (GFunc)g_free, NULL);
- g_slist_free (writable_schemes);
-
- g_free (scheme);
-
- return res;
+ return g_file_has_uri_scheme (location, "file");
}
static void
@@ -344,19 +306,18 @@ gedit_utils_set_atk_relation (GtkWidget *obj1,
}
gboolean
-gedit_utils_uri_exists (const gchar* text_uri)
+gedit_utils_location_exists (GFile *location)
{
- GFile *gfile;
gboolean res;
+ gchar *uri;
- g_return_val_if_fail (text_uri != NULL, FALSE);
-
- gedit_debug_message (DEBUG_UTILS, "text_uri: %s", text_uri);
+ g_return_val_if_fail (G_IS_FILE (location), FALSE);
- gfile = g_file_new_for_uri (text_uri);
- res = g_file_query_exists (gfile, NULL);
+ uri = g_file_get_uri (location);
+ gedit_debug_message (DEBUG_UTILS, "text_uri: %s", uri);
+ g_free (uri);
- g_object_unref (gfile);
+ res = g_file_query_exists (location, NULL);
gedit_debug_message (DEBUG_UTILS, res ? "TRUE" : "FALSE");
@@ -1019,15 +980,24 @@ has_valid_scheme (const gchar *uri)
}
gboolean
-gedit_utils_is_valid_uri (const gchar *uri)
+gedit_utils_is_valid_location (GFile *location)
{
const guchar *p;
+ gchar *uri;
+ gboolean is_valid;
- if (uri == NULL)
+ if (location == NULL)
return FALSE;
+ uri = g_file_get_uri (location);
+
if (!has_valid_scheme (uri))
+ {
+ g_free (uri);
return FALSE;
+ }
+
+ is_valid = TRUE;
/* We expect to have a fully valid set of characters */
for (p = (const guchar *)uri; *p; p++) {
@@ -1035,20 +1005,31 @@ gedit_utils_is_valid_uri (const gchar *uri)
{
++p;
if (!g_ascii_isxdigit (*p))
- return FALSE;
+ {
+ is_valid = FALSE;
+ break;
+ }
++p;
if (!g_ascii_isxdigit (*p))
- return FALSE;
+ {
+ is_valid = FALSE;
+ break;
+ }
}
else
{
if (*p <= 32 || *p >= 128)
- return FALSE;
+ {
+ is_valid = FALSE;
+ break;
+ }
}
}
- return TRUE;
+ g_free (uri);
+
+ return is_valid;
}
static GtkWidget *
@@ -1214,13 +1195,15 @@ gedit_utils_make_canonical_uri_from_shell_arg (const gchar *str)
*/
gfile = g_file_new_for_commandline_arg (str);
- uri = g_file_get_uri (gfile);
- g_object_unref (gfile);
- if (gedit_utils_is_valid_uri (uri))
+ if (gedit_utils_is_valid_location (gfile))
+ {
+ uri = g_file_get_uri (gfile);
+ g_object_unref (gfile);
return uri;
+ }
- g_free (uri);
+ g_object_unref (gfile);
return NULL;
}
@@ -1248,26 +1231,26 @@ gedit_utils_file_has_parent (GFile *gfile)
/**
* gedit_utils_basename_for_display:
- * @uri: uri for which the basename should be displayed
+ * @location: location for which the basename should be displayed
*
* Return the basename of a file suitable for display to users.
*/
gchar *
-gedit_utils_basename_for_display (gchar const *uri)
+gedit_utils_basename_for_display (GFile *location)
{
gchar *name;
- GFile *gfile;
gchar *hn;
+ gchar *uri;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
- gfile = g_file_new_for_uri (uri);
+ uri = g_file_get_uri (location);
/* First, try to query the display name, but only on local files */
- if (g_file_has_uri_scheme (gfile, "file"))
+ if (gedit_utils_location_has_file_scheme (location))
{
GFileInfo *info;
- info = g_file_query_info (gfile,
+ info = g_file_query_info (location,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
G_FILE_QUERY_INFO_NONE,
NULL,
@@ -1285,12 +1268,12 @@ gedit_utils_basename_for_display (gchar const *uri)
* g_filename_display_basename on the local path */
gchar *local_path;
- local_path = g_file_get_path (gfile);
+ local_path = g_file_get_path (location);
name = g_filename_display_basename (local_path);
g_free (local_path);
}
}
- else if (gedit_utils_file_has_parent (gfile) || !gedit_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL))
+ else if (gedit_utils_file_has_parent (location) || !gedit_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL))
{
/* For remote files with a parent (so not just http://foo.com)
or remote file for which the decoding of the host name fails,
@@ -1298,7 +1281,7 @@ gedit_utils_basename_for_display (gchar const *uri)
gchar *parse_name;
gchar *base;
- parse_name = g_file_get_parse_name (gfile);
+ parse_name = g_file_get_parse_name (location);
base = g_filename_display_basename (parse_name);
name = g_uri_unescape_string (base, NULL);
@@ -1323,14 +1306,14 @@ gedit_utils_basename_for_display (gchar const *uri)
g_free (hn);
}
- g_object_unref (gfile);
+ g_free (uri);
return name;
}
/**
* gedit_utils_uri_for_display:
- * @uri: uri to be displayed.
+ * @location: location to be displayed.
*
* Filter, modify, unescape and change @uri to make it appropriate
* for display to users.
@@ -1340,16 +1323,9 @@ gedit_utils_basename_for_display (gchar const *uri)
* Return value: a string which represents @uri and can be displayed.
*/
gchar *
-gedit_utils_uri_for_display (const gchar *uri)
+gedit_utils_uri_for_display (GFile *location)
{
- GFile *gfile;
- gchar *parse_name;
-
- gfile = g_file_new_for_uri (uri);
- parse_name = g_file_get_parse_name (gfile);
- g_object_unref (gfile);
-
- return parse_name;
+ return g_file_get_parse_name (location);
}
/**
diff --git a/gedit/gedit-utils.h b/gedit/gedit-utils.h
index ddf1d9c..df29bed 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -48,8 +48,7 @@ G_BEGIN_DECLS
enum { GEDIT_ALL_WORKSPACES = 0xffffffff };
-gboolean gedit_utils_uri_has_writable_scheme (const gchar *uri);
-gboolean gedit_utils_uri_has_file_scheme (const gchar *uri);
+gboolean gedit_utils_location_has_file_scheme (GFile *location);
void gedit_utils_menu_position_under_widget (GtkMenu *menu,
gint *x,
@@ -96,7 +95,7 @@ void gedit_utils_set_atk_relation (GtkWidget *obj1,
GtkWidget *obj2,
AtkRelationType rel_type);
-gboolean gedit_utils_uri_exists (const gchar* text_uri);
+gboolean gedit_utils_location_exists (GFile *location);
gchar *gedit_utils_escape_search_text (const gchar *text);
@@ -128,7 +127,7 @@ void gedit_utils_activate_url (GtkAboutDialog *about,
const gchar *url,
gpointer data);
-gboolean gedit_utils_is_valid_uri (const gchar *uri);
+gboolean gedit_utils_is_valid_location (GFile *location);
gboolean gedit_utils_get_ui_objects (const gchar *filename,
gchar **root_objects,
@@ -142,8 +141,8 @@ gboolean gedit_utils_file_has_parent (GFile *gfile);
gchar *gedit_utils_make_canonical_uri_from_shell_arg
(const gchar *str);
-gchar *gedit_utils_uri_for_display (const gchar *uri);
-gchar *gedit_utils_basename_for_display (const gchar *uri);
+gchar *gedit_utils_uri_for_display (GFile *location);
+gchar *gedit_utils_basename_for_display (GFile *location);
gboolean gedit_utils_decode_uri (const gchar *uri,
gchar **scheme,
gchar **user,
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index c4bf240..644927e 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -1146,11 +1146,12 @@ update_languages_menu (GeditWindow *window)
void
_gedit_recent_add (GeditWindow *window,
- const gchar *uri,
+ GFile *location,
const gchar *mime)
{
GtkRecentManager *recent_manager;
GtkRecentData *recent_data;
+ gchar *uri;
static gchar *groups[2] = {
"gedit",
@@ -1169,10 +1170,12 @@ _gedit_recent_add (GeditWindow *window,
recent_data->groups = groups;
recent_data->is_private = FALSE;
+ uri = g_file_get_uri (location);
gtk_recent_manager_add_full (recent_manager,
uri,
recent_data);
+ g_free (uri);
g_free (recent_data->app_exec);
g_slice_free (GtkRecentData, recent_data);
@@ -1180,40 +1183,50 @@ _gedit_recent_add (GeditWindow *window,
void
_gedit_recent_remove (GeditWindow *window,
- const gchar *uri)
+ GFile *location)
{
GtkRecentManager *recent_manager;
+ gchar *uri;
recent_manager = gtk_recent_manager_get_default ();
+ uri = g_file_get_uri (location);
gtk_recent_manager_remove_item (recent_manager, uri, NULL);
+ g_free (uri);
}
static void
-open_recent_file (const gchar *uri,
+open_recent_file (GFile *location,
GeditWindow *window)
{
- GSList *uris = NULL;
+ GSList *locations = NULL;
- uris = g_slist_prepend (uris, (gpointer) uri);
+ locations = g_slist_prepend (locations, (gpointer) location);
- if (gedit_commands_load_uris (window, uris, NULL, 0) != 1)
+ if (gedit_commands_load_locations (window, locations, NULL, 0) != 1)
{
- _gedit_recent_remove (window, uri);
+ _gedit_recent_remove (window, location);
}
- g_slist_free (uris);
+ g_slist_free (locations);
}
static void
recent_chooser_item_activated (GtkRecentChooser *chooser,
GeditWindow *window)
{
+ GFile *location;
gchar *uri;
+ /* TODO: get_current_file when exists */
uri = gtk_recent_chooser_get_current_uri (chooser);
+ location = g_file_new_for_uri (uri);
- open_recent_file (uri, window);
+ if (location)
+ {
+ open_recent_file (location, window);
+ g_object_unref (location);
+ }
g_free (uri);
}
@@ -1224,13 +1237,20 @@ recents_menu_activate (GtkAction *action,
{
GtkRecentInfo *info;
const gchar *uri;
+ GFile *location;
info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
g_return_if_fail (info != NULL);
+ /* TODO: get_file when exists */
uri = gtk_recent_info_get_uri (info);
+ location = g_file_new_for_uri (uri);
- open_recent_file (uri, window);
+ if (location)
+ {
+ open_recent_file (location, window);
+ g_object_unref (location);
+ }
}
static gint
@@ -1316,6 +1336,7 @@ update_recent_files_menu (GeditWindow *window)
gchar *tip;
GtkAction *action;
GtkRecentInfo *info = l->data;
+ GFile *location;
/* clamp */
if (i >= max_recents)
@@ -1339,7 +1360,9 @@ update_recent_files_menu (GeditWindow *window)
/* gtk_recent_info_get_uri_display (info) is buggy and
* works only for local files */
- uri = gedit_utils_uri_for_display (gtk_recent_info_get_uri (info));
+ location = g_file_new_for_uri (gtk_recent_info_get_uri (info));
+ uri = gedit_utils_uri_for_display (location);
+ g_object_unref (location);
ruri = gedit_utils_replace_home_dir_with_tilde (uri);
g_free (uri);
@@ -2815,7 +2838,7 @@ static void
load_uris_from_drop (GeditWindow *window,
gchar **uri_list)
{
- GSList *uris = NULL;
+ GSList *locations = NULL;
gint i;
if (uri_list == NULL)
@@ -2823,16 +2846,17 @@ load_uris_from_drop (GeditWindow *window,
for (i = 0; uri_list[i] != NULL; ++i)
{
- uris = g_slist_prepend (uris, uri_list[i]);
+ locations = g_slist_prepend (locations, g_file_new_for_uri (uri_list[i]));
}
- uris = g_slist_reverse (uris);
- gedit_commands_load_uris (window,
- uris,
- NULL,
- 0);
+ locations = g_slist_reverse (locations);
+ gedit_commands_load_locations (window,
+ locations,
+ NULL,
+ 0);
- g_slist_free (uris);
+ g_slist_foreach (locations, (GFunc) g_object_unref, NULL);
+ g_slist_free (locations);
}
/* Handle drops on the GeditWindow */
@@ -4159,9 +4183,9 @@ gedit_window_create_tab (GeditWindow *window,
}
/**
- * gedit_window_create_tab_from_uri:
+ * gedit_window_create_tab_from_location:
* @window: a #GeditWindow
- * @uri: the uri of the document
+ * @location: the location of the document
* @encoding: a #GeditEncoding
* @line_pos: the line position to visualize
* @create: %TRUE to create a new document in case @uri does exist
@@ -4175,22 +4199,22 @@ gedit_window_create_tab (GeditWindow *window,
* Returns: a new #GeditTab
*/
GeditTab *
-gedit_window_create_tab_from_uri (GeditWindow *window,
- const gchar *uri,
- const GeditEncoding *encoding,
- gint line_pos,
- gboolean create,
- gboolean jump_to)
+gedit_window_create_tab_from_location (GeditWindow *window,
+ GFile *location,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create,
+ gboolean jump_to)
{
GtkWidget *tab;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
- tab = _gedit_tab_new_from_uri (uri,
- encoding,
- line_pos,
- create);
+ tab = _gedit_tab_new_from_location (location,
+ encoding,
+ line_pos,
+ create);
if (tab == NULL)
return NULL;
diff --git a/gedit/gedit-window.h b/gedit/gedit-window.h
index e8c7eef..23d2cdd 100644
--- a/gedit/gedit-window.h
+++ b/gedit/gedit-window.h
@@ -105,8 +105,8 @@ GType gedit_window_get_type (void) G_GNUC_CONST;
GeditTab *gedit_window_create_tab (GeditWindow *window,
gboolean jump_to);
-GeditTab *gedit_window_create_tab_from_uri (GeditWindow *window,
- const gchar *uri,
+GeditTab *gedit_window_create_tab_from_location (GeditWindow *window,
+ GFile *location,
const GeditEncoding *encoding,
gint line_pos,
gboolean create,
@@ -185,10 +185,10 @@ gboolean _gedit_window_is_fullscreen (GeditWindow *window);
/* these are in gedit-window because of screen safety */
void _gedit_recent_add (GeditWindow *window,
- const gchar *uri,
+ GFile *location,
const gchar *mime);
void _gedit_recent_remove (GeditWindow *window,
- const gchar *uri);
+ GFile *location);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]