From 50e50348688fa826f5592a29b180cb06a4cfafb7 Mon Sep 17 00:00:00 2001 From: Toni Corvera Date: Sun, 4 May 2008 14:02:54 +0000 Subject: [PATCH] Retro-fitted branch 1.0.99-pre.1 git-svn-id: https://svn.outlyer.net/svn/pub/nautilus-follow-symlink/branches/1.0.99-pre.1@37 da2faf11-d50b-4b07-92cd-6070d1bd8887 --- ChangeLog | 5 +++ INSTALL | 23 +++++++++++ Makefile.am | 2 +- configure.in | 6 ++- debian/changelog | 6 +++ debian/control | 6 +-- dist | 6 +++ src/common.h | 13 ++++++- src/follow-symlink.c | 92 ++++++++++++++++++++++++++++++++++++++++++-- 9 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 INSTALL diff --git a/ChangeLog b/ChangeLog index 35ba7ee..60ecbb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1.1.0: (pre-release) + * Adapted to work with GNOME 2.22, support for older GNOME versions + is dropped in newer releases; 1.0.2 can be used since it provides + the same functionality. + 1.0.2: (2007-05-12) * BUGFIX: Fixed icon location, was broken on newer systems diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..7a063e7 --- /dev/null +++ b/INSTALL @@ -0,0 +1,23 @@ +BUILD / INSTALLATION INSTRUCTIONS +================================= + +First and foremost, if you use Debian or a derived distribution try first +the upstream packages found at the project's homepage +. Or try building a deb +package yourself ($ dpkg-buildpackage -rfakeroot) + +Building +======== + +Run the included script "dist", this should create the missing files needed +to prepare the configuration. If some tool required to build is missing it +should also point it. + +$ ./dist + +The follow the usual GNU build instructions: + +$ ./configure --prefix=/usr/local +$ make +# make install + diff --git a/Makefile.am b/Makefile.am index 95198e6..e48c667 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = po src # This doesn't work as expected -libdir = @libdir@/nautilus/extensions-1.0 +libdir = @libdir@/nautilus/extensions-2.0 EXTRA_DIST = dist po/nautilus-follow-symlink.pot diff --git a/configure.in b/configure.in index f2d6aff..8164335 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ AC_INIT(src/follow-symlink.c) -AM_INIT_AUTOMAKE([ 1.9 libnautilus-follow-symlink ], "1.0.2") +AM_INIT_AUTOMAKE([ 1.9 libnautilus-follow-symlink ], "1.0.99") AC_CONFIG_HEADER(src/config.h) dnl default FLAGS @@ -37,7 +37,9 @@ dnl Xref: http://www.seul.org/docs/autotut/#libtool # glib-2.0: ensure it's present dnl and set GLIB_CFLAGS and GLIB_LIBS -AM_PATH_GLIB_2_0 +dnl The newer API in GNOME 2.22 requires 2.16 (maybe 2.14?), +dnl gio is the only module required (probably) +AM_PATH_GLIB_2_0(2.16.0, [], [], gio) # pkg-config: ensure libnautilus-extension is found by pkg-config PKG_CHECK_MODULES(NAUTILUS_EXTENSION, [libnautilus-extension]) diff --git a/debian/changelog b/debian/changelog index 6e7427e..6fc9005 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +nautilus-follow-symlink (1.0.99-upstream.0-pre.1) experimental; urgency=low + + * First pre-release for GNOME 2.22. + + -- Toni Corvera Sat, 03 May 2008 21:48:02 +0200 + nautilus-follow-symlink (1.0.2-out.1) unstable; urgency=low * New upstream release. diff --git a/debian/control b/debian/control index 320b173..9be2969 100644 --- a/debian/control +++ b/debian/control @@ -1,13 +1,13 @@ Source: nautilus-follow-symlink Section: contrib/gnome Priority: extra -Maintainer: Toni Corvera -Build-Depends: debhelper (>= 4.0.0), gcc, libtool, pkg-config, libc6-dev, libglib2.0-dev, libnautilus-extension-dev, intltool (>= 0.18), gettext, automake1.9, autoconf +Maintainer: Toni Corvera +Build-Depends: debhelper (>= 4.0.0), gcc, libtool, pkg-config, libc6-dev, libglib2.0-dev (>= 2.16), libnautilus-extension-dev (>= 2.21), intltool (>= 0.18), gettext, automake (>= 1.9), autoconf Standards-Version: 3.6.2 Package: nautilus-follow-symlink Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, nautilus +Depends: ${shlibs:Depends}, ${misc:Depends}, nautilus (>= 2.21) Description: nautilus plugin to open the location pointed by a symlink This extension adds a context menu option to symbolic links to folders which opens the pointed folder instead of the symbolic link. diff --git a/dist b/dist index 28c201d..9a2cbd5 100755 --- a/dist +++ b/dist @@ -89,3 +89,9 @@ package-source: clean --exclude='devel_docs' \ --exclude='.*' \ `basename $$OLDPWD`/ + +# Aliases +src: package-source +source: package-source +tarball: package-source + diff --git a/src/common.h b/src/common.h index 33208de..06b9392 100644 --- a/src/common.h +++ b/src/common.h @@ -4,7 +4,7 @@ * nautilus-follow-symlink: Nautilus extension which allows opening the real * path of symbolic links * - * Copyright (C) 2006 Toni Corvera + * Copyright (C) 2006-2008 Toni Corvera * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,6 +31,9 @@ * Also, includes config.h. */ +// Define NX_1_0 to use the older code, for nautilus-extension 1.0 +// It will be removed soon though + #include /* g_print() */ #include /* g_printf() */ @@ -48,6 +51,12 @@ #include "config.h" #endif // HAVE_CONFIG_H +// Not including this produces multiple definition errors as of 2008 (it didn't +// at the time of the previous release) +#ifdef HAVE_SYS_STAT_H + #include +#endif // HAVE_SYS_STAT_H + #if !defined(__inline) #define __inline #elif defined(_DEBUG) @@ -224,7 +233,7 @@ #define FSL_LOG(f, ...) ///* Unneeded for the time being */ #define FSL_LOG_WITH_LEVEL(l,f,rest...) #define FSL_LOG_COND(c,f,...) -#endif +#endif // _DEBUG #endif /* FOLLOW_SYMLINK_COMMON_H */ /* vim:set ts=4 et ai: */ diff --git a/src/follow-symlink.c b/src/follow-symlink.c index 6ef337e..c64a218 100644 --- a/src/follow-symlink.c +++ b/src/follow-symlink.c @@ -4,7 +4,7 @@ * nautilus-follow-symlink: Nautilus extension which allows opening the real * path of symbolic links * - * Copyright (C) 2006 Toni Corvera + * Copyright (C) 2006-2008 Toni Corvera * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,8 +25,15 @@ #include "follow-symlink.h" +#include + extern int errno; +// References for gio and the newer nautilus-extension: (required to support GNOME 2.22) +// http://library.gnome.org/devel/gio/unstable/GFile.html +// http://library.gnome.org/devel/gio/unstable/GFileInfo.html +// http://library.gnome.org/devel/libnautilus-extension/unstable/libnautilus-extension-nautilus-file-info.html + /* Menu initialization */ void fsl_extension_menu_provider_iface_init(NautilusMenuProviderIface *iface) { @@ -37,7 +44,7 @@ void fsl_extension_menu_provider_iface_init(NautilusMenuProviderIface *iface) } /* Implementation of the menu attachment, - * this is slightly different whith file items and with background (one folder) + * this is slightly different with file items and with background (one folder) * items, but shares most of the code, so the common part is here. */ GList * fsl_get_items_impl(GtkWidget * window, @@ -60,6 +67,27 @@ GList * fsl_get_items_impl(GtkWidget * window, g_free(uri_scheme); } + +#ifndef NX_1_0 + // TODO: Once the older code is deprecated, some nautilus_* function can be + // translated to their g_file_* counterparts. + + // Only process symlinks to directories, we know already the file is a + // direcoty or a symlink to one + GFile * gf = nautilus_file_info_get_location(file_info); // Get the pointed GFile + // FIXME: Can NULL be passed as last argument??? + GFileInfo* gfi = g_file_query_info(gf, + G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, // <== Important :P + NULL, + NULL); // Retrieve the symlink attribute + + if (!g_file_info_get_is_symlink(gfi)) { + FSL_LOG("No " G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK " attribute in %s", + nautilus_file_info_get_uri(file_info)); + return NULL; + } +#else // We know the file is either a directory or a symlink to a directory // TODO: Has glib/gnome any better/faster alternatives? GnomeVFSFileInfo * gfi = nautilus_file_info_get_vfs_file_info(file_info); @@ -73,7 +101,7 @@ GList * fsl_get_items_impl(GtkWidget * window, FSL_LOG("GnomeVFS Flags: ! SYMLINK in %s", nautilus_file_info_get_uri(file_info)); return NULL; } - +#endif item = fsl_menu_item_new(gtk_widget_get_screen(window), is_file_item, nautilus_file_info_get_name(file_info)); @@ -99,13 +127,20 @@ fsl_get_background_items(NautilusMenuProvider * provider __UNUSED, gboolean file_is_directory (const gpointer const file_data) { TRACE(); - + +#ifndef NX_1_0 // Nautilus extension v1.0, deprected + /* + * The "effective" type is returned, a symlink to a directory is a directory + */ + return G_FILE_TYPE_DIRECTORY == nautilus_file_info_get_file_type(file_data); +#else /* * Apparently type is never GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK and symlinks * are resolved to the target type */ const GnomeVFSFileInfo * const gfi = nautilus_file_info_get_vfs_file_info(file_data); return gfi->type == GNOME_VFS_FILE_TYPE_DIRECTORY; +#endif } /* @@ -159,6 +194,54 @@ void fsl_callback (NautilusMenuItem * item __UNUSED, NautilusFileInfo * file_inf { TRACE(); +#ifndef NX_1_0 + gchar ** argv; + + GFile * gf = nautilus_file_info_get_location(file_info); // Get the pointed GFile + // FIXME: Can NULL be passed as last argument??? + GFileInfo* gfi = g_file_query_info(gf, + G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, // <== Important :P + NULL, + NULL); // Retrieve the symlink attribute + + // The result will relative if the symlink is, must use the correct CWD + const char * target = g_file_info_get_symlink_target(gfi); + + GFile * parent = nautilus_file_info_get_parent_location(file_info); + + const gchar const * BASE_CMD = "nautilus --no-desktop --no-default-window '%s'"; + const gsize mem_block_size = printf_string_upper_bound(BASE_CMD, target); + gchar * command_line = g_try_malloc( mem_block_size ); + + if (NULL == command_line) { + g_printerr(__FILE__ ":%d: Failed to allocate enough memory " + "for command line, can't spawn new nautilus.\n", __LINE__); + // Redundant, but issues a CRITICAL message + g_return_if_fail( NULL != command_line ); + } + + g_sprintf(command_line, BASE_CMD, target); + + if (FALSE == g_shell_parse_argv(command_line, NULL, &argv, NULL)) { + g_free(command_line); + + g_printerr("Failed in creating the arguments for the child nautilus.\n"); + //g_return_if_fail( FALSE ); + g_return_if_reached(); + } + + g_printf("nautilus-follow-symlink: Spawning nautilus with\n '%s'\n", command_line); + + g_spawn_async( g_file_get_path(parent), // Inherit CWD + argv, + NULL, + G_SPAWN_SEARCH_PATH, //| G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, NULL, NULL); + + g_free(command_line); + g_strfreev(argv); +#else gchar ** argv; const GnomeVFSFileInfo * gfi = nautilus_file_info_get_vfs_file_info(file_info); // See /usr/include/gnome-vfs-2.0/libgnomevfs/gnome-vfs-file-info.h, @@ -196,6 +279,7 @@ void fsl_callback (NautilusMenuItem * item __UNUSED, NautilusFileInfo * file_inf g_free(command_line); g_strfreev(argv); +#endif } /*