X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fui_pref.c;h=46b9fc31a21d8ae143c8ef45abd65bebd319b078;hb=8a3d16ade26321374c684080d627cf12ba71e598;hp=2663f986696cf24f16dceebb1080aaa208d63ab9;hpb=e34af72ddaecb2baf56a0e0a7e135e8f25861ba2;p=psensor.git diff --git a/src/ui_pref.c b/src/ui_pref.c index 2663f98..46b9fc3 100644 --- a/src/ui_pref.c +++ b/src/ui_pref.c @@ -1,38 +1,38 @@ /* - 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-2014 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 #include -#include "ui.h" -#include "cfg.h" -#include "ui_pref.h" -#include "ui_color.h" -#include "compat.h" +#include +#include +#include +#include +#include -GdkColor *color_to_gdkcolor(struct color *color) +GdkRGBA color_to_GdkRGBA(struct color *color) { - GdkColor *c = malloc(sizeof(GdkColor)); + GdkRGBA c; - c->red = color->red; - c->green = color->green; - c->blue = color->blue; + c.red = color->red; + c.green = color->green; + c.blue = color->blue; + c.alpha = 1.0; return c; } @@ -45,15 +45,18 @@ void ui_pref_dialog_run(struct ui_psensor *ui) GtkBuilder *builder; guint ok; GError *error = NULL; - GdkColor *color_fg, *color_bg; - GtkColorButton *w_color_fg, *w_color_bg; - GtkHScale *w_bg_opacity; + GdkRGBA color_fg, color_bg; + GtkColorChooser *w_color_fg, *w_color_bg; + GtkScale *w_bg_opacity; GtkSpinButton *w_update_interval, *w_monitoring_duration, - *w_s_update_interval; + *w_s_update_interval, *w_slog_interval; GtkComboBox *w_sensorlist_pos; GtkToggleButton *w_hide_window_decoration, *w_keep_window_below, *w_enable_menu, *w_enable_launcher_counter, *w_hide_on_startup, - *w_win_restore; + *w_win_restore, *w_slog_enabled, *w_autostart; + GtkComboBoxText *w_temp_unit; + GtkEntry *w_notif_script; + char *notif_script; cfg = ui->config; @@ -65,25 +68,33 @@ void ui_pref_dialog_run(struct ui_psensor *ui) &error); if (!ok) { - g_warning("%s", error->message); + log_printf(LOG_ERR, error->message); g_error_free(error); - return ; + return; } diag = GTK_DIALOG(gtk_builder_get_object(builder, "dialog1")); - color_fg = color_to_gdkcolor(cfg->graph_fgcolor); - w_color_fg = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, - "color_fg")); - gtk_color_button_set_color(w_color_fg, color_fg); + w_notif_script = GTK_ENTRY(gtk_builder_get_object(builder, + "notif_script")); + notif_script = config_get_notif_script(); + if (notif_script) { + gtk_entry_set_text(GTK_ENTRY(w_notif_script), notif_script); + free(notif_script); + } + + color_fg = color_to_GdkRGBA(cfg->graph_fgcolor); + w_color_fg = GTK_COLOR_CHOOSER(gtk_builder_get_object(builder, + "color_fg")); + gtk_color_chooser_set_rgba(w_color_fg, &color_fg); - color_bg = color_to_gdkcolor(cfg->graph_bgcolor); - w_color_bg = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, + color_bg = color_to_GdkRGBA(cfg->graph_bgcolor); + w_color_bg = GTK_COLOR_CHOOSER(gtk_builder_get_object(builder, "color_bg")); - gtk_color_button_set_color(w_color_bg, color_bg); + gtk_color_chooser_set_rgba(w_color_bg, &color_bg); - w_bg_opacity = GTK_HSCALE(gtk_builder_get_object(builder, - "bg_opacity")); + w_bg_opacity = GTK_SCALE(gtk_builder_get_object(builder, + "bg_opacity")); gtk_range_set_value(GTK_RANGE(w_bg_opacity), cfg->graph_bg_alpha); w_update_interval = GTK_SPIN_BUTTON(gtk_builder_get_object @@ -117,6 +128,10 @@ void ui_pref_dialog_run(struct ui_psensor *ui) gtk_toggle_button_set_active(w_keep_window_below, cfg->window_keep_below_enabled); + w_autostart = GTK_TOGGLE_BUTTON + (gtk_builder_get_object(builder, "autostart")); + gtk_toggle_button_set_active(w_autostart, pxdg_is_autostarted()); + w_enable_menu = GTK_TOGGLE_BUTTON (gtk_builder_get_object(builder, "enable_menu")); gtk_toggle_button_set_active(w_enable_menu, !cfg->menu_bar_disabled); @@ -126,6 +141,14 @@ void ui_pref_dialog_run(struct ui_psensor *ui) gtk_toggle_button_set_active(w_enable_launcher_counter, !cfg->unity_launcher_count_disabled); + w_slog_enabled = GTK_TOGGLE_BUTTON + (gtk_builder_get_object(builder, "enable_slog")); + gtk_toggle_button_set_active(w_slog_enabled, cfg->slog_enabled); + + w_slog_interval = GTK_SPIN_BUTTON + (gtk_builder_get_object(builder, "slog_interval")); + gtk_spin_button_set_value(w_slog_interval, cfg->slog_interval); + w_hide_on_startup = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "hide_on_startup")); @@ -137,21 +160,34 @@ void ui_pref_dialog_run(struct ui_psensor *ui) gtk_toggle_button_set_active(w_win_restore, cfg->window_restore_enabled); + w_temp_unit + = GTK_COMBO_BOX_TEXT(gtk_builder_get_object + (builder, "temperature_unit")); + gtk_combo_box_set_active(GTK_COMBO_BOX(w_temp_unit), + cfg->temperature_unit); + result = gtk_dialog_run(diag); if (result == GTK_RESPONSE_ACCEPT) { double value; - GdkColor color; + GdkRGBA color; - g_mutex_lock(ui->sensors_mutex); + pthread_mutex_lock(&ui->sensors_mutex); - gtk_color_button_get_color(w_color_fg, &color); + config_set_notif_script + (gtk_entry_get_text(GTK_ENTRY(w_notif_script))); + + gtk_color_chooser_get_rgba(w_color_fg, &color); color_set(cfg->graph_fgcolor, - color.red, color.green, color.blue); + color.red, + color.green, + color.blue); - gtk_color_button_get_color(w_color_bg, &color); + gtk_color_chooser_get_rgba(w_color_bg, &color); color_set(cfg->graph_bgcolor, - color.red, color.green, color.blue); + color.red, + color.green, + color.blue); value = gtk_range_get_value(GTK_RANGE(w_bg_opacity)); cfg->graph_bg_alpha = value; @@ -203,9 +239,20 @@ void ui_pref_dialog_run(struct ui_psensor *ui) cfg->window_restore_enabled = gtk_toggle_button_get_active(w_win_restore); + cfg->slog_enabled + = gtk_toggle_button_get_active(w_slog_enabled); + + cfg->slog_interval + = gtk_spin_button_get_value_as_int(w_slog_interval); + + cfg->temperature_unit + = gtk_combo_box_get_active(GTK_COMBO_BOX(w_temp_unit)); + config_save(cfg); - g_mutex_unlock(ui->sensors_mutex); + pxdg_set_autostart(gtk_toggle_button_get_active(w_autostart)); + + pthread_mutex_unlock(&ui->sensors_mutex); ui_window_update(ui); }