inkscape.cpp revision 6cc2da37c4f1d408dbc9ca92ee622d4093f554fb
/**
* @file
* Interface to main application.
*/
/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Liam P. White <inkscapebrony@gmail.com>
*
* Copyright (C) 1999-2014 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>
#endif
#include <gtkmm/messagedialog.h>
#include "debug/simple-event.h"
#include "debug/event-tracker.h"
#ifndef WIN32
# define HAS_PROC_SELF_EXE //to get path of executable
#else
# define _WIN32_IE 0x0400
#endif
//#define HAS_SHGetSpecialFolderPath
#define HAS_SHGetSpecialFolderLocation
#define HAS_GetModuleFileName
# include <shlobj.h>
#endif
#include <cstring>
#include <glibmm/miscutils.h>
#include <signal.h>
#include <string>
#include "desktop.h"
#include "desktop-handles.h"
#include "device-manager.h"
#include "document.h"
#include "helper/action-context.h"
#include "helper/sp-marshal.h"
#include "inkscape.h"
#include "layer-model.h"
#include "message-stack.h"
#include "preferences.h"
#include "resource-manager.h"
#include "selection.h"
#include "ui/tools/tool-base.h"
/* Backbones of configuration xml data */
#include "menus-skeleton.h"
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"
#define SP_INDENT 8
#ifdef WIN32
typedef int uid_t;
#define getuid() 0
#endif
public:
{}
virtual ~InkErrorHandler() {}
{
if (_useGui) {
} else {
}
}
private:
bool _useGui;
};
{
return in;
}
{
delete in;
}
return NULL;
}
int inkscape_autosave(gpointer) {
}
/**
* Returns the current Inkscape::Application global object
*/
{
return inkscape;
}
/* fixme: This is EVIL, and belongs to main after all */
static bool crashIsHappening = false;
bool inkscapeIsCrashing()
{
return crashIsHappening;
}
void
{
if (!inkscape) {
} else {
}
}
namespace Inkscape {
/**
* static gint inkscape_autosave(gpointer);
*
* Callback passed to g_timeout_add_seconds()
* Responsible for autosaving all open documents
*/
int Application::autosave()
{
return TRUE;
}
// Use UID for separating autosave-documents between users if directory is multiuser
{
autosave_dir = tmp;
} else {
}
}
if (!autosave_dir_ptr) {
// Try to create the autosave directory if it doesn't exist
// the creation failed
return TRUE;
}
// Try to read dir again
if( !autosave_dir_ptr ){
return TRUE;
}
}
++iter) {
++docnum;
if (doc->isModifiedSinceSave()) {
gchar *oldest_autosave = 0;
// Look for previous autosaves
if ( oldest_autosave ) {
}
}
count ++;
}
}
}
}
// 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;
// Try to save the file
if (file) {
try{
}
}
else {
}
if (errortext) {
}
}
}
return TRUE;
}
void Application::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
}
}
{
}
refCount(1),
{
/* fixme: load application defaults */
#ifndef WIN32
#endif
/* Load the preferences and menus */
{
}
}
if (use_gui) {
load_menus();
}
/* 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 */
}
{
if (desktops) {
g_error("FATAL: desktops still in list on application destruction!");
}
if (menus) {
}
if (_argv0) {
}
refCount = 0;
gtk_main_quit ();
}
/* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */
{
_mapalt = 0;
} else {
}
}
void
{
/*
* 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->getName()) ? g_strdup(doc->getName()) : 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';
// checking whether we have an Inkscape instance after that instance caused an exception is like
// checking if your mother existed after sitting on you and nearly hospitalizing you
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 */
}
/**
* Menus management
*
*/
bool Application::load_menus()
{
// load the menus_xml file
menus_xml = 0;
}
fn = 0;
if ( !menus ) {
}
return (menus != 0);
}
void
{
}
}
void
{
}
}
void
{
if (DESKTOP_IS_ACTIVE (desktop)) {
}
}
void
{
}
}
void
{
}
}
void
{
g_message("Creating new desktop list.");
}
g_error("Attempted to add desktop already in list.");
}
}
void
{
g_error("Attempted to remove desktop not in list.");
}
if (DESKTOP_IS_ACTIVE (desktop)) {
} else {
if (sp_desktop_selection(desktop))
}
}
// if this was the last desktop, shut down the program
g_message("Shutting down.");
this->exit();
delete desktops;
}
}
void
{
if (DESKTOP_IS_ACTIVE (desktop)) {
return;
}
g_error("Tried to activate desktop not added to list.");
}
}
/**
* 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)) {
}
}
{
return *r;
}
}
return NULL;
}
unsigned int
{
unsigned int dkey = 0;
}
}
return dkey;
}
{
if (dkey_current < maximum_dkey()) {
// find next existing
d = find_desktop_by_dkey (i);
if (d) {
break;
}
}
} else {
// find first existing
for (unsigned int i = 0; i <= maximum_dkey(); ++i) {
d = 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 = find_desktop_by_dkey (i);
if (d) {
break;
}
}
}
if (!d) {
// find last existing
d = find_desktop_by_dkey (maximum_dkey());
}
g_assert (d);
return d;
}
void
{
next_desktop()->presentWindow();
}
void
{
prev_desktop()->presentWindow();
}
void
{
signal_dialogs_hide.emit(this);
}
void
{
signal_dialogs_unhide.emit(this);
}
void
{
if (_dialogs_toggle) {
dialogs_hide();
} else {
}
}
void
{
signal_external_change.emit(this);
}
/**
* 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
}
}
} else {
// insert succeeded, this document is new. Do we need to create a
// selection model for it, i.e. are we running without a desktop?
if (!_use_gui) {
// Create layer model and selection model so we can run some verbs without a GUI
}
}
}
// 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
// also remove the selection model
}
return true;
} else {
return false;
}
}
}
return false;
}
{
return NULL;
}
}
{
if (SP_ACTIVE_DESKTOP) {
return sp_desktop_document (SP_ACTIVE_DESKTOP);
} else if (!document_set.empty()) {
// If called from the command line there will be no desktop
// So 'fall back' to take the first listed document in the Inkscape instance
}
return NULL;
}
bool
if (!document) {
return false;
}
for ( std::vector<SPDesktop*>::iterator iter = desktops->begin(), e = desktops->end() ; iter != e; ++iter ) {
return false;
}
}
return true;
}
Application::active_event_context (void)
{
if (SP_ACTIVE_DESKTOP) {
return SP_ACTIVE_DESKTOP->getEventContext();
}
return NULL;
}
{
if (SP_ACTIVE_DESKTOP) {
}
if (!doc) {
return Inkscape::ActionContext();
}
return action_context_for_document(doc);
}
{
// If there are desktops, check them first to see if the document is bound to one of them
for (std::vector<SPDesktop*>::iterator iter = desktops->begin(), e = desktops->end() ; iter != e ; ++iter) {
}
}
// Document is not associated with any desktops - maybe we're in command-line mode
return Inkscape::ActionContext();
}
}
/*#####################
# HELPERS
#####################*/
void
{
(*l)->requestRedraw();
}
}
/**
* Handler for Inkscape's Exit verb. This emits the shutdown signal,
* saves the preferences if appropriate, and quits.
*/
void
Application::exit ()
{
//emit shutdown signal so that dialogs could remember layout
signal_shut_down.emit(this);
gtk_main_quit ();
}
char *
{
if (!homedir) {
homedir = g_get_home_dir();
}
if (!homedir) {
if (inkscape) {
}
}
}
/**
* Get, or guess, or decide the location where the preferences.xml
* file should be located.
*/
gchar *
{
if (!prefdir) {
// First check for a custom environment variable for a "portable app"
if (val) {
}
// Then check for a custom user environment variable
if (userenv) {
}
// prefer c:\Documents and Settings\UserName\Application Data\ to
// c:\Documents and Settings\userName\;
if (!prefdir) {
ITEMIDLIST *pidl = 0;
{
}
}
if ( utf8Path ) {
g_warning( "SHGetPathFromIDListW() resulted in invalid UTF-8");
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
{
}
} // namespace Inkscape
/*
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 :