From 36309af730e239289925ea5701edf9ec8452bae3 Mon Sep 17 00:00:00 2001 From: rbuj Date: Sat, 18 Jul 2020 19:06:21 +0200 Subject: battstat: Rewrite preference dialog from scratch To manage the settings stored by GSettings. The preference dialog is a subclass of GtkDialog, and the ui file is a template. There is more info available in the "GTK+ Overview" chapter of "GTK+ 3 Reference Manual": "Building applications - A preference dialog" https://developer.gnome.org/gtk3/stable/ch01s04.html --- battstat/Makefile.am | 89 ++++---- battstat/battstat-preferences.c | 343 +++++++++++++++++++++++++++++ battstat/battstat-preferences.h | 39 ++++ battstat/battstat-preferences.ui | 335 +++++++++++++++++++++++++++++ battstat/battstat-resources.gresource.xml | 7 + battstat/battstat.h | 16 +- battstat/battstat_applet.c | 45 ++-- battstat/battstat_applet.ui | 345 ------------------------------ battstat/properties.c | 338 ----------------------------- po/POTFILES.in | 4 +- 10 files changed, 809 insertions(+), 752 deletions(-) create mode 100644 battstat/battstat-preferences.c create mode 100644 battstat/battstat-preferences.h create mode 100644 battstat/battstat-preferences.ui create mode 100644 battstat/battstat-resources.gresource.xml delete mode 100644 battstat/battstat_applet.ui delete mode 100644 battstat/properties.c diff --git a/battstat/Makefile.am b/battstat/Makefile.am index 35ed3aa9..7606ab4d 100644 --- a/battstat/Makefile.am +++ b/battstat/Makefile.am @@ -1,5 +1,4 @@ - -builder_DATA = battstat_applet.ui +NULL = ACPIINC= @ACPIINC@ @@ -7,7 +6,7 @@ if NEED_LIBAPM if HAVE_LIBAPM APMLIB = -lapm APMDIR = -APMINC = +APMINC = else APMLIB = apmlib/libapm.a APMDIR = apmlib @@ -16,7 +15,7 @@ endif else APMLIB = APMDIR = -APMINC = +APMINC = endif SUBDIRS = docs sounds $(APMDIR) @@ -31,31 +30,40 @@ AM_CPPFLAGS = \ $(APMINC) \ $(ACPIINC) \ -DG_LOG_DOMAIN=\"battstat_applet\" \ - -DBATTSTAT_MENU_UI_DIR=\""$(uidir)"\" - + -DBATTSTAT_RESOURCE_PATH=\""/org/mate/mate-applets/battstat/"\" \ + $(NULL) libexec_PROGRAMS = battstat-applet - -battstat_applet_SOURCES = \ - battstat.h \ - properties.c \ - battstat_applet.c \ - power-management.c \ - acpi-linux.c \ - acpi-linux.h \ - acpi-freebsd.c \ - acpi-freebsd.h \ - battstat-upower.c \ - battstat-upower.h - - -battstat_applet_LDADD = \ - $(MATE_APPLETS4_LIBS) \ - $(LIBNOTIFY_LIBS) \ - $(APMLIB) \ - $(UPOWER_LIBS) \ - -lm +BUILT_SOURCES = battstat-resources.c battstat-resources.h +nodist_battstat_applet_SOURCES = $(BUILT_SOURCES) +battstat_applet_SOURCES = \ + battstat.h \ + battstat_applet.c \ + battstat-preferences.c \ + battstat-preferences.h \ + power-management.c \ + acpi-linux.c \ + acpi-linux.h \ + acpi-freebsd.c \ + acpi-freebsd.h \ + battstat-upower.c \ + battstat-upower.h \ + $(NULL) + +battstat_applet_LDADD = \ + $(MATE_APPLETS4_LIBS) \ + $(LIBNOTIFY_LIBS) \ + $(APMLIB) \ + $(UPOWER_LIBS) \ + -lm \ + $(NULL) + +battstat-resources.c: battstat-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/battstat-resources.gresource.xml) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name battstat $< + +battstat-resources.h: battstat-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/battstat-resources.gresource.xml) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name battstat $< batstat_gschema_in_files = org.mate.panel.applet.battstat.gschema.xml.in gsettings_SCHEMAS = $(batstat_gschema_in_files:.xml.in=.xml) @@ -83,17 +91,22 @@ org.mate.panel.applet.BattstatAppletFactory.service: $(service_in_files) -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ $< > $@ -CLEANFILES = $(applet_DATA) $(applet_in_files) $(service_DATA) $(gsettings_SCHEMAS) *.gschema.valid - -uidir = $(datadir)/mate/ui -ui_DATA = battstat-applet-menu.xml - -EXTRA_DIST = \ - $(builder_DATA) \ - $(ui_DATA) \ - $(applet_in_files).in \ - $(service_in_files) \ - $(batstat_gschema_in_files) - +CLEANFILES = \ + $(applet_DATA) \ + $(applet_in_files) \ + $(service_DATA) \ + $(gsettings_SCHEMAS) \ + $(BUILT_SOURCES) \ + *.gschema.valid \ + $(NULL) + +EXTRA_DIST = \ + battstat-applet-menu.xml \ + battstat-preferences.ui \ + battstat-resources.gresource.xml \ + $(applet_in_files).in \ + $(service_in_files) \ + $(batstat_gschema_in_files) \ + $(NULL) -include $(top_srcdir)/git.mk diff --git a/battstat/battstat-preferences.c b/battstat/battstat-preferences.c new file mode 100644 index 00000000..40d38f42 --- /dev/null +++ b/battstat/battstat-preferences.c @@ -0,0 +1,343 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */ +/* battstat A MATE battery meter for laptops. + * Copyright (C) 2000 by Jörgen Pehrson + * + * 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. + * + $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include +#ifdef HAVE_SYS_SYSCTL_H +#include +#endif + +#ifdef HAVE_ERR_H +#include +#endif +#include +#include +#include +#include + +#include + +#include + +#include "battstat-preferences.h" + +enum { + PROP_0, + PROP_PROGRESS_DATA +}; + +struct _BattstatPreferences +{ + GtkDialog parent; + + GtkWidget *radio_text_1; + GtkWidget *radio_text_2; + GtkWidget *check_text; + GtkWidget *check_text_ptr; + GtkWidget *lowbatt_toggle; + GtkWidget *full_toggle; + GtkWidget *hbox_ptr; + GtkWidget *combo_ptr; + GtkWidget *spin_ptr; + + ProgressData *battstat; +}; + +G_DEFINE_TYPE (BattstatPreferences, battstat_preferences, GTK_TYPE_DIALOG); + +static void +combo_ptr_cb (GtkWidget *combo_ptr, + gpointer data) +{ + BattstatPreferences *dialog = data; + + if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo_ptr))) + dialog->battstat->red_value_is_time = TRUE; + else + dialog->battstat->red_value_is_time = FALSE; + + g_settings_set_boolean (dialog->battstat->settings, + "red-value-is-time", + dialog->battstat->red_value_is_time); +} + +static void +spin_ptr_cb (GtkWidget *spin_ptr, + gpointer data) +{ + BattstatPreferences *dialog = data; + + dialog->battstat->red_val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin_ptr)); + /* automatically calculate orangle and yellow values from the + * red value + */ + dialog->battstat->orange_val = dialog->battstat->red_val * ORANGE_MULTIPLIER; + dialog->battstat->orange_val = MIN (dialog->battstat->orange_val, 100); + + dialog->battstat->yellow_val = dialog->battstat->red_val * YELLOW_MULTIPLIER; + dialog->battstat->yellow_val = MIN (dialog->battstat->yellow_val, 100); + + g_settings_set_int (dialog->battstat->settings, + "red-value", + dialog->battstat->red_val); +} + +static void +show_text_toggled (GtkToggleButton *button, + gpointer data) +{ + BattstatPreferences *dialog = data; + gboolean show_text_active; + + show_text_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->check_text)); + if (show_text_active) { + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radio_text_1))) + dialog->battstat->showtext = APPLET_SHOW_TIME; + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radio_text_2))) + dialog->battstat->showtext = APPLET_SHOW_PERCENT; + else + dialog->battstat->showtext = APPLET_SHOW_NONE; + } else { + dialog->battstat->showtext = APPLET_SHOW_NONE; + } + + dialog->battstat->refresh_label = TRUE; + + reconfigure_layout (dialog->battstat); + + g_settings_set_int (dialog->battstat->settings, + "show-text", + dialog->battstat->showtext); +} + +static void +lowbatt_toggled (GtkToggleButton *button, + gpointer data) +{ + BattstatPreferences *dialog = data; + + dialog->battstat->lowbattnotification = gtk_toggle_button_get_active (button); +} + +static void +full_toggled (GtkToggleButton *button, + gpointer data) +{ + BattstatPreferences *dialog = data; + + dialog->battstat->fullbattnot = gtk_toggle_button_get_active (button); +} + +static void +response_cb (GtkDialog *dialog, + gint id, + gpointer data) +{ + BattstatPreferences *self = data; + + if (id == GTK_RESPONSE_HELP) + battstat_show_help (self->battstat, "battstat-appearance"); + else + gtk_widget_hide (GTK_WIDGET (dialog)); +} + +static void +battstat_preferences_update (BattstatPreferences *dialog) +{ + gboolean check_text_active = TRUE; + + if (!g_settings_is_writable (dialog->battstat->settings, "low-battery-notification")) { + gtk_widget_set_sensitive (dialog->lowbatt_toggle, FALSE); + } + + gtk_widget_set_sensitive (dialog->hbox_ptr, dialog->battstat->lowbattnotification); + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->spin_ptr), dialog->battstat->red_val); + + if (dialog->battstat->red_value_is_time) + gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combo_ptr), 1); + else + gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combo_ptr), 0); + + if (!g_settings_is_writable (dialog->battstat->settings, "full-battery-notification")) + gtk_widget_set_sensitive (dialog->full_toggle, FALSE); + + if (dialog->battstat->fullbattnot) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->full_toggle), TRUE); + + if (dialog->battstat->lowbattnotification) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->lowbatt_toggle), TRUE); + + if (!g_settings_is_writable (dialog->battstat->settings, "show-text")) + { + gtk_widget_set_sensitive (dialog->check_text, FALSE); + check_text_active = FALSE; + } + switch (dialog->battstat->showtext) { + case APPLET_SHOW_PERCENT: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->check_text), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radio_text_2), TRUE); + break; + case APPLET_SHOW_TIME: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->check_text), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radio_text_1), TRUE); + break; + case APPLET_SHOW_NONE: + default: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->check_text), FALSE); + check_text_active = FALSE; + } + gtk_widget_set_sensitive (dialog->check_text_ptr, check_text_active); +} + +static void +battstat_preferences_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + BattstatPreferences *dialog; + + dialog = BATTSTAT_PREFERENCES (object); + + switch (prop_id) { + case PROP_PROGRESS_DATA: + dialog->battstat = g_value_get_pointer (value); + break; + default: + /* We don't have any other property... */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +battstat_preferences_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + BattstatPreferences *dialog; + + dialog = BATTSTAT_PREFERENCES (object); + + switch (prop_id) { + case PROP_PROGRESS_DATA: + g_value_set_pointer (value, dialog->battstat); + break; + default: + /* We don't have any other property... */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +battstat_preferences_init (BattstatPreferences *dialog) +{ + gtk_widget_init_template (GTK_WIDGET (dialog)); + + g_object_bind_property (dialog->check_text, "active", + dialog->check_text_ptr, "sensitive", + G_BINDING_DEFAULT); + + g_object_bind_property (dialog->lowbatt_toggle, "active", + dialog->hbox_ptr, "sensitive", + G_BINDING_DEFAULT); +} + +static GObject* +battstat_preferences_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + BattstatPreferences *self; + + object = G_OBJECT_CLASS (battstat_preferences_parent_class)-> + constructor (type, n_construct_params, construct_params); + self = BATTSTAT_PREFERENCES (object); + + battstat_preferences_update (self); + + g_settings_bind (self->battstat->settings, "low-battery-notification", + self->lowbatt_toggle, "active", + G_SETTINGS_BIND_DEFAULT); + + g_settings_bind (self->battstat->settings, "full-battery-notification", + self->full_toggle, "active", + G_SETTINGS_BIND_DEFAULT); + + return object; +} + +GtkWidget* +battstat_preferences_new (ProgressData *battstat) +{ + return g_object_new (BATTSTAT_TYPE_PREFERENCES, + "progress-data", battstat, + NULL); +} + +static void +battstat_preferences_class_init (BattstatPreferencesClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->set_property = battstat_preferences_set_property; + object_class->get_property = battstat_preferences_get_property; + object_class->constructor = battstat_preferences_constructor; + + g_object_class_install_property (object_class, + PROP_PROGRESS_DATA, + g_param_spec_pointer ("progress-data", + "Progress Data", + "The Progress Data", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + gtk_widget_class_set_template_from_resource (widget_class, + BATTSTAT_RESOURCE_PATH "battstat-preferences.ui"); + + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, check_text); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, check_text_ptr); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, radio_text_1); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, radio_text_2); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, lowbatt_toggle); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, full_toggle); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, hbox_ptr); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, combo_ptr); + gtk_widget_class_bind_template_child (widget_class, BattstatPreferences, spin_ptr); + + gtk_widget_class_bind_template_callback (widget_class, lowbatt_toggled); + gtk_widget_class_bind_template_callback (widget_class, combo_ptr_cb); + gtk_widget_class_bind_template_callback (widget_class, spin_ptr_cb); + gtk_widget_class_bind_template_callback (widget_class, full_toggled); + gtk_widget_class_bind_template_callback (widget_class, show_text_toggled); + gtk_widget_class_bind_template_callback (widget_class, response_cb); +} diff --git a/battstat/battstat-preferences.h b/battstat/battstat-preferences.h new file mode 100644 index 00000000..d3cc882d --- /dev/null +++ b/battstat/battstat-preferences.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */ +/* battstat A MATE battery meter for laptops. + * Copyright (C) 2000 by Jörgen Pehrson + * + * 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. + * + $Id$ + */ + +#ifndef __BATTSTAT_PREFERENCES_H__ +#define __BATTSTAT_PREFERENCES_H__ + +#include + +#include "battstat.h" + +G_BEGIN_DECLS + +#define BATTSTAT_TYPE_PREFERENCES battstat_preferences_get_type () +G_DECLARE_FINAL_TYPE (BattstatPreferences, battstat_preferences, + BATTSTAT, PREFERENCES, GtkDialog) + +GtkWidget *battstat_preferences_new (ProgressData *battstat); + +G_END_DECLS + +#endif /* __BATTSTAT_PREFERENCES_H__ */ diff --git a/battstat/battstat-preferences.ui b/battstat/battstat-preferences.ui new file mode 100644 index 00000000..424f0b9c --- /dev/null +++ b/battstat/battstat-preferences.ui @@ -0,0 +1,335 @@ + + + + + + 25 + 1 + 5 + + + True + False + window-close + + + True + False + help-browser + + + diff --git a/battstat/battstat-resources.gresource.xml b/battstat/battstat-resources.gresource.xml new file mode 100644 index 00000000..8be5403e --- /dev/null +++ b/battstat/battstat-resources.gresource.xml @@ -0,0 +1,7 @@ + + + + battstat-applet-menu.xml + battstat-preferences.ui + + diff --git a/battstat/battstat.h b/battstat/battstat.h index 9e45e56b..d0d4e402 100644 --- a/battstat/battstat.h +++ b/battstat/battstat.h @@ -41,7 +41,7 @@ typedef enum { - APPLET_SHOW_NONE, + APPLET_SHOW_NONE = 0, APPLET_SHOW_PERCENT, APPLET_SHOW_TIME } AppletTextType; @@ -87,14 +87,6 @@ typedef struct typedef struct _ProgressData { GtkWidget *applet; - /* these are used by properties.c */ - GtkWidget *radio_text_1; - GtkWidget *radio_text_2; - GtkWidget *check_text; - GtkWidget *lowbatt_toggle; - GtkWidget *full_toggle; - GtkWidget *hbox_ptr; - /* flags set from gsettings or the properties dialog */ GSettings *settings; guint red_val; @@ -118,7 +110,7 @@ typedef struct _ProgressData { GtkWidget *percent; /* dialog boxes that might be displayed */ - GtkDialog *prop_win; + GtkWidget *prop_win; GtkWidget *battery_low_dialog; /* text label inside the low battery dialog */ @@ -149,12 +141,10 @@ typedef struct _ProgressData { gboolean last_present; } ProgressData; -/* properties.c */ -void prop_cb (GtkAction *, ProgressData *); - /* battstat_applet.c */ void reconfigure_layout( ProgressData *battstat ); void battstat_show_help( ProgressData *battstat, const char *section ); +void prop_cb (GtkAction *, ProgressData *); /* power-management.c */ const char *power_management_getinfo( BatteryStatus *status ); diff --git a/battstat/battstat_applet.c b/battstat/battstat_applet.c index e951c71c..16755717 100644 --- a/battstat/battstat_applet.c +++ b/battstat/battstat_applet.c @@ -45,10 +45,7 @@ #endif #include "battstat.h" - -#ifndef gettext_noop -#define gettext_noop(String) (String) -#endif +#include "battstat-preferences.h" #define BATTSTAT_SCHEMA "org.mate.panel.applet.battstat" @@ -759,7 +756,8 @@ destroy_applet( GtkWidget *widget, ProgressData *battstat ) * button in the preferences dialog. */ void -battstat_show_help( ProgressData *battstat, const char *section ) +battstat_show_help (ProgressData *battstat, + const char *section) { GError *error = NULL; char *uri; @@ -770,21 +768,21 @@ battstat_show_help( ProgressData *battstat, const char *section ) uri = g_strdup ("help:mate-battstat"); gtk_show_uri_on_window (NULL, - uri, - gtk_get_current_event_time (), - &error); + uri, + gtk_get_current_event_time (), + &error); g_free (uri); - if( error ) + if (error) { char *message; - message = g_strdup_printf( _("There was an error displaying help: %s"), + message = g_strdup_printf (_("There was an error displaying help: %s"), error->message ); - battstat_error_dialog( battstat->applet, message ); - g_error_free( error ); - g_free( message ); + battstat_error_dialog (battstat->applet, message); + g_error_free (error); + g_free (message); } } @@ -1098,6 +1096,20 @@ create_layout(ProgressData *battstat) return FALSE; } +void +prop_cb (GtkAction *action, + ProgressData *battstat) +{ + if (battstat->prop_win) { + gtk_window_set_screen (GTK_WINDOW (battstat->prop_win), + gtk_widget_get_screen (battstat->applet)); + gtk_window_present (GTK_WINDOW (battstat->prop_win)); + } else { + battstat->prop_win = battstat_preferences_new (battstat); + gtk_widget_show_all (GTK_WIDGET (battstat->prop_win)); + } +} + /* Called by the factory to fill in the fields for the applet. */ static gboolean @@ -1145,9 +1157,10 @@ battstat_applet_fill (MatePanelApplet *applet) battstat_menu_actions, G_N_ELEMENTS (battstat_menu_actions), battstat); - mate_panel_applet_setup_menu_from_file (MATE_PANEL_APPLET (battstat->applet), - BATTSTAT_MENU_UI_DIR G_DIR_SEPARATOR_S "battstat-applet-menu.xml", - action_group); + + mate_panel_applet_setup_menu_from_resource (MATE_PANEL_APPLET (battstat->applet), + BATTSTAT_RESOURCE_PATH "battstat-applet-menu.xml", + action_group); if (mate_panel_applet_get_locked_down (MATE_PANEL_APPLET (battstat->applet))) { GtkAction *action; diff --git a/battstat/battstat_applet.ui b/battstat/battstat_applet.ui deleted file mode 100644 index 5b892502..00000000 --- a/battstat/battstat_applet.ui +++ /dev/null @@ -1,345 +0,0 @@ - - - - - - 1 - 1 - 25 - 1 - 5 - - - 5 - Battery Charge Monitor Preferences - dialog - - - True - 2 - - - True - 5 - 18 - - - True - 6 - - - True - 0 - Appearance - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - 12 - - - True - 6 - - - _Show time/percentage: - True - True - False - True - True - True - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - 6 - - - Show _time remaining - True - True - False - True - True - - - False - False - 0 - - - - - Show _percentage remaining - True - True - False - True - True - show_text_radio - - - False - False - 1 - - - - - 1 - - - - - 1 - - - - - 1 - - - - - False - False - 1 - - - - - False - False - 1 - - - - - False - False - 0 - - - - - True - 6 - - - True - 0 - Notifications - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - 6 - - - _Warn when battery charge drops to: - True - True - False - True - True - - - False - False - 0 - - - - - True - 5 - - - True - - - - False - False - 0 - - - - - True - True - adjustment1 - 1 - - - False - False - 1 - - - - - True - - - 2 - - - - - 1 - - - - - _Notify when battery is fully recharged - True - True - False - True - True - - - False - False - 2 - - - - - 1 - - - - - 1 - - - - - False - False - 1 - - - - - 1 - - - - - True - end - - - gtk-help - True - True - True - False - True - - - False - False - 0 - - - - - gtk-close - True - True - True - False - True - - - False - False - 1 - - - - - False - end - 0 - - - - - - button1 - button2 - - - diff --git a/battstat/properties.c b/battstat/properties.c deleted file mode 100644 index b2b6db62..00000000 --- a/battstat/properties.c +++ /dev/null @@ -1,338 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */ -/* battstat A MATE battery meter for laptops. - * Copyright (C) 2000 by Jörgen Pehrson - * - * 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. - * - $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include -#include -#ifdef HAVE_SYS_SYSCTL_H -#include -#endif - -#ifdef HAVE_ERR_H -#include -#endif -#include -#include -#include -#include - -#include - -#include - -#include "battstat.h" - -#ifndef gettext_noop -#define gettext_noop(String) (String) -#endif - -#define NEVER_SENSITIVE "never_sensitive" - -/* set sensitive and setup NEVER_SENSITIVE appropriately */ -static void -hard_set_sensitive (GtkWidget *w, gboolean sensitivity) -{ - gtk_widget_set_sensitive (w, sensitivity); - g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE, - GINT_TO_POINTER ( ! sensitivity)); -} - - -#if 0 -/* set sensitive, but always insensitive if NEVER_SENSITIVE is set */ -static void -soft_set_sensitive (GtkWidget *w, gboolean sensitivity) -{ - if (g_object_get_data (G_OBJECT (w), NEVER_SENSITIVE)) - gtk_widget_set_sensitive (w, FALSE); - else - gtk_widget_set_sensitive (w, sensitivity); -} -#endif /* 0 */ - -static void -combo_ptr_cb (GtkWidget *combo_ptr, gpointer data) -{ - ProgressData *battstat = data; - - if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo_ptr))) - battstat->red_value_is_time = TRUE; - else - battstat->red_value_is_time = FALSE; - - g_settings_set_boolean (battstat->settings, - "red-value-is-time", - battstat->red_value_is_time); -} - -static void -spin_ptr_cb (GtkWidget *spin_ptr, gpointer data) -{ - ProgressData *battstat = data; - - battstat->red_val = gtk_spin_button_get_value_as_int ( - GTK_SPIN_BUTTON (spin_ptr)); - /* automatically calculate orangle and yellow values from the - * red value - */ - battstat->orange_val = battstat->red_val * ORANGE_MULTIPLIER; - battstat->orange_val = CLAMP (battstat->orange_val, 0, 100); - - battstat->yellow_val = battstat->red_val * YELLOW_MULTIPLIER; - battstat->yellow_val = CLAMP (battstat->yellow_val, 0, 100); - - g_settings_set_int (battstat->settings, - "red-value", - battstat->red_val); -} - -static void -show_text_toggled (GtkToggleButton *button, gpointer data) -{ - ProgressData *battstat = data; - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (battstat->radio_text_2)) - && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (battstat->check_text))) - battstat->showtext = APPLET_SHOW_PERCENT; - else if (gtk_toggle_button_get_active ( - GTK_TOGGLE_BUTTON (battstat->radio_text_1)) && - gtk_toggle_button_get_active ( - GTK_TOGGLE_BUTTON (battstat->check_text))) - battstat->showtext = APPLET_SHOW_TIME; - else - battstat->showtext = APPLET_SHOW_NONE; - - battstat->refresh_label = TRUE; - - reconfigure_layout( battstat ); - - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_1), - battstat->showtext); - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_2), - battstat->showtext); - - g_settings_set_int (battstat->settings, "show-text", battstat->showtext); -} - -static void -lowbatt_toggled (GtkToggleButton *button, gpointer data) -{ - ProgressData *battstat = data; - - battstat->lowbattnotification = gtk_toggle_button_get_active (button); - g_settings_set_boolean (battstat->settings, "low-battery-notification", - battstat->lowbattnotification); - - hard_set_sensitive (battstat->hbox_ptr, battstat->lowbattnotification); -} - -static void -full_toggled (GtkToggleButton *button, gpointer data) -{ - ProgressData *battstat = data; - - battstat->fullbattnot = gtk_toggle_button_get_active (button); - g_settings_set_boolean (battstat->settings, "full-battery-notification", - battstat->fullbattnot); -} - -static void -response_cb (GtkDialog *dialog, gint id, gpointer data) -{ - ProgressData *battstat = data; - - if (id == GTK_RESPONSE_HELP) - battstat_show_help (battstat, "battstat-appearance"); - else - gtk_widget_hide (GTK_WIDGET (battstat->prop_win)); -} - -void -prop_cb (GtkAction *action, - ProgressData *battstat) -{ - GtkBuilder *builder; - GtkWidget *combo_ptr, *spin_ptr; - GtkListStore *liststore; - GtkCellRenderer *renderer; - GtkTreeIter iter; - - if (DEBUG) g_print("prop_cb()\n"); - - if (battstat->prop_win) { - gtk_window_set_screen (GTK_WINDOW (battstat->prop_win), - gtk_widget_get_screen (battstat->applet)); - gtk_window_present (GTK_WINDOW (battstat->prop_win)); - return; - } - - builder = gtk_builder_new (); - gtk_builder_add_from_file (builder, GTK_BUILDERDIR"/battstat_applet.ui", NULL); - - battstat->prop_win = GTK_DIALOG (gtk_builder_get_object (builder, - "battstat_properties")); - gtk_window_set_screen (GTK_WINDOW (battstat->prop_win), - gtk_widget_get_screen (battstat->applet)); - - g_signal_connect (G_OBJECT (battstat->prop_win), "delete_event", - G_CALLBACK (gtk_true), NULL); - - battstat->lowbatt_toggle = GTK_WIDGET (gtk_builder_get_object (builder, "lowbatt_toggle")); - g_signal_connect (G_OBJECT (battstat->lowbatt_toggle), "toggled", - G_CALLBACK (lowbatt_toggled), battstat); - - if (!g_settings_is_writable (battstat->settings, - "low-battery-notification")) - { - hard_set_sensitive (battstat->lowbatt_toggle, FALSE); - } - - battstat->hbox_ptr = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_ptr")); - hard_set_sensitive (battstat->hbox_ptr, battstat->lowbattnotification); - - combo_ptr = GTK_WIDGET (gtk_builder_get_object (builder, "combo_ptr")); - g_signal_connect (G_OBJECT (combo_ptr), "changed", - G_CALLBACK (combo_ptr_cb), battstat); - - liststore = gtk_list_store_new (1, G_TYPE_STRING); - gtk_combo_box_set_model (GTK_COMBO_BOX (combo_ptr), - GTK_TREE_MODEL (liststore)); - gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_ptr)); - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_ptr), - renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_ptr), - renderer, - "text", 0, - NULL); - gtk_list_store_append (liststore, &iter); - /* TRANSLATOR: this is a selectable item in a drop-down menu to end - * this sentence: - * "Warn when battery charge drops to: [XX] percent". - */ - gtk_list_store_set (liststore, &iter, 0, _("Percent"), -1); - gtk_list_store_append (liststore, &iter); - /* TRANSLATOR: this is a selectable item in a drop-down menu to end - * this sentence: - * "Warn when battery charge drops to: [XX] minutes remaining" - */ - gtk_list_store_set (liststore, &iter, 0, _("Minutes Remaining"), -1); - - spin_ptr = GTK_WIDGET (gtk_builder_get_object (builder, "spin_ptr")); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_ptr), - battstat->red_val); - g_signal_connect (G_OBJECT (spin_ptr), "value-changed", - G_CALLBACK (spin_ptr_cb), battstat); - - if (battstat->red_value_is_time) - gtk_combo_box_set_active (GTK_COMBO_BOX (combo_ptr), 1); - else - gtk_combo_box_set_active (GTK_COMBO_BOX (combo_ptr), 0); - - battstat->full_toggle = GTK_WIDGET (gtk_builder_get_object (builder, "full_toggle")); - g_signal_connect (G_OBJECT (battstat->full_toggle), "toggled", - G_CALLBACK (full_toggled), battstat); - - if (!g_settings_is_writable (battstat->settings, - "full-battery-notification")) - { - hard_set_sensitive (battstat->full_toggle, FALSE); - } - if (battstat->fullbattnot) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (battstat->full_toggle), - TRUE); - } - if (battstat->lowbattnotification) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (battstat->lowbatt_toggle), - TRUE); - } - - battstat->radio_text_1 = GTK_WIDGET (gtk_builder_get_object (builder, "show_text_radio")); - battstat->radio_text_2 = GTK_WIDGET (gtk_builder_get_object (builder, - "show_text_radio_2")); - battstat->check_text = GTK_WIDGET (gtk_builder_get_object (builder, - "show_text_remaining")); - - g_object_unref (builder); - - g_signal_connect (G_OBJECT (battstat->radio_text_1), "toggled", - G_CALLBACK (show_text_toggled), battstat); - g_signal_connect (G_OBJECT (battstat->radio_text_2), "toggled", - G_CALLBACK (show_text_toggled), battstat); - g_signal_connect (G_OBJECT (battstat->check_text), "toggled", - G_CALLBACK (show_text_toggled), battstat); - - if (!g_settings_is_writable (battstat->settings, "show-text")) - { - hard_set_sensitive (battstat->check_text, FALSE); - hard_set_sensitive (battstat->radio_text_1, FALSE); - hard_set_sensitive (battstat->radio_text_2, FALSE); - } - - if (battstat->showtext == APPLET_SHOW_PERCENT) - { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (battstat->check_text), TRUE); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (battstat->radio_text_2), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_1), - TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_2), - TRUE); - } - else if (battstat->showtext == APPLET_SHOW_TIME) - { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (battstat->check_text), - TRUE); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (battstat->radio_text_1), - TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_1), - TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_2), - TRUE); - } - else /* APPLET_SHOW_NONE */ - { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (battstat->check_text), FALSE); - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_1), - FALSE); - gtk_widget_set_sensitive (GTK_WIDGET (battstat->radio_text_2), - FALSE); - } - - gtk_dialog_set_default_response (GTK_DIALOG (battstat->prop_win), - GTK_RESPONSE_CLOSE); - gtk_window_set_resizable (GTK_WINDOW (battstat->prop_win), FALSE); - g_signal_connect (G_OBJECT (battstat->prop_win), "response", - G_CALLBACK (response_cb), battstat); - gtk_widget_show_all (GTK_WIDGET (battstat->prop_win)); -} diff --git a/po/POTFILES.in b/po/POTFILES.in index d2fc5000..4c140cc9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,10 +4,10 @@ accessx-status/applet.c accessx-status/org.mate.applets.AccessxStatusApplet.mate-panel-applet.desktop.in.in battstat/battstat_applet.c -battstat/battstat_applet.ui +battstat/battstat-preferences.c +battstat/battstat-preferences.ui battstat/org.mate.applets.BattstatApplet.mate-panel-applet.desktop.in.in battstat/org.mate.panel.applet.battstat.gschema.xml.in -battstat/properties.c battstat/sounds/mate-battstat_applet.soundlist.desktop.in charpick/charpick.c charpick/org.mate.applets.CharpickerApplet.mate-panel-applet.desktop.in.in -- cgit v1.2.1