fixed memory leak
[psensor.git] / src / ui_sensorpref.c
index 9e8447e..6ca0815 100644 (file)
 
 #include <gtk/gtk.h>
 
-#include "cfg.h"
-#include "ui_pref.h"
-#include "ui_sensorlist.h"
-#include "ui_sensorpref.h"
-#include "ui_color.h"
+#include <cfg.h>
+#include <temperature.h>
+#include <ui_pref.h>
+#include <ui_sensorlist.h>
+#include <ui_sensorpref.h>
+#include <ui_color.h>
+
 
 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
 #include "ui_appindicator.h"
@@ -87,7 +89,7 @@ sensor_pref_new(struct psensor *s, struct config *cfg)
 static void sensor_pref_free(struct sensor_pref *p)
 {
        if (!p)
-               return ;
+               return;
 
        free(p->name);
        free(p->color);
@@ -182,12 +184,12 @@ ui_sensorpref_appindicator_label_toggled_cb(GtkToggleButton *btn, gpointer data)
 void ui_sensorpref_color_set_cb(GtkColorButton *widget, gpointer data)
 {
        struct sensor_pref *p;
-       GdkColor color;
+       GdkRGBA color;
 
        p = get_selected_sensor_pref(GTK_TREE_VIEW(data));
 
        if (p) {
-               gtk_color_button_get_color(widget, &color);
+               gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), &color);
                color_set(p->color, color.red, color.green, color.blue);
        }
 }
@@ -224,7 +226,7 @@ update_pref(struct sensor_pref *p, struct config *cfg, GtkBuilder *builder)
                *w_appindicator_label_enabled, *w_display;
        GtkColorButton *w_color;
        GtkSpinButton *w_high_threshold, *w_low_threshold;
-       GdkColor *color;
+       GdkRGBA color;
        struct psensor *s;
        int use_celsius;
 
@@ -254,10 +256,10 @@ update_pref(struct sensor_pref *p, struct config *cfg, GtkBuilder *builder)
                                       "sensor_enable_checkbox"));
        gtk_toggle_button_set_active(w_display, p->display_enabled);
 
-       color = color_to_gdkcolor(p->color);
+       color = color_to_GdkRGBA(p->color);
        w_color = GTK_COLOR_BUTTON(gtk_builder_get_object(builder,
                                                          "sensor_color"));
-       gtk_color_button_set_color(w_color, color);
+       gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(w_color), &color);
 
        w_alarm = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder,
                                                           "sensor_alarm"));
@@ -288,23 +290,12 @@ update_pref(struct sensor_pref *p, struct config *cfg, GtkBuilder *builder)
        w_appindicator_label_enabled = GTK_TOGGLE_BUTTON
                (gtk_builder_get_object(builder, "indicator_label_checkbox"));
 
-       if (is_temp_type(s->type) || is_fan_type(s->type)) {
-               gtk_toggle_button_set_active(w_alarm, p->alarm_enabled);
-               gtk_spin_button_set_value(w_high_threshold,
-                                         p->alarm_high_threshold);
-               gtk_spin_button_set_value(w_low_threshold,
-                                         p->alarm_low_threshold);
-               gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), TRUE);
-               gtk_widget_set_sensitive(GTK_WIDGET(w_high_threshold), TRUE);
-               gtk_widget_set_sensitive(GTK_WIDGET(w_low_threshold), TRUE);
-       } else {
-               gtk_toggle_button_set_active(w_alarm, 0);
-               gtk_spin_button_set_value(w_high_threshold, 0);
-               gtk_spin_button_set_value(w_low_threshold, 0);
-               gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), FALSE);
-               gtk_widget_set_sensitive(GTK_WIDGET(w_high_threshold), FALSE);
-               gtk_widget_set_sensitive(GTK_WIDGET(w_low_threshold), FALSE);
-       }
+       gtk_toggle_button_set_active(w_alarm, p->alarm_enabled);
+       gtk_spin_button_set_value(w_high_threshold, p->alarm_high_threshold);
+       gtk_spin_button_set_value(w_low_threshold, p->alarm_low_threshold);
+       gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), TRUE);
+       gtk_widget_set_sensitive(GTK_WIDGET(w_high_threshold), TRUE);
+       gtk_widget_set_sensitive(GTK_WIDGET(w_low_threshold), TRUE);
 
        gtk_toggle_button_set_active(w_appindicator_enabled,
                                     p->appindicator_enabled);
@@ -383,7 +374,10 @@ static void apply_pref(struct sensor_pref *p, int pos, struct config *cfg)
                config_set_sensor_alarm_enabled(s->id, s->alarm_enabled);
        }
 
-       color_set(s->color, p->color->red, p->color->green, p->color->blue);
+       color_set(s->color,
+                 p->color->red,
+                 p->color->green,
+                 p->color->blue);
        config_set_sensor_color(s->id, s->color);
 
        if (s->appindicator_enabled != p->appindicator_enabled) {
@@ -448,7 +442,7 @@ void ui_sensorpref_dialog_run(struct psensor *sensor, struct ui_psensor *ui)
        if (!ok) {
                log_printf(LOG_ERR, error->message);
                g_error_free(error);
-               return ;
+               return;
        }
 
        w_sensors_list