summaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
authorrbuj <[email protected]>2021-12-16 23:39:00 +0100
committerLuke from DC <[email protected]>2021-12-19 11:24:23 +0000
commit440a9eef740e04821393c383c23d3937ea3bc28e (patch)
treefc59c93879572de3455d17682fbb535740c71e70 /applets
parenteefd98c9bd9965c9022316d1336d914bfb1063ed (diff)
downloadmate-panel-440a9eef740e04821393c383c23d3937ea3bc28e.tar.bz2
mate-panel-440a9eef740e04821393c383c23d3937ea3bc28e.tar.xz
clock: simplify temperature_unit_changed and speed_unit_changed
Diffstat (limited to 'applets')
-rw-r--r--applets/clock/clock.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index f806a387..5383ca92 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -2322,23 +2322,25 @@ clock_timezone_changed (SystemTimezone *systz,
refresh_click_timeout_time_only (cd);
}
+#define unit_combo_box_set_active(x,y) (gtk_combo_box_set_active (GTK_COMBO_BOX (gtk_builder_get_object (cd->builder, (x))), (y)))
+
static void
temperature_unit_changed (GSettings *settings,
gchar *key,
ClockData *cd)
{
- cd->temperature_unit = g_settings_get_enum (settings, key);
- if (cd->temperature_unit > 0)
- {
- GtkWidget *widget;
- int oldvalue;
+ TempUnit temperature_unit = g_settings_get_enum (settings, key);
- widget = _clock_get_widget (cd, "temperature_combo");
- oldvalue = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) + 2;
- if (((TempUnit) oldvalue) != cd->temperature_unit)
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget),
- cd->temperature_unit - 2);
- }
+ if (cd->temperature_unit == temperature_unit)
+ return;
+
+ /* TEMP_UNIT_INVALID = 0 */
+ if (temperature_unit == TEMP_UNIT_INVALID)
+ return;
+
+ unit_combo_box_set_active ("temperature_combo",
+ ((int) temperature_unit) - 2);
+ cd->temperature_unit = temperature_unit;
update_weather_locations (cd);
}
@@ -2347,19 +2349,18 @@ speed_unit_changed (GSettings *settings,
gchar *key,
ClockData *cd)
{
- cd->speed_unit = g_settings_get_enum (settings, key);
- if (cd->speed_unit > 0)
- {
- GtkWidget *widget;
- int oldvalue;
+ SpeedUnit speed_unit = g_settings_get_enum (settings, key);
+
+ if (cd->speed_unit == speed_unit)
+ return;
- widget = _clock_get_widget (cd, "wind_speed_combo");
- oldvalue = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) + 2;
+ /* SPEED_UNIT_INVALID = 0 */
+ if (speed_unit == SPEED_UNIT_INVALID)
+ return;
- if (((SpeedUnit) oldvalue) != cd->speed_unit)
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget),
- cd->speed_unit - 2);
- }
+ unit_combo_box_set_active ("wind_speed_combo",
+ ((int) speed_unit) - 2);
+ cd->speed_unit = speed_unit;
update_weather_locations (cd);
}