[evince/wip/chpe/export-print-portal-custom-options: 12/12] shell: Migrate custom print setting keys




commit 52c2a08dd56e802bfca51786ebce11797f16dd26
Author: Christian Persch <chpe src gnome org>
Date:   Wed Nov 24 18:48:50 2021 +0100

    shell: Migrate custom print setting keys
    
    The print settings custom options requires options to start with
    a common prefix; migrate the existing settings over when the new
    ones don't exist.

 shell/ev-window.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 634caafa2..5cc358f45 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -3561,13 +3561,38 @@ ev_window_load_print_page_setup_from_metadata (EvWindow     *window,
 static GtkPrintSettings *
 get_print_settings (GKeyFile *key_file)
 {
-       GtkPrintSettings *print_settings;
+       static const char *migrate_keys[] = {
+               "evince-print-setting-page-scale",
+               "evince-print-setting-page-autorotate",
+               "evince-print-setting-page-size",
+               "evince-print-setting-page-draw-borders"
+       };
+       GtkPrintSettings *print_settings = NULL;
+       guint i;
+
+       /* Migrate some keys */
+       for (i = 0; i < G_N_ELEMENTS (migrate_keys); ++i) {
+               const char *key = migrate_keys[i];
+               char *new_key, *value;
+
+               if (!g_key_file_has_key (key_file, EV_PRINT_SETTINGS_GROUP, key, NULL))
+                       continue;
+
+               new_key = g_strdup_printf ("xdp-custom-%s", key);
+               value = g_key_file_get_value (key_file, EV_PRINT_SETTINGS_GROUP, key, NULL);
+
+               g_key_file_remove_key (key_file, EV_PRINT_SETTINGS_GROUP, key, NULL);
+               g_key_file_set_value (key_file, EV_PRINT_SETTINGS_GROUP, new_key, value);
+
+               g_free (new_key);
+               g_free (value);
+       }
 
-       print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
-               gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
-               gtk_print_settings_new ();
+       print_settings = gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL);
+       if (print_settings == NULL)
+               print_settings = gtk_print_settings_new ();
 
-       return print_settings ? print_settings : gtk_print_settings_new ();
+       return print_settings;
 }
 
 static GtkPageSetup *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]