annotate pui-prefs-application.c @ 60:346153e041a0

Added tag version-8 for changeset e3fc9db49d36
author Guido Berhoerster <guido+pui@berhoerster.name>
date Wed, 07 Sep 2022 08:45:55 +0200
parents 9cbb0f8a66c4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
1 /*
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2018 Guido Berhoerster <guido+pui@berhoerster.name>
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
3 *
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
4 * Permission is hereby granted, free of charge, to any person obtaining
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
5 * a copy of this software and associated documentation files (the
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
6 * "Software"), to deal in the Software without restriction, including
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
7 * without limitation the rights to use, copy, modify, merge, publish,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
8 * distribute, sublicense, and/or sell copies of the Software, and to
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
9 * permit persons to whom the Software is furnished to do so, subject to
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
10 * the following conditions:
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
11 *
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
13 * in all copies or substantial portions of the Software.
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
14 *
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
22 */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
23
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
24 #include <glib/gi18n.h>
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
25 #include <gio/gio.h>
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
26
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
27 #include "pui-prefs-application.h"
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
28 #include "pui-settings.h"
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
29
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
30 #define COLUMN_REFRESH_INTERVAL 2
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
31
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
32 struct _PuiPrefsApplication {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
33 GtkApplication parent_instance;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
34 GSettings *settings;
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
35 GtkWidget *update_command_entry;
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
36 GtkWidget *refresh_interval_combo_box;
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
37 GtkWidget *use_mobile_check_button;
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
38 };
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
39
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
40 G_DEFINE_TYPE(PuiPrefsApplication, pui_prefs_application, GTK_TYPE_APPLICATION)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
41
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
42 static void pui_prefs_application_quit(GSimpleAction *, GVariant *,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
43 gpointer);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
44
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
45 static const GActionEntry pui_prefs_application_actions[] = {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
46 { "quit", pui_prefs_application_quit }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
47 };
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
48
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
49 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
50 pui_prefs_application_quit(GSimpleAction *simple, GVariant *parameter,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
51 gpointer user_data)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
52 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
53 PuiPrefsApplication *self = user_data;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
54
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
55 g_application_quit(G_APPLICATION(self));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
56 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
57
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
58 static gboolean
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
59 map_refresh_interval_to_index(GValue *value, GVariant *variant,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
60 gpointer user_data)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
61 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
62 GtkTreeModel *tree_model = user_data;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
63 guint32 setting_interval;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
64 gint index;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
65 gboolean iter_continue;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
66 GtkTreeIter iter = { 0 };
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
67 GValue model_value = G_VALUE_INIT;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
68 guint model_interval;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
69
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
70 setting_interval = g_variant_get_uint32(variant);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
71
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
72 /* try to find a matching entry in the list */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
73 for (iter_continue = gtk_tree_model_get_iter_first(tree_model, &iter),
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
74 index = 0; iter_continue;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
75 iter_continue = gtk_tree_model_iter_next(tree_model, &iter),
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
76 index++) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
77 gtk_tree_model_get_value(tree_model, &iter,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
78 COLUMN_REFRESH_INTERVAL, &model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
79 model_interval = g_value_get_uint(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
80 g_value_unset(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
81 if (setting_interval == model_interval) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
82 g_debug("mapping refresh-interval %" G_GUINT32_FORMAT
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
83 " to index %d", setting_interval, index);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
84 g_value_set_int(value, index);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
85
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
86 return (TRUE);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
87 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
88 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
89
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
90 g_debug("mapping refresh-interval %" G_GUINT32_FORMAT " to index -1",
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
91 setting_interval);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
92 g_value_set_int(value, -1);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
93
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
94 return (TRUE);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
95 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
96
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
97 static GVariant *
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
98 map_index_to_refresh_interval(const GValue *value,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
99 const GVariantType *expected_type, gpointer user_data)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
100 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
101 GtkTreeModel *tree_model = GTK_TREE_MODEL(user_data);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
102 gint index;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
103 GtkTreeIter iter = { 0 };
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
104 GValue model_value = G_VALUE_INIT;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
105 guint model_interval;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
106
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
107 index = g_value_get_int(value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
108 if (!gtk_tree_model_iter_nth_child(tree_model, &iter, NULL, index)) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
109 return (NULL);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
110 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
111
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
112 gtk_tree_model_get_value(tree_model, &iter, COLUMN_REFRESH_INTERVAL,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
113 &model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
114 model_interval = g_value_get_uint(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
115 g_debug("mapping index %d to refresh-interval value %" G_GUINT32_FORMAT,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
116 index, model_interval);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
117 g_value_unset(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
118
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
119 return (g_variant_new_uint32(model_interval));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
120 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
121
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
122 static void
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
123 update_widgets(PuiPrefsApplication *self)
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
124 {
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
125 gchar ** disabled_preferences;
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
126
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
127 g_return_if_fail(self->update_command_entry != NULL);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
128 g_return_if_fail(self->refresh_interval_combo_box != NULL);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
129 g_return_if_fail(self->use_mobile_check_button != NULL);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
130
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
131 disabled_preferences = g_settings_get_strv(self->settings,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
132 "disable-preferences");
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
133 g_return_if_fail(disabled_preferences != NULL);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
134 gtk_widget_set_sensitive(self->update_command_entry,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
135 !g_strv_contains((const gchar * const *)disabled_preferences,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
136 "update-command"));
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
137 gtk_widget_set_sensitive(self->refresh_interval_combo_box,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
138 !g_strv_contains((const gchar * const *)disabled_preferences,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
139 "refresh-interval"));
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
140 gtk_widget_set_sensitive(self->use_mobile_check_button,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
141 !g_strv_contains((const gchar * const *)disabled_preferences,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
142 "use-mobile-connection"));
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
143 g_strfreev(disabled_preferences);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
144 }
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
145
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
146 static void
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
147 on_disable_preferences_changed(GSettings *settings, gchar *key,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
148 gpointer user_data)
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
149 {
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
150 g_debug("setting disable-preferences changed");
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
151 update_widgets(user_data);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
152 }
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
153
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
154 static void
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
155 pui_prefs_application_startup(GApplication *application)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
156 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
157 PuiPrefsApplication *self = PUI_PREFS_APPLICATION(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
158 GApplicationClass *application_class =
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
159 G_APPLICATION_CLASS(pui_prefs_application_parent_class);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
160 GtkBuilder *builder;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
161 GtkWidget *window;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
162 GtkTreeModel *tree_model;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
163
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
164 application_class->startup(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
165
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
166 /* create actions */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
167 g_action_map_add_action_entries(G_ACTION_MAP(self),
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
168 pui_prefs_application_actions,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
169 G_N_ELEMENTS(pui_prefs_application_actions), self);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
170
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
171 /* get widgets from builder */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
172 builder = gtk_builder_new_from_resource("/org/guido-berhoerster/code/"
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
173 "package-update-indicator/preferences/pui-prefs-window.ui");
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
174 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
175 gtk_application_add_window(GTK_APPLICATION(self), GTK_WINDOW(window));
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
176 self->update_command_entry = GTK_WIDGET(gtk_builder_get_object(builder,
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
177 "update-command"));
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
178 self->refresh_interval_combo_box =
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
179 GTK_WIDGET(gtk_builder_get_object(builder, "refresh-interval"));
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
180 tree_model = gtk_combo_box_get_model(
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
181 GTK_COMBO_BOX(self->refresh_interval_combo_box));
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
182 self->use_mobile_check_button =
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
183 GTK_WIDGET(gtk_builder_get_object(builder,
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
184 "use-mobile-connection"));
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
185
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
186 /* bind settings to widgets */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
187 self->settings = pui_settings_new();
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
188 g_settings_bind(self->settings, "update-command",
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
189 self->update_command_entry, "text", G_SETTINGS_BIND_DEFAULT);
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
190 g_settings_bind_with_mapping(self->settings, "refresh-interval",
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
191 self->refresh_interval_combo_box, "active",
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
192 G_SETTINGS_BIND_DEFAULT, map_refresh_interval_to_index,
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
193 map_index_to_refresh_interval, tree_model, NULL);
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
194 g_settings_bind(self->settings, "use-mobile-connection",
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
195 self->use_mobile_check_button, "active", G_SETTINGS_BIND_DEFAULT);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
196
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
197 /* watch disable-preferences setting in order to update the window */
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
198 g_signal_connect(self->settings, "changed::disable-preferences",
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
199 G_CALLBACK(on_disable_preferences_changed), self);
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
200 update_widgets(self);
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
201
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
202 /* show window */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
203 gtk_widget_show(window);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
204 gtk_window_present(GTK_WINDOW(window));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
205
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
206 g_object_unref(builder);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
207 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
208
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
209 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
210 pui_prefs_application_activate(GApplication *application) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
211 GtkApplication *gtk_application = GTK_APPLICATION(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
212 GApplicationClass *application_class =
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
213 G_APPLICATION_CLASS(pui_prefs_application_parent_class);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
214
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
215 /* raise window when activated */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
216 gtk_window_present(gtk_application_get_active_window(gtk_application));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
217
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
218 application_class->activate(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
219 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
220
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
221 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
222 pui_prefs_application_dispose(GObject *object)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
223 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
224 PuiPrefsApplication *self = PUI_PREFS_APPLICATION(object);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
225
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
226 if (self->settings != NULL) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
227 g_clear_object(&self->settings);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
228 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
229
58
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
230 self->update_command_entry = NULL;
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
231 self->refresh_interval_combo_box = NULL;
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
232 self->use_mobile_check_button = NULL;
9cbb0f8a66c4 Add setting to disable preferences widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
233
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
234 G_OBJECT_CLASS(pui_prefs_application_parent_class)->dispose(object);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
235 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
236
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
237 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
238 pui_prefs_application_class_init(PuiPrefsApplicationClass *klass)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
239 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
240 GObjectClass *object_class = G_OBJECT_CLASS(klass);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
241 GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
242
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
243 object_class->dispose = pui_prefs_application_dispose;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
244
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
245 application_class->startup = pui_prefs_application_startup;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
246 application_class->activate = pui_prefs_application_activate;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
247 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
248
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
249 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
250 pui_prefs_application_init(PuiPrefsApplication *self)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
251 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
252 /* do nothing, implementation required */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
253 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
254
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
255 PuiPrefsApplication *
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
256 pui_prefs_application_new(void)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
257 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
258 return (g_object_new(PUI_TYPE_PREFS_APPLICATION,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
259 "application-id", APPLICATION_ID, NULL));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
260 }