Code

more unreffing temporary styles properly
[inkscape.git] / src / ui / dialog / filedialog.cpp
index 25390d56fa20e6e8f0571be763d240bdc94f48ea..2a5ededbb475bf88fd9f0f35b722587cb484a9fd 100644 (file)
@@ -20,6 +20,7 @@
 //General includes
 #include <unistd.h>
 #include <sys/stat.h>
+#include <errno.h>
 #include <set>
 
 //Gtk includes
@@ -33,6 +34,9 @@
 //Another hack
 #include <gtk/gtkentry.h>
 #include <gtk/gtkexpander.h>
+#ifdef WITH_GNOME_VFS
+# include <libgnomevfs/gnome-vfs-init.h>  // gnome_vfs_initialized
+#endif
 
 
 
@@ -59,7 +63,6 @@ void dump_str( const gchar* str, const gchar* prefix );
 void dump_ustr( const Glib::ustring& ustr );
 #endif
 
-extern int errno;
 
 
 namespace Inkscape
@@ -246,7 +249,11 @@ bool SVGPreview::setFileName(Glib::ustring &theFileName)
 
     fileName = Glib::filename_to_utf8(fileName);
 
-    SPDocument *doc = sp_document_new (fileName.c_str(), 0);
+    /**
+     * I don't know why passing false to keepalive is bad.  But it
+     * prevents the display of an svg with a non-ascii filename
+     */              
+    SPDocument *doc = sp_document_new (fileName.c_str(), true);
     if (!doc) {
         g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
         return false;
@@ -627,7 +634,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
     if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
         return false;
 
-    g_message("fname:%s", fileName.c_str());
+    //g_message("fname:%s", fileName.c_str());
 
     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
         showNoPreview();
@@ -817,12 +824,14 @@ void FileDialogBase::_updatePreviewCallback()
     Glib::ustring fileName = get_preview_filename();
 
 #ifdef WITH_GNOME_VFS
-    if (fileName.length() < 1)
+    if ( fileName.empty() && gnome_vfs_initialized() ) {
         fileName = get_preview_uri();
+    }
 #endif
 
-    if (fileName.length() < 1)
+    if (fileName.empty()) {
         return;
+    }
 
     svgPreview.set(fileName, dialogType);
 }
@@ -951,7 +960,9 @@ FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
     set_select_multiple(true);
 
 #ifdef WITH_GNOME_VFS
-    set_local_only(false);
+    if (gnome_vfs_initialized()) {
+        set_local_only(false);
+    }
 #endif
 
     /* Initalize to Autodetect */
@@ -1043,7 +1054,7 @@ FileOpenDialogImpl::show()
             }
         myFilename = get_filename();
 #ifdef WITH_GNOME_VFS
-        if (myFilename.length() < 1)
+        if (myFilename.empty() && gnome_vfs_initialized())
             myFilename = get_uri();
 #endif
         cleanup( true );
@@ -1086,7 +1097,7 @@ std::vector<Glib::ustring>FileOpenDialogImpl::getFilenames()
 {    
     std::vector<Glib::ustring> result = get_filenames();
 #ifdef WITH_GNOME_VFS
-    if (result.empty())
+    if (result.empty() && gnome_vfs_initialized())
         result = get_uris();
 #endif
     return result;
@@ -1307,7 +1318,9 @@ FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir,
     set_select_multiple(false);
 
 #ifdef WITH_GNOME_VFS
-    set_local_only(false);
+    if (gnome_vfs_initialized()) {
+        set_local_only(false);
+    }
 #endif
 
     /* Initalize to Autodetect */
@@ -1460,18 +1473,16 @@ FileSaveDialogImpl::getSelectionType()
 
 void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
 {
-    extension = key;
-
     // If no pointer to extension is passed in, look up based on filename extension.
-    if ( !extension ) {
+    if ( !key ) {
         // Not quite UTF-8 here.
         gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
-        for ( int i = 0; !extension && (i < (int)fileTypes.size()); i++ ) {
+        for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
             Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
             if ( ext && ext->get_extension() ) {
                 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
                 if ( g_str_has_suffix(filenameLower, extensionLower) ) {
-                    extension = fileTypes[i].extension;
+                    key = fileTypes[i].extension;
                 }
                 g_free(extensionLower);
             }
@@ -1480,7 +1491,8 @@ void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key
     }
 
     // Ensure the proper entry in the combo box is selected.
-    if ( extension ) {
+    if ( key ) {
+        extension = key;
         gchar const * extensionID = extension->get_id();
         if ( extensionID ) {
             for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
@@ -1554,7 +1566,7 @@ void FileSaveDialogImpl::updateNameAndExtension()
     // Pick up any changes the user has typed in.
     Glib::ustring tmp = get_filename();
 #ifdef WITH_GNOME_VFS
-    if ( tmp.empty() ) {
+    if ( tmp.empty() && gnome_vfs_initialized() ) {
         tmp = get_uri();
     }
 #endif
@@ -1929,7 +1941,9 @@ FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir,
     set_select_multiple(false);
 
 #ifdef WITH_GNOME_VFS
-    set_local_only(false);
+    if (gnome_vfs_initialized()) {
+        set_local_only(false);
+    }
 #endif
 
     /* Initalize to Autodetect */
@@ -2138,8 +2152,9 @@ FileExportDialogImpl::show()
             }
         myFilename = get_filename();
 #ifdef WITH_GNOME_VFS
-        if (myFilename.length() < 1)
+        if ( myFilename.empty() && gnome_vfs_initialized() ) {
             myFilename = get_uri();
+        }
 #endif
 
         /*