~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/ui/dialog/filedialogimpl-gtkmm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 * @brief Implementation of the file dialog interfaces defined in filedialogimpl.h
 
3
 */
 
4
/* Authors:
 
5
 *   Bob Jamison
 
6
 *   Joel Holdsworth
 
7
 *   Bruno Dilly
 
8
 *   Other dudes from The Inkscape Organization
 
9
 *
 
10
 * Copyright (C) 2004-2007 Bob Jamison
 
11
 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
 
12
 * Copyright (C) 2007-2008 Joel Holdsworth
 
13
 * Copyright (C) 2004-2007 The Inkscape Organization
 
14
 *
 
15
 * Released under GNU GPL, read the file 'COPYING' for more information
 
16
 */
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
# include <config.h>
 
20
#endif
 
21
 
 
22
#include "filedialogimpl-gtkmm.h"
 
23
#include "dialogs/dialog-events.h"
 
24
#include "interface.h"
 
25
#include "io/sys.h"
 
26
#include "path-prefix.h"
 
27
#include "preferences.h"
 
28
 
 
29
#ifdef WITH_GNOME_VFS
 
30
# include <libgnomevfs/gnome-vfs.h>
 
31
#endif
 
32
 
 
33
//Routines from file.cpp
 
34
#undef INK_DUMP_FILENAME_CONV
 
35
 
 
36
#ifdef INK_DUMP_FILENAME_CONV
 
37
void dump_str( const gchar* str, const gchar* prefix );
 
38
void dump_ustr( const Glib::ustring& ustr );
 
39
#endif
 
40
 
 
41
 
 
42
 
 
43
namespace Inkscape
 
44
{
 
45
namespace UI
 
46
{
 
47
namespace Dialog
 
48
{
 
49
 
 
50
 
 
51
 
 
52
 
 
53
 
 
54
//########################################################################
 
55
//### U T I L I T Y
 
56
//########################################################################
 
57
 
 
58
void
 
59
fileDialogExtensionToPattern(Glib::ustring &pattern,
 
60
                      Glib::ustring &extension)
 
61
{
 
62
    for (unsigned int i = 0; i < extension.length(); i++ )
 
63
        {
 
64
        Glib::ustring::value_type ch = extension[i];
 
65
        if ( Glib::Unicode::isalpha(ch) )
 
66
            {
 
67
            pattern += '[';
 
68
            pattern += Glib::Unicode::toupper(ch);
 
69
            pattern += Glib::Unicode::tolower(ch);
 
70
            pattern += ']';
 
71
            }
 
72
        else
 
73
            {
 
74
            pattern += ch;
 
75
            }
 
76
        }
 
77
}
 
78
 
 
79
 
 
80
void
 
81
findEntryWidgets(Gtk::Container *parent,
 
82
                 std::vector<Gtk::Entry *> &result)
 
83
{
 
84
    if (!parent)
 
85
        return;
 
86
    std::vector<Gtk::Widget *> children = parent->get_children();
 
87
    for (unsigned int i=0; i<children.size() ; i++)
 
88
        {
 
89
        Gtk::Widget *child = children[i];
 
90
        GtkWidget *wid = child->gobj();
 
91
        if (GTK_IS_ENTRY(wid))
 
92
           result.push_back((Gtk::Entry *)child);
 
93
        else if (GTK_IS_CONTAINER(wid))
 
94
            findEntryWidgets((Gtk::Container *)child, result);
 
95
        }
 
96
 
 
97
}
 
98
 
 
99
void
 
100
findExpanderWidgets(Gtk::Container *parent,
 
101
                    std::vector<Gtk::Expander *> &result)
 
102
{
 
103
    if (!parent)
 
104
        return;
 
105
    std::vector<Gtk::Widget *> children = parent->get_children();
 
106
    for (unsigned int i=0; i<children.size() ; i++)
 
107
        {
 
108
        Gtk::Widget *child = children[i];
 
109
        GtkWidget *wid = child->gobj();
 
110
        if (GTK_IS_EXPANDER(wid))
 
111
           result.push_back((Gtk::Expander *)child);
 
112
        else if (GTK_IS_CONTAINER(wid))
 
113
            findExpanderWidgets((Gtk::Container *)child, result);
 
114
        }
 
115
 
 
116
}
 
117
 
 
118
 
 
119
/*#########################################################################
 
120
### SVG Preview Widget
 
121
#########################################################################*/
 
122
 
 
123
bool SVGPreview::setDocument(SPDocument *doc)
 
124
{
 
125
    if (document)
 
126
        sp_document_unref(document);
 
127
 
 
128
    sp_document_ref(doc);
 
129
    document = doc;
 
130
 
 
131
    //This should remove it from the box, and free resources
 
132
    if (viewerGtk)
 
133
        gtk_widget_destroy(viewerGtk);
 
134
 
 
135
    viewerGtk  = sp_svg_view_widget_new(doc);
 
136
    GtkWidget *vbox = (GtkWidget *)gobj();
 
137
    gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);
 
138
    gtk_widget_show(viewerGtk);
 
139
 
 
140
    return true;
 
141
}
 
142
 
 
143
 
 
144
bool SVGPreview::setFileName(Glib::ustring &theFileName)
 
145
{
 
146
    Glib::ustring fileName = theFileName;
 
147
 
 
148
    fileName = Glib::filename_to_utf8(fileName);
 
149
 
 
150
    /**
 
151
     * I don't know why passing false to keepalive is bad.  But it
 
152
     * prevents the display of an svg with a non-ascii filename
 
153
     */
 
154
    SPDocument *doc = sp_document_new (fileName.c_str(), true);
 
155
    if (!doc) {
 
156
        g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
 
157
        return false;
 
158
    }
 
159
 
 
160
    setDocument(doc);
 
161
 
 
162
    sp_document_unref(doc);
 
163
 
 
164
    return true;
 
165
}
 
166
 
 
167
 
 
168
 
 
169
bool SVGPreview::setFromMem(char const *xmlBuffer)
 
170
{
 
171
    if (!xmlBuffer)
 
172
        return false;
 
173
 
 
174
    gint len = (gint)strlen(xmlBuffer);
 
175
    SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);
 
176
    if (!doc) {
 
177
        g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);
 
178
        return false;
 
179
    }
 
180
 
 
181
    setDocument(doc);
 
182
 
 
183
    sp_document_unref(doc);
 
184
 
 
185
    Inkscape::GC::request_early_collection();
 
186
 
 
187
    return true;
 
188
}
 
189
 
 
190
 
 
191
 
 
192
void SVGPreview::showImage(Glib::ustring &theFileName)
 
193
{
 
194
    Glib::ustring fileName = theFileName;
 
195
 
 
196
 
 
197
    /*#####################################
 
198
    # LET'S HAVE SOME FUN WITH SVG!
 
199
    # Instead of just loading an image, why
 
200
    # don't we make a lovely little svg and
 
201
    # display it nicely?
 
202
    #####################################*/
 
203
 
 
204
    //Arbitrary size of svg doc -- rather 'portrait' shaped
 
205
    gint previewWidth  = 400;
 
206
    gint previewHeight = 600;
 
207
 
 
208
    //Get some image info. Smart pointer does not need to be deleted
 
209
    Glib::RefPtr<Gdk::Pixbuf> img(NULL);
 
210
    try {
 
211
        img = Gdk::Pixbuf::create_from_file(fileName);
 
212
    }
 
213
    catch (const Glib::FileError & e)
 
214
    {
 
215
        g_message("caught Glib::FileError in SVGPreview::showImage");
 
216
        return;
 
217
    }
 
218
    catch (const Gdk::PixbufError & e)
 
219
    {
 
220
        g_message("Gdk::PixbufError in SVGPreview::showImage");
 
221
        return;
 
222
    }
 
223
    catch (...)
 
224
    {
 
225
        g_message("Caught ... in SVGPreview::showImage");
 
226
        return;
 
227
    }
 
228
 
 
229
    gint imgWidth  = img->get_width();
 
230
    gint imgHeight = img->get_height();
 
231
 
 
232
    //Find the minimum scale to fit the image inside the preview area
 
233
    double scaleFactorX = (0.9 *(double)previewWidth)  / ((double)imgWidth);
 
234
    double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);
 
235
    double scaleFactor = scaleFactorX;
 
236
    if (scaleFactorX > scaleFactorY)
 
237
        scaleFactor = scaleFactorY;
 
238
 
 
239
    //Now get the resized values
 
240
    gint scaledImgWidth  = (int) (scaleFactor * (double)imgWidth);
 
241
    gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);
 
242
 
 
243
    //center the image on the area
 
244
    gint imgX = (previewWidth  - scaledImgWidth)  / 2;
 
245
    gint imgY = (previewHeight - scaledImgHeight) / 2;
 
246
 
 
247
    //wrap a rectangle around the image
 
248
    gint rectX      = imgX-1;
 
249
    gint rectY      = imgY-1;
 
250
    gint rectWidth  = scaledImgWidth +2;
 
251
    gint rectHeight = scaledImgHeight+2;
 
252
 
 
253
    //Our template.  Modify to taste
 
254
    gchar const *xformat =
 
255
          "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 
256
          "<svg\n"
 
257
          "xmlns=\"http://www.w3.org/2000/svg\"\n"
 
258
          "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
 
259
          "width=\"%d\" height=\"%d\">\n"  //# VALUES HERE
 
260
          "<rect\n"
 
261
          "  style=\"fill:#eeeeee;stroke:none\"\n"
 
262
          "  x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
 
263
          "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
 
264
          "xlink:href=\"%s\"/>\n"
 
265
          "<rect\n"
 
266
          "  style=\"fill:none;"
 
267
          "    stroke:#000000;stroke-width:1.0;"
 
268
          "    stroke-linejoin:miter;stroke-opacity:1.0000000;"
 
269
          "    stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
 
270
          "  x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
 
271
          "<text\n"
 
272
          "  style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
 
273
          "    fill:#000000;fill-opacity:1.0000000;stroke:none;"
 
274
          "    font-family:Bitstream Vera Sans\"\n"
 
275
          "  x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
 
276
          "</svg>\n\n";
 
277
 
 
278
    //if (!Glib::get_charset()) //If we are not utf8
 
279
    fileName = Glib::filename_to_utf8(fileName);
 
280
 
 
281
    //Fill in the template
 
282
    /* FIXME: Do proper XML quoting for fileName. */
 
283
    gchar *xmlBuffer = g_strdup_printf(xformat,
 
284
           previewWidth, previewHeight,
 
285
           imgX, imgY, scaledImgWidth, scaledImgHeight,
 
286
           fileName.c_str(),
 
287
           rectX, rectY, rectWidth, rectHeight,
 
288
           imgWidth, imgHeight);
 
289
 
 
290
    //g_message("%s\n", xmlBuffer);
 
291
 
 
292
    //now show it!
 
293
    setFromMem(xmlBuffer);
 
294
    g_free(xmlBuffer);
 
295
}
 
296
 
 
297
 
 
298
 
 
299
void SVGPreview::showNoPreview()
 
300
{
 
301
    //Are we already showing it?
 
302
    if (showingNoPreview)
 
303
        return;
 
304
 
 
305
    //Arbitrary size of svg doc -- rather 'portrait' shaped
 
306
    gint previewWidth  = 300;
 
307
    gint previewHeight = 600;
 
308
 
 
309
    //Our template.  Modify to taste
 
310
    gchar const *xformat =
 
311
          "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 
312
          "<svg\n"
 
313
          "xmlns=\"http://www.w3.org/2000/svg\"\n"
 
314
          "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
 
315
          "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
 
316
          "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
 
317
          "<path\n"
 
318
          "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
 
319
          "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
 
320
          "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
 
321
          "id=\"whiteSpace\" />\n"
 
322
          "<path\n"
 
323
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
324
          "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
 
325
          "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
 
326
          "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
 
327
          "id=\"droplet01\" />\n"
 
328
          "<path\n"
 
329
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
330
          "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
 
331
          "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
 
332
          "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
 
333
          "287.18046 343.1206 286.46194 340.42914 z \"\n"
 
334
          "id=\"droplet02\" />\n"
 
335
          "<path\n"
 
336
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
337
          "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
 
338
          "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
 
339
          "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
 
340
          "id=\"droplet03\" />\n"
 
341
          "<path\n"
 
342
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
343
          "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
 
344
          "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
 
345
          "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
 
346
          "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
 
347
          "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
 
348
          "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
 
349
          "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
 
350
          "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
 
351
          "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
 
352
          "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
 
353
          "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
 
354
          "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
 
355
          "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
 
356
          "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
 
357
          "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
 
358
          "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
 
359
          "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
 
360
          "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
 
361
          "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
 
362
          "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
 
363
          "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
 
364
          "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
 
365
          "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
 
366
          "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
 
367
          "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
 
368
          "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
 
369
          "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
 
370
          "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
 
371
          "id=\"mountainDroplet\" />\n"
 
372
          "</g> <g transform=\"translate(-20,0)\">\n"
 
373
          "<text xml:space=\"preserve\"\n"
 
374
          "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
 
375
          "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
 
376
          "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
 
377
          "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
 
378
          "x=\"190\" y=\"240\">%s</text></g>\n"  //# VALUE HERE
 
379
          "</svg>\n\n";
 
380
 
 
381
    //Fill in the template
 
382
    gchar *xmlBuffer = g_strdup_printf(xformat,
 
383
           previewWidth, previewHeight, _("No preview"));
 
384
 
 
385
    //g_message("%s\n", xmlBuffer);
 
386
 
 
387
    //now show it!
 
388
    setFromMem(xmlBuffer);
 
389
    g_free(xmlBuffer);
 
390
    showingNoPreview = true;
 
391
 
 
392
}
 
393
 
 
394
 
 
395
/**
 
396
 * Inform the user that the svg file is too large to be displayed.
 
397
 * This does not check for sizes of embedded images (yet)
 
398
 */
 
399
void SVGPreview::showTooLarge(long fileLength)
 
400
{
 
401
 
 
402
    //Arbitrary size of svg doc -- rather 'portrait' shaped
 
403
    gint previewWidth  = 300;
 
404
    gint previewHeight = 600;
 
405
 
 
406
    //Our template.  Modify to taste
 
407
    gchar const *xformat =
 
408
          "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 
409
          "<svg\n"
 
410
          "xmlns=\"http://www.w3.org/2000/svg\"\n"
 
411
          "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
 
412
          "width=\"%d\" height=\"%d\">\n"  //# VALUES HERE
 
413
          "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
 
414
          "<path\n"
 
415
          "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
 
416
          "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
 
417
          "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
 
418
          "id=\"whiteSpace\" />\n"
 
419
          "<path\n"
 
420
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
421
          "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
 
422
          "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
 
423
          "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
 
424
          "id=\"droplet01\" />\n"
 
425
          "<path\n"
 
426
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
427
          "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
 
428
          "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
 
429
          "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
 
430
          "287.18046 343.1206 286.46194 340.42914 z \"\n"
 
431
          "id=\"droplet02\" />\n"
 
432
          "<path\n"
 
433
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
434
          "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
 
435
          "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
 
436
          "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
 
437
          "id=\"droplet03\" />\n"
 
438
          "<path\n"
 
439
          "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
 
440
          "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
 
441
          "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
 
442
          "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
 
443
          "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
 
444
          "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
 
445
          "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
 
446
          "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
 
447
          "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
 
448
          "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
 
449
          "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
 
450
          "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
 
451
          "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
 
452
          "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
 
453
          "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
 
454
          "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
 
455
          "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
 
456
          "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
 
457
          "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
 
458
          "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
 
459
          "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
 
460
          "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
 
461
          "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
 
462
          "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
 
463
          "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
 
464
          "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
 
465
          "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
 
466
          "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
 
467
          "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
 
468
          "id=\"mountainDroplet\" />\n"
 
469
          "</g>\n"
 
470
          "<text xml:space=\"preserve\"\n"
 
471
          "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
 
472
          "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
 
473
          "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
 
474
          "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
 
475
          "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE
 
476
          "<text xml:space=\"preserve\"\n"
 
477
          "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
 
478
          "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
 
479
          "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
 
480
          "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
 
481
          "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE
 
482
          "</svg>\n\n";
 
483
 
 
484
    //Fill in the template
 
485
    double floatFileLength = ((double)fileLength) / 1048576.0;
 
486
    //printf("%ld %f\n", fileLength, floatFileLength);
 
487
    gchar *xmlBuffer = g_strdup_printf(xformat,
 
488
           previewWidth, previewHeight, floatFileLength,
 
489
           _("too large for preview"));
 
490
 
 
491
    //g_message("%s\n", xmlBuffer);
 
492
 
 
493
    //now show it!
 
494
    setFromMem(xmlBuffer);
 
495
    g_free(xmlBuffer);
 
496
 
 
497
}
 
498
 
 
499
bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
 
500
{
 
501
 
 
502
    if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
 
503
        return false;
 
504
 
 
505
    //g_message("fname:%s", fileName.c_str());
 
506
 
 
507
    if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
 
508
        showNoPreview();
 
509
        return false;
 
510
    }
 
511
 
 
512
    if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
 
513
        {
 
514
        Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);
 
515
        gchar *fName = (gchar *)fileNameUtf8.c_str();
 
516
        struct stat info;
 
517
        if (g_stat(fName, &info))
 
518
            {
 
519
            g_warning("SVGPreview::set() : %s : %s",
 
520
                           fName, strerror(errno));
 
521
            return FALSE;
 
522
            }
 
523
        long fileLen = info.st_size;
 
524
        if (fileLen > 0x150000L)
 
525
            {
 
526
            showingNoPreview = false;
 
527
            showTooLarge(fileLen);
 
528
            return FALSE;
 
529
            }
 
530
        }
 
531
 
 
532
    Glib::ustring svg = ".svg";
 
533
    Glib::ustring svgz = ".svgz";
 
534
 
 
535
    if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
 
536
           (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz)   )
 
537
        ) {
 
538
        bool retval = setFileName(fileName);
 
539
        showingNoPreview = false;
 
540
        return retval;
 
541
    } else if (isValidImageFile(fileName)) {
 
542
        showImage(fileName);
 
543
        showingNoPreview = false;
 
544
        return true;
 
545
    } else {
 
546
        showNoPreview();
 
547
        return false;
 
548
    }
 
549
}
 
550
 
 
551
 
 
552
SVGPreview::SVGPreview()
 
553
{
 
554
    if (!INKSCAPE)
 
555
        inkscape_application_init("",false);
 
556
    document = NULL;
 
557
    viewerGtk = NULL;
 
558
    set_size_request(150,150);
 
559
    showingNoPreview = false;
 
560
}
 
561
 
 
562
SVGPreview::~SVGPreview()
 
563
{
 
564
 
 
565
}
 
566
 
 
567
 
 
568
/*#########################################################################
 
569
### F I L E     D I A L O G    B A S E    C L A S S
 
570
#########################################################################*/
 
571
 
 
572
void FileDialogBaseGtk::internalSetup()
 
573
{
 
574
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
575
    bool enablePreview = prefs->getBool( preferenceBase + "/enable_preview", true);
 
576
 
 
577
    previewCheckbox.set_label( Glib::ustring(_("Enable preview")) );
 
578
    previewCheckbox.set_active( enablePreview );
 
579
 
 
580
    previewCheckbox.signal_toggled().connect(
 
581
        sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB) );
 
582
 
 
583
    //Catch selection-changed events, so we can adjust the text widget
 
584
    signal_update_preview().connect(
 
585
         sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback) );
 
586
 
 
587
    //###### Add a preview widget
 
588
    set_preview_widget(svgPreview);
 
589
    set_preview_widget_active( enablePreview );
 
590
    set_use_preview_label (false);
 
591
 
 
592
}
 
593
 
 
594
 
 
595
void FileDialogBaseGtk::cleanup( bool showConfirmed )
 
596
{
 
597
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
598
    if ( showConfirmed )
 
599
        prefs->setBool( preferenceBase + "/enable_preview", previewCheckbox.get_active() );
 
600
}
 
601
 
 
602
 
 
603
void FileDialogBaseGtk::_previewEnabledCB()
 
604
{
 
605
    bool enabled = previewCheckbox.get_active();
 
606
    set_preview_widget_active(enabled);
 
607
    if ( enabled ) {
 
608
        _updatePreviewCallback();
 
609
    }
 
610
}
 
611
 
 
612
 
 
613
 
 
614
/**
 
615
 * Callback for checking if the preview needs to be redrawn
 
616
 */
 
617
void FileDialogBaseGtk::_updatePreviewCallback()
 
618
{
 
619
    Glib::ustring fileName = get_preview_filename();
 
620
 
 
621
#ifdef WITH_GNOME_VFS
 
622
    if ( fileName.empty() && gnome_vfs_initialized() ) {
 
623
        fileName = get_preview_uri();
 
624
    }
 
625
#endif
 
626
 
 
627
    if (fileName.empty()) {
 
628
        return;
 
629
    }
 
630
 
 
631
    svgPreview.set(fileName, _dialogType);
 
632
}
 
633
 
 
634
 
 
635
/*#########################################################################
 
636
### F I L E    O P E N
 
637
#########################################################################*/
 
638
 
 
639
/**
 
640
 * Constructor.  Not called directly.  Use the factory.
 
641
 */
 
642
FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow,
 
643
                                       const Glib::ustring &dir,
 
644
                                       FileDialogType fileTypes,
 
645
                                       const Glib::ustring &title) :
 
646
    FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_OPEN, fileTypes, "/dialogs/open")
 
