/**
* @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
* c++ port Copyright (C) 2003 Nathan Hurst
* c++ification Copyright (C) 2014 Liam P. White
*
* 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 <gtkmm/messagedialog.h>
#include "debug/simple-event.h"
#include "debug/event-tracker.h"
#ifndef WIN32
#else
#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 "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"
// Inkscape::Application static members
#ifndef WIN32
#endif
#ifdef WIN32
typedef int uid_t;
#define getuid() 0
#endif
/** C++ification TODO list
* - _S_inst should NOT need to be assigned inside the constructor, but if it isn't the Filters+Extensions menus break.
* - Application::_deskops has to be a pointer because of a signal bug somewhere else. Basically, it will attempt to access a deleted object in sp_ui_close_all(),
* but if it's a pointer we can stop and return NULL in Application::active_desktop()
* - These functions are calling Application::create for no good reason I can determine:
*
* Inkscape::UI::Dialog::SVGPreview::SVGPreview()
* src/ui/dialog/filedialogimpl-gtkmm.cpp:542:9
* void Inkscape::UI::Widget::ImageIcon::init()
* src/ui/widget/imageicon.cpp:93:9
*/
public:
{}
virtual ~InkErrorHandler() {}
{
if (_useGui) {
} else {
}
}
private:
bool _useGui;
};
{
}
{
}
} else {
g_error("Attempt to unref an Application (=%p) not the current instance (=%p) (maybe it's already been destroyed?)",
}
}
// Callback passed to g_timeout_add_seconds()
// gets the current instance and calls autosave()
}
namespace Inkscape {
/**
* Defined only for debugging purposes. If we are certain the bugs are gone we can remove this
* and the references in inkscape_ref and inkscape_unref.
*/
Application::operator &() const
{
return const_cast<Application*>(this);
}
/**
* Creates a new Inkscape::Application global object.
*/
void
{
if (!Application::exists()) {
} else {
}
}
/**
* Checks whether the current Inkscape::Application global object exists.
*/
bool
{
}
/**
* Returns the current Inkscape::Application global object.
* \pre Application::_S_inst != NULL
*/
{
if (!exists()) {
g_error("Inkscape::Application does not yet exist.");
}
return *Application::_S_inst;
}
/**
* static gint inkscape_autosave(gpointer);
*
* 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) {
// 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()) {
// 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;
}
{
// 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
}
}
{
}
/* \brief Constructor for the application.
* Creates a new Inkscape::Application.
*
* \pre Application::_S_inst == NULL
*/
refCount(1),
{
/* fixme: load application defaults */
#ifndef WIN32
#endif
// \TODO: this belongs to Application::init but if it isn't here
// then the Filters and Extensions menus don't work.
_S_inst = this;
/* 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
{
static bool recursion = false;
/*
* reset all signal handlers: any further crashes should just be allowed
* to crash normally.
* */
#ifndef WIN32
#endif
/* Stop bizarre loops */
if (recursion) {
abort ();
}
recursion = true;
_crashIsHappening = true;
for (std::map<SPDocument*,int>::iterator iter = INKSCAPE._document_set.begin(), e = INKSCAPE._document_set.end();
iter != e;
++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 *sstr = _("Automatic backups of unsaved documents were done to the following locations:\n");
}
}
len += 1;
if (savednames) {
}
}
if (failednames) {
}
}
*(b + pos) = '\0';
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
*
*/
{
// 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_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 (desktop->getSelection())
}
}
// if this was the last desktop, shut down the program
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
{
_dialogs_toggle = false;
}
void
{
_dialogs_toggle = true;
}
void
{
if (_dialogs_toggle) {
dialogs_hide();
} 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
}
}
} 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_ACTIVE_DESKTOP->getDocument();
} 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;
}
{
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
{
//emit shutdown signal so that dialogs could remember layout
gtk_main_quit ();
}
char *
{
if (!homedir) {
homedir = g_get_home_dir();
}
if (!homedir) {
if (Application::exists()) {
}
}
}
/**
* 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) {
{
}
}
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 :