Subversion Repositories pub

Compare Revisions

No changes between revisions

Ignore whitespace Rev 45 → Rev 46

/nautilus-follow-symlink/branches/1.2.0/nautilus/src/follow-symlink.c
0,0 → 1,359
/* $Id$
*
* follow-symlink.c
* nautilus-follow-symlink: Nautilus extension which allows opening the real
* path of symbolic links
*
* Copyright (C) 2006, 2008, 2009, 2011, 2012 Toni Corvera
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Toni Corvera <outlyer@outlyer.net>
*/
 
#include "follow-symlink.h"
 
#include <gio/gio.h>
#include <gtk/gtk.h>
 
// Symbolic name of the icon, use to be in /usr/share/icons/gnome/[16x16]/emblems/
#define FSL_ICON_NAME "emblem-symbolic-link"
 
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
 
#if 0 // See comments below
/* Obtains the icon path
* The returned string should be freed with g_free()
*
* If the real icon path can't be obtained, a symbolic icon name is returned
* instead.
*
* XXX: This is technically unneeded, passing FSL_ICON_NAME is enough for nautilus
* to resolve the icon in GNOME3.
* But neither method seems to work anymore in GNOME2 for some
* reason, other plugins don't show icons either so I guess that's normal.
*/
static gchar * fsl_icon_name() {
TRACE();
 
GtkIconTheme * git = gtk_icon_theme_get_default(); // Don't deallocate
g_assert( NULL != git );
GtkIconInfo * gii = gtk_icon_theme_lookup_icon(git,
FSL_ICON_NAME,
16, // Size
GTK_ICON_LOOKUP_GENERIC_FALLBACK); // Flags
if (NULL == gii) {
// Lookup failed
return g_strdup(FSL_ICON_NAME);
}
// gtk_icon_info_get_filename() returns an string owned by
// GTK. It was quickly overwritten in my tests.
// g_strdup() is safe to be called on NULL (return NULL)
gchar * fn = g_strdup(gtk_icon_info_get_filename(gii));
gtk_icon_info_free(gii);
if (NULL == fn) { // No filename associated
return g_strdup(FSL_ICON_NAME);
}
return fn;
}
#endif
 
/* Menu initialization */
void fsl_extension_menu_provider_iface_init(NautilusMenuProviderIface *iface)
{
TRACE();
 
iface->get_file_items = fsl_get_file_items;
iface->get_background_items = fsl_get_background_items;
}
 
/* Implementation of the menu attachment,
* 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,
NautilusFileInfo * file_info,
gboolean is_file_item,
GList * input)
{
TRACE();
 
NautilusMenuItem *item;
 
// Only file uris
{
// TODO: what about GnomeVFSFileInfo's is_local ?
gchar * uri_scheme = nautilus_file_info_get_uri_scheme(file_info);
if (strcmp(uri_scheme, "file") != 0) {
FSL_LOG1( "Not file scheme" );
return NULL;
}
g_free(uri_scheme);
}
 
// 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
// directory 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;
}
 
item = fsl_menu_item_new(gtk_widget_get_screen(window),
is_file_item,
nautilus_file_info_get_name(file_info));
g_signal_connect(item, "activate", G_CALLBACK(fsl_callback), file_info);
 
return g_list_append(input, item);
}
 
GList *
fsl_get_background_items(NautilusMenuProvider * provider __UNUSED,
GtkWidget * window,
NautilusFileInfo * current_folder)
{
TRACE();
 
if (NULL == current_folder) { // XXX: Does this ever happen?
FSL_LOG1( "No folder selected");
}
return fsl_get_items_impl(window, current_folder, FALSE, NULL);
}
 
 
gboolean file_is_directory (const gpointer const file_data)
{
TRACE();
 
/*
* 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);
}
 
/*
* Bind to the menu if needed
*
*
*/
GList * fsl_get_file_items (NautilusMenuProvider * provider __UNUSED,
GtkWidget * window,
GList * files)
{
TRACE();
 
// Number of files = g_list_length(files)
// Directory = nautilus_file_info_is_directory(files->data)
if (NULL == files) {
FSL_LOG1("No file selected");
return NULL;
}
 
assert( g_list_length(files) > 0 );
 
FSL_LOG_COND( g_list_length(files) > 1, "More than one file selected (%d)", g_list_length(files) );
 
GList * items = NULL;
 
for (int i=0; i<g_list_length(files); ++i) {
const gpointer file_info = g_list_nth_data(files, i);
if (!file_is_directory(file_info)) {
FSL_LOG ( "File %s is not a directory, discarded",
nautilus_file_info_get_name(file_info) );
continue;
}
FSL_LOG( "%s is a directory", nautilus_file_info_get_name(file_info) );
// TODO: Am I loosing memory?
GList * ret = fsl_get_items_impl(window, file_info, TRUE, items);
if (NULL != ret) {
items = ret;
}
}
 
return items;
}
 
