Commits

Anonymous committed d93f4b2

vcl115: #i113908# improve some border cases for recent file manager

  • Participants
  • Parent commits 5dd2ac9

Comments (0)

Files changed (1)

File vcl/unx/gtk/app/gtkinst.cxx

 
 #include <rtl/strbuf.hxx>
 
+#include <rtl/uri.hxx>
+
 #if OSL_DEBUG_LEVEL > 1
 #include <stdio.h>
 #endif
 
 void GtkInstance::AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType)
 {
+    rtl::OString sGtkURL;
+    rtl_TextEncoding aSystemEnc = osl_getThreadTextEncoding();
+    if ((aSystemEnc == RTL_TEXTENCODING_UTF8) || (rFileUrl.compareToAscii( "file://", 7 ) !=  0))
+        sGtkURL = rtl::OUStringToOString(rFileUrl, RTL_TEXTENCODING_UTF8);
+    else
+    {
+        //Non-utf8 locales are a bad idea if trying to work with non-ascii filenames
+        //Decode %XX components
+        rtl::OUString sDecodedUri = Uri::decode(rFileUrl.copy(7), rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8);
+        //Convert back to system locale encoding
+        rtl::OString sSystemUrl = rtl::OUStringToOString(sDecodedUri, aSystemEnc);
+        //Encode to an escaped ASCII-encoded URI
+        gchar *g_uri = g_filename_to_uri(sSystemUrl.getStr(), NULL, NULL);
+        sGtkURL = rtl::OString(g_uri);
+        g_free(g_uri);
+    }
 #if GTK_CHECK_VERSION(2,10,0)
     GtkRecentManager *manager = gtk_recent_manager_get_default ();
-    gtk_recent_manager_add_item (manager, rtl::OUStringToOString(rFileUrl, RTL_TEXTENCODING_UTF8).getStr());
+    gtk_recent_manager_add_item (manager, sGtkURL);
     (void)rMimeType;
 #else
     static getDefaultFnc sym_gtk_recent_manager_get_default =
     static addItemFnc sym_gtk_recent_manager_add_item = 
         (addItemFnc)osl_getAsciiFunctionSymbol( GetSalData()->m_pPlugin, "gtk_recent_manager_add_item");
     if (sym_gtk_recent_manager_get_default && sym_gtk_recent_manager_add_item)
-    {
-        sym_gtk_recent_manager_add_item(sym_gtk_recent_manager_get_default(),
-            rtl::OUStringToOString(rFileUrl, RTL_TEXTENCODING_UTF8).getStr());
-    }
+        sym_gtk_recent_manager_add_item(sym_gtk_recent_manager_get_default(), sGtkURL);
     else
         X11SalInstance::AddToRecentDocumentList(rFileUrl, rMimeType);
 #endif