fixed changelog indentation
[psensor.git] / src / ui_sensorpref.c
1 /*
2     Copyright (C) 2010-2011 wpitchoune@gmail.com
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17     02110-1301 USA
18 */
19
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include "ui.h"
24 #include "ui_pref.h"
25 #include "ui_color.h"
26 #include "ui_sensorpref.h"
27
28 GtkWidget *ui_sensorpref_add_entry(GtkWidget * table,
29                                    const char *label,
30                                    const char *text, guint row)
31 {
32         GtkWidget *alig, *entry;
33
34         ui_pref_add_label(table, label, 0, row);
35
36         alig = gtk_alignment_new(0, 0.5, 0, 0);
37         gtk_alignment_set_padding(GTK_ALIGNMENT(alig), 4, 4, 4, 4);
38         entry = gtk_entry_new();
39         gtk_entry_set_text(GTK_ENTRY(entry), text);
40
41         gtk_container_add(GTK_CONTAINER(alig), entry);
42
43         gtk_table_attach(GTK_TABLE(table),
44                          alig,
45                          1, 2,
46                          row, row + 1,
47                          GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
48
49         return entry;
50
51 }
52
53 struct ui_sensorpref *ui_sensorpref_create(struct ui_sensorlist *ui_sensorlist,
54                                            struct psensor *sensor)
55 {
56         struct ui_sensorpref *pref;
57         const char *stype;
58         GtkSpinButton *spin_button;
59         GtkWidget *alig, *table, *w_alarm_enabled;
60
61         pref = malloc(sizeof(struct ui_sensorpref));
62
63         table = gtk_table_new(10, 2, FALSE);
64         gtk_table_set_col_spacing(GTK_TABLE(table), 0, 0);
65
66         /* Section Sensor Information */
67         ui_pref_add_section_title(table, _("Sensor Information"), 0);
68
69         ui_pref_add_label(table, _("Id:"), 0, 1);
70         ui_pref_add_label(table, sensor->id, 1, 1);
71
72         stype = psensor_type_to_str(sensor->type);
73         ui_pref_add_label(table, _("Type:"), 0, 2);
74         ui_pref_add_label(table, stype, 1, 2);
75
76         pref->w_name = ui_sensorpref_add_entry(table,
77                                                _("Name:"), sensor->name, 3);
78
79         /* Section graph */
80         ui_pref_add_section_title(table, _("Graph"), 4);
81
82         pref->w_enabled = ui_pref_add_check_button
83                 (table, _("Draw sensor curve"), sensor->enabled, 5);
84
85         pref->w_color = ui_pref_add_color_button
86                 (table, _("Color:"), sensor->color, 6);
87
88         /* Section Alarm */
89         ui_pref_add_section_title(table, _("Alarm"), 7);
90
91         w_alarm_enabled = ui_pref_add_check_button
92                 (table,
93                  _("Activate desktop notifications"), sensor->alarm_enabled,
94                  8);
95         if (!is_temp_type(sensor->type))
96                 gtk_widget_set_sensitive(w_alarm_enabled, FALSE);
97
98         ui_pref_add_label(table, _("Temperature limit:"), 0, 9);
99
100         spin_button
101             = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(0, 255, 1));
102         if (!is_temp_type(sensor->type))
103                 gtk_widget_set_sensitive(GTK_WIDGET(spin_button), FALSE);
104         gtk_spin_button_set_value(spin_button, sensor->alarm_limit);
105         alig = gtk_alignment_new(0, 0.5, 0, 0);
106         gtk_alignment_set_padding(GTK_ALIGNMENT(alig), 4, 4, 4, 4);
107         gtk_container_add(GTK_CONTAINER(alig), GTK_WIDGET(spin_button));
108         gtk_table_attach(GTK_TABLE(table),
109                          alig,
110                          1, 2,
111                          9, 10,
112                          GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
113
114         pref->widget = table;
115         pref->w_alarm_limit = GTK_WIDGET(spin_button);
116         pref->w_alarm_enabled = w_alarm_enabled;
117         pref->ui_sensorlist = ui_sensorlist;
118
119         return pref;
120 }