Made Fancy's custom stylesheet pref work on Windows
authorAndrej Kacian <ticho@claws-mail.org>
Sun, 22 Oct 2017 15:27:08 +0000 (17:27 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Sun, 22 Oct 2017 15:27:08 +0000 (17:27 +0200)
src/plugins/fancy/fancy_prefs.c
src/plugins/fancy/fancy_viewer.c

index cbba959..a2ca781 100644 (file)
@@ -442,7 +442,15 @@ static void save_fancy_prefs_page(PrefsPage *page)
                fancy_prefs.enable_proxy = gtk_toggle_button_get_active
                                (GTK_TOGGLE_BUTTON(prefs_page->proxy_checkbox));
                fancy_prefs.proxy_str = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->proxy_str));
+#ifdef G_OS_WIN32
+               /* pref_get_pref_from_entry() escapes the backslashes in strings,
+                * we do not want that, since this entry contains a Windows path.
+                * Let's just strdup it. */
+               fancy_prefs.stylesheet = g_strdup(gtk_entry_get_text(
+                                       GTK_ENTRY(prefs_page->stylesheet)));
+#else
                fancy_prefs.stylesheet = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->stylesheet));
+#endif
 
                save_fancy_prefs(page);
 }
index 5aeff3d..81f8f04 100644 (file)
@@ -148,10 +148,29 @@ static void fancy_set_defaults(FancyViewer *viewer)
        viewer->override_prefs_plugins = fancy_prefs.enable_plugins;
        viewer->override_prefs_java = fancy_prefs.enable_java;
 
-       gchar *tmp = g_uri_escape_string(fancy_prefs.stylesheet, "/", TRUE);
+       gchar *tmp;
+#ifdef G_OS_WIN32
+       /* Replace backslashes with forward slashes, since we'll be
+        * using this string in an URI. */
+       gchar *tmp2 = g_strdup(fancy_prefs.stylesheet);
+       gchar *c;
+       for (c = tmp2; *c != '\0'; c++) {
+               if (*c == '\\')
+                       *c = '/';
+       }
+
+       /* Escape string for use in an URI, keeping dir separators
+        * and colon for Windows drive name ("C:") intact. */
+       tmp = g_uri_escape_string(tmp2, "/:", TRUE);
+       g_free(tmp2);
+#else
+       /* Escape string for use in an URI, keeping dir separators
+        * intact. */
+       tmp = g_uri_escape_string(fancy_prefs.stylesheet, "/", TRUE);
+#endif
        viewer->override_stylesheet = g_strconcat("file://", tmp, NULL);
        g_free(tmp);
-       debug_print("Passing '%s' stylesheet URI to Webkit\n",
+       debug_print("Passing '%s' as stylesheet URI to Webkit\n",
                        viewer->override_stylesheet);
 
        g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_images),