Revision: 3457 http://geany.svn.sourceforge.net/geany/?rev=3457&view=rev Author: eht16 Date: 2009-01-09 18:22:07 +0000 (Fri, 09 Jan 2009)
Log Message: ----------- Add utils_is_remote_path(). Add private field 'is_remote' to GeanyDocument to indicate whether an opened file is locally accessed or via gvfs-fuse.
Modified Paths: -------------- trunk/ChangeLog trunk/src/document.c trunk/src/documentprivate.h trunk/src/utils.c trunk/src/utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-01-09 18:21:44 UTC (rev 3456) +++ trunk/ChangeLog 2009-01-09 18:22:07 UTC (rev 3457) @@ -5,6 +5,10 @@ Add checks for GIO (GLib >= 2.16) support. Allow to specify files on the command line and from remote instances to be URIs (local and with GIO also remote URIs). + * src/document.c, src/documentprivate.h, src/utils.c, src/utils.h: + Add utils_is_remote_path(). + Add private field 'is_remote' to GeanyDocument to indicate whether + an opened file is locally accessed or via gvfs-fuse.
2009-01-08 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2009-01-09 18:21:44 UTC (rev 3456) +++ trunk/src/document.c 2009-01-09 18:22:07 UTC (rev 3457) @@ -1076,9 +1076,14 @@ return NULL; }
- if (! reload) doc = document_create(utf8_filename); - g_return_val_if_fail(doc != NULL, NULL); /* really should not happen */ + if (! reload) + { + doc = document_create(utf8_filename); + g_return_val_if_fail(doc != NULL, NULL); /* really should not happen */
+ doc->priv->is_remote = utils_is_remote_path(locale_filename); + } + sci_set_undo_collection(doc->editor->sci, FALSE); /* avoid creation of an undo action */ sci_empty_undo_buffer(doc->editor->sci);
@@ -1114,7 +1119,7 @@ { /* file exists on disk, set real_path */ g_free(doc->real_path); - doc->real_path = get_real_path_from_utf8(doc->file_name); + doc->real_path = tm_get_real_path(locale_filename);
/* "the" SCI signal (connect after initial setup(i.e. adding text)) */ g_signal_connect(doc->editor->sci, "sci-notify", G_CALLBACK(editor_sci_notify_cb), @@ -1453,6 +1458,13 @@ err = errno;
fclose(fp); + + /* now the file is on disk, set real_path */ + if (err == 0 && doc->real_path == NULL) + { + doc->real_path = tm_get_real_path(locale_filename); + doc->priv->is_remote = utils_is_remote_path(locale_filename); + } g_free(locale_filename);
return err; @@ -1548,12 +1560,6 @@ return FALSE; }
- /* now the file is on disk, set real_path */ - if (doc->real_path == NULL) - { - doc->real_path = get_real_path_from_utf8(doc->file_name); - } - /* store the opened encoding for undo/redo */ store_saved_encoding(doc);
Modified: trunk/src/documentprivate.h =================================================================== --- trunk/src/documentprivate.h 2009-01-09 18:21:44 UTC (rev 3456) +++ trunk/src/documentprivate.h 2009-01-09 18:22:07 UTC (rev 3457) @@ -64,10 +64,12 @@ GTrashStack *redo_actions; /* Used so Undo/Redo works for encoding changes. */ FileEncoding saved_encoding; - gboolean colourise_needed; /* use document.c:queue_colourise() instead */ - gint line_count; /* Number of lines in the document. */ - gint symbol_list_sort_mode; -} + gboolean colourise_needed; /* use document.c:queue_colourise() instead */ + gint line_count; /* Number of lines in the document. */ + gint symbol_list_sort_mode; + /* indicates whether a file is on a remote filesystem, works only with GIO/GVFS */ + gboolean is_remote; + } GeanyDocumentPrivate;
#endif
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2009-01-09 18:21:44 UTC (rev 3456) +++ trunk/src/utils.c 2009-01-09 18:22:07 UTC (rev 3457) @@ -1595,3 +1595,34 @@
return (strstr(uri, "://") != NULL); } + + +/* path should be in locale encoding */ +gboolean utils_is_remote_path(const gchar *path) +{ + g_return_val_if_fail(path != NULL, FALSE); + + /* if path is an URI and it doesn't start "file://", we take it as remote */ + if (utils_is_uri(path) && strncmp(path, "file:", 5) != 0) + return TRUE; + +#ifndef G_OS_WIN32 + { + static gchar *fuse_path = NULL; + static gsize len = 0; + if (fuse_path == NULL) + { + fuse_path = g_build_filename(g_get_home_dir(), ".gvfs", NULL); + len = strlen(fuse_path); + } + /* Comparing the file path against a hardcoded path is not the most elegant solution + * but for now it is better than nothing. Ideally, g_file_new_for_path() should create + * proper GFile objects for Fuse paths, but it only does in future GVFS + * versions (gvfs 1.1.1). */ + return (strncmp(path, fuse_path, len) == 0); + } +#endif + return FALSE; +} + +
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2009-01-09 18:21:44 UTC (rev 3456) +++ trunk/src/utils.h 2009-01-09 18:22:07 UTC (rev 3457) @@ -155,4 +155,6 @@
gboolean utils_is_uri(const gchar *uri);
+gboolean utils_is_remote_path(const gchar *path); + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.