647
{
 
648
 
 
649
 
 
650
    /* One file at a time */
 
651
    /* And also Multiple Files */
 
652
    set_select_multiple(true);
 
653
 
 
654
#ifdef WITH_GNOME_VFS
 
655
    if (gnome_vfs_initialized()) {
 
656
        set_local_only(false);
 
657
    }
 
658
#endif
 
659
 
 
660
    /* Initalize to Autodetect */
 
661
    extension = NULL;
 
662
    /* No filename to start out with */
 
663
    myFilename = "";
 
664
 
 
665
    /* Set our dialog type (open, import, etc...)*/
 
666
    _dialogType = fileTypes;
 
667
 
 
668
 
 
669
    /* Set the pwd and/or the filename */
 
670
    if (dir.size() > 0)
 
671
        {
 
672
        Glib::ustring udir(dir);
 
673
        Glib::ustring::size_type len = udir.length();
 
674
        // leaving a trailing backslash on the directory name leads to the infamous
 
675
        // double-directory bug on win32
 
676
        if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
 
677
        set_current_folder(udir.c_str());
 
678
        }
 
679
 
 
680
 
 
681
    set_extra_widget( previewCheckbox );
 
682
 
 
683
 
 
684
    //###### Add the file types menu
 
685
    createFilterMenu();
 
686
 
 
687
    add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 
688
    set_default(*add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK));
 
689
 
 
690
    //###### Allow easy access to our examples folder
 
691
    if ( Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_EXISTS)
 
692
         && Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_IS_DIR)
 
693
         && g_path_is_absolute(INKSCAPE_EXAMPLESDIR)
 
694
        )
 
695
    {
 
696
        add_shortcut_folder(INKSCAPE_EXAMPLESDIR);
 
697
    }
 
698
}
 
699
 
 
700
/**
 
701
 * Destructor
 
702
 */
 
703
FileOpenDialogImplGtk::~FileOpenDialogImplGtk()
 
704
{
 
705
 
 
706
}
 
707
 
 
708
void FileOpenDialogImplGtk::createFilterMenu()
 
709
{
 
710
    Gtk::FileFilter allInkscapeFilter;
 
711
    allInkscapeFilter.set_name(_("All Inkscape Files"));
 
712
    extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
 
713
    add_filter(allInkscapeFilter);
 
714
 
 
715
    Gtk::FileFilter allFilter;
 
716
    allFilter.set_name(_("All Files"));
 
717
    extensionMap[Glib::ustring(_("All Files"))]=NULL;
 
718
    allFilter.add_pattern("*");
 
719
    add_filter(allFilter);
 
720
 
 
721
    Gtk::FileFilter allImageFilter;
 
722
    allImageFilter.set_name(_("All Images"));
 
723
    extensionMap[Glib::ustring(_("All Images"))]=NULL;
 
724
    add_filter(allImageFilter);
 
725
 
 
726
    Gtk::FileFilter allVectorFilter;
 
727
    allVectorFilter.set_name(_("All Vectors"));
 
728
    extensionMap[Glib::ustring(_("All Vectors"))]=NULL;
 
729
    add_filter(allVectorFilter);
 
730
 
 
731
    Gtk::FileFilter allBitmapFilter;
 
732
    allBitmapFilter.set_name(_("All Bitmaps"));
 
733
    extensionMap[Glib::ustring(_("All Bitmaps"))]=NULL;
 
734
    add_filter(allBitmapFilter);
 
735
 
 
736
    //patterns added dynamically below
 
737
    Inkscape::Extension::DB::InputList extension_list;
 
738
    Inkscape::Extension::db.get_input_list(extension_list);
 
739
 
 
740
    for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
 
741
         current_item != extension_list.end(); current_item++)
 
742
    {
 
743
        Inkscape::Extension::Input * imod = *current_item;
 
744
 
 
745
        // FIXME: would be nice to grey them out instead of not listing them
 
746
        if (imod->deactivated()) continue;
 
747
 
 
748
        Glib::ustring upattern("*");
 
749
        Glib::ustring extension = imod->get_extension();
 
750
        fileDialogExtensionToPattern(upattern, extension);
 
751
 
 
752
        Gtk::FileFilter filter;
 
753
        Glib::ustring uname(_(imod->get_filetypename()));
 
754
        filter.set_name(uname);
 
755
        filter.add_pattern(upattern);
 
756
        add_filter(filter);
 
757
        extensionMap[uname] = imod;
 
758
 
 
759
        //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
 
760
        allInkscapeFilter.add_pattern(upattern);
 
761
        if ( strncmp("image", imod->get_mimetype(), 5)==0 )
 
762
            allImageFilter.add_pattern(upattern);
 
763
 
 
764
        // uncomment this to find out all mime types supported by Inkscape import/open
 
765
        // g_print ("%s\n", imod->get_mimetype());
 
766
 
 
767
        // I don't know of any other way to define "bitmap" formats other than by listing them
 
768
        if ( 
 
769
            strncmp("image/png", imod->get_mimetype(), 9)==0 ||
 
770
            strncmp("image/jpeg", imod->get_mimetype(), 10)==0 ||
 
771
            strncmp("image/gif", imod->get_mimetype(), 9)==0 ||
 
772
            strncmp("image/x-icon", imod->get_mimetype(), 12)==0 ||
 
773
            strncmp("image/x-navi-animation", imod->get_mimetype(), 22)==0 ||
 
774
            strncmp("image/x-cmu-raster", imod->get_mimetype(), 18)==0 ||
 
775
            strncmp("image/x-xpixmap", imod->get_mimetype(), 15)==0 ||
 
776
            strncmp("image/bmp", imod->get_mimetype(), 9)==0 ||
 
777
            strncmp("image/vnd.wap.wbmp", imod->get_mimetype(), 18)==0 ||
 
778
            strncmp("image/tiff", imod->get_mimetype(), 10)==0 ||
 
779
            strncmp("image/x-xbitmap", imod->get_mimetype(), 15)==0 ||
 
780
            strncmp("image/x-tga", imod->get_mimetype(), 11)==0 ||
 
781
            strncmp("image/x-pcx", imod->get_mimetype(), 11)==0 
 
782
           )
 
783
            allBitmapFilter.add_pattern(upattern);
 
784
        else 
 
785
            allVectorFilter.add_pattern(upattern);
 
786
    }
 
787
 
 
788
    return;
 
789
}
 
790
 
 
791
/**
 
792
 * Show this dialog modally.  Return true if user hits [OK]
 
793
 */
 
794
bool
 
795
FileOpenDialogImplGtk::show()
 
796
{
 
797
    set_modal (TRUE);                      //Window
 
798
    sp_transientize((GtkWidget *)gobj());  //Make transient
 
799
    gint b = run();                        //Dialog
 
800
    svgPreview.showNoPreview();
 
801
    hide();
 
802
 
 
803
    if (b == Gtk::RESPONSE_OK)
 
804
        {
 
805
        //This is a hack, to avoid the warning messages that
 
806
        //Gtk::FileChooser::get_filter() returns
 
807
        //should be:  Gtk::FileFilter *filter = get_filter();
 
808
        GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
 
809
        GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
 
810
        if (filter)
 
811
            {
 
812
            //Get which extension was chosen, if any
 
813
            extension = extensionMap[gtk_file_filter_get_name(filter)];
 
814
            }
 
815
        myFilename = get_filename();
 
816
#ifdef WITH_GNOME_VFS
 
817
        if (myFilename.empty() && gnome_vfs_initialized())
 
818
            myFilename = get_uri();
 
819
#endif
 
820
        cleanup( true );
 
821
        return TRUE;
 
822
        }
 
823
    else
 
824
       {
 
825
       cleanup( false );
 
826
       return FALSE;
 
827
       }
 
828
}
 
829
 
 
830
 
 
831
 
 
832
 
 
833
/**
 
834
 * Get the file extension type that was selected by the user. Valid after an [OK]
 
835
 */
 
836
Inkscape::Extension::Extension *
 
837
FileOpenDialogImplGtk::getSelectionType()
 
838
{
 
839
    return extension;
 
840
}
 
