/*
- Copyright (C) 2010-2011 jeanfi@gmail.com
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301 USA
-*/
-
+ * Copyright (C) 2010-2012 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
#include <stdlib.h>
#include <gtk/gtk.h>
int enabled;
struct color *color;
int alarm_enabled;
- double alarm_limit;
+ int alarm_high_thresold;
};
struct cb_data {
struct sensor_pref **prefs;
};
-static struct sensor_pref *sensor_pref_new(struct psensor *s)
+static struct sensor_pref *sensor_pref_new(struct psensor *s,
+ struct config *cfg)
{
struct sensor_pref *p = malloc(sizeof(struct sensor_pref));
p->name = strdup(s->name);
p->enabled = s->enabled;
p->alarm_enabled = s->alarm_enabled;
- p->alarm_limit = s->alarm_limit;
p->color = color_dup(s->color);
+ if (cfg->temperature_unit == CELCIUS)
+ p->alarm_high_thresold = s->alarm_high_thresold;
+ else
+ p->alarm_high_thresold
+ = celcius_to_fahrenheit(s->alarm_high_thresold);
+
return p;
}
free(p);
}
-static struct sensor_pref **sensor_pref_list_new(struct psensor **sensors)
+static struct sensor_pref **sensor_pref_list_new(struct psensor **sensors,
+ struct config *cfg)
{
int n, i;
struct sensor_pref **pref_list;
pref_list = malloc(sizeof(struct sensor_pref *) * (n+1));
for (i = 0; i < n; i++)
- pref_list[i] = sensor_pref_new(sensors[i]);
+ pref_list[i] = sensor_pref_new(sensors[i],
+ cfg);
pref_list[n] = NULL;
}
static struct sensor_pref *
-get_seleted_sensor_pref(GtkBuilder *builder, struct sensor_pref **ps)
+get_selected_sensor_pref(GtkBuilder *builder, struct sensor_pref **ps)
{
GtkTreeModel *model;
GtkTreeIter iter;
str = gtk_entry_get_text(entry);
- p = get_seleted_sensor_pref(cbdata->builder, cbdata->prefs);
+ p = get_selected_sensor_pref(cbdata->builder, cbdata->prefs);
if (p && strcmp(p->name, str)) {
free(p->name);
struct cb_data *cbdata = data;
struct sensor_pref *p;
- p = get_seleted_sensor_pref(cbdata->builder, cbdata->prefs);
+ p = get_selected_sensor_pref(cbdata->builder, cbdata->prefs);
if (p)
p->enabled = gtk_toggle_button_get_active(btn);
struct cb_data *cbdata = data;
struct sensor_pref *p;
- p = get_seleted_sensor_pref(cbdata->builder, cbdata->prefs);
+ p = get_selected_sensor_pref(cbdata->builder, cbdata->prefs);
if (p)
p->alarm_enabled = gtk_toggle_button_get_active(btn);
struct sensor_pref *p;
GdkColor color;
- p = get_seleted_sensor_pref(cbdata->builder, cbdata->prefs);
+ p = get_selected_sensor_pref(cbdata->builder, cbdata->prefs);
if (p) {
gtk_color_button_get_color(widget, &color);
struct cb_data *cbdata = data;
struct sensor_pref *p;
- p = get_seleted_sensor_pref(cbdata->builder, cbdata->prefs);
+ p = get_selected_sensor_pref(cbdata->builder, cbdata->prefs);
if (p)
- p->alarm_limit = gtk_spin_button_get_value(btn);
+ p->alarm_high_thresold = gtk_spin_button_get_value(btn);
}
static void connect_signals(GtkBuilder *builder, struct cb_data *cbdata)
}
static void
-update_pref(struct psensor *s, struct sensor_pref **prefs, GtkBuilder *builder)
+update_pref(struct psensor *s,
+ struct sensor_pref **prefs,
+ struct config *cfg,
+ GtkBuilder *builder)
{
- GtkLabel *w_id, *w_type;
+ GtkLabel *w_id, *w_type, *w_temp_unit;
GtkEntry *w_name;
GtkToggleButton *w_draw, *w_alarm;
GtkColorButton *w_color;
GtkSpinButton *w_temp_limit;
GdkColor *color;
struct sensor_pref *p = sensor_pref_get(prefs, s);
+ int use_celcius;
w_id = GTK_LABEL(gtk_builder_get_object(builder, "sensor_id"));
gtk_label_set_text(w_id, s->id);
= GTK_SPIN_BUTTON(gtk_builder_get_object(builder,
"sensor_temp_limit"));
+ w_temp_unit
+ = GTK_LABEL(gtk_builder_get_object(builder,
+ "sensor_temp_unit"));
+
+ use_celcius = cfg->temperature_unit == CELCIUS ? 1 : 0;
+ gtk_label_set_text(w_temp_unit,
+ psensor_type_to_unit_str(s->type,
+ use_celcius));
+
if (is_temp_type(s->type)) {
gtk_toggle_button_set_active(w_alarm, p->alarm_enabled);
- gtk_spin_button_set_value(w_temp_limit, p->alarm_limit);
+ gtk_spin_button_set_value(w_temp_limit, p->alarm_high_thresold);
gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(w_temp_limit), TRUE);
} else {
gint *indices = gtk_tree_path_get_indices(p);
struct psensor *s = *(ui->sensors + *indices);
- update_pref(s, cbdata->prefs, cbdata->builder);
+ update_pref(s,
+ cbdata->prefs,
+ ui->config,
+ cbdata->builder);
gtk_tree_path_free(p);
}
}
static void
-apply_prefs(struct sensor_pref **prefs, struct psensor **sensors)
+apply_prefs(struct sensor_pref **prefs,
+ struct psensor **sensors,
+ struct config *cfg)
{
int n = psensor_list_size(sensors);
int i;
config_set_sensor_enabled(s->id, s->enabled);
}
- if (s->alarm_limit != p->alarm_limit) {
- s->alarm_limit = p->alarm_limit;
- config_set_sensor_alarm_limit(s->id,
- s->alarm_limit);
- }
+ if (cfg->temperature_unit == CELCIUS)
+ s->alarm_high_thresold = p->alarm_high_thresold;
+ else
+ s->alarm_high_thresold = fahrenheit_to_celcius
+ (p->alarm_high_thresold);
+
+ config_set_sensor_alarm_high_thresold(s->id,
+ s->alarm_high_thresold);
if (s->alarm_enabled != p->alarm_enabled) {
s->alarm_enabled = p->alarm_enabled;
struct cb_data cbdata;
cbdata.ui = ui;
- cbdata.prefs = sensor_pref_list_new(ui->sensors);
+ cbdata.prefs = sensor_pref_list_new(ui->sensors,
+ ui->config);
builder = gtk_builder_new();
cbdata.builder = builder;
return ;
}
- update_pref(sensor, cbdata.prefs, builder);
+ update_pref(sensor, cbdata.prefs, ui->config, builder);
connect_signals(builder, &cbdata);
w_sensors_list
result = gtk_dialog_run(diag);
if (result == GTK_RESPONSE_ACCEPT) {
- apply_prefs(cbdata.prefs, ui->sensors);
+ apply_prefs(cbdata.prefs, ui->sensors, ui->config);
ui_sensorlist_update_sensors_preferences(ui);
}