~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/inkscape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#endif
19
19
 
20
20
 
 
21
#include <set>
21
22
#include "debug/simple-event.h"
22
23
#include "debug/event-tracker.h"
23
24
 
42
43
#include <gtk/gtkmessagedialog.h>
43
44
 
44
45
#include <glibmm/i18n.h>
 
46
#include <string>
 
47
#include <cstring>
45
48
#include "helper/sp-marshal.h"
46
49
#include "dialogs/debugdialog.h"
47
50
#include "application/application.h"
109
112
struct Inkscape::Application {
110
113
    GObject object;
111
114
    Inkscape::XML::Document *menus;
 
115
    std::multiset<SPDocument *> document_set;
112
116
    GSList *documents;
113
117
    GSList *desktops;
114
118
    gchar *argv0;
115
119
    gboolean dialogs_toggle;
116
120
    gboolean use_gui;         // may want to consider a virtual function
117
121
                              // for overriding things like the warning dlg's
 
122
    guint mapalt;
118
123
};
119
124
 
120
125
struct Inkscape::ApplicationClass {
139
144
static GObjectClass * parent_class;
140
145
static guint inkscape_signals[LAST_SIGNAL] = {0};
141
146
 
142
 
static void (* segv_handler) (int) = NULL;
 
147
static void (* segv_handler) (int) = SIG_DFL;
 
148
static void (* abrt_handler) (int) = SIG_DFL;
 
149
static void (* fpe_handler)  (int) = SIG_DFL;
 
150
static void (* ill_handler)  (int) = SIG_DFL;
 
151
static void (* bus_handler)  (int) = SIG_DFL;
143
152
 
144
153
#ifdef WIN32
145
154
#define INKSCAPE_PROFILE_DIR "Inkscape"
288
297
        g_assert_not_reached ();
289
298
    }
290
299
 
 
300
    new (&inkscape->document_set) std::multiset<SPDocument *>();
 
301
 
291
302
    inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL);
292
303
 
293
304
    inkscape->documents = NULL;
294
305
    inkscape->desktops = NULL;
295
306
 
296
307
    inkscape->dialogs_toggle = TRUE;
 
308
 
 
309
    inkscape->mapalt=GDK_MOD1_MASK;    
297
310
}
298
311
 
299
 
 
300
312
static void
301
313
inkscape_dispose (GObject *object)
302
314
{
317
329
        inkscape->menus = NULL;
318
330
    }
319
331
 
 
332
    inkscape->document_set.~multiset();
 
333
 
320
334
    G_OBJECT_CLASS (parent_class)->dispose (object);
321
335
 
322
336
    gtk_main_quit ();
338
352
        g_object_unref (G_OBJECT (inkscape));
339
353
}
340
354
 
 
355
/* returns the mask of the keyboard modifier to map to Alt, zero if no mapping */
 
356
/* Needs to be a guint because gdktypes.h does not define a 'no-modifier' value */
 
357
guint
 
358
inkscape_mapalt() {
 
359
    return inkscape->mapalt;
 
360
}
 
361
 
 
362
/* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */
 
363
void inkscape_mapalt(guint maskvalue)
 
364
{
 
365
    if(maskvalue<2 || maskvalue> 5 ){  /* MOD5 is the highest defined in gdktypes.h */
 
366
        inkscape->mapalt=0;
 
367
    }else{
 
368
        inkscape->mapalt=(GDK_MOD1_MASK << (maskvalue-1));
 
369
    }
 
370
}
341
371
 
342
372
static void
343
 
inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop)
 
373
inkscape_activate_desktop_private (Inkscape::Application */*inkscape*/, SPDesktop *desktop)
344
374
{
345
375
    desktop->set_active (true);
346
376
}
347
377
 
348
378
 
349
379
static void
350
 
inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop)
 
380
inkscape_deactivate_desktop_private (Inkscape::Application */*inkscape*/, SPDesktop *desktop)
351
381
{
352
382
    desktop->set_active (false);
353
383
}
359
389
 
360
390
 
361
391
static void
362
 
inkscape_segv_handler (int signum)
 
