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

📄 plugins.c

📁 系统任务管理器
💻 C
📖 第 1 页 / 共 3 页
字号:
	{	if (allow)		*allow = _GK.allow_scaling;	if (width_ref)		*width_ref = _GK.chart_width_ref;	}gintgkrellm_plugin_debug(void)	{	return _GK.debug;	}/* ======================================================================= */static GkrellmMonitor		*place_plugin;enum	{	NAME_COLUMN,	ENABLE_COLUMN,	MON_COLUMN,	N_COLUMNS	};static GtkTreeView		*treeview;static GtkTreeRowReference *row_reference;static GtkWidget	*place_label,					*place_button,					*after_button,					*before_button,					*gravity_spin_button,					*builtin_button[N_BUILTIN_MONITORS];static GList		*plugins_list,					*plugins_enable_list,					*plugins_place_list;static gboolean		plugin_enable_list_modified,					plugin_placement_modified;gchar				*plugin_install_log;GkrellmMonitor *gkrellm_monitor_from_id(gint id)	{	GList			*list;	GkrellmMonitor	*mon;	for (list = gkrellm_monitor_list; list; list = list->next)		{		mon = (GkrellmMonitor *) list->data;		if (mon->id == id)			return mon;		}	return NULL;	}GkrellmMonitor *lookup_monitor_from_name(gchar *name)	{	GkrellmMonitor	*mon;	GList			*list;	for (list = gkrellm_monitor_list; list; list = list->next)		{		mon = (GkrellmMonitor *) list->data;		if (!mon->name || mon->id < 0)			continue;		if (!strcmp(name, mon->name))			return mon;		}	return NULL;	}GkrellmMonitor *gkrellm_monitor_from_style_name(gchar *style_name)	{	GkrellmMonitor	*mon;	GList			*list;	for (list = gkrellm_monitor_list; list; list = list->next)		{		mon = (GkrellmMonitor *) list->data;		if (!mon->privat || !mon->privat->style_name)			continue;		if (!strcmp(style_name, mon->privat->style_name))			return mon;		}	return NULL;	}static voidplugin_log(gchar *string1, ...)	{	va_list		args;	gchar		*s, *old_log;	if (!string1)		return;	va_start(args, string1);	s = string1;	while (s)		{		old_log = plugin_install_log;		if (plugin_install_log)			plugin_install_log = g_strconcat(plugin_install_log, s, NULL);		else			plugin_install_log = g_strconcat(s, NULL);		g_free(old_log);		s = va_arg(args, gchar *);		}	va_end(args);	}static gbooleanuser_placement(GkrellmMonitor *plugin)	{	GList			*list;	GkrellmMonitor	*mon;	gchar			*line, *s, *plugin_name, *mon_name;	gint			n, after, gravity;	if (!plugin->name)		return FALSE;	for (list = plugins_place_list; list; list = list->next)		{		line = g_strconcat((gchar *) list->data, NULL);		plugin_name = gkrellm_cut_quoted_string(line, &s);		mon_name = gkrellm_cut_quoted_string(s, &s);		n = sscanf(s, "%d %d", &after, &gravity);		if (n == 2)			{			if (after)				gravity = 0;			if (   !strcmp(plugin_name, plugin->name)				&& (mon = lookup_monitor_from_name(mon_name)) != NULL			   )				{				plugin->privat->insert_before_id = mon->id;				plugin->privat->gravity = gravity;				plugin->privat->insert_after = after;				g_free(line);				return TRUE;				}			}		g_free(line);		}	return FALSE;	}voidgkrellm_place_plugin(GList **monitor_list, GkrellmMonitor *plugin)	{	GkrellmMonitor	*mon;	GList			*list, *plist, *waste;	gint			n, gravity, after_flag;	gchar			buf[120];	if (plugin->create_monitor && !plugin->privat->main_vbox)		{		plugin->privat->main_vbox = gtk_vbox_new(FALSE, 0);		plugin->privat->top_spacer.vbox = gtk_vbox_new(FALSE, 0);		plugin->privat->vbox = gtk_vbox_new(FALSE, 0);		plugin->privat->bottom_spacer.vbox = gtk_vbox_new(FALSE, 0);		}	for (plist = NULL, list = *monitor_list; list; list = list->next)		{		mon = (GkrellmMonitor *) list->data;		/* Save list position as plugins are encountered so we can later		|  walk through them looking at gravity.		*/		if (MONITOR_ID(mon) == MON_PLUGIN && plist == NULL)			plist = list;		if (MONITOR_ID(mon) == plugin->privat->insert_before_id)			{			after_flag = plugin->privat->insert_after;			gravity = plugin->privat->gravity;			snprintf(buf, sizeof(buf), _("\t%s: placement is %s %s  G:%d\n"),					plugin->name,					after_flag ? _("after") : _("before"), mon->name, gravity);			plugin_log(buf, NULL);			if (after_flag)				{				if ((n = g_list_position(*monitor_list, list)) < 0)					n = 0;				*monitor_list = g_list_insert(*monitor_list, plugin, n + 1);				}			else				{				/* If there are plugins already above this builtin, then place				|  based on gravity.  Insert above the first plugin found that				|  has greater gravity than the current placing plugin.				*/				if (plist)					{					for ( ; plist != list; plist = plist->next)						{						mon = (GkrellmMonitor *) plist->data;						if (mon->privat->gravity > gravity)							break;						}					list = plist;					}				if (list == *monitor_list)					*monitor_list = g_list_prepend(list, plugin);				else					waste = g_list_prepend(list, plugin);				}			return;			}		else if (MONITOR_ID(mon) != MON_PLUGIN)			plist = NULL;		}	if (plugin->privat->insert_before_id != MON_UPTIME)		{		plugin->privat->insert_before_id = MON_UPTIME;		gkrellm_place_plugin(monitor_list, plugin);		return;		}	*monitor_list = g_list_append(*monitor_list, plugin);	}GkrellmMonitor *install_plugin(gchar *plugin_name)	{	GList					*list;	GModule					*module;	GkrellmMonitor			*m, *mm;	GkrellmMonitor			*(*init_plugin)();	gchar					buf[256];	static GkrellmMonitor	mon_tmp;	if (!g_module_supported())		return NULL;	module = g_module_open(plugin_name, 0);	plugin_log(plugin_name, "\n", NULL);	if (! module)		{		snprintf(buf, sizeof(buf), _("\tError: %s\n"), g_module_error());		plugin_log(buf, NULL);		return NULL;		}	if (!g_module_symbol(module, "gkrellm_init_plugin",				(gpointer) &init_plugin))		{		snprintf(buf, sizeof(buf), _("\tError: %s\n"), g_module_error());		plugin_log(buf, NULL);		g_module_close(module);		return NULL;		}	_GK.no_messages = TRUE;		/* Enforce policy */	mon_tmp.name = g_strdup(plugin_name);	gkrellm_record_state(INIT_MONITOR, &mon_tmp);#if !defined(WIN32)	m = (*init_plugin)();#else	m = (*init_plugin)(callbacks);#endif	_GK.no_messages = FALSE;	g_free(mon_tmp.name);	mon_tmp.name = NULL;	gkrellm_record_state(INTERNAL, NULL);	if (m == NULL)		{		plugin_log(_("\tOoops! plugin returned NULL, aborting\n"), NULL);		g_module_close(module);		return NULL;		}	for (list = gkrellm_monitor_list; list; list = list->next)		{		mm = (GkrellmMonitor *) list->data;		if (   !mm->privat || !mm->privat->style_name			|| !m->privat  || !m->privat->style_name			|| strcmp(mm->privat->style_name, m->privat->style_name)		   )			continue;		plugin_log(_("\tWarning: style name \""), m->privat->style_name,			_("\" already used by:\n\t\t"), mm->path, "\n", NULL);		}	for (list = gkrellm_monitor_list; list; list = list->next)		{		mm = (GkrellmMonitor *) list->data;		if (   !mm->config_keyword || !m->config_keyword			|| strcmp(mm->config_keyword, m->config_keyword)		   )			continue;		plugin_log(_("\tWarning: config keyword \""), m->config_keyword,			_("\" already used by:\n\t\t"), mm->path, "\n", NULL);		}	m->handle = module;	m->path = plugin_name;	if (!m->name)		m->name = g_path_get_basename(m->path);	if (m->privat == NULL)		/* Won't be null if style was added */		m->privat = g_new0(GkrellmMonprivate, 1);	m->privat->enabled = TRUE;	/* Enforce some id fields.	*/	m->id &= ~(MON_ID_MASK | MON_CONFIG_MASK);	m->id |= MON_PLUGIN;	if (PLUGIN_INSERT_BEFORE_ID(m) >= N_BUILTIN_MONITORS)		m->insert_before_id = MON_UPTIME;	if (!user_placement(m))		{		m->privat->insert_before_id = PLUGIN_INSERT_BEFORE_ID(m);		m->privat->gravity = PLUGIN_GRAVITY(m);		m->privat->insert_after = PLUGIN_INSERT_AFTER(m);		}	gkrellm_place_plugin(&gkrellm_monitor_list, m);	return m;	}pid_tgkrellm_get_pid(void)	{	return getpid();	}voidgkrellm_disable_plugin_connect(GkrellmMonitor *mon, void (*cb_func)())	{	if (!mon || !mon->privat || !cb_func)		return;	mon->privat->cb_disable_plugin = cb_func;	}static voiddisable_plugin(GkrellmMonitor *plugin)	{	GkrellmMonprivate	*mp = plugin->privat;	if (!mp->enabled)		return;	if (mp->top_spacer.image)		gtk_widget_destroy(mp->top_spacer.image);	mp->top_spacer.image = NULL;	if (mp->bottom_spacer.image)		gtk_widget_destroy(mp->bottom_spacer.image);	mp->bottom_spacer.image = NULL;	/* It is not safe to destroy a plugin widget tree.	|  They have already done one time first_create stuff.	*/	gtk_widget_hide(mp->vbox);	gtk_widget_hide(mp->main_vbox);	mp->enabled = FALSE;	if (mp->cb_disable_plugin)		(*mp->cb_disable_plugin)();	gkrellm_build();	gkrellm_remove_plugin_config_page(plugin);	plugin_enable_list_modified = TRUE;	}static voidenable_plugin(GkrellmMonitor *plugin)	{	GkrellmMonprivate	*mp = plugin->privat;	if (mp->enabled)		return;	gtk_widget_show(mp->vbox);	gtk_widget_show(mp->main_vbox);	mp->enabled = TRUE;	gkrellm_build();	gkrellm_add_plugin_config_page(plugin);	plugin_enable_list_modified = TRUE;	}static voidload_plugins_placement_file(void)	{	FILE	*f;	gchar	*path, *s, buf[256];	gkrellm_free_glist_and_data(&plugins_place_list);	path = gkrellm_make_config_file_name(gkrellm_homedir(),				PLUGIN_PLACEMENT_FILE);	if ((f = fopen(path, "r")) != NULL)		{		while ((fgets(buf, sizeof(buf), f)) != NULL)			{			if ((s = strchr(buf, '\n')) != NULL)				*s = '\0';			s = g_strdup(buf);			plugins_place_list = g_list_append(plugins_place_list, s);			}		fclose(f);		}	g_free(path);	}static voidsave_plugins_placement_file(void)	{	FILE				*f;	GList				*list;	GkrellmMonitor		*builtin, *plugin;	GkrellmMonprivate	*mp;	gchar				*path;		if (!plugin_placement_modified || _GK.demo)		return;	path = gkrellm_make_config_file_name(gkrellm_homedir(),				PLUGIN_PLACEMENT_FILE);	if ((f = fopen(path, "w")) != NULL)		{		for (list = plugins_list; list; list = list->next)			{			plugin = (GkrellmMonitor *) list->data;			mp  = plugin->privat;			if (   mp->enabled && !mp->from_command_line				&& (   mp->insert_before_id != PLUGIN_INSERT_BEFORE_ID(plugin)					|| mp->insert_after != PLUGIN_INSERT_AFTER(plugin)					|| mp->gravity != PLUGIN_GRAVITY(plugin)				   )			   )				{				builtin = gkrellm_monitor_from_id(mp->insert_before_id);				if (!builtin)					continue;				fprintf(f, "\"%s\" \"%s\" %d %d\n", plugin->name,						builtin->name, mp->insert_after, mp->gravity);				}			}		fclose(f);		}	plugin_placement_modified = FALSE;	g_free(path);	}static voidload_plugins_enable_file(void)	{	FILE	*f;	gchar	*path, *s, buf[256];	gkrellm_free_glist_and_data(&plugins_enable_list);	path = gkrellm_make_config_file_name(gkrellm_homedir(),PLUGIN_ENABLE_FILE);	if ((f = fopen(path, "r")) != NULL)		{		while ((fgets(buf, sizeof(buf), f)) != NULL)			{			if ((s = strchr(buf, '\n')) != NULL)				*s = '\0';			if (!buf[0])				continue;			s = g_path_get_basename(buf);			plugins_enable_list = g_list_append(plugins_enable_list, s);			}		fclose(f);		}	g_free(path);	}static voidsave_plugins_enable_file(void)	{	FILE			*f;	GList			*list;	GkrellmMonitor	*m;	gchar			*path, *s;		if (!plugin_enable_list_modified || _GK.demo)		return;	path = gkrellm_make_config_file_name(gkrellm_homedir(),				PLUGIN_ENABLE_FILE);	if ((f = fopen(path, "w")) != NULL)		{		for (list = plugins_list; list; list = list->next)			{			m = (GkrellmMonitor *) list->data;			if (m->privat->enabled && !m->privat->from_command_line)				{				s = g_path_get_basename(m->path);				fprintf(f, "%s\n", s);				g_free(s);				}			}		fclose(f);		}	plugin_enable_list_modified = FALSE;	g_free(path);	}static gchar *string_suffix(gchar *string, gchar *suffix)	{	gchar	*dot;	dot = strrchr(string, '.');	if (dot && !strcmp(dot + 1, suffix))		return dot + 1;	return NULL;	}static voidscan_for_plugins(gchar *path)	{    GDir			*dir;    gchar			*name, *filename;	GList			*list;	GkrellmMonitor	*m = NULL;	gchar			*s;	gboolean		exists;		if (!path || !*path || (dir = g_dir_open(path, 0, NULL)) == NULL)		return;	while ((name = (gchar *) g_dir_read_name(dir)) != NULL)		{		if (   !string_suffix(name, "so")			&& !string_suffix(name, "la")			&& !string_suffix(name, "dll")		   )			continue;		/* If there's a libtool .la archive, won't want to load this .so		*/		if (   !string_suffix(name, "la")			&& (s = strrchr(name, '.')) != NULL		   )			{			s = g_strndup(name, s - name);			filename = g_strconcat(path, G_DIR_SEPARATOR_S, s, ".la", NULL);			exists = g_file_test(filename, G_FILE_TEST_EXISTS);			g_free(s);			g_free(filename);			if (exists)				continue;			}		for (list = plugins_list; list; list = list->next)			{			m = (GkrellmMonitor *) list->data;			s = g_path_get_basename(m->path);			exists = !strcmp(s, name);			g_free(s);			if (exists)				break;			m = NULL;			}		s = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);		if (m)			{			plugin_log(_("Ignoring duplicate plugin "), s, "\n", NULL);

⌨️ 快捷键说明

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