⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugin.c

📁 GNOME下的短信息发送中心
💻 C
字号:
/* * plugin interface - load/save/find plugin * xxx * * Authors:     Michael Jochum <e9725005@stud3.tuwien.ac.at> * * TODO:         * * Fixes: * * For license terms, see the file COPYING in the project directory. */ /* Plugins system based on that used in Gnumeric */ #include <config.h>#include <gnome.h>#include <gmodule.h>#include <dirent.h> #include "gsms-plugin.h"#include "plugin.h"GSList	*plugin_list = NULL;static gint plugin_compare(gconstpointer plugin1, gconstpointer plugin2);static gintplugin_compare(gconstpointer plugin1, gconstpointer plugin2){	gint p1 = ((PluginData *) plugin1) -> priority;	gint p2 = ((PluginData *) plugin2) -> priority;	return p1 - p2;}/* search for a providers supporting sms messages for phone number tel *//* returns a list of Plugins that would work sorted by priority        *//* you have to free the returned list                                  */GList *plugin_find (const char *tel){	GSList *plugin;	GList *working_plugins=NULL;	gint len;       	g_return_val_if_fail (tel != NULL, NULL);	len = strlen(tel);	g_return_val_if_fail (len > 0, NULL);	plugin = plugin_list;	while (plugin != NULL) {		GSList *nw;		nw = ((PluginData *) plugin->data) -> networks;		while (nw != NULL) {			gchar *prefix = ((GSMNetwork *) nw->data) -> prefix;			if (strncmp(prefix, tel, strlen(prefix)) == 0) {				working_plugins = g_list_append(					working_plugins, plugin->data);				break;			}                	nw = g_slist_next(nw);		}		plugin = g_slist_next(plugin);	}	return g_list_sort(working_plugins, plugin_compare);}PluginData *plugin_load (const gchar *file){	PluginData *pd;	guint res;	gchar *p;		g_return_val_if_fail (file != NULL, NULL);	pd = g_new0(PluginData, 1);		pd->file = g_strdup (file);	pd->handle = g_module_open (file, 0);	if (!pd->handle) {		g_print (_("Error, unable to open module file, %s"),			 g_module_error ());				g_free (pd);		return NULL;	}		if (!g_module_symbol (pd->handle, "init_plugin", 			      (gpointer*)&pd->init_plugin)) {		g_print (_("Error, plugin does not contain init_plugin function."));	     	g_module_close (pd->handle);		g_free (pd->file);		g_free (pd);		return NULL;	}		res = pd->init_plugin (pd);	if (res != PLUGIN_OK)	{		g_print (_("Error, init_plugin returned an error"));			     	g_module_close (pd->handle);		g_free (pd->file);		g_free (pd);		return NULL;	}	/* try to load priority from config file */	gnome_config_push_prefix ("/gsms/Plugin_Priority/");	/* there must be an easy way to do this ? */	pd->priority = -1;	if(pd->name != NULL) {		p = g_strdup_printf("%s=-1", pd->name);		pd->priority = gnome_config_get_int(p);		g_free(p);	}	if(pd->priority < 0 || pd->priority > 999)		pd->priority = pd->default_priority;	gnome_config_pop_prefix ();		plugin_list = g_slist_append (plugin_list, pd);	return pd;/*		g_module_close (pd->handle);	g_free (pd->file);	g_free (pd);	return NULL; */}voidplugin_unload (PluginData *pd){	g_return_if_fail (pd != NULL);		if (pd->can_unload != NULL)		if( ! pd->can_unload (pd) ) {			g_print (_("Error, plugin is still in use"));			return;		}		if (pd->destroy_plugin)		pd->destroy_plugin (pd);		plugin_list = g_slist_remove (plugin_list, pd);		g_module_close (pd->handle);	g_free (pd->file);	g_free (pd);}static voidplugin_load_plugins_in_dir (char *dir){	DIR *d;	struct dirent *e;		if ((d = opendir (dir)) == NULL)		return;		while ((e = readdir (d)) != NULL) {		if (strncmp(e->d_name + strlen(e->d_name) - 3, ".so", 3) == 0){			char *plugin = g_strdup_printf("%s/%s", dir, e->d_name);			plugin_load (plugin);			g_free (plugin);		}	}	closedir (d);}static voidload_all_plugins (void){	char *pdir;	char const * const home = g_get_home_dir ();		/* load user plugins */	if (home != NULL) {		pdir = gnome_util_prepend_user_home (".gsms/plugins");		plugin_load_plugins_in_dir (pdir);		g_free (pdir);	}		/* load system plgins */	plugin_load_plugins_in_dir (GSMS_PLUGIN_DIR);}/** * gedit_plugins_init: * */voidplugins_init (void){	if (!g_module_supported ())		return;		load_all_plugins ();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -