diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/glade-preferences.c | 314 | ||||
-rw-r--r-- | src/glade-preferences.h | 16 | ||||
-rw-r--r-- | src/glade-settings.c | 316 | ||||
-rw-r--r-- | src/glade-settings.h | 46 | ||||
-rw-r--r-- | src/glade-window.c | 41 | ||||
-rw-r--r-- | src/meson.build | 1 |
6 files changed, 514 insertions, 220 deletions
diff --git a/src/glade-preferences.c b/src/glade-preferences.c index cf77ac17..23348f91 100644 --- a/src/glade-preferences.c +++ b/src/glade-preferences.c @@ -24,26 +24,6 @@ #include <gladeui/glade-utils.h> #define CONFIG_GROUP "Preferences" -#define CONFIG_KEY_CATALOG_PATHS "catalog-paths" - -#define CONFIG_GROUP_LOAD_SAVE "Load and Save" -#define CONFIG_KEY_BACKUP "backup" -#define CONFIG_KEY_AUTOSAVE "autosave" -#define CONFIG_KEY_AUTOSAVE_SECONDS "autosave-seconds" - -#define CONFIG_GROUP_SAVE_WARNINGS "Save Warnings" -#define CONFIG_KEY_VERSIONING "versioning" -#define CONFIG_KEY_DEPRECATIONS "deprecations" -#define CONFIG_KEY_UNRECOGNIZED "unrecognized" - -/* Default preference values */ -#define DEFAULT_BACKUP TRUE -#define DEFAULT_AUTOSAVE TRUE -#define DEFAULT_AUTOSAVE_SECONDS 5 -#define DEFAULT_WARN_VERSIONS TRUE -#define DEFAULT_WARN_DEPRECATIONS FALSE -#define DEFAULT_WARN_UNRECOGNIZED TRUE - enum { COLUMN_PATH = 0, COLUMN_CANONICAL_PATH @@ -62,8 +42,17 @@ struct _GladePreferencesPrivate GtkWidget *versioning_toggle; GtkWidget *deprecations_toggle; GtkWidget *unrecognized_toggle; + + GladeSettings *settings; }; +enum +{ + PROP_SETTINGS = 1, + N_PROPERTIES +}; + +static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; G_DEFINE_TYPE_WITH_PRIVATE (GladePreferences, glade_preferences, GTK_TYPE_DIALOG); @@ -169,6 +158,110 @@ catalog_selection_changed (GtkTreeSelection *selection, gtk_widget_set_sensitive (preferences->priv->remove_catalog_button, selected); } +static gboolean +glade_preferences_transform_to (GBinding *binding, + const GValue *from_value, + GValue *to_value, + gpointer user_data) +{ + GladeVerifyFlags flag = (GladeVerifyFlags) user_data; + g_value_set_boolean (to_value, g_value_get_flags (from_value) & flag); + return TRUE; +} + +static gboolean +glade_preferences_transform_from (GBinding *binding, + const GValue *from_value, + GValue *to_value, + gpointer user_data) +{ + GladeVerifyFlags flag = (GladeVerifyFlags) user_data; + GladeVerifyFlags previous_flags = glade_settings_get_verify_flags (GLADE_SETTINGS (g_binding_get_source (binding))); + + if (g_value_get_boolean (from_value)) + g_value_set_flags (to_value, previous_flags | flag); + else + g_value_set_flags (to_value, previous_flags & ~flag); + + return TRUE; +} + +static void +glade_preferences_set_settings (GladePreferences *self, + GladeSettings *settings) +{ + const GList *paths, *l; + + self->priv->settings = settings; + g_object_bind_property (settings, "backup", self->priv->create_backups_toggle, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + g_object_bind_property (settings, "autosave", self->priv->autosave_spin, "sensitive", G_BINDING_SYNC_CREATE); + g_object_bind_property (settings, "autosave", self->priv->autosave_toggle, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + g_object_bind_property (settings, "autosave-seconds", self->priv->autosave_spin, "value", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + g_object_bind_property_full (settings, "verify-flags", self->priv->versioning_toggle, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, + glade_preferences_transform_to, glade_preferences_transform_from, (void *)GLADE_VERIFY_VERSIONS, NULL); + g_object_bind_property_full (settings, "verify-flags", self->priv->deprecations_toggle, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, + glade_preferences_transform_to, glade_preferences_transform_from, (void *)GLADE_VERIFY_DEPRECATIONS, NULL); + g_object_bind_property_full (settings, "verify-flags", self->priv->unrecognized_toggle, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, + glade_preferences_transform_to, glade_preferences_transform_from, (void *)GLADE_VERIFY_UNRECOGNIZED, NULL); + + paths = glade_catalog_get_extra_paths (); + gtk_list_store_clear (GTK_LIST_STORE (self->priv->catalog_path_store)); + for (l = paths; l != NULL; l = l->next) + { + const gchar *path = (const gchar *)(l->data); + gchar *display = glade_utils_replace_home_dir_with_tilde (path); + GtkTreeIter iter; + + gtk_list_store_append (GTK_LIST_STORE (self->priv->catalog_path_store), &iter); + gtk_list_store_set (GTK_LIST_STORE (self->priv->catalog_path_store), &iter, + COLUMN_PATH, display, + COLUMN_CANONICAL_PATH, path, + -1); + + g_free (display); + } +} + +static void +glade_preferences_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GladePreferences *self = GLADE_PREFERENCES (object); + + switch (property_id) + { + case PROP_SETTINGS: + glade_preferences_set_settings (self, GLADE_SETTINGS (g_value_get_object (value))); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +glade_preferences_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GladePreferences *self = GLADE_PREFERENCES (object); + + switch (property_id) + { + case PROP_SETTINGS: + g_value_set_object (value, self->priv->settings); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + /******************************************************** * Class/Instance Init * ********************************************************/ @@ -184,6 +277,21 @@ static void glade_preferences_class_init (GladePreferencesClass *klass) { GtkWidgetClass *widget_class; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = glade_preferences_set_property; + object_class->get_property = glade_preferences_get_property; + + obj_properties[PROP_SETTINGS] = + g_param_spec_object ("settings", + "Settings", + "Settings object.", + GLADE_TYPE_SETTINGS, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, + N_PROPERTIES, + obj_properties); widget_class = GTK_WIDGET_CLASS (klass); @@ -216,167 +324,9 @@ glade_preferences_class_init (GladePreferencesClass *klass) * API * ********************************************************/ GtkWidget * -glade_preferences_new (void) -{ - return g_object_new (GLADE_TYPE_PREFERENCES, NULL); -} - -void -glade_preferences_save (GladePreferences *prefs, - GKeyFile *config) -{ - GtkTreeModel *model = prefs->priv->catalog_path_store; - GString *string = g_string_new (""); - GtkTreeIter iter; - gboolean valid; - - valid = gtk_tree_model_get_iter_first (model, &iter); - while (valid) - { - gchar *path; - - gtk_tree_model_get (model, &iter, COLUMN_CANONICAL_PATH, &path, -1); - - valid = gtk_tree_model_iter_next (model, &iter); - - g_string_append (string, path); - if (valid) g_string_append (string, ":"); - - g_free (path); - } - - g_key_file_set_string (config, CONFIG_GROUP, CONFIG_KEY_CATALOG_PATHS, string->str); - - /* Load and save */ - g_key_file_set_boolean (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, - glade_preferences_backup (prefs)); - g_key_file_set_boolean (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE, - glade_preferences_autosave (prefs)); - g_key_file_set_integer (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE_SECONDS, - glade_preferences_autosave_seconds (prefs)); - - /* Warnings */ - g_key_file_set_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, - glade_preferences_warn_versioning (prefs)); - g_key_file_set_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, - glade_preferences_warn_deprecations (prefs)); - g_key_file_set_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, - glade_preferences_warn_unrecognized (prefs)); - - g_string_free (string, TRUE); -} - -void -glade_preferences_load (GladePreferences *prefs, - GKeyFile *config) -{ - gboolean backups = DEFAULT_BACKUP; - gboolean autosave = DEFAULT_AUTOSAVE; - gboolean warn_versioning = DEFAULT_WARN_VERSIONS; - gboolean warn_deprecations = DEFAULT_WARN_DEPRECATIONS; - gboolean warn_unrecognized = DEFAULT_WARN_UNRECOGNIZED; - gint autosave_seconds = DEFAULT_AUTOSAVE_SECONDS; - gchar *string; - - string = g_key_file_get_string (config, CONFIG_GROUP, CONFIG_KEY_CATALOG_PATHS, NULL); - - if (string && g_strcmp0 (string, "")) - { - gchar **paths, **path; - - gtk_list_store_clear (GTK_LIST_STORE (prefs->priv->catalog_path_store)); - glade_catalog_remove_path (NULL); - - paths = g_strsplit (string, ":", -1); - - path = paths; - do - { - GtkTreeIter iter; - gchar *canonical, *display; - - canonical = glade_util_canonical_path (*path); - display = glade_utils_replace_home_dir_with_tilde (canonical); - - glade_catalog_add_path (canonical); - - gtk_list_store_append (GTK_LIST_STORE (prefs->priv->catalog_path_store), &iter); - gtk_list_store_set (GTK_LIST_STORE (prefs->priv->catalog_path_store), &iter, - COLUMN_PATH, display, - COLUMN_CANONICAL_PATH, canonical, - -1); - g_free (display); - g_free (canonical); - - } while (*++path); - - g_strfreev (paths); - } - - /* Load and save */ - if (g_key_file_has_key (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, NULL)) - backups = g_key_file_get_boolean (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, NULL); - - if (g_key_file_has_key (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE, NULL)) - autosave = g_key_file_get_boolean (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE, NULL); - - if (g_key_file_has_key (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE_SECONDS, NULL)) - autosave_seconds = g_key_file_get_integer (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE_SECONDS, NULL); - - /* Warnings */ - if (g_key_file_has_key (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, NULL)) - warn_versioning = g_key_file_get_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, NULL); - - if (g_key_file_has_key (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, NULL)) - warn_deprecations = g_key_file_get_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, NULL); - - if (g_key_file_has_key (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, NULL)) - warn_unrecognized = g_key_file_get_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, NULL); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->create_backups_toggle), backups); - gtk_widget_set_sensitive (prefs->priv->autosave_spin, autosave); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->autosave_toggle), autosave); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (prefs->priv->autosave_spin), autosave_seconds); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->versioning_toggle), warn_versioning); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->deprecations_toggle), warn_deprecations); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->unrecognized_toggle), warn_unrecognized); - - g_free (string); -} - -gboolean -glade_preferences_backup (GladePreferences *prefs) -{ - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->create_backups_toggle)); -} - -gboolean -glade_preferences_autosave (GladePreferences *prefs) -{ - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->autosave_toggle)); -} - -gint -glade_preferences_autosave_seconds (GladePreferences *prefs) -{ - return (gint)gtk_spin_button_get_value (GTK_SPIN_BUTTON (prefs->priv->autosave_spin)); -} - -gboolean -glade_preferences_warn_versioning (GladePreferences *prefs) -{ - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->versioning_toggle)); -} - -gboolean -glade_preferences_warn_deprecations (GladePreferences *prefs) -{ - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->deprecations_toggle)); -} - -gboolean -glade_preferences_warn_unrecognized (GladePreferences *prefs) +glade_preferences_new (GladeSettings *settings) { - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->unrecognized_toggle)); + return g_object_new (GLADE_TYPE_PREFERENCES, + "settings", settings, + NULL); } diff --git a/src/glade-preferences.h b/src/glade-preferences.h index 874855d5..490d5b32 100644 --- a/src/glade-preferences.h +++ b/src/glade-preferences.h @@ -24,6 +24,7 @@ #define __GLADE_PREFERENCES_H__ #include <gtk/gtk.h> +#include "glade-settings.h" G_BEGIN_DECLS @@ -52,20 +53,7 @@ struct _GladePreferencesClass }; GType glade_preferences_get_type (void) G_GNUC_CONST; -GtkWidget *glade_preferences_new (void); - -void glade_preferences_save (GladePreferences *prefs, - GKeyFile *config); -void glade_preferences_load (GladePreferences *prefs, - GKeyFile *config); - -gboolean glade_preferences_backup (GladePreferences *prefs); -gboolean glade_preferences_autosave (GladePreferences *prefs); -gint glade_preferences_autosave_seconds (GladePreferences *prefs); - -gboolean glade_preferences_warn_versioning (GladePreferences *prefs); -gboolean glade_preferences_warn_deprecations(GladePreferences *prefs); -gboolean glade_preferences_warn_unrecognized(GladePreferences *prefs); +GtkWidget *glade_preferences_new (GladeSettings *settings); G_END_DECLS diff --git a/src/glade-settings.c b/src/glade-settings.c new file mode 100644 index 00000000..c26683b7 --- /dev/null +++ b/src/glade-settings.c @@ -0,0 +1,316 @@ +/* + * Copyright 2019 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Authors: + * Corentin Noël <corentin.noel@collabora.com> + */ +#include <gladeui/glade-catalog.h> +#include <gladeui/glade-utils.h> +#include <gladeui/gladeui-enum-types.h> + +#include "glade-settings.h" + +#define CONFIG_GROUP "Preferences" +#define CONFIG_KEY_CATALOG_PATHS "catalog-paths" + +#define CONFIG_GROUP_LOAD_SAVE "Load and Save" +#define CONFIG_KEY_BACKUP "backup" +#define CONFIG_KEY_AUTOSAVE "autosave" +#define CONFIG_KEY_AUTOSAVE_SECONDS "autosave-seconds" + +#define CONFIG_GROUP_SAVE_WARNINGS "Save Warnings" +#define CONFIG_KEY_VERSIONING "versioning" +#define CONFIG_KEY_DEPRECATIONS "deprecations" +#define CONFIG_KEY_UNRECOGNIZED "unrecognized" + +struct _GladeSettings +{ + GObject parent_instance; + + gboolean backup; + gboolean autosave; + gint autosave_seconds; + GladeVerifyFlags flags; +}; + +enum +{ + PROP_BACKUP = 1, + PROP_AUTOSAVE, + PROP_AUTOSAVE_SECONDS, + PROP_VERIFY_FLAGS, + N_PROPERTIES +}; + +static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; + +G_DEFINE_TYPE (GladeSettings, glade_settings, G_TYPE_OBJECT) + +static void +glade_settings_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GladeSettings *self = GLADE_SETTINGS (object); + + switch (property_id) + { + case PROP_BACKUP: + self->backup = g_value_get_boolean (value); + break; + + case PROP_AUTOSAVE: + self->autosave = g_value_get_boolean (value); + break; + + case PROP_AUTOSAVE_SECONDS: + self->autosave_seconds = g_value_get_int (value); + break; + + case PROP_VERIFY_FLAGS: + self->flags = g_value_get_flags (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +glade_settings_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GladeSettings *self = GLADE_SETTINGS (object); + + switch (property_id) + { + case PROP_BACKUP: + g_value_set_boolean (value, self->backup); + break; + + case PROP_AUTOSAVE: + g_value_set_boolean (value, self->autosave); + break; + + case PROP_AUTOSAVE_SECONDS: + g_value_set_int (value, self->autosave_seconds); + break; + + case PROP_VERIFY_FLAGS: + g_value_set_flags (value, self->flags); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +glade_settings_class_init (GladeSettingsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = glade_settings_set_property; + object_class->get_property = glade_settings_get_property; + + obj_properties[PROP_BACKUP] = + g_param_spec_boolean ("backup", + "Backup", + "Whether a backup of the edited file is required.", + TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + obj_properties[PROP_AUTOSAVE] = + g_param_spec_boolean ("autosave", + "Autosave", + "Save the files automatically.", + TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + obj_properties[PROP_AUTOSAVE_SECONDS] = + g_param_spec_int ("autosave-seconds", + "Autosave Seconds", + "Time in seconds for saving the files automatically.", + G_MININT, G_MAXINT, 5, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + obj_properties[PROP_VERIFY_FLAGS] = + g_param_spec_flags ("verify-flags", + "Verify flags", + "Verify Flags.", + GLADE_TYPE_VERIFY_FLAGS, + GLADE_VERIFY_VERSIONS | GLADE_VERIFY_UNRECOGNIZED, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, + N_PROPERTIES, + obj_properties); +} + +static void +glade_settings_init (GladeSettings *self) +{ + self->backup = TRUE; + self->autosave = TRUE; + self->autosave_seconds = 5; + self->flags = GLADE_VERIFY_VERSIONS | GLADE_VERIFY_UNRECOGNIZED; +} + +GladeSettings * +glade_settings_new (void) +{ + return g_object_new (GLADE_TYPE_SETTINGS, NULL); +} + +void +glade_settings_save (GladeSettings *self, + GKeyFile *file) +{ + const GList *paths, *l; + GString *string; + + g_return_if_fail (GLADE_IS_SETTINGS (self)); + + string = g_string_new (""); + paths = glade_catalog_get_extra_paths (); + for (l = paths; l != NULL; l = l->next) + { + const gchar *path = (const gchar *)(l->data); + g_string_append (string, path); + if (l->next != NULL) + g_string_append (string, ":"); + } + + g_key_file_set_string (file, CONFIG_GROUP, CONFIG_KEY_CATALOG_PATHS, + string->str); + + g_key_file_set_boolean (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, + self->backup); + g_key_file_set_boolean (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE, + self->autosave); + g_key_file_set_integer (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE_SECONDS, + self->autosave_seconds); + + g_key_file_set_boolean (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, + self->flags & GLADE_VERIFY_VERSIONS); + g_key_file_set_boolean (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, + self->flags & GLADE_VERIFY_DEPRECATIONS); + g_key_file_set_boolean (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, + self->flags & GLADE_VERIFY_UNRECOGNIZED); + + g_string_free (string, TRUE); +} + +void +glade_settings_load (GladeSettings *self, + GKeyFile *file) +{ + gchar *paths_string; + + g_return_if_fail (GLADE_IS_SETTINGS (self)); + + paths_string = g_key_file_get_string (file, CONFIG_GROUP, CONFIG_KEY_CATALOG_PATHS, NULL); + if (paths_string && g_strcmp0 (paths_string, "")) + { + gchar **paths = g_strsplit (paths_string, ":", -1); + guint paths_len = g_strv_length (paths); + + glade_catalog_remove_path (NULL); + + for (guint i = 0; i < paths_len; i++) + { + gchar *canonical = glade_util_canonical_path (paths[i]); + glade_catalog_add_path (canonical); + g_free (canonical); + } + + g_strfreev (paths); + } + g_free (paths_string); + + /* Load and save */ + if (g_key_file_has_key (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, NULL)) + self->backup = g_key_file_get_boolean (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, NULL); + + if (g_key_file_has_key (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE, NULL)) + self->autosave = g_key_file_get_boolean (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE, NULL); + + if (g_key_file_has_key (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE_SECONDS, NULL)) + self->autosave_seconds = g_key_file_get_integer (file, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE_SECONDS, NULL); + + /* Warnings */ + if (g_key_file_has_key (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, NULL)) + { + if (g_key_file_get_boolean (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, NULL)) + self->flags |= GLADE_VERIFY_VERSIONS; + else + self->flags &= ~GLADE_VERIFY_VERSIONS; + } + + if (g_key_file_has_key (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, NULL)) + { + if (g_key_file_get_boolean (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, NULL)) + self->flags |= GLADE_VERIFY_DEPRECATIONS; + else + self->flags &= ~GLADE_VERIFY_DEPRECATIONS; + } + + if (g_key_file_has_key (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, NULL)) + { + if (g_key_file_get_boolean (file, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, NULL)) + self->flags |= GLADE_VERIFY_UNRECOGNIZED; + else + self->flags &= ~GLADE_VERIFY_UNRECOGNIZED; + } +} + +gboolean +glade_settings_backup (GladeSettings *self) +{ + g_return_val_if_fail (GLADE_IS_SETTINGS (self), FALSE); + + return self->backup; +} + +gboolean +glade_settings_autosave (GladeSettings *self) +{ + g_return_val_if_fail (GLADE_IS_SETTINGS (self), FALSE); + + return self->autosave; +} + +gint +glade_settings_autosave_seconds (GladeSettings *self) +{ + g_return_val_if_fail (GLADE_IS_SETTINGS (self), 0); + + return self->autosave_seconds; +} + +GladeVerifyFlags +glade_settings_get_verify_flags (GladeSettings *self) +{ + g_return_val_if_fail (GLADE_IS_SETTINGS (self), 0); + + return self->flags; +} diff --git a/src/glade-settings.h b/src/glade-settings.h new file mode 100644 index 00000000..ddd0ca5c --- /dev/null +++ b/src/glade-settings.h @@ -0,0 +1,46 @@ +/* + * Copyright 2019 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Authors: + * Corentin Noël <corentin.noel@collabora.com> + */ + +#ifndef __GLADE_SETTINGS_H__ +#define __GLADE_SETTINGS_H__ + +#include <gio/gio.h> +#include <gladeui/glade-project.h> + +G_BEGIN_DECLS + +#define GLADE_TYPE_SETTINGS glade_settings_get_type () +G_DECLARE_FINAL_TYPE (GladeSettings, glade_settings, GLADE, SETTINGS, GObject) + +GladeSettings *glade_settings_new (void); +void glade_settings_save (GladeSettings *self, + GKeyFile *file); +void glade_settings_load (GladeSettings *self, + GKeyFile *file); + +gboolean glade_settings_backup (GladeSettings *self); +gboolean glade_settings_autosave (GladeSettings *self); +gint glade_settings_autosave_seconds (GladeSettings *self); +GladeVerifyFlags glade_settings_get_verify_flags (GladeSettings *self); + +G_END_DECLS + +#endif /* __GLADE_SETTINGS_H__ */ diff --git a/src/glade-window.c b/src/glade-window.c index 253ff961..9863a61a 100644 --- a/src/glade-window.c +++ b/src/glade-window.c @@ -30,6 +30,7 @@ #include "glade-resources.h" #include "glade-preferences.h" #include "glade-registration.h" +#include "glade-settings.h" #include "glade-intro.h" #include <gladeui/glade.h> @@ -90,7 +91,7 @@ struct _GladeWindowPrivate GtkHeaderBar *headerbar; GtkWidget *project_switcher ; GtkWindow *about_dialog; - GladePreferences *preferences; + GladeSettings *settings; GtkWidget *start_page; GtkLabel *version_label; @@ -509,10 +510,10 @@ project_queue_autosave (GladeWindow *window, GladeProject *project) { if (glade_project_get_path (project) != NULL && glade_project_get_modified (project) && - glade_preferences_autosave (window->priv->preferences)) + glade_settings_autosave (window->priv->settings)) { guint autosave_id = - g_timeout_add_seconds (glade_preferences_autosave_seconds (window->priv->preferences), + g_timeout_add_seconds (glade_settings_autosave_seconds (window->priv->settings), autosave_project, project); g_object_set_data_full (G_OBJECT (project), "glade-autosave-id", @@ -762,10 +763,10 @@ static gboolean do_save (GladeWindow *window, GladeProject *project, const gchar *path) { GError *error = NULL; - GladeVerifyFlags verify_flags = 0; + GladeVerifyFlags verify_flags = glade_settings_get_verify_flags (window->priv->settings); gchar *display_path = g_strdup (path); - if (glade_preferences_backup (window->priv->preferences) && + if (glade_settings_backup (window->priv->settings) && !glade_project_backup (project, path, NULL)) { if (!glade_util_ui_message (GTK_WIDGET (window), @@ -777,13 +778,6 @@ do_save (GladeWindow *window, GladeProject *project, const gchar *path) } } - if (glade_preferences_warn_versioning (window->priv->preferences)) - verify_flags |= GLADE_VERIFY_VERSIONS; - if (glade_preferences_warn_deprecations (window->priv->preferences)) - verify_flags |= GLADE_VERIFY_DEPRECATIONS; - if (glade_preferences_warn_unrecognized (window->priv->preferences)) - verify_flags |= GLADE_VERIFY_UNRECOGNIZED; - if (!glade_project_save_verify (project, path, verify_flags, &error)) { if (error) @@ -1477,7 +1471,14 @@ on_preferences_action_activate (GSimpleAction *action, gpointer data) { GladeWindow *window = data; - gtk_widget_show (GTK_WIDGET (window->priv->preferences)); + GladeWindowPrivate *priv = window->priv; + GtkWidget *preferences = glade_preferences_new (priv->settings); + + gtk_window_set_transient_for (GTK_WINDOW (preferences), GTK_WINDOW (window)); + gtk_widget_show (preferences); + + gtk_dialog_run (GTK_DIALOG (preferences)); + gtk_widget_destroy (preferences); } static void @@ -1925,7 +1926,7 @@ glade_window_config_save (GladeWindow * window) save_paned_position (config, window->priv->center_paned, "center_pane"); save_paned_position (config, window->priv->left_paned, "left_pane"); - glade_preferences_save (window->priv->preferences, config); + glade_settings_save (window->priv->settings, config); glade_app_config_save (); } @@ -2119,15 +2120,8 @@ glade_window_init (GladeWindow *window) priv->default_path = NULL; - /* Init preferences first, this has to be done before anything initializes - * the real GladeApp, so that catalog paths are loaded correctly before we - * continue. - * - * This should be fixed so that dynamic addition of catalogs at runtime - * is supported. - */ - priv->preferences = (GladePreferences *)glade_preferences_new (); - glade_preferences_load (window->priv->preferences, glade_app_get_config ()); + priv->settings = glade_settings_new (); + glade_settings_load (priv->settings, glade_app_get_config ()); /* We need this for the icons to be available */ glade_init (); @@ -2143,7 +2137,6 @@ glade_window_init (GladeWindow *window) static void glade_window_action_handler (GladeWindow *window, const gchar *name) { - GladeWindowPrivate *priv = window->priv; GAction *action; if ((action = GLADE_WINDOW_GET_ACTION (window, name))) diff --git a/src/meson.build b/src/meson.build index 2be16e73..28e8fd97 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,6 +3,7 @@ sources = files( 'glade-intro.c', 'glade-preferences.c', 'glade-registration.c', + 'glade-settings.c', 'glade-window.c', 'main.c', ) |