annotate pui-prefs-application.c @ 11:7f995e958703 version-1

Release version 1
author Guido Berhoerster <guido+pui@berhoerster.name>
date Fri, 06 Jul 2018 14:21:28 +0200
parents 3d72ca76538d
children 9cbb0f8a66c4
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;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
35 };
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
36
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
37 G_DEFINE_TYPE(PuiPrefsApplication, pui_prefs_application, GTK_TYPE_APPLICATION)
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 static void pui_prefs_application_quit(GSimpleAction *, GVariant *,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
40 gpointer);
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 const GActionEntry pui_prefs_application_actions[] = {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
43 { "quit", pui_prefs_application_quit }
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
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
46 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
47 pui_prefs_application_quit(GSimpleAction *simple, GVariant *parameter,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
48 gpointer user_data)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
49 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
50 PuiPrefsApplication *self = user_data;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
51
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
52 g_application_quit(G_APPLICATION(self));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
53 }
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 static gboolean
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
56 map_refresh_interval_to_index(GValue *value, GVariant *variant,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
57 gpointer user_data)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
58 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
59 GtkTreeModel *tree_model = user_data;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
60 guint32 setting_interval;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
61 gint index;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
62 gboolean iter_continue;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
63 GtkTreeIter iter = { 0 };
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
64 GValue model_value = G_VALUE_INIT;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
65 guint model_interval;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
66
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
67 setting_interval = g_variant_get_uint32(variant);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
68
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
69 /* try to find a matching entry in the list */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
70 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
71 index = 0; iter_continue;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
72 iter_continue = gtk_tree_model_iter_next(tree_model, &iter),
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
73 index++) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
74 gtk_tree_model_get_value(tree_model, &iter,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
75 COLUMN_REFRESH_INTERVAL, &model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
76 model_interval = g_value_get_uint(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
77 g_value_unset(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
78 if (setting_interval == model_interval) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
79 g_debug("mapping refresh-interval %" G_GUINT32_FORMAT
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
80 " to index %d", setting_interval, index);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
81 g_value_set_int(value, index);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
82
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
83 return (TRUE);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
84 }
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
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
87 g_debug("mapping refresh-interval %" G_GUINT32_FORMAT " to index -1",
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
88 setting_interval);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
89 g_value_set_int(value, -1);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
90
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
91 return (TRUE);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
92 }
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 static GVariant *
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
95 map_index_to_refresh_interval(const GValue *value,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
96 const GVariantType *expected_type, gpointer user_data)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
97 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
98 GtkTreeModel *tree_model = GTK_TREE_MODEL(user_data);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
99 gint index;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
100 GtkTreeIter iter = { 0 };
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
101 GValue model_value = G_VALUE_INIT;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
102 guint model_interval;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
103
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
104 index = g_value_get_int(value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
105 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
106 return (NULL);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
107 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
108
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
109 gtk_tree_model_get_value(tree_model, &iter, COLUMN_REFRESH_INTERVAL,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
110 &model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
111 model_interval = g_value_get_uint(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
112 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
113 index, model_interval);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
114 g_value_unset(&model_value);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
115
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
116 return (g_variant_new_uint32(model_interval));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
117 }
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 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
120 pui_prefs_application_startup(GApplication *application)
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 PuiPrefsApplication *self = PUI_PREFS_APPLICATION(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
123 GApplicationClass *application_class =
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
124 G_APPLICATION_CLASS(pui_prefs_application_parent_class);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
125 GtkBuilder *builder;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
126 GtkWidget *window;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
127 GtkTreeModel *tree_model;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
128 GtkWidget *update_command_entry;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
129 GtkWidget *refresh_interval_combo_box;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
130 GtkWidget *use_mobile_check_button;
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
131
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
132 application_class->startup(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
133
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
134 /* create actions */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
135 g_action_map_add_action_entries(G_ACTION_MAP(self),
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
136 pui_prefs_application_actions,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
137 G_N_ELEMENTS(pui_prefs_application_actions), self);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
138
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
139 /* get widgets from builder */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
140 builder = gtk_builder_new_from_resource("/org/guido-berhoerster/code/"
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
141 "package-update-indicator/preferences/pui-prefs-window.ui");
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
142 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
143 gtk_application_add_window(GTK_APPLICATION(self), GTK_WINDOW(window));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
144 update_command_entry = GTK_WIDGET(gtk_builder_get_object(builder,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
145 "update-command"));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
146 refresh_interval_combo_box = GTK_WIDGET(gtk_builder_get_object(builder,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
147 "refresh-interval"));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
148 tree_model =
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
149 gtk_combo_box_get_model(GTK_COMBO_BOX(refresh_interval_combo_box));
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
150 use_mobile_check_button = GTK_WIDGET(gtk_builder_get_object(builder,
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
151 "use-mobile-connection"));
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
152
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
153 /* bind settings to widgets */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
154 self->settings = pui_settings_new();
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
155 g_settings_bind(self->settings, "update-command",
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
156 update_command_entry, "text", G_SETTINGS_BIND_DEFAULT);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
157 g_settings_bind_with_mapping(self->settings, "refresh-interval",
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
158 refresh_interval_combo_box, "active", G_SETTINGS_BIND_DEFAULT,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
159 map_refresh_interval_to_index, map_index_to_refresh_interval,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
160 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
161 g_settings_bind(self->settings, "use-mobile-connection",
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
162 use_mobile_check_button, "active", G_SETTINGS_BIND_DEFAULT);
1
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 /* show window */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
165 gtk_widget_show(window);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
166 gtk_window_present(GTK_WINDOW(window));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
167
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
168 g_object_unref(builder);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
169 }
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 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
172 pui_prefs_application_activate(GApplication *application) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
173 GtkApplication *gtk_application = GTK_APPLICATION(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
174 GApplicationClass *application_class =
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
175 G_APPLICATION_CLASS(pui_prefs_application_parent_class);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
176
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
177 /* raise window when activated */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
178 gtk_window_present(gtk_application_get_active_window(gtk_application));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
179
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
180 application_class->activate(application);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
181 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
182
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
183 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
184 pui_prefs_application_dispose(GObject *object)
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 PuiPrefsApplication *self = PUI_PREFS_APPLICATION(object);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
187
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
188 if (self->settings != NULL) {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
189 g_clear_object(&self->settings);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
190 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
191
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
192 G_OBJECT_CLASS(pui_prefs_application_parent_class)->dispose(object);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
193 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
194
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
195 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
196 pui_prefs_application_class_init(PuiPrefsApplicationClass *klass)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
197 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
198 GObjectClass *object_class = G_OBJECT_CLASS(klass);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
199 GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
200
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
201 object_class->dispose = pui_prefs_application_dispose;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
202
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
203 application_class->startup = pui_prefs_application_startup;
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
204 application_class->activate = pui_prefs_application_activate;
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
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
207 static void
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
208 pui_prefs_application_init(PuiPrefsApplication *self)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
209 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
210 /* do nothing, implementation required */
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
211 }
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
212
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
213 PuiPrefsApplication *
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
214 pui_prefs_application_new(void)
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
215 {
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
216 return (g_object_new(PUI_TYPE_PREFS_APPLICATION,
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
217 "application-id", APPLICATION_ID, NULL));
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
218 }