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 if(uri == NULL) {
93 g_warning("sp_file_add_recent: uri == NULL");
94 return;
95 }
96 GtkRecentManager *recent = gtk_recent_manager_get_default();
97 gchar *fn = g_filename_from_utf8(uri, -1, NULL, NULL, NULL);
98 if (fn) {
99 gchar *uri_to_add = g_filename_to_uri(fn, NULL, NULL);
100 if (uri_to_add) {
101 gtk_recent_manager_add_item(recent, uri_to_add);
102 g_free(uri_to_add);
103 }
104 g_free(fn);
105 }
106 }
109 /*######################
110 ## N E W
111 ######################*/
113 /**
114 * Create a blank document and add it to the desktop
115 */
116 SPDesktop*
117 sp_file_new(const Glib::ustring &templ)
118 {
119 char *templName = NULL;
120 if (templ.size()>0)
121 templName = (char *)templ.c_str();
122 SPDocument *doc = sp_document_new(templName, TRUE, true);
123 g_return_val_if_fail(doc != NULL, NULL);
125 SPDesktop *dt;
126 if (Inkscape::NSApplication::Application::getNewGui())
127 {
128 dt = Inkscape::NSApplication::Editor::createDesktop (doc);
129 } else {
130 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
131 g_return_val_if_fail(dtw != NULL, NULL);
132 sp_document_unref(doc);
134 sp_create_window(dtw, TRUE);
135 dt = static_cast<SPDesktop*>(dtw->view);
136 sp_namedview_window_from_document(dt);
137 sp_namedview_update_layers_from_document(dt);
138 }
139 return dt;
140 }
142 SPDesktop*
143 sp_file_new_default()
144 {
145 std::list<gchar *> sources;
146 sources.push_back( profile_path("templates") ); // first try user's local dir
147 sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
149 while (!sources.empty()) {
150 gchar *dirname = sources.front();
151 if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) {
153 // TRANSLATORS: default.svg is localizable - this is the name of the default document
154 // template. This way you can localize the default pagesize, translate the name of
155 // the default layer, etc. If you wish to localize this file, please create a
156 // localized share/templates/default.xx.svg file, where xx is your language code.
157 char *default_template = g_build_filename(dirname, _("default.svg"), NULL);
158 if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) {
159 return sp_file_new(default_template);
160 }
161 }
162 g_free(dirname);
163 sources.pop_front();
164 }
166 return sp_file_new("");
167 }
170 /*######################
171 ## D E L E T E
172 ######################*/
174 /**
175 * Perform document closures preceding an exit()
176 */
177 void
178 sp_file_exit()
179 {
180 sp_ui_close_all();
181 // no need to call inkscape_exit here; last document being closed will take care of that
182 }
185 /*######################
186 ## O P E N
187 ######################*/
189 /**
190 * Open a file, add the document to the desktop
191 *
192 * \param replace_empty if true, and the current desktop is empty, this document
193 * will replace the empty one.
194 */
195 bool
196 sp_file_open(const Glib::ustring &uri,
197 Inkscape::Extension::Extension *key,
198 bool add_to_recent, bool replace_empty)
199 {
200 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
201 if (desktop)
202 desktop->setWaitingCursor();
204 SPDocument *doc = NULL;
205 try {
206 doc = Inkscape::Extension::open(key, uri.c_str());
207 } catch (Inkscape::Extension::Input::no_extension_found &e) {
208 doc = NULL;
209 } catch (Inkscape::Extension::Input::open_failed &e) {
210 doc = NULL;
211 }
213 if (desktop)
214 desktop->clearWaitingCursor();
216 if (doc) {
217 SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;
219 if (existing && existing->virgin && replace_empty) {
220 // If the current desktop is empty, open the document there
221 sp_document_ensure_up_to_date (doc);
222 desktop->change_document(doc);
223 sp_document_resized_signal_emit (doc, sp_document_width(doc), sp_document_height(doc));
224 } else {
225 if (!Inkscape::NSApplication::Application::getNewGui()) {
226 // create a whole new desktop and window
227 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
228 sp_create_window(dtw, TRUE);
229 desktop = static_cast<SPDesktop*>(dtw->view);
230 } else {
231 desktop = Inkscape::NSApplication::Editor::createDesktop (doc);
232 }
233 }
235 doc->virgin = FALSE;
236 // everyone who cares now has a reference, get rid of ours
237 sp_document_unref(doc);
238 // resize the window to match the document properties
239 sp_namedview_window_from_document(desktop);
240 sp_namedview_update_layers_from_document(desktop);
242 if (add_to_recent) {
243 sp_file_add_recent(SP_DOCUMENT_URI(doc));
244 }
246 return TRUE;
247 } else {
248 gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
249 gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), safeUri);
250 sp_ui_error_dialog(text);
251 g_free(text);
252 g_free(safeUri);
253 return FALSE;
254 }
255 }
257 /**
258 * Handle prompting user for "do you want to revert"? Revert on "OK"
259 */
260 void
261 sp_file_revert_dialog()
262 {
263 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
264 g_assert(desktop != NULL);
266 SPDocument *doc = sp_desktop_document(desktop);
267 g_assert(doc != NULL);
269 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
270 g_assert(repr != NULL);
272 gchar const *uri = doc->uri;
273 if (!uri) {
274 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet. Cannot revert."));
275 return;
276 }
278 bool do_revert = true;
279 if (doc->isModifiedSinceSave()) {
280 gchar *text = g_strdup_printf(_("Changes will be lost! Are you sure you want to reload document %s?"), uri);
282 bool response = desktop->warnDialog (text);
283 g_free(text);
285 if (!response) {
286 do_revert = false;
287 }
288 }
290 bool reverted;
291 if (do_revert) {
292 // Allow overwriting of current document.
293 doc->virgin = TRUE;
295 // remember current zoom and view
296 double zoom = desktop->current_zoom();
297 Geom::Point c = desktop->get_display_area().midpoint();
299 reverted = sp_file_open(uri,NULL);
300 if (reverted) {
301 // restore zoom and view
302 desktop->zoom_absolute(c[Geom::X], c[Geom::Y], zoom);
303 }
304 } else {
305 reverted = false;
306 }
308 if (reverted) {
309 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document reverted."));
310 } else {
311 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not reverted."));
312 }
313 }
315 void dump_str(gchar const *str, gchar const *prefix)
316 {
317 Glib::ustring tmp;
318 tmp = prefix;
319 tmp += " [";
320 size_t const total = strlen(str);
321 for (unsigned i = 0; i < total; i++) {
322 gchar *const tmp2 = g_strdup_printf(" %02x", (0x0ff & str[i]));
323 tmp += tmp2;
324 g_free(tmp2);
325 }
327 tmp += "]";
328 g_message("%s", tmp.c_str());
329 }
331 void dump_ustr(Glib::ustring const &ustr)
332 {
333 char const *cstr = ustr.c_str();
334 char const *data = ustr.data();
335 Glib::ustring::size_type const byteLen = ustr.bytes();
336 Glib::ustring::size_type const dataLen = ustr.length();
337 Glib::ustring::size_type const cstrLen = strlen(cstr);
339 g_message(" size: %lu\n length: %lu\n bytes: %lu\n clen: %lu",
340 gulong(ustr.size()), gulong(dataLen), gulong(byteLen), gulong(cstrLen) );
341 g_message( " ASCII? %s", (ustr.is_ascii() ? "yes":"no") );
342 g_message( " UTF-8? %s", (ustr.validate() ? "yes":"no") );
344 try {
345 Glib::ustring tmp;
346 for (Glib::ustring::size_type i = 0; i < ustr.bytes(); i++) {
347 tmp = " ";
348 if (i < dataLen) {
349 Glib::ustring::value_type val = ustr.at(i);
350 gchar* tmp2 = g_strdup_printf( (((val & 0xff00) == 0) ? " %02x" : "%04x"), val );
351 tmp += tmp2;
352 g_free( tmp2 );
353 } else {
354 tmp += " ";
355 }
357 if (i < byteLen) {
358 int val = (0x0ff & data[i]);
359 gchar *tmp2 = g_strdup_printf(" %02x", val);
360 tmp += tmp2;
361 g_free( tmp2 );
362 if ( val > 32 && val < 127 ) {
363 tmp2 = g_strdup_printf( " '%c'", (gchar)val );
364 tmp += tmp2;
365 g_free( tmp2 );
366 } else {
367 tmp += " . ";
368 }
369 } else {
370 tmp += " ";
371 }
373 if ( i < cstrLen ) {
374 int val = (0x0ff & cstr[i]);
375 gchar* tmp2 = g_strdup_printf(" %02x", val);
376 tmp += tmp2;
377 g_free(tmp2);
378 if ( val > 32 && val < 127 ) {
379 tmp2 = g_strdup_printf(" '%c'", (gchar) val);
380 tmp += tmp2;
381 g_free( tmp2 );
382 } else {
383 tmp += " . ";
384 }
385 } else {
386 tmp += " ";
387 }
389 g_message( "%s", tmp.c_str() );
390 }
391 } catch (...) {
392 g_message("XXXXXXXXXXXXXXXXXX Exception" );
393 }
394 g_message("---------------");
395 }
397 /**
398 * Display an file Open selector. Open a document if OK is pressed.
399 * Can select single or multiple files for opening.
400 */
401 void
402 sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
403 {
404 //# Get the current directory for finding files
405 static Glib::ustring open_path;
406 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
408 if(open_path.empty())
409 {
410 Glib::ustring attr = prefs->getString("/dialogs/open/path");
411 if (!attr.empty()) open_path = attr;
412 }
414 //# Test if the open_path directory exists
415 if (!Inkscape::IO::file_test(open_path.c_str(),
416 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
417 open_path = "";
419 #ifdef WIN32
420 //# If no open path, default to our win32 documents folder
421 if (open_path.empty())
422 {
423 // The path to the My Documents folder is read from the
424 // value "HKEY_CURRENT_USER\Software\Windows\CurrentVersion\Explorer\Shell Folders\Personal"
425 HKEY key = NULL;
426 if(RegOpenKeyExA(HKEY_CURRENT_USER,
427 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
428 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
429 {
430 WCHAR utf16path[_MAX_PATH];
431 DWORD value_type;
432 DWORD data_size = sizeof(utf16path);
433 if(RegQueryValueExW(key, L"Personal", NULL, &value_type,
434 (BYTE*)utf16path, &data_size) == ERROR_SUCCESS)
435 {
436 g_assert(value_type == REG_SZ);
437 gchar *utf8path = g_utf16_to_utf8(
438 (const gunichar2*)utf16path, -1, NULL, NULL, NULL);
439 if(utf8path)
440 {
441 open_path = Glib::ustring(utf8path);
442 g_free(utf8path);
443 }
444 }
445 }
446 }
447 #endif
449 //# If no open path, default to our home directory
450 if (open_path.empty())
451 {
452 open_path = g_get_home_dir();
453 open_path.append(G_DIR_SEPARATOR_S);
454 }
456 //# Create a dialog
457 Inkscape::UI::Dialog::FileOpenDialog *openDialogInstance =
458 Inkscape::UI::Dialog::FileOpenDialog::create(
459 parentWindow, open_path,
460 Inkscape::UI::Dialog::SVG_TYPES,
461 _("Select file to open"));
463 //# Show the dialog
464 bool const success = openDialogInstance->show();
466 //# Save the folder the user selected for later
467 open_path = openDialogInstance->getCurrentDirectory();
469 if (!success)
470 {
471 delete openDialogInstance;
472 return;
473 }
475 //# User selected something. Get name and type
476 Glib::ustring fileName = openDialogInstance->getFilename();
478 Inkscape::Extension::Extension *selection =
479 openDialogInstance->getSelectionType();
481 //# Code to check & open if multiple files.
482 std::vector<Glib::ustring> flist = openDialogInstance->getFilenames();
484 //# We no longer need the file dialog object - delete it
485 delete openDialogInstance;
486 openDialogInstance = NULL;
488 //# Iterate through filenames if more than 1
489 if (flist.size() > 1)
490 {
491 for (unsigned int i = 0; i < flist.size(); i++)
492 {
493 fileName = flist[i];
495 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
496 if ( newFileName.size() > 0 )
497 fileName = newFileName;
498 else
499 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
501 #ifdef INK_DUMP_FILENAME_CONV
502 g_message("Opening File %s\n", fileName.c_str());
503 #endif
504 sp_file_open(fileName, selection);
505 }
507 return;
508 }
511 if (!fileName.empty())
512 {
513 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
515 if ( newFileName.size() > 0)
516 fileName = newFileName;
517 else
518 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
520 open_path = Glib::path_get_dirname (fileName);
521 open_path.append(G_DIR_SEPARATOR_S);
522 prefs->setString("/dialogs/open/path", open_path);
524 sp_file_open(fileName, selection);
525 }
527 return;
528 }
531 /*######################
532 ## V A C U U M
533 ######################*/
535 /**
536 * Remove unreferenced defs from the defs section of the document.
537 */
540 void
541 sp_file_vacuum()
542 {
543 SPDocument *doc = SP_ACTIVE_DOCUMENT;
545 unsigned int diff = vacuum_document (doc);
547 sp_document_done(doc, SP_VERB_FILE_VACUUM,
548 _("Vacuum <defs>"));
550 SPDesktop *dt = SP_ACTIVE_DESKTOP;
551 if (diff > 0) {
552 dt->messageStack()->flashF(Inkscape::NORMAL_MESSAGE,
553 ngettext("Removed <b>%i</b> unused definition in <defs>.",
554 "Removed <b>%i</b> unused definitions in <defs>.",
555 diff),
556 diff);
557 } else {
558 dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("No unused definitions in <defs>."));
559 }
560 }
564 /*######################
565 ## S A V E
566 ######################*/
568 /**
569 * This 'save' function called by the others below
570 *
571 * \param official whether to set :output_module and :modified in the
572 * document; is true for normal save, false for temporary saves
573 */
574 static bool
575 file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
576 Inkscape::Extension::Extension *key, bool saveas, bool official)
577 {
578 if (!doc || uri.size()<1) //Safety check
579 return false;
581 try {
582 Inkscape::Extension::save(key, doc, uri.c_str(),
583 false,
584 saveas, official);
585 } catch (Inkscape::Extension::Output::no_extension_found &e) {
586 gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
587 gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s). This may have been caused by an unknown filename extension."), safeUri);
588 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
589 sp_ui_error_dialog(text);
590 g_free(text);
591 g_free(safeUri);
592 return FALSE;
593 } catch (Inkscape::Extension::Output::save_failed &e) {
594 gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
595 gchar *text = g_strdup_printf(_("File %s could not be saved."), safeUri);
596 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
597 sp_ui_error_dialog(text);
598 g_free(text);
599 g_free(safeUri);
600 return FALSE;
601 } catch (Inkscape::Extension::Output::save_cancelled &e) {
602 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
603 return FALSE;
604 } catch (Inkscape::Extension::Output::no_overwrite &e) {
605 return sp_file_save_dialog(parentWindow, doc);
606 }
608 SP_ACTIVE_DESKTOP->event_log->rememberFileSave();
609 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document saved."));
610 return true;
611 }
613 /*
614 * Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp.
615 */
616 bool
617 file_save_remote(SPDocument */*doc*/,
618 #ifdef WITH_GNOME_VFS
619 const Glib::ustring &uri,
620 #else
621 const Glib::ustring &/*uri*/,
622 #endif
623 Inkscape::Extension::Extension */*key*/, bool /*saveas*/, bool /*official*/)
624 {
625 #ifdef WITH_GNOME_VFS
627 #define BUF_SIZE 8192
628 gnome_vfs_init();
630 GnomeVFSHandle *from_handle = NULL;
631 GnomeVFSHandle *to_handle = NULL;
632 GnomeVFSFileSize bytes_read;
633 GnomeVFSFileSize bytes_written;
634 GnomeVFSResult result;
635 guint8 buffer[8192];
637 gchar* uri_local = g_filename_from_utf8( uri.c_str(), -1, NULL, NULL, NULL);
639 if ( uri_local == NULL ) {
640 g_warning( "Error converting filename to locale encoding.");
641 }
643 // Gets the temp file name.
644 Glib::ustring fileName = Glib::get_tmp_dir ();
645 fileName.append(G_DIR_SEPARATOR_S);
646 fileName.append((gnome_vfs_uri_extract_short_name(gnome_vfs_uri_new(uri_local))));
648 // Open the temp file to send.
649 result = gnome_vfs_open (&from_handle, fileName.c_str(), GNOME_VFS_OPEN_READ);
651 if (result != GNOME_VFS_OK) {
652 g_warning("Could not find the temp saving.");
653 return false;
654 }
656 result = gnome_vfs_create (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
657 result = gnome_vfs_open (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE);
659 if (result != GNOME_VFS_OK) {
660 g_warning("file creating: %s", gnome_vfs_result_to_string(result));
661 return false;
662 }
664 while (1) {
666 result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
668 if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
669 result = gnome_vfs_close (from_handle);
670 result = gnome_vfs_close (to_handle);
671 return true;
672 }
674 if (result != GNOME_VFS_OK) {
675 g_warning("%s", gnome_vfs_result_to_string(result));
676 return false;
677 }
678 result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
679 if (result != GNOME_VFS_OK) {
680 g_warning("%s", gnome_vfs_result_to_string(result));
681 return false;
682 }
685 if (bytes_read != bytes_written){
686 return false;
687 }
689 }
690 return true;
691 #else
692 // in case we do not have GNOME_VFS
693 return false;
694 #endif
696 }
699 /**
700 * Display a SaveAs dialog. Save the document if OK pressed.
701 *
702 * \param ascopy (optional) wether to set the documents->uri to the new filename or not
703 */
704 bool
705 sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
706 {
708 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
709 Inkscape::Extension::Output *extension = 0;
710 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
712 //# Get the default extension name
713 Glib::ustring default_extension;
714 char *attr = (char *)repr->attribute("inkscape:output_extension");
715 if (!attr) {
716 Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
717 if(!attr2.empty()) default_extension = attr2;
718 } else {
719 default_extension = attr;
720 }
721 //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
723 Glib::ustring save_path;
724 Glib::ustring save_loc;
726 if (doc->uri == NULL) {
727 char formatBuf[256];
728 int i = 1;
730 Glib::ustring filename_extension = ".svg";
731 extension = dynamic_cast<Inkscape::Extension::Output *>
732 (Inkscape::Extension::db.get(default_extension.c_str()));
733 //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
734 if (extension)
735 filename_extension = extension->get_extension();
737 Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
738 if (!attr3.empty())
739 save_path = attr3;
741 if (!Inkscape::IO::file_test(save_path.c_str(),
742 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
743 save_path = "";
745 if (save_path.size()<1)
746 save_path = g_get_home_dir();
748 save_loc = save_path;
749 save_loc.append(G_DIR_SEPARATOR_S);
750 snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
751 save_loc.append(formatBuf);
753 while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) {
754 save_loc = save_path;
755 save_loc.append(G_DIR_SEPARATOR_S);
756 snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str());
757 save_loc.append(formatBuf);
758 }
759 } else {
760 save_loc = Glib::build_filename(Glib::path_get_dirname(doc->uri),
761 Glib::path_get_basename(doc->uri));
762 }
764 // convert save_loc from utf-8 to locale
765 // is this needed any more, now that everything is handled in
766 // Inkscape::IO?
767 Glib::ustring save_loc_local = Glib::filename_from_utf8(save_loc);
769 if ( save_loc_local.size() > 0)
770 save_loc = save_loc_local;
772 //# Show the SaveAs dialog
773 char const * dialog_title;
774 if (is_copy) {
775 dialog_title = (char const *) _("Select file to save a copy to");
776 } else {
777 dialog_title = (char const *) _("Select file to save to");
778 }
779 gchar* doc_title = doc->root->title();
780 Inkscape::UI::Dialog::FileSaveDialog *saveDialog =
781 Inkscape::UI::Dialog::FileSaveDialog::create(
782 parentWindow,
783 save_loc,
784 Inkscape::UI::Dialog::SVG_TYPES,
785 dialog_title,
786 default_extension,
787 doc_title ? doc_title : ""
788 );
790 saveDialog->setSelectionType(extension);
792 bool success = saveDialog->show();
793 if (!success) {
794 delete saveDialog;
795 return success;
796 }
798 // set new title here (call RDF to ensure metadata and title element are updated)
799 rdf_set_work_entity(doc, rdf_find_entity("title"), saveDialog->getDocTitle().c_str());
800 // free up old string
801 if(doc_title) g_free(doc_title);
803 Glib::ustring fileName = saveDialog->getFilename();
804 Inkscape::Extension::Extension *selectionType = saveDialog->getSelectionType();
806 delete saveDialog;
808 saveDialog = 0;
810 if (fileName.size() > 0) {
811 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
813 if ( newFileName.size()>0 )
814 fileName = newFileName;
815 else
816 g_warning( "Error converting save filename to UTF-8." );
818 success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy);
820 if (success && SP_DOCUMENT_URI(doc)) {
821 sp_file_add_recent(SP_DOCUMENT_URI(doc));
822 }
824 save_path = Glib::path_get_dirname(fileName);
825 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
826 prefs->setString("/dialogs/save_as/path", save_path);
828 return success;
829 }
832 return false;
833 }
836 /**
837 * Save a document, displaying a SaveAs dialog if necessary.
838 */
839 bool
840 sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc)
841 {
842 bool success = true;
844 if (doc->isModifiedSinceSave()) {
845 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
846 if ( doc->uri == NULL
847 || repr->attribute("inkscape:output_extension") == NULL )
848 {
849 return sp_file_save_dialog(parentWindow, doc, FALSE);
850 } else {
851 gchar const *fn = g_strdup(doc->uri);
852 gchar const *ext = repr->attribute("inkscape:output_extension");
853 success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE);
854 g_free((void *) fn);
855 }
856 } else {
857 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved."));
858 success = TRUE;
859 }
861 return success;
862 }
865 /**
866 * Save a document.
867 */
868 bool
869 sp_file_save(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
870 {
871 if (!SP_ACTIVE_DOCUMENT)
872 return false;
874 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Saving document..."));
876 sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
877 return sp_file_save_document(parentWindow, SP_ACTIVE_DOCUMENT);
878 }
881 /**
882 * Save a document, always displaying the SaveAs dialog.
883 */
884 bool
885 sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
886 {
887 if (!SP_ACTIVE_DOCUMENT)
888 return false;
889 sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
890 return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, FALSE);
891 }
895 /**
896 * Save a copy of a document, always displaying a sort of SaveAs dialog.
897 */
898 bool
899 sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
900 {
901 if (!SP_ACTIVE_DOCUMENT)
902 return false;
903 sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
904 return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, TRUE);
905 }
908 /*######################
909 ## I M P O R T
910 ######################*/
912 /**
913 * Import a resource. Called by sp_file_import()
914 */
915 void
916 file_import(SPDocument *in_doc, const Glib::ustring &uri,
917 Inkscape::Extension::Extension *key)
918 {
919 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
921 //DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
922 SPDocument *doc;
923 try {
924 doc = Inkscape::Extension::open(key, uri.c_str());
925 } catch (Inkscape::Extension::Input::no_extension_found &e) {
926 doc = NULL;
927 } catch (Inkscape::Extension::Input::open_failed &e) {
928 doc = NULL;
929 }
931 if (doc != NULL) {
932 Inkscape::XML::rebase_hrefs(doc, in_doc->base, true);
933 Inkscape::XML::Document *xml_in_doc = sp_document_repr_doc(in_doc);
935 prevent_id_clashes(doc, in_doc);
937 SPObject *in_defs = SP_DOCUMENT_DEFS(in_doc);
938 Inkscape::XML::Node *last_def = SP_OBJECT_REPR(in_defs)->lastChild();
940 SPCSSAttr *style = sp_css_attr_from_object(SP_DOCUMENT_ROOT(doc));
942 // Count the number of top-level items in the imported document.
943 guint items_count = 0;
944 for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
945 child != NULL; child = SP_OBJECT_NEXT(child))
946 {
947 if (SP_IS_ITEM(child)) items_count++;
948 }
950 // Create a new group if necessary.
951 Inkscape::XML::Node *newgroup = NULL;
952 if ((style && style->firstChild()) || items_count > 1) {
953 newgroup = xml_in_doc->createElement("svg:g");
954 sp_repr_css_set(newgroup, style, "style");
955 }
957 // Determine the place to insert the new object.
958 // This will be the current layer, if possible.
959 // FIXME: If there's no desktop (command line run?) we need
960 // a document:: method to return the current layer.
961 // For now, we just use the root in this case.
962 SPObject *place_to_insert;
963 if (desktop) {
964 place_to_insert = desktop->currentLayer();
965 } else {
966 place_to_insert = SP_DOCUMENT_ROOT(in_doc);
967 }
969 // Construct a new object representing the imported image,
970 // and insert it into the current document.
971 SPObject *new_obj = NULL;
972 for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
973 child != NULL; child = SP_OBJECT_NEXT(child) )
974 {
975 if (SP_IS_ITEM(child)) {
976 Inkscape::XML::Node *newitem = SP_OBJECT_REPR(child)->duplicate(xml_in_doc);
978 // convert layers to groups, and make sure they are unlocked
979 // FIXME: add "preserve layers" mode where each layer from
980 // import is copied to the same-named layer in host
981 newitem->setAttribute("inkscape:groupmode", NULL);
982 newitem->setAttribute("sodipodi:insensitive", NULL);
984 if (newgroup) newgroup->appendChild(newitem);
985 else new_obj = place_to_insert->appendChildRepr(newitem);
986 }
988 // don't lose top-level defs or style elements
989 else if (SP_OBJECT_REPR(child)->type() == Inkscape::XML::ELEMENT_NODE) {
990 const gchar *tag = SP_OBJECT_REPR(child)->name();
991 if (!strcmp(tag, "svg:defs")) {
992 for (SPObject *x = sp_object_first_child(child);
993 x != NULL; x = SP_OBJECT_NEXT(x))
994 {
995 SP_OBJECT_REPR(in_defs)->addChild(SP_OBJECT_REPR(x)->duplicate(xml_in_doc), last_def);
996 }
997 }
998 else if (!strcmp(tag, "svg:style")) {
999 SP_DOCUMENT_ROOT(in_doc)->appendChildRepr(SP_OBJECT_REPR(child)->duplicate(xml_in_doc));
1000 }
1001 }
1002 }
1003 if (newgroup) new_obj = place_to_insert->appendChildRepr(newgroup);
1005 // release some stuff
1006 if (newgroup) Inkscape::GC::release(newgroup);
1007 if (style) sp_repr_css_attr_unref(style);
1009 // select and move the imported item
1010 if (new_obj && SP_IS_ITEM(new_obj)) {
1011 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1012 selection->set(SP_ITEM(new_obj));
1014 // preserve parent and viewBox transformations
1015 // c2p is identity matrix at this point unless sp_document_ensure_up_to_date is called
1016 sp_document_ensure_up_to_date(doc);
1017 Geom::Matrix affine = SP_ROOT(SP_DOCUMENT_ROOT(doc))->c2p * sp_item_i2doc_affine(SP_ITEM(place_to_insert)).inverse();
1018 sp_selection_apply_affine(selection, desktop->dt2doc() * affine * desktop->doc2dt(), true, false);
1020 // move to mouse pointer
1021 {
1022 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1023 Geom::OptRect sel_bbox = selection->bounds();
1024 if (sel_bbox) {
1025 Geom::Point m( desktop->point() - sel_bbox->midpoint() );
1026 sp_selection_move_relative(selection, m, false);
1027 }
1028 }
1029 }
1031 sp_document_unref(doc);
1032 sp_document_done(in_doc, SP_VERB_FILE_IMPORT,
1033 _("Import"));
1035 } else {
1036 gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), uri.c_str());
1037 sp_ui_error_dialog(text);
1038 g_free(text);
1039 }
1041 return;
1042 }
1045 /**
1046 * Display an Open dialog, import a resource if OK pressed.
1047 */
1048 void
1049 sp_file_import(Gtk::Window &parentWindow)
1050 {
1051 static Glib::ustring import_path;
1053 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1054 if (!doc)
1055 return;
1057 // Create new dialog (don't use an old one, because parentWindow has probably changed)
1058 Inkscape::UI::Dialog::FileOpenDialog *importDialogInstance =
1059 Inkscape::UI::Dialog::FileOpenDialog::create(
1060 parentWindow,
1061 import_path,
1062 Inkscape::UI::Dialog::IMPORT_TYPES,
1063 (char const *)_("Select file to import"));
1065 bool success = importDialogInstance->show();
1066 if (!success) {
1067 delete importDialogInstance;
1068 return;
1069 }
1071 //# Get file name and extension type
1072 Glib::ustring fileName = importDialogInstance->getFilename();
1073 Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1075 delete importDialogInstance;
1076 importDialogInstance = NULL;
1078 if (fileName.size() > 0) {
1080 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1082 if ( newFileName.size() > 0)
1083 fileName = newFileName;
1084 else
1085 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1088 import_path = fileName;
1089 if (import_path.size()>0)
1090 import_path.append(G_DIR_SEPARATOR_S);
1092 file_import(doc, fileName, selection);
1093 }
1095 return;
1096 }
1100 /*######################
1101 ## E X P O R T
1102 ######################*/
1104 //#define NEW_EXPORT_DIALOG
1108 #ifdef NEW_EXPORT_DIALOG
1110 /**
1111 * Display an Export dialog, export as the selected type if OK pressed
1112 */
1113 bool
1114 sp_file_export_dialog(void *widget)
1115 {
1116 //# temp hack for 'doc' until we can switch to this dialog
1117 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1119 Glib::ustring export_path;
1120 Glib::ustring export_loc;
1122 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
1123 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1124 Inkscape::Extension::Output *extension;
1126 //# Get the default extension name
1127 Glib::ustring default_extension;
1128 char *attr = (char *)repr->attribute("inkscape:output_extension");
1129 if (!attr) {
1130 Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
1131 if(!attr2.empty()) default_extension = attr2;
1132 } else {
1133 default_extension = attr;
1134 }
1135 //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
1137 if (doc->uri == NULL)
1138 {
1139 char formatBuf[256];
1141 Glib::ustring filename_extension = ".svg";
1142 extension = dynamic_cast<Inkscape::Extension::Output *>
1143 (Inkscape::Extension::db.get(default_extension.c_str()));
1144 //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
1145 if (extension)
1146 filename_extension = extension->get_extension();
1148 Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
1149 if (!attr3.empty())
1150 export_path = attr3;
1152 if (!Inkscape::IO::file_test(export_path.c_str(),
1153 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1154 export_path = "";
1156 if (export_path.size()<1)
1157 export_path = g_get_home_dir();
1159 export_loc = export_path;
1160 export_loc.append(G_DIR_SEPARATOR_S);
1161 snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1162 export_loc.append(formatBuf);
1164 }
1165 else
1166 {
1167 export_path = Glib::path_get_dirname(doc->uri);
1168 }
1170 // convert save_loc from utf-8 to locale
1171 // is this needed any more, now that everything is handled in
1172 // Inkscape::IO?
1173 Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1174 if ( export_path_local.size() > 0)
1175 export_path = export_path_local;
1177 //# Show the SaveAs dialog
1178 Inkscape::UI::Dialog::FileExportDialog *exportDialogInstance =
1179 Inkscape::UI::Dialog::FileExportDialog::create(
1180 export_path,
1181 Inkscape::UI::Dialog::EXPORT_TYPES,
1182 (char const *) _("Select file to export to"),
1183 default_extension
1184 );
1186 bool success = exportDialogInstance->show();
1187 if (!success) {
1188 delete exportDialogInstance;
1189 return success;
1190 }
1192 Glib::ustring fileName = exportDialogInstance->getFilename();
1194 Inkscape::Extension::Extension *selectionType =
1195 exportDialogInstance->getSelectionType();
1197 delete exportDialogInstance;
1198 exportDialogInstance = NULL;
1200 if (fileName.size() > 0) {
1201 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1203 if ( newFileName.size()>0 )
1204 fileName = newFileName;
1205 else
1206 g_warning( "Error converting save filename to UTF-8." );
1208 success = file_save(doc, fileName, selectionType, TRUE, FALSE);
1210 if (success) {
1211 Glib::RefPtr<Gtk::RecentManager> recent = Gtk::RecentManager::get_default();
1212 recent->add_item(SP_DOCUMENT_URI(doc));
1213 }
1215 export_path = fileName;
1216 prefs->setString("/dialogs/save_as/path", export_path);
1218 return success;
1219 }
1222 return false;
1223 }
1225 #else
1227 /**
1228 *
1229 */
1230 bool
1231 sp_file_export_dialog(void */*widget*/)
1232 {
1233 sp_export_dialog();
1234 return true;
1235 }
1237 #endif
1239 /*######################
1240 ## E X P O R T T O O C A L
1241 ######################*/
1243 /**
1244 * Display an Export dialog, export as the selected type if OK pressed
1245 */
1246 bool
1247 sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow)
1248 {
1250 if (!SP_ACTIVE_DOCUMENT)
1251 return false;
1253 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1255 Glib::ustring export_path;
1256 Glib::ustring export_loc;
1257 Glib::ustring fileName;
1258 Inkscape::Extension::Extension *selectionType;
1260 bool success = false;
1262 static bool gotSuccess = false;
1264 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
1265 (void)repr;
1267 if (!doc->uri && !doc->isModifiedSinceSave())
1268 return false;
1270 // Get the default extension name
1271 Glib::ustring default_extension = "org.inkscape.output.svg.inkscape";
1272 char formatBuf[256];
1274 Glib::ustring filename_extension = ".svg";
1275 selectionType = Inkscape::Extension::db.get(default_extension.c_str());
1277 export_path = Glib::get_tmp_dir ();
1279 export_loc = export_path;
1280 export_loc.append(G_DIR_SEPARATOR_S);
1281 snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1282 export_loc.append(formatBuf);
1284 // convert save_loc from utf-8 to locale
1285 // is this needed any more, now that everything is handled in
1286 // Inkscape::IO?
1287 Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1288 if ( export_path_local.size() > 0)
1289 export_path = export_path_local;
1291 // Show the Export To OCAL dialog
1292 Inkscape::UI::Dialog::FileExportToOCALDialog *exportDialogInstance =
1293 new Inkscape::UI::Dialog::FileExportToOCALDialog(
1294 parentWindow,
1295 Inkscape::UI::Dialog::EXPORT_TYPES,
1296 (char const *) _("Select file to export to")
1297 );
1299 success = exportDialogInstance->show();
1300 if (!success) {
1301 delete exportDialogInstance;
1302 return success;
1303 }
1305 fileName = exportDialogInstance->getFilename();
1307 delete exportDialogInstance;
1308 exportDialogInstance = NULL;;
1310 fileName.append(filename_extension.c_str());
1311 if (fileName.size() > 0) {
1312 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1314 if ( newFileName.size()>0 )
1315 fileName = newFileName;
1316 else
1317 g_warning( "Error converting save filename to UTF-8." );
1318 }
1319 Glib::ustring filePath = export_path;
1320 filePath.append(G_DIR_SEPARATOR_S);
1321 filePath.append(Glib::path_get_basename(fileName));
1323 fileName = filePath;
1325 success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE);
1327 if (!success){
1328 gchar *text = g_strdup_printf(_("Error saving a temporary copy"));
1329 sp_ui_error_dialog(text);
1331 return success;
1332 }
1334 // Start now the submition
1336 // Create the uri
1337 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1338 Glib::ustring uri = "dav://";
1339 Glib::ustring username = prefs->getString("/options/ocalusername/str");
1340 Glib::ustring password = prefs->getString("/options/ocalpassword/str");
1341 if (username.empty() || password.empty())
1342 {
1343 Inkscape::UI::Dialog::FileExportToOCALPasswordDialog *exportPasswordDialogInstance = NULL;
1344 if(!gotSuccess)
1345 {
1346 exportPasswordDialogInstance = new Inkscape::UI::Dialog::FileExportToOCALPasswordDialog(
1347 parentWindow,
1348 (char const *) _("Open Clip Art Login"));
1349 success = exportPasswordDialogInstance->show();
1350 if (!success) {
1351 delete exportPasswordDialogInstance;
1352 return success;
1353 }
1354 }
1355 username = exportPasswordDialogInstance->getUsername();
1356 password = exportPasswordDialogInstance->getPassword();
1358 delete exportPasswordDialogInstance;
1359 exportPasswordDialogInstance = NULL;
1360 }
1361 uri.append(username);
1362 uri.append(":");
1363 uri.append(password);
1364 uri.append("@");
1365 uri.append(prefs->getString("/options/ocalurl/str"));
1366 uri.append("/dav.php/");
1367 uri.append(Glib::path_get_basename(fileName));
1369 // Save as a remote file using the dav protocol.
1370 success = file_save_remote(doc, uri, selectionType, FALSE, FALSE);
1371 remove(fileName.c_str());
1372 if (!success)
1373 {
1374 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."));
1375 sp_ui_error_dialog(text);
1376 }
1377 else
1378 gotSuccess = true;
1380 return success;
1381 }
1383 /**
1384 * Export the current document to OCAL
1385 */
1386 void
1387 sp_file_export_to_ocal(Gtk::Window &parentWindow)
1388 {
1390 // Try to execute the new code and return;
1391 if (!SP_ACTIVE_DOCUMENT)
1392 return;
1393 bool success = sp_file_export_to_ocal_dialog(parentWindow);
1394 if (success)
1395 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Document exported..."));
1396 }
1399 /*######################
1400 ## I M P O R T F R O M O C A L
1401 ######################*/
1403 /**
1404 * Display an ImportToOcal Dialog, and the selected document from OCAL
1405 */
1406 void
1407 sp_file_import_from_ocal(Gtk::Window &parentWindow)
1408 {
1409 static Glib::ustring import_path;
1411 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1412 if (!doc)
1413 return;
1415 Inkscape::UI::Dialog::FileImportFromOCALDialog *importDialogInstance = NULL;
1417 if (!importDialogInstance) {
1418 importDialogInstance = new
1419 Inkscape::UI::Dialog::FileImportFromOCALDialog(
1420 parentWindow,
1421 import_path,
1422 Inkscape::UI::Dialog::IMPORT_TYPES,
1423 (char const *)_("Import From Open Clip Art Library"));
1424 }
1426 bool success = importDialogInstance->show();
1427 if (!success) {
1428 delete importDialogInstance;
1429 return;
1430 }
1432 // Get file name and extension type
1433 Glib::ustring fileName = importDialogInstance->getFilename();
1434 Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1436 delete importDialogInstance;
1437 importDialogInstance = NULL;
1439 if (fileName.size() > 0) {
1441 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1443 if ( newFileName.size() > 0)
1444 fileName = newFileName;
1445 else
1446 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1448 import_path = fileName;
1449 if (import_path.size()>0)
1450 import_path.append(G_DIR_SEPARATOR_S);
1452 file_import(doc, fileName, selection);
1453 }
1455 return;
1456 }
1458 /*######################
1459 ## P R I N T
1460 ######################*/
1463 /**
1464 * Print the current document, if any.
1465 */
1466 void
1467 sp_file_print(Gtk::Window& parentWindow)
1468 {
1469 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1470 if (doc)
1471 sp_print_document(parentWindow, doc);
1472 }
1474 /**
1475 * Display what the drawing would look like, if
1476 * printed.
1477 */
1478 void
1479 sp_file_print_preview(gpointer /*object*/, gpointer /*data*/)
1480 {
1482 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1483 if (doc)
1484 sp_print_preview_document(doc);
1486 }
1489 /*
1490 Local Variables:
1491 mode:c++
1492 c-file-style:"stroustrup"
1493 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1494 indent-tabs-mode:nil
1495 fill-column:99
1496 End:
1497 */
1498 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :