420eaec6393c7038ba576ad9f7a99f4beb4bc4d2
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/ocaldialogs.h"
63 #include "ui/view/view-widget.h"
64 #include "uri.h"
65 #include "xml/rebase-hrefs.h"
67 #ifdef WITH_GNOME_VFS
68 # include <libgnomevfs/gnome-vfs.h>
69 #endif
71 #ifdef WITH_INKBOARD
72 #include "jabber_whiteboard/session-manager.h"
73 #endif
75 #ifdef WIN32
76 #include <windows.h>
77 #endif
79 //#define INK_DUMP_FILENAME_CONV 1
80 #undef INK_DUMP_FILENAME_CONV
82 //#define INK_DUMP_FOPEN 1
83 #undef INK_DUMP_FOPEN
85 void dump_str(gchar const *str, gchar const *prefix);
86 void dump_ustr(Glib::ustring const &ustr);
88 // what gets passed here is not actually an URI... it is an UTF-8 encoded filename (!)
89 static void sp_file_add_recent(gchar const *uri)
90 {
91 if(uri == NULL) {
92 g_warning("sp_file_add_recent: uri == NULL");
93 return;
94 }
95 GtkRecentManager *recent = gtk_recent_manager_get_default();
96 gchar *fn = g_filename_from_utf8(uri, -1, NULL, NULL, NULL);
97 if (fn) {
98 gchar *uri_to_add = g_filename_to_uri(fn, NULL, NULL);
99 if (uri_to_add) {
100 gtk_recent_manager_add_item(recent, uri_to_add);
101 g_free(uri_to_add);
102 }
103 g_free(fn);
104 }
105 }
108 /*######################
109 ## N E W
110 ######################*/
112 /**
113 * Create a blank document and add it to the desktop
114 */
115 SPDesktop*
116 sp_file_new(const Glib::ustring &templ)
117 {
118 char *templName = NULL;
119 if (templ.size()>0)
120 templName = (char *)templ.c_str();
121 SPDocument *doc = sp_document_new(templName, TRUE, true);
122 g_return_val_if_fail(doc != NULL, NULL);
124 SPDesktop *dt;
125 if (Inkscape::NSApplication::Application::getNewGui())
126 {
127 dt = Inkscape::NSApplication::Editor::createDesktop (doc);
128 } else {
129 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
130 g_return_val_if_fail(dtw != NULL, NULL);
131 sp_document_unref(doc);
133 sp_create_window(dtw, TRUE);
134 dt = static_cast<SPDesktop*>(dtw->view);
135 sp_namedview_window_from_document(dt);
136 sp_namedview_update_layers_from_document(dt);
137 }
138 return dt;
139 }
141 SPDesktop*
142 sp_file_new_default()
143 {
144 std::list<gchar *> sources;
145 sources.push_back( profile_path("templates") ); // first try user's local dir
146 sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
148 while (!sources.empty()) {
149 gchar *dirname = sources.front();
150 if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) {
152 // TRANSLATORS: default.svg is localizable - this is the name of the default document
153 // template. This way you can localize the default pagesize, translate the name of
154 // the default layer, etc. If you wish to localize this file, please create a
155 // localized share/templates/default.xx.svg file, where xx is your language code.
156 char *default_template = g_build_filename(dirname, _("default.svg"), NULL);
157 if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) {
158 return sp_file_new(default_template);
159 }
160 }
161 g_free(dirname);
162 sources.pop_front();
163 }
165 return sp_file_new("");
166 }
169 /*######################
170 ## D E L E T E
171 ######################*/
173 /**
174 * Perform document closures preceding an exit()
175 */
176 void
177 sp_file_exit()
178 {
179 sp_ui_close_all();
180 // no need to call inkscape_exit here; last document being closed will take care of that
181 }
184 /*######################
185 ## O P E N
186 ######################*/
188 /**
189 * Open a file, add the document to the desktop
190 *
191 * \param replace_empty if true, and the current desktop is empty, this document
192 * will replace the empty one.
193 */
194 bool
195 sp_file_open(const Glib::ustring &uri,
196 Inkscape::Extension::Extension *key,
197 bool add_to_recent, bool replace_empty)
198 {
199 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
200 if (desktop)
201 desktop->setWaitingCursor();
203 SPDocument *doc = NULL;
204 try {
205 doc = Inkscape::Extension::open(key, uri.c_str());
206 } catch (Inkscape::Extension::Input::no_extension_found &e) {
207 doc = NULL;
208 } catch (Inkscape::Extension::Input::open_failed &e) {
209 doc = NULL;
210 }
212 if (desktop)
213 desktop->clearWaitingCursor();
215 if (doc) {
216 SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;
218 if (existing && existing->virgin && replace_empty) {
219 // If the current desktop is empty, open the document there
220 sp_document_ensure_up_to_date (doc);
221 desktop->change_document(doc);
222 sp_document_resized_signal_emit (doc, sp_document_width(doc), sp_document_height(doc));
223 } else {
224 if (!Inkscape::NSApplication::Application::getNewGui()) {
225 // create a whole new desktop and window
226 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
227 sp_create_window(dtw, TRUE);
228 desktop = static_cast<SPDesktop*>(dtw->view);
229 } else {
230 desktop = Inkscape::NSApplication::Editor::createDesktop (doc);
231 }
232 }
234 doc->virgin = FALSE;
235 // everyone who cares now has a reference, get rid of ours
236 sp_document_unref(doc);
237 // resize the window to match the document properties
238 sp_namedview_window_from_document(desktop);
239 sp_namedview_update_layers_from_document(desktop);
241 if (add_to_recent) {
242 sp_file_add_recent(SP_DOCUMENT_URI(doc));
243 }
245 return TRUE;
246 } else {
247 gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
248 gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), safeUri);
249 sp_ui_error_dialog(text);
250 g_free(text);
251 g_free(safeUri);
252 return FALSE;
253 }
254 }
256 /**
257 * Handle prompting user for "do you want to revert"? Revert on "OK"
258 */
259 void
260 sp_file_revert_dialog()
261 {
262 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
263 g_assert(desktop != NULL);
265 SPDocument *doc = sp_desktop_document(desktop);
266 g_assert(doc != NULL);
268 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
269 g_assert(repr != NULL);
271 gchar const *uri = doc->uri;
272 if (!uri) {
273 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet. Cannot revert."));
274 return;
275 }
277 bool do_revert = true;
278 if (doc->isModifiedSinceSave()) {
279 gchar *text = g_strdup_printf(_("Changes will be lost! Are you sure you want to reload document %s?"), uri);
281 bool response = desktop->warnDialog (text);
282 g_free(text);
284 if (!response) {
285 do_revert = false;
286 }
287 }
289 bool reverted;
290 if (do_revert) {
291 // Allow overwriting of current document.
292 doc->virgin = TRUE;
294 // remember current zoom and view
295 double zoom = desktop->current_zoom();
296 Geom::Point c = desktop->get_display_area().midpoint();
298 reverted = sp_file_open(uri,NULL);
299 if (reverted) {
300 // restore zoom and view
301 desktop->zoom_absolute(c[Geom::X], c[Geom::Y], zoom);
302 }
303 } else {
304 reverted = false;
305 }
307 if (reverted) {
308 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document reverted."));
309 } else {
310 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not reverted."));
311 }
312 }
314 void dump_str(gchar const *str, gchar const *prefix)
315 {
316 Glib::ustring tmp;
317 tmp = prefix;
318 tmp += " [";
319 size_t const total = strlen(str);
320 for (unsigned i = 0; i < total; i++) {
321 gchar *const tmp2 = g_strdup_printf(" %02x", (0x0ff & str[i]));
322 tmp += tmp2;
323 g_free(tmp2);
324 }
326 tmp += "]";
327 g_message("%s", tmp.c_str());
328 }
330 void dump_ustr(Glib::ustring const &ustr)
331 {
332 char const *cstr = ustr.c_str();
333 char const *data = ustr.data();
334 Glib::ustring::size_type const byteLen = ustr.bytes();
335 Glib::ustring::size_type const dataLen = ustr.length();
336 Glib::ustring::size_type const cstrLen = strlen(cstr);
338 g_message(" size: %lu\n length: %lu\n bytes: %lu\n clen: %lu",
339 gulong(ustr.size()), gulong(dataLen), gulong(byteLen), gulong(cstrLen) );
340 g_message( " ASCII? %s", (ustr.is_ascii() ? "yes":"no") );
341 g_message( " UTF-8? %s", (ustr.validate() ? "yes":"no") );
343 try {
344 Glib::ustring tmp;
345 for (Glib::ustring::size_type i = 0; i < ustr.bytes(); i++) {
346 tmp = " ";
347 if (i < dataLen) {
348 Glib::ustring::value_type val = ustr.at(i);
349 gchar* tmp2 = g_strdup_printf( (((val & 0xff00) == 0) ? " %02x" : "%04x"), val );
350 tmp += tmp2;
351 g_free( tmp2 );
352 } else {
353 tmp += " ";
354 }
356 if (i < byteLen) {
357 int val = (0x0ff & data[i]);
358 gchar *tmp2 = g_strdup_printf(" %02x", val);
359 tmp += tmp2;
360 g_free( tmp2 );
361 if ( val > 32 && val < 127 ) {
362 tmp2 = g_strdup_printf( " '%c'", (gchar)val );
363 tmp += tmp2;
364 g_free( tmp2 );
365 } else {
366 tmp += " . ";
367 }
368 } else {
369 tmp += " ";
370 }
372 if ( i < cstrLen ) {
373 int val = (0x0ff & cstr[i]);
374 gchar* tmp2 = g_strdup_printf(" %02x", val);
375 tmp += tmp2;
376 g_free(tmp2);
377 if ( val > 32 && val < 127 ) {
378 tmp2 = g_strdup_printf(" '%c'", (gchar) val);
379 tmp += tmp2;
380 g_free( tmp2 );
381 } else {
382 tmp += " . ";
383 }
384 } else {
385 tmp += " ";
386 }
388 g_message( "%s", tmp.c_str() );
389 }
390 } catch (...) {
391 g_message("XXXXXXXXXXXXXXXXXX Exception" );
392 }
393 g_message("---------------");
394 }
396 /**
397 * Display an file Open selector. Open a document if OK is pressed.
398 * Can select single or multiple files for opening.
399 */
400 void
401 sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
402 {
403 //# Get the current directory for finding files
404 static Glib::ustring open_path;
405 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
407 if(open_path.empty())
408 {
409 Glib::ustring attr = prefs->getString("/dialogs/open/path");
410 if (!attr.empty()) open_path = attr;
411 }
413 //# Test if the open_path directory exists
414 if (!Inkscape::IO::file_test(open_path.c_str(),
415 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
416 open_path = "";
418 #ifdef WIN32
419 //# If no open path, default to our win32 documents folder
420 if (open_path.empty())
421 {
422 // The path to the My Documents folder is read from the
423 // value "HKEY_CURRENT_USER\Software\Windows\CurrentVersion\Explorer\Shell Folders\Personal"
424 HKEY key = NULL;
425 if(RegOpenKeyExA(HKEY_CURRENT_USER,
426 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
427 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
428 {
429 WCHAR utf16path[_MAX_PATH];
430 DWORD value_type;
431 DWORD data_size = sizeof(utf16path);
432 if(RegQueryValueExW(key, L"Personal", NULL, &value_type,
433 (BYTE*)utf16path, &data_size) == ERROR_SUCCESS)
434 {
435 g_assert(value_type == REG_SZ);
436 gchar *utf8path = g_utf16_to_utf8(
437 (const gunichar2*)utf16path, -1, NULL, NULL, NULL);
438 if(utf8path)
439 {
440 open_path = Glib::ustring(utf8path);
441 g_free(utf8path);
442 }
443 }
444 }
445 }
446 #endif
448 //# If no open path, default to our home directory
449 if (open_path.empty())
450 {
451 open_path = g_get_home_dir();
452 open_path.append(G_DIR_SEPARATOR_S);
453 }
455 //# Create a dialog
456 Inkscape::UI::Dialog::FileOpenDialog *openDialogInstance =
457 Inkscape::UI::Dialog::FileOpenDialog::create(
458 parentWindow, open_path,
459 Inkscape::UI::Dialog::SVG_TYPES,
460 _("Select file to open"));
462 //# Show the dialog
463 bool const success = openDialogInstance->show();
465 //# Save the folder the user selected for later
466 open_path = openDialogInstance->getCurrentDirectory();
468 if (!success)
469 {
470 delete openDialogInstance;
471 return;
472 }
474 //# User selected something. Get name and type
475 Glib::ustring fileName = openDialogInstance->getFilename();
477 Inkscape::Extension::Extension *selection =
478 openDialogInstance->getSelectionType();
480 //# Code to check & open if multiple files.
481 std::vector<Glib::ustring> flist = openDialogInstance->getFilenames();
483 //# We no longer need the file dialog object - delete it
484 delete openDialogInstance;
485 openDialogInstance = NULL;
487 //# Iterate through filenames if more than 1
488 if (flist.size() > 1)
489 {
490 for (unsigned int i = 0; i < flist.size(); i++)
491 {
492 fileName = flist[i];
494 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
495 if ( newFileName.size() > 0 )
496 fileName = newFileName;
497 else
498 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
500 #ifdef INK_DUMP_FILENAME_CONV
501 g_message("Opening File %s\n", fileName.c_str());
502 #endif
503 sp_file_open(fileName, selection);
504 }
506 return;
507 }
510 if (!fileName.empty())
511 {
512 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
514 if ( newFileName.size() > 0)
515 fileName = newFileName;
516 else
517 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
519 open_path = Glib::path_get_dirname (fileName);
520 open_path.append(G_DIR_SEPARATOR_S);
521 prefs->setString("/dialogs/open/path", open_path);
523 sp_file_open(fileName, selection);
524 }
526 return;
527 }
530 /*######################
531 ## V A C U U M
532 ######################*/
534 /**
535 * Remove unreferenced defs from the defs section of the document.
536 */
539 void
540 sp_file_vacuum()
541 {
542 SPDocument *doc = SP_ACTIVE_DOCUMENT;
544 unsigned int diff = vacuum_document (doc);
546 sp_document_done(doc, SP_VERB_FILE_VACUUM,
547 _("Vacuum <defs>"));
549 SPDesktop *dt = SP_ACTIVE_DESKTOP;
550 if (diff > 0) {
551 dt->messageStack()->flashF(Inkscape::NORMAL_MESSAGE,
552 ngettext("Removed <b>%i</b> unused definition in <defs>.",
553 "Removed <b>%i</b> unused definitions in <defs>.",
554 diff),
555 diff);
556 } else {
557 dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("No unused definitions in <defs>."));
558 }
559 }
563 /*######################
564 ## S A V E
565 ######################*/
567 /**
568 * This 'save' function called by the others below
569 *
570 * \param official whether to set :output_module and :modified in the
571 * document; is true for normal save, false for temporary saves
572 */
573 static bool
574 file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
575 Inkscape::Extension::Extension *key, bool checkoverwrite, bool official,
576 Inkscape::Extension::FileSaveMethod save_method)
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 checkoverwrite, official,
585 save_method);
586 } catch (Inkscape::Extension::Output::no_extension_found &e) {
587 gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
588 gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s). This may have been caused by an unknown filename extension."), safeUri);
589 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
590 sp_ui_error_dialog(text);
591 g_free(text);
592 g_free(safeUri);
593 return FALSE;
594 } catch (Inkscape::Extension::Output::save_failed &e) {
595 gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
596 gchar *text = g_strdup_printf(_("File %s could not be saved."), safeUri);
597 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
598 sp_ui_error_dialog(text);
599 g_free(text);
600 g_free(safeUri);
601 return FALSE;
602 } catch (Inkscape::Extension::Output::save_cancelled &e) {
603 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
604 return FALSE;
605 } catch (Inkscape::Extension::Output::no_overwrite &e) {
606 return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
607 }
609 SP_ACTIVE_DESKTOP->event_log->rememberFileSave();
610 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document saved."));
611 return true;
612 }
614 /*
615 * Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp.
616 */
617 bool
618 file_save_remote(SPDocument */*doc*/,
619 #ifdef WITH_GNOME_VFS
620 const Glib::ustring &uri,
621 #else
622 const Glib::ustring &/*uri*/,
623 #endif
624 Inkscape::Extension::Extension */*key*/, bool /*saveas*/, bool /*official*/)
625 {
626 #ifdef WITH_GNOME_VFS
628 #define BUF_SIZE 8192
629 gnome_vfs_init();
631 GnomeVFSHandle *from_handle = NULL;
632 GnomeVFSHandle *to_handle = NULL;
633 GnomeVFSFileSize bytes_read;
634 GnomeVFSFileSize bytes_written;
635 GnomeVFSResult result;
636 guint8 buffer[8192];
638 gchar* uri_local = g_filename_from_utf8( uri.c_str(), -1, NULL, NULL, NULL);
640 if ( uri_local == NULL ) {
641 g_warning( "Error converting filename to locale encoding.");
642 }
644 // Gets the temp file name.
645 Glib::ustring fileName = Glib::get_tmp_dir ();
646 fileName.append(G_DIR_SEPARATOR_S);
647 fileName.append((gnome_vfs_uri_extract_short_name(gnome_vfs_uri_new(uri_local))));
649 // Open the temp file to send.
650 result = gnome_vfs_open (&from_handle, fileName.c_str(), GNOME_VFS_OPEN_READ);
652 if (result != GNOME_VFS_OK) {
653 g_warning("Could not find the temp saving.");
654 return false;
655 }
657 result = gnome_vfs_create (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
658 result = gnome_vfs_open (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE);
660 if (result != GNOME_VFS_OK) {
661 g_warning("file creating: %s", gnome_vfs_result_to_string(result));
662 return false;
663 }
665 while (1) {
667 result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
669 if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
670 result = gnome_vfs_close (from_handle);
671 result = gnome_vfs_close (to_handle);
672 return true;
673 }
675 if (result != GNOME_VFS_OK) {
676 g_warning("%s", gnome_vfs_result_to_string(result));
677 return false;
678 }
679 result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
680 if (result != GNOME_VFS_OK) {
681 g_warning("%s", gnome_vfs_result_to_string(result));
682 return false;
683 }
686 if (bytes_read != bytes_written){
687 return false;
688 }
690 }
691 return true;
692 #else
693 // in case we do not have GNOME_VFS
694 return false;
695 #endif
697 }
700 /**
701 * Display a SaveAs dialog. Save the document if OK pressed.
702 */
703 bool
704 sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extension::FileSaveMethod save_method)
705 {
706 Inkscape::Extension::Output *extension = 0;
707 bool is_copy = (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY);
709 // Note: default_extension has the format "org.inkscape.output.svg.inkscape", whereas
710 // filename_extension only uses ".svg"
711 Glib::ustring default_extension;
712 Glib::ustring filename_extension = ".svg";
714 default_extension= Inkscape::Extension::get_file_save_extension(save_method);
715 //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
717 extension = dynamic_cast<Inkscape::Extension::Output *>
718 (Inkscape::Extension::db.get(default_extension.c_str()));
720 if (extension)
721 filename_extension = extension->get_extension();
723 Glib::ustring save_path;
724 Glib::ustring save_loc;
726 save_path = Inkscape::Extension::get_file_save_path(doc, save_method);
728 if (!Inkscape::IO::file_test(save_path.c_str(),
729 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
730 save_path = "";
732 if (save_path.size()<1)
733 save_path = g_get_home_dir();
735 save_loc = save_path;
736 save_loc.append(G_DIR_SEPARATOR_S);
738 char formatBuf[256];
739 int i = 1;
740 if (!doc->uri) {
741 // We are saving for the first time; create a unique default filename
742 snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
743 save_loc.append(formatBuf);
745 while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) {
746 save_loc = save_path;
747 save_loc.append(G_DIR_SEPARATOR_S);
748 snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str());
749 save_loc.append(formatBuf);
750 }
751 } else {
752 snprintf(formatBuf, 255, _("%s"), Glib::path_get_basename(doc->uri).c_str());
753 save_loc.append(formatBuf);
754 }
756 // convert save_loc from utf-8 to locale
757 // is this needed any more, now that everything is handled in
758 // Inkscape::IO?
759 Glib::ustring save_loc_local = Glib::filename_from_utf8(save_loc);
761 if ( save_loc_local.size() > 0)
762 save_loc = save_loc_local;
764 //# Show the SaveAs dialog
765 char const * dialog_title;
766 if (is_copy) {
767 dialog_title = (char const *) _("Select file to save a copy to");
768 } else {
769 dialog_title = (char const *) _("Select file to save to");
770 }
771 gchar* doc_title = doc->root->title();
772 Inkscape::UI::Dialog::FileSaveDialog *saveDialog =
773 Inkscape::UI::Dialog::FileSaveDialog::create(
774 parentWindow,
775 save_loc,
776 Inkscape::UI::Dialog::SVG_TYPES,
777 dialog_title,
778 default_extension,
779 doc_title ? doc_title : "",
780 save_method
781 );
783 saveDialog->setSelectionType(extension);
785 bool success = saveDialog->show();
786 if (!success) {
787 delete saveDialog;
788 return success;
789 }
791 // set new title here (call RDF to ensure metadata and title element are updated)
792 rdf_set_work_entity(doc, rdf_find_entity("title"), saveDialog->getDocTitle().c_str());
793 // free up old string
794 if(doc_title) g_free(doc_title);
796 Glib::ustring fileName = saveDialog->getFilename();
797 Inkscape::Extension::Extension *selectionType = saveDialog->getSelectionType();
799 delete saveDialog;
801 saveDialog = 0;
803 if (fileName.size() > 0) {
804 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
806 if ( newFileName.size()>0 )
807 fileName = newFileName;
808 else
809 g_warning( "Error converting save filename to UTF-8." );
811 // FIXME: does the argument !is_copy really convey the correct meaning here?
812 success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy, save_method);
814 if (success && SP_DOCUMENT_URI(doc)) {
815 sp_file_add_recent(SP_DOCUMENT_URI(doc));
816 }
818 save_path = Glib::path_get_dirname(fileName);
819 Inkscape::Extension::store_save_path_in_prefs(save_path, save_method);
821 return success;
822 }
825 return false;
826 }
829 /**
830 * Save a document, displaying a SaveAs dialog if necessary.
831 */
832 bool
833 sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc)
834 {
835 bool success = true;
837 if (doc->isModifiedSinceSave()) {
838 if ( doc->uri == NULL )
839 {
840 // Hier sollte in Argument mitgegeben werden, das anzeigt, daß das Dokument das erste
841 // Mal gespeichert wird, so daß als default .svg ausgewählt wird und nicht die zuletzt
842 // benutzte "Save as ..."-Endung
843 return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG);
844 } else {
845 Glib::ustring extension = Inkscape::Extension::get_file_save_extension(Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
846 Glib::ustring fn = g_strdup(doc->uri);
847 // Try to determine the extension from the uri; this may not lead to a valid extension,
848 // but this case is caught in the file_save method below (or rather in Extension::save()
849 // further down the line).
850 Glib::ustring ext = "";
851 Glib::ustring::size_type pos = fn.rfind('.');
852 if (pos != Glib::ustring::npos) {
853 // FIXME: this could/should be more sophisticated (see FileSaveDialog::appendExtension()),
854 // but hopefully it's a reasonable workaround for now
855 ext = fn.substr( pos );
856 }
857 success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext.c_str()), FALSE, TRUE, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
858 }
859 } else {
860 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved."));
861 success = TRUE;
862 }
864 return success;
865 }
868 /**
869 * Save a document.
870 */
871 bool
872 sp_file_save(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
873 {
874 if (!SP_ACTIVE_DOCUMENT)
875 return false;
877 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Saving document..."));
879 sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
880 return sp_file_save_document(parentWindow, SP_ACTIVE_DOCUMENT);
881 }
884 /**
885 * Save a document, always displaying the SaveAs dialog.
886 */
887 bool
888 sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
889 {
890 if (!SP_ACTIVE_DOCUMENT)
891 return false;
892 sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
893 return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
894 }
898 /**
899 * Save a copy of a document, always displaying a sort of SaveAs dialog.
900 */
901 bool
902 sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/)
903 {
904 if (!SP_ACTIVE_DOCUMENT)
905 return false;
906 sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
907 return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY);
908 }
911 /*######################
912 ## I M P O R T
913 ######################*/
915 /**
916 * Import a resource. Called by sp_file_import()
917 */
918 void
919 file_import(SPDocument *in_doc, const Glib::ustring &uri,
920 Inkscape::Extension::Extension *key)
921 {
922 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
924 //DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
925 SPDocument *doc;
926 try {
927 doc = Inkscape::Extension::open(key, uri.c_str());
928 } catch (Inkscape::Extension::Input::no_extension_found &e) {
929 doc = NULL;
930 } catch (Inkscape::Extension::Input::open_failed &e) {
931 doc = NULL;
932 }
934 if (doc != NULL) {
935 Inkscape::XML::rebase_hrefs(doc, in_doc->base, true);
936 Inkscape::XML::Document *xml_in_doc = sp_document_repr_doc(in_doc);
938 prevent_id_clashes(doc, in_doc);
940 SPObject *in_defs = SP_DOCUMENT_DEFS(in_doc);
941 Inkscape::XML::Node *last_def = SP_OBJECT_REPR(in_defs)->lastChild();
943 SPCSSAttr *style = sp_css_attr_from_object(SP_DOCUMENT_ROOT(doc));
945 // Count the number of top-level items in the imported document.
946 guint items_count = 0;
947 for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
948 child != NULL; child = SP_OBJECT_NEXT(child))
949 {
950 if (SP_IS_ITEM(child)) items_count++;
951 }
953 // Create a new group if necessary.
954 Inkscape::XML::Node *newgroup = NULL;
955 if ((style && style->firstChild()) || items_count > 1) {
956 newgroup = xml_in_doc->createElement("svg:g");
957 sp_repr_css_set(newgroup, style, "style");
958 }
960 // Determine the place to insert the new object.
961 // This will be the current layer, if possible.
962 // FIXME: If there's no desktop (command line run?) we need
963 // a document:: method to return the current layer.
964 // For now, we just use the root in this case.
965 SPObject *place_to_insert;
966 if (desktop) {
967 place_to_insert = desktop->currentLayer();
968 } else {
969 place_to_insert = SP_DOCUMENT_ROOT(in_doc);
970 }
972 // Construct a new object representing the imported image,
973 // and insert it into the current document.
974 SPObject *new_obj = NULL;
975 for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc));
976 child != NULL; child = SP_OBJECT_NEXT(child) )
977 {
978 if (SP_IS_ITEM(child)) {
979 Inkscape::XML::Node *newitem = SP_OBJECT_REPR(child)->duplicate(xml_in_doc);
981 // convert layers to groups, and make sure they are unlocked
982 // FIXME: add "preserve layers" mode where each layer from
983 // import is copied to the same-named layer in host
984 newitem->setAttribute("inkscape:groupmode", NULL);
985 newitem->setAttribute("sodipodi:insensitive", NULL);
987 if (newgroup) newgroup->appendChild(newitem);
988 else new_obj = place_to_insert->appendChildRepr(newitem);
989 }
991 // don't lose top-level defs or style elements
992 else if (SP_OBJECT_REPR(child)->type() == Inkscape::XML::ELEMENT_NODE) {
993 const gchar *tag = SP_OBJECT_REPR(child)->name();
994 if (!strcmp(tag, "svg:defs")) {
995 for (SPObject *x = sp_object_first_child(child);
996 x != NULL; x = SP_OBJECT_NEXT(x))
997 {
998 SP_OBJECT_REPR(in_defs)->addChild(SP_OBJECT_REPR(x)->duplicate(xml_in_doc), last_def);
999 }
1000 }
1001 else if (!strcmp(tag, "svg:style")) {
1002 SP_DOCUMENT_ROOT(in_doc)->appendChildRepr(SP_OBJECT_REPR(child)->duplicate(xml_in_doc));
1003 }
1004 }
1005 }
1006 if (newgroup) new_obj = place_to_insert->appendChildRepr(newgroup);
1008 // release some stuff
1009 if (newgroup) Inkscape::GC::release(newgroup);
1010 if (style) sp_repr_css_attr_unref(style);
1012 // select and move the imported item
1013 if (new_obj && SP_IS_ITEM(new_obj)) {
1014 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1015 selection->set(SP_ITEM(new_obj));
1017 // preserve parent and viewBox transformations
1018 // c2p is identity matrix at this point unless sp_document_ensure_up_to_date is called
1019 sp_document_ensure_up_to_date(doc);
1020 Geom::Matrix affine = SP_ROOT(SP_DOCUMENT_ROOT(doc))->c2p * sp_item_i2doc_affine(SP_ITEM(place_to_insert)).inverse();
1021 sp_selection_apply_affine(selection, desktop->dt2doc() * affine * desktop->doc2dt(), true, false);
1023 // move to mouse pointer
1024 {
1025 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1026 Geom::OptRect sel_bbox = selection->bounds();
1027 if (sel_bbox) {
1028 Geom::Point m( desktop->point() - sel_bbox->midpoint() );
1029 sp_selection_move_relative(selection, m, false);
1030 }
1031 }
1032 }
1034 sp_document_unref(doc);
1035 sp_document_done(in_doc, SP_VERB_FILE_IMPORT,
1036 _("Import"));
1038 } else {
1039 gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), uri.c_str());
1040 sp_ui_error_dialog(text);
1041 g_free(text);
1042 }
1044 return;
1045 }
1048 /**
1049 * Display an Open dialog, import a resource if OK pressed.
1050 */
1051 void
1052 sp_file_import(Gtk::Window &parentWindow)
1053 {
1054 static Glib::ustring import_path;
1056 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1057 if (!doc)
1058 return;
1060 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1062 if(import_path.empty())
1063 {
1064 Glib::ustring attr = prefs->getString("/dialogs/import/path");
1065 if (!attr.empty()) import_path = attr;
1066 }
1068 //# Test if the import_path directory exists
1069 if (!Inkscape::IO::file_test(import_path.c_str(),
1070 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1071 import_path = "";
1073 //# If no open path, default to our home directory
1074 if (import_path.empty())
1075 {
1076 import_path = g_get_home_dir();
1077 import_path.append(G_DIR_SEPARATOR_S);
1078 }
1080 // Create new dialog (don't use an old one, because parentWindow has probably changed)
1081 Inkscape::UI::Dialog::FileOpenDialog *importDialogInstance =
1082 Inkscape::UI::Dialog::FileOpenDialog::create(
1083 parentWindow,
1084 import_path,
1085 Inkscape::UI::Dialog::IMPORT_TYPES,
1086 (char const *)_("Select file to import"));
1088 bool success = importDialogInstance->show();
1089 if (!success) {
1090 delete importDialogInstance;
1091 return;
1092 }
1094 //# Get file name and extension type
1095 Glib::ustring fileName = importDialogInstance->getFilename();
1096 Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1098 delete importDialogInstance;
1099 importDialogInstance = NULL;
1101 if (fileName.size() > 0) {
1103 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1105 if ( newFileName.size() > 0)
1106 fileName = newFileName;
1107 else
1108 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1110 import_path = Glib::path_get_dirname (fileName);
1111 import_path.append(G_DIR_SEPARATOR_S);
1112 prefs->setString("/dialogs/import/path", import_path);
1114 file_import(doc, fileName, selection);
1115 }
1117 return;
1118 }
1122 /*######################
1123 ## E X P O R T
1124 ######################*/
1127 #ifdef NEW_EXPORT_DIALOG
1129 /**
1130 * Display an Export dialog, export as the selected type if OK pressed
1131 */
1132 bool
1133 sp_file_export_dialog(void *widget)
1134 {
1135 //# temp hack for 'doc' until we can switch to this dialog
1136 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1138 Glib::ustring export_path;
1139 Glib::ustring export_loc;
1141 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1142 Inkscape::Extension::Output *extension;
1144 //# Get the default extension name
1145 Glib::ustring default_extension = prefs->getString("/dialogs/save_export/default");
1146 if(default_extension.empty()) {
1147 // FIXME: Is this a good default? Should there be a macro for the string?
1148 default_extension = "org.inkscape.output.png.cairo";
1149 }
1150 //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
1152 if (doc->uri == NULL)
1153 {
1154 char formatBuf[256];
1156 Glib::ustring filename_extension = ".svg";
1157 extension = dynamic_cast<Inkscape::Extension::Output *>
1158 (Inkscape::Extension::db.get(default_extension.c_str()));
1159 //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
1160 if (extension)
1161 filename_extension = extension->get_extension();
1163 Glib::ustring attr3 = prefs->getString("/dialogs/save_export/path");
1164 if (!attr3.empty())
1165 export_path = attr3;
1167 if (!Inkscape::IO::file_test(export_path.c_str(),
1168 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1169 export_path = "";
1171 if (export_path.size()<1)
1172 export_path = g_get_home_dir();
1174 export_loc = export_path;
1175 export_loc.append(G_DIR_SEPARATOR_S);
1176 snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1177 export_loc.append(formatBuf);
1179 }
1180 else
1181 {
1182 export_path = Glib::path_get_dirname(doc->uri);
1183 }
1185 // convert save_loc from utf-8 to locale
1186 // is this needed any more, now that everything is handled in
1187 // Inkscape::IO?
1188 Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1189 if ( export_path_local.size() > 0)
1190 export_path = export_path_local;
1192 //# Show the Export dialog
1193 Inkscape::UI::Dialog::FileExportDialog *exportDialogInstance =
1194 Inkscape::UI::Dialog::FileExportDialog::create(
1195 export_path,
1196 Inkscape::UI::Dialog::EXPORT_TYPES,
1197 (char const *) _("Select file to export to"),
1198 default_extension
1199 );
1201 bool success = exportDialogInstance->show();
1202 if (!success) {
1203 delete exportDialogInstance;
1204 return success;
1205 }
1207 Glib::ustring fileName = exportDialogInstance->getFilename();
1209 Inkscape::Extension::Extension *selectionType =
1210 exportDialogInstance->getSelectionType();
1212 delete exportDialogInstance;
1213 exportDialogInstance = NULL;
1215 if (fileName.size() > 0) {
1216 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1218 if ( newFileName.size()>0 )
1219 fileName = newFileName;
1220 else
1221 g_warning( "Error converting save filename to UTF-8." );
1223 success = file_save(doc, fileName, selectionType, TRUE, FALSE);
1225 if (success) {
1226 Glib::RefPtr<Gtk::RecentManager> recent = Gtk::RecentManager::get_default();
1227 recent->add_item(SP_DOCUMENT_URI(doc));
1228 }
1230 export_path = fileName;
1231 prefs->setString("/dialogs/save_export/path", export_path);
1233 return success;
1234 }
1237 return false;
1238 }
1240 #else
1242 /**
1243 *
1244 */
1245 bool
1246 sp_file_export_dialog(void */*widget*/)
1247 {
1248 sp_export_dialog();
1249 return true;
1250 }
1252 #endif
1254 /*######################
1255 ## E X P O R T T O O C A L
1256 ######################*/
1258 /**
1259 * Display an Export dialog, export as the selected type if OK pressed
1260 */
1261 bool
1262 sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow)
1263 {
1265 if (!SP_ACTIVE_DOCUMENT)
1266 return false;
1268 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1270 Glib::ustring export_path;
1271 Glib::ustring export_loc;
1272 Glib::ustring fileName;
1273 Inkscape::Extension::Extension *selectionType;
1275 bool success = false;
1277 static bool gotSuccess = false;
1279 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
1280 (void)repr;
1282 if (!doc->uri && !doc->isModifiedSinceSave())
1283 return false;
1285 // Get the default extension name
1286 Glib::ustring default_extension = "org.inkscape.output.svg.inkscape";
1287 char formatBuf[256];
1289 Glib::ustring filename_extension = ".svg";
1290 selectionType = Inkscape::Extension::db.get(default_extension.c_str());
1292 export_path = Glib::get_tmp_dir ();
1294 export_loc = export_path;
1295 export_loc.append(G_DIR_SEPARATOR_S);
1296 snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
1297 export_loc.append(formatBuf);
1299 // convert save_loc from utf-8 to locale
1300 // is this needed any more, now that everything is handled in
1301 // Inkscape::IO?
1302 Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
1303 if ( export_path_local.size() > 0)
1304 export_path = export_path_local;
1306 // Show the Export To OCAL dialog
1307 Inkscape::UI::Dialog::FileExportToOCALDialog *exportDialogInstance =
1308 new Inkscape::UI::Dialog::FileExportToOCALDialog(
1309 parentWindow,
1310 Inkscape::UI::Dialog::EXPORT_TYPES,
1311 (char const *) _("Select file to export to")
1312 );
1314 success = exportDialogInstance->show();
1315 if (!success) {
1316 delete exportDialogInstance;
1317 return success;
1318 }
1320 fileName = exportDialogInstance->getFilename();
1322 delete exportDialogInstance;
1323 exportDialogInstance = NULL;;
1325 fileName.append(filename_extension.c_str());
1326 if (fileName.size() > 0) {
1327 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1329 if ( newFileName.size()>0 )
1330 fileName = newFileName;
1331 else
1332 g_warning( "Error converting save filename to UTF-8." );
1333 }
1334 Glib::ustring filePath = export_path;
1335 filePath.append(G_DIR_SEPARATOR_S);
1336 filePath.append(Glib::path_get_basename(fileName));
1338 fileName = filePath;
1340 success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE, Inkscape::Extension::FILE_SAVE_METHOD_EXPORT);
1342 if (!success){
1343 gchar *text = g_strdup_printf(_("Error saving a temporary copy"));
1344 sp_ui_error_dialog(text);
1346 return success;
1347 }
1349 // Start now the submition
1351 // Create the uri
1352 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1353 Glib::ustring uri = "dav://";
1354 Glib::ustring username = prefs->getString("/options/ocalusername/str");
1355 Glib::ustring password = prefs->getString("/options/ocalpassword/str");
1356 if (username.empty() || password.empty())
1357 {
1358 Inkscape::UI::Dialog::FileExportToOCALPasswordDialog *exportPasswordDialogInstance = NULL;
1359 if(!gotSuccess)
1360 {
1361 exportPasswordDialogInstance = new Inkscape::UI::Dialog::FileExportToOCALPasswordDialog(
1362 parentWindow,
1363 (char const *) _("Open Clip Art Login"));
1364 success = exportPasswordDialogInstance->show();
1365 if (!success) {
1366 delete exportPasswordDialogInstance;
1367 return success;
1368 }
1369 }
1370 username = exportPasswordDialogInstance->getUsername();
1371 password = exportPasswordDialogInstance->getPassword();
1373 delete exportPasswordDialogInstance;
1374 exportPasswordDialogInstance = NULL;
1375 }
1376 uri.append(username);
1377 uri.append(":");
1378 uri.append(password);
1379 uri.append("@");
1380 uri.append(prefs->getString("/options/ocalurl/str"));
1381 uri.append("/dav.php/");
1382 uri.append(Glib::path_get_basename(fileName));
1384 // Save as a remote file using the dav protocol.
1385 success = file_save_remote(doc, uri, selectionType, FALSE, FALSE);
1386 remove(fileName.c_str());
1387 if (!success)
1388 {
1389 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."));
1390 sp_ui_error_dialog(text);
1391 }
1392 else
1393 gotSuccess = true;
1395 return success;
1396 }
1398 /**
1399 * Export the current document to OCAL
1400 */
1401 void
1402 sp_file_export_to_ocal(Gtk::Window &parentWindow)
1403 {
1405 // Try to execute the new code and return;
1406 if (!SP_ACTIVE_DOCUMENT)
1407 return;
1408 bool success = sp_file_export_to_ocal_dialog(parentWindow);
1409 if (success)
1410 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Document exported..."));
1411 }
1414 /*######################
1415 ## I M P O R T F R O M O C A L
1416 ######################*/
1418 /**
1419 * Display an ImportToOcal Dialog, and the selected document from OCAL
1420 */
1421 void
1422 sp_file_import_from_ocal(Gtk::Window &parentWindow)
1423 {
1424 static Glib::ustring import_path;
1426 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1427 if (!doc)
1428 return;
1430 Inkscape::UI::Dialog::FileImportFromOCALDialog *importDialogInstance = NULL;
1432 if (!importDialogInstance) {
1433 importDialogInstance = new
1434 Inkscape::UI::Dialog::FileImportFromOCALDialog(
1435 parentWindow,
1436 import_path,
1437 Inkscape::UI::Dialog::IMPORT_TYPES,
1438 (char const *)_("Import From Open Clip Art Library"));
1439 }
1441 bool success = importDialogInstance->show();
1442 if (!success) {
1443 delete importDialogInstance;
1444 return;
1445 }
1447 // Get file name and extension type
1448 Glib::ustring fileName = importDialogInstance->getFilename();
1449 Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType();
1451 delete importDialogInstance;
1452 importDialogInstance = NULL;
1454 if (fileName.size() > 0) {
1456 Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
1458 if ( newFileName.size() > 0)
1459 fileName = newFileName;
1460 else
1461 g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
1463 import_path = fileName;
1464 if (import_path.size()>0)
1465 import_path.append(G_DIR_SEPARATOR_S);
1467 file_import(doc, fileName, selection);
1468 }
1470 return;
1471 }
1473 /*######################
1474 ## P R I N T
1475 ######################*/
1478 /**
1479 * Print the current document, if any.
1480 */
1481 void
1482 sp_file_print(Gtk::Window& parentWindow)
1483 {
1484 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1485 if (doc)
1486 sp_print_document(parentWindow, doc);
1487 }
1489 /**
1490 * Display what the drawing would look like, if
1491 * printed.
1492 */
1493 void
1494 sp_file_print_preview(gpointer /*object*/, gpointer /*data*/)
1495 {
1497 SPDocument *doc = SP_ACTIVE_DOCUMENT;
1498 if (doc)
1499 sp_print_preview_document(doc);
1501 }
1504 /*
1505 Local Variables:
1506 mode:c++
1507 c-file-style:"stroustrup"
1508 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1509 indent-tabs-mode:nil
1510 fill-column:99
1511 End:
1512 */
1513 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :