Code

Added test script I thought was already added.
[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 "extension/dbus/dbus-init.h"
46 #include "file.h"
47 #include "helper/png-write.h"
48 #include "id-clash.h"
49 #include "inkscape.h"
50 #include "inkscape.h"
51 #include "interface.h"
52 #include "io/sys.h"
53 #include "message.h"
54 #include "message-stack.h"
55 #include "path-prefix.h"
56 #include "preferences.h"
57 #include "print.h"
58 #include "rdf.h"
59 #include "selection-chemistry.h"
60 #include "selection.h"
61 #include "sp-namedview.h"
62 #include "style.h"
63 #include "ui/dialog/filedialog.h"
64 #include "ui/dialog/ocaldialogs.h"
65 #include "ui/view/view-widget.h"
66 #include "uri.h"
67 #include "xml/rebase-hrefs.h"
69 #ifdef WITH_GNOME_VFS
70 # include <libgnomevfs/gnome-vfs.h>
71 #endif
73 #ifdef WITH_INKBOARD
74 #include "jabber_whiteboard/session-manager.h"
75 #endif
77 #ifdef WIN32
78 #include <windows.h>
79 #endif
81 //#define INK_DUMP_FILENAME_CONV 1
82 #undef INK_DUMP_FILENAME_CONV
84 //#define INK_DUMP_FOPEN 1
85 #undef INK_DUMP_FOPEN
87 void dump_str(gchar const *str, gchar const *prefix);
88 void dump_ustr(Glib::ustring const &ustr);
90 // what gets passed here is not actually an URI... it is an UTF-8 encoded filename (!)
91 static void sp_file_add_recent(gchar const *uri)
92 {
93     if(uri == NULL) {
94         g_warning("sp_file_add_recent: uri == NULL");
95         return;
96     }
97     GtkRecentManager *recent = gtk_recent_manager_get_default();
98     gchar *fn = g_filename_from_utf8(uri, -1, NULL, NULL, NULL);
99     if (fn) {
100         gchar *uri_to_add = g_filename_to_uri(fn, NULL, NULL);
101         if (uri_to_add) {
102             gtk_recent_manager_add_item(recent, uri_to_add);
103             g_free(uri_to_add);
104         }
105         g_free(fn);
106     }
110 /*######################
111 ## N E W
112 ######################*/
114 /**
115  * Create a blank document and add it to the desktop
116  */
117 SPDesktop*
118 sp_file_new(const Glib::ustring &templ)
120     char *templName = NULL;
121     if (templ.size()>0)
122         templName = (char *)templ.c_str();
123     SPDocument *doc = sp_document_new(templName, TRUE, true);
124     g_return_val_if_fail(doc != NULL, NULL);
126     SPDesktop *dt;
127     if (Inkscape::NSApplication::Application::getNewGui())
128     {
129         dt = Inkscape::NSApplication::Editor::createDesktop (doc);
130     } else {
131         SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
132         g_return_val_if_fail(dtw != NULL, NULL);
133         sp_document_unref(doc);
135         sp_create_window(dtw, TRUE);
136         dt = static_cast<SPDesktop*>(dtw->view);
137         sp_namedview_window_from_document(dt);
138         sp_namedview_update_layers_from_document(dt);
139     }
140     Inkscape::Extension::Dbus::dbus_init_desktop_interface(dt);
141     return dt;
144 SPDesktop*
145 sp_file_new_default()
147     std::list<gchar *> sources;
148     sources.push_back( profile_path("templates") ); // first try user's local dir
149     sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
151     while (!sources.empty()) {
152         gchar *dirname = sources.front();
153         if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) {
155             // TRANSLATORS: default.svg is localizable - this is the name of the default document
156             //  template. This way you can localize the default pagesize, translate the name of
157             //  the default layer, etc. If you wish to localize this file, please create a
158             //  localized share/templates/default.xx.svg file, where xx is your language code.
159             char *default_template = g_build_filename(dirname, _("default.svg"), NULL);
160             if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) {
161                 return sp_file_new(default_template);
162             }
163         }
164         g_free(dirname);
165         sources.pop_front();
166     }
168     return sp_file_new("");
172 /*######################
173 ## D E L E T E
174 ######################*/
176 /**
177  *  Perform document closures preceding an exit()
178  */
179 void
180 sp_file_exit()
182     sp_ui_close_all();
183     // no need to call inkscape_exit here; last document being closed will take care of that
187 /*######################
188 ## O P E N
189 ######################*/
191 /**
192  *  Open a file, add the document to the desktop
193  *
194  *  \param replace_empty if true, and the current desktop is empty, this document
195  *  will replace the empty one.
196  */
197 bool
198 sp_file_open(const Glib::ustring &uri,
199              Inkscape::Extension::Extension *key,
200              bool add_to_recent, bool replace_empty)
202     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
203     if (desktop)
204         desktop->setWaitingCursor();
206     SPDocument *doc = NULL;
207     try {
208         doc = Inkscape::Extension::open(key, uri.c_str());
209     } catch (Inkscape::Extension::Input::no_extension_found &e) {
210         doc = NULL;
211     } catch (Inkscape::Extension::Input::open_failed &e) {
212         doc = NULL;
213     }
215     if (desktop)
216         desktop->clearWaitingCursor();
218     if (doc) {
219         SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;
221         if (existing && existing->virgin && replace_empty) {
222             // If the current desktop is empty, open the document there
223             sp_document_ensure_up_to_date (doc);
224             desktop->change_document(doc);
225             sp_document_resized_signal_emit (doc, sp_document_width(doc), sp_document_height(doc));
226         } else {
227             if (!Inkscape::NSApplication::Application::getNewGui()) {
228                 // create a whole new desktop and window
229                 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
230                 sp_create_window(dtw, TRUE);
231                 desktop = static_cast<SPDesktop*>(dtw->view);
232             } else {
233                 desktop = Inkscape::NSApplication::Editor::createDesktop (doc);
234             }
235         }
237         doc->virgin = FALSE;
238         // everyone who cares now has a reference, get rid of ours
239         sp_document_unref(doc);
240         // resize the window to match the document properties
241         sp_namedview_window_from_document(desktop);
242         sp_namedview_update_layers_from_document(desktop);
244         if (add_to_recent) {
245             sp_file_add_recent(SP_DOCUMENT_URI(doc));
246         }
248         return TRUE;
249     } else {
250         gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
251         gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), safeUri);
252         sp_ui_error_dialog(text);
253         g_free(text);
254         g_free(safeUri);
255         return FALSE;
256     }
259 /**
260  *  Handle prompting user for "do you want to revert"?  Revert on "OK"
261  */
262 void
263 sp_file_revert_dialog()
265     SPDesktop  *desktop = SP_ACTIVE_DESKTOP;
266     g_assert(desktop != NULL);
268     SPDocument *doc = sp_desktop_document(desktop);
269     g_assert(doc != NULL);
271     Inkscape::XML::Node     *repr = sp_document_repr_root(doc);
272     g_assert(repr != NULL);
274     gchar const *uri = doc->uri;
275     if (!uri) {
276         desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet.  Cannot revert."));
277         return;
278     }
280     bool do_revert = true;
281     if (doc->isModifiedSinceSave()) {
282         gchar *text = g_strdup_printf(_("Changes will be lost!  Are you sure you want to reload document %s?"), uri);
284         bool response = desktop->warnDialog (text);
285         g_free(text);
287         if (!response) {
288             do_revert = false;
289         }
290     }
292     bool reverted;
293     if (do_revert) {
294         // Allow overwriting of current document.
295         doc->virgin = TRUE;
297         // remember current zoom and view
298         double zoom = desktop->current_zoom();
299         Geom::Point c = desktop->get_display_area().midpoint();
301         reverted = sp_file_open(uri,NULL);
302         if (reverted) {
303             // restore zoom and view
304             desktop->zoom_absolute(c[Geom::X], c[Geom::Y], zoom);
305         }
306     } else {
307         reverted = false;
308     }
310     if (reverted) {
311         desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document reverted."));
312     } else {
313         desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not reverted."));
314     }
317 void dump_str(gchar const *str, gchar const *prefix)
319     Glib::ustring tmp;
320     tmp = prefix;
321     tmp += " [";
322     size_t const total = strlen(str);
323     for (unsigned i = 0; i < total; i++) {
324         gchar *const tmp2 = g_strdup_printf(" %02x", (0x0ff & str[i]));
325         tmp += tmp2;
326         g_free(tmp2);
327     }
329     tmp += "]";
330     g_message("%s", tmp.c_str());
333 void dump_ustr(Glib::ustring const &ustr)
335     char const *cstr = ustr.c_str();
336     char const *data = ustr.data();
337     Glib::ustring::size_type const byteLen = ustr.bytes();
338     Glib::ustring::size_type const dataLen = ustr.length();
339     Glib::ustring::size_type const cstrLen = strlen(cstr);
341     g_message("   size: %lu\n   length: %lu\n   bytes: %lu\n    clen: %lu",
342               gulong(ustr.size()), gulong(dataLen), gulong(byteLen), gulong(cstrLen) );
343     g_message( "  ASCII? %s", (ustr.is_ascii() ? "yes":"no") );
344     g_message( "  UTF-8? %s", (ustr.validate() ? "yes":"no") );
346     try {
347         Glib::ustring tmp;
348         for (Glib::ustring::size_type i = 0; i < ustr.bytes(); i++) {
349             tmp = "    ";
350             if (i < dataLen) {
351                 Glib::ustring::value_type val = ustr.at(i);
352                 gchar* tmp2 = g_strdup_printf( (((val & 0xff00) == 0) ? "  %02x" : "%04x"), val );
353                 tmp += tmp2;
354                 g_free( tmp2 );
355             } else {
356                 tmp += "    ";
357             }
359             if (i < byteLen) {
360                 int val = (0x0ff & data[i]);
361                 gchar *tmp2 = g_strdup_printf("    %02x", val);
362                 tmp += tmp2;
363                 g_free( tmp2 );
364                 if ( val > 32 && val < 127 ) {
365                     tmp2 = g_strdup_printf( "   '%c'", (gchar)val );
366                     tmp += tmp2;
367                     g_free( tmp2 );
368                 } else {
369                     tmp += "    . ";
370                 }
371             } else {
372                 tmp += "       ";
373             }
375             if ( i < cstrLen ) {
376                 int val = (0x0ff & cstr[i]);
377                 gchar* tmp2 = g_strdup_printf("    %02x", val);
378                 tmp += tmp2;
379                 g_free(tmp2);
380                 if ( val > 32 && val < 127 ) {
381                     tmp2 = g_strdup_printf("   '%c'", (gchar) val);
382                     tmp += tmp2;
383                     g_free( tmp2 );
384                 } else {
385                     tmp += "    . ";
386                 }
387             } else {
388                 tmp += "            ";
389             }
391             g_message( "%s", tmp.c_str() );
392         }
393     } catch (...) {
394         g_message("XXXXXXXXXXXXXXXXXX Exception" );
395     }
396     g_message("---------------");
399 /**
400  *  Display an file Open selector.  Open a document if OK is pressed.
401  *  Can select single or multiple files for opening.
402  */
403 void
404 sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
406     //# Get the current directory for finding files
407     static Glib::ustring open_path;
408     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
410     if(open_path.empty())
411     {
412         Glib::ustring attr = prefs->getString("/dialogs/open/path");
413         if (!attr.empty()) open_path = attr;
414     }
416     //# Test if the open_path directory exists
417     if (!Inkscape::IO::file_test(open_path.c_str(),
418               (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
419         open_path = "";
421 #ifdef WIN32
422     //# If no open path, default to our win32 documents folder
423     if (open_path.empty())
424     {
425         // The path to the My Documents folder is read from the
426         // value "HKEY_CURRENT_USER\Software\Windows\CurrentVersion\Explorer\Shell Folders\Personal"
427         HKEY key = NULL;
428         if(RegOpenKeyExA(HKEY_CURRENT_USER,
429             "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
430             0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
431         {
432             WCHAR utf16path[_MAX_PATH];
433             DWORD value_type;
434             DWORD data_size = sizeof(utf16path);
435             if(RegQueryValueExW(key, L"Personal", NULL, &value_type,
436                 (BYTE*)utf16path, &data_size) == ERROR_SUCCESS)
437             {
438                 g_assert(value_type == REG_SZ);
439                 gchar *utf8path = g_utf16_to_utf8(
440                     (const gunichar2*)utf16path, -1, NULL, NULL, NULL);
441                 if(utf8path)
442                 {
443                     open_path = Glib::ustring(utf8path);
444                     g_free(utf8path);
445                 }
446             }
447         }
448     }
449 #endif
451     //# If no open path, default to our home directory
452     if (open_path.empty())
453     {
454         open_path = g_get_home_dir();
455         open_path.append(G_DIR_SEPARATOR_S);
456     }
458     //# Create a dialog
459     Inkscape::UI::Dialog::FileOpenDialog *openDialogInstance =
460               Inkscape::UI::Dialog::FileOpenDialog::create(
461                  parentWindow, open_path,
462                  Inkscape::UI::Dialog::SVG_TYPES,
463                  _("Select file to open"));
465     //# Show the dialog
466     bool const success = openDialogInstance->show();
468     //# Save the folder the user selected for later
469     open_path = openDialogInstance->getCurrentDirectory();
471     if (!success)
472     {
473         delete openDialogInstance;
474         return;
475     }
477     //# User selected something.  Get name and type
478     Glib::ustring fileName = openDialogInstance->getFilename();
480     Inkscape::Extension::Extension *selection =
481             openDialogInstance->getSelectionType();
483     //# Code to check & open if multiple files.
484     std::vector<Glib::ustring> flist = openDialogInstance->getFilenames();
486     //# We no longer need the file dialog object - delete it
487     delete openDialogInstance;
488     openDialogInstance = NULL;
490     //# Iterate through filenames if more than 1
491     if (flist.size() > 1)
492     {
493         for (unsigned int i = 0; i < flist.size(); i++)
494         {
495             fileName = flist[i];
497             Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
498             if ( newFileName.size() > 0 )
499                 fileName = newFileName;
500             else
501                 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
503 #ifdef INK_DUMP_FILENAME_CONV
504             g_message("Opening File %s\n", fileName.c_str());
505 #endif
506             sp_file_open(fileName, selection);
507         }
509         return;
510     }
513     if (!fileName.empty())
514     {
515         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
517         if ( newFileName.size() > 0)
518             fileName = newFileName;
519         else
520             g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
522         open_path = Glib::path_get_dirname (fileName);
523         open_path.append(G_DIR_SEPARATOR_S);
524         prefs->setString("/dialogs/open/path", open_path);
526         sp_file_open(fileName, selection);
527     }
529     return;
533 /*######################
534 ## V A C U U M
535 ######################*/
537 /**
538  * Remove unreferenced defs from the defs section of the document.
539  */
542 void
543 sp_file_vacuum()
545     SPDocument *doc = SP_ACTIVE_DOCUMENT;
547     unsigned int diff = vacuum_document (doc);
549     sp_document_done(doc, SP_VERB_FILE_VACUUM,
550                      _("Vacuum &lt;defs&gt;"));
552     SPDesktop *dt = SP_ACTIVE_DESKTOP;
553     if (diff > 0) {
554         dt->messageStack()->flashF(Inkscape::NORMAL_MESSAGE,
555                 ngettext("Removed <b>%i</b> unused definition in &lt;defs&gt;.",
556                          "Removed <b>%i</b> unused definitions in &lt;defs&gt;.",
557                          diff),
558                 diff);
559     } else {
560         dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE,  _("No unused definitions in &lt;defs&gt;."));
561     }
566 /*######################
567 ## S A V E
568 ######################*/
570 /**
571  * This 'save' function called by the others below
572  *
573  * \param    official  whether to set :output_module and :modified in the
574  *                     document; is true for normal save, false for temporary saves
575  */
576 static bool
577 file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
578           Inkscape::Extension::Extension *key, bool saveas, bool official)
580     if (!doc || uri.size()<1) //Safety check
581         return false;
583     try {
584         Inkscape::Extension::save(key, doc, uri.c_str(),
585                  false,
586                  saveas, official);
587     } catch (Inkscape::Extension::Output::no_extension_found &e) {
588         gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
589         gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s).  This may have been caused by an unknown filename extension."), safeUri);
590         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
591         sp_ui_error_dialog(text);
592         g_free(text);
593         g_free(safeUri);
594         return FALSE;
595     } catch (Inkscape::Extension::Output::save_failed &e) {
596         gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
597         gchar *text = g_strdup_printf(_("File %s could not be saved."), safeUri);
598         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
599         sp_ui_error_dialog(text);
600         g_free(text);
601         g_free(safeUri);
602         return FALSE;
603     } catch (Inkscape::Extension::Output::save_cancelled &e) {
604         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
605         return FALSE;
606     } catch (Inkscape::Extension::Output::no_overwrite &e) {
607         return sp_file_save_dialog(parentWindow, doc);
608     }
610     SP_ACTIVE_DESKTOP->event_log->rememberFileSave();
611     SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document saved."));
612     return true;
615 /*
616  * Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp.
617  */
618 bool
619 file_save_remote(SPDocument */*doc*/,
620     #ifdef WITH_GNOME_VFS
621                  const Glib::ustring &uri,
622     #else
623                  const Glib::ustring &/*uri*/,
624     #endif
625                  Inkscape::Extension::Extension */*key*/, bool /*saveas*/, bool /*official*/)
627 #ifdef WITH_GNOME_VFS
629 #define BUF_SIZE 8192
630     gnome_vfs_init();
632     GnomeVFSHandle    *from_handle = NULL;
633     GnomeVFSHandle    *to_handle = NULL;
634     GnomeVFSFileSize  bytes_read;
635     GnomeVFSFileSize  bytes_written;
636     GnomeVFSResult    result;
637     guint8 buffer[8192];
639     gchar* uri_local = g_filename_from_utf8( uri.c_str(), -1, NULL, NULL, NULL);
641     if ( uri_local == NULL ) {
642         g_warning( "Error converting filename to locale encoding.");
643     }
645     // Gets the temp file name.
646     Glib::ustring fileName = Glib::get_tmp_dir ();
647     fileName.append(G_DIR_SEPARATOR_S);
648     fileName.append((gnome_vfs_uri_extract_short_name(gnome_vfs_uri_new(uri_local))));
650     // Open the temp file to send.
651     result = gnome_vfs_open (&from_handle, fileName.c_str(), GNOME_VFS_OPEN_READ);
653     if (result != GNOME_VFS_OK) {
654         g_warning("Could not find the temp saving.");
655         return false;
656     }
658     result = gnome_vfs_create (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
659     result = gnome_vfs_open (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE);
661     if (result != GNOME_VFS_OK) {
662         g_warning("file creating: %s", gnome_vfs_result_to_string(result));
663         return false;
664     }
666     while (1) {
668         result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
670         if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
671             result = gnome_vfs_close (from_handle);
672             result = gnome_vfs_close (to_handle);
673             return true;
674         }
676         if (result != GNOME_VFS_OK) {
677             g_warning("%s", gnome_vfs_result_to_string(result));
678             return false;
679         }
680         result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
681         if (result != GNOME_VFS_OK) {
682             g_warning("%s", gnome_vfs_result_to_string(result));
683             return false;
684         }
687         if (bytes_read != bytes_written){
688             return false;
689         }
691     }
692     return true;
693 #else
694     // in case we do not have GNOME_VFS
695     return false;
696 #endif
701 /**
702  *  Display a SaveAs dialog.  Save the document if OK pressed.
703  *
704  * \param    ascopy  (optional) wether to set the documents->uri to the new filename or not
705  */
706 bool
707 sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
710     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
711     Inkscape::Extension::Output *extension = 0;
712     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
714     //# Get the default extension name
715     Glib::ustring default_extension;
716     char *attr = (char *)repr->attribute("inkscape:output_extension");
717     if (!attr) {
718         Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
719         if(!attr2.empty()) default_extension = attr2;
720     } else {
721         default_extension = attr;
722     }
723     //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
725     Glib::ustring save_path;
726     Glib::ustring save_loc;
728     if (doc->uri == NULL) {
729         char formatBuf[256];
730         int i = 1;
732         Glib::ustring filename_extension = ".svg";
733         extension = dynamic_cast<Inkscape::Extension::Output *>
734               (Inkscape::Extension::db.get(default_extension.c_str()));
735         //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
736         if (extension)
737             filename_extension = extension->get_extension();
739         Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
740         if (!attr3.empty())
741             save_path = attr3;
743         if (!Inkscape::IO::file_test(save_path.c_str(),
744               (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
745             save_path = "";
747         if (save_path.size()<1)
748             save_path = g_get_home_dir();
750         save_loc = save_path;
751         save_loc.append(G_DIR_SEPARATOR_S);
752         snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
753         save_loc.append(formatBuf);
755         while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) {
756             save_loc = save_path;
757             save_loc.append(G_DIR_SEPARATOR_S);
758             snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str());
759             save_loc.append(formatBuf);
760         }
761     } else {
762         save_loc = Glib::build_filename(Glib::path_get_dirname(doc->uri),
763                                         Glib::path_get_basename(doc->uri));
764     }
766     // convert save_loc from utf-8 to locale
767     // is this needed any more, now that everything is handled in
768     // Inkscape::IO?
769     Glib::ustring save_loc_local = Glib::filename_from_utf8(save_loc);
771     if ( save_loc_local.size() > 0)
772         save_loc = save_loc_local;
774     //# Show the SaveAs dialog
775     char const * dialog_title;
776     if (is_copy) {
777         dialog_title = (char const *) _("Select file to save a copy to");
778     } else {
779         dialog_title = (char const *) _("Select file to save to");
780     }
781     gchar* doc_title = doc->root->title();
782     Inkscape::UI::Dialog::FileSaveDialog *saveDialog =
783         Inkscape::UI::Dialog::FileSaveDialog::create(
784             parentWindow,
785             save_loc,
786             Inkscape::UI::Dialog::SVG_TYPES,
787             dialog_title,
788             default_extension,
789             doc_title ? doc_title : ""
790             );
792     saveDialog->setSelectionType(extension);
794     bool success = saveDialog->show();
795     if (!success) {
796         delete saveDialog;
797         return success;
798     }
800     // set new title here (call RDF to ensure metadata and title element are updated)
801     rdf_set_work_entity(doc, rdf_find_entity("title"), saveDialog->getDocTitle().c_str());
802     // free up old string
803     if(doc_title) g_free(doc_title);
805     Glib::ustring fileName = saveDialog->getFilename();
806     Inkscape::Extension::Extension *selectionType = saveDialog->getSelectionType();
808     delete saveDialog;
810     saveDialog = 0;
812     if (fileName.size() > 0) {
813         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
815         if ( newFileName.size()>0 )
816             fileName = newFileName;
817         else
818             g_warning( "Error converting save filename to UTF-8." );
820         success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy);
822         if (success && SP_DOCUMENT_URI(doc)) {
823             sp_file_add_recent(SP_DOCUMENT_URI(doc));
824         }
826         save_path = Glib::path_get_dirname(fileName);
827         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
828         prefs->setString("/dialogs/save_as/path", save_path);
830         return success;
831     }
834     return false;
838 /**
839  * Save a document, displaying a SaveAs dialog if necessary.
840  */
841 bool
842 sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc)
844     bool success = true;
846     if (doc->isModifiedSinceSave()) {
847         Inkscape::XML::Node *repr = sp_document_repr_root(doc);
848         if ( doc->uri == NULL
849             || repr->attribute("inkscape:output_extension") == NULL )
850         {
851             return sp_file_save_dialog(parentWindow, doc, FALSE);
852         } else {
853             gchar const *fn = g_strdup(doc->uri);
854             gchar const *ext = repr->attribute("inkscape:output_extension");
855             success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE);
856             g_free((void *) fn);
857         }
858     } else {
859         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved."));
860         success = TRUE;
861     }
863     return success;
867 /**
868  * Save a document.
869  */
870 bool
871 sp_file_save(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
873     if (!SP_ACTIVE_DOCUMENT)
874         return false;
876     SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Saving document..."));
878     sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
879     return sp_file_save_document(parentWindow, SP_ACTIVE_DOCUMENT);
883 /**
884  *  Save a document, always displaying the SaveAs dialog.
885  */
886 bool
887 sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
889     if (!SP_ACTIVE_DOCUMENT)
890         return false;
891     sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
892     return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, FALSE);
897 /**
898  *  Save a copy of a document, always displaying a sort of SaveAs dialog.
899  */
900 bool
901 sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
903     if (!SP_ACTIVE_DOCUMENT)
904         return false;
905     sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
906     return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, TRUE);
910 /*######################
911 ## I M P O R T
912 ######################*/
914 /**
915  *  Import a resource.  Called by sp_file_import()
916  */
917 void
918 file_import(SPDocument *in_doc, const Glib::ustring &uri,
919                Inkscape::Extension::Extension *key)
921     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
923     //DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
924     SPDocument *doc;
925     try {
926         doc = Inkscape::Extension::open(key, uri.c_str());
927     } catch (Inkscape::Extension::Input::no_extension_found &e) {
928         doc = NULL;
929     } catch (Inkscape::Extension::Input::open_failed &e) {
930         doc = NULL;
931     }
933     if (doc != NULL) {
934         Inkscape::XML::rebase_hrefs(doc, in_doc->base, true);
935         Inkscape::XML::Document *xml_in_doc = sp_document_repr_doc(in_doc);
937         prevent_id_clashes(doc, in_doc);
939         SPObject *in_defs = SP_DOCUMENT_DEFS(in_doc);
940         Inkscape::XML::Node *last_def = SP_OBJECT_REPR(in_defs)->lastChild();
942         SPCSSAttr *style = sp_css_attr_from_object(SP_DOCUMENT_ROOT(doc));
944         // Count the number of top-level items in the imported document.
945         guint items_count = 0;
946         for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
947              child != NULL; child = SP_OBJECT_NEXT(child))
948         {
949             if (SP_IS_ITEM(child)) items_count++;
950         }
952         // Create a new group if necessary.
953         Inkscape::XML::Node *newgroup = NULL;
954         if ((style && style->firstChild()) || items_count > 1) {
955             newgroup = xml_in_doc->createElement("svg:g");
956             sp_repr_css_set(newgroup, style, "style");
957         }
959         // Determine the place to insert the new object.
960         // This will be the current layer, if possible.
961         // FIXME: If there's no desktop (command line run?) we need
962         //        a document:: method to return the current layer.
963         //        For now, we just use the root in this case.
964         SPObject *place_to_insert;
965         if (desktop) {
966             place_to_insert = desktop->currentLayer();
967         } else {
968             place_to_insert = SP_DOCUMENT_ROOT(in_doc);
969         }
971         // Construct a new object representing the imported image,
972         // and insert it into the current document.
973         SPObject *new_obj = NULL;
974         for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
975              child != NULL; child = SP_OBJECT_NEXT(child) )
976         {
977             if (SP_IS_ITEM(child)) {
978                 Inkscape::XML::Node *newitem = SP_OBJECT_REPR(child)->duplicate(xml_in_doc);
980                 // convert layers to groups, and make sure they are unlocked
981                 // FIXME: add "preserve layers" mode where each layer from
982                 //        import is copied to the same-named layer in host
983                 newitem->setAttribute("inkscape:groupmode", NULL);
984                 newitem->setAttribute("sodipodi:insensitive", NULL);
986                 if (newgroup) newgroup->appendChild(newitem);
987                 else new_obj = place_to_insert->appendChildRepr(newitem);
988             }
990             // don't lose top-level defs or style elements
991             else if (SP_OBJECT_REPR(child)->type() == Inkscape::XML::ELEMENT_NODE) {
992                 const gchar *tag = SP_OBJECT_REPR(child)->name();
993                 if (!strcmp(tag, "svg:defs")) {
994                     for (SPObject *x = sp_object_first_child(child);
995                          x != NULL; x = SP_OBJECT_NEXT(x))
996                     {
997                         SP_OBJECT_REPR(in_defs)->addChild(SP_OBJECT_REPR(x)->duplicate(xml_in_doc), last_def);
998                     }
999                 }
1000                 else if (!strcmp(tag, "svg:style")) {
1001                     SP_DOCUMENT_ROOT(in_doc)->appendChildRepr(SP_OBJECT_REPR(child)->duplicate(xml_in_doc));
1002                 }
1003             }
1004         }
1005         if (newgroup) new_obj = place_to_insert->appendChildRepr(newgroup);
1007         // release some stuff
1008         if (newgroup) Inkscape::GC::release(newgroup);
1009         if (style) sp_repr_css_attr_unref(style);
1011         // select and move the imported item
1012         if (new_obj && SP_IS_ITEM(new_obj)) {
1013             Inkscape::Selection *selection = sp_desktop_selection(desktop);
1014             selection->set(SP_ITEM(new_obj));
1016             // preserve parent and viewBox transformations
1017             // c2p is identity matrix at this point unless sp_document_ensure_up_to_date is called
1018             sp_document_ensure_up_to_date(doc);
1019             Geom::Matrix affine = SP_ROOT(SP_DOCUMENT_ROOT(doc))->c2p * sp_item_i2doc_affine(SP_ITEM(place_to_insert)).inverse();
1020             sp_selection_apply_affine(selection, desktop->dt2doc() * affine * desktop->doc2dt(), true, false);
1022             // move to mouse pointer
1023             {
1024                 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1025                 Geom::OptRect sel_bbox = selection->bounds();
1026                 if (sel_bbox) {
1027                     Geom::Point m( desktop->point() - sel_bbox->midpoint() );
1028                     sp_selection_move_relative(selection, m, false);
1029                 }
1030             }
1031         }
1033         sp_document_unref(doc);
1034         sp_document_done(in_doc, SP_VERB_FILE_IMPORT,
1035                          _("Import"));
1037     } else {
1038         gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), uri.c_str());
1039         sp_ui_error_dialog(text);
1040         g_free(text);
1041     }
1043     return;
1047 /**
1048  *  Display an Open dialog, import a resource if OK pressed.
1049  */
1050 void
1051 sp_file_import(Gtk::Window &parentWindow)
1053     static Glib::ustring import_path;
1055     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1056     if (!doc)
1057         return;
1059     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1061     if(import_path.empty())
1062     {
1063         Glib::ustring attr = prefs->getString("/dialogs/import/path");
1064         if (!attr.empty()) import_path = attr;
1065     }
1067     //# Test if the import_path directory exists
1068     if (!Inkscape::IO::file_test(import_path.c_str(),
1069               (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1070         import_path = "";
1072     //# If no open path, default to our home directory
1073     if (import_path.empty())
1074     {
1075         import_path = g_get_home_dir();
1076         import_path.append(G_DIR_SEPARATOR_S);
1077     }
1079     // Create new dialog (don't use an old one, because parentWindow has probably changed)
1080     Inkscape::UI::Dialog::FileOpenDialog *importDialogInstance =
1081              Inkscape::UI::Dialog::FileOpenDialog::create(
1082                  parentWindow,
1083                  import_path,
1084                  Inkscape::UI::Dialog::IMPORT_TYPES,
1085                  (char const *)_("Select file to import"));
1087     bool success = importDialogInstance->show();
1088     if (!success) {
1089         delete importDialogInstance;
1090         return;
1091     }
1093     //# Get file name and extension type
1094     Glib::ustring fileName = importDialogInstance->getFilename();
1095     Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1097     delete importDialogInstance;
1098     importDialogInstance = NULL;
1100     if (fileName.size() > 0) {
1102         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1104         if ( newFileName.size() > 0)
1105             fileName = newFileName;
1106         else
1107             g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1109         import_path = Glib::path_get_dirname (fileName);
1110         import_path.append(G_DIR_SEPARATOR_S);
1111         prefs->setString("/dialogs/import/path", import_path);
1113         file_import(doc, fileName, selection);
1114     }
1116     return;
1121 /*######################
1122 ## E X P O R T
1123 ######################*/
1125 //#define NEW_EXPORT_DIALOG
1129 #ifdef NEW_EXPORT_DIALOG
1131 /**
1132  *  Display an Export dialog, export as the selected type if OK pressed
1133  */
1134 bool
1135 sp_file_export_dialog(void *widget)
1137     //# temp hack for 'doc' until we can switch to this dialog
1138     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1140     Glib::ustring export_path;
1141     Glib::ustring export_loc;
1143     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
1144     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1145     Inkscape::Extension::Output *extension;
1147     //# Get the default extension name
1148     Glib::ustring default_extension;
1149     char *attr = (char *)repr->attribute("inkscape:output_extension");
1150     if (!attr) {
1151         Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
1152         if(!attr2.empty()) default_extension = attr2;
1153     } else {
1154         default_extension = attr;
1155     }
1156     //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
1158     if (doc->uri == NULL)
1159         {
1160         char formatBuf[256];
1162         Glib::ustring filename_extension = ".svg";
1163         extension = dynamic_cast<Inkscape::Extension::Output *>
1164               (Inkscape::Extension::db.get(default_extension.c_str()));
1165         //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
1166         if (extension)
1167             filename_extension = extension->get_extension();
1169         Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
1170         if (!attr3.empty())
1171             export_path = attr3;
1173         if (!Inkscape::IO::file_test(export_path.c_str(),
1174               (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1175             export_path = "";
1177         if (export_path.size()<1)
1178             export_path = g_get_home_dir();
1180         export_loc = export_path;
1181         export_loc.append(G_DIR_SEPARATOR_S);
1182         snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1183         export_loc.append(formatBuf);
1185         }
1186     else
1187         {
1188         export_path = Glib::path_get_dirname(doc->uri);
1189         }
1191     // convert save_loc from utf-8 to locale
1192     // is this needed any more, now that everything is handled in
1193     // Inkscape::IO?
1194     Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1195     if ( export_path_local.size() > 0)
1196         export_path = export_path_local;
1198     //# Show the SaveAs dialog
1199     Inkscape::UI::Dialog::FileExportDialog *exportDialogInstance =
1200         Inkscape::UI::Dialog::FileExportDialog::create(
1201             export_path,
1202             Inkscape::UI::Dialog::EXPORT_TYPES,
1203             (char const *) _("Select file to export to"),
1204             default_extension
1205         );
1207     bool success = exportDialogInstance->show();
1208     if (!success) {
1209         delete exportDialogInstance;
1210         return success;
1211     }
1213     Glib::ustring fileName = exportDialogInstance->getFilename();
1215     Inkscape::Extension::Extension *selectionType =
1216         exportDialogInstance->getSelectionType();
1218     delete exportDialogInstance;
1219     exportDialogInstance = NULL;
1221     if (fileName.size() > 0) {
1222         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1224         if ( newFileName.size()>0 )
1225             fileName = newFileName;
1226         else
1227             g_warning( "Error converting save filename to UTF-8." );
1229         success = file_save(doc, fileName, selectionType, TRUE, FALSE);
1231         if (success) {
1232             Glib::RefPtr<Gtk::RecentManager> recent = Gtk::RecentManager::get_default();
1233             recent->add_item(SP_DOCUMENT_URI(doc));
1234         }
1236         export_path = fileName;
1237         prefs->setString("/dialogs/save_as/path", export_path);
1239         return success;
1240     }
1243     return false;
1246 #else
1248 /**
1249  *
1250  */
1251 bool
1252 sp_file_export_dialog(void */*widget*/)
1254     sp_export_dialog();
1255     return true;
1258 #endif
1260 /*######################
1261 ## E X P O R T  T O  O C A L
1262 ######################*/
1264 /**
1265  *  Display an Export dialog, export as the selected type if OK pressed
1266  */
1267 bool
1268 sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow)
1271    if (!SP_ACTIVE_DOCUMENT)
1272         return false;
1274     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1276     Glib::ustring export_path;
1277     Glib::ustring export_loc;
1278     Glib::ustring fileName;
1279     Inkscape::Extension::Extension *selectionType;
1281     bool success = false;
1283     static bool gotSuccess = false;
1285     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
1286     (void)repr;
1288     if (!doc->uri && !doc->isModifiedSinceSave())
1289         return false;
1291     //  Get the default extension name
1292     Glib::ustring default_extension = "org.inkscape.output.svg.inkscape";
1293     char formatBuf[256];
1295     Glib::ustring filename_extension = ".svg";
1296     selectionType = Inkscape::Extension::db.get(default_extension.c_str());
1298     export_path = Glib::get_tmp_dir ();
1300     export_loc = export_path;
1301     export_loc.append(G_DIR_SEPARATOR_S);
1302     snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1303     export_loc.append(formatBuf);
1305     // convert save_loc from utf-8 to locale
1306     // is this needed any more, now that everything is handled in
1307     // Inkscape::IO?
1308     Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1309     if ( export_path_local.size() > 0)
1310         export_path = export_path_local;
1312     // Show the Export To OCAL dialog
1313     Inkscape::UI::Dialog::FileExportToOCALDialog *exportDialogInstance =
1314         new Inkscape::UI::Dialog::FileExportToOCALDialog(
1315                 parentWindow,
1316                 Inkscape::UI::Dialog::EXPORT_TYPES,
1317                 (char const *) _("Select file to export to")
1318                 );
1320     success = exportDialogInstance->show();
1321     if (!success) {
1322         delete exportDialogInstance;
1323         return success;
1324     }
1326     fileName = exportDialogInstance->getFilename();
1328     delete exportDialogInstance;
1329     exportDialogInstance = NULL;;
1331     fileName.append(filename_extension.c_str());
1332     if (fileName.size() > 0) {
1333         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1335         if ( newFileName.size()>0 )
1336             fileName = newFileName;
1337         else
1338             g_warning( "Error converting save filename to UTF-8." );
1339     }
1340     Glib::ustring filePath = export_path;
1341     filePath.append(G_DIR_SEPARATOR_S);
1342     filePath.append(Glib::path_get_basename(fileName));
1344     fileName = filePath;
1346     success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE);
1348     if (!success){
1349         gchar *text = g_strdup_printf(_("Error saving a temporary copy"));
1350         sp_ui_error_dialog(text);
1352         return success;
1353     }
1355     // Start now the submition
1357     // Create the uri
1358     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1359     Glib::ustring uri = "dav://";
1360     Glib::ustring username = prefs->getString("/options/ocalusername/str");
1361     Glib::ustring password = prefs->getString("/options/ocalpassword/str");
1362     if (username.empty() || password.empty())
1363     {
1364         Inkscape::UI::Dialog::FileExportToOCALPasswordDialog *exportPasswordDialogInstance = NULL;
1365         if(!gotSuccess)
1366         {
1367             exportPasswordDialogInstance = new Inkscape::UI::Dialog::FileExportToOCALPasswordDialog(
1368                     parentWindow,
1369                     (char const *) _("Open Clip Art Login"));
1370             success = exportPasswordDialogInstance->show();
1371             if (!success) {
1372                 delete exportPasswordDialogInstance;
1373                 return success;
1374             }
1375         }
1376         username = exportPasswordDialogInstance->getUsername();
1377         password = exportPasswordDialogInstance->getPassword();
1379         delete exportPasswordDialogInstance;
1380         exportPasswordDialogInstance = NULL;
1381     }
1382     uri.append(username);
1383     uri.append(":");
1384     uri.append(password);
1385     uri.append("@");
1386     uri.append(prefs->getString("/options/ocalurl/str"));
1387     uri.append("/dav.php/");
1388     uri.append(Glib::path_get_basename(fileName));
1390     // Save as a remote file using the dav protocol.
1391     success = file_save_remote(doc, uri, selectionType, FALSE, FALSE);
1392     remove(fileName.c_str());
1393     if (!success)
1394     {
1395         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."));
1396         sp_ui_error_dialog(text);
1397     }
1398     else
1399         gotSuccess = true;
1401     return success;
1404 /**
1405  * Export the current document to OCAL
1406  */
1407 void
1408 sp_file_export_to_ocal(Gtk::Window &parentWindow)
1411     // Try to execute the new code and return;
1412     if (!SP_ACTIVE_DOCUMENT)
1413         return;
1414     bool success = sp_file_export_to_ocal_dialog(parentWindow);
1415     if (success)
1416         SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Document exported..."));
1420 /*######################
1421 ## I M P O R T  F R O M  O C A L
1422 ######################*/
1424 /**
1425  * Display an ImportToOcal Dialog, and the selected document from OCAL
1426  */
1427 void
1428 sp_file_import_from_ocal(Gtk::Window &parentWindow)
1430     static Glib::ustring import_path;
1432     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1433     if (!doc)
1434         return;
1436     Inkscape::UI::Dialog::FileImportFromOCALDialog *importDialogInstance = NULL;
1438     if (!importDialogInstance) {
1439         importDialogInstance = new
1440              Inkscape::UI::Dialog::FileImportFromOCALDialog(
1441                  parentWindow,
1442                  import_path,
1443                  Inkscape::UI::Dialog::IMPORT_TYPES,
1444                  (char const *)_("Import From Open Clip Art Library"));
1445     }
1447     bool success = importDialogInstance->show();
1448     if (!success) {
1449         delete importDialogInstance;
1450         return;
1451     }
1453     // Get file name and extension type
1454     Glib::ustring fileName = importDialogInstance->getFilename();
1455     Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1457     delete importDialogInstance;
1458     importDialogInstance = NULL;
1460     if (fileName.size() > 0) {
1462         Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1464         if ( newFileName.size() > 0)
1465             fileName = newFileName;
1466         else
1467             g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1469         import_path = fileName;
1470         if (import_path.size()>0)
1471             import_path.append(G_DIR_SEPARATOR_S);
1473         file_import(doc, fileName, selection);
1474     }
1476     return;
1479 /*######################
1480 ## P R I N T
1481 ######################*/
1484 /**
1485  *  Print the current document, if any.
1486  */
1487 void
1488 sp_file_print(Gtk::Window& parentWindow)
1490     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1491     if (doc)
1492         sp_print_document(parentWindow, doc);
1495 /**
1496  * Display what the drawing would look like, if
1497  * printed.
1498  */
1499 void
1500 sp_file_print_preview(gpointer /*object*/, gpointer /*data*/)
1503     SPDocument *doc = SP_ACTIVE_DOCUMENT;
1504     if (doc)
1505         sp_print_preview_document(doc);
1510 /*
1511   Local Variables:
1512   mode:c++
1513   c-file-style:"stroustrup"
1514   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1515   indent-tabs-mode:nil
1516   fill-column:99
1517   End:
1518 */
1519 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :