README: add deprecation notice
[nautilus-actions.git] / src / plugin-menu / fma-menu-module.c
blob1163c23a98da6827af5fcfd99d03ff5ea6f82afb
1 /*
2 * FileManager-Actions
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/>.
23 * Authors:
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)
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
34 #include <string.h>
35 #include <syslog.h>
36 #include <unistd.h>
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
61 void
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 )
68 #endif
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 );
74 set_log_handler();
76 g_debug( "%s: module=%p", thisfn, ( void * ) module );
78 g_type_module_set_name( module, PACKAGE_STRING );
80 /* pwi 2011-01-05
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 );
89 void
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 )
96 #endif
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;
104 *types = type_list;
105 *num_types = 1;
107 /* this may let us some time to attach nautilus to the debugger :) */
108 /*sleep( 60 ); */
111 void
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 )
118 #endif
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)
143 static void
144 set_log_handler( void )
146 gboolean is_log_enabled;
148 #ifdef FMA_MAINTAINER_MODE
149 is_log_enabled = TRUE;
150 #else
151 is_log_enabled =
152 g_getenv( NAUTILUS_ACTIONS_DEBUG ) ||
153 fma_settings_get_boolean( IPREFS_PLUGIN_MENU_LOG, NULL, NULL );
154 #endif
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
166 static void
167 log_handler( const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data )
169 gchar *tmp;
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 )){
178 g_free( tmp );
179 tmp = g_strdup_printf( "[%s] ", log_domain );
182 syslog( LOG_USER | LOG_DEBUG, "%s%s", tmp, message );
183 g_free( tmp );