Changed the "error" icon to emblem-noread.
Updated the hdaps slurp/parse functions to always return HDAPS_ERROR when there is an error.
Altered hdaps_set_icon to check for (status == HDAPS_ERROR) rather than (status < HDAPS_OFF) as a result of the previous modification.
dnl ***************************
dnl *** Version information ***
dnl ***************************
-m4_define([xfce4_hdaps_version], [0.0.2])
+m4_define([xfce4_hdaps_version], [0.0.3])
dnl ***************************
dnl *** Initialize autoconf ***
#define SYSFS_BLOCK_DEVICE_DIR "/sys/block/"
+
static int hdaps_device_exists(const char* device) {
/* Determine whether or not a device (file) exists and has an
unload_heads entry in sysfs. */
}
+
int get_hdaps_device_list(char list[MAX_HDAPS_DEVICES][FILENAME_MAX]) {
+ /* Gets a list of devices which support HDAPS.
+ * We start by getting every device in the sysfs
+ * block device directory, and then eliminate those
+ * which don't have an unload_heads entry.
+ */
int list_idx = 0;
DIR *dp;
struct dirent *ep;
}
+
int slurp_file(const char* filename, char* buf, int max_bytes) {
/* This function just reads the contents of filename
- * into buf. It is slightly stolen from the hdapsd project.
- */
-
- /* Return an error value by default. */
- int ret = HDAPS_ERROR;
- int fd = open(filename, O_RDONLY);
-
+ * into buf, and returns the number of bytes read.
+ */
if (filename == NULL || buf == NULL) {
- return ret;
+ /* HDAPS_SUPER_BAD_ERROR */
+ return HDAPS_ERROR;
}
-
+
+
+ /* Return an error value by default. */
+ int bytes_read = HDAPS_ERROR;
+
+ int fd = open(filename, O_RDONLY);
+
if (fd < 0) {
+ /* open() didn't work. Report the error, and bail. */
fprintf(stderr, "open(%s): %s\n", filename, strerror(errno));
- return fd;
+ return HDAPS_ERROR;
}
- ret = read(fd, buf, max_bytes-1);
+ bytes_read = read(fd, buf, max_bytes-1);
- if (ret < 0) {
+ if (bytes_read < 0) {
+ /* Why did we read fewer than 0 bytes? */
fprintf(stderr, "read(%s): %s\n", filename, strerror(errno));
}
else {
- buf[ret] = 0; /* Null-terminate buf. */
+ /* Null-terminate buf if read() worked. */
+ buf[bytes_read] = 0;
}
+
if (close(fd)) {
- fprintf(stderr, "close(%s): %s\n", filename, strerror(errno));
+ /* Oh hey we should be able to close the file, too. */
+ fprintf(stderr, "close(%s): %s\n", filename, strerror(errno));
}
- return ret;
+ return bytes_read;
}
to contain an integer (although in string form). */
char buf[MAX_FILE_CONTENTS_SIZE];
- int ret = slurp_file(filename, buf, sizeof(buf));
-
- if (ret < 0) {
- /* Why did we read fewer than 0 bytes? */
- return ret;
+ int bytes_read = slurp_file(filename, buf, sizeof(buf));
+
+ if (bytes_read <= 0) {
+ /* We can't parse what doesn't exist. Note that
+ * reading "0" from a file should result in reading
+ * at least 1 byte.
+ */
+ return HDAPS_ERROR;
}
else {
/* If we read more than 0 bytes, hopefully we can
- count on atoi to succeed. */
+ * count on atoi to succeed. */
return atoi(buf);
}
}
size = xfce_panel_plugin_get_size(hdaps->plugin) - 6;
/* Try to load an icon from the current icon theme. */
- if (status < HDAPS_OFF) {
+ if (status == HDAPS_ERROR) {
/* Error */
icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
- "dialog-error",
+ "emblem-noread",
size, 0, NULL);
}
else if (status == HDAPS_OFF) {
}
+
+void hdaps_set_tooltip(HdapsPlugin *hdaps, int status) {
+
+ if (status == HDAPS_ERROR) {
+ gtk_tooltips_set_tip(hdaps->tooltip, hdaps->eventbox, "HDAPS Error", NULL);
+ }
+ else if (status == HDAPS_OFF) {
+ gtk_tooltips_set_tip(hdaps->tooltip, hdaps->eventbox, "HDAPS Off", NULL);
+ }
+ else {
+ gtk_tooltips_set_tip(hdaps->tooltip, hdaps->eventbox, "HDAPS On", NULL);
+ }
+}
+
+
static void hdaps_set_defaults(HdapsPlugin *hdaps) {
DBG("Configuring all settings to defaults.");
hdaps->device_name = g_strdup(DEFAULT_DEVICE_NAME);
so it's important that they start out n*sync. */
hdaps->previous_status = HDAPS_OFF;
hdaps_set_icon(hdaps, HDAPS_OFF);
+
+ /* Create the tooltip widget, and set its initial value.
+ * The first couple of lines are stolen from the battery
+ * status plugin. I make no claim as to their correctness.
+ */
+ hdaps->tooltip = gtk_tooltips_new();
+ g_object_ref(G_OBJECT(hdaps->tooltip));
+ gtk_object_sink(GTK_OBJECT(hdaps->tooltip));
+ hdaps_set_tooltip(hdaps, HDAPS_OFF);
return hdaps;
}
if (G_LIKELY(hdaps->device_name != NULL)) {
g_free(hdaps->device_name);
}
+
+ /* Goodbye, tooltips. */
+ gtk_tooltips_set_tip(hdaps->tooltip, hdaps->eventbox, NULL, NULL);
+ g_object_unref(G_OBJECT(hdaps->tooltip));
/* ...and finally free the plugin structure. */
panel_slice_free(HdapsPlugin, hdaps);
if (status != hdaps->previous_status) {
/* And we only update the icon if we need to. */
hdaps_set_icon(hdaps, status);
+ hdaps_set_tooltip(hdaps, status);
hdaps->previous_status = status;
}
XfcePanelPlugin *plugin;
/* Panel widgets */
- GtkWidget *eventbox;
- GtkWidget *hvbox;
- GtkWidget *icon;
+ GtkWidget *eventbox;
+ GtkWidget *hvbox;
+ GtkWidget *icon;
+ GtkTooltips *tooltip;
/* A pointer to the timeout function.
That is, a pointer to the function that gets