Skip to content

Commit

Permalink
Add checks for GIO (GLib >= 2.16) support.
Browse files Browse the repository at this point in the history
Allow to specify files on the command line and from remote instances to be URIs (local and with GIO also remote URIs).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3454 ea778897-0a13-0410-b9d1-a72fbfd435f5
  • Loading branch information
eht16 committed Jan 9, 2009
1 parent 1b2af6a commit 787a680
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 10 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2009-01-09 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

* configure.in, win32-config.h, wscript, src/main.c, src/main.h,
src/utils.c, src/utils.h:
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).


2009-01-08 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

* src/prefs.c, src/stash.c, src/keyfile.c:
Expand Down
4 changes: 4 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ gtk_modules="gtk+-2.0 >= 2.6.0"
PKG_CHECK_MODULES(GTK, [$gtk_modules])
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
# GIO checks
gio_modules="gio-2.0 >= 2.16"
PKG_CHECK_MODULES(GIO, [$gio_modules], have_gio=1, have_gio=0)
AC_DEFINE_UNQUOTED(HAVE_GIO, $have_gio, [Whether GIO is available])

# --disable-deprecated switch for GTK2 purification
AC_ARG_ENABLE(deprecated, [ --disable-deprecated Disable deprecated GTK functions. ],
Expand Down
36 changes: 27 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ gchar *main_get_argv_filename(const gchar *filename)
{
gchar *result;

if (g_path_is_absolute(filename))
if (g_path_is_absolute(filename) || utils_is_uri(filename))
result = g_strdup(filename);
else
{
Expand Down Expand Up @@ -717,37 +717,46 @@ static void signal_cb(gint sig)

/* Used for command-line arguments at startup or from socket.
* this will strip any :line:col filename suffix from locale_filename */
gboolean main_handle_filename(gchar *locale_filename)
gboolean main_handle_filename(const gchar *locale_filename)
{
GeanyDocument *doc;
gint line = -1, column = -1;
gchar *filename;

g_return_val_if_fail(locale_filename, FALSE);

get_line_and_column_from_filename(locale_filename, &line, &column);
/* check whether the passed filename is an URI */
filename = utils_get_path_from_uri(locale_filename);
if (filename == NULL)
return FALSE;

get_line_and_column_from_filename(filename, &line, &column);
if (line >= 0)
cl_options.goto_line = line;
if (column >= 0)
cl_options.goto_column = column;

if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
if (g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
{
doc = document_open_file(locale_filename, FALSE, NULL, NULL);
doc = document_open_file(filename, FALSE, NULL, NULL);
/* add recent file manually if opening_session_files is set */
if (doc != NULL && main_status.opening_session_files)
ui_add_recent_file(doc->file_name);
g_free(filename);
return TRUE;
}
else if (file_prefs.cmdline_new_files)
{ /* create new file with the given filename */
gchar *utf8_filename = utils_get_utf8_from_locale(locale_filename);
gchar *utf8_filename = utils_get_utf8_from_locale(filename);

doc = document_new_file(utf8_filename, NULL, NULL);
if (doc != NULL)
ui_add_recent_file(doc->file_name);
g_free(utf8_filename);
g_free(filename);
return TRUE;
}
g_free(filename);
return FALSE;
}

Expand Down Expand Up @@ -825,9 +834,18 @@ static void load_startup_files(gint argc, gchar **argv)
if (prefs.load_session)
{
if (load_project_from_cl)
project_load_file(argv[1]);
else
if (cl_options.load_session && !cl_options.new_instance)
{
gchar *pfile = argv[1];
if (utils_is_uri(argv[1]))
pfile = utils_get_path_from_uri(argv[1]);
if (pfile != NULL)
{
project_load_file(pfile);
if (pfile != argv[1])
g_free(pfile);
}
}
else if (cl_options.load_session && !cl_options.new_instance)
load_session_project_file();

/* when we want a new instance, we still load project session files unless -s
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gchar *main_get_argv_filename(const gchar *filename);

void main_quit(void);

gboolean main_handle_filename(gchar *locale_filename);
gboolean main_handle_filename(const gchar *locale_filename);

void main_reload_configuration(void);

Expand Down
45 changes: 45 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1550,3 +1550,48 @@ const gchar *utils_build_path(const gchar *first, ...)
}


/* Retrieves the path for the given URI.
* It returns:
* - the path which was determined by g_filename_from_uri() or GIO
* - NULL if the URI is non-local and gvfs-fuse is not installed
* - a new copy of 'uri' if it is not an URI. */
gchar *utils_get_path_from_uri(const gchar *uri)
{
gchar *locale_filename;

g_return_val_if_fail(uri != NULL, NULL);

if (! utils_is_uri(uri))
return g_strdup(uri);

/* this will work only for 'file://' URIs */
locale_filename = g_filename_from_uri(uri, NULL, NULL);
#ifdef HAVE_GIO
/* g_filename_from_uri() failed, so we probably have a non-local URI */
if (locale_filename == NULL)
{
GFile *file = g_file_new_for_uri(uri);
locale_filename = g_file_get_path(file);
g_object_unref(file);
if (locale_filename == NULL)
{
geany_debug("The URI '%s' could not be resolved to a local path. This means "
"that the URI is invalid or that you don't have gvfs-fuse installed.", uri);
return NULL;
}
}
#endif
if (locale_filename == NULL)
geany_debug("The URI '%s' could not be resolved to a local path. This means that the "
"URI is invalid or that Geany can't use GVFS (maybe it is not installed).", uri);

return locale_filename;
}


gboolean utils_is_uri(const gchar *uri)
{
g_return_val_if_fail(uri != NULL, FALSE);

return (strstr(uri, "://") != NULL);
}
4 changes: 4 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,8 @@ gint utils_str_casecmp(const gchar *s1, const gchar *s2);

const gchar *utils_build_path(const gchar *first, ...) G_GNUC_NULL_TERMINATED;

gchar *utils_get_path_from_uri(const gchar *uri);

gboolean utils_is_uri(const gchar *uri);

#endif
3 changes: 3 additions & 0 deletions win32-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,6 @@
/* Define if you want to detect a running instance */
#define HAVE_SOCKET 1

/* Define if GIO should be used, need GLib 2.16.x or newer */
#define HAVE_GIO 1

2 changes: 2 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def configure(conf):
have_gtk_210 = True
else:
gtk_version = 'Unknown'
# GIO check
conf.check_cfg(package='gio-2.0', uselib_store='GIO')

conf_define_from_opt('LIBDIR', Options.options.libdir, conf.env['PREFIX'] + '/lib')
conf_define_from_opt('DOCDIR', Options.options.docdir, conf.env['DATADIR'] + '/doc/geany')
Expand Down

0 comments on commit 787a680

Please sign in to comment.