added static to create_sensor_popup
authorJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 3 May 2011 21:55:38 +0000 (21:55 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 3 May 2011 21:55:38 +0000 (21:55 +0000)
put sensor pref dialog into a separate new file (ui_sensorpref.c|h)

po/Makefile.in
src/Makefile.am
src/Makefile.in
src/ui.c
src/ui_sensorlist.c
src/ui_sensorpref.c [new file with mode: 0644]

index 120519a..78af544 100644 (file)
@@ -21,7 +21,7 @@ srcdir = .
 top_srcdir = ..
 
 
-prefix = /home/jporsini/tmp
+prefix = /usr/local
 exec_prefix = ${prefix}
 datarootdir = ${prefix}/share
 datadir = ${datarootdir}
index e567c83..2b1e5f4 100644 (file)
@@ -40,7 +40,8 @@ psensor_SOURCES = \
        ui_color.h ui_color.c \
        ui_graph.h ui_graph.c \
        ui_pref.h ui_pref.c \
-       ui_sensorlist.h ui_sensorlist.c 
+       ui_sensorlist.h ui_sensorlist.c \
+       ui_sensorpref.h ui_sensorpref.c
 
 if LIBNOTIFY
 psensor_SOURCES += ui_notify.h ui_notify.c
index 5316191..d03ffb6 100644 (file)
@@ -66,15 +66,17 @@ PROGRAMS = $(bin_PROGRAMS)
 am__psensor_SOURCES_DIST = compat.h cfg.h cfg.c graph.h graph.c main.c \
        ui.h ui.c ui_color.h ui_color.c ui_graph.h ui_graph.c \
        ui_pref.h ui_pref.c ui_sensorlist.h ui_sensorlist.c \
-       ui_notify.h ui_notify.c ui_appindicator.h ui_appindicator.c \
-       rsensor.h rsensor.c plib/url.c plib/url.h
+       ui_sensorpref.h ui_sensorpref.c ui_notify.h ui_notify.c \
+       ui_appindicator.h ui_appindicator.c rsensor.h rsensor.c \
+       plib/url.c plib/url.h
 @LIBNOTIFY_TRUE@am__objects_1 = ui_notify.$(OBJEXT)
 @APPINDICATOR_TRUE@am__objects_2 = ui_appindicator.$(OBJEXT)
 @CURL_TRUE@@JSON_TRUE@am__objects_3 = rsensor.$(OBJEXT) url.$(OBJEXT)
 am_psensor_OBJECTS = cfg.$(OBJEXT) graph.$(OBJEXT) main.$(OBJEXT) \
        ui.$(OBJEXT) ui_color.$(OBJEXT) ui_graph.$(OBJEXT) \
-       ui_pref.$(OBJEXT) ui_sensorlist.$(OBJEXT) $(am__objects_1) \
-       $(am__objects_2) $(am__objects_3)
+       ui_pref.$(OBJEXT) ui_sensorlist.$(OBJEXT) \
+       ui_sensorpref.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
+       $(am__objects_3)
 psensor_OBJECTS = $(am_psensor_OBJECTS)
 psensor_LDADD = $(LDADD)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -308,8 +310,9 @@ AM_CPPFLAGS = -Wall -pedantic -Werror \
        $(am__append_11) $(am__append_15)
 psensor_SOURCES = compat.h cfg.h cfg.c graph.h graph.c main.c ui.h \
        ui.c ui_color.h ui_color.c ui_graph.h ui_graph.c ui_pref.h \
-       ui_pref.c ui_sensorlist.h ui_sensorlist.c $(am__append_3) \
-       $(am__append_6) $(am__append_13)
+       ui_pref.c ui_sensorlist.h ui_sensorlist.c ui_sensorpref.h \
+       ui_sensorpref.c $(am__append_3) $(am__append_6) \
+       $(am__append_13)
 dist_man_MANS = psensor.1
 all: all-recursive
 
@@ -403,6 +406,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui_notify.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui_pref.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui_sensorlist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui_sensorpref.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/url.Po@am__quote@
 
 .c.o:
index 53589d9..132fb7b 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -26,6 +26,7 @@
 static gboolean
 on_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
+
 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
        gtk_widget_hide(((struct ui_psensor *)data)->main_window);
 #else
index e07011b..f563050 100644 (file)
@@ -266,8 +266,8 @@ static void cb_sensor_settings_activated(GtkWidget *menu_item, gpointer data)
        gtk_widget_destroy(GTK_WIDGET(diag));
 }
 
