3 * A file-manager extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
9 * FileManager-Actions is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * FileManager-Actions is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FileManager-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
24 * Frederic Ruaudel <grumz@grumz.net>
25 * Rodrigo Moya <rodrigo@gnome-db.org>
26 * Pierre Wieser <pwieser@trychlos.org>
27 * ... and many others (see AUTHORS)
38 #include <api/fma-fm-defines.h>
40 #include <core/fma-gconf-migration.h>
41 #include <core/fma-settings.h>
43 #include "fma-menu-plugin.h"
45 static void set_log_handler( void );
46 static void log_handler( const gchar
*log_domain
, GLogLevelFlags log_level
, const gchar
*message
, gpointer user_data
);
48 static GLogFunc st_default_log_func
= NULL
;
51 * A nautilus/nemo extension must implement three functions :
53 * - xxx_module_initialize
54 * - xxx_module_list_types
55 * - xxx_module_shutdown
57 * The first two functions are called at nautilus startup.
59 * The prototypes for these functions are defined in nautilus-extension-types.h
62 #if FMA_TARGET_ID == NAUTILUS_ID
63 nautilus_module_initialize( GTypeModule
*module
)
64 #elif FMA_TARGET_ID == NEMO_ID
65 nemo_module_initialize( GTypeModule
*module
)
66 #elif FMA_TARGET_ID == CAJA_ID
67 caja_module_initialize( GTypeModule
*module
)
70 static const gchar
*thisfn
= "fma_menu_module_" FMA_TARGET_LABEL
"_module_initialize";
72 syslog( LOG_USER
| LOG_INFO
, "[FMA] %s Menu Extender %s initializing...", PACKAGE_NAME
, PACKAGE_VERSION
);
76 g_debug( "%s: module=%p", thisfn
, ( void * ) module
);
78 g_type_module_set_name( module
, PACKAGE_STRING
);
81 * run GConf migration tools before doing anything else
82 * above all before allocating a new FMAPivot
84 fma_gconf_migration_run();
86 fma_menu_plugin_register_type( module
);
90 #if FMA_TARGET_ID == NAUTILUS_ID
91 nautilus_module_list_types( const GType
**types
, int *num_types
)
92 #elif FMA_TARGET_ID == NEMO_ID
93 nemo_module_list_types( const GType
**types
, int *num_types
)
94 #elif FMA_TARGET_ID == CAJA_ID
95 caja_module_list_types( const GType
**types
, int *num_types
)
98 static const gchar
*thisfn
= "fma_menu_module_" FMA_TARGET_LABEL
"_module_list_types";
99 static GType type_list
[1];
101 g_debug( "%s: types=%p, num_types=%p", thisfn
, ( void * ) types
, ( void * ) num_types
);
103 type_list
[0] = FMA_MENU_PLUGIN_TYPE
;
107 /* this may let us some time to attach nautilus to the debugger :) */
112 #if FMA_TARGET_ID == NAUTILUS_ID
113 nautilus_module_shutdown( void )
114 #elif FMA_TARGET_ID == NEMO_ID
115 nemo_module_shutdown( void )
116 #elif FMA_TARGET_ID == CAJA_ID
117 caja_module_shutdown( void )
120 static const gchar
*thisfn
= "fma_menu_module_" FMA_TARGET_LABEL
"_module_shutdown";
122 g_debug( "%s", thisfn
);
124 /* remove the log handler
125 * almost useless as the process is nonetheless terminating at this time
126 * but this is the art of coding...
128 if( st_default_log_func
){
129 g_log_set_default_handler( st_default_log_func
, NULL
);
130 st_default_log_func
= NULL
;
135 * a log handler that we install when in development mode in order to be
136 * able to log plugin runtime
138 * enabling log in the plugin menu at runtime requires a Nautilus restart
139 * (because we need to run in the code, which embeds g_debug instructions,
140 * and we have to do so before the log handler be set, or we will run
141 * into a deep stack recursion)
144 set_log_handler( void )
146 gboolean is_log_enabled
;
148 #ifdef FMA_MAINTAINER_MODE
149 is_log_enabled
= TRUE
;
152 g_getenv( NAUTILUS_ACTIONS_DEBUG
) ||
153 fma_settings_get_boolean( IPREFS_PLUGIN_MENU_LOG
, NULL
, NULL
);
156 st_default_log_func
= g_log_set_default_handler(( GLogFunc
) log_handler
, GUINT_TO_POINTER( is_log_enabled
));
160 * we used to install a log handler for each and every log domain used
161 * in FileManager-Actions ; this led to a fastidious enumeration
162 * instead we install a default log handler which will receive all
163 * debug messages, i.e. not only from FMA, but also from other code
164 * in the Nautilus process
167 log_handler( const gchar
*log_domain
, GLogLevelFlags log_level
, const gchar
*message
, gpointer user_data
)
170 gboolean is_log_enabled
;
172 is_log_enabled
= ( gboolean
) GPOINTER_TO_UINT( user_data
);
174 if( is_log_enabled
){
175 tmp
= g_strdup( "" );
177 if( log_domain
&& strlen( log_domain
)){
179 tmp
= g_strdup_printf( "[%s] ", log_domain
);
182 syslog( LOG_USER
| LOG_DEBUG
, "%s%s", tmp
, message
);