/**
* @file
*/
/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Chema Celorio <chema@celorio.com>
* bulia byak <buliabyak@users.sf.net>
* Bruno Dilly <bruno.dilly@gmail.com>
* Stephen Silver <sasilver@users.sourceforge.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
* David Xiong
*
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
* Copyright (C) 1999-2012 Authors
* Copyright (C) 2004 David Turner
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/** @file
* @note This file needs to be cleaned up extensively.
* What it probably needs is to have one .h file for
* the API, and two or more .cpp files for the implementations.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ui/dialog/ocaldialogs.h"
#include "desktop.h"
#include "dir-util.h"
#include "document-private.h"
#include "document-undo.h"
#include "ui/tools/tool-base.h"
#include "file.h"
#include "helper/png-write.h"
#include "id-clash.h"
#include "inkscape.h"
#include "inkscape.h"
#include "ui/interface.h"
#include "message.h"
#include "message-stack.h"
#include "path-prefix.h"
#include "preferences.h"
#include "print.h"
#include "resource-manager.h"
#include "rdf.h"
#include "selection-chemistry.h"
#include "selection.h"
#include "sp-namedview.h"
#include "style.h"
#include "ui/view/view-widget.h"
#include "uri.h"
#include "xml/rebase-hrefs.h"
#include "xml/sp-css-attr.h"
#include "verbs.h"
#include "event-log.h"
#include "ui/dialog/font-substitution.h"
#include <glibmm/miscutils.h>
#include <string>
using Inkscape::DocumentUndo;
#ifdef WITH_GNOME_VFS
# include <libgnomevfs/gnome-vfs.h>
#endif
#ifdef WITH_DBUS
#include "extension/dbus/dbus-init.h"
#endif
#ifdef WIN32
#include <windows.h>
#endif
//#define INK_DUMP_FILENAME_CONV 1
//#define INK_DUMP_FOPEN 1
// what gets passed here is not actually an URI... it is an UTF-8 encoded filename (!)
{
g_warning("sp_file_add_recent: uri == NULL");
return;
}
if (fn) {
if (uri_to_add) {
}
}
}
/*######################
## N E W
######################*/
/**
* Create a blank document and add it to the desktop
*/
{
// Remove all the template info from xml tree
if (nodeToRemove != NULL){
delete nodeToRemove;
}
// Set viewBox if it doesn't exist
doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit())));
}
if (olddesktop)
SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.
#ifdef WITH_DBUS
#endif
if (olddesktop)
if (desktop)
return desktop;
}
{
sources.push_back( Inkscape::Application::profile_path("templates") ); // first try user's local dir
}
for (std::list<gchar *>::iterator it = sources.begin(); (it != sources.end()) && !foundTemplate; ++it) {
for (std::list<gchar const*>::iterator nameIt = baseNames.begin(); (nameIt != baseNames.end()) && !foundTemplate; ++nameIt) {
// TRANSLATORS: default.svg is localizable - this is the name of the default document
// template. This way you can localize the default pagesize, translate the name of
// the default layer, etc. If you wish to localize this file, please create a
// localized share/templates/default.xx.svg file, where xx is your language code.
foundTemplate = tmp;
} else {
}
}
}
}
}
if (foundTemplate) {
foundTemplate = 0;
}
return templateUri;
}
{
//rdf_add_from_preferences( SP_ACTIVE_DOCUMENT );
return desk;
}
/*######################
## D E L E T E
######################*/
/**
* Perform document closures preceding an exit()
*/
void
{
if (SP_ACTIVE_DESKTOP == NULL) {
// We must be in console mode
} else {
// no need to call inkscape_exit here; last document being closed will take care of that
}
}
/*######################
## O P E N
######################*/
/**
* Open a file, add the document to the desktop
*
* \param replace_empty if true, and the current desktop is empty, this document
* will replace the empty one.
*/
bool add_to_recent,
bool replace_empty)
{
if (desktop) {
}
bool cancelled = false;
try {
cancelled = true;
}
if (desktop) {
}
if (doc) {
// Set viewBox if it doesn't exist
doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit())));
}
// If the current desktop is empty, open the document there
} else {
// create a whole new desktop and window
SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.
}
// everyone who cares now has a reference, get rid of our`s
// resize the window to match the document properties
if (add_to_recent) {
}
// Perform a fixup pass for hrefs.
}
// Check for font substitutions
}
return TRUE;
} else if (!cancelled) {
return FALSE;
}
return FALSE;
}
/**
* Handle prompting user for "do you want to revert"? Revert on "OK"
*/
void sp_file_revert_dialog()
{
if (!uri) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet. Cannot revert."));
return;
}
bool do_revert = true;
if (doc->isModifiedSinceSave()) {
Glib::ustring tmpString = Glib::ustring::compose(_("Changes will be lost! Are you sure you want to reload document %1?"), uri);
if (!response) {
do_revert = false;
}
}
bool reverted;
if (do_revert) {
// Allow overwriting of current document.
// remember current zoom and view
if (reverted) {
// restore zoom and view
}
} else {
reverted = false;
}
if (reverted) {
} else {
}
}
{
tmp += " [";
for (unsigned i = 0; i < total; i++) {
}
tmp += "]";
}
{
g_message(" size: %lu\n length: %lu\n bytes: %lu\n clen: %lu",
try {
tmp = " ";
if (i < dataLen) {
} else {
tmp += " ";
}
if (i < byteLen) {
} else {
tmp += " . ";
}
} else {
tmp += " ";
}
if ( i < cstrLen ) {
} else {
tmp += " . ";
}
} else {
tmp += " ";
}
}
} catch (...) {
g_message("XXXXXXXXXXXXXXXXXX Exception" );
}
g_message("---------------");
}
/**
* Display an file Open selector. Open a document if OK is pressed.
* Can select single or multiple files for opening.
*/
void
{
//# Get the current directory for finding files
{
}
//# Test if the open_path directory exists
open_path = "";
#ifdef WIN32
//# If no open path, default to our win32 documents folder
{
// The path to the My Documents folder is read from the
// value "HKEY_CURRENT_USER\Software\Windows\CurrentVersion\Explorer\Shell Folders\Personal"
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
{
{
if(utf8path)
{
}
}
}
}
#endif
//# If no open path, default to our home directory
{
open_path = g_get_home_dir();
}
//# Create a dialog
_("Select file to open"));
//# Show the dialog
//# Save the folder the user selected for later
if (!success)
{
delete openDialogInstance;
return;
}
//# User selected something. Get name and type
//# Code to check & open if multiple files.
//# We no longer need the file dialog object - delete it
delete openDialogInstance;
//# Iterate through filenames if more than 1
{
{
if ( newFileName.size() > 0 )
else
g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
#ifdef INK_DUMP_FILENAME_CONV
#endif
}
return;
}
{
if ( newFileName.size() > 0)
else
g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
}
return;
}
/*######################
## V A C U U M
######################*/
/**
* Remove unreferenced defs from the defs section of the document.
*/
{
_("Clean up document"));
// Show status messages when in GUI mode
if (diff > 0) {
ngettext("Removed <b>%i</b> unused definition in <defs>.",
"Removed <b>%i</b> unused definitions in <defs>.",
diff),
diff);
} else {
}
}
}
/*######################
## S A V E
######################*/
/**
* This 'save' function called by the others below
*
* \param official whether to set :output_module and :modified in the
* document; is true for normal save, false for temporary saves
*/
static bool
{
return false;
try {
false,
gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s). This may have been caused by an unknown filename extension."), safeUri);
return false;
gchar *text = g_strdup_printf(_("File %s is write protected. Please remove write protection and try again."), safeUri);
return false;
return false;
return false;
} catch (...) {
return false;
}
if (SP_ACTIVE_DESKTOP) {
if (! SP_ACTIVE_DESKTOP->event_log) {
g_message("file_save: ->event_log == NULL. please report to bug #967416");
}
if (! SP_ACTIVE_DESKTOP->messageStack()) {
g_message("file_save: ->messageStack() == NULL. please report to bug #967416");
}
} else {
g_message("file_save: SP_ACTIVE_DESKTOP == NULL. please report to bug #967416");
}
} else {
}
return true;
}
/*
* Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp.
*/
bool
#ifdef WITH_GNOME_VFS
#else
#endif
{
#ifdef WITH_GNOME_VFS
g_warning( "Error converting filename to locale encoding.");
}
// Gets the temp file name.
// Open the temp file to send.
if (result != GNOME_VFS_OK) {
g_warning("Could not find the temp saving.");
return false;
}
if (result != GNOME_VFS_OK) {
return false;
}
while (1) {
return true;
}
if (result != GNOME_VFS_OK) {
return false;
}
if (result != GNOME_VFS_OK) {
return false;
}
if (bytes_read != bytes_written){
return false;
}
}
return true;
#else
// in case we do not have GNOME_VFS
return false;
#endif
}
/**
* Check if a string ends with another string.
* \todo Find a better code file to put this general purpose method
*/
{
} else {
return false;
}
}
/**
* Display a SaveAs dialog. Save the document if OK pressed.
*/
bool
sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extension::FileSaveMethod save_method)
{
// Note: default_extension has the format "org.inkscape.output.svg.inkscape", whereas
// filename_extension only uses ".svg"
//g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
if (extension)
save_path = g_get_home_dir();
int i = 1;
// We are saving for the first time; create a unique default filename
}
} else {
}
// convert save_loc from utf-8 to locale
// is this needed any more, now that everything is handled in
// Inkscape::IO?
if (!save_loc_local.empty())
//# Show the SaveAs dialog
char const * dialog_title;
if (is_copy) {
dialog_title = (char const *) _("Select file to save a copy to");
} else {
dialog_title = (char const *) _("Select file to save to");
}
);
if (!success) {
delete saveDialog;
return success;
}
// set new title here (call RDF to ensure metadata and title element are updated)
delete saveDialog;
saveDialog = 0;
if (!newFileName.empty())
else
g_warning( "Error converting filename for saving to UTF-8." );
if (omod) {
}
}
// FIXME: does the argument !is_copy really convey the correct meaning here?
}
return success;
}
return false;
}
/**
* Save a document, displaying a SaveAs dialog if necessary.
*/
bool
{
bool success = true;
if (doc->isModifiedSinceSave()) {
{
// Hier sollte in Argument mitgegeben werden, das anzeigt, da� das Dokument das erste
// Mal gespeichert wird, so da� als default .svg ausgew�hlt wird und nicht die zuletzt
// benutzte "Save as ..."-Endung
} else {
Glib::ustring extension = Inkscape::Extension::get_file_save_extension(Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
// Try to determine the extension from the uri; this may not lead to a valid extension,
// but this case is caught in the file_save method below (or rather in Extension::save()
// further down the line).
// but hopefully it's a reasonable workaround for now
}
success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext.c_str()), FALSE, TRUE, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
if (success == false) {
// give the user the chance to change filename or extension
}
}
} else {
{
} else {
}
}
return success;
}
/**
* Save a document.
*/
bool
{
if (!SP_ACTIVE_DOCUMENT)
return false;
}
/**
* Save a document, always displaying the SaveAs dialog.
*/
bool
{
if (!SP_ACTIVE_DOCUMENT)
return false;
return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
}
/**
* Save a copy of a document, always displaying a sort of SaveAs dialog.
*/
bool
{
if (!SP_ACTIVE_DOCUMENT)
return false;
return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY);
}
/*######################
## I M P O R T
######################*/
/**
* Paste the contents of a document into the active desktop.
* @param clipdoc The document to paste
* @param in_place Whether to paste the selection where it was when copied
* @pre @c clipdoc is not empty and items can be added to the current layer
*/
{
//TODO: merge with file_import()
// copy definitions
// copy objects
// Don't copy metadata, defs, named views and internal clipboard contents to the document
continue;
}
continue;
}
continue;
}
continue;
}
}
/* take that stuff into account:
* if( use && selection->includes(use->get_original()) ){//we are copying something whose parent is also copied (!)
* transform = ((SPItem*)(use->get_original()->parent))->i2doc_affine().inverse() * transform;
* }
*
*/
if(clipboard)
}
sp_selection_apply_affine(selection, desktop->dt2doc() * doc2parent * desktop->doc2dt(), true, false, false);
// Change the selection to the freshly pasted objects
// Apply inverse of parent transform
sp_selection_apply_affine(selection, desktop->dt2doc() * doc2parent * desktop->doc2dt(), true, false, false);
// Update (among other things) all curves in paths, for bounds() to work
// move selection either to original position (in_place) or to mouse pointer
if (sel_bbox) {
// get offset of selection to original position of copied elements
if (clipnode) {
}
if (!in_place) {
// get offset from mouse pointer to bbox center, snap to grid if enabled
m.unSetup();
}
}
}
/**
* Import a resource. Called by sp_file_import()
*/
SPObject *
{
bool cancelled = false;
//DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
try {
cancelled = true;
}
// Count the number of top-level items in the imported document.
if (SP_IS_ITEM(child)) {
items_count++;
}
}
// Create a new group if necessary.
}
// Determine the place to insert the new object.
// This will be the current layer, if possible.
// FIXME: If there's no desktop (command line run?) we need
// a document:: method to return the current layer.
// For now, we just use the root in this case.
if (desktop) {
} else {
}
// Construct a new object representing the imported image,
// and insert it into the current document.
if (SP_IS_ITEM(child)) {
// convert layers to groups, and make sure they are unlocked
// FIXME: add "preserve layers" mode where each layer from
// import is copied to the same-named layer in host
}
// don't lose top-level defs or style elements
}
}
}
// release some stuff
// select and move the imported item
// preserve parent and viewBox transformations
// c2p is identity matrix at this point unless ensureUpToDate is called
doc->ensureUpToDate();
sp_selection_apply_affine(selection, desktop->dt2doc() * affine * desktop->doc2dt(), true, false, false);
// move to mouse pointer
{
if (sel_bbox) {
sp_selection_move_relative(selection, m, false);
}
}
}
_("Import"));
return new_obj;
} else if (!cancelled) {
}
return NULL;
}
/**
* Display an Open dialog, import a resource if OK pressed.
*/
void
{
if (!doc)
return;
if(import_path.empty())
{
}
//# Test if the import_path directory exists
import_path = "";
//# If no open path, default to our home directory
if (import_path.empty())
{
}
// Create new dialog (don't use an old one, because parentWindow has probably changed)
(char const *)_("Select file to import"));
if (!success) {
delete importDialogInstance;
return;
}
// Get file name and extension type
delete importDialogInstance;
//# Iterate through filenames if more than 1
{
{
if (!newFileName.empty())
else
g_warning("ERROR CONVERTING IMPORT FILENAME TO UTF-8");
#ifdef INK_DUMP_FILENAME_CONV
#endif
}
return;
}
if (!newFileName.empty())
else
g_warning("ERROR CONVERTING IMPORT FILENAME TO UTF-8");
}
return;
}
/*######################
## E X P O R T
######################*/
#ifdef NEW_EXPORT_DIALOG
/**
* Display an Export dialog, export as the selected type if OK pressed
*/
bool
{
//# temp hack for 'doc' until we can switch to this dialog
//# Get the default extension name
if(default_extension.empty()) {
// FIXME: Is this a good default? Should there be a macro for the string?
}
//g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);
{
//g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
if (extension)
export_path = attr3;
if (export_path.empty())
}
else
{
}
// convert save_loc from utf-8 to locale
// is this needed any more, now that everything is handled in
// Inkscape::IO?
if (!export_path_local.empty())
//# Show the Export dialog
(char const *) _("Select file to export to"),
);
if (!success) {
delete exportDialogInstance;
return success;
}
delete exportDialogInstance;
if ( newFileName.size()>0 )
else
g_warning( "Error converting save filename to UTF-8." );
success = file_save(parentWindow, doc, fileName, selectionType, TRUE, FALSE, Inkscape::Extension::FILE_SAVE_METHOD_EXPORT);
if (success) {
}
return success;
}
return false;
}
#else
/**
* TODO Delete
* This is now a dialog called from dialog manager
*
bool
sp_file_export_dialog(Gtk::Window &parentWindow)
{
// sp_export_dialog();
return true;
}
*/
#endif
/*######################
## E X P O R T T O O C A L
######################*/
/**
* Display an Export dialog, export as the selected type if OK pressed
*/
/*
bool
sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow)
{
if (!SP_ACTIVE_DOCUMENT)
return false;
SPDocument *doc = SP_ACTIVE_DOCUMENT;
Glib::ustring export_path;
Glib::ustring export_loc;
Glib::ustring fileName;
Inkscape::Extension::Extension *selectionType;
bool success = false;
static bool gotSuccess = false;
Inkscape::XML::Node *repr = doc->getReprRoot();
(void)repr;
if (!doc->uri && !doc->isModifiedSinceSave())
return false;
// Get the default extension name
Glib::ustring default_extension = "org.inkscape.output.svg.inkscape";
char formatBuf[256];
Glib::ustring filename_extension = ".svg";
selectionType = Inkscape::Extension::db.get(default_extension.c_str());
export_path = Glib::get_tmp_dir ();
export_loc = export_path;
export_loc.append(G_DIR_SEPARATOR_S);
snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
export_loc.append(formatBuf);
// convert save_loc from utf-8 to locale
// is this needed any more, now that everything is handled in
// Inkscape::IO?
Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
if ( export_path_local.size() > 0)
export_path = export_path_local;
// Show the Export To OCAL dialog
Inkscape::UI::Dialog::OCAL:ExportDialog *exportDialogInstance =
new Inkscape::UI::Dialog::OCAL:ExportDialog
parentWindow,
Inkscape::UI::Dialog::EXPORT_TYPES,
(char const *) _("Select file to export to")
);
success = exportDialogInstance->show();
if (!success) {
delete exportDialogInstance;
return success;
}
fileName = exportDialogInstance->getFilename();
delete exportDialogInstance;
exportDialogInstance = NULL;;
fileName.append(filename_extension.c_str());
if (fileName.size() > 0) {
Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
if ( newFileName.size()>0 )
fileName = newFileName;
else
g_warning( "Error converting save filename to UTF-8." );
}
Glib::ustring filePath = export_path;
filePath.append(G_DIR_SEPARATOR_S);
filePath.append(Glib::path_get_basename(fileName));
fileName = filePath;
success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE, Inkscape::Extension::FILE_SAVE_METHOD_EXPORT);
if (!success){
gchar *text = g_strdup_printf(_("Error saving a temporary copy"));
sp_ui_error_dialog(text);
return success;
}
// Start now the submition
// Create the uri
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Glib::ustring uri = "dav://";
Glib::ustring username = prefs->getString("/options/ocalusername/str");
Glib::ustring password = prefs->getString("/options/ocalpassword/str");
if (username.empty() || password.empty())
{
Inkscape::UI::Dialog::FileExportToOCALPasswordDialog *exportPasswordDialogInstance = NULL;
if(!gotSuccess)
{
exportPasswordDialogInstance = new Inkscape::UI::Dialog::FileExportToOCALPasswordDialog(
parentWindow,
(char const *) _("Open Clip Art Login"));
success = exportPasswordDialogInstance->show();
if (!success) {
delete exportPasswordDialogInstance;
return success;
}
}
username = exportPasswordDialogInstance->getUsername();
password = exportPasswordDialogInstance->getPassword();
delete exportPasswordDialogInstance;
exportPasswordDialogInstance = NULL;
}
uri.append(username);
uri.append(":");
uri.append(password);
uri.append("@");
uri.append("/dav.php/");
uri.append(Glib::path_get_basename(fileName));
// Save as a remote file using the dav protocol.
success = file_save_remote(doc, uri, selectionType, FALSE, FALSE);
remove(fileName.c_str());
if (!success)
{
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."));
sp_ui_error_dialog(text);
}
else
gotSuccess = true;
return success;
}
*/
/**
* Export the current document to OCAL
*/
/*
void
sp_file_export_to_ocal(Gtk::Window &parentWindow)
{
// Try to execute the new code and return;
if (!SP_ACTIVE_DOCUMENT)
return;
bool success = sp_file_export_to_ocal_dialog(parentWindow);
if (success)
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Document exported..."));
}
*/
/*######################
## I M P O R T F R O M O C A L
######################*/
/**
* Display an ImportFromOcal Dialog, and the selected document from OCAL
*/
{
}
}
void
{
if (!doc)
return;
if (import_ocal_dialog == NULL) {
import_ocal_dialog = new
(char const *)_("Import Clip Art"));
}
}
/*######################
## P R I N T
######################*/
/**
* Print the current document, if any.
*/
void
{
if (doc)
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :