Wierd Panel Applet Problem

Howdy folks,
	Am writing a small applet and am having a weird bug crop up where if I
add the applet to my main panel, it runs fine, but if I add it to a
different panel it has a runtime error (which I think I have nailed down
to calling the g_dir_open function for a second time - here I get the

"Error opening directory '(null)': Invalid or incomplete multibyte or
wide character

this is called on a gchar * assigned from g_strdup_printf so it would
seem that g_strdup_printf is not creating a properly from string for
g_dir_open to work on..

However if I execute the applet from the command line, THEN add it to
the panel, it works as expected, no matter which panel I add it to...

this problem doesn't occur for root user, just me...

Has anyone had any experience with this kind of thing??

Thanks for any ideas...

/* this is where we will do the main work */

#include <gtk/gtk.h>
#include <panel-applet.h>
#include <string.h>
#include "sensor.h"

#define I2C_PATH "/sys/bus/i2c/devices/"

gboolean display_error_as_applet(GError *error, PanelApplet *applet);

static gboolean sensors_applet_init(PanelApplet *applet,
				    const gchar *iid,
				    gpointer data) {
	if (strcmp (iid, "OAFIID:SensorsApplet") != 0)
		return FALSE;
	GtkLabel *label;
	GDir *i2c_base_dir, *sensors_dir;
	gchar *string;
	const gchar *sensor_file, *i2c_subdir, *sensors_path;
	GList *sensors = NULL;
	Sensor *s;
	GError *error = NULL;
	i2c_base_dir = g_dir_open(I2C_PATH, 0, &error);
	if (error == NULL) {
		i2c_subdir = g_dir_read_name(i2c_base_dir);
		sensors_path = g_strdup_printf("%s%s/", I2C_PATH, i2c_subdir);
		sensors_dir = g_dir_open(sensors_path, 0, &error);
		if (error == NULL) {
			/* for each entry in sensors_dir, check if it is a sensor input file 
			   and create a Sensor if so */
			for (sensor_file = g_dir_read_name(sensors_dir); sensor_file != NULL; sensor_file = g_dir_read_name(sensors_dir)) {
				if (g_str_has_suffix(sensor_file, "_input")) {
					s = sensor_new(sensor_file, sensors_path);
					sensors = g_list_prepend(sensors, s);

			/* CHANGE BELOW!! */
			string = g_strdup_printf("%d sensors found.", g_list_length(sensors));
			g_list_foreach(sensors, sensor_free, NULL);

			label = g_object_new(GTK_TYPE_LABEL,
				     "label", string,
			gtk_container_add(GTK_CONTAINER(applet), GTK_WIDGET(label));

			return TRUE;
		} else { /* error occurred */
			return display_error_as_applet(error, applet);
	} else { /* error occurred */
		return display_error_as_applet(error, applet);

			    "Sensors Applet",

gboolean display_error_as_applet(GError *error, PanelApplet *applet) {
	GtkLabel *label;	
	label = g_object_new(GTK_TYPE_LABEL,
			     "label", error->message,
	gtk_container_add(GTK_CONTAINER(applet), GTK_WIDGET(label));
	return TRUE;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]