Exemple #1
0
static void _preferences_window_applets_plugin_add(GtkListStore * store,
		char const * name)
{
	Plugin * p;
	PanelAppletDefinition * pad;
	GtkTreeIter iter;
	GtkIconTheme * theme;
	GdkPixbuf * pixbuf = NULL;

	if((p = plugin_new(LIBDIR, PACKAGE, "applets", name)) == NULL)
		return;
	if((pad = plugin_lookup(p, "applet")) == NULL)
	{
		plugin_delete(p);
		return;
	}
	theme = gtk_icon_theme_get_default();
	if(pad->icon != NULL)
		pixbuf = gtk_icon_theme_load_icon(theme, pad->icon, 24, 0,
				NULL);
	if(pixbuf == NULL)
		pixbuf = gtk_icon_theme_load_icon(theme, "gnome-settings", 24,
				0, NULL);
	gtk_list_store_append(store, &iter);
	gtk_list_store_set(store, &iter, 0, name, 1, pixbuf, 2, pad->name, -1);
	plugin_delete(p);
}
Exemple #2
0
/* panel_window_append */
int panel_window_append(PanelWindow * panel, char const * applet)
{
	PanelAppletHelper * helper = panel->helper;
	PanelApplet * pa;

	if((pa = realloc(panel->applets, sizeof(*pa)
					* (panel->applets_cnt + 1))) == NULL)
		return -error_set_code(1, "%s", strerror(errno));
	panel->applets = pa;
	pa = &panel->applets[panel->applets_cnt];
	if((pa->plugin = plugin_new(LIBDIR, PACKAGE, "applets", applet))
			== NULL)
		return -1;
	pa->widget = NULL;
	if((pa->pad = plugin_lookup(pa->plugin, "applet")) == NULL
			|| (pa->pa = pa->pad->init(helper, &pa->widget)) == NULL
			|| pa->widget == NULL)
	{
		if(pa->pa != NULL)
			pa->pad->destroy(pa->pa);
		plugin_delete(pa->plugin);
		return -1;
	}
	gtk_box_pack_start(GTK_BOX(panel->box), pa->widget, pa->pad->expand,
			pa->pad->fill, 0);
	gtk_widget_show_all(pa->widget);
	panel->applets_cnt++;
	return 0;
}
Exemple #3
0
/* panel_load */
int panel_load(Panel * panel, PanelPosition position, char const * applet)
{
	PanelWindow * window;
	PanelAppletHelper * helper;
	Plugin * plugin;
	PanelAppletDefinition * pad;
	PanelApplet * pa;
	GtkWidget * widget = NULL;
	GtkWidget * vbox;

	if(position == PANEL_POSITION_BOTTOM && panel->bottom != NULL)
	{
		window = panel->bottom;
		helper = &panel->bottom_helper;
	}
	else if(position == PANEL_POSITION_TOP && panel->top != NULL)
	{
		window = panel->top;
		helper = &panel->top_helper;
	}
	else
		return -1;
	if((plugin = plugin_new(LIBDIR, PACKAGE, "applets", applet)) == NULL)
		return -1;
	if((pad = plugin_lookup(plugin, "applet")) == NULL
			|| pad->init == NULL || pad->destroy == NULL
			|| (pa = pad->init(helper, &widget)) == NULL)
	{
		plugin_delete(plugin);
		return -1;
	}
	panel_window_append(window, widget, pad->expand, pad->fill);
	if(pad->settings != NULL
			&& (widget = pad->settings(pa, FALSE, FALSE)) != NULL)
	{
		vbox = gtk_vbox_new(FALSE, 4);
		/* XXX ugly */
		g_object_set_data(G_OBJECT(vbox), "definition", pad);
		g_object_set_data(G_OBJECT(vbox), "applet", pa);
		gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
		gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0);
		gtk_widget_show(vbox);
		gtk_notebook_append_page(GTK_NOTEBOOK(panel->pr_notebook),
				vbox, gtk_label_new(pad->name));
	}
	return 0;
}
Exemple #4
0
static int _new_target(Code * code, char const * target,
		C99Option const * options, size_t options_cnt)
{
	C99Option const * p;
	size_t i;
	size_t j;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%s, %zu)\n", __func__, target ? target
			: "NULL", options_cnt);
#endif
	if(target == NULL)
		target = "asm";
	if((code->plugin = plugin_new(LIBDIR, PACKAGE, "target", target))
			== NULL
			|| (code->target = plugin_lookup(code->plugin,
					"target_plugin")) == NULL)
		return -1;
	code->target->helper = code->helper;
	if(code->target->options == NULL && options_cnt != 0)
		return -error_set_code(1, "%s", "Target supports no options");
	for(i = 0; i < options_cnt; i++)
	{
		p = &options[i];
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() option \"%s\"\n", __func__,
				p->name);
