1 /**
2 * Implementation of the file dialog interfaces defined in filedialog.h
3 *
4 * Authors:
5 * Bob Jamison
6 * Other dudes from The Inkscape Organization
7 *
8 * Copyright (C) 2004-2007 Bob Jamison
9 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
10 * Copyright (C) 2004-2007 The Inkscape Organization
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
20 //General includes
21 #include <unistd.h>
22 #include <sys/stat.h>
23 #include <errno.h>
24 #include <set>
26 //Gtk includes
27 #include <gtkmm.h>
28 #include <glibmm/i18n.h>
29 #include <glib/gstdio.h>
30 //Temporary ugly hack
31 //Remove this after the get_filter() calls in
32 //show() on both classes are fixed
33 #include <gtk/gtkfilechooser.h>
34 //Another hack
35 #include <gtk/gtkentry.h>
36 #include <gtk/gtkexpander.h>
40 //Inkscape includes
41 #include "prefs-utils.h"
42 #include <dialogs/dialog-events.h>
43 #include <extension/input.h>
44 #include <extension/output.h>
45 #include <extension/db.h>
46 #include "inkscape.h"
47 #include "svg-view-widget.h"
48 #include "filedialog.h"
49 #include "gc-core.h"
51 //For export dialog
52 #include "ui/widget/scalar-unit.h"
55 //Routines from file.cpp
56 #undef INK_DUMP_FILENAME_CONV
58 #ifdef INK_DUMP_FILENAME_CONV
59 void dump_str( const gchar* str, const gchar* prefix );
60 void dump_ustr( const Glib::ustring& ustr );
61 #endif
65 namespace Inkscape
66 {
67 namespace UI
68 {
69 namespace Dialog
70 {
76 //########################################################################
77 //### U T I L I T Y
78 //########################################################################
80 /**
81 \brief A quick function to turn a standard extension into a searchable
82 pattern for the file dialogs
83 \param pattern The patter that the extension should be written to
84 \param in_file_extension The C string that represents the extension
86 This function just goes through the string, and takes all characters
87 and puts a [<upper><lower>] so that both are searched and shown in
88 the file dialog. This function edits the pattern string to make
89 this happen.
90 */
91 static void
92 fileDialogExtensionToPattern(Glib::ustring &pattern,
93 Glib::ustring &extension)
94 {
95 for (unsigned int i = 0; i < extension.length(); i++ )
96 {
97 Glib::ustring::value_type ch = extension[i];
98 if ( Glib::Unicode::isalpha(ch) )
99 {
100 pattern += '[';
101 pattern += Glib::Unicode::toupper(ch);
102 pattern += Glib::Unicode::tolower(ch);
103 pattern += ']';
104 }
105 else
106 {
107 pattern += ch;
108 }
109 }
110 }
113 /**
114 * Hack: Find all entry widgets in a container
115 */
116 static void
117 findEntryWidgets(Gtk::Container *parent,
118 std::vector<Gtk::Entry *> &result)
119 {
120 if (!parent)
121 return;
122 std::vector<Gtk::Widget *> children = parent->get_children();
123 for (unsigned int i=0; i<children.size() ; i++)
124 {
125 Gtk::Widget *child = children[i];
126 GtkWidget *wid = child->gobj();
127 if (GTK_IS_ENTRY(wid))
128 result.push_back((Gtk::Entry *)child);
129 else if (GTK_IS_CONTAINER(wid))
130 findEntryWidgets((Gtk::Container *)child, result);
131 }
133 }
138 /**
139 * Hack: Find all expander widgets in a container
140 */
141 static void
142 findExpanderWidgets(Gtk::Container *parent,
143 std::vector<Gtk::Expander *> &result)
144 {
145 if (!parent)
146 return;
147 std::vector<Gtk::Widget *> children = parent->get_children();
148 for (unsigned int i=0; i<children.size() ; i++)
149 {
150 Gtk::Widget *child = children[i];
151 GtkWidget *wid = child->gobj();
152 if (GTK_IS_EXPANDER(wid))
153 result.push_back((Gtk::Expander *)child);
154 else if (GTK_IS_CONTAINER(wid))
155 findExpanderWidgets((Gtk::Container *)child, result);
156 }
158 }
161 /*#########################################################################
162 ### SVG Preview Widget
163 #########################################################################*/
165 /**
166 * Simple class for displaying an SVG file in the "preview widget."
167 * Currently, this is just a wrapper of the sp_svg_view Gtk widget.
168 * Hopefully we will eventually replace with a pure Gtkmm widget.
169 */
170 class SVGPreview : public Gtk::VBox
171 {
172 public:
174 SVGPreview();
176 ~SVGPreview();
178 bool setDocument(SPDocument *doc);
180 bool setFileName(Glib::ustring &fileName);
182 bool setFromMem(char const *xmlBuffer);
184 bool set(Glib::ustring &fileName, int dialogType);
186 bool setURI(URI &uri);
188 /**
189 * Show image embedded in SVG
190 */
191 void showImage(Glib::ustring &fileName);
193 /**
194 * Show the "No preview" image
195 */
196 void showNoPreview();
198 /**
199 * Show the "Too large" image
200 */
201 void showTooLarge(long fileLength);
203 private:
204 /**
205 * The svg document we are currently showing
206 */
207 SPDocument *document;
209 /**
210 * The sp_svg_view widget
211 */
212 GtkWidget *viewerGtk;
214 /**
215 * are we currently showing the "no preview" image?
216 */
217 bool showingNoPreview;
219 };
222 bool SVGPreview::setDocument(SPDocument *doc)
223 {
224 if (document)
225 sp_document_unref(document);
227 sp_document_ref(doc);
228 document = doc;
230 //This should remove it from the box, and free resources
231 if (viewerGtk)
232 gtk_widget_destroy(viewerGtk);
234 viewerGtk = sp_svg_view_widget_new(doc);
235 GtkWidget *vbox = (GtkWidget *)gobj();
236 gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);
237 gtk_widget_show(viewerGtk);
239 return true;
240 }
243 bool SVGPreview::setFileName(Glib::ustring &theFileName)
244 {
245 Glib::ustring fileName = theFileName;
247 fileName = Glib::filename_to_utf8(fileName);
249 /**
250 * I don't know why passing false to keepalive is bad. But it
251 * prevents the display of an svg with a non-ascii filename
252 */
253 SPDocument *doc = sp_document_new (fileName.c_str(), true);
254 if (!doc) {
255 g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
256 return false;
257 }
259 setDocument(doc);
261 sp_document_unref(doc);
263 return true;
264 }
268 bool SVGPreview::setFromMem(char const *xmlBuffer)
269 {
270 if (!xmlBuffer)
271 return false;
273 gint len = (gint)strlen(xmlBuffer);
274 SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);
275 if (!doc) {
276 g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);
277 return false;
278 }
280 setDocument(doc);
282 sp_document_unref(doc);
284 Inkscape::GC::request_early_collection();
286 return true;
287 }
291 void SVGPreview::showImage(Glib::ustring &theFileName)
292 {
293 Glib::ustring fileName = theFileName;
296 /*#####################################
297 # LET'S HAVE SOME FUN WITH SVG!
298 # Instead of just loading an image, why
299 # don't we make a lovely little svg and
300 # display it nicely?
301 #####################################*/
303 //Arbitrary size of svg doc -- rather 'portrait' shaped
304 gint previewWidth = 400;
305 gint previewHeight = 600;
307 //Get some image info. Smart pointer does not need to be deleted
308 Glib::RefPtr<Gdk::Pixbuf> img = Gdk::Pixbuf::create_from_file(fileName);
309 gint imgWidth = img->get_width();
310 gint imgHeight = img->get_height();
312 //Find the minimum scale to fit the image inside the preview area
313 double scaleFactorX = (0.9 *(double)previewWidth) / ((double)imgWidth);
314 double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);
315 double scaleFactor = scaleFactorX;
316 if (scaleFactorX > scaleFactorY)
317 scaleFactor = scaleFactorY;
319 //Now get the resized values
320 gint scaledImgWidth = (int) (scaleFactor * (double)imgWidth);
321 gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);
323 //center the image on the area
324 gint imgX = (previewWidth - scaledImgWidth) / 2;
325 gint imgY = (previewHeight - scaledImgHeight) / 2;
327 //wrap a rectangle around the image
328 gint rectX = imgX-1;
329 gint rectY = imgY-1;
330 gint rectWidth = scaledImgWidth +2;
331 gint rectHeight = scaledImgHeight+2;
333 //Our template. Modify to taste
334 gchar const *xformat =
335 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
336 "<svg\n"
337 "xmlns=\"http://www.w3.org/2000/svg\"\n"
338 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
339 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
340 "<rect\n"
341 " style=\"fill:#eeeeee;stroke:none\"\n"
342 " x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
343 "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
344 "xlink:href=\"%s\"/>\n"
345 "<rect\n"
346 " style=\"fill:none;"
347 " stroke:#000000;stroke-width:1.0;"
348 " stroke-linejoin:miter;stroke-opacity:1.0000000;"
349 " stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
350 " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
351 "<text\n"
352 " style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
353 " fill:#000000;fill-opacity:1.0000000;stroke:none;"
354 " font-family:Bitstream Vera Sans\"\n"
355 " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
356 "</svg>\n\n";
358 //if (!Glib::get_charset()) //If we are not utf8
359 fileName = Glib::filename_to_utf8(fileName);
361 //Fill in the template
362 /* FIXME: Do proper XML quoting for fileName. */
363 gchar *xmlBuffer = g_strdup_printf(xformat,
364 previewWidth, previewHeight,
365 imgX, imgY, scaledImgWidth, scaledImgHeight,
366 fileName.c_str(),
367 rectX, rectY, rectWidth, rectHeight,
368 imgWidth, imgHeight);
370 //g_message("%s\n", xmlBuffer);
372 //now show it!
373 setFromMem(xmlBuffer);
374 g_free(xmlBuffer);
375 }
379 void SVGPreview::showNoPreview()
380 {
381 //Are we already showing it?
382 if (showingNoPreview)
383 return;
385 //Arbitrary size of svg doc -- rather 'portrait' shaped
386 gint previewWidth = 300;
387 gint previewHeight = 600;
389 //Our template. Modify to taste
390 gchar const *xformat =
391 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
392 "<svg\n"
393 "xmlns=\"http://www.w3.org/2000/svg\"\n"
394 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
395 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
396 "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
397 "<path\n"
398 "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
399 "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
400 "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
401 "id=\"whiteSpace\" />\n"
402 "<path\n"
403 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
404 "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
405 "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
406 "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
407 "id=\"droplet01\" />\n"
408 "<path\n"
409 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
410 "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
411 "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
412 "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
413 "287.18046 343.1206 286.46194 340.42914 z \"\n"
414 "id=\"droplet02\" />\n"
415 "<path\n"
416 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
417 "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
418 "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
419 "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
420 "id=\"droplet03\" />\n"
421 "<path\n"
422 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
423 "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
424 "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
425 "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
426 "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
427 "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
428 "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
429 "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
430 "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
431 "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
432 "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
433 "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
434 "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
435 "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
436 "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
437 "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
438 "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
439 "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
440 "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
441 "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
442 "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
443 "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
444 "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
445 "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
446 "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
447 "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
448 "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
449 "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
450 "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
451 "id=\"mountainDroplet\" />\n"
452 "</g> <g transform=\"translate(-20,0)\">\n"
453 "<text xml:space=\"preserve\"\n"
454 "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
455 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
456 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
457 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
458 "x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE
459 "</svg>\n\n";
461 //Fill in the template
462 gchar *xmlBuffer = g_strdup_printf(xformat,
463 previewWidth, previewHeight, _("No preview"));
465 //g_message("%s\n", xmlBuffer);
467 //now show it!
468 setFromMem(xmlBuffer);
469 g_free(xmlBuffer);
470 showingNoPreview = true;
472 }
475 /**
476 * Inform the user that the svg file is too large to be displayed.
477 * This does not check for sizes of embedded images (yet)
478 */
479 void SVGPreview::showTooLarge(long fileLength)
480 {
482 //Arbitrary size of svg doc -- rather 'portrait' shaped
483 gint previewWidth = 300;
484 gint previewHeight = 600;
486 //Our template. Modify to taste
487 gchar const *xformat =
488 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
489 "<svg\n"
490 "xmlns=\"http://www.w3.org/2000/svg\"\n"
491 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
492 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
493 "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
494 "<path\n"
495 "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
496 "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
497 "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
498 "id=\"whiteSpace\" />\n"
499 "<path\n"
500 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
501 "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
502 "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
503 "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
504 "id=\"droplet01\" />\n"
505 "<path\n"
506 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
507 "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
508 "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
509 "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
510 "287.18046 343.1206 286.46194 340.42914 z \"\n"
511 "id=\"droplet02\" />\n"
512 "<path\n"
513 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
514 "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
515 "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
516 "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
517 "id=\"droplet03\" />\n"
518 "<path\n"
519 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
520 "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
521 "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
522 "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
523 "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
524 "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
525 "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
526 "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
527 "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
528 "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
529 "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
530 "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
531 "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
532 "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
533 "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
534 "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
535 "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
536 "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
537 "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
538 "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
539 "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
540 "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
541 "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
542 "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
543 "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
544 "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
545 "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
546 "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
547 "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
548 "id=\"mountainDroplet\" />\n"
549 "</g>\n"
550 "<text xml:space=\"preserve\"\n"
551 "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
552 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
553 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
554 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
555 "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE
556 "<text xml:space=\"preserve\"\n"
557 "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
558 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
559 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
560 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
561 "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE
562 "</svg>\n\n";
564 //Fill in the template
565 double floatFileLength = ((double)fileLength) / 1048576.0;
566 //printf("%ld %f\n", fileLength, floatFileLength);
567 gchar *xmlBuffer = g_strdup_printf(xformat,
568 previewWidth, previewHeight, floatFileLength,
569 _("too large for preview"));
571 //g_message("%s\n", xmlBuffer);
573 //now show it!
574 setFromMem(xmlBuffer);
575 g_free(xmlBuffer);
577 }
580 /**
581 * Return true if the string ends with the given suffix
582 */
583 static bool
584 hasSuffix(Glib::ustring &str, Glib::ustring &ext)
585 {
586 int strLen = str.length();
587 int extLen = ext.length();
588 if (extLen > strLen)
589 return false;
590 int strpos = strLen-1;
591 for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)
592 {
593 Glib::ustring::value_type ch = str[strpos];
594 if (ch != ext[extpos])
595 {
596 if ( ((ch & 0xff80) != 0) ||
597 static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )
598 {
599 return false;
600 }
601 }
602 }
603 return true;
604 }
607 /**
608 * Return true if the image is loadable by Gdk, else false
609 */
610 static bool
611 isValidImageFile(Glib::ustring &fileName)
612 {
613 std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();
614 for (unsigned int i=0; i<formats.size(); i++)
615 {
616 Gdk::PixbufFormat format = formats[i];
617 std::vector<Glib::ustring>extensions = format.get_extensions();
618 for (unsigned int j=0; j<extensions.size(); j++)
619 {
620 Glib::ustring ext = extensions[j];
621 if (hasSuffix(fileName, ext))
622 return true;
623 }
624 }
625 return false;
626 }
628 bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
629 {
631 if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
632 return false;
634 //g_message("fname:%s", fileName.c_str());
636 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
637 showNoPreview();
638 return false;
639 }
641 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
642 {
643 Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);
644 gchar *fName = (gchar *)fileNameUtf8.c_str();
645 struct stat info;
646 if (g_stat(fName, &info))
647 {
648 g_warning("SVGPreview::set() : %s : %s",
649 fName, strerror(errno));
650 return FALSE;
651 }
652 long fileLen = info.st_size;
653 if (fileLen > 0x150000L)
654 {
655 showingNoPreview = false;
656 showTooLarge(fileLen);
657 return FALSE;
658 }
659 }
661 Glib::ustring svg = ".svg";
662 Glib::ustring svgz = ".svgz";
664 if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
665 (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) )
666 ) {
667 bool retval = setFileName(fileName);
668 showingNoPreview = false;
669 return retval;
670 } else if (isValidImageFile(fileName)) {
671 showImage(fileName);
672 showingNoPreview = false;
673 return true;
674 } else {
675 showNoPreview();
676 return false;
677 }
678 }
681 SVGPreview::SVGPreview()
682 {
683 if (!INKSCAPE)
684 inkscape_application_init("",false);
685 document = NULL;
686 viewerGtk = NULL;
687 set_size_request(150,150);
688 showingNoPreview = false;
689 }
691 SVGPreview::~SVGPreview()
692 {
694 }
700 /*#########################################################################
701 ### F I L E D I A L O G B A S E C L A S S
702 #########################################################################*/
704 /**
705 * This class is the base implementation for the others. This
706 * reduces redundancies and bugs.
707 */
708 class FileDialogBase : public Gtk::FileChooserDialog
709 {
710 public:
712 /**
713 *
714 */
715 FileDialogBase(const Glib::ustring &title, FileDialogType type, gchar const* preferenceBase) :
716 Gtk::FileChooserDialog(title),
717 preferenceBase(preferenceBase ? preferenceBase : "unknown"),
718 dialogType(type)
719 {
720 internalSetup();
721 }
723 /**
724 *
725 */
726 FileDialogBase(const Glib::ustring &title,
727 Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :
728 Gtk::FileChooserDialog(title, dialogType),
729 preferenceBase(preferenceBase ? preferenceBase : "unknown"),
730 dialogType(type)
731 {
732 internalSetup();
733 }
735 /**
736 *
737 */
738 virtual ~FileDialogBase()
739 {}
741 protected:
742 void cleanup( bool showConfirmed );
744 Glib::ustring preferenceBase;
745 /**
746 * What type of 'open' are we? (open, import, place, etc)
747 */
748 FileDialogType dialogType;
750 /**
751 * Our svg preview widget
752 */
753 SVGPreview svgPreview;
755 //# Child widgets
756 Gtk::CheckButton previewCheckbox;
758 private:
759 void internalSetup();
761 /**
762 * Callback for user changing preview checkbox
763 */
764 void _previewEnabledCB();
766 /**
767 * Callback for seeing if the preview needs to be drawn
768 */
769 void _updatePreviewCallback();
770 };
773 void FileDialogBase::internalSetup()
774 {
775 bool enablePreview =
776 (bool)prefs_get_int_attribute( preferenceBase.c_str(),
777 "enable_preview", 1 );
779 previewCheckbox.set_label( Glib::ustring(_("Enable Preview")) );
780 previewCheckbox.set_active( enablePreview );
782 previewCheckbox.signal_toggled().connect(
783 sigc::mem_fun(*this, &FileDialogBase::_previewEnabledCB) );
785 //Catch selection-changed events, so we can adjust the text widget
786 signal_update_preview().connect(
787 sigc::mem_fun(*this, &FileDialogBase::_updatePreviewCallback) );
789 //###### Add a preview widget
790 set_preview_widget(svgPreview);
791 set_preview_widget_active( enablePreview );
792 set_use_preview_label (false);
794 }
797 void FileDialogBase::cleanup( bool showConfirmed )
798 {
799 if ( showConfirmed )
800 prefs_set_int_attribute( preferenceBase.c_str(),
801 "enable_preview", previewCheckbox.get_active() );
802 }
805 void FileDialogBase::_previewEnabledCB()
806 {
807 bool enabled = previewCheckbox.get_active();
808 set_preview_widget_active(enabled);
809 if ( enabled ) {
810 _updatePreviewCallback();
811 }
812 }
816 /**
817 * Callback for checking if the preview needs to be redrawn
818 */
819 void FileDialogBase::_updatePreviewCallback()
820 {
821 Glib::ustring fileName = get_preview_filename();
823 #ifdef WITH_GNOME_VFS
824 if (fileName.length() < 1)
825 fileName = get_preview_uri();
826 #endif
828 if (fileName.length() < 1)
829 return;
831 svgPreview.set(fileName, dialogType);
832 }
835 /*#########################################################################
836 ### F I L E O P E N
837 #########################################################################*/
839 /**
840 * Our implementation class for the FileOpenDialog interface..
841 */
842 class FileOpenDialogImpl : public FileOpenDialog, public FileDialogBase
843 {
844 public:
846 FileOpenDialogImpl(const Glib::ustring &dir,
847 FileDialogType fileTypes,
848 const Glib::ustring &title);
850 virtual ~FileOpenDialogImpl();
852 bool show();
854 Inkscape::Extension::Extension *getSelectionType();
856 Glib::ustring getFilename();
858 std::vector<Glib::ustring> getFilenames ();
860 private:
862 /**
863 * Create a filter menu for this type of dialog
864 */
865 void createFilterMenu();
867 /**
868 * Filter name->extension lookup
869 */
870 std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;
872 /**
873 * The extension to use to write this file
874 */
875 Inkscape::Extension::Extension *extension;
877 /**
878 * Filename that was given
879 */
880 Glib::ustring myFilename;
882 };
890 void FileOpenDialogImpl::createFilterMenu()
891 {
892 //patterns added dynamically below
893 Gtk::FileFilter allImageFilter;
894 allImageFilter.set_name(_("All Images"));
895 extensionMap[Glib::ustring(_("All Images"))]=NULL;
896 add_filter(allImageFilter);
898 Gtk::FileFilter allFilter;
899 allFilter.set_name(_("All Files"));
900 extensionMap[Glib::ustring(_("All Files"))]=NULL;
901 allFilter.add_pattern("*");
902 add_filter(allFilter);
904 //patterns added dynamically below
905 Gtk::FileFilter allInkscapeFilter;
906 allInkscapeFilter.set_name(_("All Inkscape Files"));
907 extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
908 add_filter(allInkscapeFilter);
910 Inkscape::Extension::DB::InputList extension_list;
911 Inkscape::Extension::db.get_input_list(extension_list);
913 for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
914 current_item != extension_list.end(); current_item++)
915 {
916 Inkscape::Extension::Input * imod = *current_item;
918 // FIXME: would be nice to grey them out instead of not listing them
919 if (imod->deactivated()) continue;
921 Glib::ustring upattern("*");
922 Glib::ustring extension = imod->get_extension();
923 fileDialogExtensionToPattern(upattern, extension);
925 Gtk::FileFilter filter;
926 Glib::ustring uname(_(imod->get_filetypename()));
927 filter.set_name(uname);
928 filter.add_pattern(upattern);
929 add_filter(filter);
930 extensionMap[uname] = imod;
932 //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
933 allInkscapeFilter.add_pattern(upattern);
934 if ( strncmp("image", imod->get_mimetype(), 5)==0 )
935 allImageFilter.add_pattern(upattern);
936 }
938 return;
939 }
943 /**
944 * Constructor. Not called directly. Use the factory.
945 */
946 FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
947 FileDialogType fileTypes,
948 const Glib::ustring &title) :
949 FileDialogBase(title, fileTypes, "dialogs.open")
950 {
953 /* One file at a time */
954 /* And also Multiple Files */
955 set_select_multiple(true);
957 #ifdef WITH_GNOME_VFS
958 set_local_only(false);
959 #endif
961 /* Initalize to Autodetect */
962 extension = NULL;
963 /* No filename to start out with */
964 myFilename = "";
966 /* Set our dialog type (open, import, etc...)*/
967 dialogType = fileTypes;
970 /* Set the pwd and/or the filename */
971 if (dir.size() > 0)
972 {
973 Glib::ustring udir(dir);
974 Glib::ustring::size_type len = udir.length();
975 // leaving a trailing backslash on the directory name leads to the infamous
976 // double-directory bug on win32
977 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
978 set_current_folder(udir.c_str());
979 }
982 set_extra_widget( previewCheckbox );
985 //###### Add the file types menu
986 createFilterMenu();
989 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
990 set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
991 }
997 /**
998 * Public factory. Called by file.cpp, among others.
999 */
1000 FileOpenDialog *FileOpenDialog::create(const Glib::ustring &path,
1001 FileDialogType fileTypes,
1002 const Glib::ustring &title)
1003 {
1004 FileOpenDialog *dialog = new FileOpenDialogImpl(path, fileTypes, title);
1005 return dialog;
1006 }
1011 /**
1012 * Destructor
1013 */
1014 FileOpenDialogImpl::~FileOpenDialogImpl()
1015 {
1017 }
1020 /**
1021 * Show this dialog modally. Return true if user hits [OK]
1022 */
1023 bool
1024 FileOpenDialogImpl::show()
1025 {
1026 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
1027 if (s.length() == 0)
1028 s = getcwd (NULL, 0);
1029 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
1030 set_modal (TRUE); //Window
1031 sp_transientize((GtkWidget *)gobj()); //Make transient
1032 gint b = run(); //Dialog
1033 svgPreview.showNoPreview();
1034 hide();
1036 if (b == Gtk::RESPONSE_OK)
1037 {
1038 //This is a hack, to avoid the warning messages that
1039 //Gtk::FileChooser::get_filter() returns
1040 //should be: Gtk::FileFilter *filter = get_filter();
1041 GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
1042 GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
1043 if (filter)
1044 {
1045 //Get which extension was chosen, if any
1046 extension = extensionMap[gtk_file_filter_get_name(filter)];
1047 }
1048 myFilename = get_filename();
1049 #ifdef WITH_GNOME_VFS
1050 if (myFilename.length() < 1)
1051 myFilename = get_uri();
1052 #endif
1053 cleanup( true );
1054 return TRUE;
1055 }
1056 else
1057 {
1058 cleanup( false );
1059 return FALSE;
1060 }
1061 }
1066 /**
1067 * Get the file extension type that was selected by the user. Valid after an [OK]
1068 */
1069 Inkscape::Extension::Extension *
1070 FileOpenDialogImpl::getSelectionType()
1071 {
1072 return extension;
1073 }
1076 /**
1077 * Get the file name chosen by the user. Valid after an [OK]
1078 */
1079 Glib::ustring
1080 FileOpenDialogImpl::getFilename (void)
1081 {
1082 return g_strdup(myFilename.c_str());
1083 }
1086 /**
1087 * To Get Multiple filenames selected at-once.
1088 */
1089 std::vector<Glib::ustring>FileOpenDialogImpl::getFilenames()
1090 {
1091 std::vector<Glib::ustring> result = get_filenames();
1092 #ifdef WITH_GNOME_VFS
1093 if (result.empty())
1094 result = get_uris();
1095 #endif
1096 return result;
1097 }
1104 //########################################################################
1105 //# F I L E S A V E
1106 //########################################################################
1108 class FileType
1109 {
1110 public:
1111 FileType() {}
1112 ~FileType() {}
1113 Glib::ustring name;
1114 Glib::ustring pattern;
1115 Inkscape::Extension::Extension *extension;
1116 };
1118 /**
1119 * Our implementation of the FileSaveDialog interface.
1120 */
1121 class FileSaveDialogImpl : public FileSaveDialog, public FileDialogBase
1122 {
1124 public:
1125 FileSaveDialogImpl(const Glib::ustring &dir,
1126 FileDialogType fileTypes,
1127 const Glib::ustring &title,
1128 const Glib::ustring &default_key);
1130 virtual ~FileSaveDialogImpl();
1132 bool show();
1134 Inkscape::Extension::Extension *getSelectionType();
1135 virtual void setSelectionType( Inkscape::Extension::Extension * key );
1137 Glib::ustring getFilename();
1139 void change_title(const Glib::ustring& title);
1140 void change_path(const Glib::ustring& path);
1141 void updateNameAndExtension();
1143 private:
1145 /**
1146 * Fix to allow the user to type the file name
1147 */
1148 Gtk::Entry *fileNameEntry;
1151 /**
1152 * Allow the specification of the output file type
1153 */
1154 Gtk::ComboBoxText fileTypeComboBox;
1157 /**
1158 * Data mirror of the combo box
1159 */
1160 std::vector<FileType> fileTypes;
1162 //# Child widgets
1163 Gtk::HBox childBox;
1164 Gtk::VBox checksBox;
1166 Gtk::CheckButton fileTypeCheckbox;
1168 /**
1169 * Callback for user input into fileNameEntry
1170 */
1171 void fileTypeChangedCallback();
1173 /**
1174 * Create a filter menu for this type of dialog
1175 */
1176 void createFileTypeMenu();
1179 /**
1180 * The extension to use to write this file
1181 */
1182 Inkscape::Extension::Extension *extension;
1184 /**
1185 * Callback for user input into fileNameEntry
1186 */
1187 void fileNameEntryChangedCallback();
1189 /**
1190 * Filename that was given
1191 */
1192 Glib::ustring myFilename;
1194 /**
1195 * List of known file extensions.
1196 */
1197 std::set<Glib::ustring> knownExtensions;
1198 };
1203 /**
1204 * Callback for fileNameEntry widget
1205 */
1206 void FileSaveDialogImpl::fileNameEntryChangedCallback()
1207 {
1208 if (!fileNameEntry)
1209 return;
1211 Glib::ustring fileName = fileNameEntry->get_text();
1212 if (!Glib::get_charset()) //If we are not utf8
1213 fileName = Glib::filename_to_utf8(fileName);
1215 //g_message("User hit return. Text is '%s'\n", fileName.c_str());
1217 if (!Glib::path_is_absolute(fileName)) {
1218 //try appending to the current path
1219 // not this way: fileName = get_current_folder() + "/" + fileName;
1220 std::vector<Glib::ustring> pathSegments;
1221 pathSegments.push_back( get_current_folder() );
1222 pathSegments.push_back( fileName );
1223 fileName = Glib::build_filename(pathSegments);
1224 }
1226 //g_message("path:'%s'\n", fileName.c_str());
1228 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1229 set_current_folder(fileName);
1230 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1231 //dialog with either (1) select a regular file or (2) cd to dir
1232 //simulate an 'OK'
1233 set_filename(fileName);
1234 response(Gtk::RESPONSE_OK);
1235 }
1236 }
1240 /**
1241 * Callback for fileNameEntry widget
1242 */
1243 void FileSaveDialogImpl::fileTypeChangedCallback()
1244 {
1245 int sel = fileTypeComboBox.get_active_row_number();
1246 if (sel<0 || sel >= (int)fileTypes.size())
1247 return;
1248 FileType type = fileTypes[sel];
1249 //g_message("selected: %s\n", type.name.c_str());
1251 extension = type.extension;
1252 Gtk::FileFilter filter;
1253 filter.add_pattern(type.pattern);
1254 set_filter(filter);
1256 updateNameAndExtension();
1257 }
1261 void FileSaveDialogImpl::createFileTypeMenu()
1262 {
1263 Inkscape::Extension::DB::OutputList extension_list;
1264 Inkscape::Extension::db.get_output_list(extension_list);
1265 knownExtensions.clear();
1267 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1268 current_item != extension_list.end(); current_item++)
1269 {
1270 Inkscape::Extension::Output * omod = *current_item;
1272 // FIXME: would be nice to grey them out instead of not listing them
1273 if (omod->deactivated()) continue;
1275 FileType type;
1276 type.name = (_(omod->get_filetypename()));
1277 type.pattern = "*";
1278 Glib::ustring extension = omod->get_extension();
1279 knownExtensions.insert( extension.casefold() );
1280 fileDialogExtensionToPattern (type.pattern, extension);
1281 type.extension= omod;
1282 fileTypeComboBox.append_text(type.name);
1283 fileTypes.push_back(type);
1284 }
1286 //#Let user choose
1287 FileType guessType;
1288 guessType.name = _("Guess from extension");
1289 guessType.pattern = "*";
1290 guessType.extension = NULL;
1291 fileTypeComboBox.append_text(guessType.name);
1292 fileTypes.push_back(guessType);
1295 fileTypeComboBox.set_active(0);
1296 fileTypeChangedCallback(); //call at least once to set the filter
1297 }
1301 /**
1302 * Constructor
1303 */
1304 FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir,
1305 FileDialogType fileTypes,
1306 const Glib::ustring &title,
1307 const Glib::ustring &default_key) :
1308 FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")
1309 {
1310 /* One file at a time */
1311 set_select_multiple(false);
1313 #ifdef WITH_GNOME_VFS
1314 set_local_only(false);
1315 #endif
1317 /* Initalize to Autodetect */
1318 extension = NULL;
1319 /* No filename to start out with */
1320 myFilename = "";
1322 /* Set our dialog type (save, export, etc...)*/
1323 dialogType = fileTypes;
1325 /* Set the pwd and/or the filename */
1326 if (dir.size() > 0)
1327 {
1328 Glib::ustring udir(dir);
1329 Glib::ustring::size_type len = udir.length();
1330 // leaving a trailing backslash on the directory name leads to the infamous
1331 // double-directory bug on win32
1332 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1333 myFilename = udir;
1334 }
1336 //###### Add the file types menu
1337 //createFilterMenu();
1339 //###### Do we want the .xxx extension automatically added?
1340 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
1341 fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.save_as",
1342 "append_extension", 1) );
1344 createFileTypeMenu();
1345 fileTypeComboBox.set_size_request(200,40);
1346 fileTypeComboBox.signal_changed().connect(
1347 sigc::mem_fun(*this, &FileSaveDialogImpl::fileTypeChangedCallback) );
1350 childBox.pack_start( checksBox );
1351 childBox.pack_end( fileTypeComboBox );
1352 checksBox.pack_start( fileTypeCheckbox );
1353 checksBox.pack_start( previewCheckbox );
1355 set_extra_widget( childBox );
1357 //Let's do some customization
1358 fileNameEntry = NULL;
1359 Gtk::Container *cont = get_toplevel();
1360 std::vector<Gtk::Entry *> entries;
1361 findEntryWidgets(cont, entries);
1362 //g_message("Found %d entry widgets\n", entries.size());
1363 if (entries.size() >=1 )
1364 {
1365 //Catch when user hits [return] on the text field
1366 fileNameEntry = entries[0];
1367 fileNameEntry->signal_activate().connect(
1368 sigc::mem_fun(*this, &FileSaveDialogImpl::fileNameEntryChangedCallback) );
1369 }
1371 //Let's do more customization
1372 std::vector<Gtk::Expander *> expanders;
1373 findExpanderWidgets(cont, expanders);
1374 //g_message("Found %d expander widgets\n", expanders.size());
1375 if (expanders.size() >=1 )
1376 {
1377 //Always show the file list
1378 Gtk::Expander *expander = expanders[0];
1379 expander->set_expanded(true);
1380 }
1383 //if (extension == NULL)
1384 // checkbox.set_sensitive(FALSE);
1386 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1387 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
1389 show_all_children();
1390 }
1394 /**
1395 * Public factory method. Used in file.cpp
1396 */
1397 FileSaveDialog *FileSaveDialog::create(const Glib::ustring &path,
1398 FileDialogType fileTypes,
1399 const Glib::ustring &title,
1400 const Glib::ustring &default_key)
1401 {
1402 FileSaveDialog *dialog = new FileSaveDialogImpl(path, fileTypes, title, default_key);
1403 return dialog;
1404 }
1410 /**
1411 * Destructor
1412 */
1413 FileSaveDialogImpl::~FileSaveDialogImpl()
1414 {
1415 }
1419 /**
1420 * Show this dialog modally. Return true if user hits [OK]
1421 */
1422 bool
1423 FileSaveDialogImpl::show()
1424 {
1425 change_path(myFilename);
1426 set_modal (TRUE); //Window
1427 sp_transientize((GtkWidget *)gobj()); //Make transient
1428 gint b = run(); //Dialog
1429 svgPreview.showNoPreview();
1430 hide();
1432 if (b == Gtk::RESPONSE_OK)
1433 {
1434 updateNameAndExtension();
1436 // Store changes of the "Append filename automatically" checkbox back to preferences.
1437 prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active());
1439 // Store the last used save-as filetype to preferences.
1440 prefs_set_string_attribute("dialogs.save_as", "default",
1441 ( extension != NULL ? extension->get_id() : "" ));
1443 cleanup( true );
1445 return TRUE;
1446 }
1447 else
1448 {
1449 cleanup( false );
1451 return FALSE;
1452 }
1453 }
1456 /**
1457 * Get the file extension type that was selected by the user. Valid after an [OK]
1458 */
1459 Inkscape::Extension::Extension *
1460 FileSaveDialogImpl::getSelectionType()
1461 {
1462 return extension;
1463 }
1465 void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
1466 {
1467 // If no pointer to extension is passed in, look up based on filename extension.
1468 if ( !key ) {
1469 // Not quite UTF-8 here.
1470 gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
1471 for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
1472 Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
1473 if ( ext && ext->get_extension() ) {
1474 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
1475 if ( g_str_has_suffix(filenameLower, extensionLower) ) {
1476 key = fileTypes[i].extension;
1477 }
1478 g_free(extensionLower);
1479 }
1480 }
1481 g_free(filenameLower);
1482 }
1484 // Ensure the proper entry in the combo box is selected.
1485 if ( key ) {
1486 extension = key;
1487 gchar const * extensionID = extension->get_id();
1488 if ( extensionID ) {
1489 for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
1490 Inkscape::Extension::Extension *ext = fileTypes[i].extension;
1491 if ( ext ) {
1492 gchar const * id = ext->get_id();
1493 if ( id && ( strcmp(extensionID, id) == 0) ) {
1494 int oldSel = fileTypeComboBox.get_active_row_number();
1495 if ( i != oldSel ) {
1496 fileTypeComboBox.set_active(i);
1497 }
1498 break;
1499 }
1500 }
1501 }
1502 }
1503 }
1504 }
1507 /**
1508 * Get the file name chosen by the user. Valid after an [OK]
1509 */
1510 Glib::ustring
1511 FileSaveDialogImpl::getFilename()
1512 {
1513 return myFilename;
1514 }
1517 void
1518 FileSaveDialogImpl::change_title(const Glib::ustring& title)
1519 {
1520 this->set_title(title);
1521 }
1523 /**
1524 * Change the default save path location.
1525 */
1526 void
1527 FileSaveDialogImpl::change_path(const Glib::ustring& path)
1528 {
1529 myFilename = path;
1530 if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
1531 //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
1532 set_current_folder(myFilename);
1533 } else {
1534 //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
1535 if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
1536 set_filename(myFilename);
1537 } else {
1538 std::string dirName = Glib::path_get_dirname( myFilename );
1539 if ( dirName != get_current_folder() ) {
1540 set_current_folder(dirName);
1541 }
1542 }
1543 Glib::ustring basename = Glib::path_get_basename(myFilename);
1544 //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
1545 try {
1546 set_current_name( Glib::filename_to_utf8(basename) );
1547 } catch ( Glib::ConvertError& e ) {
1548 g_warning( "Error converting save filename to UTF-8." );
1549 // try a fallback.
1550 set_current_name( basename );
1551 }
1552 }
1553 }
1555 void FileSaveDialogImpl::updateNameAndExtension()
1556 {
1557 // Pick up any changes the user has typed in.
1558 Glib::ustring tmp = get_filename();
1559 #ifdef WITH_GNOME_VFS
1560 if ( tmp.empty() ) {
1561 tmp = get_uri();
1562 }
1563 #endif
1564 if ( !tmp.empty() ) {
1565 myFilename = tmp;
1566 }
1568 Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
1569 if ( fileTypeCheckbox.get_active() && newOut ) {
1570 try {
1571 bool appendExtension = true;
1572 Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
1573 Glib::ustring::size_type pos = utf8Name.rfind('.');
1574 if ( pos != Glib::ustring::npos ) {
1575 Glib::ustring trail = utf8Name.substr( pos );
1576 Glib::ustring foldedTrail = trail.casefold();
1577 if ( (trail == ".")
1578 | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()
1579 && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {
1580 utf8Name = utf8Name.erase( pos );
1581 } else {
1582 appendExtension = false;
1583 }
1584 }
1586 if (appendExtension) {
1587 utf8Name = utf8Name + newOut->get_extension();
1588 myFilename = Glib::filename_from_utf8( utf8Name );
1589 change_path(myFilename);
1590 }
1591 } catch ( Glib::ConvertError& e ) {
1592 // ignore
1593 }
1594 }
1595 }
1599 //########################################################################
1600 //# F I L E E X P O R T
1601 //########################################################################
1604 /**
1605 * Our implementation of the FileExportDialog interface.
1606 */
1607 class FileExportDialogImpl : public FileExportDialog, public FileDialogBase
1608 {
1610 public:
1611 FileExportDialogImpl(const Glib::ustring &dir,
1612 FileDialogType fileTypes,
1613 const Glib::ustring &title,
1614 const Glib::ustring &default_key);
1616 virtual ~FileExportDialogImpl();
1618 bool show();
1620 Inkscape::Extension::Extension *getSelectionType();
1622 Glib::ustring getFilename();
1625 /**
1626 * Return the scope of the export. One of the enumerated types
1627 * in ScopeType
1628 */
1629 ScopeType getScope()
1630 {
1631 if (pageButton.get_active())
1632 return SCOPE_PAGE;
1633 else if (selectionButton.get_active())
1634 return SCOPE_SELECTION;
1635 else if (customButton.get_active())
1636 return SCOPE_CUSTOM;
1637 else
1638 return SCOPE_DOCUMENT;
1640 }
1642 /**
1643 * Return left side of the exported region
1644 */
1645 double getSourceX()
1646 { return sourceX0Spinner.getValue(); }
1648 /**
1649 * Return the top of the exported region
1650 */
1651 double getSourceY()
1652 { return sourceY1Spinner.getValue(); }
1654 /**
1655 * Return the width of the exported region
1656 */
1657 double getSourceWidth()
1658 { return sourceWidthSpinner.getValue(); }
1660 /**
1661 * Return the height of the exported region
1662 */
1663 double getSourceHeight()
1664 { return sourceHeightSpinner.getValue(); }
1666 /**
1667 * Return the units of the coordinates of exported region
1668 */
1669 Glib::ustring getSourceUnits()
1670 { return sourceUnitsSpinner.getUnitAbbr(); }
1672 /**
1673 * Return the width of the destination document
1674 */
1675 double getDestinationWidth()
1676 { return destWidthSpinner.getValue(); }
1678 /**
1679 * Return the height of the destination document
1680 */
1681 double getDestinationHeight()
1682 { return destHeightSpinner.getValue(); }
1684 /**
1685 * Return the height of the exported region
1686 */
1687 Glib::ustring getDestinationUnits()
1688 { return destUnitsSpinner.getUnitAbbr(); }
1690 /**
1691 * Return the destination DPI image resulution, if bitmap
1692 */
1693 double getDestinationDPI()
1694 { return destDPISpinner.getValue(); }
1696 /**
1697 * Return whether we should use Cairo for rendering
1698 */
1699 bool getUseCairo()
1700 { return cairoButton.get_active(); }
1702 /**
1703 * Return whether we should use antialiasing
1704 */
1705 bool getUseAntialias()
1706 { return antiAliasButton.get_active(); }
1708 /**
1709 * Return the background color for exporting
1710 */
1711 unsigned long getBackground()
1712 { return backgroundButton.get_color().get_pixel(); }
1714 private:
1716 /**
1717 * Fix to allow the user to type the file name
1718 */
1719 Gtk::Entry *fileNameEntry;
1721 //##########################################
1722 //# EXTRA WIDGET -- SOURCE SIDE
1723 //##########################################
1725 Gtk::Frame sourceFrame;
1726 Gtk::VBox sourceBox;
1728 Gtk::HBox scopeBox;
1729 Gtk::RadioButtonGroup scopeGroup;
1730 Gtk::RadioButton documentButton;
1731 Gtk::RadioButton pageButton;
1732 Gtk::RadioButton selectionButton;
1733 Gtk::RadioButton customButton;
1735 Gtk::Table sourceTable;
1736 Inkscape::UI::Widget::Scalar sourceX0Spinner;
1737 Inkscape::UI::Widget::Scalar sourceY0Spinner;
1738 Inkscape::UI::Widget::Scalar sourceX1Spinner;
1739 Inkscape::UI::Widget::Scalar sourceY1Spinner;
1740 Inkscape::UI::Widget::Scalar sourceWidthSpinner;
1741 Inkscape::UI::Widget::Scalar sourceHeightSpinner;
1742 Inkscape::UI::Widget::UnitMenu sourceUnitsSpinner;
1745 //##########################################
1746 //# EXTRA WIDGET -- DESTINATION SIDE
1747 //##########################################
1749 Gtk::Frame destFrame;
1750 Gtk::VBox destBox;
1752 Gtk::Table destTable;
1753 Inkscape::UI::Widget::Scalar destWidthSpinner;
1754 Inkscape::UI::Widget::Scalar destHeightSpinner;
1755 Inkscape::UI::Widget::Scalar destDPISpinner;
1756 Inkscape::UI::Widget::UnitMenu destUnitsSpinner;
1758 Gtk::HBox otherOptionBox;
1759 Gtk::CheckButton cairoButton;
1760 Gtk::CheckButton antiAliasButton;
1761 Gtk::ColorButton backgroundButton;
1764 /**
1765 * 'Extra' widget that holds two boxes above
1766 */
1767 Gtk::HBox exportOptionsBox;
1770 //# Child widgets
1771 Gtk::CheckButton fileTypeCheckbox;
1773 /**
1774 * Allow the specification of the output file type
1775 */
1776 Gtk::ComboBoxText fileTypeComboBox;
1779 /**
1780 * Data mirror of the combo box
1781 */
1782 std::vector<FileType> fileTypes;
1786 /**
1787 * Callback for user input into fileNameEntry
1788 */
1789 void fileTypeChangedCallback();
1791 /**
1792 * Create a filter menu for this type of dialog
1793 */
1794 void createFileTypeMenu();
1797 bool append_extension;
1799 /**
1800 * The extension to use to write this file
1801 */
1802 Inkscape::Extension::Extension *extension;
1804 /**
1805 * Callback for user input into fileNameEntry
1806 */
1807 void fileNameEntryChangedCallback();
1809 /**
1810 * Filename that was given
1811 */
1812 Glib::ustring myFilename;
1813 };
1820 /**
1821 * Callback for fileNameEntry widget
1822 */
1823 void FileExportDialogImpl::fileNameEntryChangedCallback()
1824 {
1825 if (!fileNameEntry)
1826 return;
1828 Glib::ustring fileName = fileNameEntry->get_text();
1829 if (!Glib::get_charset()) //If we are not utf8
1830 fileName = Glib::filename_to_utf8(fileName);
1832 //g_message("User hit return. Text is '%s'\n", fileName.c_str());
1834 if (!Glib::path_is_absolute(fileName)) {
1835 //try appending to the current path
1836 // not this way: fileName = get_current_folder() + "/" + fileName;
1837 std::vector<Glib::ustring> pathSegments;
1838 pathSegments.push_back( get_current_folder() );
1839 pathSegments.push_back( fileName );
1840 fileName = Glib::build_filename(pathSegments);
1841 }
1843 //g_message("path:'%s'\n", fileName.c_str());
1845 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1846 set_current_folder(fileName);
1847 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1848 //dialog with either (1) select a regular file or (2) cd to dir
1849 //simulate an 'OK'
1850 set_filename(fileName);
1851 response(Gtk::RESPONSE_OK);
1852 }
1853 }
1857 /**
1858 * Callback for fileNameEntry widget
1859 */
1860 void FileExportDialogImpl::fileTypeChangedCallback()
1861 {
1862 int sel = fileTypeComboBox.get_active_row_number();
1863 if (sel<0 || sel >= (int)fileTypes.size())
1864 return;
1865 FileType type = fileTypes[sel];
1866 //g_message("selected: %s\n", type.name.c_str());
1867 Gtk::FileFilter filter;
1868 filter.add_pattern(type.pattern);
1869 set_filter(filter);
1870 }
1874 void FileExportDialogImpl::createFileTypeMenu()
1875 {
1876 Inkscape::Extension::DB::OutputList extension_list;
1877 Inkscape::Extension::db.get_output_list(extension_list);
1879 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1880 current_item != extension_list.end(); current_item++)
1881 {
1882 Inkscape::Extension::Output * omod = *current_item;
1884 // FIXME: would be nice to grey them out instead of not listing them
1885 if (omod->deactivated()) continue;
1887 FileType type;
1888 type.name = (_(omod->get_filetypename()));
1889 type.pattern = "*";
1890 Glib::ustring extension = omod->get_extension();
1891 fileDialogExtensionToPattern (type.pattern, extension);
1892 type.extension= omod;
1893 fileTypeComboBox.append_text(type.name);
1894 fileTypes.push_back(type);
1895 }
1897 //#Let user choose
1898 FileType guessType;
1899 guessType.name = _("Guess from extension");
1900 guessType.pattern = "*";
1901 guessType.extension = NULL;
1902 fileTypeComboBox.append_text(guessType.name);
1903 fileTypes.push_back(guessType);
1906 fileTypeComboBox.set_active(0);
1907 fileTypeChangedCallback(); //call at least once to set the filter
1908 }
1911 /**
1912 * Constructor
1913 */
1914 FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir,
1915 FileDialogType fileTypes,
1916 const Glib::ustring &title,
1917 const Glib::ustring &default_key) :
1918 FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),
1919 sourceX0Spinner("X0", _("Left edge of source")),
1920 sourceY0Spinner("Y0", _("Top edge of source")),
1921 sourceX1Spinner("X1", _("Right edge of source")),
1922 sourceY1Spinner("Y1", _("Bottom edge of source")),
1923 sourceWidthSpinner("Width", _("Source width")),
1924 sourceHeightSpinner("Height", _("Source height")),
1925 destWidthSpinner("Width", _("Destination width")),
1926 destHeightSpinner("Height", _("Destination height")),
1927 destDPISpinner("DPI", _("Resolution (dots per inch)"))
1928 {
1929 append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);
1931 /* One file at a time */
1932 set_select_multiple(false);
1934 #ifdef WITH_GNOME_VFS
1935 set_local_only(false);
1936 #endif
1938 /* Initalize to Autodetect */
1939 extension = NULL;
1940 /* No filename to start out with */
1941 myFilename = "";
1943 /* Set our dialog type (save, export, etc...)*/
1944 dialogType = fileTypes;
1946 /* Set the pwd and/or the filename */
1947 if (dir.size()>0)
1948 {
1949 Glib::ustring udir(dir);
1950 Glib::ustring::size_type len = udir.length();
1951 // leaving a trailing backslash on the directory name leads to the infamous
1952 // double-directory bug on win32
1953 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1954 set_current_folder(udir.c_str());
1955 }
1957 //#########################################
1958 //## EXTRA WIDGET -- SOURCE SIDE
1959 //#########################################
1961 //##### Export options buttons/spinners, etc
1962 documentButton.set_label(_("Document"));
1963 scopeBox.pack_start(documentButton);
1964 scopeGroup = documentButton.get_group();
1966 pageButton.set_label(_("Page"));
1967 pageButton.set_group(scopeGroup);
1968 scopeBox.pack_start(pageButton);
1970 selectionButton.set_label(_("Selection"));
1971 selectionButton.set_group(scopeGroup);
1972 scopeBox.pack_start(selectionButton);
1974 customButton.set_label(_("Custom"));
1975 customButton.set_group(scopeGroup);
1976 scopeBox.pack_start(customButton);
1978 sourceBox.pack_start(scopeBox);
1982 //dimension buttons
1983 sourceTable.resize(3,3);
1984 sourceTable.attach(sourceX0Spinner, 0,1,0,1);
1985 sourceTable.attach(sourceY0Spinner, 1,2,0,1);
1986 sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
1987 sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);
1988 sourceTable.attach(sourceX1Spinner, 0,1,1,2);
1989 sourceTable.attach(sourceY1Spinner, 1,2,1,2);
1990 sourceTable.attach(sourceWidthSpinner, 0,1,2,3);
1991 sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
1993 sourceBox.pack_start(sourceTable);
1994 sourceFrame.set_label(_("Source"));
1995 sourceFrame.add(sourceBox);
1996 exportOptionsBox.pack_start(sourceFrame);
1999 //#########################################
2000 //## EXTRA WIDGET -- SOURCE SIDE
2001 //#########################################
2004 destTable.resize(3,3);
2005 destTable.attach(destWidthSpinner, 0,1,0,1);
2006 destTable.attach(destHeightSpinner, 1,2,0,1);
2007 destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
2008 destTable.attach(destUnitsSpinner, 2,3,0,1);
2009 destTable.attach(destDPISpinner, 0,1,1,2);
2011 destBox.pack_start(destTable);
2014 cairoButton.set_label(_("Cairo"));
2015 otherOptionBox.pack_start(cairoButton);
2017 antiAliasButton.set_label(_("Antialias"));
2018 otherOptionBox.pack_start(antiAliasButton);
2020 backgroundButton.set_label(_("Background"));
2021 otherOptionBox.pack_start(backgroundButton);
2023 destBox.pack_start(otherOptionBox);
2029 //###### File options
2030 //###### Do we want the .xxx extension automatically added?
2031 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
2032 fileTypeCheckbox.set_active(append_extension);
2033 destBox.pack_start(fileTypeCheckbox);
2035 //###### File type menu
2036 createFileTypeMenu();
2037 fileTypeComboBox.set_size_request(200,40);
2038 fileTypeComboBox.signal_changed().connect(
2039 sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
2041 destBox.pack_start(fileTypeComboBox);
2043 destFrame.set_label(_("Destination"));
2044 destFrame.add(destBox);
2045 exportOptionsBox.pack_start(destFrame);
2047 //##### Put the two boxes and their parent onto the dialog
2048 exportOptionsBox.pack_start(sourceFrame);
2049 exportOptionsBox.pack_start(destFrame);
2051 set_extra_widget(exportOptionsBox);
2056 //Let's do some customization
2057 fileNameEntry = NULL;
2058 Gtk::Container *cont = get_toplevel();
2059 std::vector<Gtk::Entry *> entries;
2060 findEntryWidgets(cont, entries);
2061 //g_message("Found %d entry widgets\n", entries.size());
2062 if (entries.size() >=1 )
2063 {
2064 //Catch when user hits [return] on the text field
2065 fileNameEntry = entries[0];
2066 fileNameEntry->signal_activate().connect(
2067 sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
2068 }
2070 //Let's do more customization
2071 std::vector<Gtk::Expander *> expanders;
2072 findExpanderWidgets(cont, expanders);
2073 //g_message("Found %d expander widgets\n", expanders.size());
2074 if (expanders.size() >=1 )
2075 {
2076 //Always show the file list
2077 Gtk::Expander *expander = expanders[0];
2078 expander->set_expanded(true);
2079 }
2082 //if (extension == NULL)
2083 // checkbox.set_sensitive(FALSE);
2085 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2086 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
2088 show_all_children();
2089 }
2093 /**
2094 * Public factory method. Used in file.cpp
2095 */
2096 FileExportDialog *FileExportDialog::create(const Glib::ustring &path,
2097 FileDialogType fileTypes,
2098 const Glib::ustring &title,
2099 const Glib::ustring &default_key)
2100 {
2101 FileExportDialog *dialog = new FileExportDialogImpl(path, fileTypes, title, default_key);
2102 return dialog;
2103 }
2109 /**
2110 * Destructor
2111 */
2112 FileExportDialogImpl::~FileExportDialogImpl()
2113 {
2114 }
2118 /**
2119 * Show this dialog modally. Return true if user hits [OK]
2120 */
2121 bool
2122 FileExportDialogImpl::show()
2123 {
2124 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
2125 if (s.length() == 0)
2126 s = getcwd (NULL, 0);
2127 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
2128 set_modal (TRUE); //Window
2129 sp_transientize((GtkWidget *)gobj()); //Make transient
2130 gint b = run(); //Dialog
2131 svgPreview.showNoPreview();
2132 hide();
2134 if (b == Gtk::RESPONSE_OK)
2135 {
2136 int sel = fileTypeComboBox.get_active_row_number ();
2137 if (sel>=0 && sel< (int)fileTypes.size())
2138 {
2139 FileType &type = fileTypes[sel];
2140 extension = type.extension;
2141 }
2142 myFilename = get_filename();
2143 #ifdef WITH_GNOME_VFS
2144 if (myFilename.length() < 1)
2145 myFilename = get_uri();
2146 #endif
2148 /*
2150 // FIXME: Why do we have more code
2152 append_extension = checkbox.get_active();
2153 prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
2154 prefs_set_string_attribute("dialogs.save_as", "default",
2155 ( extension != NULL ? extension->get_id() : "" ));
2156 */
2157 return TRUE;
2158 }
2159 else
2160 {
2161 return FALSE;
2162 }
2163 }
2166 /**
2167 * Get the file extension type that was selected by the user. Valid after an [OK]
2168 */
2169 Inkscape::Extension::Extension *
2170 FileExportDialogImpl::getSelectionType()
2171 {
2172 return extension;
2173 }
2176 /**
2177 * Get the file name chosen by the user. Valid after an [OK]
2178 */
2179 Glib::ustring
2180 FileExportDialogImpl::getFilename()
2181 {
2182 return myFilename;
2183 }
2188 } //namespace Dialog
2189 } //namespace UI
2190 } //namespace Inkscape
2193 /*
2194 Local Variables:
2195 mode:c++
2196 c-file-style:"stroustrup"
2197 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2198 indent-tabs-mode:nil
2199 fill-column:99
2200 End:
2201 */
2202 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :