Mercurial > projects > package-update-indicator
diff pui-prefs-application.c @ 58:9cbb0f8a66c4
Add setting to disable preferences widgets
This just makes the widgets in the preferences application insensitive,
settings can still be changed by directly editing the configuration file.
author | Guido Berhoerster <guido+pui@berhoerster.name> |
---|---|
date | Tue, 06 Sep 2022 19:11:21 +0200 |
parents | 3d72ca76538d |
children |
line wrap: on
line diff
--- a/pui-prefs-application.c Tue Sep 06 09:02:57 2022 +0200 +++ b/pui-prefs-application.c Tue Sep 06 19:11:21 2022 +0200 @@ -32,6 +32,9 @@ struct _PuiPrefsApplication { GtkApplication parent_instance; GSettings *settings; + GtkWidget *update_command_entry; + GtkWidget *refresh_interval_combo_box; + GtkWidget *use_mobile_check_button; }; G_DEFINE_TYPE(PuiPrefsApplication, pui_prefs_application, GTK_TYPE_APPLICATION) @@ -117,6 +120,38 @@ } static void +update_widgets(PuiPrefsApplication *self) +{ + gchar ** disabled_preferences; + + g_return_if_fail(self->update_command_entry != NULL); + g_return_if_fail(self->refresh_interval_combo_box != NULL); + g_return_if_fail(self->use_mobile_check_button != NULL); + + disabled_preferences = g_settings_get_strv(self->settings, + "disable-preferences"); + g_return_if_fail(disabled_preferences != NULL); + gtk_widget_set_sensitive(self->update_command_entry, + !g_strv_contains((const gchar * const *)disabled_preferences, + "update-command")); + gtk_widget_set_sensitive(self->refresh_interval_combo_box, + !g_strv_contains((const gchar * const *)disabled_preferences, + "refresh-interval")); + gtk_widget_set_sensitive(self->use_mobile_check_button, + !g_strv_contains((const gchar * const *)disabled_preferences, + "use-mobile-connection")); + g_strfreev(disabled_preferences); +} + +static void +on_disable_preferences_changed(GSettings *settings, gchar *key, + gpointer user_data) +{ + g_debug("setting disable-preferences changed"); + update_widgets(user_data); +} + +static void pui_prefs_application_startup(GApplication *application) { PuiPrefsApplication *self = PUI_PREFS_APPLICATION(application); @@ -125,9 +160,6 @@ GtkBuilder *builder; GtkWidget *window; GtkTreeModel *tree_model; - GtkWidget *update_command_entry; - GtkWidget *refresh_interval_combo_box; - GtkWidget *use_mobile_check_button; application_class->startup(application); @@ -141,25 +173,31 @@ "package-update-indicator/preferences/pui-prefs-window.ui"); window = GTK_WIDGET(gtk_builder_get_object(builder, "window")); gtk_application_add_window(GTK_APPLICATION(self), GTK_WINDOW(window)); - update_command_entry = GTK_WIDGET(gtk_builder_get_object(builder, + self->update_command_entry = GTK_WIDGET(gtk_builder_get_object(builder, "update-command")); - refresh_interval_combo_box = GTK_WIDGET(gtk_builder_get_object(builder, - "refresh-interval")); - tree_model = - gtk_combo_box_get_model(GTK_COMBO_BOX(refresh_interval_combo_box)); - use_mobile_check_button = GTK_WIDGET(gtk_builder_get_object(builder, + self->refresh_interval_combo_box = + GTK_WIDGET(gtk_builder_get_object(builder, "refresh-interval")); + tree_model = gtk_combo_box_get_model( + GTK_COMBO_BOX(self->refresh_interval_combo_box)); + self->use_mobile_check_button = + GTK_WIDGET(gtk_builder_get_object(builder, "use-mobile-connection")); /* bind settings to widgets */ self->settings = pui_settings_new(); g_settings_bind(self->settings, "update-command", - update_command_entry, "text", G_SETTINGS_BIND_DEFAULT); + self->update_command_entry, "text", G_SETTINGS_BIND_DEFAULT); g_settings_bind_with_mapping(self->settings, "refresh-interval", - refresh_interval_combo_box, "active", G_SETTINGS_BIND_DEFAULT, - map_refresh_interval_to_index, map_index_to_refresh_interval, - tree_model, NULL); + self->refresh_interval_combo_box, "active", + G_SETTINGS_BIND_DEFAULT, map_refresh_interval_to_index, + map_index_to_refresh_interval, tree_model, NULL); g_settings_bind(self->settings, "use-mobile-connection", - use_mobile_check_button, "active", G_SETTINGS_BIND_DEFAULT); + self->use_mobile_check_button, "active", G_SETTINGS_BIND_DEFAULT); + + /* watch disable-preferences setting in order to update the window */ + g_signal_connect(self->settings, "changed::disable-preferences", + G_CALLBACK(on_disable_preferences_changed), self); + update_widgets(self); /* show window */ gtk_widget_show(window); @@ -189,6 +227,10 @@ g_clear_object(&self->settings); } + self->update_command_entry = NULL; + self->refresh_interval_combo_box = NULL; + self->use_mobile_check_button = NULL; + G_OBJECT_CLASS(pui_prefs_application_parent_class)->dispose(object); }