-GtkWidget *create_sensor_popup(struct ui_sensorlist *ui_sensorlist,
-                              struct psensor *sensor)
+static GtkWidget *create_sensor_popup(struct ui_sensorlist *ui_sensorlist,
+                                     struct psensor *sensor)
 {
        GtkWidget *menu;
        GtkWidget *item;
diff --git a/src/ui_sensorpref.c b/src/ui_sensorpref.c
new file mode 100644 (file)
index 0000000..a13ac07
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+    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
+*/
+
+#include <stdlib.h>
+
+#include <gtk/gtk.h>
+
+#include "cfg.h"
+#include "ui_pref.h"
+#include "ui_sensorlist.h"
+#include "ui_sensorpref.h"
+#include "ui_color.h"
+
+void ui_sensorpref_dialog_run(struct psensor *sensor, struct ui_psensor *ui)
+{
+       GtkDialog *diag;
+       gint result;
+       GtkBuilder *builder;
+       GError *error = NULL;
+       GtkLabel *w_id, *w_type;
+       GtkEntry *w_name;
+       GtkToggleButton *w_draw, *w_alarm;
+       GtkColorButton *w_color;
+       GtkSpinButton *w_temp_limit;
+       GdkColor *color;
+       guint ok;
+
+       builder = gtk_builder_new();
+
+       ok = gtk_builder_add_from_file
+               (builder,
+                PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "sensor-edit.glade",
+                &error);
+
+       if (!ok) {
+               g_warning("%s", error->message);
+               g_free(error);
+               return ;
+       }
+
+       w_id = GTK_LABEL(gtk_builder_get_object(builder, "sensor_id"));
+       gtk_label_set_text(w_id, sensor->id);
+
+       w_type = GTK_LABEL(gtk_builder_get_object(builder, "sensor_type"));
+       gtk_label_set_text(w_type, psensor_type_to_str(sensor->type));
+
+       w_name = GTK_ENTRY(gtk_builder_get_object(builder, "sensor_name"));
+       gtk_entry_set_text(w_name, sensor->name);
+
+       w_draw = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder,
+                                                         "sensor_draw"));
+       gtk_toggle_button_set_active(w_draw, sensor->enabled);
+
+       color = color_to_gdkcolor(sensor->color);
+       w_color = GTK_COLOR_BUTTON(gtk_builder_get_object(builder,
+                                                         "sensor_color"));
+       gtk_color_button_set_color(w_color, color);
+
+       w_alarm = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder,
+                                                          "sensor_alarm"));
+       w_temp_limit
+               = GTK_SPIN_BUTTON(gtk_builder_get_object(builder,
+                                                        "sensor_temp_limit"));
+
+       if (is_temp_type(sensor->type)) {
+               gtk_toggle_button_set_active(w_alarm, sensor->alarm_enabled);
+               gtk_spin_button_set_value(w_temp_limit, sensor->alarm_limit);
+       } else {
+               gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), FALSE);
+               gtk_widget_set_sensitive(GTK_WIDGET(w_temp_limit), FALSE);
+       }
+
+       diag = GTK_DIALOG(gtk_builder_get_object(builder, "dialog1"));
+       result = gtk_dialog_run(diag);
+
+       if (result == GTK_RESPONSE_ACCEPT) {
+
+               free(sensor->name);
+               sensor->name = strdup(gtk_entry_get_text(w_name));
+               config_set_sensor_name(sensor->id, sensor->name);
+
+               sensor->enabled = gtk_toggle_button_get_active(w_draw);
+               config_set_sensor_enabled(sensor->id, sensor->enabled);
+
+               sensor->alarm_limit = gtk_spin_button_get_value(w_temp_limit);
+               config_set_sensor_alarm_limit(sensor->id, sensor->alarm_limit);
+
+               sensor->alarm_enabled = gtk_toggle_button_get_active(w_alarm);
+               config_set_sensor_alarm_enabled(sensor->id,
+                                               sensor->alarm_enabled);
+
+               gtk_color_button_get_color(w_color, color);
+               color_set(sensor->color, color->red, color->green, color->blue);
+               config_set_sensor_color(sensor->id, sensor->color);
+
+               ui_sensorlist_update_sensors_preferences(ui->ui_sensorlist);
+       }
+
+       g_object_unref(G_OBJECT(builder));
+
+       gtk_widget_destroy(GTK_WIDGET(diag));
+}