file.cpp revision 1a02c2b616bd167a58870ad9ed33af5e042c9daf
#define __SP_FILE_C__
/*
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Chema Celorio <chema@celorio.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2005 Authors
* Copyright (C) 2001-2002 Ximian, Inc.
* Copyright (C) 2004 David Turner
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/**
* 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 <libnr/nr-pixops.h>
#include "document-private.h"
#include "selection-chemistry.h"
#include "ui/view/view-widget.h"
#include "dir-util.h"
#include "helper/png-write.h"
#include "inkscape.h"
#include "desktop.h"
#include "selection.h"
#include "interface.h"
#include "style.h"
#include "print.h"
#include "file.h"
#include "message-stack.h"
#include "dialogs/filedialog.h"
#include "prefs-utils.h"
#include "path-prefix.h"
#include "sp-namedview.h"
#include "desktop-handles.h"
#include "application/application.h"
#include "application/editor.h"
#include "inkscape.h"
#include "uri.h"
#ifdef WITH_INKBOARD
#include "jabber_whiteboard/session-manager.h"
#endif
/**
* 'Current' paths. Used to remember which directory
* had the last file accessed.
* Static globals are evil. This will be gone soon
* as C++ification continues
*/
//#define INK_DUMP_FILENAME_CONV 1
//#define INK_DUMP_FOPEN 1
/*######################
## N E W
######################*/
/**
* Create a blank document and add it to the desktop
*/
{
{
} else {
}
return dt;
}
{
// 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.
return sp_file_new(default_template);
}
}
}
return sp_file_new(NULL);
}
/*######################
## D E L E T E
######################*/
/**
* Perform document closures preceding an exit()
*/
void
{
// 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
sp_file_open(gchar const *uri, Inkscape::Extension::Extension *key, bool add_to_recent, bool replace_empty)
{
try {
}
if (doc) {
// If the current desktop is empty, open the document there
} else {
// create a whole new desktop and window
} else {
}
}
// everyone who cares now has a reference, get rid of ours
// resize the window to match the document properties
// (this may be redundant for new windows... if so, move to the "virgin"
// section above)
#ifdef WITH_INKBOARD
#endif
if (add_to_recent) {
}
return TRUE;
} else {
return FALSE;
}
}
/**
* Handle prompting user for "do you want to revert"? Revert on "OK"
*/
void
{
if (!uri) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet. Cannot revert."));
return;
}
bool do_revert = true;
gchar *text = g_strdup_printf(_("Changes will be lost! Are you sure you want to reload document %s?"), uri);
if (!response) {
do_revert = false;
}
}
bool reverted;
if (do_revert) {
// Allow overwriting of current document.
} 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
{
}
if (open_path && !Inkscape::IO::file_test(open_path, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
}
if (!openDialogInstance) {
(char const *)open_path,
(char const *)_("Select file to open"));
}
: NULL );
if (!success) return;
// Code to check & open iff multiple files.
{
{
#ifdef INK_DUMP_FILENAME_CONV
#endif
gsize bytesWritten = 0;
#ifdef INK_DUMP_FILENAME_CONV
#endif
-1,
&error);
if ( newFileName != NULL ) {
#ifdef INK_DUMP_FILENAME_CONV
#endif
} else {
// TODO: bulia, please look over
g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
}
#ifdef INK_DUMP_FILENAME_CONV
#endif
}
else
{
}
}
return;
}
if (fileName) {
gsize bytesWritten = 0;
#ifdef INK_DUMP_FILENAME_CONV
#endif
-1,
&error);
if ( newFileName != NULL ) {
#ifdef INK_DUMP_FILENAME_CONV
#endif
} else {
// TODO: bulia, please look over
g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
}
// TODO: bulia, please look over
g_warning( "INPUT FILENAME IS NOT UTF-8" );
}
}
return;
}
/*######################
## V A C U U M
######################*/
/**
* Remove unreferenced defs from the defs section of the document.
*/
void
{
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
*/
static bool
{
return FALSE;
try {
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;
return FALSE;
return sp_file_save_dialog(doc);
}
return TRUE;
}
/**
* Display a SaveAs dialog. Save the document if OK pressed.
*/
{
if (default_extension == NULL) {
}
//g_warning("%s: extension name: '%s'", __FUNCTION__, default_extension);
int i = 1;
char const *filename_extension;
char *temp_filename;
extension = dynamic_cast<Inkscape::Extension::Output *>(Inkscape::Extension::db.get(default_extension));
//g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
filename_extension = ".svg";
} else {
}
}
if (save_path && !Inkscape::IO::file_test(save_path, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
}
}
} else {
}
{ // convert save_loc from utf-8 to locale
// is this needed any more, now that everything is handled in
// Inkscape::IO?
gsize bytesWritten = 0;
#ifdef INK_DUMP_FILENAME_CONV
#endif
if ( save_loc_local != NULL ) {
#ifdef INK_DUMP_FILENAME_CONV
#endif
} else {
//g_warning( "Error converting save filename stored in the file to locale encoding.");
}
}
if (!saveDialogInstance) {
(char const *) save_loc,
(char const *) _("Select file to save to"),
);
} // FIXME: else (i.e. if reshowing an already shown dialog) save_loc is not used, it thus always displays the previously opened dir
: NULL );
if (!success) {
return success;
}
gsize bytesWritten = 0;
#ifdef INK_DUMP_FILENAME_CONV
#endif
-1,
&error);
if ( newFileName != NULL ) {
#ifdef INK_DUMP_FILENAME_CONV
#endif
} else {
g_warning( "Error converting save filename to UTF-8." );
}
// TODO: bulia, please look over
g_warning( "The filename is not UTF-8." );
}
if (success) {
}
return success;
} else {
return FALSE;
}
}
/**
* Save a document, displaying a SaveAs dialog if necessary.
*/
{
{
return sp_file_save_dialog(doc);
} else {
}
} else {
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved."));
}
return success;
}
/**
* Save a document.
*/
bool
{
if (!SP_ACTIVE_DOCUMENT)
return false;
return sp_file_save_document(SP_ACTIVE_DOCUMENT);
}
/**
* Save a document, always displaying the SaveAs dialog.
*/
bool
{
if (!SP_ACTIVE_DOCUMENT)
return false;
return sp_file_save_dialog(SP_ACTIVE_DOCUMENT);
}
/*######################
## I M P O R T
######################*/
/**
* Import a resource. Called by sp_file_import()
*/
void
{
//DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
try {
}
// the import extension has passed us a document, now we need to embed it into our document
if ( 0 ) {
// const gchar *docbase = (sp_repr_document_root( sp_repr_document( repr ))->attribute("sodipodi:docbase" );
g_message(" mid-fixup");
}
// move imported defs to our document's defs
{
// FIXME: in case of id conflict, newly added thing will be re-ided and thus likely break a reference to it from imported stuff
}
guint items_count = 0;
if (SP_IS_ITEM(child))
items_count ++;
}
// create group
for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM(child)) {
// convert layers to groups; FIXME: add "preserve layers" mode where each layer
// from impot is copied to the same-named layer in host
}
}
if (desktop) {
// Add it to the current layer
} else {
// There's no desktop (command line run?)
// FIXME: For such cases we need a document:: method to return the current layer
}
} else {
// just add one item
for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM(child)) {
if (desktop) {
// Add it to the current layer
} else {
// There's no desktop (command line run?)
// FIXME: For such cases we need a document:: method to return the current layer
}
}
}
}
// select and move the imported item
// To move the imported object, we must temporarily set the "transform pattern with
// object" option.
{
}
}
} else {
}
return;
}
/**
* Display an Open dialog, import a resource if OK pressed.
*/
void
{
if (!doc)
return;
if (!importDialogInstance) {
(char const *)import_path,
(char const *)_("Select file to import"));
}
: NULL );
if (!success) return;
if (fileName) {
gsize bytesWritten = 0;
#ifdef INK_DUMP_FILENAME_CONV
#endif
-1,
&error);
if ( newFileName != NULL ) {
#ifdef INK_DUMP_FILENAME_CONV
#endif
} else {
// TODO: bulia, please look over
g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
}
// TODO: bulia, please look over
g_warning( "INPUT FILENAME IS NOT UTF-8" );
}
}
return;
}
/*######################
## E X P O R T
######################*/
/**
*
*/
void
sp_file_export_dialog(void *widget)
{
}
#include <display/nr-arena-item.h>
#include <display/nr-arena.h>
struct SPEBP {
guchar r, g, b, a;
unsigned (*status)(float, void *);
void *data;
};
/**
*
*/
static int
{
}
/* Set area of interest */
/* Update to renderable state */
nr_arena_item_invoke_update(ebp->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
for (int r = 0; r < num_rows; r++) {
*p++ = ebp->r;
*p++ = ebp->g;
*p++ = ebp->b;
*p++ = ebp->a;
}
}
/* Render */
for (int r = 0; r < num_rows; r++) {
}
return num_rows;
}
/**
Hide all items which are not listed in list, recursively, skipping groups and defs
*/
void
{
if (SP_IS_ITEM(o)
&& !SP_IS_DEFS(o)
&& !SP_IS_ROOT(o)
&& !SP_IS_GROUP(o)
&& !g_slist_find(list, o))
{
}
// recurse
if (!g_slist_find(list, o)) {
}
}
}
/**
* Render the SVG drawing onto a PNG raster image, then save to
* a file. Returns TRUE if succeeded in writing the file,
* FALSE otherwise.
*/
int
unsigned long bgcolor,
unsigned (*status)(float, void *),
void *data, bool force_overwrite,
{
int write_status = TRUE;
return FALSE;
}
/* Go to document coordinates */
/*
* 1) a[0] * x0 + a[2] * y1 + a[4] = 0.0
* 2) a[1] * x0 + a[3] * y1 + a[5] = 0.0
* 3) a[0] * x1 + a[2] * y1 + a[4] = width
* 4) a[1] * x0 + a[3] * y0 + a[5] = height
* 5) a[1] = 0.0;
* 6) a[2] = 0.0;
*
* (1,3) a[0] * x1 - a[0] * x0 = width
* a[0] = width / (x1 - x0)
* (2,4) a[3] * y0 - a[3] * y1 = height
* a[3] = height / (y0 - y1)
* (1) a[4] = -a[0] * x0
* (2) a[5] = -a[3] * y1
*/
//SP_PRINT_MATRIX("SVG2PNG", &affine);
/* Create new arena */
/* Create ArenaItems and set transform */
// We show all and then hide all items we don't want, instead of showing only requested items,
// because that would not work if the shown item references something in defs
if (items_only) {
}
write_status = sp_png_write_rgba_striped(filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
} else {
write_status = sp_png_write_rgba_striped(filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
}
// Hide items
/* Free Arena and ArenaItem */
return write_status;
}
/*######################
## P R I N T
######################*/
/**
* Print the current document, if any.
*/
void
{
if (doc)
}
/**
* Print the current document, if any. Do not use
* the machine's print drivers.
*/
void
{
if (doc)
}
/**
* Display what the drawing would look like, if
* printed.
*/
void
{
if (doc)
}
{
//g_message("Inkscape::IO::fixupHrefs( , [%s], )", base );
if ( 0 ) {
"data:foo,bar",
"foo.svg",
"file:foo.svg",
"bar\xe1\x84\x92.svg",
"bar%e1%84%92.svg",
};
g_message("+------");
for ( int i = 0; things[i]; i++ )
{
try
{
(int)uri.isRelative(),
things[i],
str );
}
catch ( MalformedURIException err )
{
{
(int)again.isRelative(),
things[i],
str );
g_message(" ----");
}
}
}
g_message("+------");
}
// First try to figure out an absolute path to the asset
//g_message("image href [%s]", href );
//g_message(" absr [%s]", absref );
if ( absref && Inkscape::IO::file_test(absref, G_FILE_TEST_EXISTS) && !Inkscape::IO::file_test(base_href, G_FILE_TEST_EXISTS))
{
// only switch over if the absref is valid while href is not
//g_message(" copied absref to href");
}
}
// Once we have an absolute path, convert it relative to the new location
//g_message(" setting to [%s]", relname );
}
// TODO next refinement is to make the first choice keeping the relative path as-is if
// based on the new location it gives us a valid file.
}
}
/*
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 :