1 /* dzl-preferences.c
2 *
3 * Copyright (C) 2015-2017 Christian Hergert <chergert@redhat.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #define G_LOG_DOMAIN "dzl-preferences"
20
21 #include "config.h"
22
23 #include <string.h>
24
25 #include "prefs/dzl-preferences.h"
26
G_DEFINE_INTERFACE(DzlPreferences,dzl_preferences,G_TYPE_OBJECT)27 G_DEFINE_INTERFACE (DzlPreferences, dzl_preferences, G_TYPE_OBJECT)
28
29 static void
30 dzl_preferences_default_init (DzlPreferencesInterface *iface)
31 {
32 }
33
34 void
dzl_preferences_add_page(DzlPreferences * self,const gchar * page_name,const gchar * title,gint priority)35 dzl_preferences_add_page (DzlPreferences *self,
36 const gchar *page_name,
37 const gchar *title,
38 gint priority)
39 {
40 g_return_if_fail (DZL_IS_PREFERENCES (self));
41 g_return_if_fail (page_name != NULL);
42 g_return_if_fail ((title != NULL) || (strchr (page_name, '.') != NULL));
43
44 DZL_PREFERENCES_GET_IFACE (self)->add_page (self, page_name, title, priority);
45 }
46
47 void
dzl_preferences_add_group(DzlPreferences * self,const gchar * page_name,const gchar * group_name,const gchar * title,gint priority)48 dzl_preferences_add_group (DzlPreferences *self,
49 const gchar *page_name,
50 const gchar *group_name,
51 const gchar *title,
52 gint priority)
53 {
54 g_return_if_fail (DZL_IS_PREFERENCES (self));
55 g_return_if_fail (page_name != NULL);
56 g_return_if_fail (group_name != NULL);
57
58 DZL_PREFERENCES_GET_IFACE (self)->add_group (self, page_name, group_name, title, priority);
59 }
60
61 /**
62 * dzl_preferences_add_switch:
63 * @path: (nullable): An optional path
64 * @variant_string: (nullable): An optional gvariant string
65 * @title: (nullable): An optional title
66 * @subtitle: (nullable): An optional subtitle
67 * @keywords: (nullable): Optional keywords for search
68 *
69 */
70 guint
dzl_preferences_add_switch(DzlPreferences * self,const gchar * page_name,const gchar * group_name,const gchar * schema_id,const gchar * key,const gchar * path,const gchar * variant_string,const gchar * title,const gchar * subtitle,const gchar * keywords,gint priority)71 dzl_preferences_add_switch (DzlPreferences *self,
72 const gchar *page_name,
73 const gchar *group_name,
74 const gchar *schema_id,
75 const gchar *key,
76 const gchar *path,
77 const gchar *variant_string,
78 const gchar *title,
79 const gchar *subtitle,
80 const gchar *keywords,
81 gint priority)
82 {
83 g_return_val_if_fail (DZL_IS_PREFERENCES (self), 0);
84 g_return_val_if_fail (page_name != NULL, 0);
85 g_return_val_if_fail (group_name != NULL, 0);
86 g_return_val_if_fail (schema_id != NULL, 0);
87 g_return_val_if_fail (key != NULL, 0);
88 g_return_val_if_fail (title != NULL, 0);
89
90 return DZL_PREFERENCES_GET_IFACE (self)->add_switch (self, page_name, group_name, schema_id, key, path, variant_string, title, subtitle, keywords, priority);
91 }
92
93 guint
dzl_preferences_add_spin_button(DzlPreferences * self,const gchar * page_name,const gchar * group_name,const gchar * schema_id,const gchar * key,const gchar * path,const gchar * title,const gchar * subtitle,const gchar * keywords,gint priority)94 dzl_preferences_add_spin_button (DzlPreferences *self,
95 const gchar *page_name,
96 const gchar *group_name,
97 const gchar *schema_id,
98 const gchar *key,
99 const gchar *path,
100 const gchar *title,
101 const gchar *subtitle,
102 const gchar *keywords,
103 gint priority)
104 {
105 g_return_val_if_fail (DZL_IS_PREFERENCES (self), 0);
106 g_return_val_if_fail (page_name != NULL, 0);
107 g_return_val_if_fail (group_name != NULL, 0);
108 g_return_val_if_fail (schema_id != NULL, 0);
109 g_return_val_if_fail (key != NULL, 0);
110 g_return_val_if_fail (title != NULL, 0);
111
112 return DZL_PREFERENCES_GET_IFACE (self)->add_spin_button (self, page_name, group_name, schema_id, key, path, title, subtitle, keywords, priority);
113 }
114
115 /**
116 * dzl_preferences_add_custom:
117 * @keywords: (nullable): Optional keywords for search
118 *
119 */
120 guint
dzl_preferences_add_custom(DzlPreferences * self,const gchar * page_name,const gchar * group_name,GtkWidget * widget,const gchar * keywords,gint priority)121 dzl_preferences_add_custom (DzlPreferences *self,
122 const gchar *page_name,
123 const gchar *group_name,
124 GtkWidget *widget,
125 const gchar *keywords,
126 gint priority)
127 {
128 g_return_val_if_fail (DZL_IS_PREFERENCES (self), 0);
129 g_return_val_if_fail (page_name != NULL, 0);
130 g_return_val_if_fail (group_name != NULL, 0);
131 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
132
133 return DZL_PREFERENCES_GET_IFACE (self)->add_custom (self, page_name, group_name, widget, keywords, priority);
134 }
135
136 void
dzl_preferences_add_list_group(DzlPreferences * self,const gchar * page_name,const gchar * group_name,const gchar * title,GtkSelectionMode mode,gint priority)137 dzl_preferences_add_list_group (DzlPreferences *self,
138 const gchar *page_name,
139 const gchar *group_name,
140 const gchar *title,
141 GtkSelectionMode mode,
142 gint priority)
143 {
144 g_return_if_fail (DZL_IS_PREFERENCES (self));
145 g_return_if_fail (page_name != NULL);
146 g_return_if_fail (group_name != NULL);
147
148 return DZL_PREFERENCES_GET_IFACE (self)->add_list_group (self, page_name, group_name, title, mode, priority);
149 }
150
151 /**
152 * dzl_preferences_add_radio:
153 * @path: (nullable): An optional path
154 * @variant_string: (nullable): An optional gvariant string
155 * @title: (nullable): An optional title
156 * @subtitle: (nullable): An optional subtitle
157 * @keywords: (nullable): Optional keywords for search
158 *
159 */
160 guint
dzl_preferences_add_radio(DzlPreferences * self,const gchar * page_name,const gchar * group_name,const gchar * schema_id,const gchar * key,const gchar * path,const gchar * variant_string,const gchar * title,const gchar * subtitle,const gchar * keywords,gint priority)161 dzl_preferences_add_radio (DzlPreferences *self,
162 const gchar *page_name,
163 const gchar *group_name,
164 const gchar *schema_id,
165 const gchar *key,
166 const gchar *path,
167 const gchar *variant_string,
168 const gchar *title,
169 const gchar *subtitle,
170 const gchar *keywords,
171 gint priority)
172 {
173 g_return_val_if_fail (DZL_IS_PREFERENCES (self), 0);
174 g_return_val_if_fail (page_name != NULL, 0);
175 g_return_val_if_fail (group_name != NULL, 0);
176 g_return_val_if_fail (schema_id != NULL, 0);
177 g_return_val_if_fail (key != NULL, 0);
178 g_return_val_if_fail (title != NULL, 0);
179
180 return DZL_PREFERENCES_GET_IFACE (self)->add_radio (self, page_name, group_name, schema_id, key, path, variant_string, title, subtitle, keywords, priority);
181 }
182
183 guint
dzl_preferences_add_font_button(DzlPreferences * self,const gchar * page_name,const gchar * group_name,const gchar * schema_id,const gchar * key,const gchar * title,const gchar * keywords,gint priority)184 dzl_preferences_add_font_button (DzlPreferences *self,
185 const gchar *page_name,
186 const gchar *group_name,
187 const gchar *schema_id,
188 const gchar *key,
189 const gchar *title,
190 const gchar *keywords,
191 gint priority)
192 {
193 g_return_val_if_fail (DZL_IS_PREFERENCES (self), 0);
194 g_return_val_if_fail (page_name != NULL, 0);
195 g_return_val_if_fail (group_name != NULL, 0);
196 g_return_val_if_fail (schema_id != NULL, 0);
197 g_return_val_if_fail (key != NULL, 0);
198 g_return_val_if_fail (title != NULL, 0);
199
200 return DZL_PREFERENCES_GET_IFACE (self)->add_font_button (self, page_name, group_name, schema_id, key, title, keywords, priority);
201 }
202
203 guint
dzl_preferences_add_file_chooser(DzlPreferences * self,const gchar * page_name,const gchar * group_name,const gchar * schema_id,const gchar * key,const gchar * path,const gchar * title,const gchar * subtitle,GtkFileChooserAction action,const gchar * keywords,gint priority)204 dzl_preferences_add_file_chooser (DzlPreferences *self,
205 const gchar *page_name,
206 const gchar *group_name,
207 const gchar *schema_id,
208 const gchar *key,
209 const gchar *path,
210 const gchar *title,
211 const gchar *subtitle,
212 GtkFileChooserAction action,
213 const gchar *keywords,
214 gint priority)
215 {
216 g_return_val_if_fail (DZL_IS_PREFERENCES (self), 0);
217 g_return_val_if_fail (page_name != NULL, 0);
218 g_return_val_if_fail (group_name != NULL, 0);
219 g_return_val_if_fail (schema_id != NULL, 0);
220 g_return_val_if_fail (key != NULL, 0);
221 g_return_val_if_fail (title != NULL, 0);
222
223 return DZL_PREFERENCES_GET_IFACE (self)->add_file_chooser (self, page_name, group_name, schema_id, key, path, title, subtitle, action, keywords, priority);
224 }
225
226 /**
227 * ide_preference_remove_id:
228 * @widget_id: An preferences widget id
229 *
230 */
231 gboolean
dzl_preferences_remove_id(DzlPreferences * self,guint widget_id)232 dzl_preferences_remove_id (DzlPreferences *self,
233 guint widget_id)
234 {
235 g_return_val_if_fail (DZL_IS_PREFERENCES (self), FALSE);
236 g_return_val_if_fail (widget_id, FALSE);
237
238 return DZL_PREFERENCES_GET_IFACE (self)->remove_id (self, widget_id);
239 }
240
241 void
dzl_preferences_set_page(DzlPreferences * self,const gchar * page_name,GHashTable * map)242 dzl_preferences_set_page (DzlPreferences *self,
243 const gchar *page_name,
244 GHashTable *map)
245 {
246 g_return_if_fail (DZL_IS_PREFERENCES (self));
247 g_return_if_fail (page_name != NULL);
248
249 DZL_PREFERENCES_GET_IFACE (self)->set_page (self, page_name, map);
250 }
251
252 /**
253 * dzl_preferences_get_widget:
254 *
255 * Returns: (transfer none) (nullable): A #GtkWidget or %NULL.
256 */
257 GtkWidget *
dzl_preferences_get_widget(DzlPreferences * self,guint widget_id)258 dzl_preferences_get_widget (DzlPreferences *self,
259 guint widget_id)
260 {
261 g_return_val_if_fail (DZL_IS_PREFERENCES (self), NULL);
262
263 return DZL_PREFERENCES_GET_IFACE (self)->get_widget (self, widget_id);
264 }
265
266 guint
dzl_preferences_add_table_row(DzlPreferences * self,const gchar * page_name,const gchar * group_name,GtkWidget * first_widget,...)267 dzl_preferences_add_table_row (DzlPreferences *self,
268 const gchar *page_name,
269 const gchar *group_name,
270 GtkWidget *first_widget,
271 ...)
272 {
273 va_list args;
274 gint ret;
275
276 g_return_val_if_fail (DZL_IS_PREFERENCES (self), 0);
277 g_return_val_if_fail (page_name != NULL, 0);
278 g_return_val_if_fail (group_name != NULL, 0);
279 g_return_val_if_fail (GTK_IS_WIDGET (first_widget), 0);
280
281 va_start (args, first_widget);
282 ret = DZL_PREFERENCES_GET_IFACE (self)->add_table_row_va (self, page_name, group_name, first_widget, args);
283 va_end (args);
284
285 return ret;
286 }
287