841
 
 
842
 
 
843
/**
 
844
 * Get the file name chosen by the user.   Valid after an [OK]
 
845
 */
 
846
Glib::ustring
 
847
FileOpenDialogImplGtk::getFilename (void)
 
848
{
 
849
    return myFilename;
 
850
}
 
851
 
 
852
 
 
853
/**
 
854
 * To Get Multiple filenames selected at-once.
 
855
 */
 
856
std::vector<Glib::ustring>FileOpenDialogImplGtk::getFilenames()
 
857
{
 
858
    std::vector<Glib::ustring> result = get_filenames();
 
859
#ifdef WITH_GNOME_VFS
 
860
    if (result.empty() && gnome_vfs_initialized())
 
861
        result = get_uris();
 
862
#endif
 
863
    return result;
 
864
}
 
865
 
 
866
Glib::ustring FileOpenDialogImplGtk::getCurrentDirectory()
 
867
{
 
868
    return get_current_folder();
 
869
}
 
870
 
 
871
 
 
872
 
 
873
 
 
874
//########################################################################
 
875
//# F I L E    S A V E
 
876
//########################################################################
 
877
 
 
878
/**
 
879
 * Constructor
 
880
 */
 
881
FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow,
 
882
                                              const Glib::ustring &dir,
 
883
                                              FileDialogType fileTypes,
 
884
                                              const Glib::ustring &title,
 
885
                                              const Glib::ustring &/*default_key*/,
 
886
                                              const gchar* docTitle) :
 
887
    FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/save_as")
 
888
{
 
889
    FileSaveDialog::myDocTitle = docTitle;
 
890
 
 
891
    /* One file at a time */
 
892
    set_select_multiple(false);
 
893
 
 
894
#ifdef WITH_GNOME_VFS
 
895
    if (gnome_vfs_initialized()) {
 
896
        set_local_only(false);
 
897
    }
 
898
#endif
 
899
 
 
900
    /* Initalize to Autodetect */
 
901
    extension = NULL;
 
902
    /* No filename to start out with */
 
903
    myFilename = "";
 
904
 
 
905
    /* Set our dialog type (save, export, etc...)*/
 
906
    _dialogType = fileTypes;
 
907
 
 
908
    /* Set the pwd and/or the filename */
 
909
    if (dir.size() > 0)
 
910
        {
 
911
        Glib::ustring udir(dir);
 
912
        Glib::ustring::size_type len = udir.length();
 
913
        // leaving a trailing backslash on the directory name leads to the infamous
 
914
        // double-directory bug on win32
 
915
        if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
 
916
        myFilename = udir;
 
917
        }
 
918
 
 
919
    //###### Add the file types menu
 
920
    //createFilterMenu();
 
921
 
 
922
    //###### Do we want the .xxx extension automatically added?
 
923
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
924
    fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
 
925
    fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_as/append_extension", true));
 
926
 
 
927
    createFileTypeMenu();
 
928
    fileTypeComboBox.set_size_request(200,40);
 
929
    fileTypeComboBox.signal_changed().connect(
 
930
         sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback) );
 
931
 
 
932
 
 
933
    childBox.pack_start( checksBox );
 
934
    childBox.pack_end( fileTypeComboBox );
 
935
    checksBox.pack_start( fileTypeCheckbox );
 
936
    checksBox.pack_start( previewCheckbox );
 
937
 
 
938
    set_extra_widget( childBox );
 
939
 
 
940
    //Let's do some customization
 
941
    fileNameEntry = NULL;
 
942
    Gtk::Container *cont = get_toplevel();
 
943
    std::vector<Gtk::Entry *> entries;
 
944
    findEntryWidgets(cont, entries);
 
945
    //g_message("Found %d entry widgets\n", entries.size());
 
946
    if (entries.size() >=1 )
 
947
        {
 
948
        //Catch when user hits [return] on the text field
 
949
        fileNameEntry = entries[0];
 
950
        fileNameEntry->signal_activate().connect(
 
951
             sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback) );
 
952
        }
 
953
 
 
954
    //Let's do more customization
 
955
    std::vector<Gtk::Expander *> expanders;
 
956
    findExpanderWidgets(cont, expanders);
 
957
    //g_message("Found %d expander widgets\n", expanders.size());
 
958
    if (expanders.size() >=1 )
 
959
        {
 
960
        //Always show the file list
 
961
        Gtk::Expander *expander = expanders[0];
 
962
        expander->set_expanded(true);
 
963
        }
 
964
 
 
965
    // allow easy access to the user's own templates folder
 
966
    gchar *templates = profile_path ("templates");
 
967
    if ( Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS)
 
968
         && Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR)
 
969
         && g_path_is_absolute(templates)
 
970
        )
 
971
    {
 
972
        add_shortcut_folder(templates);
 
973
    }
 
974
    g_free (templates);
 
975
 
 
976
 
 
977
    //if (extension == NULL)
 
978
    //    checkbox.set_sensitive(FALSE);
 
979
 
 
980
    add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 
981
    set_default(*add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK));
 
982
 
 
983
    show_all_children();
 
984
}
 
985
 
 
986
/**
 
987
 * Destructor
 
988
 */
 
989
FileSaveDialogImplGtk::~FileSaveDialogImplGtk()
 
990
{
 
991
}
 
992
 
 
993
/**
 
994
 * Callback for fileNameEntry widget
 
995
 */
 
996
void FileSaveDialogImplGtk::fileNameEntryChangedCallback()
 
997
{
 
998
    if (!fileNameEntry)
 
999
        return;
 
1000
 
 
1001
    Glib::ustring fileName = fileNameEntry->get_text();
 
1002
    if (!Glib::get_charset()) //If we are not utf8
 
1003
        fileName = Glib::filename_to_utf8(fileName);
 
1004
 
 
1005
    //g_message("User hit return.  Text is '%s'\n", fileName.c_str());
 
1006
 
 
1007
    if (!Glib::path_is_absolute(fileName)) {
 
1008
        //try appending to the current path
 
1009
        // not this way: fileName = get_current_folder() + "/" + fileName;
 
1010
        std::vector<Glib::ustring> pathSegments;
 
1011
        pathSegments.push_back( get_current_folder() );
 
1012
        pathSegments.push_back( fileName );
 
1013
        fileName = Glib::build_filename(pathSegments);
 
1014
    }
 
1015
 
 
1016
    //g_message("path:'%s'\n", fileName.c_str());
 
1017
 
 
1018
    if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
 
1019
        set_current_folder(fileName);
 
1020
    } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
 
1021
        //dialog with either (1) select a regular file or (2) cd to dir
 
1022
        //simulate an 'OK'
 
1023
        set_filename(fileName);
 
1024
        response(Gtk::RESPONSE_OK);
 
1025
    }
 
1026
}
 
1027
 
 
1028
 
 
1029
 
 
1030
/**
 
1031
 * Callback for fileNameEntry widget
 
1032
 */
 
1033
void FileSaveDialogImplGtk::fileTypeChangedCallback()
 
1034
{
 
1035
    int sel = fileTypeComboBox.get_active_row_number();
 
1036
    if (sel<0 || sel >= (int)fileTypes.size())
 
1037
        return;
 
1038
    FileType type = fileTypes[sel];
 
1039
    //g_message("selected: %s\n", type.name.c_str());
 
1040
 
 
1041
    extension = type.extension;
 
1042
    Gtk::FileFilter filter;
 
1043
    filter.add_pattern(type.pattern);
 
1044
    set_filter(filter);
 
1045
 
 
1046
    updateNameAndExtension();
 
1047
}
 