#endif
		for(j = 0; code->target->options[j].name != NULL; j++)
			if(strcmp(p->name, code->target->options[j].name) == 0)
				break;
		if(code->target->options[j].name == NULL)
			break;
		code->target->options[j].value = p->value;
	}
	if(i != options_cnt)
	{
		code->target = NULL;
		return error_set_code(1, "%s: %s%s%s", target,
				"Unknown option \"", p->name, "\" for target");
	}
	return 0;
}
Exemple #5
0
/* format_new */
AsmFormat * format_new(char const * format)
{
	AsmFormat * f;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, format);
#endif
	if(format == NULL)
	{
		error_set_code(1, "%s", strerror(EINVAL));
		return NULL;
	}
	if((f = object_new(sizeof(*f))) == NULL)
		return NULL;
	if((f->handle = plugin_new(LIBDIR, PACKAGE, "format", format)) == NULL
			|| (f->definition = plugin_lookup(f->handle,
					"format_plugin")) == NULL)
	{
		if(f->handle != NULL)
			plugin_delete(f->handle);
		object_delete(f);
		return NULL;
	}
	f->plugin = NULL;
	memset(&f->helper, 0, sizeof(f->helper));
	f->helper.format = f;
	f->helper.decode = _format_helper_decode;
	f->helper.get_filename = _format_helper_get_filename;
	f->helper.get_function_by_id = _format_helper_get_function_by_id;
	f->helper.get_functions = _format_helper_get_functions;
	f->helper.get_section_by_id = _format_helper_get_section_by_id;
	f->helper.get_string_by_id = _format_helper_get_string_by_id;
	f->helper.set_function = _format_helper_set_function;
	f->helper.set_section = _format_helper_set_section;
	f->helper.set_string = _format_helper_set_string;
	f->helper.read = _format_helper_read;
	f->helper.seek = _format_helper_seek;
	f->helper.write = _format_helper_write;
	return f;
}
Exemple #6
0
/* desktop_widget_new */
DesktopWidget * desktop_widget_new(char const * name)
{
	DesktopWidget * widget;

	if((widget = object_new(sizeof(*widget))) == NULL)
		return NULL;
	widget->definition = NULL;
	widget->dplugin = NULL;
	if((widget->plugin = plugin_new(LIBDIR, "Desktop", "widget",
					name)) == NULL
			|| (widget->definition = plugin_lookup(widget->plugin,
					"widget")) == NULL
			|| widget->definition->init == NULL
			|| widget->definition->destroy == NULL
			|| widget->definition->get_widget == NULL
			|| (widget->dplugin = widget->definition->init(name))
			== NULL)
	{
		desktop_widget_delete(widget);
		return NULL;
	}
	return widget;
}
Exemple #7
0
/* arch_new */
AsmArch * arch_new(char const * name)
{
	AsmArch * a;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, name);
#endif
	if((a = object_new(sizeof(*a))) == NULL)
		return NULL;
	memset(&a->helper, 0, sizeof(a->helper));
	if((a->handle = plugin_new(LIBDIR, PACKAGE, "arch", name)) == NULL
			|| (a->definition = plugin_lookup(a->handle,
					"arch_plugin")) == NULL)
	{
		if(a->handle != NULL)
			plugin_delete(a->handle);
		object_delete(a);
		return NULL;
	}
	a->plugin = NULL;
#if 1 /* XXX should be done when initializing */
	a->instructions_cnt = 0;
	if(a->definition->instructions != NULL)
		for(; a->definition->instructions[a->instructions_cnt].name
				!= NULL; a->instructions_cnt++);
	a->registers_cnt = 0;
	if(a->definition->registers != NULL)
		for(; a->definition->registers[a->registers_cnt].name != NULL;
				a->registers_cnt++);
#endif
	a->filename = NULL;
	a->fp = NULL;
	a->buffer = NULL;
	a->buffer_cnt = 0;
	a->buffer_pos = 0;
	return a;
}
Exemple #8
0
/* modem_new */
Modem * modem_new(Config * config, char const * name, unsigned int retry)
{
	Modem * modem;

	if((modem = object_new(sizeof(*modem))) == NULL)
		return NULL;
	modem->name = string_new(name);
	modem->modem = NULL;
	modem->config = config;
	modem->retry = retry;
	modem->active = 0;
	modem->callback = NULL;
	modem->priv = NULL;
	if((modem->plugin = plugin_new(LIBDIR, PACKAGE, "modem", name)) != NULL)
		modem->definition = plugin_lookup(modem->plugin, "plugin");
	/* check errors */
	if(modem->name == NULL || modem->plugin == NULL)
	{
		modem_delete(modem);
		return NULL;
	}
	modem->helper.modem = modem;
	modem->helper.config_get = _modem_helper_config_get;
	modem->helper.config_set = _modem_helper_config_set;
	modem->helper.event = _modem_event_callback;
	modem->helper.error = _modem_helper_error;
	if(modem->definition->init == NULL
			|| (modem->modem = modem->definition->init(
					&modem->helper)) == NULL)
	{
		modem->modem = NULL;
		modem_delete(modem);
		return NULL;
	}
	return modem;
}