1ab500863250a2267019703959448a3521db4df9
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 extension = key;
1469 // If no pointer to extension is passed in, look up based on filename extension.
1470 if ( !extension ) {
1471 // Not quite UTF-8 here.
1472 gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
1473 for ( int i = 0; !extension && (i < (int)fileTypes.size()); i++ ) {
1474 Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
1475 if ( ext && ext->get_extension() ) {
1476 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
1477 if ( g_str_has_suffix(filenameLower, extensionLower) ) {
1478 extension = fileTypes[i].extension;
1479 }
1480 g_free(extensionLower);
1481 }
1482 }
1483 g_free(filenameLower);
1484 }
1486 // Ensure the proper entry in the combo box is selected.
1487 if ( extension ) {
1488 gchar const * extensionID = extension->get_id();
1489 if ( extensionID ) {
1490 for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
1491 Inkscape::Extension::Extension *ext = fileTypes[i].extension;
1492 if ( ext ) {
1493 gchar const * id = ext->get_id();
1494 if ( id && ( strcmp(extensionID, id) == 0) ) {
1495 int oldSel = fileTypeComboBox.get_active_row_number();
1496 if ( i != oldSel ) {
1497 fileTypeComboBox.set_active(i);
1498 }
1499 break;
1500 }
1501 }
1502 }
1503 }
1504 }
1505 }
1508 /**
1509 * Get the file name chosen by the user. Valid after an [OK]
1510 */
1511 Glib::ustring
1512 FileSaveDialogImpl::getFilename()
1513 {
1514 return myFilename;
1515 }
1518 void
1519 FileSaveDialogImpl::change_title(const Glib::ustring& title)
1520 {
1521 this->set_title(title);
1522 }
1524 /**
1525 * Change the default save path location.
1526 */
1527 void
1528 FileSaveDialogImpl::change_path(const Glib::ustring& path)
1529 {
1530 myFilename = path;
1531 if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
1532 //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
1533 set_current_folder(myFilename);
1534 } else {
1535 //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
1536 if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
1537 set_filename(myFilename);
1538 } else {
1539 std::string dirName = Glib::path_get_dirname( myFilename );
1540 if ( dirName != get_current_folder() ) {
1541 set_current_folder(dirName);
1542 }
1543 }
1544 Glib::ustring basename = Glib::path_get_basename(myFilename);
1545 //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
1546 try {
1547 set_current_name( Glib::filename_to_utf8(basename) );
1548 } catch ( Glib::ConvertError& e ) {
1549 g_warning( "Error converting save filename to UTF-8." );
1550 // try a fallback.
1551 set_current_name( basename );
1552 }
1553 }
1554 }
1556 void FileSaveDialogImpl::updateNameAndExtension()
1557 {
1558 // Pick up any changes the user has typed in.
1559 Glib::ustring tmp = get_filename();
1560 #ifdef WITH_GNOME_VFS
1561 if ( tmp.empty() ) {
1562 tmp = get_uri();
1563 }
1564 #endif
1565 if ( !tmp.empty() ) {
1566 myFilename = tmp;
1567 }
1569 Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
1570 if ( fileTypeCheckbox.get_active() && newOut ) {
1571 try {
1572 bool appendExtension = true;
1573 Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
1574 Glib::ustring::size_type pos = utf8Name.rfind('.');
1575 if ( pos != Glib::ustring::npos ) {
1576 Glib::ustring trail = utf8Name.substr( pos );
1577 Glib::ustring foldedTrail = trail.casefold();
1578 if ( (trail == ".")
1579 | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()
1580 && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {
1581 utf8Name = utf8Name.erase( pos );
1582 } else {
1583 appendExtension = false;
1584 }
1585 }
1587 if (appendExtension) {
1588 utf8Name = utf8Name + newOut->get_extension();
1589 myFilename = Glib::filename_from_utf8( utf8Name );
1590 change_path(myFilename);
1591 }
1592 } catch ( Glib::ConvertError& e ) {
1593 // ignore
1594 }
1595 }
1596 }
1600 //########################################################################
1601 //# F I L E E X P O R T
1602 //########################################################################
1605 /**
1606 * Our implementation of the FileExportDialog interface.
1607 */
1608 class FileExportDialogImpl : public FileExportDialog, public FileDialogBase
1609 {
1611 public:
1612 FileExportDialogImpl(const Glib::ustring &dir,
1613 FileDialogType fileTypes,
1614 const Glib::ustring &title,
1615 const Glib::ustring &default_key);
1617 virtual ~FileExportDialogImpl();
1619 bool show();
1621 Inkscape::Extension::Extension *getSelectionType();
1623 Glib::ustring getFilename();
1626 /**
1627 * Return the scope of the export. One of the enumerated types
1628 * in ScopeType
1629 */
1630 ScopeType getScope()
1631 {
1632 if (pageButton.get_active())
1633 return SCOPE_PAGE;
1634 else if (selectionButton.get_active())
1635 return SCOPE_SELECTION;
1636 else if (customButton.get_active())
1637 return SCOPE_CUSTOM;
1638 else
1639 return SCOPE_DOCUMENT;
1641 }
1643 /**
1644 * Return left side of the exported region
1645 */
1646 double getSourceX()
1647 { return sourceX0Spinner.getValue(); }
1649 /**
1650 * Return the top of the exported region
1651 */
1652 double getSourceY()
1653 { return sourceY1Spinner.getValue(); }
1655 /**
1656 * Return the width of the exported region
1657 */
1658 double getSourceWidth()
1659 { return sourceWidthSpinner.getValue(); }
1661 /**
1662 * Return the height of the exported region
1663 */
1664 double getSourceHeight()
1665 { return sourceHeightSpinner.getValue(); }
1667 /**
1668 * Return the units of the coordinates of exported region
1669 */
1670 Glib::ustring getSourceUnits()
1671 { return sourceUnitsSpinner.getUnitAbbr(); }
1673 /**
1674 * Return the width of the destination document
1675 */
1676 double getDestinationWidth()
1677 { return destWidthSpinner.getValue(); }
1679 /**
1680 * Return the height of the destination document
1681 */
1682 double getDestinationHeight()
1683 { return destHeightSpinner.getValue(); }
1685 /**
1686 * Return the height of the exported region
1687 */
1688 Glib::ustring getDestinationUnits()
1689 { return destUnitsSpinner.getUnitAbbr(); }
1691 /**
1692 * Return the destination DPI image resulution, if bitmap
1693 */
1694 double getDestinationDPI()
1695 { return destDPISpinner.getValue(); }
1697 /**
1698 * Return whether we should use Cairo for rendering
1699 */
1700 bool getUseCairo()
1701 { return cairoButton.get_active(); }
1703 /**
1704 * Return whether we should use antialiasing
1705 */
1706 bool getUseAntialias()
1707 { return antiAliasButton.get_active(); }
1709 /**
1710 * Return the background color for exporting
1711 */
1712 unsigned long getBackground()
1713 { return backgroundButton.get_color().get_pixel(); }
1715 private:
1717 /**
1718 * Fix to allow the user to type the file name
1719 */
1720 Gtk::Entry *fileNameEntry;
1722 //##########################################
1723 //# EXTRA WIDGET -- SOURCE SIDE
1724 //##########################################
1726 Gtk::Frame sourceFrame;
1727 Gtk::VBox sourceBox;
1729 Gtk::HBox scopeBox;
1730 Gtk::RadioButtonGroup scopeGroup;
1731 Gtk::RadioButton documentButton;
1732 Gtk::RadioButton pageButton;
1733 Gtk::RadioButton selectionButton;
1734 Gtk::RadioButton customButton;
1736 Gtk::Table sourceTable;
1737 Inkscape::UI::Widget::Scalar sourceX0Spinner;
1738 Inkscape::UI::Widget::Scalar sourceY0Spinner;
1739 Inkscape::UI::Widget::Scalar sourceX1Spinner;
1740 Inkscape::UI::Widget::Scalar sourceY1Spinner;
1741 Inkscape::UI::Widget::Scalar sourceWidthSpinner;
1742 Inkscape::UI::Widget::Scalar sourceHeightSpinner;
1743 Inkscape::UI::Widget::UnitMenu sourceUnitsSpinner;
1746 //##########################################
1747 //# EXTRA WIDGET -- DESTINATION SIDE
1748 //##########################################
1750 Gtk::Frame destFrame;
1751 Gtk::VBox destBox;
1753 Gtk::Table destTable;
1754 Inkscape::UI::Widget::Scalar destWidthSpinner;
1755 Inkscape::UI::Widget::Scalar destHeightSpinner;
1756 Inkscape::UI::Widget::Scalar destDPISpinner;
1757 Inkscape::UI::Widget::UnitMenu destUnitsSpinner;
1759 Gtk::HBox otherOptionBox;
1760 Gtk::CheckButton cairoButton;
1761 Gtk::CheckButton antiAliasButton;
1762 Gtk::ColorButton backgroundButton;
1765 /**
1766 * 'Extra' widget that holds two boxes above
1767 */
1768 Gtk::HBox exportOptionsBox;
1771 //# Child widgets
1772 Gtk::CheckButton fileTypeCheckbox;
1774 /**
1775 * Allow the specification of the output file type
1776 */
1777 Gtk::ComboBoxText fileTypeComboBox;
1780 /**
1781 * Data mirror of the combo box
1782 */
1783 std::vector<FileType> fileTypes;
1787 /**
1788 * Callback for user input into fileNameEntry
1789 */
1790 void fileTypeChangedCallback();
1792 /**
1793 * Create a filter menu for this type of dialog
1794 */
1795 void createFileTypeMenu();
1798 bool append_extension;
1800 /**
1801 * The extension to use to write this file
1802 */
1803 Inkscape::Extension::Extension *extension;
1805 /**
1806 * Callback for user input into fileNameEntry
1807 */
1808 void fileNameEntryChangedCallback();
1810 /**
1811 * Filename that was given
1812 */
1813 Glib::ustring myFilename;
1814 };
1821 /**
1822 * Callback for fileNameEntry widget
1823 */
1824 void FileExportDialogImpl::fileNameEntryChangedCallback()
1825 {
1826 if (!fileNameEntry)
1827 return;
1829 Glib::ustring fileName = fileNameEntry->get_text();
1830 if (!Glib::get_charset()) //If we are not utf8
1831 fileName = Glib::filename_to_utf8(fileName);
1833 //g_message("User hit return. Text is '%s'\n", fileName.c_str());
1835 if (!Glib::path_is_absolute(fileName)) {
1836 //try appending to the current path
1837 // not this way: fileName = get_current_folder() + "/" + fileName;
1838 std::vector<Glib::ustring> pathSegments;
1839 pathSegments.push_back( get_current_folder() );
1840 pathSegments.push_back( fileName );
1841 fileName = Glib::build_filename(pathSegments);
1842 }
1844 //g_message("path:'%s'\n", fileName.c_str());
1846 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1847 set_current_folder(fileName);
1848 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1849 //dialog with either (1) select a regular file or (2) cd to dir
1850 //simulate an 'OK'
1851 set_filename(fileName);
1852 response(Gtk::RESPONSE_OK);
1853 }
1854 }
1858 /**
1859 * Callback for fileNameEntry widget
1860 */
1861 void FileExportDialogImpl::fileTypeChangedCallback()
1862 {
1863 int sel = fileTypeComboBox.get_active_row_number();
1864 if (sel<0 || sel >= (int)fileTypes.size())
1865 return;
1866 FileType type = fileTypes[sel];
1867 //g_message("selected: %s\n", type.name.c_str());
1868 Gtk::FileFilter filter;
1869 filter.add_pattern(type.pattern);
1870 set_filter(filter);
1871 }
1875 void FileExportDialogImpl::createFileTypeMenu()
1876 {
1877 Inkscape::Extension::DB::OutputList extension_list;
1878 Inkscape::Extension::db.get_output_list(extension_list);
1880 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1881 current_item != extension_list.end(); current_item++)
1882 {
1883 Inkscape::Extension::Output * omod = *current_item;
1885 // FIXME: would be nice to grey them out instead of not listing them
1886 if (omod->deactivated()) continue;
1888 FileType type;
1889 type.name = (_(omod->get_filetypename()));
1890 type.pattern = "*";
1891 Glib::ustring extension = omod->get_extension();
1892 fileDialogExtensionToPattern (type.pattern, extension);
1893 type.extension= omod;
1894 fileTypeComboBox.append_text(type.name);
1895 fileTypes.push_back(type);
1896 }
1898 //#Let user choose
1899 FileType guessType;
1900 guessType.name = _("Guess from extension");
1901 guessType.pattern = "*";
1902 guessType.extension = NULL;
1903 fileTypeComboBox.append_text(guessType.name);
1904 fileTypes.push_back(guessType);
1907 fileTypeComboBox.set_active(0);
1908 fileTypeChangedCallback(); //call at least once to set the filter
1909 }
1912 /**
1913 * Constructor
1914 */
1915 FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir,
1916 FileDialogType fileTypes,
1917 const Glib::ustring &title,
1918 const Glib::ustring &default_key) :
1919 FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),
1920 sourceX0Spinner("X0", _("Left edge of source")),
1921 sourceY0Spinner("Y0", _("Top edge of source")),
1922 sourceX1Spinner("X1", _("Right edge of source")),
1923 sourceY1Spinner("Y1", _("Bottom edge of source")),
1924 sourceWidthSpinner("Width", _("Source width")),
1925 sourceHeightSpinner("Height", _("Source height")),
1926 destWidthSpinner("Width", _("Destination width")),
1927 destHeightSpinner("Height", _("Destination height")),
1928 destDPISpinner("DPI", _("Resolution (dots per inch)"))
1929 {
1930 append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);
1932 /* One file at a time */
1933 set_select_multiple(false);
1935 #ifdef WITH_GNOME_VFS
1936 set_local_only(false);
1937 #endif
1939 /* Initalize to Autodetect */
1940 extension = NULL;
1941 /* No filename to start out with */
1942 myFilename = "";
1944 /* Set our dialog type (save, export, etc...)*/
1945 dialogType = fileTypes;
1947 /* Set the pwd and/or the filename */
1948 if (dir.size()>0)
1949 {
1950 Glib::ustring udir(dir);
1951 Glib::ustring::size_type len = udir.length();
1952 // leaving a trailing backslash on the directory name leads to the infamous
1953 // double-directory bug on win32
1954 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1955 set_current_folder(udir.c_str());
1956 }
1958 //#########################################
1959 //## EXTRA WIDGET -- SOURCE SIDE
1960 //#########################################
1962 //##### Export options buttons/spinners, etc
1963 documentButton.set_label(_("Document"));
1964 scopeBox.pack_start(documentButton);
1965 scopeGroup = documentButton.get_group();
1967 pageButton.set_label(_("Page"));
1968 pageButton.set_group(scopeGroup);
1969 scopeBox.pack_start(pageButton);
1971 selectionButton.set_label(_("Selection"));
1972 selectionButton.set_group(scopeGroup);
1973 scopeBox.pack_start(selectionButton);
1975 customButton.set_label(_("Custom"));
1976 customButton.set_group(scopeGroup);
1977 scopeBox.pack_start(customButton);
1979 sourceBox.pack_start(scopeBox);
1983 //dimension buttons
1984 sourceTable.resize(3,3);
1985 sourceTable.attach(sourceX0Spinner, 0,1,0,1);
1986 sourceTable.attach(sourceY0Spinner, 1,2,0,1);
1987 sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
1988 sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);
1989 sourceTable.attach(sourceX1Spinner, 0,1,1,2);
1990 sourceTable.attach(sourceY1Spinner, 1,2,1,2);
1991 sourceTable.attach(sourceWidthSpinner, 0,1,2,3);
1992 sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
1994 sourceBox.pack_start(sourceTable);
1995 sourceFrame.set_label(_("Source"));
1996 sourceFrame.add(sourceBox);
1997 exportOptionsBox.pack_start(sourceFrame);
2000 //#########################################
2001 //## EXTRA WIDGET -- SOURCE SIDE
2002 //#########################################
2005 destTable.resize(3,3);
2006 destTable.attach(destWidthSpinner, 0,1,0,1);
2007 destTable.attach(destHeightSpinner, 1,2,0,1);
2008 destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
2009 destTable.attach(destUnitsSpinner, 2,3,0,1);
2010 destTable.attach(destDPISpinner, 0,1,1,2);
2012 destBox.pack_start(destTable);
2015 cairoButton.set_label(_("Cairo"));
2016 otherOptionBox.pack_start(cairoButton);
2018 antiAliasButton.set_label(_("Antialias"));
2019 otherOptionBox.pack_start(antiAliasButton);
2021 backgroundButton.set_label(_("Background"));
2022 otherOptionBox.pack_start(backgroundButton);
2024 destBox.pack_start(otherOptionBox);
2030 //###### File options
2031 //###### Do we want the .xxx extension automatically added?
2032 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
2033 fileTypeCheckbox.set_active(append_extension);
2034 destBox.pack_start(fileTypeCheckbox);
2036 //###### File type menu
2037 createFileTypeMenu();
2038 fileTypeComboBox.set_size_request(200,40);
2039 fileTypeComboBox.signal_changed().connect(
2040 sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
2042 destBox.pack_start(fileTypeComboBox);
2044 destFrame.set_label(_("Destination"));
2045 destFrame.add(destBox);
2046 exportOptionsBox.pack_start(destFrame);
2048 //##### Put the two boxes and their parent onto the dialog
2049 exportOptionsBox.pack_start(sourceFrame);
2050 exportOptionsBox.pack_start(destFrame);
2052 set_extra_widget(exportOptionsBox);
2057 //Let's do some customization
2058 fileNameEntry = NULL;
2059 Gtk::Container *cont = get_toplevel();
2060 std::vector<Gtk::Entry *> entries;
2061 findEntryWidgets(cont, entries);
2062 //g_message("Found %d entry widgets\n", entries.size());
2063 if (entries.size() >=1 )
2064 {
2065 //Catch when user hits [return] on the text field
2066 fileNameEntry = entries[0];
2067 fileNameEntry->signal_activate().connect(
2068 sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
2069 }
2071 //Let's do more customization
2072 std::vector<Gtk::Expander *> expanders;
2073 findExpanderWidgets(cont, expanders);
2074 //g_message("Found %d expander widgets\n", expanders.size());
2075 if (expanders.size() >=1 )
2076 {
2077 //Always show the file list
2078 Gtk::Expander *expander = expanders[0];
2079 expander->set_expanded(true);
2080 }
2083 //if (extension == NULL)
2084 // checkbox.set_sensitive(FALSE);
2086 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2087 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
2089 show_all_children();
2090 }
2094 /**
2095 * Public factory method. Used in file.cpp
2096 */
2097 FileExportDialog *FileExportDialog::create(const Glib::ustring &path,
2098 FileDialogType fileTypes,
2099 const Glib::ustring &title,
2100 const Glib::ustring &default_key)
2101 {
2102 FileExportDialog *dialog = new FileExportDialogImpl(path, fileTypes, title, default_key);
2103 return dialog;
2104 }
2110 /**
2111 * Destructor
2112 */
2113 FileExportDialogImpl::~FileExportDialogImpl()
2114 {
2115 }
2119 /**
2120 * Show this dialog modally. Return true if user hits [OK]
2121 */
2122 bool
2123 FileExportDialogImpl::show()
2124 {
2125 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
2126 if (s.length() == 0)
2127 s = getcwd (NULL, 0);
2128 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
2129 set_modal (TRUE); //Window
2130 sp_transientize((GtkWidget *)gobj()); //Make transient
2131 gint b = run(); //Dialog
2132 svgPreview.showNoPreview();
2133 hide();
2135 if (b == Gtk::RESPONSE_OK)
2136 {
2137 int sel = fileTypeComboBox.get_active_row_number ();
2138 if (sel>=0 && sel< (int)fileTypes.size())
2139 {
2140 FileType &type = fileTypes[sel];
2141 extension = type.extension;
2142 }
2143 myFilename = get_filename();
2144 #ifdef WITH_GNOME_VFS
2145 if (myFilename.length() < 1)
2146 myFilename = get_uri();
2147 #endif
2149 /*
2151 // FIXME: Why do we have more code
2153 append_extension = checkbox.get_active();
2154 prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
2155 prefs_set_string_attribute("dialogs.save_as", "default",
2156 ( extension != NULL ? extension->get_id() : "" ));
2157 */
2158 return TRUE;
2159 }
2160 else
2161 {
2162 return FALSE;
2163 }
2164 }
2167 /**
2168 * Get the file extension type that was selected by the user. Valid after an [OK]
2169 */
2170 Inkscape::Extension::Extension *
2171 FileExportDialogImpl::getSelectionType()
2172 {
2173 return extension;
2174 }
2177 /**
2178 * Get the file name chosen by the user. Valid after an [OK]
2179 */
2180 Glib::ustring
2181 FileExportDialogImpl::getFilename()
2182 {
2183 return myFilename;
2184 }
2189 } //namespace Dialog
2190 } //namespace UI
2191 } //namespace Inkscape
2194 /*
2195 Local Variables:
2196 mode:c++
2197 c-file-style:"stroustrup"
2198 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2199 indent-tabs-mode:nil
2200 fill-column:99
2201 End:
2202 */
2203 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :