X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fui%2Fdialog%2Ffiledialog.cpp;h=2a5ededbb475bf88fd9f0f35b722587cb484a9fd;hb=4d79affe53b5c0e7dbc67014aee9be5251dc56df;hp=0cdd49477ef32b9cf9474333e3ac8c541d698080;hpb=b8f395d240c30bc66890313f4bbb2ce6b75930cb;p=inkscape.git diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp index 0cdd49477..2a5ededbb 100644 --- a/src/ui/dialog/filedialog.cpp +++ b/src/ui/dialog/filedialog.cpp @@ -1,47 +1,46 @@ -/* +/** * Implementation of the file dialog interfaces defined in filedialog.h * * Authors: * Bob Jamison * Other dudes from The Inkscape Organization * + * Copyright (C) 2004-2007 Bob Jamison * Copyright (C) 2006 Johan Engelen - * Copyright (C) 2004-2006 The Inkscape Organization + * Copyright (C) 2004-2007 The Inkscape Organization * * Released under GNU GPL, read the file 'COPYING' for more information */ + #ifdef HAVE_CONFIG_H # include #endif +//General includes +#include +#include +#include +#include - +//Gtk includes +#include +#include +#include //Temporary ugly hack -//Remove these after the get_filter() calls in +//Remove this after the get_filter() calls in //show() on both classes are fixed #include - //Another hack #include #include +#ifdef WITH_GNOME_VFS +# include // gnome_vfs_initialized +#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + +//Inkscape includes #include "prefs-utils.h" #include #include @@ -56,6 +55,7 @@ #include "ui/widget/scalar-unit.h" +//Routines from file.cpp #undef INK_DUMP_FILENAME_CONV #ifdef INK_DUMP_FILENAME_CONV @@ -63,6 +63,8 @@ void dump_str( const gchar* str, const gchar* prefix ); void dump_ustr( const Glib::ustring& ustr ); #endif + + namespace Inkscape { namespace UI @@ -240,13 +242,18 @@ bool SVGPreview::setDocument(SPDocument *doc) return true; } + bool SVGPreview::setFileName(Glib::ustring &theFileName) { Glib::ustring fileName = 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; @@ -332,7 +339,7 @@ void SVGPreview::showImage(Glib::ustring &theFileName) "\n" + "width=\"%d\" height=\"%d\">\n" //# VALUES HERE "\n" @@ -348,7 +355,7 @@ void SVGPreview::showImage(Glib::ustring &theFileName) " style=\"font-size:24.000000;font-style:normal;font-weight:normal;" " fill:#000000;fill-opacity:1.0000000;stroke:none;" " font-family:Bitstream Vera Sans\"\n" - " x=\"10\" y=\"26\">%d x %d\n" + " x=\"10\" y=\"26\">%d x %d\n" //# VALUES HERE "\n\n"; //if (!Glib::get_charset()) //If we are not utf8 @@ -388,7 +395,7 @@ void SVGPreview::showNoPreview() "\n" + "width=\"%d\" height=\"%d\">\n" //# VALUES HERE "\n" "%s\n" + "x=\"190\" y=\"240\">%s\n" //# VALUE HERE "\n\n"; //Fill in the template @@ -467,6 +474,11 @@ void SVGPreview::showNoPreview() } + +/** + * Inform the user that the svg file is too large to be displayed. + * This does not check for sizes of embedded images (yet) + */ void SVGPreview::showTooLarge(long fileLength) { @@ -480,7 +492,7 @@ void SVGPreview::showTooLarge(long fileLength) "\n" + "width=\"%d\" height=\"%d\">\n" //# VALUES HERE "\n" "%5.1f MB\n" + "x=\"170\" y=\"215\">%5.1f MB\n" //# VALUE HERE "%s\n" + "x=\"180\" y=\"245\">%s\n" //# VALUE HERE "\n\n"; //Fill in the template @@ -622,8 +634,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) return false; - gchar *fName = (gchar *)fileName.c_str(); - //g_message("fname:%s\n", fName); + //g_message("fname:%s", fileName.c_str()); if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) { showNoPreview(); @@ -632,9 +643,13 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { + Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName); + gchar *fName = (gchar *)fileNameUtf8.c_str(); struct stat info; - if (stat(fName, &info)) + if (g_stat(fName, &info)) { + g_warning("SVGPreview::set() : %s : %s", + fName, strerror(errno)); return FALSE; } long fileLen = info.st_size; @@ -645,7 +660,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) return FALSE; } } - + Glib::ustring svg = ".svg"; Glib::ustring svgz = ".svgz"; @@ -760,7 +775,10 @@ private: void FileDialogBase::internalSetup() { - bool enablePreview = (bool)prefs_get_int_attribute( preferenceBase.c_str(), "enable_preview", 1 ); + bool enablePreview = + (bool)prefs_get_int_attribute( preferenceBase.c_str(), + "enable_preview", 1 ); + previewCheckbox.set_label( Glib::ustring(_("Enable Preview")) ); previewCheckbox.set_active( enablePreview ); @@ -778,13 +796,15 @@ void FileDialogBase::internalSetup() } + void FileDialogBase::cleanup( bool showConfirmed ) { - if ( showConfirmed ) { - prefs_set_int_attribute( preferenceBase.c_str(), "enable_preview", previewCheckbox.get_active() ); - } + if ( showConfirmed ) + prefs_set_int_attribute( preferenceBase.c_str(), + "enable_preview", previewCheckbox.get_active() ); } + void FileDialogBase::_previewEnabledCB() { bool enabled = previewCheckbox.get_active(); @@ -795,23 +815,25 @@ void FileDialogBase::_previewEnabledCB() } + /** * Callback for checking if the preview needs to be redrawn */ 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); -// bool retval = svgPreview.set(fileName, dialogType); -// set_preview_widget_active(retval); } @@ -938,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 */ @@ -1030,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 ); @@ -1073,7 +1097,7 @@ std::vectorFileOpenDialogImpl::getFilenames() { std::vector result = get_filenames(); #ifdef WITH_GNOME_VFS - if (result.empty()) + if (result.empty() && gnome_vfs_initialized()) result = get_uris(); #endif return result; @@ -1294,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 */ @@ -1447,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(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); } @@ -1467,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++ ) { @@ -1541,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 @@ -1554,7 +1579,7 @@ void FileSaveDialogImpl::updateNameAndExtension() try { bool appendExtension = true; Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename ); - size_t pos = utf8Name.rfind('.'); + Glib::ustring::size_type pos = utf8Name.rfind('.'); if ( pos != Glib::ustring::npos ) { Glib::ustring trail = utf8Name.substr( pos ); Glib::ustring foldedTrail = trail.casefold(); @@ -1916,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 */ @@ -2125,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 /*