GCC Code Coverage Report


Directory: ./
File: panels/display/cc-night-light-page.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 331 0.0%
Functions: 0 34 0.0%
Branches: 0 113 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
3 *
4 * Licensed under the GNU General Public License Version 2
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include "config.h"
22
23 #include <gdesktop-enums.h>
24 #include <gtk/gtk.h>
25 #include <glib/gi18n.h>
26 #include <math.h>
27
28 #include "cc-night-light-page.h"
29
30 #include "shell/cc-object-storage.h"
31 #include "cc-hostname.h"
32 #include "cc-display-config-manager-dbus.h"
33
34 struct _CcNightLightPage {
35 AdwBin parent;
36
37 AdwViewStack *main_stack;
38 GtkWidget *night_light_settings;
39 GtkWidget *box_manual;
40 GtkButton *button_from_am;
41 GtkButton *button_from_pm;
42 GtkButton *button_to_am;
43 GtkButton *button_to_pm;
44 AdwStatusPage *night_light_unsupported_page;
45 GtkWidget *infobar_disabled;
46 GtkWidget *scale_color_temperature;
47 AdwSwitchRow *night_light_toggle_row;
48 AdwComboRow *schedule_type_row;
49 GtkWidget *from_spinbuttons_box;
50 GtkSpinButton *spinbutton_from_hours;
51 GtkSpinButton *spinbutton_from_minutes;
52 GtkWidget *to_spinbuttons_box;
53 GtkSpinButton *spinbutton_to_hours;
54 GtkSpinButton *spinbutton_to_minutes;
55 GtkStack *stack_from;
56 GtkStack *stack_to;
57
58 GtkAdjustment *adjustment_from_hours;
59 GtkAdjustment *adjustment_from_minutes;
60 GtkAdjustment *adjustment_to_hours;
61 GtkAdjustment *adjustment_to_minutes;
62 GtkAdjustment *adjustment_color_temperature;
63
64 GSettings *settings_display;
65 GSettings *settings_clock;
66 GDBusProxy *proxy_color;
67 GDBusProxy *proxy_color_props;
68 GCancellable *cancellable;
69 gboolean ignore_value_changed;
70 guint timer_id;
71 GDesktopClockFormat clock_format;
72
73 CcDisplayConfigManager *config_manager;
74 };
75
76 G_DEFINE_TYPE (CcNightLightPage, cc_night_light_page, ADW_TYPE_BIN);
77
78 #define CLOCK_SCHEMA "org.gnome.desktop.interface"
79 #define DISPLAY_SCHEMA "org.gnome.settings-daemon.plugins.color"
80 #define CLOCK_FORMAT_KEY "clock-format"
81 #define NIGHT_LIGHT_PREVIEW_TIMEOUT_SECONDS 5
82
83 static void
84 dialog_adjustments_set_frac_hours (CcNightLightPage *self,
85 gdouble value,
86 GtkAdjustment *adj_hours,
87 GtkAdjustment *adj_mins,
88 GtkStack *stack,
89 GtkButton *button_am,
90 GtkButton *button_pm)
91 {
92 gdouble hours;
93 gdouble mins = 0.f;
94 gboolean is_pm = FALSE;
95 gboolean is_24h;
96
97 /* display the right thing for AM/PM */
98 is_24h = self->clock_format == G_DESKTOP_CLOCK_FORMAT_24H;
99 mins = modf (value, &hours) * 60.f;
100 if (!is_24h)
101 {
102 if (hours > 12)
103 {
104 hours -= 12;
105 is_pm = TRUE;
106 }
107 else if (hours < 1.0)
108 {
109 hours += 12;
110 is_pm = FALSE;
111 }
112 else if (hours == 12.f)
113 {
114 is_pm = TRUE;
115 }
116 }
117
118 g_debug ("setting adjustment %.3f to %.0f:%02.0f", value, hours, mins);
119
120 self->ignore_value_changed = TRUE;
121 gtk_adjustment_set_value (GTK_ADJUSTMENT (adj_hours), hours);
122 gtk_adjustment_set_value (GTK_ADJUSTMENT (adj_mins), mins);
123 self->ignore_value_changed = FALSE;
124
125 gtk_widget_set_visible (GTK_WIDGET (stack), !is_24h);
126 gtk_stack_set_visible_child (stack, is_pm ? GTK_WIDGET (button_pm) : GTK_WIDGET (button_am));
127 }
128
129 static void
130 dialog_update_state (CcNightLightPage *self)
131 {
132 if (cc_display_config_manager_get_night_light_supported (self->config_manager))
133 {
134 gboolean automatic;
135 gboolean disabled_until_tomorrow = FALSE;
136 gboolean enabled;
137 gdouble value = 0.f;
138
139 /* only show the infobar if we are disabled */
140 if (self->proxy_color != NULL)
141 {
142 g_autoptr(GVariant) disabled = NULL;
143 disabled = g_dbus_proxy_get_cached_property (self->proxy_color,
144 "DisabledUntilTomorrow");
145 if (disabled != NULL)
146 disabled_until_tomorrow = g_variant_get_boolean (disabled);
147 }
148 gtk_widget_set_visible (self->infobar_disabled, disabled_until_tomorrow);
149
150 /* make things insensitive if the switch is disabled */
151 enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled");
152 automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
153
154 gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
155
156 adw_combo_row_set_selected (self->schedule_type_row, automatic ? 0 : 1);
157
158 /* set from */
159 if (automatic && self->proxy_color != NULL)
160 {
161 g_autoptr(GVariant) sunset = NULL;
162 sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunset");
163 if (sunset != NULL)
164 {
165 value = g_variant_get_double (sunset);
166 }
167 else
168 {
169 value = 16.0f;
170 g_warning ("no sunset data, using %02.2f", value);
171 }
172 }
173 else
174 {
175 value = g_settings_get_double (self->settings_display, "night-light-schedule-from");
176 value = fmod (value, 24.f);
177 }
178 dialog_adjustments_set_frac_hours (self, value,
179 self->adjustment_from_hours,
180 self->adjustment_from_minutes,
181 self->stack_from,
182 self->button_from_am,
183 self->button_from_pm);
184
185 /* set to */
186 if (automatic && self->proxy_color != NULL)
187 {
188 g_autoptr(GVariant) sunset = NULL;
189 sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunrise");
190 if (sunset != NULL)
191 {
192 value = g_variant_get_double (sunset);
193 }
194 else
195 {
196 value = 8.0f;
197 g_warning ("no sunrise data, using %02.2f", value);
198 }
199 }
200 else
201 {
202 value = g_settings_get_double (self->settings_display, "night-light-schedule-to");
203 value = fmod (value, 24.f);
204 }
205 dialog_adjustments_set_frac_hours (self, value,
206 self->adjustment_to_hours,
207 self->adjustment_to_minutes,
208 self->stack_to,
209 self->button_to_am,
210 self->button_to_pm);
211
212 self->ignore_value_changed = TRUE;
213 value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
214 gtk_adjustment_set_value (self->adjustment_color_temperature, value);
215 self->ignore_value_changed = FALSE;
216
217 adw_view_stack_set_visible_child_name (self->main_stack, "night-light-page");
218 }
219 else
220 {
221 adw_status_page_set_description (self->night_light_unsupported_page,
222 cc_hostname_is_vm_chassis (cc_hostname_get_default ()) ?
223 _("Night Light cannot be used from a virtual machine") :
224 _("This could be the result of the graphics driver being used, or the desktop being used remotely."));
225 adw_view_stack_set_visible_child_name (self->main_stack, "night-light-unsupported-page");
226 }
227 }
228
229 static void
230 build_schedule_combo_row (CcNightLightPage *self)
231 {
232 gboolean automatic;
233 gboolean enabled;
234
235 self->ignore_value_changed = TRUE;
236
237
238 enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled");
239 automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
240
241 gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
242
243 adw_combo_row_set_selected (self->schedule_type_row, automatic ? 0 : 1);
244
245 self->ignore_value_changed = FALSE;
246 }
247
248 static void
249 on_schedule_type_row_selected_changed_cb (CcNightLightPage *self)
250 {
251 guint selected;
252 gboolean automatic;
253
254 if (self->ignore_value_changed)
255 return;
256
257 selected = adw_combo_row_get_selected (self->schedule_type_row);
258 automatic = selected == 0;;
259
260 g_settings_set_boolean (self->settings_display, "night-light-schedule-automatic", automatic);
261 }
262
263 static gboolean
264 dialog_tick_cb (gpointer user_data)
265 {
266 CcNightLightPage *self = (CcNightLightPage *) user_data;
267 dialog_update_state (self);
268 return G_SOURCE_CONTINUE;
269 }
270
271 static void
272 dialog_enabled_notify_cb (GtkSwitch *sw,
273 GParamSpec *pspec,
274 CcNightLightPage *self)
275 {
276 g_settings_set_boolean (self->settings_display, "night-light-enabled",
277 gtk_switch_get_active (sw));
278 }
279
280 static void
281 dialog_undisable_call_cb (GObject *source_object,
282 GAsyncResult *res,
283 gpointer user_data)
284 {
285 g_autoptr(GVariant) val = NULL;
286 g_autoptr(GError) error = NULL;
287
288 val = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
289 res, &error);
290 if (val == NULL)
291 {
292 g_warning ("failed to undisable: %s", error->message);
293 return;
294 }
295 }
296
297 static void
298 dialog_undisable_clicked_cb (CcNightLightPage *self)
299 {
300 g_dbus_proxy_call (self->proxy_color_props,
301 "Set",
302 g_variant_new ("(ssv)",
303 "org.gnome.SettingsDaemon.Color",
304 "DisabledUntilTomorrow",
305 g_variant_new_boolean (FALSE)),
306 G_DBUS_CALL_FLAGS_NONE,
307 5000,
308 self->cancellable,
309 dialog_undisable_call_cb,
310 self);
311 }
312
313 static gdouble
314 dialog_adjustments_get_frac_hours (CcNightLightPage *self,
315 GtkAdjustment *adj_hours,
316 GtkAdjustment *adj_mins,
317 GtkStack *stack)
318 {
319 gdouble value;
320
321 value = gtk_adjustment_get_value (adj_hours);
322 value += gtk_adjustment_get_value (adj_mins) / 60.0f;
323
324 if (g_strcmp0 (gtk_stack_get_visible_child_name (stack), "pm") == 0)
325 value += 12.f;
326
327 return value;
328 }
329
330 static void
331 dialog_time_from_value_changed_cb (CcNightLightPage *self)
332 {
333 gdouble value;
334
335 if (self->ignore_value_changed)
336 return;
337
338 value = dialog_adjustments_get_frac_hours (self,
339 self->adjustment_from_hours,
340 self->adjustment_from_minutes,
341 self->stack_from);
342
343 if (value >= 24.f)
344 value = fmod (value, 24);
345
346 g_debug ("new value = %.3f", value);
347
348 g_settings_set_double (self->settings_display, "night-light-schedule-from", value);
349 }
350
351 static void
352 dialog_time_to_value_changed_cb (CcNightLightPage *self)
353 {
354 gdouble value;
355
356 if (self->ignore_value_changed)
357 return;
358
359 value = dialog_adjustments_get_frac_hours (self,
360 self->adjustment_to_hours,
361 self->adjustment_to_minutes,
362 self->stack_to);
363 if (value >= 24.f)
364 value = fmod (value, 24);
365
366 g_debug ("new value = %.3f", value);
367
368 g_settings_set_double (self->settings_display, "night-light-schedule-to", value);
369 }
370
371 static void
372 dialog_color_temperature_value_changed_cb (CcNightLightPage *self)
373 {
374 gdouble value;
375
376 if (self->ignore_value_changed)
377 return;
378
379 value = gtk_adjustment_get_value (self->adjustment_color_temperature);
380
381 g_debug ("new value = %.0f", value);
382
383 if (self->proxy_color != NULL)
384 g_dbus_proxy_call (self->proxy_color,
385 "NightLightPreview",
386 g_variant_new ("(u)", NIGHT_LIGHT_PREVIEW_TIMEOUT_SECONDS),
387 G_DBUS_CALL_FLAGS_NONE,
388 5000,
389 NULL,
390 NULL,
391 NULL);
392
393 g_settings_set_uint (self->settings_display, "night-light-temperature", (guint) value);
394 }
395
396 static void
397 dialog_color_properties_changed_cb (CcNightLightPage *self)
398 {
399 dialog_update_state (self);
400 }
401
402 static void
403 dialog_got_proxy_cb (GObject *source_object,
404 GAsyncResult *res,
405 gpointer user_data)
406 {
407 CcNightLightPage *self = (CcNightLightPage *) user_data;
408 GDBusProxy *proxy;
409 g_autoptr(GError) error = NULL;
410
411 proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
412 if (proxy == NULL)
413 {
414 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
415 g_warning ("failed to connect to g-s-d: %s", error->message);
416 return;
417 }
418
419 self->proxy_color = proxy;
420
421 g_signal_connect_object (self->proxy_color, "g-properties-changed",
422 G_CALLBACK (dialog_color_properties_changed_cb), self, G_CONNECT_SWAPPED);
423 dialog_update_state (self);
424 self->timer_id = g_timeout_add_seconds (10, dialog_tick_cb, self);
425 }
426
427 static void
428 dialog_got_proxy_props_cb (GObject *source_object,
429 GAsyncResult *res,
430 gpointer user_data)
431 {
432 CcNightLightPage *self = (CcNightLightPage *) user_data;
433 GDBusProxy *proxy;
434 g_autoptr(GError) error = NULL;
435
436 proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
437 if (proxy == NULL)
438 {
439 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
440 g_warning ("failed to connect to g-s-d: %s", error->message);
441 return;
442 }
443
444 self->proxy_color_props = proxy;
445 }
446
447 static void
448 dialog_format_minutes_combobox (GtkSpinButton *spin)
449 {
450 GtkAdjustment *adjustment;
451 g_autofree gchar *text = NULL;
452 adjustment = gtk_spin_button_get_adjustment (spin);
453 text = g_strdup_printf ("%02.0f", gtk_adjustment_get_value (adjustment));
454 gtk_editable_set_text (GTK_EDITABLE (spin), text);
455 }
456
457 static gboolean
458 dialog_format_from_minutes_combobox (CcNightLightPage *self)
459 {
460 dialog_format_minutes_combobox (self->spinbutton_from_minutes);
461 return TRUE;
462 }
463
464 static gboolean
465 dialog_format_to_minutes_combobox (CcNightLightPage *self)
466 {
467 dialog_format_minutes_combobox (self->spinbutton_to_minutes);
468 return TRUE;
469 }
470
471 static void
472 dialog_format_hours_combobox (CcNightLightPage *self, GtkSpinButton *spin)
473 {
474 GtkAdjustment *adjustment;
475 g_autofree gchar *text = NULL;
476 adjustment = gtk_spin_button_get_adjustment (spin);
477 if (self->clock_format == G_DESKTOP_CLOCK_FORMAT_12H)
478 text = g_strdup_printf ("%.0f", gtk_adjustment_get_value (adjustment));
479 else
480 text = g_strdup_printf ("%02.0f", gtk_adjustment_get_value (adjustment));
481 gtk_editable_set_text (GTK_EDITABLE (spin), text);
482 }
483
484 static gboolean
485 dialog_format_from_hours_combobox (CcNightLightPage *self)
486 {
487 dialog_format_hours_combobox (self, self->spinbutton_from_hours);
488 return TRUE;
489 }
490
491 static gboolean
492 dialog_format_to_hours_combobox (CcNightLightPage *self)
493 {
494 dialog_format_hours_combobox (self, self->spinbutton_to_hours);
495 return TRUE;
496 }
497
498 static void
499 dialog_update_adjustments (CcNightLightPage *self)
500 {
501 /* from */
502 if (self->clock_format == G_DESKTOP_CLOCK_FORMAT_24H)
503 {
504 gtk_adjustment_set_lower (self->adjustment_from_hours, 0);
505 gtk_adjustment_set_upper (self->adjustment_from_hours, 23);
506 }
507 else
508 {
509 if (gtk_adjustment_get_value (self->adjustment_from_hours) > 12)
510 gtk_stack_set_visible_child (self->stack_from, GTK_WIDGET (self->button_from_pm));
511
512 gtk_adjustment_set_lower (self->adjustment_from_hours, 1);
513 gtk_adjustment_set_upper (self->adjustment_from_hours, 12);
514 }
515
516 /* to */
517 if (self->clock_format == G_DESKTOP_CLOCK_FORMAT_24H)
518 {
519 gtk_adjustment_set_lower (self->adjustment_to_hours, 0);
520 gtk_adjustment_set_upper (self->adjustment_to_hours, 23);
521 }
522 else
523 {
524 if (gtk_adjustment_get_value (self->adjustment_to_hours) > 12)
525 gtk_stack_set_visible_child (self->stack_to, GTK_WIDGET (self->button_to_pm));
526
527 gtk_adjustment_set_lower (self->adjustment_to_hours, 1);
528 gtk_adjustment_set_upper (self->adjustment_to_hours, 12);
529 }
530 }
531
532 static void
533 dialog_settings_changed_cb (CcNightLightPage *self)
534 {
535 dialog_update_state (self);
536 }
537
538 static void
539 dialog_clock_settings_changed_cb (CcNightLightPage *self)
540 {
541 self->clock_format = g_settings_get_enum (self->settings_clock, CLOCK_FORMAT_KEY);
542
543 /* uncontionally widen this to avoid truncation */
544 gtk_adjustment_set_lower (self->adjustment_from_hours, 0);
545 gtk_adjustment_set_upper (self->adjustment_from_hours, 23);
546 gtk_adjustment_set_lower (self->adjustment_to_hours, 0);
547 gtk_adjustment_set_upper (self->adjustment_to_hours, 23);
548
549 /* update spinbuttons */
550 gtk_spin_button_update (self->spinbutton_from_hours);
551 gtk_spin_button_update (self->spinbutton_to_hours);
552
553 /* update UI */
554 dialog_update_state (self);
555 dialog_update_adjustments (self);
556 }
557
558 static void
559 dialog_am_pm_from_button_clicked_cb (CcNightLightPage *self)
560 {
561 gdouble value;
562 value = g_settings_get_double (self->settings_display, "night-light-schedule-from");
563 if (value > 12.f)
564 value -= 12.f;
565 else
566 value += 12.f;
567 if (value >= 24.f)
568 value = fmod (value, 24);
569 g_settings_set_double (self->settings_display, "night-light-schedule-from", value);
570 g_debug ("new value = %.3f", value);
571 }
572
573 static void
574 dialog_am_pm_to_button_clicked_cb (CcNightLightPage *self)
575 {
576 gdouble value;
577 value = g_settings_get_double (self->settings_display, "night-light-schedule-to");
578 if (value > 12.f)
579 value -= 12.f;
580 else
581 value += 12.f;
582 if (value >= 24.f)
583 value = fmod (value, 24);
584 g_settings_set_double (self->settings_display, "night-light-schedule-to", value);
585 g_debug ("new value = %.3f", value);
586 }
587
588 static void
589 config_manager_changed_cb (CcNightLightPage *self)
590 {
591 dialog_update_state (self);
592 }
593
594 /* GObject overrides */
595 static void
596 cc_night_light_page_finalize (GObject *object)
597 {
598 CcNightLightPage *self = CC_NIGHT_LIGHT_PAGE (object);
599
600 g_cancellable_cancel (self->cancellable);
601
602 g_clear_object (&self->cancellable);
603 g_clear_object (&self->config_manager);
604 g_clear_object (&self->proxy_color);
605 g_clear_object (&self->proxy_color_props);
606 g_clear_object (&self->settings_display);
607 g_clear_object (&self->settings_clock);
608 g_clear_handle_id (&self->timer_id, g_source_remove);
609
610 G_OBJECT_CLASS (cc_night_light_page_parent_class)->finalize (object);
611 }
612
613 static void
614 cc_night_light_page_class_init (CcNightLightPageClass *klass)
615 {
616 GObjectClass *object_class = G_OBJECT_CLASS (klass);
617 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
618
619 object_class->finalize = cc_night_light_page_finalize;
620
621 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/display/cc-night-light-page.ui");
622
623 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, main_stack);
624 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_from_hours);
625 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_from_minutes);
626 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_hours);
627 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_minutes);
628 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_color_temperature);
629 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_settings);
630 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, box_manual);
631 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_am);
632 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_pm);
633 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_am);
634 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_pm);
635 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_unsupported_page);
636 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled);
637 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_row);
638 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, schedule_type_row);
639 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, scale_color_temperature);
640 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, from_spinbuttons_box);
641 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_from_hours);
642 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_from_minutes);
643 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, to_spinbuttons_box);
644 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_to_hours);
645 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_to_minutes);
646 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, stack_from);
647 gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, stack_to);
648
649 gtk_widget_class_bind_template_callback (widget_class, dialog_am_pm_from_button_clicked_cb);
650 gtk_widget_class_bind_template_callback (widget_class, dialog_am_pm_to_button_clicked_cb);
651 gtk_widget_class_bind_template_callback (widget_class, dialog_enabled_notify_cb);
652 gtk_widget_class_bind_template_callback (widget_class, dialog_format_from_hours_combobox);
653 gtk_widget_class_bind_template_callback (widget_class, dialog_format_to_hours_combobox);
654 gtk_widget_class_bind_template_callback (widget_class, dialog_format_from_minutes_combobox);
655 gtk_widget_class_bind_template_callback (widget_class, dialog_format_to_minutes_combobox);
656 gtk_widget_class_bind_template_callback (widget_class, dialog_time_from_value_changed_cb);
657 gtk_widget_class_bind_template_callback (widget_class, dialog_time_to_value_changed_cb);
658 gtk_widget_class_bind_template_callback (widget_class, dialog_color_temperature_value_changed_cb);
659 gtk_widget_class_bind_template_callback (widget_class, dialog_undisable_clicked_cb);
660 gtk_widget_class_bind_template_callback (widget_class, on_schedule_type_row_selected_changed_cb);
661
662 }
663
664 static void
665 cc_night_light_page_init (CcNightLightPage *self)
666 {
667 g_autoptr(GtkCssProvider) provider = NULL;
668
669 gtk_widget_init_template (GTK_WIDGET (self));
670
671 gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
672 1700, GTK_POS_BOTTOM,
673 NULL);
674
675 gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
676 2700, GTK_POS_BOTTOM,
677 NULL);
678
679 gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
680 3700, GTK_POS_BOTTOM,
681 NULL);
682
683 gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
684 4700, GTK_POS_BOTTOM,
685 NULL);
686
687 self->cancellable = g_cancellable_new ();
688 self->settings_display = g_settings_new (DISPLAY_SCHEMA);
689
690 g_signal_connect_object (self->settings_display, "changed", G_CALLBACK (dialog_settings_changed_cb), self, G_CONNECT_SWAPPED);
691
692 build_schedule_combo_row (self);
693
694 g_settings_bind (self->settings_display, "night-light-enabled",
695 self->night_light_toggle_row, "active",
696 G_SETTINGS_BIND_DEFAULT);
697
698 g_settings_bind_writable (self->settings_display, "night-light-enabled",
699 self->night_light_toggle_row, "sensitive",
700 FALSE);
701
702 g_settings_bind_writable (self->settings_display, "night-light-schedule-from",
703 self->spinbutton_from_hours, "sensitive",
704 FALSE);
705 g_settings_bind_writable (self->settings_display, "night-light-schedule-from",
706 self->spinbutton_from_minutes, "sensitive",
707 FALSE);
708 g_settings_bind_writable (self->settings_display, "night-light-schedule-to",
709 self->spinbutton_to_minutes, "sensitive",
710 FALSE);
711 g_settings_bind_writable (self->settings_display, "night-light-schedule-to",
712 self->spinbutton_to_minutes, "sensitive",
713 FALSE);
714
715 /* use custom CSS */
716 provider = gtk_css_provider_new ();
717 gtk_css_provider_load_from_resource (provider, "/org/gnome/control-center/display/night-light.css");
718 gtk_style_context_add_provider_for_display (gdk_display_get_default (),
719 GTK_STYLE_PROVIDER (provider),
720 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
721
722 cc_object_storage_create_dbus_proxy (G_BUS_TYPE_SESSION,
723 G_DBUS_PROXY_FLAGS_NONE,
724 "org.gnome.SettingsDaemon.Color",
725 "/org/gnome/SettingsDaemon/Color",
726 "org.gnome.SettingsDaemon.Color",
727 self->cancellable,
728 dialog_got_proxy_cb,
729 self);
730
731 cc_object_storage_create_dbus_proxy (G_BUS_TYPE_SESSION,
732 G_DBUS_PROXY_FLAGS_NONE,
733 "org.gnome.SettingsDaemon.Color",
734 "/org/gnome/SettingsDaemon/Color",
735 "org.freedesktop.DBus.Properties",
736 self->cancellable,
737 dialog_got_proxy_props_cb,
738 self);
739
740 /* clock settings_display */
741 self->settings_clock = g_settings_new (CLOCK_SCHEMA);
742 self->clock_format = g_settings_get_enum (self->settings_clock, CLOCK_FORMAT_KEY);
743 dialog_update_adjustments (self);
744 g_signal_connect_object (self->settings_clock,
745 "changed::" CLOCK_FORMAT_KEY,
746 G_CALLBACK (dialog_clock_settings_changed_cb),
747 self, G_CONNECT_SWAPPED);
748
749 if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
750 {
751 gtk_widget_set_direction (self->to_spinbuttons_box, GTK_TEXT_DIR_LTR);
752 gtk_widget_set_direction (self->from_spinbuttons_box, GTK_TEXT_DIR_LTR);
753 }
754
755 self->config_manager = cc_display_config_manager_dbus_new ();
756 g_signal_connect_object (self->config_manager, "changed",
757 G_CALLBACK (config_manager_changed_cb), self,
758 G_CONNECT_SWAPPED);
759
760 dialog_update_state (self);
761 }
762
763 CcNightLightPage *
764 cc_night_light_page_new (void)
765 {
766 return g_object_new (CC_TYPE_NIGHT_LIGHT_PAGE,
767 NULL);
768 }
769
770