inkscape.cpp revision a39a6c00b097c411f84488cdd0d4f82a4083b139
/** @file
* @brief Legacy interface to main application
*/
/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2005 authors
* g++ port Copyright (C) 2003 Nathan Hurst
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <map>
#include "debug/simple-event.h"
#include "debug/event-tracker.h"
#ifndef WIN32
# define HAS_PROC_SELF_EXE //to get path of executable
#else
// For now to get at is_os_wide().
#define _WIN32_IE 0x0400
//#define HAS_SHGetSpecialFolderPath
#define HAS_SHGetSpecialFolderLocation
#define HAS_GetModuleFileName
# include <shlobj.h>
#endif
#include <cstring>
#include <glib.h>
#include <gtk/gtkmessagedialog.h>
#include <gtkmm/messagedialog.h>
#include <signal.h>
#include <string>
#include "desktop.h"
#include "desktop-handles.h"
#include "device-manager.h"
#include "document.h"
#include "event-context.h"
//#include "helper/sp-marshal.h"
#include "inkscape-private.h"
#include "message-stack.h"
#include "preferences.h"
#include "selection.h"
/* Backbones of configuration xml data */
#include "menus-skeleton.h"
enum {
MODIFY_SELECTION, // global: one of selections modified
CHANGE_SELECTION, // global: one of selections changed
CHANGE_SUBSELECTION, // global: one of subselections (text selection, gradient handle, etc) changed
SET_SELECTION, // global: one of selections set
SET_EVENTCONTEXT, // tool switched
ACTIVATE_DESKTOP, // some desktop got focus
DEACTIVATE_DESKTOP, // some desktop lost focus
SHUTDOWN_SIGNAL, // inkscape is quitting
DIALOGS_HIDE, // user pressed F12
DIALOGS_UNHIDE, // user pressed F12
EXTERNAL_CHANGE, // a document was changed by some external means (undo or XML editor); this
// may not be reflected by a selection change and thus needs a separate signal
};
/*################################
# FORWARD DECLARATIONS
################################*/
static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
static void inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
struct Inkscape::Application {
// for overriding things like the warning dlg's
};
struct Inkscape::ApplicationClass {
/* Signals */
void (* modify_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection, guint flags);
};
static GObjectClass * parent_class;
static void (* segv_handler) (int) = SIG_DFL;
static void (* abrt_handler) (int) = SIG_DFL;
static void (* fpe_handler) (int) = SIG_DFL;
static void (* ill_handler) (int) = SIG_DFL;
#ifndef WIN32
static void (* bus_handler) (int) = SIG_DFL;
#endif
#define INKSCAPE_PROFILE_DIR "inkscape"
#define INKSCAPE_PROFILE_DIR_047DEV "Inkscape"
#define INKSCAPE_LEGACY_PROFILE_DIR ".inkscape"
#define MENUS_FILE "menus.xml"
/**
* Retrieves the GType for the Inkscape Application object.
*/
inkscape_get_type (void)
{
if (!type) {
sizeof (Inkscape::ApplicationClass),
sizeof (Inkscape::Application),
4,
};
}
return type;
}
/**
* Initializes the inkscape class, registering all of its signal handlers
* and virtual functions
*/
static void
{
G_TYPE_NONE, 2,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
}
#ifdef WIN32
typedef int uid_t;
#define getuid() 0
#endif
/**
* static gint inkscape_autosave(gpointer);
*
* Callback passed to g_timeout_add_seconds()
* Responsible for autosaving all open documents
*/
{
return TRUE;
}
// Use UID for separating autosave-documents between users if directory is multiuser
{
autosave_dir = tmp;
} else {
}
}
if( !autosave_dir_ptr ){
g_warning("Cannot open autosave directory!");
return TRUE;
}
++iter) {
++docnum;
// g_debug("Document %d: \"%s\" %s", docnum, doc ? doc->name : "(null)", doc ? (doc->isModifiedSinceSave() ? "(dirty)" : "(clean)") : "(null)");
if (doc->isModifiedSinceSave()) {
gchar *oldest_autosave = 0;
// Look for previous autosaves
if ( oldest_autosave ) {
}
}
count ++;
}
}
}
// g_debug("%d previous autosaves exists. Max = %d", count, autosave_max);
// Have we reached the limit for number of autosaves?
if ( count >= autosave_max ){
// Remove the oldest file
if ( oldest_autosave ) {
}
}
if ( oldest_autosave ) {
oldest_autosave = 0;
}
// Set the filename we will actually save to
baseName = 0;
// g_debug("Filename: %s", full_path);
// Try to save the file
if (file) {
try{
}
}
else {
}
if (errortext) {
}
}
}
return TRUE;
}
void inkscape_autosave_init()
{
static guint32 autosave_timeout_id = 0;
// Turn off any previously initiated timeouts
if ( autosave_timeout_id ) {
autosave_timeout_id = 0;
}
// Is autosave enabled?
autosave_timeout_id = 0;
} else {
// Turn on autosave
#else
#endif
}
}
static void
{
if (!inkscape) {
} else {
}
}
static void
{
/* fixme: This is not the best place */
}
gtk_main_quit ();
}
void
inkscape_ref (void)
{
if (inkscape)
}
void
inkscape_unref (void)
{
if (inkscape)
}
/* returns the mask of the keyboard modifier to map to Alt, zero if no mapping */
/* Needs to be a guint because gdktypes.h does not define a 'no-modifier' value */
inkscape_mapalt() {
}
/* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */
{
}else{
}
}
}
{
}
static void
{
desktop->set_active (true);
}
static void
{
desktop->set_active (false);
}
/* fixme: This is EVIL, and belongs to main after all */
#define SP_INDENT 8
static bool crashIsHappening = false;
bool inkscapeIsCrashing()
{
return crashIsHappening;
}
static void
inkscape_crash_handler (int /*signum*/)
{
/*
* reset all signal handlers: any further crashes should just be allowed
* to crash normally.
* */
#ifndef WIN32
#endif
/* Stop bizarre loops */
if (recursion) {
abort ();
}
crashIsHappening = true;
++iter) {
if (doc->isModifiedSinceSave()) {
/* originally, the document name was retrieved from
* the sodipod:docname attribute */
if (docname) {
/* Removes an emergency save suffix if present: /(.*)\.[0-9_]*\.[0-9_]*\.[~\.]*$/\1/ */
const char* d = d0;
unsigned int dots = 0;
d -= 1;
if (*d=='.') dots++;
}
char n[64];
n[len] = '\0';
docname = n;
}
}
}
// Emergency filename
char c[1024];
// Find a location
const char* locations[] = {
};
if (!locations[i]) continue; // It seems to be okay, but just in case
if (file) {
g_snprintf (c, 1024, "%s", filename); // we want the complete path to be stored in c (for reporting purposes)
break;
}
}
// Save
if (file) {
} else {
failednames = g_slist_prepend (failednames, (doc->name) ? g_strdup (doc->name) : g_strdup (_("Untitled document")));
}
count++;
}
}
if (savednames) {
}
}
if (failednames) {
}
}
// do not save the preferences since they can be in a corrupted state
fprintf (stderr, "with a detailed description of the steps leading to the crash, so we can fix it.\n");
/* Show nice dialog box */
char const *istr = _("Inkscape encountered an internal error and will close now.\n");
char const *sstr = _("Automatic backups of unsaved documents were done to the following locations:\n");
char const *fstr = _("Automatic backup of the following documents failed:\n");
}
}
len += 1;
if (savednames) {
}
}
if (failednames) {
}
}
*(b + pos) = '\0';
if ( inkscape_get_instance() && inkscape_use_gui() ) {
GtkWidget *msgbox = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", b);
}
else
{
g_message( "Error: %s", b );
}
g_free (b);
/* on exit, allow restored signal handler to take over and crash us */
}
public:
{}
virtual ~InkErrorHandler() {}
{
if (_useGui) {
} else {
}
}
private:
bool _useGui;
};
void
{
/* fixme: load application defaults */
#ifndef WIN32
#endif
/* Load the preferences and menus */
{
}
}
if (use_gui) {
}
/* set language for user interface according setting in preferences */
if(!ui_language.empty())
{
}
/* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON.
* Use only if use_gui is enabled
*/
#ifdef WIN32
#define DEFAULT_LOG_REDIRECT true
#else
#define DEFAULT_LOG_REDIRECT false
#endif
{
}
/* Check for global remapping of Alt key */
if (use_gui)
{
}
/* Initialize the extensions */
return;
}
/**
* Returns the current Inkscape::Application global object
*/
{
return inkscape;
}
{
return inkscape_get_instance()->use_gui;
}
/**
* Menus management
*
*/
{
// TODO fix that fn is being leaked
// load the menus_xml file
return true;
}
}
}
void
{
}
}
void
{
}
}
void
{
if (DESKTOP_IS_ACTIVE (desktop)) {
}
}
void
{
}
}
void
{
}
}
void
{
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
}
void
{
if (DESKTOP_IS_ACTIVE (desktop)) {
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
} else {
if (sp_desktop_selection(desktop))
}
}
// if this was the last desktop, shut down the program
}
}
void
{
if (DESKTOP_IS_ACTIVE (desktop)) {
return;
}
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
}
/**
* Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
*/
void
{
if (DESKTOP_IS_ACTIVE (desktop))
}
inkscape_find_desktop_by_dkey (unsigned int dkey)
{
}
return NULL;
}
unsigned int
{
unsigned int dkey = 0;
}
return dkey;
}
{
if (dkey_current < inkscape_maximum_dkey()) {
// find next existing
d = inkscape_find_desktop_by_dkey (i);
if (d) {
break;
}
}
} else {
// find first existing
for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
d = inkscape_find_desktop_by_dkey (i);
if (d) {
break;
}
}
}
g_assert (d);
return d;
}
{
if (dkey_current > 0) {
// find prev existing
for (signed int i = dkey_current - 1; i >= 0; i--) {
d = inkscape_find_desktop_by_dkey (i);
if (d) {
break;
}
}
}
if (!d) {
// find last existing
}
g_assert (d);
return d;
}
void
{
}
void
{
}
void
{
}
void
{
}
void
{
if (inkscape->dialogs_toggle) {
} else {
}
}
void
{
}
/**
* fixme: These need probably signals too
*/
void
{
// try to insert the pair into the list
//insert failed, this key (document) is already in the list
++iter) {
// found this document in list, increase its count
}
}
}
}
// returns true if this was last reference to this document, so you can delete it
bool
{
++iter) {
// found this document in list, decrease its count
// this was the last one, remove the pair from list
return true;
} else {
return false;
}
}
}
return false;
}
inkscape_active_desktop (void)
{
return NULL;
}
}
inkscape_active_document (void)
{
if (SP_ACTIVE_DESKTOP) {
return sp_desktop_document (SP_ACTIVE_DESKTOP);
}
return NULL;
}
if (!document) {
return false;
}
return false;
}
}
return true;
}
{
if (SP_ACTIVE_DESKTOP) {
return sp_desktop_event_context (SP_ACTIVE_DESKTOP);
}
return NULL;
}
/*#####################
# HELPERS
#####################*/
void
{
}
}
/**
* Handler for Inkscape's Exit verb. This emits the shutdown signal,
* saves the preferences if appropriate, and quits.
*/
void
{
//emit shutdown signal so that dialogs could remember layout
gtk_main_quit ();
}
char *
homedir_path(const char *filename)
{
if (!homedir) {
homedir = g_get_home_dir();
}
if (!homedir) {
}
}
/**
* Get, or guess, or decide the location where the preferences.xml
* file should be located.
*/
gchar *
profile_path(const char *filename)
{
if (!prefdir) {
// First check for a custom environment variable for a "portable app"
if (val) {
}
// prefer c:\Documents and Settings\UserName\Application Data\ to
// c:\Documents and Settings\userName\;
if (!prefdir) {
ITEMIDLIST *pidl = 0;
if ( PrintWin32::is_os_wide() ) {
}
} else {
}
}
if ( utf8Path ) {
g_warning( "SHGetPathFromIDList%c() resulted in invalid UTF-8", (PrintWin32::is_os_wide() ? 'W' : 'A') );
utf8Path = 0;
} else {
}
}
/* not compiling yet...
// Remember to free the list pointer
IMalloc * imalloc = 0;
if ( SHGetMalloc(&imalloc) == NOERROR) {
imalloc->lpVtbl->Free( imalloc, pidl );
imalloc->lpVtbl->Release( imalloc );
}
*/
}
if (prefdir) {
}
}
#endif
if (!prefdir) {
bool needsMigration = ( !Inkscape::IO::file_test( prefdir, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( legacyDir, G_FILE_TEST_EXISTS ) );
if (needsMigration) {
// TODO here is a point to hook in preference migration
}
bool needsRenameWarning = ( !Inkscape::IO::file_test( prefdir, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( dev47Dir, G_FILE_TEST_EXISTS ) );
if (needsRenameWarning) {
}
legacyDir = 0;
dev47Dir = 0;
// In case the XDG user config dir of the moment does not yet exist...
#ifdef S_IRGRP
#endif
#ifdef S_IXGRP
#endif
#ifdef S_IXOTH
#endif
} else {
}
}
}
}
}
{
return repr->firstChild();
}
void
{
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :