Branch data Line data Source code
1 : : // SPDX-License-Identifier: GPL-3.0-or-later
2 : : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
3 : :
4 : : #define G_LOG_DOMAIN "valent-device-preferences-dialog"
5 : :
6 : : #include "config.h"
7 : :
8 : : #include <glib/gi18n-lib.h>
9 : : #include <adwaita.h>
10 : : #include <gtk/gtk.h>
11 : : #include <valent.h>
12 : :
13 : : #include "valent-preferences-status-page.h"
14 : :
15 : :
16 : : struct _ValentPreferencesStatusPage
17 : : {
18 : : ValentPreferencesPage parent_instance;
19 : :
20 : : /* template */
21 : : AdwExpanderRow *full_notification;
22 : : GtkAdjustment *full_notification_level;
23 : : AdwExpanderRow *low_notification;
24 : : GtkAdjustment *low_notification_level;
25 : :
26 : : AdwComboRow *ringing_volume;
27 : : GtkSwitch *ringing_pause;
28 : : AdwComboRow *talking_volume;
29 : : GtkSwitch *talking_pause;
30 : : GtkSwitch *talking_microphone;
31 : : GtkSwitch *offline_notification;
32 : : };
33 : :
34 [ + + + - ]: 39 : G_DEFINE_FINAL_TYPE (ValentPreferencesStatusPage, valent_preferences_status_page, VALENT_TYPE_PREFERENCES_PAGE)
35 : :
36 : : /* Mapping functions for converting our [-1...100] volume range to a boolean,
37 : : * where -1 generally means "don't change", 0 means mute and any other value is
38 : : * a volume percentage.
39 : : * */
40 : : static gboolean
41 : 3 : get_mute_volume_boolean (GValue *value,
42 : : GVariant *variant,
43 : : gpointer user_data)
44 : : {
45 : 3 : int volume;
46 : :
47 : 3 : volume = g_variant_get_int32 (variant);
48 : :
49 : 3 : g_value_set_boolean (value, (volume == 0));
50 : :
51 : 3 : return TRUE;
52 : : }
53 : :
54 : : static GVariant *
55 : 0 : set_mute_volume_boolean (const GValue *value,
56 : : const GVariantType *expected_type,
57 : : gpointer user_data)
58 : : {
59 : 0 : gboolean mute_volume;
60 : :
61 : 0 : mute_volume = g_value_get_boolean (value);
62 : :
63 [ # # ]: 0 : if (mute_volume)
64 : 0 : return g_variant_new_int32 (0);
65 : : else
66 : 0 : return g_variant_new_int32 (-1);
67 : : }
68 : :
69 : : #define VOLUME_NOTHING -1
70 : : #define VOLUME_LOWER 15
71 : : #define VOLUME_MUTE 0
72 : :
73 : : static gboolean
74 : 6 : get_volume (GValue *value,
75 : : GVariant *variant,
76 : : gpointer user_data)
77 : : {
78 [ - + + - ]: 6 : switch (g_variant_get_int32 (variant))
79 : : {
80 : 0 : case VOLUME_NOTHING:
81 : 0 : g_value_set_uint (value, 0);
82 : 0 : return TRUE;
83 : :
84 : 3 : case VOLUME_LOWER:
85 : 3 : g_value_set_uint (value, 1);
86 : 3 : return TRUE;
87 : :
88 : 3 : case VOLUME_MUTE:
89 : 3 : g_value_set_uint (value, 2);
90 : 3 : return TRUE;
91 : :
92 : : default:
93 : : return FALSE;
94 : : }
95 : : }
96 : :
97 : : static GVariant *
98 : 0 : set_volume (const GValue *value,
99 : : const GVariantType *expected_type,
100 : : gpointer user_data)
101 : : {
102 [ # # # # ]: 0 : switch (g_value_get_uint (value))
103 : : {
104 : 0 : case 0:
105 : 0 : return g_variant_new_int32 (VOLUME_NOTHING);
106 : :
107 : 0 : case 1:
108 : 0 : return g_variant_new_int32 (VOLUME_LOWER);
109 : :
110 : 0 : case 2:
111 : 0 : return g_variant_new_int32 (VOLUME_MUTE);
112 : :
113 : 0 : default:
114 : 0 : return g_variant_new_int32 (VOLUME_NOTHING);
115 : : }
116 : : }
117 : :
118 : : static inline void
119 : 3 : valent_preferences_status_page_bind_context (ValentPreferencesStatusPage *self)
120 : : {
121 : 3 : ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (self);
122 : 3 : GSettings *settings = NULL;
123 : :
124 : : /* Battery
125 : : */
126 : 3 : settings = valent_preferences_page_get_settings (page, "battery");
127 : 3 : g_settings_bind (settings, "full-notification",
128 : 3 : self->full_notification, "enable-expansion",
129 : : G_SETTINGS_BIND_DEFAULT);
130 : 3 : g_settings_bind (settings, "full-notification-level",
131 : 3 : self->full_notification_level, "value",
132 : : G_SETTINGS_BIND_DEFAULT);
133 : 3 : g_settings_bind (settings, "low-notification",
134 : 3 : self->low_notification, "enable-expansion",
135 : : G_SETTINGS_BIND_DEFAULT);
136 : 3 : g_settings_bind (settings, "low-notification-level",
137 : 3 : self->low_notification_level, "value",
138 : : G_SETTINGS_BIND_DEFAULT);
139 : :
140 : : /* Telephony
141 : : */
142 : 3 : settings = valent_preferences_page_get_settings (page, "telephony");
143 : 3 : g_settings_bind (settings, "ringing-pause",
144 : 3 : self->ringing_pause, "active",
145 : : G_SETTINGS_BIND_DEFAULT);
146 : 3 : g_settings_bind_with_mapping (settings, "ringing-volume",
147 : 3 : self->ringing_volume, "selected",
148 : : G_SETTINGS_BIND_DEFAULT,
149 : : get_volume,
150 : : set_volume,
151 : : NULL, NULL);
152 : 3 : g_settings_bind_with_mapping (settings, "talking-microphone",
153 : 3 : self->talking_microphone, "active",
154 : : G_SETTINGS_BIND_DEFAULT,
155 : : get_mute_volume_boolean,
156 : : set_mute_volume_boolean,
157 : : NULL, NULL);
158 : 3 : g_settings_bind_with_mapping (settings, "talking-volume",
159 : 3 : self->talking_volume, "selected",
160 : : G_SETTINGS_BIND_DEFAULT,
161 : : get_volume,
162 : : set_volume,
163 : : NULL, NULL);
164 : 3 : g_settings_bind (settings, "talking-pause",
165 : 3 : self->talking_pause, "active",
166 : : G_SETTINGS_BIND_DEFAULT);
167 : :
168 : : /* Connectivity
169 : : */
170 : 3 : settings = valent_preferences_page_get_settings (page, "connectivity_report");
171 : 3 : g_settings_bind (settings, "offline-notification",
172 : 3 : self->offline_notification, "active",
173 : : G_SETTINGS_BIND_DEFAULT);
174 : 3 : }
175 : :
176 : : /*
177 : : * GObject
178 : : */
179 : : static void
180 : 3 : valent_preferences_status_page_dispose (GObject *object)
181 : : {
182 : 3 : GtkWidget *widget = GTK_WIDGET (object);
183 : :
184 : 3 : gtk_widget_dispose_template (widget, VALENT_TYPE_PREFERENCES_STATUS_PAGE);
185 : :
186 : 3 : G_OBJECT_CLASS (valent_preferences_status_page_parent_class)->dispose (object);
187 : 3 : }
188 : :
189 : : static void
190 : 27 : valent_preferences_status_page_notify (GObject *object,
191 : : GParamSpec *pspec)
192 : : {
193 : 27 : ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (object);
194 : 27 : ValentPreferencesStatusPage *self = VALENT_PREFERENCES_STATUS_PAGE (object);
195 : :
196 [ + + ]: 27 : if (g_strcmp0 (pspec->name, "context") == 0)
197 : : {
198 [ + - ]: 3 : if (valent_preferences_page_get_context (page) != NULL)
199 : 3 : valent_preferences_status_page_bind_context (self);
200 : : }
201 : :
202 [ - + ]: 27 : if (G_OBJECT_CLASS (valent_preferences_status_page_parent_class)->notify)
203 : 0 : G_OBJECT_CLASS (valent_preferences_status_page_parent_class)->notify (object,
204 : : pspec);
205 : 27 : }
206 : :
207 : : static void
208 : 2 : valent_preferences_status_page_class_init (ValentPreferencesStatusPageClass *klass)
209 : : {
210 : 2 : GObjectClass *object_class = G_OBJECT_CLASS (klass);
211 : 2 : GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
212 : :
213 : 2 : object_class->dispose = valent_preferences_status_page_dispose;
214 : 2 : object_class->notify = valent_preferences_status_page_notify;
215 : :
216 : 2 : gtk_widget_class_set_template_from_resource (widget_class, "/plugins/gnome/valent-preferences-status-page.ui");
217 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, full_notification);
218 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, full_notification_level);
219 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, low_notification);
220 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, low_notification_level);
221 : :
222 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, ringing_volume);
223 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, ringing_pause);
224 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, talking_volume);
225 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, talking_pause);
226 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, talking_microphone);
227 : 2 : gtk_widget_class_bind_template_child (widget_class, ValentPreferencesStatusPage, offline_notification);
228 : 2 : }
229 : :
230 : : static void
231 : 3 : valent_preferences_status_page_init (ValentPreferencesStatusPage *self)
232 : : {
233 : 3 : gtk_widget_init_template (GTK_WIDGET (self));
234 : 3 : }
235 : :
|