392
inkscape_crash_handler (int /*signum*/)
363
393
{
364
394
    using Inkscape::Debug::SimpleEvent;
365
395
    using Inkscape::Debug::EventTracker;
367
397
 
368
398
    static gint recursion = FALSE;
369
399
 
370
 
    /* let any SIGABRTs seen from within this handler dump core */
371
 
    signal(SIGABRT, SIG_DFL);
372
 
 
373
 
    /* Kill loops */
 
400
    /* 
 
401
     * reset all signal handlers: any further crashes should just be allowed
 
402
     * to crash normally.
 
403
     * */
 
404
    signal (SIGSEGV, segv_handler );
 
405
    signal (SIGABRT, abrt_handler );
 
406
    signal (SIGFPE,  fpe_handler  );
 
407
    signal (SIGILL,  ill_handler  );
 
408
#ifndef WIN32
 
409
    signal (SIGBUS,  bus_handler  );
 
410
#endif
 
411
    
 
412
    /* Stop bizarre loops */
374
413
    if (recursion) {
375
414
        abort ();
376
415
    }
394
433
        Inkscape::XML::Node *repr;
395
434
        doc = (SPDocument *) l->data;
396
435
        repr = sp_document_repr_root (doc);
397
 
        if (repr->attribute("sodipodi:modified")) {
 
436
        if (doc->isModifiedSinceSave()) {
398
437
            const gchar *docname, *d0, *d;
399
438
            gchar n[64], c[1024];
400
439
            FILE *file;
439
478
                file = Inkscape::IO::fopen_utf8name(c, "w");
440
479
            }
441
480
            if (file) {
442
 
                sp_repr_save_stream (sp_repr_document (repr), file, SP_SVG_NS_URI);
 
481
                sp_repr_save_stream (repr->document(), file, SP_SVG_NS_URI);
443
482
                savednames = g_slist_prepend (savednames, g_strdup (c));
444
483
                fclose (file);
445
484
            } else {
534
573
    tracker.clear();
535
574
    Logger::shutdown();
536
575
 
537
 
    (* segv_handler) (signum);
 
576
    /* on exit, allow restored signal handler to take over and crash us */
538
577
}
539
578
 
540
579
 
545
584
    inkscape = (Inkscape::Application *)g_object_new (SP_TYPE_INKSCAPE, NULL);
546
585
    /* fixme: load application defaults */
547
586
 
548
 
    segv_handler = signal (SIGSEGV, inkscape_segv_handler);
549
 
    signal (SIGFPE,  inkscape_segv_handler);
550
 
    signal (SIGILL,  inkscape_segv_handler);
 
587
    segv_handler = signal (SIGSEGV, inkscape_crash_handler);
 
588
    abrt_handler = signal (SIGABRT, inkscape_crash_handler);
 
589
    fpe_handler  = signal (SIGFPE,  inkscape_crash_handler);
 
590
    ill_handler  = signal (SIGILL,  inkscape_crash_handler);
551
591
#ifndef WIN32
552
 
    signal (SIGBUS,  inkscape_segv_handler);
 
592
    bus_handler  = signal (SIGBUS,  inkscape_crash_handler);
553
593
#endif
554
 
    signal (SIGABRT, inkscape_segv_handler);
555
594
 
556
595
    inkscape->use_gui = use_gui;
557
596
    inkscape->argv0 = g_strdup(argv0);
575
614
                Inkscape::UI::Dialogs::DebugDialog::getInstance()->captureLogMessages();
576
615
    }
577
616
 
 
617
    /* Check for global remapping of Alt key */
 
618
    if(use_gui)
 
619
    {
 
620
        inkscape_mapalt(guint(prefs_get_int_attribute("options.mapalt","value",0)));
 
621
    }
 
622
 
578
623
    /* Initialize the extensions */
579
624
    Inkscape::Extension::init();
580
625
 
645
690
        return false;
646
691
    }
647
692
 
648
 
    Inkscape::XML::Node *root = sp_repr_document_root (doc);
 
693
    Inkscape::XML::Node *root = doc->root();
649
694
    if (strcmp (root->name(), "inkscape")) {
650
695
        gchar *safeFn = Inkscape::IO::sanitizeString(fn);
651
696
        GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notsp, safeFn, warn);
708
753
Inkscape::XML::Node *
709
754
inkscape_get_repr (Inkscape::Application *inkscape, const gchar *key)
710
755
{
711
 
    if (key == NULL) {
712
 
        return NULL;
713
 
    }
714
 
 
715
 
    Inkscape::XML::Node *repr = sp_repr_document_root (Inkscape::Preferences::get());
 
756
    if ( (key == NULL) || (inkscape == NULL) ) {
 
757
        return NULL;
 
758
    }
 
759
 
 
760
    Inkscape::XML::Node *prefs = Inkscape::Preferences::get();
 
761
    if ( !prefs ) {
 
762
        return NULL;
 
763
    }
 
764
 
 
765
    Inkscape::XML::Node *repr = prefs->root();
 
766
    if (!repr) return NULL;
716
767
    g_assert (!(strcmp (repr->name(), "inkscape")));
717
768
 
718
769
    gchar const *s = key;
837
888
 
838
889
    g_assert (!g_slist_find (inkscape->desktops, desktop));
839
890
 
840
 
    inkscape->desktops = g_slist_append (inkscape->desktops, desktop);
 
891
    inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
841
892
 
842
 
    if (DESKTOP_IS_ACTIVE (desktop)) {
843
 
        g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
844
 
        g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
845
 
        g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
846
 
        g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
847
 
    }
 
893
    g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
 
894
    g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
 
895
    g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
 
896
    g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
848
897
}
849
898
 
850
899
 
1098
1147
 
1099
1148
    if (!Inkscape::NSApplication::Application::getNewGui())
1100
1149
    {
1101
 
        g_assert (!g_slist_find (inkscape->documents, document));
1102
 
        inkscape->documents = g_slist_append (inkscape->documents, document);
 
1150
        if ( inkscape->document_set.find(document) == inkscape->document_set.end() ) {
 
1151
    
 
1152
            inkscape->documents = g_slist_append (inkscape->documents, document);
 
1153
        }
 
1154
        inkscape->document_set.insert(document);
1103
1155
    }
1104
1156
    else
1105
1157
    {
1116
1168
 
1117
1169
    if (!Inkscape::NSApplication::Application::getNewGui())
1118
1170
    {
1119
 
        g_assert (g_slist_find (inkscape->documents, document));
1120
 
        inkscape->documents = g_slist_remove (inkscape->documents, document);
 
1171
        inkscape->document_set.erase(document);
 
1172
        if ( inkscape->document_set.find(document) != inkscape->document_set.end() ) {
 
1173
            inkscape->documents = g_slist_remove (inkscape->documents, document);
 
1174
        }
1121
1175
    }
1122
1176
    else
1123
1177
    {
1185
1239
#####################*/
1186
1240
 
1187
1241
static bool
1188
 
inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
 
1242
inkscape_init_config (Inkscape::XML::Document */*doc*/, const gchar *config_name, const gchar *skeleton,
1189
1243
                      unsigned int skel_size,
1190
1244
                      const gchar *e_mkdir,
1191
1245
                      const gchar *e_notdir,
1213
1267
                return false;
1214
1268
            }
1215
1269
        }
 
1270
 
 
1271
        // Also create (empty for now) subdirectories for the user's stuff
 
1272
        {
 
1273
            gchar *temp_dn = profile_path("templates");
 
1274
            Inkscape::IO::mkdir_utf8name(temp_dn);
 
1275
        }
 
1276
        {
 
1277
            gchar *temp_dn = profile_path("keys");
 
1278
            Inkscape::IO::mkdir_utf8name(temp_dn);
 
1279
        }
 
1280
        {
 
1281
            gchar *temp_dn = profile_path("icons");
 
1282
            Inkscape::IO::mkdir_utf8name(temp_dn);
 
1283
        }
 
1284
        {
 
1285
            gchar *temp_dn = profile_path("extensions");
 
1286
            Inkscape::IO::mkdir_utf8name(temp_dn);
 
1287
        }
 
1288
        {
 
1289
            gchar *temp_dn = profile_path("palettes");
 
1290
            Inkscape::IO::mkdir_utf8name(temp_dn);
 
1291
        }
 
1292
 
1216
1293
    } else if (!Inkscape::IO::file_test(dn, G_FILE_TEST_IS_DIR)) {
1217
1294
        if (use_gui) {
1218
1295
            // Not a directory
1289
1366
 *  saves the preferences if appropriate, and quits.
1290
1367
 */
1291
1368
void
1292
 
inkscape_exit (Inkscape::Application *inkscape)
 
1369
inkscape_exit (Inkscape::Application */*inkscape*/)
1293
1370
{
1294
1371
    g_assert (INKSCAPE);
1295
1372
 
1396
1473
Inkscape::XML::Node *
1397
1474
inkscape_get_menus (Inkscape::Application * inkscape)
1398
1475
{
1399
 
    Inkscape::XML::Node *repr = sp_repr_document_root (inkscape->menus);
 
1476
    Inkscape::XML::Node *repr = inkscape->menus->root();
1400
1477
    g_assert (!(strcmp (repr->name(), "inkscape")));
1401
1478
    return repr->firstChild();
1402
1479
}
1403
1480
 
 
1481
void
 
1482
inkscape_get_all_desktops(std::list< SPDesktop* >& listbuf)
 
1483
{
 
1484
    for(GSList* l = inkscape->desktops; l != NULL; l = l->next) {
 
1485
        listbuf.push_back(static_cast< SPDesktop* >(l->data));
 
1486
    }
 
1487
}
 
1488
 
1404
1489
 
1405
1490
 
1406
1491
/*