~ubuntu-branches/ubuntu/precise/inkscape/precise-updates

« back to all changes in this revision

Viewing changes to src/inkscape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alex Valavanis
  • Date: 2010-09-12 19:44:58 UTC
  • mfrom: (1.1.12 upstream) (45.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20100912194458-4sjwmbl7dlsrk5dc
Tags: 0.48.0-1ubuntu1
* Merge with Debian unstable (LP: #628048, LP: #401567, LP: #456248, 
  LP: #463602, LP: #591986)
* debian/control: 
  - Ubuntu maintainers
  - Promote python-lxml, python-numpy, python-uniconvertor to Recommends.
  - Demote pstoedit to Suggests (universe package).
  - Suggests ttf-dejavu instead of ttf-bitstream-vera (LP: #513319)
* debian/rules:
  - Run intltool-update on build (Ubuntu-specific).
  - Add translation domain to .desktop files (Ubuntu-specific).
* debian/dirs:
  - Add usr/share/pixmaps.  Allow inkscape.xpm installation
* drop 50-poppler-API.dpatch (now upstream)
* drop 51-paste-in-unwritable-directory.dpatch (now upstream) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include "application/editor.h"
50
50
#include "desktop.h"
51
51
#include "desktop-handles.h"
52
 
#include "dialogs/input.h"
 
52
#include "device-manager.h"
53
53
#include "document.h"
54
54
#include "event-context.h"
55
55
#include "extension/db.h"
56
56
#include "extension/init.h"
57
57
#include "extension/output.h"
58
58
#include "extension/system.h"
59
 
#include "helper/sp-marshal.h"
 
59
//#include "helper/sp-marshal.h"
60
60
#include "inkscape-private.h"
61
61
#include "io/sys.h"
62
62
#include "message-stack.h"
193
193
                               G_SIGNAL_RUN_FIRST,
194
194
                               G_STRUCT_OFFSET (Inkscape::ApplicationClass, modify_selection),
195
195
                               NULL, NULL,
196
 
                               sp_marshal_NONE__POINTER_UINT,
 
196
                               g_cclosure_marshal_VOID__UINT_POINTER,
197
197
                               G_TYPE_NONE, 2,
198
198
                               G_TYPE_POINTER, G_TYPE_UINT);
199
199
    inkscape_signals[CHANGE_SELECTION] = g_signal_new ("change_selection",
201
201
                               G_SIGNAL_RUN_FIRST,
202
202
                               G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_selection),
203
203
                               NULL, NULL,
204
 
                               sp_marshal_NONE__POINTER,
 
204
                               g_cclosure_marshal_VOID__POINTER,
205
205
                               G_TYPE_NONE, 1,
206
206
                               G_TYPE_POINTER);
207
207
    inkscape_signals[CHANGE_SUBSELECTION] = g_signal_new ("change_subselection",
209
209
                               G_SIGNAL_RUN_FIRST,
210
210
                               G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_subselection),
211
211
                               NULL, NULL,
212
 
                               sp_marshal_NONE__POINTER,
 
212
                               g_cclosure_marshal_VOID__POINTER,
213
213
                               G_TYPE_NONE, 1,
214
214
                               G_TYPE_POINTER);
215
215
    inkscape_signals[SET_SELECTION] =    g_signal_new ("set_selection",
217
217
                               G_SIGNAL_RUN_FIRST,
218
218
                               G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_selection),
219
219
                               NULL, NULL,
220
 
                               sp_marshal_NONE__POINTER,
 
220
                               g_cclosure_marshal_VOID__POINTER,
221
221
                               G_TYPE_NONE, 1,
222
222
                               G_TYPE_POINTER);
223
223
    inkscape_signals[SET_EVENTCONTEXT] = g_signal_new ("set_eventcontext",
225
225
                               G_SIGNAL_RUN_FIRST,
226
226
                               G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_eventcontext),
227
227
                               NULL, NULL,
228
 
                               sp_marshal_NONE__POINTER,
 
228
                               g_cclosure_marshal_VOID__POINTER,
229
229
                               G_TYPE_NONE, 1,
230
230
                               G_TYPE_POINTER);
231
231
    inkscape_signals[ACTIVATE_DESKTOP] = g_signal_new ("activate_desktop",
233
233
                               G_SIGNAL_RUN_FIRST,
234
234
                               G_STRUCT_OFFSET (Inkscape::ApplicationClass, activate_desktop),
235
235
                               NULL, NULL,
236
 
                               sp_marshal_NONE__POINTER,
 
236
                               g_cclosure_marshal_VOID__POINTER,
237
237
                               G_TYPE_NONE, 1,
238
238
                               G_TYPE_POINTER);
239
239
    inkscape_signals[DEACTIVATE_DESKTOP] = g_signal_new ("deactivate_desktop",
241
241
                               G_SIGNAL_RUN_FIRST,
242
242
                               G_STRUCT_OFFSET (Inkscape::ApplicationClass, deactivate_desktop),
243
243
                               NULL, NULL,
244
 
                               sp_marshal_NONE__POINTER,
 
244
                               g_cclosure_marshal_VOID__POINTER,
245
245
                               G_TYPE_NONE, 1,
246
246
                               G_TYPE_POINTER);
247
247
    inkscape_signals[SHUTDOWN_SIGNAL] =        g_signal_new ("shut_down",
595
595
    strftime (sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
596
596
 
597
597
    gint count = 0;
 
598
    gchar *curdir = g_get_current_dir(); // This one needs to be freed explicitly
 
599
    gchar *inkscapedir = g_path_get_dirname(INKSCAPE->argv0); // Needs to be freed
598
600
    GSList *savednames = NULL;
599
601
    GSList *failednames = NULL;
600
602
    for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
604
606
        Inkscape::XML::Node *repr;
605
607
        repr = sp_document_repr_root (doc);
606
608
        if (doc->isModifiedSinceSave()) {
607
 
            const gchar *docname, *d0, *d;
608
 
            gchar n[64], c[1024];
609
 
            FILE *file;
 
609
            const gchar *docname;
610
610
 
611
611
            /* originally, the document name was retrieved from
612
612
             * the sodipod:docname attribute */
613
613
            docname = doc->name;
614
614
            if (docname) {
615
 
                /* fixme: Quick hack to remove emergency file suffix */
616
 
                d0 = strrchr ((char*)docname, '.');
 
615
                /* Removes an emergency save suffix if present: /(.*)\.[0-9_]*\.[0-9_]*\.[~\.]*$/\1/ */
 
616
                const char* d0 = strrchr ((char*)docname, '.');
617
617
                if (d0 && (d0 > docname)) {
618
 
                    d0 = strrchr ((char*)(d0 - 1), '.');
619
 
                    if (d0 && (d0 > docname)) {
620
 
                        d = d0;
621
 
                        while (isdigit (*d) || (*d == '.') || (*d == '_')) d += 1;
622
 
                        if (*d) {
623
 
                            memcpy (n, docname, MIN (d0 - docname - 1, 64));
624
 
                            n[63] = '\0';
625
 
                            docname = n;
626
 
                        }
 
618
                    const char* d = d0;
 
619
                    unsigned int dots = 0;
 
620
                    while ((isdigit (*d) || *d=='_' || *d=='.') && d>docname && dots<2) {
 
621
                        d -= 1;
 
622
                        if (*d=='.') dots++;
 
623
                    }
 
624
                    if (*d=='.' && d>docname && dots==2) {
 
625
                        char n[64];
 
626
                        size_t len = MIN (d - docname, 63);
 
627
                        memcpy (n, docname, len);
 
628
                        n[len] = '\0';
 
629
                        docname = n;
627
630
                    }
628
631
                }
629
632
            }
630
 
 
631
633
            if (!docname || !*docname) docname = "emergency";
632
 
            // try saving to the profile location
 
634
 
 
635
            // Emergency filename
 
636
            char c[1024];
633
637
            g_snprintf (c, 1024, "%.256s.%s.%d.svg", docname, sptstr, count);
634
 
            gchar * location = homedir_path(c);
635
 
            Inkscape::IO::dump_fopen_call(location, "E");
636
 
            file = Inkscape::IO::fopen_utf8name(location, "w");
637
 
            g_snprintf (c, 1024, "%s", location); // we want the complete path to be stored in c (for reporting purposes)
638
 
            g_free(location);
639
 
            if (!file) {
640
 
                // try saving to /tmp
641
 
                g_snprintf (c, 1024, "/tmp/inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
642
 
                Inkscape::IO::dump_fopen_call(c, "G");
643
 
                file = Inkscape::IO::fopen_utf8name(c, "w");
644
 
            }
645
 
            if (!file) {
646
 
                // try saving to the current directory
647
 
                gchar *curdir = g_get_current_dir();
648
 
                g_snprintf (c, 1024, "inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
649
 
                Inkscape::IO::dump_fopen_call(c, "F");
650
 
                file = Inkscape::IO::fopen_utf8name(c, "w");
651
 
                // store the complete path in c so that it can be reported later
652
 
                gchar * location = g_build_filename(curdir, c, NULL);
653
 
                g_snprintf (c, 1024, "%s", location);
654
 
                g_free(location);
655
 
            }
 
638
 
 
639
            // Find a location
 
640
            const char* locations[] = {
 
641
                doc->base,
 
642
                g_get_home_dir(),
 
643
                g_get_tmp_dir(),
 
644
                curdir,
 
645
                inkscapedir
 
646
            };
 
647
            FILE *file = 0;
 
648
            for(size_t i=0; i<sizeof(locations)/sizeof(*locations); i++) {
 
649
                if (!locations[i]) continue; // It seems to be okay, but just in case
 
650
                gchar * filename = g_build_filename(locations[i], c, NULL);
 
651
                Inkscape::IO::dump_fopen_call(filename, "E");
 
652
                file = Inkscape::IO::fopen_utf8name(filename, "w");
 
653
                if (file) {
 
654
                    g_snprintf (c, 1024, "%s", filename); // we want the complete path to be stored in c (for reporting purposes)
 
655
                    break;
 
656
                }
 
657
            }
 
658
 
 
659
            // Save
656
660
            if (file) {
657
661
                sp_repr_save_stream (repr->document(), file, SP_SVG_NS_URI);
658
662
                savednames = g_slist_prepend (savednames, g_strdup (c));
663
667
            count++;
664
668
        }
665
669
    }
 
670
    g_free(curdir);
 
671
    g_free(inkscapedir);
666
672
 
667
673
    savednames = g_slist_reverse (savednames);
668
674
    failednames = g_slist_reverse (failednames);
807
813
 
808
814
    if (use_gui) {
809
815
        inkscape_load_menus(inkscape);
810
 
        sp_input_load_from_preferences();
 
816
        Inkscape::DeviceManager::getManager().loadConfig();
811
817
    }
812
818
 
813
819
    /* set language for user interface according setting in preferences */