/*
* Opens the real path of the symbolic link
*
* file_info: The symbolic link
*/
void fsl_callback (NautilusMenuItem * item __UNUSED, NautilusFileInfo * file_info)
{
TRACE();
 
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);
 
gchar * escaped_tgt = g_shell_quote(target);
gchar * command_line = g_strdup_printf(NAUTILUS_COMMAND " --no-desktop --no-default-window %s", escaped_tgt);
g_free(escaped_tgt);
 
if (G_UNLIKELY(FALSE == g_shell_parse_argv(command_line, NULL, &argv, NULL))) {
g_free(command_line);
g_printerr("Failed preparing " NAUTILUS_COMMAND " command-line.\n");
g_return_if_reached();
}
 
//g_printf(FSL_MSG_PREFIX ": Spawning with [PWD=%s]\n `%s`\n", g_file_get_path(parent), command_line);
g_printf(FSL_MSG_PREFIX ": Spawning 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);
}
 
/*
* Creates the new menu item
*
* is_file_item: TRUE if we're working over a (selected) file, FALSE if working
* over a (opened) folder
* base_name: file name, without path, of the given file
*/
NautilusMenuItem * fsl_menu_item_new(GdkScreen *screen __UNUSED,
gboolean is_file_item,
const gchar * a_base_name)
{
TRACE();
 
NautilusMenuItem *ret;
 
gchar * name, * tooltip, * fmt_name, * fmt_tooltip, * unique_name;
 
if (is_file_item) {
fmt_name = _("Follow symbolic _link '%s'");
fmt_tooltip = _("Open the directory pointed by the symbolic link '%s'");
}
else {
fmt_name = _("Open _real path of '%s'");
fmt_tooltip = _("Open the real path of the folder pointed by '%s'");
}
 
gchar * base_name = (gchar*)a_base_name;
 
// Replace any _ in the file name with __ (to display correctly in the
// context menu)
{
// Count them
size_t count = 0;
for (size_t i=0; i<strlen(base_name); ++i) {
if (*(base_name + i) == '_') {
++count;
}
}
 
// Escape the string if needed
if (count > 0) {
gchar * escaped_name = g_malloc( (strlen(base_name) + count)*sizeof(gchar) );
gchar * src = base_name, * dst = escaped_name;
 
while (count > 0) {
const gchar c = *src;
if (c == '_') {
*dst = '_';
dst++;
 
--count;
}
*dst = *src;
dst++; src++;
}
g_stpcpy(dst, src);
base_name = escaped_name;
}
}
 
// Trial and error showed that the menu item name must be different
// when various are to be shown (multiple selections), and also that the
// name should always be the same for a given file, hence the base name is
// appended to the command name
static const gchar * const ITEM_NAME_FMT = "FsymlinkExtension::follow_symlink_%s";
 
// g_try_malloc would allow nautilus to stay up even if some allocation fails
// but we'd be in trouble anyway. Apparently returning NULL is not an option either.
name = g_malloc( printf_string_upper_bound(fmt_name, base_name) );
tooltip = g_malloc( printf_string_upper_bound(fmt_tooltip, a_base_name) );
unique_name = g_malloc( printf_string_upper_bound(ITEM_NAME_FMT, a_base_name) );
 
g_sprintf(name, fmt_name, base_name);
g_sprintf(tooltip, fmt_tooltip, a_base_name);
g_sprintf(unique_name, ITEM_NAME_FMT, a_base_name);
 
// (name, label, tip, icon)
ret = nautilus_menu_item_new(unique_name, name, tooltip, FSL_ICON_NAME);
 
if (base_name != a_base_name) {
g_free(base_name);
}
g_free(unique_name);
g_free(name);
g_free(tooltip);
 
//g_object_set_data(G_OBJECT(ret), "FsymlinkExtension::screen", screen);
return ret;
}
 
/*** Utility(-es) ***/
 
/*
* Wrapper for g_printf_string_upper_bound with a variadic signature
*
* Returns the maximum space needed to store the formatted string
*/
gsize printf_string_upper_bound(const gchar * format, ...) {
va_list ap;
va_start(ap, format);
 
gsize retval = g_printf_string_upper_bound(format, ap);
 
va_end(ap);
 
return retval;
}
 
/* vim:set ts=4 et ai: */
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property
/nautilus-follow-symlink/branches/1.2.0/nautilus/src/nautilus-ext-follow-symlink.c
0,0 → 1,121
/* $Id$
*
* nautilus-ext-follow-symlink.c
* nautilus-follow-symlink: Nautilus extension which allows opening the real
* path of symbolic links
*
* Copyright (C) 2006 Toni Corvera
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Toni Corvera <outlyer@outlyer.net>
*/
 
#include "nautilus-ext-follow-symlink.h"
 
/* Public interface */
static GType fsl_type;
static GType provider_types[1];
 
void nautilus_module_initialize (GTypeModule *module)
{
TRACE();
FSL_DEBUG_INIT();
 
setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
textdomain(GETTEXT_PACKAGE);
 
g_printf("Initializing nautilus-follow-symlink extension (v%s)\n", VERSION);
 
fsl_register_type(module);
# if 0
provider_types[0] = fsl_get_type();
#endif
provider_types[0] = fsl_type;
}
 
void nautilus_module_shutdown (void)
{
TRACE();
 
/* Module-specific shutdown */
g_print ("Shutting down nautilus-follow-symlink extension\n");
}
 
void nautilus_module_list_types (const GType **types, int *num_types)
{
TRACE();
 
*types = provider_types;
*num_types = G_N_ELEMENTS(provider_types);
}
 
void fsl_register_type (GTypeModule * module)
{
TRACE();
 
static const GTypeInfo info = {
sizeof(FsymlinkExtensionClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
//TODO: Does nullifyng this have side effects?
NULL, //(GClassInitFunc) fsl_class_init,
NULL,
NULL,
sizeof (FsymlinkExtension),
0,
NULL, //(GInstanceInitFunc) fsl_instance_init,
};
 
fsl_type = g_type_module_register_type (module,
G_TYPE_OBJECT,
"FsymlinkExtension",
&info, 0);
/* Menu provider interface */
static const GInterfaceInfo menu_provider_iface_info = {
(GInterfaceInitFunc)fsl_extension_menu_provider_iface_init,
NULL,
NULL,
};
 
g_type_module_add_interface(module, fsl_type,
NAUTILUS_TYPE_MENU_PROVIDER, &menu_provider_iface_info);
 
/* Other Interfaces */
}
 
#if 0
GType fsl_get_type(void)
{
TRACE();
 
return fsl_type;
}
#endif
 
#if 0
void fsl_instance_init(FsymlinkExtension *instance)
{
TRACE();
}
 
void fsl_class_init(FsymlinkExtensionClass *class)
{
TRACE();
}
#endif
 
/* vim:set ts=4 et ai: */
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property
/nautilus-follow-symlink/branches/1.2.0/nautilus/src/Makefile.am
0,0 → 1,23
# $Id$ #
#
 
# Required to correctly install the locale files (and to access them)
CPPFLAGS+=-DGNOMELOCALEDIR=\""$(datadir)/locale"\"
 
nautilus_extension_lib_LTLIBRARIES = libnautilus-follow-symlink.la
 
# Must be installed in nautilus' extension dir
#nautilus_extension_libdir = $(libdir)/nautilus/extensions-1.0
# Cleaner way:
nautilus_extension_libdir = `pkg-config --variable=extensiondir libnautilus-extension`
 
noinst_HEADERS=*.h
 
libnautilus_follow_symlink_la_SOURCES = follow-symlink.c nautilus-ext-follow-symlink.c
libnautilus_follow_symlink_la_LIBADD = $(NAUTILUS_EXTENSION_LIBS)
libnautilus_follow_symlink_la_CFLAGS = $(NAUTILUS_EXTENSION_CFLAGS)
# There's really no need to have versioned file names
libnautilus_follow_symlink_la_LDFLAGS = -avoid-version
# See e.g. <http://www.seul.org/docs/autotut/#libtool> for version instructions
#libnautilus_follow_symlink_la_LDFLAGS = -version-info 0:0:0
 
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property
/nautilus-follow-symlink/branches/1.2.0/nautilus/src/nautilus-ext-follow-symlink.h
0,0 → 1,83
/* $Id$
*
* nautilus-ext-follow-symlink.h
* nautilus-follow-symlink: Nautilus extension which allows opening the real
* path of symbolic links
*
* Copyright (C) 2006 Toni Corvera
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Toni Corvera <outlyer@outlyer.net>
*/
 
#ifndef NAUTILUS_EXT_FOLLOW_SYMLINK_H
#define NAUTILUS_EXT_FOLLOW_SYMLINK_H
 
#include "common.h"
 
#include <glib-object.h>
#include <libnautilus-extension/nautilus-menu-provider.h>
 
#include <locale.h>
#include <libintl.h>
 
#include <glib/gprintf.h>
 
/*
* This file contains nautilus-follow-symlink's "public" interface,
* the functions required to bind the extension to nautilus
*/
 
void nautilus_module_initialize(GTypeModule *);
 
void nautilus_module_shutdown(void);
 
void nautilus_module_list_types(const GType **, int *);
 
/* These ones don't need public visibility */
 
static void fsl_register_type(GTypeModule *);
 
#if 0
static __constfn GType fsl_get_type(void);
#endif
 
/* Data Types */
 
struct _FsymlinkExtensionClass {
GObjectClass parent_slot;
};
 
struct _FsymlinkExtension {
GObject parent_slot;
};
 
typedef struct _FsymlinkExtensionClass FsymlinkExtensionClass;
 
typedef struct _FsymlinkExtension FsymlinkExtension;
 
/* Data initializers, not really needed */
#if 0
static void fsl_class_init (FsymlinkExtensionClass *class);
 
static void fsl_instance_init (FsymlinkExtension *cvs);
#endif
 
/* Defined in the private interface */
extern void fsl_extension_menu_provider_iface_init(NautilusMenuProviderIface *iface);
 
#endif /* NAUTILUS_EXT_FOLLOW_SYMLINK_H */
/* vim:set ts=4 et ai: */
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property
/nautilus-follow-symlink/branches/1.2.0/nautilus/src/common.h
0,0 → 1,253
/* $Id$
*
* common.h
* nautilus-follow-symlink: Nautilus extension which allows opening the real
* path of symbolic links
*
* Copyright (C) 2006, 2008, 2009, 2011, 2012 Toni Corvera
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Toni Corvera <outlyer@outlyer.net>
*/
 
#ifndef FOLLOW_SYMLINK_COMMON_H
#define FOLLOW_SYMLINK_COMMON_H
 
/*
* This file defines common debug utilities.
* Also, includes config.h.
*/
 
#if 0 // Separate includes. Might be problematic depending on flags
# include <glib/gmessages.h> /* g_print() */
# include <glib/gprintf.h> /* g_printf() */
#else
# include <glib.h>
#endif
 
// Used to allow simpler nautilus/caja code sharing
#define NAUTILUS_COMMAND "nautilus"
#define FSL_MSG_PREFIX "nautilus-follow-symlink"
 
#if 1 // Tricky workaround
// I truly have no clue why on earth I need this, but on Fedora 17,
// with GCC 4.7.0, when -O2 is used a "multiple definition" of
// ferror_unlocked will be triggered.
// Adding -fcommon didn't help
# include <stdio.h>
extern int ferror_unlocked(FILE*);
#endif
 
#include <stdlib.h> /* getenv() (3) */
#include <string.h> /* strcmp() (3) */
 
#ifdef _DEBUG
#include <stdarg.h> /* va_list, va_start ... */
#endif
 
#include "libintl.h"
#define _(STR) gettext(STR)
 
#ifdef HAVE_CONFIG_H
#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 <sys/stat.h>
#endif // HAVE_SYS_STAT_H
 
#if !defined(__inline)
#define __inline
#elif defined(_DEBUG)
#undef __inline
#define __inline
#endif
 
// Based on : http://rlove.org/log/2005102601
#if __GNUC__ >= 3
#define inline inline __attribute__((always_inline))
#define __pure __attribute__((pure))
//#define __const __attribute__((const)) // fails
#define __constfn __attribute__((const))
#define __noreturn __attribute__((noreturn))
#define __malloc __attribute__((malloc))
#define __must_check __attribute__((warn_unused_result))
#define __deprecated __attribute__((deprecated))
#define __used __attribute__((used))
// __unused gives errors in x86_64
#define __UNUSED __attribute__((unused))
#define __packed __attribute__((packed))
#define likely(x) __builtin_expect (!!(x), 1)
#define unlikely(x) __builtin_expect (!!(x), 0)
 
/* These are mine: used to hint the compiler in variadic printf-like
* functions, this way it will warn if format/arguments are incorrect */
/* printf-like variadic arguments (format is first, args from second) */
#define __va_printf __attribute__((format(printf, 1, 2)))
/* fprintf-like variadic arguments (format is second, args from third */
#define __va_fprintf __attribute__((format(printf, 2, 3)))
#else
#define inline /* no inline */
#define __pure /* no pure */
#define __constfn /* no const */
#define __noreturn /* no noreturn */
#define __malloc /* no malloc */
#define __must_check /* no warn_unused_result */
#define __deprecated /* no deprecated */
#define __used /* no used */
#define __UNUSED /* no unused */
#define __packed /* no packed */
#define likely(x) (x)
#define unlikely(x) (x)
 
#define __va_printf
#define __va_fprintf
#endif
 
/*
* Uber-anal glib usage: disallow stdlib's functions where glib provides
* their own
*/
#if 0 && __GNUC__
#pragma GCC poison printf sprintf
#endif
 
#ifdef _DEBUG
/* Debugging facilities */
 
/* Prefix for messages */
#define FSL_ "nautilus-follow-symlink: "
 
enum {
FINE = 1,
FINER,
 
TRACE = FINER,
};
 
/* Check on runtime the environment variable's value
*
* (set to 1 to enable verbosity, to 2 for extra verbosity)
*/
static inline int VERBOSITY_LEVEL(void)
{
const char * const DBGENV = getenv("FSL_DBG");
if (NULL == DBGENV || 0 == strcmp(DBGENV, "0")) {
return 0;
}
else if (0 == strcmp(DBGENV, "2")) {
return 2;
}
return 1;
}
 
/* Informational message shown on initialisation */
static inline void FSL_DEBUG_INIT(void)
{
g_print( FSL_ "DEBUG mode is available, and ");
g_printf(" set to %d.\n", VERBOSITY_LEVEL());
g_print( FSL_ "set the environment variable FSL_DBG to \n"
FSL_ "1 to enable it or to any other value to disable it.\n");
}
 
/* Display the name of the current function name */
#define TRACE() FSL_LOG_WITH_LEVEL(TRACE, FSL_ "trace: %s()", __func__);
 
/*
* Display a log message with a given log level if the level
* is at least VERBOSITY_LEVEL().
* Same as FSL_LOG_WITH_LEVEL but taking a va_list, this function
* provides the implementation used by the other FSL_LOG_*'s
*/
static inline void __UNUSED FSL_LOG_WITH_LEVEL_IMPL(int level,
gchar * const format,
va_list ap)
{
if (VERBOSITY_LEVEL() >= level) {
g_vprintf(format, ap);
g_print("\n");
}
}
 
/*
* Display a log message with a given log level if the level
* is at least VERBOSITY_LEVEL().
*/
static void __UNUSED __va_fprintf FSL_LOG_WITH_LEVEL(int level,
gchar * const format,
...)
{
va_list ap;
va_start(ap, format);
 
FSL_LOG_WITH_LEVEL_IMPL(level, format, ap);
 
va_end(ap);
}
 
/* Display a message
*
* NOTE: Variadic functions can't be inlined
*/
static void __UNUSED __va_printf FSL_LOG(gchar * const format, ...)
{
va_list ap;
va_start(ap, format);
 
FSL_LOG_WITH_LEVEL_IMPL(FINE, format, ap);
 
va_end(ap);
}
 
/* Display a message if a condition is true
*
* NOTE: Variadic functions can't be inlined
*/
static void __UNUSED __va_fprintf FSL_LOG_COND(int cond, gchar * const format, ...)
{
if (cond) {
va_list ap;
va_start(ap, format);
 
FSL_LOG_WITH_LEVEL_IMPL(FINE, format, ap);
 
va_end(ap);
}
}
 
/* see below for an explanation */
#define FSL_LOG1(s) FSL_LOG(s)
#else
/* Debugging facilities disabled */
#define FINE
#define FINER
#define TRACE()
#define FSL_DEBUG_INIT()
/* With variadic functions there's no way (AFAIK) to provide empty
* alternative macros that won't raise a compiler error if no variable
* arguments are given, hence this hackish FSL_LOG1, for the cases
* in which just an argument is used
*/
#define FSL_LOG1(s)
#define FSL_LOG(f, ...)
///* Unneeded for the time being */ #define FSL_LOG_WITH_LEVEL(l,f,rest...)
#define FSL_LOG_COND(c,f,...)
#endif // _DEBUG
 
#endif /* FOLLOW_SYMLINK_COMMON_H */
/* vim:set ts=4 et ai: */
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property
/nautilus-follow-symlink/branches/1.2.0/nautilus/src/follow-symlink.h
0,0 → 1,74
/* $Id$
*
* follow-symlink.h
* nautilus-follow-symlink: Nautilus extension which allows opening the real
* path of symbolic links
*
* Copyright (C) 2006 Toni Corvera
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Toni Corvera <outlyer@outlyer.net>
*/
 
#ifndef FOLLOW_SYMLINK_H
#define FOLLOW_SYMLINK_H
 
/*
* This file contains nautilus-follow-symlink's private interface,
* its core functionality
*/
 
#include "common.h"
 
#include <libnautilus-extension/nautilus-menu-provider.h>
 
#include <glib/gprintf.h>
#include <errno.h> /* errno (3) */
#include <string.h> /* strlen(), strerror() (3) */
#include <assert.h>
 
/* Static Prototypes */
 
static void fsl_callback(NautilusMenuItem *, NautilusFileInfo *);
 
// This signature can't be changed
static GList * fsl_get_file_items(NautilusMenuProvider *,
GtkWidget *,
GList *);
 
// This signature can't be changed
static GList * fsl_get_background_items(NautilusMenuProvider *,
GtkWidget *,
NautilusFileInfo *);
 
static inline GList * fsl_get_items_impl(GtkWidget *,
NautilusFileInfo *,
gboolean,
GList *);
 
static NautilusMenuItem * fsl_menu_item_new(GdkScreen *, gboolean, const gchar *);
 
static inline __pure gboolean file_is_directory(const gpointer const);
 
static gsize printf_string_upper_bound(const gchar *, ...);
 
/* Exported Prototypes
* Here the namespace is a bit more explicit just in case
*/
void fsl_extension_menu_provider_iface_init(NautilusMenuProviderIface *);
 
#endif /* FOLLOW_SYMLINK_H */
/* vim:set ts=4 et ai: */
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property