Code

0bc68f86269c8db7777400a9594704a3e1180368
[inkscape.git] / src / file.cpp
1 /** @file
2  * @brief File/Print operations
3  */
4 /* Authors:
5  *   Lauris Kaplinski <lauris@kaplinski.com>
6  *   Chema Celorio <chema@celorio.com>
7  *   bulia byak <buliabyak@users.sf.net>
8  *   Bruno Dilly <bruno.dilly@gmail.com>
9  *   Stephen Silver <sasilver@users.sourceforge.net>
10  *
11  * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
12  * Copyright (C) 1999-2008 Authors
13  * Copyright (C) 2004 David Turner
14  * Copyright (C) 2001-2002 Ximian, Inc.
15  *
16  * Released under GNU GPL, read the file 'COPYING' for more information
17  */
19 /** @file
20  * @note This file needs to be cleaned up extensively.
21  * What it probably needs is to have one .h file for
22  * the API, and two or more .cpp files for the implementations.
23  */
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <gtk/gtk.h>
30 #include <glib/gmem.h>
31 #include <glibmm/i18n.h>
32 #include <libnr/nr-pixops.h>
34 #include "application/application.h"
35 #include "application/editor.h"
36 #include "desktop.h"
37 #include "desktop-handles.h"
38 #include "dialogs/export.h"
39 #include "dir-util.h"
40 #include "document-private.h"
41 #include "extension/db.h"
42 #include "extension/input.h"
43 #include "extension/output.h"
44 #include "extension/system.h"
45 #include "file.h"
46 #include "helper/png-write.h"
47 #include "id-clash.h"
48 #include "inkscape.h"
49 #include "inkscape.h"
50 #include "interface.h"
51 #include "io/sys.h"
52 #include "message.h"
53 #include "message-stack.h"
54 #include "path-prefix.h"
55 #include "preferences.h"
56 #include "print.h"
57 #include "rdf.h"
58 #include "selection-chemistry.h"
59 #include "selection.h"
60 #include "sp-namedview.h"
61 #include "style.h"
62 #include "ui/dialog/filedialog.h"
63 #include "ui/dialog/ocaldialogs.h"
64 #include "ui/view/view-widget.h"
65 #include "uri.h"
66 #include "xml/rebase-hrefs.h"
68 #ifdef WITH_GNOME_VFS
69 # include <libgnomevfs/gnome-vfs.h>
70 #endif
72 #ifdef WITH_INKBOARD
73 #include "jabber_whiteboard/session-manager.h"
74 #endif
76 #ifdef WIN32
77 #include <windows.h>
78 #endif
80 //#define INK_DUMP_FILENAME_CONV 1
81 #undef INK_DUMP_FILENAME_CONV
83 //#define INK_DUMP_FOPEN 1
84 #undef INK_DUMP_FOPEN
86 void dump_str(gchar const *str, gchar const *prefix);
87 void dump_ustr(Glib::ustring const &ustr);
89 // what gets passed here is not actually an URI... it is an UTF-8 encoded filename (!)
90 static void sp_file_add_recent(gchar const *uri)
91 {
92     GtkRecentManager *recent = gtk_recent_manager_get_default();
93     gchar *fn = g_filename_from_utf8(uri, -1, NULL, NULL, NULL);
94     if (fn) {
95         gchar *uri_to_add = g_filename_to_uri(fn, NULL, NULL);
96         if (uri_to_add) {
97             gtk_recent_manager_add_item(recent, uri_to_add);
98             g_free(uri_to_add);
99         }
100         g_free(fn);
101     }
105 /*######################
106 ## N E W
107 ######################*/
109 /**
110  * Create a blank document and add it to the desktop
111  */
112 SPDesktop*
113 sp_file_new(const Glib::ustring &templ)
115     char *templName = NULL;
116     if (templ.size()>0)
117         templName = (char *)templ.c_str();
118     SPDocument *doc = sp_document_new(templName, TRUE, true);
119     g_return_val_if_fail(doc != NULL, NULL);
121     SPDesktop *dt;
122     if (Inkscape::NSApplication::Application::getNewGui())
123     {
124         dt = Inkscape::NSApplication::Editor::createDesktop (doc);
125     } else {
126         SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
127         g_return_val_if_fail(dtw != NULL, NULL);
128         sp_document_unref(doc);
130         sp_create_window(dtw, TRUE);
131         dt = static_cast<SPDesktop*>(dtw->view);
132         sp_namedview_window_from_document(dt);
133         sp_namedview_update_layers_from_document(dt);
134     }
135     return dt;
138 SPDesktop*
139 sp_file_new_default()
141     std::list<gchar *> sources;
142     sources.push_back( profile_path("templates") ); // first try user's local dir
143     sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
145     while (!sources.empty()) {
146         gchar *dirname = sources.front();
147         if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) {
149             // TRANSLATORS: default.svg is localizable - this is the name of the default document
150             //  template. This way you can localize the default pagesize, translate the name of
151             //  the default layer, etc. If you wish to localize this file, please create a
152             //  localized share/templates/default.xx.svg file, where xx is your language code.
153             char *default_template = g_build_filename(dirname, _("default.svg"), NULL);
154             if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) {
155                 return sp_file_new(default_template);
156             }
157         }
158         g_free(dirname);
159         sources.pop_front();
160     }
162     return sp_file_new("");
166 /*######################
167 ## D E L E T E
168 ######################*/
170 /**
171  *  Perform document closures preceding an exit()
172  */
173 void
174 sp_file_exit()
176     sp_ui_close_all();
177     // no need to call inkscape_exit here; last document being closed will take care of that
181 /*######################
182 ## O P E N
183 ######################*/
185 /**
186  *  Open a file, add the document to the desktop
187  *
188  *  \param replace_empty if true, and the current desktop is empty, this document
189  *  will replace the empty one.
190  */
191 bool
192 sp_file_open(const Glib::ustring &uri,
193              Inkscape::Extension::Extension *key,
194              bool add_to_recent, bool replace_empty)
196     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
197     if (desktop)
198         desktop->setWaitingCursor();
200     SPDocument *doc = NULL;
201     try {
202         doc = Inkscape::Extension::open(key, uri.c_str());
203     } catch (Inkscape::Extension::Input::no_extension_found &e) {
204         doc = NULL;
205     } catch (Inkscape::Extension::Input::open_failed &e) {
206         doc = NULL;
207     }
209     if (desktop)
210         desktop->clearWaitingCursor();
212     if (doc) {
213         SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;
215         if (existing && existing->virgin && replace_empty) {
216             // If the current desktop is empty, open the document there
217             sp_document_ensure_up_to_date (doc);
218             desktop->change_document(doc);
219             sp_document_resized_signal_emit (doc, sp_document_width(doc), sp_document_height(doc));
220         } else {
221             if (!Inkscape::NSApplication::Application::getNewGui()) {
222                 // create a whole new desktop and window
223                 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
224                 sp_create_window(dtw, TRUE);
225                 desktop = static_cast<SPDesktop*>(dtw->view);
226             } else {
227                 desktop = Inkscape::NSApplication::Editor::createDesktop (doc);
228             }
229         }
231         doc->virgin = FALSE;
232         // everyone who cares now has a reference, get rid of ours
233         sp_document_unref(doc);
234         // resize the window to match the document properties
235         sp_namedview_window_from_document(desktop);
236         sp_namedview_update_layers_from_document(desktop);
238         if (add_to_recent) {
239             sp_file_add_recent(SP_DOCUMENT_URI(doc));
240         }
242         return TRUE;
243     } else {
244         gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
245         gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), safeUri);
246         sp_ui_error_dialog(text);
247         g_free(text);
248         g_free(safeUri);
249         return FALSE;
250     }
253 /**
254  *  Handle prompting user for "do you want to revert"?  Revert on "OK"
255  */
256 void
257 sp_file_revert_dialog()
259     SPDesktop  *desktop = SP_ACTIVE_DESKTOP;
260     g_assert(desktop != NULL);
262     SPDocument *doc = sp_desktop_document(desktop);
263     g_assert(doc != NULL);
265     Inkscape::XML::Node     *repr = sp_document_repr_root(doc);
266     g_assert(repr != NULL);
268     gchar const *uri = doc->uri;
269     if (!uri) {
270         desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet.  Cannot revert."));
271         return;
272     }
274     bool do_revert = true;
275     if (doc->isModifiedSinceSave()) {
276         gchar *text = g_strdup_printf(_("Changes will be lost!  Are you sure you want to reload document %s?"), uri);
278         bool response = desktop->warnDialog (text);
279         g_free(text);
281         if (!response) {
282             do_revert = false;
283         }
284     }
286     bool reverted;
287     if (do_revert) {
288         // Allow overwriting of current document.
289         doc->virgin = TRUE;
291         // remember current zoom and view
292         double zoom = desktop->current_zoom();
293         Geom::Point c = desktop->get_display_area().midpoint();
295         reverted = sp_file_open(uri,NULL);
296         if (reverted) {
297             // restore zoom and view
298             desktop->zoom_absolute(c[Geom::X], c[Geom::Y], zoom);
299         }
300     } else {
301         reverted = false;
302     }
304     if (reverted) {
305         desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document reverted."));
306     } else {
307         desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not reverted."));
308     }
311 void dump_str(gchar const *str, gchar const *prefix)
313     Glib::ustring tmp;
314     tmp = prefix;
315     tmp += " [";
316     size_t const total = strlen(str);
317     for (unsigned i = 0; i < total; i++) {
318         gchar *const tmp2 = g_strdup_printf(" %02x", (0x0ff & str[i]));
319         tmp += tmp2;
320         g_free(tmp2);
321     }
323     tmp += "]";
324     g_message("%s", tmp.c_str());
327 void dump_ustr(Glib::ustring const &ustr)
329     char const *cstr = ustr.c_str();
330     char const *data = ustr.data();
331     Glib::ustring::size_type const byteLen = ustr.bytes();
332     Glib::ustring::size_type const dataLen = ustr.length();
333     Glib::ustring::size_type const cstrLen = strlen(cstr);
335     g_message("   size: %lu\n   length: %lu\n   bytes: %lu\n    clen: %lu",
336               gulong(ustr.size()), gulong(dataLen), gulong(byteLen), gulong(cstrLen) );
337     g_message( "  ASCII? %s", (ustr.is_ascii() ? "yes":"no") );
338     g_message( "  UTF-8? %s", (ustr.validate() ? "yes":"no") );
340     try {
341         Glib::ustring tmp;
342         for (Glib::ustring::size_type i = 0; i < ustr.bytes(); i++) {
343             tmp = "    ";
344             if (i < dataLen) {
345                 Glib::ustring::value_type val = ustr.at(i);
346                 gchar* tmp2 = g_strdup_printf( (((val & 0xff00) == 0) ? "  %02x" : "%04x"), val );
347                 tmp += tmp2;
348                 g_free( tmp2 );
349             } else {
350                 tmp += "    ";
351             }
353             if (i < byteLen) {
354                 int val = (0x0ff & data[i]);
355                 gchar *tmp2 = g_strdup_printf("    %02x", val);
356                 tmp += tmp2;
357                 g_free( tmp2 );
358                 if ( val > 32 && val < 127 ) {
359                     tmp2 = g_strdup_printf( "   '%c'", (gchar)val );
360                     tmp += tmp2;
361                     g_free( tmp2 );
362                 } else {
363                     tmp += "    . ";
364                 }
365             } else {
366                 tmp += "       ";
367             }
369             if ( i < cstrLen ) {
370                 int val = (0x0ff & cstr[i]);
371                 gchar* tmp2 = g_strdup_printf("    %02x", val);
372                 tmp += tmp2;
373                 g_free(tmp2);
374                 if ( val > 32 && val < 127 ) {
375                     tmp2 = g_strdup_printf("   '%c'", (gchar) val);
376                     tmp += tmp2;
377                     g_free( tmp2 );
378                 } else {
379                     tmp += "    . ";
380                 }
381             } else {
382                 tmp += "            ";
383             }
385             g_message( "%s", tmp.c_str() );
386         }
387     } catch (...) {
388         g_message("XXXXXXXXXXXXXXXXXX Exception" );
389     }
390     g_message("---------------");
393 /**
394  *  Display an file Open selector.  Open a document if OK is pressed.
395  *  Can select single or multiple files for opening.
396  */
397 void
398 sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
400     //# Get the current directory for finding files
401     static Glib::ustring open_path;
402     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
404     if(open_path.empty())
405     {
406         Glib::ustring attr = prefs->getString("/dialogs/open/path");
407         if (!attr.empty()) open_path = attr;
408     }
410     //# Test if the open_path directory exists
411     if (!Inkscape::IO::file_test(open_path.c_str(),
412               (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
413         open_path = "";
415 #ifdef WIN32
416     //# If no open path, default to our win32 documents folder
417     if (open_path.empty())
418     {
419         // The path to the My Documents folder is read from the
420         // value "HKEY_CURRENT_USER\Software\Windows\CurrentVersion\Explorer\Shell Folders\Personal"
421         HKEY key = NULL;
422         if(RegOpenKeyExA(HKEY_CURRENT_USER,
423             "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
424             0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
425         {
426             WCHAR utf16path[_MAX_PATH];
427             DWORD value_type;
428             DWORD data_size = sizeof(utf16path);
429             if(RegQueryValueExW(key, L"Personal", NULL, &value_type,
430                 (BYTE*)utf16path, &data_size) == ERROR_SUCCESS)
431             {
432                 g_assert(value_type == REG_SZ);
433                 gchar *utf8path = g_utf16_to_utf8(
434                     (const gunichar2*)utf16path, -1, NULL, NULL, NULL);
435                 if(utf8path)
436                 {
437                     open_path = Glib::ustring(utf8path);
438                     g_free(utf8path);
439                 }
440             }
441         }
442     }
443 #endif
445     //# If no open path, default to our home directory
446     if (open_path.empty())
447     {
448         open_path = g_get_home_dir();
449         open_path.append(G_DIR_SEPARATOR_S);
450     }
452     //# Create a dialog
453     Inkscape::UI::Dialog::FileOpenDialog *openDialogInstance =
454               Inkscape::UI::Dialog::FileOpenDialog::create(
455                  parentWindow, open_path,
456                  Inkscape::UI::Dialog::SVG_TYPES,
457                  _("Select file to open"));
459     //# Show the dialog
460     bool const success = openDialogInstance->show();
462     //# Save the folder the user selected for later
463     open_path = openDialogInstance->getCurrentDirectory();
465     if (!success)
466     {
467         delete openDialogInstance;
468         return;
469     }
471     //# User selected something.  Get name and type
472     Glib::ustring fileName = openDialogInstance->getFilename();
474     Inkscape::Extension::Extension *selection =
475             openDialogInstance->getSelectionType();
477     //# Code to check & open if multiple files.
478     std::vector<Glib::ustring> flist = openDialogInstance->getFilenames();
480     //# We no longer need the file dialog object - delete it
481     delete openDialogInstance;
482     openDialogInstance = NULL;
484     //# Iterate through filenames if more than 1
485     if (flist.size() > 1)
486     {
487         for (unsigned int i = 0; i < flist.size(); i++)
488         {
489             fileName = flist[i];
491             Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
492             if ( newFileName.size() > 0 )
493                 fileName = newFileName;
494             else
495                 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
497 #ifdef INK_DUMP_FILENAME_CONV
498             g_message("Opening File %s\n", fileName.c_str());
499 #endif
500             sp_file_open(fileName, selection);
501         }
503         return;
504     }
507     if (!fileName.empty())
508     {
509         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
511         if ( newFileName.size() > 0)
512             fileName = newFileName;
513         else
514             g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
516         open_path = Glib::path_get_dirname (fileName);
517         open_path.append(G_DIR_SEPARATOR_S);
518         prefs->setString("/dialogs/open/path", open_path);
520         sp_file_open(fileName, selection);
521     }
523     return;
527 /*######################
528 ## V A C U U M
529 ######################*/
531 /**
532  * Remove unreferenced defs from the defs section of the document.
533  */
536 void
537 sp_file_vacuum()
539     SPDocument *doc = SP_ACTIVE_DOCUMENT;
541     unsigned int diff = vacuum_document (doc);
543     sp_document_done(doc, SP_VERB_FILE_VACUUM,
544                      _("Vacuum &lt;defs&gt;"));
546     SPDesktop *dt = SP_ACTIVE_DESKTOP;
547     if (diff > 0) {
548         dt->messageStack()->flashF(Inkscape::NORMAL_MESSAGE,
549                 ngettext("Removed <b>%i</b> unused definition in &lt;defs&gt;.",
550                          "Removed <b>%i</b> unused definitions in &lt;defs&gt;.",
551                          diff),
552                 diff);
553     } else {
554         dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE,  _("No unused definitions in &lt;defs&gt;."));
555     }
560 /*######################
561 ## S A V E
562 ######################*/
564 /**
565  * This 'save' function called by the others below
566  *
567  * \param    official  whether to set :output_module and :modified in the
568  *                     document; is true for normal save, false for temporary saves
569  */
570 static bool
571 file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
572           Inkscape::Extension::Extension *key, bool saveas, bool official)
574     if (!doc || uri.size()<1) //Safety check
575         return false;
577     try {
578         Inkscape::Extension::save(key, doc, uri.c_str(),
579                  false,
580                  saveas, official);
581     } catch (Inkscape::Extension::Output::no_extension_found &e) {
582         gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
583         gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s).  This may have been caused by an unknown filename extension."), safeUri);
584         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
585         sp_ui_error_dialog(text);
586         g_free(text);
587         g_free(safeUri);
588         return FALSE;
589     } catch (Inkscape::Extension::Output::save_failed &e) {
590         gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
591         gchar *text = g_strdup_printf(_("File %s could not be saved."), safeUri);
592         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
593         sp_ui_error_dialog(text);
594         g_free(text);
595         g_free(safeUri);
596         return FALSE;
597     } catch (Inkscape::Extension::Output::save_cancelled &e) {
598         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
599         return FALSE;
600     } catch (Inkscape::Extension::Output::no_overwrite &e) {
601         return sp_file_save_dialog(parentWindow, doc);
602     }
604     SP_ACTIVE_DESKTOP->event_log->rememberFileSave();
605     SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document saved."));
606     return true;
609 /*
610  * Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp.
611  */
612 bool
613 file_save_remote(SPDocument */*doc*/,
614     #ifdef WITH_GNOME_VFS
615                  const Glib::ustring &uri,
616     #else
617                  const Glib::ustring &/*uri*/,
618     #endif
619                  Inkscape::Extension::Extension */*key*/, bool /*saveas*/, bool /*official*/)
621 #ifdef WITH_GNOME_VFS
623 #define BUF_SIZE 8192
624     gnome_vfs_init();
626     GnomeVFSHandle    *from_handle = NULL;
627     GnomeVFSHandle    *to_handle = NULL;
628     GnomeVFSFileSize  bytes_read;
629     GnomeVFSFileSize  bytes_written;
630     GnomeVFSResult    result;
631     guint8 buffer[8192];
633     gchar* uri_local = g_filename_from_utf8( uri.c_str(), -1, NULL, NULL, NULL);
635     if ( uri_local == NULL ) {
636         g_warning( "Error converting filename to locale encoding.");
637     }
639     // Gets the temp file name.
640     Glib::ustring fileName = Glib::get_tmp_dir ();
641     fileName.append(G_DIR_SEPARATOR_S);
642     fileName.append((gnome_vfs_uri_extract_short_name(gnome_vfs_uri_new(uri_local))));
644     // Open the temp file to send.
645     result = gnome_vfs_open (&from_handle, fileName.c_str(), GNOME_VFS_OPEN_READ);
647     if (result != GNOME_VFS_OK) {
648         g_warning("Could not find the temp saving.");
649         return false;
650     }
652     result = gnome_vfs_create (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
653     result = gnome_vfs_open (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE);
655     if (result != GNOME_VFS_OK) {
656         g_warning("file creating: %s", gnome_vfs_result_to_string(result));
657         return false;
658     }
660     while (1) {
662         result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
664         if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
665             result = gnome_vfs_close (from_handle);
666             result = gnome_vfs_close (to_handle);
667             return true;
668         }
670         if (result != GNOME_VFS_OK) {
671             g_warning("%s", gnome_vfs_result_to_string(result));
672             return false;
673         }
674         result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
675         if (result != GNOME_VFS_OK) {
676             g_warning("%s", gnome_vfs_result_to_string(result));
677             return false;
678         }
681         if (bytes_read != bytes_written){
682             return false;
683         }
685     }
686     return true;
687 #else
688     // in case we do not have GNOME_VFS
689     return false;
690 #endif
695 /**
696  *  Display a SaveAs dialog.  Save the document if OK pressed.
697  *
698  * \param    ascopy  (optional) wether to set the documents->uri to the new filename or not
699  */
700 bool
701 sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
704     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
705     Inkscape::Extension::Output *extension = 0;
706     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
708     //# Get the default extension name
709     Glib::ustring default_extension;
710     char *attr = (char *)repr->attribute("inkscape:output_extension");
711     if (!attr) {
712         Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
713         if(!attr2.empty()) default_extension = attr2;
714     } else {
715         default_extension = attr;
716     }
717     //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
719     Glib::ustring save_path;
720     Glib::ustring save_loc;
722     if (doc->uri == NULL) {
723         char formatBuf[256];
724         int i = 1;
726         Glib::ustring filename_extension = ".svg";
727         extension = dynamic_cast<Inkscape::Extension::Output *>
728               (Inkscape::Extension::db.get(default_extension.c_str()));
729         //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
730         if (extension)
731             filename_extension = extension->get_extension();
733         Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
734         if (!attr3.empty())
735             save_path = attr3;
737         if (!Inkscape::IO::file_test(save_path.c_str(),
738               (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
739             save_path = "";
741         if (save_path.size()<1)
742             save_path = g_get_home_dir();
744         save_loc = save_path;
745         save_loc.append(G_DIR_SEPARATOR_S);
746         snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
747         save_loc.append(formatBuf);
749         while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) {
750             save_loc = save_path;
751             save_loc.append(G_DIR_SEPARATOR_S);
752             snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str());
753             save_loc.append(formatBuf);
754         }
755     } else {
756         save_loc = Glib::build_filename(Glib::path_get_dirname(doc->uri),
757                                         Glib::path_get_basename(doc->uri));
758     }
760     // convert save_loc from utf-8 to locale
761     // is this needed any more, now that everything is handled in
762     // Inkscape::IO?
763     Glib::ustring save_loc_local = Glib::filename_from_utf8(save_loc);
765     if ( save_loc_local.size() > 0)
766         save_loc = save_loc_local;
768     //# Show the SaveAs dialog
769     char const * dialog_title;
770     if (is_copy) {
771         dialog_title = (char const *) _("Select file to save a copy to");
772     } else {
773         dialog_title = (char const *) _("Select file to save to");
774     }
775     gchar* doc_title = doc->root->title();
776     Inkscape::UI::Dialog::FileSaveDialog *saveDialog =
777         Inkscape::UI::Dialog::FileSaveDialog::create(
778             parentWindow,
779             save_loc,
780             Inkscape::UI::Dialog::SVG_TYPES,
781             dialog_title,
782             default_extension,
783             doc_title ? doc_title : ""
784             );
786     saveDialog->setSelectionType(extension);
788     bool success = saveDialog->show();
789     if (!success) {
790         delete saveDialog;
791         return success;
792     }
794     // set new title here (call RDF to ensure metadata and title element are updated)
795     rdf_set_work_entity(doc, rdf_find_entity("title"), saveDialog->getDocTitle().c_str());
796     // free up old string
797     if(doc_title) g_free(doc_title);
799     Glib::ustring fileName = saveDialog->getFilename();
800     Inkscape::Extension::Extension *selectionType = saveDialog->getSelectionType();
802     delete saveDialog;
804     saveDialog = 0;
806     if (fileName.size() > 0) {
807         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
809         if ( newFileName.size()>0 )
810             fileName = newFileName;
811         else
812             g_warning( "Error converting save filename to UTF-8." );
814         success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy);
816         if (success) {
817             sp_file_add_recent(SP_DOCUMENT_URI(doc));
818         }
820         save_path = Glib::path_get_dirname(fileName);
821         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
822         prefs->setString("/dialogs/save_as/path", save_path);
824         return success;
825     }
828     return false;
832 /**
833  * Save a document, displaying a SaveAs dialog if necessary.
834  */
835 bool
836 sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc)
838     bool success = true;
840     if (doc->isModifiedSinceSave()) {
841         Inkscape::XML::Node *repr = sp_document_repr_root(doc);
842         if ( doc->uri == NULL
843             || repr->attribute("inkscape:output_extension") == NULL )
844         {
845             return sp_file_save_dialog(parentWindow, doc, FALSE);
846         } else {
847             gchar const *fn = g_strdup(doc->uri);
848             gchar const *ext = repr->attribute("inkscape:output_extension");
849             success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE);
850             g_free((void *) fn);
851         }
852     } else {
853         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved."));
854         success = TRUE;
855     }
857     return success;
861 /**
862  * Save a document.
863  */
864 bool
865 sp_file_save(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
867     if (!SP_ACTIVE_DOCUMENT)
868         return false;
870     SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Saving document..."));
872     sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
873     return sp_file_save_document(parentWindow, SP_ACTIVE_DOCUMENT);
877 /**
878  *  Save a document, always displaying the SaveAs dialog.
879  */
880 bool
881 sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
883     if (!SP_ACTIVE_DOCUMENT)
884         return false;
885     sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
886     return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, FALSE);
891 /**
892  *  Save a copy of a document, always displaying a sort of SaveAs dialog.
893  */
894 bool
895 sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
897     if (!SP_ACTIVE_DOCUMENT)
898         return false;
899     sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
900     return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, TRUE);
904 /*######################
905 ## I M P O R T
906 ######################*/
908 /**
909  *  Import a resource.  Called by sp_file_import()
910  */
911 void
912 file_import(SPDocument *in_doc, const Glib::ustring &uri,
913                Inkscape::Extension::Extension *key)
915     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
917     //DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
918     SPDocument *doc;
919     try {
920         doc = Inkscape::Extension::open(key, uri.c_str());
921     } catch (Inkscape::Extension::Input::no_extension_found &e) {
922         doc = NULL;
923     } catch (Inkscape::Extension::Input::open_failed &e) {
924         doc = NULL;
925     }
927     if (doc != NULL) {
928         Inkscape::XML::rebase_hrefs(doc, in_doc->base, true);
929         Inkscape::XML::Document *xml_in_doc = sp_document_repr_doc(in_doc);
931         prevent_id_clashes(doc, in_doc);
933         SPObject *in_defs = SP_DOCUMENT_DEFS(in_doc);
934         Inkscape::XML::Node *last_def = SP_OBJECT_REPR(in_defs)->lastChild();
936         SPCSSAttr *style = sp_css_attr_from_object(SP_DOCUMENT_ROOT(doc));
938         // Count the number of top-level items in the imported document.
939         guint items_count = 0;
940         for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
941              child != NULL; child = SP_OBJECT_NEXT(child))
942         {
943             if (SP_IS_ITEM(child)) items_count++;
944         }
946         // Create a new group if necessary.
947         Inkscape::XML::Node *newgroup = NULL;
948         if ((style && style->firstChild()) || items_count > 1) {
949             newgroup = xml_in_doc->createElement("svg:g");
950             sp_repr_css_set(newgroup, style, "style");
951         }
953         // Determine the place to insert the new object.
954         // This will be the current layer, if possible.
955         // FIXME: If there's no desktop (command line run?) we need
956         //        a document:: method to return the current layer.
957         //        For now, we just use the root in this case.
958         SPObject *place_to_insert;
959         if (desktop) {
960             place_to_insert = desktop->currentLayer();
961         } else {
962             place_to_insert = SP_DOCUMENT_ROOT(in_doc);
963         }
965         // Construct a new object representing the imported image,
966         // and insert it into the current document.
967         SPObject *new_obj = NULL;
968         for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
969              child != NULL; child = SP_OBJECT_NEXT(child) )
970         {
971             if (SP_IS_ITEM(child)) {
972                 Inkscape::XML::Node *newitem = SP_OBJECT_REPR(child)->duplicate(xml_in_doc);
974                 // convert layers to groups, and make sure they are unlocked
975                 // FIXME: add "preserve layers" mode where each layer from
976                 //        import is copied to the same-named layer in host
977                 newitem->setAttribute("inkscape:groupmode", NULL);
978                 newitem->setAttribute("sodipodi:insensitive", NULL);
980                 if (newgroup) newgroup->appendChild(newitem);
981                 else new_obj = place_to_insert->appendChildRepr(newitem);
982             }
984             // don't lose top-level defs or style elements
985             else if (SP_OBJECT_REPR(child)->type() == Inkscape::XML::ELEMENT_NODE) {
986                 const gchar *tag = SP_OBJECT_REPR(child)->name();
987                 if (!strcmp(tag, "svg:defs")) {
988                     for (SPObject *x = sp_object_first_child(child);
989                          x != NULL; x = SP_OBJECT_NEXT(x))
990                     {
991                         SP_OBJECT_REPR(in_defs)->addChild(SP_OBJECT_REPR(x)->duplicate(xml_in_doc), last_def);
992                     }
993                 }
994                 else if (!strcmp(tag, "svg:style")) {
995                     SP_DOCUMENT_ROOT(in_doc)->appendChildRepr(SP_OBJECT_REPR(child)->duplicate(xml_in_doc));
996                 }
997             }
998         }
999         if (newgroup) new_obj = place_to_insert->appendChildRepr(newgroup);
1001         // release some stuff
1002         if (newgroup) Inkscape::GC::release(newgroup);
1003         if (style) sp_repr_css_attr_unref(style);
1005         // select and move the imported item
1006         if (new_obj && SP_IS_ITEM(new_obj)) {
1007             Inkscape::Selection *selection = sp_desktop_selection(desktop);
1008             selection->set(SP_ITEM(new_obj));
1010             // To move the imported object, we must temporarily set the "transform pattern with
1011             // object" option.
1012             {
1013                 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1014                 bool const saved_pref = prefs->getBool("/options/transform/pattern", true);
1015                 prefs->setBool("/options/transform/pattern", true);
1016                 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1017                 Geom::OptRect sel_bbox = selection->bounds();
1018                 if (sel_bbox) {
1019                     Geom::Point m( desktop->point() - sel_bbox->midpoint() );
1020                     sp_selection_move_relative(selection, m);
1021                 }
1022                 prefs->setBool("/options/transform/pattern", saved_pref);
1023             }
1024         }
1026         sp_document_unref(doc);
1027         sp_document_done(in_doc, SP_VERB_FILE_IMPORT,
1028                          _("Import"));
1030     } else {
1031         gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), uri.c_str());
1032         sp_ui_error_dialog(text);
1033         g_free(text);
1034     }
1036     return;
1040 /**
1041  *  Display an Open dialog, import a resource if OK pressed.
1042  */
1043 void
1044 sp_file_import(Gtk::Window &parentWindow)
1046     static Glib::ustring import_path;
1048     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1049     if (!doc)
1050         return;
1052     // Create new dialog (don't use an old one, because parentWindow has probably changed)
1053     Inkscape::UI::Dialog::FileOpenDialog *importDialogInstance =
1054              Inkscape::UI::Dialog::FileOpenDialog::create(
1055                  parentWindow,
1056                  import_path,
1057                  Inkscape::UI::Dialog::IMPORT_TYPES,
1058                  (char const *)_("Select file to import"));
1060     bool success = importDialogInstance->show();
1061     if (!success) {
1062         delete importDialogInstance;
1063         return;
1064     }
1066     //# Get file name and extension type
1067     Glib::ustring fileName = importDialogInstance->getFilename();
1068     Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1070     delete importDialogInstance;
1071     importDialogInstance = NULL;
1073     if (fileName.size() > 0) {
1075         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1077         if ( newFileName.size() > 0)
1078             fileName = newFileName;
1079         else
1080             g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1083         import_path = fileName;
1084         if (import_path.size()>0)
1085             import_path.append(G_DIR_SEPARATOR_S);
1087         file_import(doc, fileName, selection);
1088     }
1090     return;
1095 /*######################
1096 ## E X P O R T
1097 ######################*/
1099 //#define NEW_EXPORT_DIALOG
1103 #ifdef NEW_EXPORT_DIALOG
1105 /**
1106  *  Display an Export dialog, export as the selected type if OK pressed
1107  */
1108 bool
1109 sp_file_export_dialog(void *widget)
1111     //# temp hack for 'doc' until we can switch to this dialog
1112     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1114     Glib::ustring export_path;
1115     Glib::ustring export_loc;
1117     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
1118     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1119     Inkscape::Extension::Output *extension;
1121     //# Get the default extension name
1122     Glib::ustring default_extension;
1123     char *attr = (char *)repr->attribute("inkscape:output_extension");
1124     if (!attr) {
1125         Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
1126         if(!attr2.empty()) default_extension = attr2;
1127     } else {
1128         default_extension = attr;
1129     }
1130     //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
1132     if (doc->uri == NULL)
1133         {
1134         char formatBuf[256];
1136         Glib::ustring filename_extension = ".svg";
1137         extension = dynamic_cast<Inkscape::Extension::Output *>
1138               (Inkscape::Extension::db.get(default_extension.c_str()));
1139         //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
1140         if (extension)
1141             filename_extension = extension->get_extension();
1143         Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
1144         if (!attr3.empty())
1145             export_path = attr3;
1147         if (!Inkscape::IO::file_test(export_path.c_str(),
1148               (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1149             export_path = "";
1151         if (export_path.size()<1)
1152             export_path = g_get_home_dir();
1154         export_loc = export_path;
1155         export_loc.append(G_DIR_SEPARATOR_S);
1156         snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1157         export_loc.append(formatBuf);
1159         }
1160     else
1161         {
1162         export_path = Glib::path_get_dirname(doc->uri);
1163         }
1165     // convert save_loc from utf-8 to locale
1166     // is this needed any more, now that everything is handled in
1167     // Inkscape::IO?
1168     Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1169     if ( export_path_local.size() > 0)
1170         export_path = export_path_local;
1172     //# Show the SaveAs dialog
1173     Inkscape::UI::Dialog::FileExportDialog *exportDialogInstance = 
1174         Inkscape::UI::Dialog::FileExportDialog::create(
1175             export_path,
1176             Inkscape::UI::Dialog::EXPORT_TYPES,
1177             (char const *) _("Select file to export to"),
1178             default_extension
1179         );
1181     bool success = exportDialogInstance->show();
1182     if (!success) {
1183         delete exportDialogInstance;
1184         return success;
1185     }
1187     Glib::ustring fileName = exportDialogInstance->getFilename();
1189     Inkscape::Extension::Extension *selectionType =
1190         exportDialogInstance->getSelectionType();
1192     delete exportDialogInstance;
1193     exportDialogInstance = NULL;
1195     if (fileName.size() > 0) {
1196         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1198         if ( newFileName.size()>0 )
1199             fileName = newFileName;
1200         else
1201             g_warning( "Error converting save filename to UTF-8." );
1203         success = file_save(doc, fileName, selectionType, TRUE, FALSE);
1205         if (success) {
1206             Glib::RefPtr<Gtk::RecentManager> recent = Gtk::RecentManager::get_default();
1207             recent->add_item(SP_DOCUMENT_URI(doc));
1208         }
1210         export_path = fileName;
1211         prefs->setString("/dialogs/save_as/path", export_path);
1213         return success;
1214     }
1217     return false;
1220 #else
1222 /**
1223  *
1224  */
1225 bool
1226 sp_file_export_dialog(void */*widget*/)
1228     sp_export_dialog();
1229     return true;
1232 #endif
1234 /*######################
1235 ## E X P O R T  T O  O C A L
1236 ######################*/
1238 /**
1239  *  Display an Export dialog, export as the selected type if OK pressed
1240  */
1241 bool
1242 sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow)
1245    if (!SP_ACTIVE_DOCUMENT)
1246         return false;
1248     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1250     Glib::ustring export_path;
1251     Glib::ustring export_loc;
1252     Glib::ustring fileName;
1253     Inkscape::Extension::Extension *selectionType;
1255     bool success = false;
1257     static bool gotSuccess = false;
1259     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
1260     (void)repr;
1262     if (!doc->uri && !doc->isModifiedSinceSave())
1263         return false;
1265     //  Get the default extension name
1266     Glib::ustring default_extension = "org.inkscape.output.svg.inkscape";
1267     char formatBuf[256];
1269     Glib::ustring filename_extension = ".svg";
1270     selectionType = Inkscape::Extension::db.get(default_extension.c_str());
1272     export_path = Glib::get_tmp_dir ();
1274     export_loc = export_path;
1275     export_loc.append(G_DIR_SEPARATOR_S);
1276     snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1277     export_loc.append(formatBuf);
1279     // convert save_loc from utf-8 to locale
1280     // is this needed any more, now that everything is handled in
1281     // Inkscape::IO?
1282     Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1283     if ( export_path_local.size() > 0)
1284         export_path = export_path_local;
1286     // Show the Export To OCAL dialog
1287     Inkscape::UI::Dialog::FileExportToOCALDialog *exportDialogInstance =
1288         new Inkscape::UI::Dialog::FileExportToOCALDialog(
1289                 parentWindow,
1290                 Inkscape::UI::Dialog::EXPORT_TYPES,
1291                 (char const *) _("Select file to export to")
1292                 );
1294     success = exportDialogInstance->show();
1295     if (!success) {
1296         delete exportDialogInstance;
1297         return success;
1298     }
1300     fileName = exportDialogInstance->getFilename();
1302     delete exportDialogInstance;
1303     exportDialogInstance = NULL;;
1305     fileName.append(filename_extension.c_str());
1306     if (fileName.size() > 0) {
1307         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1309         if ( newFileName.size()>0 )
1310             fileName = newFileName;
1311         else
1312             g_warning( "Error converting save filename to UTF-8." );
1313     }
1314     Glib::ustring filePath = export_path;
1315     filePath.append(G_DIR_SEPARATOR_S);
1316     filePath.append(Glib::path_get_basename(fileName));
1318     fileName = filePath;
1320     success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE);
1322     if (!success){
1323         gchar *text = g_strdup_printf(_("Error saving a temporary copy"));
1324         sp_ui_error_dialog(text);
1326         return success;
1327     }
1329     // Start now the submition
1331     // Create the uri
1332     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1333     Glib::ustring uri = "dav://";
1334     Glib::ustring username = prefs->getString("/options/ocalusername/str");
1335     Glib::ustring password = prefs->getString("/options/ocalpassword/str");
1336     if (username.empty() || password.empty())
1337     {
1338         Inkscape::UI::Dialog::FileExportToOCALPasswordDialog *exportPasswordDialogInstance = NULL;
1339         if(!gotSuccess)
1340         {
1341             exportPasswordDialogInstance = new Inkscape::UI::Dialog::FileExportToOCALPasswordDialog(
1342                     parentWindow,
1343                     (char const *) _("Open Clip Art Login"));
1344             success = exportPasswordDialogInstance->show();
1345             if (!success) {
1346                 delete exportPasswordDialogInstance;
1347                 return success;
1348             }
1349         }
1350         username = exportPasswordDialogInstance->getUsername();
1351         password = exportPasswordDialogInstance->getPassword();
1353         delete exportPasswordDialogInstance;
1354         exportPasswordDialogInstance = NULL;
1355     }
1356     uri.append(username);
1357     uri.append(":");
1358     uri.append(password);
1359     uri.append("@");
1360     uri.append(prefs->getString("/options/ocalurl/str"));
1361     uri.append("/dav.php/");
1362     uri.append(Glib::path_get_basename(fileName));
1364     // Save as a remote file using the dav protocol.
1365     success = file_save_remote(doc, uri, selectionType, FALSE, FALSE);
1366     remove(fileName.c_str());
1367     if (!success)
1368     {
1369         gchar *text = g_strdup_printf(_("Error exporting the document. Verify if the server name, username and password are correct, if the server has support for webdav and verify if you didn't forget to choose a license."));
1370         sp_ui_error_dialog(text);
1371     }
1372     else
1373         gotSuccess = true;
1375     return success;
1378 /**
1379  * Export the current document to OCAL
1380  */
1381 void
1382 sp_file_export_to_ocal(Gtk::Window &parentWindow)
1385     // Try to execute the new code and return;
1386     if (!SP_ACTIVE_DOCUMENT)
1387         return;
1388     bool success = sp_file_export_to_ocal_dialog(parentWindow);
1389     if (success)
1390         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Document exported..."));
1394 /*######################
1395 ## I M P O R T  F R O M  O C A L
1396 ######################*/
1398 /**
1399  * Display an ImportToOcal Dialog, and the selected document from OCAL
1400  */
1401 void
1402 sp_file_import_from_ocal(Gtk::Window &parentWindow)
1404     static Glib::ustring import_path;
1406     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1407     if (!doc)
1408         return;
1410     Inkscape::UI::Dialog::FileImportFromOCALDialog *importDialogInstance = NULL;
1412     if (!importDialogInstance) {
1413         importDialogInstance = new
1414              Inkscape::UI::Dialog::FileImportFromOCALDialog(
1415                  parentWindow,
1416                  import_path,
1417                  Inkscape::UI::Dialog::IMPORT_TYPES,
1418                  (char const *)_("Import From Open Clip Art Library"));
1419     }
1421     bool success = importDialogInstance->show();
1422     if (!success) {
1423         delete importDialogInstance;
1424         return;
1425     }
1427     // Get file name and extension type
1428     Glib::ustring fileName = importDialogInstance->getFilename();
1429     Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1431     delete importDialogInstance;
1432     importDialogInstance = NULL;
1434     if (fileName.size() > 0) {
1436         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1438         if ( newFileName.size() > 0)
1439             fileName = newFileName;
1440         else
1441             g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1443         import_path = fileName;
1444         if (import_path.size()>0)
1445             import_path.append(G_DIR_SEPARATOR_S);
1447         file_import(doc, fileName, selection);
1448     }
1450     return;
1453 /*######################
1454 ## P R I N T
1455 ######################*/
1458 /**
1459  *  Print the current document, if any.
1460  */
1461 void
1462 sp_file_print(Gtk::Window& parentWindow)
1464     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1465     if (doc)
1466         sp_print_document(parentWindow, doc);
1469 /**
1470  * Display what the drawing would look like, if
1471  * printed.
1472  */
1473 void
1474 sp_file_print_preview(gpointer /*object*/, gpointer /*data*/)
1477     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1478     if (doc)
1479         sp_print_preview_document(doc);
1484 /*
1485   Local Variables:
1486   mode:c++
1487   c-file-style:"stroustrup"
1488   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1489   indent-tabs-mode:nil
1490   fill-column:99
1491   End:
1492 */
1493 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :