2 Copyright (C) 2010-2011 jeanfi@gmail.com
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.
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.
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
29 GdkColor *color_to_gdkcolor(struct color *color)
31 GdkColor *c = malloc(sizeof(GdkColor));
34 c->green = color->green;
35 c->blue = color->blue;
40 void ui_pref_dialog_run(struct ui_psensor *ui)
48 GdkColor *color_fg, *color_bg;
49 GtkColorButton *w_color_fg, *w_color_bg;
50 GtkHScale *w_bg_opacity;
51 GtkSpinButton *w_update_interval, *w_monitoring_duration,
53 GtkComboBox *w_sensorlist_pos;
54 GtkToggleButton *w_hide_window_decoration, *w_keep_window_below,
55 *w_enable_menu, *w_enable_launcher_counter, *w_hide_on_startup;
59 builder = gtk_builder_new();
61 ok = gtk_builder_add_from_file
63 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "psensor-pref.glade",
67 g_warning("%s", error->message);
72 diag = GTK_DIALOG(gtk_builder_get_object(builder, "dialog1"));
74 color_fg = color_to_gdkcolor(cfg->graph_fgcolor);
75 w_color_fg = GTK_COLOR_BUTTON(gtk_builder_get_object(builder,
77 gtk_color_button_set_color(w_color_fg, color_fg);
79 color_bg = color_to_gdkcolor(cfg->graph_bgcolor);
80 w_color_bg = GTK_COLOR_BUTTON(gtk_builder_get_object(builder,
82 gtk_color_button_set_color(w_color_bg, color_bg);
84 w_bg_opacity = GTK_HSCALE(gtk_builder_get_object(builder,
86 gtk_range_set_value(GTK_RANGE(w_bg_opacity), cfg->graph_bg_alpha);
88 w_update_interval = GTK_SPIN_BUTTON(gtk_builder_get_object
89 (builder, "update_interval"));
90 gtk_spin_button_set_value(w_update_interval,
91 cfg->graph_update_interval);
94 = GTK_SPIN_BUTTON(gtk_builder_get_object
95 (builder, "sensor_update_interval"));
96 gtk_spin_button_set_value(w_s_update_interval,
97 cfg->sensor_update_interval);
100 = GTK_SPIN_BUTTON(gtk_builder_get_object
101 (builder, "monitoring_duration"));
102 gtk_spin_button_set_value(w_monitoring_duration,
103 cfg->graph_monitoring_duration);
105 w_sensorlist_pos = GTK_COMBO_BOX
106 (gtk_builder_get_object(builder, "sensors_list_position"));
107 gtk_combo_box_set_active(w_sensorlist_pos, cfg->sensorlist_position);
109 w_hide_window_decoration = GTK_TOGGLE_BUTTON
110 (gtk_builder_get_object(builder, "hide_window_decoration"));
111 gtk_toggle_button_set_active(w_hide_window_decoration,
112 !cfg->window_decoration_enabled);
114 w_keep_window_below = GTK_TOGGLE_BUTTON
115 (gtk_builder_get_object(builder, "keep_window_below"));
116 gtk_toggle_button_set_active(w_keep_window_below,
117 cfg->window_keep_below_enabled);
119 w_enable_menu = GTK_TOGGLE_BUTTON
120 (gtk_builder_get_object(builder, "enable_menu"));
121 gtk_toggle_button_set_active(w_enable_menu, !cfg->menu_bar_disabled);
123 w_enable_launcher_counter = GTK_TOGGLE_BUTTON
124 (gtk_builder_get_object(builder, "enable_launcher_counter"));
125 gtk_toggle_button_set_active(w_enable_launcher_counter,
126 !cfg->unity_launcher_count_disabled);
128 w_hide_on_startup = GTK_TOGGLE_BUTTON
129 (gtk_builder_get_object(builder, "hide_on_startup"));
130 gtk_toggle_button_set_active(w_hide_on_startup, cfg->hide_on_startup);
132 result = gtk_dialog_run(diag);
134 if (result == GTK_RESPONSE_ACCEPT) {
138 g_mutex_lock(ui->sensors_mutex);
140 gtk_color_button_get_color(w_color_fg, &color);
141 color_set(cfg->graph_fgcolor,
142 color.red, color.green, color.blue);
144 gtk_color_button_get_color(w_color_bg, &color);
145 color_set(cfg->graph_bgcolor,
146 color.red, color.green, color.blue);
148 value = gtk_range_get_value(GTK_RANGE(w_bg_opacity));
149 cfg->graph_bg_alpha = value;
152 cfg->alpha_channel_enabled = 0;
154 cfg->alpha_channel_enabled = 1;
156 cfg->sensorlist_position
157 = gtk_combo_box_get_active(w_sensorlist_pos);
159 cfg->window_decoration_enabled =
160 !gtk_toggle_button_get_active(w_hide_window_decoration);
162 cfg->window_keep_below_enabled
163 = gtk_toggle_button_get_active(w_keep_window_below);
165 cfg->menu_bar_disabled
166 = !gtk_toggle_button_get_active(w_enable_menu);
168 cfg->unity_launcher_count_disabled
169 = !gtk_toggle_button_get_active
170 (w_enable_launcher_counter);
172 gtk_window_set_decorated(GTK_WINDOW(ui->main_window),
173 cfg->window_decoration_enabled);
175 gtk_window_set_keep_below(GTK_WINDOW(ui->main_window),
176 cfg->window_keep_below_enabled);
178 cfg->sensor_update_interval
179 = gtk_spin_button_get_value_as_int(w_s_update_interval);
181 cfg->graph_update_interval = gtk_spin_button_get_value_as_int
184 cfg->graph_monitoring_duration
185 = gtk_spin_button_get_value_as_int
186 (w_monitoring_duration);
188 cfg->sensor_values_max_length
189 = (cfg->graph_monitoring_duration * 60) /
190 cfg->sensor_update_interval;
193 = gtk_toggle_button_get_active(w_hide_on_startup);
197 g_mutex_unlock(ui->sensors_mutex);
199 ui_window_update(ui);
201 g_object_unref(G_OBJECT(builder));
202 gtk_widget_destroy(GTK_WIDGET(diag));