1048
 
 
1049
 
 
1050
 
 
1051
void FileSaveDialogImplGtk::createFileTypeMenu()
 
1052
{
 
1053
    Inkscape::Extension::DB::OutputList extension_list;
 
1054
    Inkscape::Extension::db.get_output_list(extension_list);
 
1055
    knownExtensions.clear();
 
1056
 
 
1057
    for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
 
1058
         current_item != extension_list.end(); current_item++)
 
1059
    {
 
1060
        Inkscape::Extension::Output * omod = *current_item;
 
1061
 
 
1062
        // FIXME: would be nice to grey them out instead of not listing them
 
1063
        if (omod->deactivated()) continue;
 
1064
 
 
1065
        FileType type;
 
1066
        type.name     = (_(omod->get_filetypename()));
 
1067
        type.pattern  = "*";
 
1068
        Glib::ustring extension = omod->get_extension();
 
1069
        knownExtensions.insert( extension.casefold() );
 
1070
        fileDialogExtensionToPattern (type.pattern, extension);
 
1071
        type.extension= omod;
 
1072
        fileTypeComboBox.append_text(type.name);
 
1073
        fileTypes.push_back(type);
 
1074
    }
 
1075
 
 
1076
    //#Let user choose
 
1077
    FileType guessType;
 
1078
    guessType.name = _("Guess from extension");
 
1079
    guessType.pattern = "*";
 
1080
    guessType.extension = NULL;
 
1081
    fileTypeComboBox.append_text(guessType.name);
 
1082
    fileTypes.push_back(guessType);
 
1083
 
 
1084
 
 
1085
    fileTypeComboBox.set_active(0);
 
1086
    fileTypeChangedCallback(); //call at least once to set the filter
 
1087
}
 
1088
 
 
1089
 
 
1090
 
 
1091
 
 
1092
 
 
1093
/**
 
1094
 * Show this dialog modally.  Return true if user hits [OK]
 
1095
 */
 
1096
bool
 
1097
FileSaveDialogImplGtk::show()
 
1098
{
 
1099
    change_path(myFilename);
 
1100
    set_modal (TRUE);                      //Window
 
1101
    sp_transientize((GtkWidget *)gobj());  //Make transient
 
1102
    gint b = run();                        //Dialog
 
1103
    svgPreview.showNoPreview();
 
1104
    set_preview_widget_active(false);
 
1105
    hide();
 
1106
 
 
1107
    if (b == Gtk::RESPONSE_OK) {
 
1108
        updateNameAndExtension();
 
1109
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
1110
        
 
1111
        // Store changes of the "Append filename automatically" checkbox back to preferences.
 
1112
        prefs->setBool("/dialogs/save_as/append_extension", fileTypeCheckbox.get_active());
 
1113
 
 
1114
        // Store the last used save-as filetype to preferences.
 
1115
        prefs->setString("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" ));
 
1116
 
 
1117
        cleanup( true );
 
1118
 
 
1119
        return TRUE;
 
1120
    } else {
 
1121
        cleanup( false );
 
1122
        return FALSE;
 
1123
    }
 
1124
}
 
1125
 
 
1126
 
 
1127
/**
 
1128
 * Get the file extension type that was selected by the user. Valid after an [OK]
 
1129
 */
 
1130
Inkscape::Extension::Extension *
 
1131
FileSaveDialogImplGtk::getSelectionType()
 
1132
{
 
1133
    return extension;
 
1134
}
 
1135
 
 
1136
void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * key )
 
1137
{
 
1138
    // If no pointer to extension is passed in, look up based on filename extension.
 
1139
    if ( !key ) {
 
1140
        // Not quite UTF-8 here.
 
1141
        gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
 
1142
        for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
 
1143
            Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
 
1144
            if ( ext && ext->get_extension() ) {
 
1145
                gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
 
1146
                if ( g_str_has_suffix(filenameLower, extensionLower) ) {
 
1147
                    key = fileTypes[i].extension;
 
1148
                }
 
1149
                g_free(extensionLower);
 
1150
            }
 
1151
        }
 
1152
        g_free(filenameLower);
 
1153
    }
 
1154
 
 
1155
    // Ensure the proper entry in the combo box is selected.
 
1156
    if ( key ) {
 
1157
        extension = key;
 
1158
        gchar const * extensionID = extension->get_id();
 
1159
        if ( extensionID ) {
 
1160
            for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
 
1161
                Inkscape::Extension::Extension *ext = fileTypes[i].extension;
 
1162
                if ( ext ) {
 
1163
                    gchar const * id = ext->get_id();
 
1164
                    if ( id && ( strcmp(extensionID, id) == 0) ) {
 
1165
                        int oldSel = fileTypeComboBox.get_active_row_number();
 
1166
                        if ( i != oldSel ) {
 
1167
                            fileTypeComboBox.set_active(i);
 
1168
                        }
 
1169
                        break;
 
1170
                    }
 
1171
                }
 
1172
            }
 
1173
        }
 
1174
    }
 
1175
}
 
1176
 
 
1177
Glib::ustring FileSaveDialogImplGtk::getCurrentDirectory()
 
1178
{
 
1179
    return get_current_folder();
 
1180
}
 
1181
 
 
1182
 
 
1183
/*void
 
1184
FileSaveDialogImplGtk::change_title(const Glib::ustring& title)
 
1185
{
 
1186
    set_title(title);
 
1187
}*/
 
1188
 
 
1189
/**
 
1190
  * Change the default save path location.
 
1191
  */
 
1192
void
 
1193
FileSaveDialogImplGtk::change_path(const Glib::ustring& path)
 
1194
{
 
1195
    myFilename = path;
 
1196
 
 
1197
    if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
 
1198
        //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
 
1199
        set_current_folder(myFilename);
 
1200
    } else {
 
1201
        //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
 
1202
        if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
 
1203
            set_filename(myFilename);
 
1204
        } else {
 
1205
            std::string dirName = Glib::path_get_dirname( myFilename  );
 
1206
            if ( dirName != get_current_folder() ) {
 
1207
                set_current_folder(dirName);
 
1208
            }
 
1209
        }
 
1210
        Glib::ustring basename = Glib::path_get_basename(myFilename);
 
1211
        //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
 
1212
        try {
 
1213
            set_current_name( Glib::filename_to_utf8(basename) );
 
1214
        } catch ( Glib::ConvertError& e ) {
 
1215
            g_warning( "Error converting save filename to UTF-8." );
 
1216
            // try a fallback.
 
1217
            set_current_name( basename );
 
1218
        }
 
1219
    }
 
1220
}
 
1221
 
 
1222
void FileSaveDialogImplGtk::updateNameAndExtension()
 
1223
{
 
1224
    // Pick up any changes the user has typed in.
 
1225
    Glib::ustring tmp = get_filename();
 
1226
#ifdef WITH_GNOME_VFS
 
1227
    if ( tmp.empty() && gnome_vfs_initialized() ) {
 
1228
        tmp = get_uri();
 
1229
    }
 
1230
#endif
 
1231
    if ( !tmp.empty() ) {
 
1232
        myFilename = tmp;
 
1233
    }
 
1234
 
 
1235
    Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
 
1236
    if ( fileTypeCheckbox.get_active() && newOut ) {
 
1237
        // Append the file extension if it's not already present
 
1238
        appendExtension(myFilename, newOut);
 
1239
    }
 
1240
}
 
1241
 
 
1242
 
 
1243
//########################################################################
 
1244
//# F I L E     E X P O R T
 
1245
//########################################################################
 
1246
 
 
1247
/**
 
1248
 * Callback for fileNameEntry widget
 
1249
 */
 
1250
void FileExportDialogImpl::fileNameEntryChangedCallback()
 
1251
{
 
1252
    if (!fileNameEntry)
 
1253
        return;
 
1254
 
 
1255
    Glib::ustring fileName = fileNameEntry->get_text();
 
1256
    if (!Glib::get_charset()) //If we are not utf8
 
1257
        fileName = Glib::filename_to_utf8(fileName);
 
1258
 
 
1259
    //g_message("User hit return.  Text is '%s'\n", fileName.c_str());
 
1260
 
 
1261
    if (!Glib::path_is_absolute(fileName)) {
 
1262
        //try appending to the current path
 
1263
        // not this way: fileName = get_current_folder() + "/" + fileName;
 
1264
        std::vector<Glib::ustring> pathSegments;
 
1265
        pathSegments.push_back( get_current_folder() );
 
1266
        pathSegments.push_back( fileName );
 
1267
        fileName = Glib::build_filename(pathSegments);
 
1268
    }
 
1269
 
 
1270
    //g_message("path:'%s'\n", fileName.c_str());
 
1271
 
 
1272
    if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
 
1273
        set_current_folder(fileName);
 
1274
    } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
 
1275
        //dialog with either (1) select a regular file or (2) cd to dir
 
1276
        //simulate an 'OK'
 
1277
        set_filename(fileName);
 
1278
        response(Gtk::RESPONSE_OK);
 
1279
    }
 
1280
}
 
1281
 
 
1282
 
 
1283
 
 
1284
/**
 
1285
 * Callback for fileNameEntry widget
 
1286
 */
 
1287
void FileExportDialogImpl::fileTypeChangedCallback()
 
1288
{
 
1289
    int sel = fileTypeComboBox.get_active_row_number();
 
1290
    if (sel<0 || sel >= (int)fileTypes.size())
 
1291
        return;
 
1292
    FileType type = fileTypes[sel];
 
1293
    //g_message("selected: %s\n", type.name.c_str());
 
1294
    Gtk::FileFilter filter;
 
1295
    filter.add_pattern(type.pattern);
 
1296
    set_filter(filter);
 
1297
}
 
1298
 
 
1299
 
 
1300
 
 
1301
void FileExportDialogImpl::createFileTypeMenu()
 
1302
{
 
1303
    Inkscape::Extension::DB::OutputList extension_list;
 
1304
    Inkscape::Extension::db.get_output_list(extension_list);
 
1305
 
 
1306
    for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
 
1307
         current_item != extension_list.end(); current_item++)
 
1308
    {
 
1309
        Inkscape::Extension::Output * omod = *current_item;
 
1310
 
 
1311
        // FIXME: would be nice to grey them out instead of not listing them
 
1312
        if (omod->deactivated()) continue;
 
1313
 
 
1314
        FileType type;
 
1315
        type.name     = (_(omod->get_filetypename()));
 
1316
        type.pattern  = "*";
 
1317
        Glib::ustring extension = omod->get_extension();
 
1318
        fileDialogExtensionToPattern (type.pattern, extension);
 
1319
        type.extension= omod;
 
1320
        fileTypeComboBox.append_text(type.name);
 
1321
        fileTypes.push_back(type);
 
1322
    }
 
1323
 
 
1324
    //#Let user choose
 
1325
    FileType guessType;
 
1326
    guessType.name = _("Guess from extension");
 
1327
    guessType.pattern = "*";
 
1328
    guessType.extension = NULL;
 
1329
    fileTypeComboBox.append_text(guessType.name);
 
1330
    fileTypes.push_back(guessType);
 
1331
 
 
1332
 
 
1333
    fileTypeComboBox.set_active(0);
 
1334
    fileTypeChangedCallback(); //call at least once to set the filter
 
1335
}
 
1336
 
 
1337
 
 
1338
/**
 
1339
 * Constructor
 
1340
 */
 
1341
FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow,
 
1342
                                            const Glib::ustring &dir,
 
1343
                                            FileDialogType fileTypes,
 
1344
                                            const Glib::ustring &title,
 
1345
                                            const Glib::ustring &/*default_key*/ ) :
 
1346
            FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/export"),
 
1347
            sourceX0Spinner("X0",         _("Left edge of source")),
 
1348
            sourceY0Spinner("Y0",         _("Top edge of source")),
 
1349
            sourceX1Spinner("X1",         _("Right edge of source")),
 
1350
            sourceY1Spinner("Y1",         _("Bottom edge of source")),
 
1351
            sourceWidthSpinner("Width",   _("Source width")),
 
1352
            sourceHeightSpinner("Height", _("Source height")),
 
1353
            destWidthSpinner("Width",     _("Destination width")),
 
1354
            destHeightSpinner("Height",   _("Destination height")),
 
1355
            destDPISpinner("DPI",         _("Resolution (dots per inch)"))
 
1356
{
 
1357
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
1358
    append_extension = prefs->getBool("/dialogs/save_as/append_extension", true);
 
1359
 
 
1360
    /* One file at a time */
 
1361
    set_select_multiple(false);
 
1362
 
 
1363
#ifdef WITH_GNOME_VFS
 
1364
    if (gnome_vfs_initialized()) {
 
1365
        set_local_only(false);
 
1366
    }
 
1367
#endif
 
1368
 
 
1369
    /* Initalize to Autodetect */
 
1370
    extension = NULL;
 
1371
    /* No filename to start out with */
 
1372
    myFilename = "";
 
1373
 
 
1374
    /* Set our dialog type (save, export, etc...)*/
 
1375
    _dialogType = fileTypes;
 
1376
 
 
1377
    /* Set the pwd and/or the filename */
 
1378
    if (dir.size()>0)
 
1379
        {
 
1380
        Glib::ustring udir(dir);
 
1381
        Glib::ustring::size_type len = udir.length();
 
1382
        // leaving a trailing backslash on the directory name leads to the infamous
 
1383
        // double-directory bug on win32
 
1384
        if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
 
1385
        set_current_folder(udir.c_str());
 
1386
        }
 
1387
 
 
1388
    //#########################################
 
1389
    //## EXTRA WIDGET -- SOURCE SIDE
 
1390
    //#########################################
 
1391
 
 
1392
    //##### Export options buttons/spinners, etc
 
1393
    documentButton.set_label(_("Document"));
 
1394
    scopeBox.pack_start(documentButton);
 
1395
    scopeGroup = documentButton.get_group();
 
1396
 
 
1397
    pageButton.set_label(_("Page"));
 
1398
    pageButton.set_group(scopeGroup);
 
1399
    scopeBox.pack_start(pageButton);
 
1400
 
 
1401
    selectionButton.set_label(_("Selection"));
 
1402
    selectionButton.set_group(scopeGroup);
 
1403
    scopeBox.pack_start(selectionButton);
 
1404
 
 
1405
    customButton.set_label(_("Custom"));
 
1406
    customButton.set_group(scopeGroup);
 
1407
    scopeBox.pack_start(customButton);
 
1408
 
 
1409
    sourceBox.pack_start(scopeBox);
 
1410
 
 
1411
 
 
1412
 
 
1413
    //dimension buttons
 
1414
    sourceTable.resize(3,3);
 
1415
    sourceTable.attach(sourceX0Spinner,     0,1,0,1);
 
1416
    sourceTable.attach(sourceY0Spinner,     1,2,0,1);
 
1417
    sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
 
1418
    sourceTable.attach(sourceUnitsSpinner,  2,3,0,1);
 
1419
    sourceTable.attach(sourceX1Spinner,     0,1,1,2);
 
1420
    sourceTable.attach(sourceY1Spinner,     1,2,1,2);
 
1421
    sourceTable.attach(sourceWidthSpinner,  0,1,2,3);
 
1422
    sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
 
1423
 
 
1424
    sourceBox.pack_start(sourceTable);
 
1425
    sourceFrame.set_label(_("Source"));
 
1426
    sourceFrame.add(sourceBox);
 
1427
    exportOptionsBox.pack_start(sourceFrame);
 
1428
 
 
1429
 
 
1430
    //#########################################
 
1431
    //## EXTRA WIDGET -- SOURCE SIDE
 
1432
    //#########################################
 
1433
 
 
1434
 
 
1435
    destTable.resize(3,3);
 
1436
    destTable.attach(destWidthSpinner,    0,1,0,1);
 
1437
    destTable.attach(destHeightSpinner,   1,2,0,1);
 
1438
    destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
 
1439
    destTable.attach(destUnitsSpinner,    2,3,0,1);
 
1440
    destTable.attach(destDPISpinner,      0,1,1,2);
 
1441
 
 
1442
    destBox.pack_start(destTable);
 
1443
 
 
1444
 
 
1445
    cairoButton.set_label(_("Cairo"));
 
1446
    otherOptionBox.pack_start(cairoButton);
 
1447
 
 
1448
    antiAliasButton.set_label(_("Antialias"));
 
1449
    otherOptionBox.pack_start(antiAliasButton);
 
1450
 
 
1451
    backgroundButton.set_label(_("Background"));
 
1452
    otherOptionBox.pack_start(backgroundButton);
 
1453
 
 
1454
    destBox.pack_start(otherOptionBox);
 
1455
 
 
1456
 
 
1457
 
 
1458
 
 
1459
 
 
1460
    //###### File options
 
1461
    //###### Do we want the .xxx extension automatically added?
 
1462
    fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
 
1463
    fileTypeCheckbox.set_active(append_extension);
 
1464
    destBox.pack_start(fileTypeCheckbox);
 
1465
 
 
1466
    //###### File type menu
 
1467
    createFileTypeMenu();
 
1468
    fileTypeComboBox.set_size_request(200,40);
 
1469
    fileTypeComboBox.signal_changed().connect(
 
1470
         sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
 
1471
 
 
1472
    destBox.pack_start(fileTypeComboBox);
 
1473
 
 
1474
    destFrame.set_label(_("Destination"));
 
1475
    destFrame.add(destBox);
 
1476
    exportOptionsBox.pack_start(destFrame);
 
1477
 
 
1478
    //##### Put the two boxes and their parent onto the dialog
 
1479
    exportOptionsBox.pack_start(sourceFrame);
 
1480
    exportOptionsBox.pack_start(destFrame);
 
1481
 
 
1482
    set_extra_widget(exportOptionsBox);
 
1483
 
 
1484
 
 
1485
 
 
1486
 
 
1487
    //Let's do some customization
 
1488
    fileNameEntry = NULL;
 
1489
    Gtk::Container *cont = get_toplevel();
 
1490
    std::vector<Gtk::Entry *> entries;
 
1491
    findEntryWidgets(cont, entries);
 
1492
    //g_message("Found %d entry widgets\n", entries.size());
 
1493
    if (entries.size() >=1 )
 
1494
        {
 
1495
        //Catch when user hits [return] on the text field
 
1496
        fileNameEntry = entries[0];
 
1497
        fileNameEntry->signal_activate().connect(
 
1498
             sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
 
1499
        }
 
1500
 
 
1501
    //Let's do more customization
 
1502
    std::vector<Gtk::Expander *> expanders;
 
1503
    findExpanderWidgets(cont, expanders);
 
1504
    //g_message("Found %d expander widgets\n", expanders.size());
 
1505
    if (expanders.size() >=1 )
 
1506
        {
 
1507
        //Always show the file list
 
1508
        Gtk::Expander *expander = expanders[0];
 
1509
        expander->set_expanded(true);
 
1510
        }
 
1511
 
 
1512
 
 
1513
    //if (extension == NULL)
 
1514
    //    checkbox.set_sensitive(FALSE);
 
1515
 
 
1516
    add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 
1517
    set_default(*add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK));
 
1518
 
 
1519
    show_all_children();
 
1520
}
 
1521
 
 
1522
/**
 
1523
 * Destructor
 
1524
 */
 
1525
FileExportDialogImpl::~FileExportDialogImpl()
 
1526
{
 
1527
}
 
1528
 
 
1529
 
 
1530
 
 
1531
/**
 
1532
 * Show this dialog modally.  Return true if user hits [OK]
 
1533
 */
 
1534
bool
 
1535
FileExportDialogImpl::show()
 
1536
{
 
1537
    Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
 
1538
    if (s.length() == 0)
 
1539
        s = getcwd (NULL, 0);
 
1540
    set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
 
1541
    set_modal (TRUE);                      //Window
 
1542
    sp_transientize((GtkWidget *)gobj());  //Make transient
 
1543
    gint b = run();                        //Dialog
 
1544
    svgPreview.showNoPreview();
 
1545
    hide();
 
1546
 
 
1547
    if (b == Gtk::RESPONSE_OK)
 
1548
        {
 
1549
        int sel = fileTypeComboBox.get_active_row_number ();
 
1550
        if (sel>=0 && sel< (int)fileTypes.size())
 
1551
            {
 
1552
            FileType &type = fileTypes[sel];
 
1553
            extension = type.extension;
 
1554
            }
 
1555
        myFilename = get_filename();
 
1556
#ifdef WITH_GNOME_VFS
 
1557
        if ( myFilename.empty() && gnome_vfs_initialized() ) {
 
1558
            myFilename = get_uri();
 
1559
        }
 
1560
#endif
 
1561
 
 
1562
        /*
 
1563
 
 
1564
        // FIXME: Why do we have more code
 
1565
 
 
1566
        append_extension = checkbox.get_active();
 
1567
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
1568
        prefs->setBool("/dialogs/save_as/append_extension", append_extension);
 
1569
        prefs->setBool("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" ));
 
1570
        */
 
1571
        return TRUE;
 
1572
        }
 
1573
    else
 
1574
        {
 
1575
        return FALSE;
 
1576
        }
 
1577
}
 
1578
 
 
1579
 
 
1580
/**
 
1581
 * Get the file extension type that was selected by the user. Valid after an [OK]
 
1582
 */
 
1583
Inkscape::Extension::Extension *
 
1584
FileExportDialogImpl::getSelectionType()
 
1585
{
 
1586
    return extension;
 
1587
}
 
1588
 
 
1589
 
 
1590
/**
 
1591
 * Get the file name chosen by the user.   Valid after an [OK]
 
1592
 */
 
1593
Glib::ustring
 
1594
FileExportDialogImpl::getFilename()
 
1595
{
 
1596
    return myFilename;
 
1597
}
 
1598
 
 
1599
 
 
1600
} //namespace Dialog
 
1601
} //namespace UI
 
1602
} //namespace Inkscape
 
1603
 
 
1604
/*
 
1605
  Local Variables:
 
1606
  mode:c++
 
1607
  c-file-style:"stroustrup"
 
1608
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
1609
  indent-tabs-mode:nil
 
1610
  fill-column:99
 
1611
  End:
 
1612
*/
 
1613
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :