2a5ededbb475bf88fd9f0f35b722587cb484a9fd
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>
37 #ifdef WITH_GNOME_VFS
38 # include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized
39 #endif
43 //Inkscape includes
44 #include "prefs-utils.h"
45 #include <dialogs/dialog-events.h>
46 #include <extension/input.h>
47 #include <extension/output.h>
48 #include <extension/db.h>
49 #include "inkscape.h"
50 #include "svg-view-widget.h"
51 #include "filedialog.h"
52 #include "gc-core.h"
54 //For export dialog
55 #include "ui/widget/scalar-unit.h"
58 //Routines from file.cpp
59 #undef INK_DUMP_FILENAME_CONV
61 #ifdef INK_DUMP_FILENAME_CONV
62 void dump_str( const gchar* str, const gchar* prefix );
63 void dump_ustr( const Glib::ustring& ustr );
64 #endif
68 namespace Inkscape
69 {
70 namespace UI
71 {
72 namespace Dialog
73 {
79 //########################################################################
80 //### U T I L I T Y
81 //########################################################################
83 /**
84 \brief A quick function to turn a standard extension into a searchable
85 pattern for the file dialogs
86 \param pattern The patter that the extension should be written to
87 \param in_file_extension The C string that represents the extension
89 This function just goes through the string, and takes all characters
90 and puts a [<upper><lower>] so that both are searched and shown in
91 the file dialog. This function edits the pattern string to make
92 this happen.
93 */
94 static void
95 fileDialogExtensionToPattern(Glib::ustring &pattern,
96 Glib::ustring &extension)
97 {
98 for (unsigned int i = 0; i < extension.length(); i++ )
99 {
100 Glib::ustring::value_type ch = extension[i];
101 if ( Glib::Unicode::isalpha(ch) )
102 {
103 pattern += '[';
104 pattern += Glib::Unicode::toupper(ch);
105 pattern += Glib::Unicode::tolower(ch);
106 pattern += ']';
107 }
108 else
109 {
110 pattern += ch;
111 }
112 }
113 }
116 /**
117 * Hack: Find all entry widgets in a container
118 */
119 static void
120 findEntryWidgets(Gtk::Container *parent,
121 std::vector<Gtk::Entry *> &result)
122 {
123 if (!parent)
124 return;
125 std::vector<Gtk::Widget *> children = parent->get_children();
126 for (unsigned int i=0; i<children.size() ; i++)
127 {
128 Gtk::Widget *child = children[i];
129 GtkWidget *wid = child->gobj();
130 if (GTK_IS_ENTRY(wid))
131 result.push_back((Gtk::Entry *)child);
132 else if (GTK_IS_CONTAINER(wid))
133 findEntryWidgets((Gtk::Container *)child, result);
134 }
136 }
141 /**
142 * Hack: Find all expander widgets in a container
143 */
144 static void
145 findExpanderWidgets(Gtk::Container *parent,
146 std::vector<Gtk::Expander *> &result)
147 {
148 if (!parent)
149 return;
150 std::vector<Gtk::Widget *> children = parent->get_children();
151 for (unsigned int i=0; i<children.size() ; i++)
152 {
153 Gtk::Widget *child = children[i];
154 GtkWidget *wid = child->gobj();
155 if (GTK_IS_EXPANDER(wid))
156 result.push_back((Gtk::Expander *)child);
157 else if (GTK_IS_CONTAINER(wid))
158 findExpanderWidgets((Gtk::Container *)child, result);
159 }
161 }
164 /*#########################################################################
165 ### SVG Preview Widget
166 #########################################################################*/
168 /**
169 * Simple class for displaying an SVG file in the "preview widget."
170 * Currently, this is just a wrapper of the sp_svg_view Gtk widget.
171 * Hopefully we will eventually replace with a pure Gtkmm widget.
172 */
173 class SVGPreview : public Gtk::VBox
174 {
175 public:
177 SVGPreview();
179 ~SVGPreview();
181 bool setDocument(SPDocument *doc);
183 bool setFileName(Glib::ustring &fileName);
185 bool setFromMem(char const *xmlBuffer);
187 bool set(Glib::ustring &fileName, int dialogType);
189 bool setURI(URI &uri);
191 /**
192 * Show image embedded in SVG
193 */
194 void showImage(Glib::ustring &fileName);
196 /**
197 * Show the "No preview" image
198 */
199 void showNoPreview();
201 /**
202 * Show the "Too large" image
203 */
204 void showTooLarge(long fileLength);
206 private:
207 /**
208 * The svg document we are currently showing
209 */
210 SPDocument *document;
212 /**
213 * The sp_svg_view widget
214 */
215 GtkWidget *viewerGtk;
217 /**
218 * are we currently showing the "no preview" image?
219 */
220 bool showingNoPreview;
222 };
225 bool SVGPreview::setDocument(SPDocument *doc)
226 {
227 if (document)
228 sp_document_unref(document);
230 sp_document_ref(doc);
231 document = doc;
233 //This should remove it from the box, and free resources
234 if (viewerGtk)
235 gtk_widget_destroy(viewerGtk);
237 viewerGtk = sp_svg_view_widget_new(doc);
238 GtkWidget *vbox = (GtkWidget *)gobj();
239 gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);
240 gtk_widget_show(viewerGtk);
242 return true;
243 }
246 bool SVGPreview::setFileName(Glib::ustring &theFileName)
247 {
248 Glib::ustring fileName = theFileName;
250 fileName = Glib::filename_to_utf8(fileName);
252 /**
253 * I don't know why passing false to keepalive is bad. But it
254 * prevents the display of an svg with a non-ascii filename
255 */
256 SPDocument *doc = sp_document_new (fileName.c_str(), true);
257 if (!doc) {
258 g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
259 return false;
260 }
262 setDocument(doc);
264 sp_document_unref(doc);
266 return true;
267 }
271 bool SVGPreview::setFromMem(char const *xmlBuffer)
272 {
273 if (!xmlBuffer)
274 return false;
276 gint len = (gint)strlen(xmlBuffer);
277 SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);
278 if (!doc) {
279 g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);
280 return false;
281 }
283 setDocument(doc);
285 sp_document_unref(doc);
287 Inkscape::GC::request_early_collection();
289 return true;
290 }
294 void SVGPreview::showImage(Glib::ustring &theFileName)
295 {
296 Glib::ustring fileName = theFileName;
299 /*#####################################
300 # LET'S HAVE SOME FUN WITH SVG!
301 # Instead of just loading an image, why
302 # don't we make a lovely little svg and
303 # display it nicely?
304 #####################################*/
306 //Arbitrary size of svg doc -- rather 'portrait' shaped
307 gint previewWidth = 400;
308 gint previewHeight = 600;
310 //Get some image info. Smart pointer does not need to be deleted
311 Glib::RefPtr<Gdk::Pixbuf> img = Gdk::Pixbuf::create_from_file(fileName);
312 gint imgWidth = img->get_width();
313 gint imgHeight = img->get_height();
315 //Find the minimum scale to fit the image inside the preview area
316 double scaleFactorX = (0.9 *(double)previewWidth) / ((double)imgWidth);
317 double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);
318 double scaleFactor = scaleFactorX;
319 if (scaleFactorX > scaleFactorY)
320 scaleFactor = scaleFactorY;
322 //Now get the resized values
323 gint scaledImgWidth = (int) (scaleFactor * (double)imgWidth);
324 gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);
326 //center the image on the area
327 gint imgX = (previewWidth - scaledImgWidth) / 2;
328 gint imgY = (previewHeight - scaledImgHeight) / 2;
330 //wrap a rectangle around the image
331 gint rectX = imgX-1;
332 gint rectY = imgY-1;
333 gint rectWidth = scaledImgWidth +2;
334 gint rectHeight = scaledImgHeight+2;
336 //Our template. Modify to taste
337 gchar const *xformat =
338 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
339 "<svg\n"
340 "xmlns=\"http://www.w3.org/2000/svg\"\n"
341 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
342 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
343 "<rect\n"
344 " style=\"fill:#eeeeee;stroke:none\"\n"
345 " x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
346 "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
347 "xlink:href=\"%s\"/>\n"
348 "<rect\n"
349 " style=\"fill:none;"
350 " stroke:#000000;stroke-width:1.0;"
351 " stroke-linejoin:miter;stroke-opacity:1.0000000;"
352 " stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
353 " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
354 "<text\n"
355 " style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
356 " fill:#000000;fill-opacity:1.0000000;stroke:none;"
357 " font-family:Bitstream Vera Sans\"\n"
358 " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
359 "</svg>\n\n";
361 //if (!Glib::get_charset()) //If we are not utf8
362 fileName = Glib::filename_to_utf8(fileName);
364 //Fill in the template
365 /* FIXME: Do proper XML quoting for fileName. */
366 gchar *xmlBuffer = g_strdup_printf(xformat,
367 previewWidth, previewHeight,
368 imgX, imgY, scaledImgWidth, scaledImgHeight,
369 fileName.c_str(),
370 rectX, rectY, rectWidth, rectHeight,
371 imgWidth, imgHeight);
373 //g_message("%s\n", xmlBuffer);
375 //now show it!
376 setFromMem(xmlBuffer);
377 g_free(xmlBuffer);
378 }
382 void SVGPreview::showNoPreview()
383 {
384 //Are we already showing it?
385 if (showingNoPreview)
386 return;
388 //Arbitrary size of svg doc -- rather 'portrait' shaped
389 gint previewWidth = 300;
390 gint previewHeight = 600;
392 //Our template. Modify to taste
393 gchar const *xformat =
394 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
395 "<svg\n"
396 "xmlns=\"http://www.w3.org/2000/svg\"\n"
397 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
398 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
399 "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
400 "<path\n"
401 "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
402 "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
403 "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
404 "id=\"whiteSpace\" />\n"
405 "<path\n"
406 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
407 "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
408 "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
409 "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
410 "id=\"droplet01\" />\n"
411 "<path\n"
412 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
413 "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
414 "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
415 "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
416 "287.18046 343.1206 286.46194 340.42914 z \"\n"
417 "id=\"droplet02\" />\n"
418 "<path\n"
419 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
420 "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
421 "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
422 "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
423 "id=\"droplet03\" />\n"
424 "<path\n"
425 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
426 "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
427 "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
428 "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
429 "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
430 "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
431 "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
432 "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
433 "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
434 "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
435 "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
436 "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
437 "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
438 "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
439 "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
440 "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
441 "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
442 "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
443 "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
444 "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
445 "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
446 "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
447 "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
448 "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
449 "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
450 "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
451 "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
452 "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
453 "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
454 "id=\"mountainDroplet\" />\n"
455 "</g> <g transform=\"translate(-20,0)\">\n"
456 "<text xml:space=\"preserve\"\n"
457 "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
458 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
459 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
460 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
461 "x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE
462 "</svg>\n\n";
464 //Fill in the template
465 gchar *xmlBuffer = g_strdup_printf(xformat,
466 previewWidth, previewHeight, _("No preview"));
468 //g_message("%s\n", xmlBuffer);
470 //now show it!
471 setFromMem(xmlBuffer);
472 g_free(xmlBuffer);
473 showingNoPreview = true;
475 }
478 /**
479 * Inform the user that the svg file is too large to be displayed.
480 * This does not check for sizes of embedded images (yet)
481 */
482 void SVGPreview::showTooLarge(long fileLength)
483 {
485 //Arbitrary size of svg doc -- rather 'portrait' shaped
486 gint previewWidth = 300;
487 gint previewHeight = 600;
489 //Our template. Modify to taste
490 gchar const *xformat =
491 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
492 "<svg\n"
493 "xmlns=\"http://www.w3.org/2000/svg\"\n"
494 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
495 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
496 "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
497 "<path\n"
498 "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
499 "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
500 "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
501 "id=\"whiteSpace\" />\n"
502 "<path\n"
503 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
504 "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
505 "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
506 "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
507 "id=\"droplet01\" />\n"
508 "<path\n"
509 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
510 "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
511 "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
512 "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
513 "287.18046 343.1206 286.46194 340.42914 z \"\n"
514 "id=\"droplet02\" />\n"
515 "<path\n"
516 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
517 "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
518 "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
519 "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
520 "id=\"droplet03\" />\n"
521 "<path\n"
522 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
523 "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
524 "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
525 "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
526 "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
527 "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
528 "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
529 "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
530 "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
531 "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
532 "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
533 "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
534 "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
535 "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
536 "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
537 "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
538 "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
539 "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
540 "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
541 "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
542 "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
543 "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
544 "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
545 "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
546 "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
547 "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
548 "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
549 "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
550 "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
551 "id=\"mountainDroplet\" />\n"
552 "</g>\n"
553 "<text xml:space=\"preserve\"\n"
554 "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
555 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
556 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
557 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
558 "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE
559 "<text xml:space=\"preserve\"\n"
560 "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
561 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
562 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
563 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
564 "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE
565 "</svg>\n\n";
567 //Fill in the template
568 double floatFileLength = ((double)fileLength) / 1048576.0;
569 //printf("%ld %f\n", fileLength, floatFileLength);
570 gchar *xmlBuffer = g_strdup_printf(xformat,
571 previewWidth, previewHeight, floatFileLength,
572 _("too large for preview"));
574 //g_message("%s\n", xmlBuffer);
576 //now show it!
577 setFromMem(xmlBuffer);
578 g_free(xmlBuffer);
580 }
583 /**
584 * Return true if the string ends with the given suffix
585 */
586 static bool
587 hasSuffix(Glib::ustring &str, Glib::ustring &ext)
588 {
589 int strLen = str.length();
590 int extLen = ext.length();
591 if (extLen > strLen)
592 return false;
593 int strpos = strLen-1;
594 for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)
595 {
596 Glib::ustring::value_type ch = str[strpos];
597 if (ch != ext[extpos])
598 {
599 if ( ((ch & 0xff80) != 0) ||
600 static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )
601 {
602 return false;
603 }
604 }
605 }
606 return true;
607 }
610 /**
611 * Return true if the image is loadable by Gdk, else false
612 */
613 static bool
614 isValidImageFile(Glib::ustring &fileName)
615 {
616 std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();
617 for (unsigned int i=0; i<formats.size(); i++)
618 {
619 Gdk::PixbufFormat format = formats[i];
620 std::vector<Glib::ustring>extensions = format.get_extensions();
621 for (unsigned int j=0; j<extensions.size(); j++)
622 {
623 Glib::ustring ext = extensions[j];
624 if (hasSuffix(fileName, ext))
625 return true;
626 }
627 }
628 return false;
629 }
631 bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
632 {
634 if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
635 return false;
637 //g_message("fname:%s", fileName.c_str());
639 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
640 showNoPreview();
641 return false;
642 }
644 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
645 {
646 Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);
647 gchar *fName = (gchar *)fileNameUtf8.c_str();
648 struct stat info;
649 if (g_stat(fName, &info))
650 {
651 g_warning("SVGPreview::set() : %s : %s",
652 fName, strerror(errno));
653 return FALSE;
654 }
655 long fileLen = info.st_size;
656 if (fileLen > 0x150000L)
657 {
658 showingNoPreview = false;
659 showTooLarge(fileLen);
660 return FALSE;
661 }
662 }
664 Glib::ustring svg = ".svg";
665 Glib::ustring svgz = ".svgz";
667 if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
668 (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) )
669 ) {
670 bool retval = setFileName(fileName);
671 showingNoPreview = false;
672 return retval;
673 } else if (isValidImageFile(fileName)) {
674 showImage(fileName);
675 showingNoPreview = false;
676 return true;
677 } else {
678 showNoPreview();
679 return false;
680 }
681 }
684 SVGPreview::SVGPreview()
685 {
686 if (!INKSCAPE)
687 inkscape_application_init("",false);
688 document = NULL;
689 viewerGtk = NULL;
690 set_size_request(150,150);
691 showingNoPreview = false;
692 }
694 SVGPreview::~SVGPreview()
695 {
697 }
703 /*#########################################################################
704 ### F I L E D I A L O G B A S E C L A S S
705 #########################################################################*/
707 /**
708 * This class is the base implementation for the others. This
709 * reduces redundancies and bugs.
710 */
711 class FileDialogBase : public Gtk::FileChooserDialog
712 {
713 public:
715 /**
716 *
717 */
718 FileDialogBase(const Glib::ustring &title, FileDialogType type, gchar const* preferenceBase) :
719 Gtk::FileChooserDialog(title),
720 preferenceBase(preferenceBase ? preferenceBase : "unknown"),
721 dialogType(type)
722 {
723 internalSetup();
724 }
726 /**
727 *
728 */
729 FileDialogBase(const Glib::ustring &title,
730 Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :
731 Gtk::FileChooserDialog(title, dialogType),
732 preferenceBase(preferenceBase ? preferenceBase : "unknown"),
733 dialogType(type)
734 {
735 internalSetup();
736 }
738 /**
739 *
740 */
741 virtual ~FileDialogBase()
742 {}
744 protected:
745 void cleanup( bool showConfirmed );
747 Glib::ustring preferenceBase;
748 /**
749 * What type of 'open' are we? (open, import, place, etc)
750 */
751 FileDialogType dialogType;
753 /**
754 * Our svg preview widget
755 */
756 SVGPreview svgPreview;
758 //# Child widgets
759 Gtk::CheckButton previewCheckbox;
761 private:
762 void internalSetup();
764 /**
765 * Callback for user changing preview checkbox
766 */
767 void _previewEnabledCB();
769 /**
770 * Callback for seeing if the preview needs to be drawn
771 */
772 void _updatePreviewCallback();
773 };
776 void FileDialogBase::internalSetup()
777 {
778 bool enablePreview =
779 (bool)prefs_get_int_attribute( preferenceBase.c_str(),
780 "enable_preview", 1 );
782 previewCheckbox.set_label( Glib::ustring(_("Enable Preview")) );
783 previewCheckbox.set_active( enablePreview );
785 previewCheckbox.signal_toggled().connect(
786 sigc::mem_fun(*this, &FileDialogBase::_previewEnabledCB) );
788 //Catch selection-changed events, so we can adjust the text widget
789 signal_update_preview().connect(
790 sigc::mem_fun(*this, &FileDialogBase::_updatePreviewCallback) );
792 //###### Add a preview widget
793 set_preview_widget(svgPreview);
794 set_preview_widget_active( enablePreview );
795 set_use_preview_label (false);
797 }
800 void FileDialogBase::cleanup( bool showConfirmed )
801 {
802 if ( showConfirmed )
803 prefs_set_int_attribute( preferenceBase.c_str(),
804 "enable_preview", previewCheckbox.get_active() );
805 }
808 void FileDialogBase::_previewEnabledCB()
809 {
810 bool enabled = previewCheckbox.get_active();
811 set_preview_widget_active(enabled);
812 if ( enabled ) {
813 _updatePreviewCallback();
814 }
815 }
819 /**
820 * Callback for checking if the preview needs to be redrawn
821 */
822 void FileDialogBase::_updatePreviewCallback()
823 {
824 Glib::ustring fileName = get_preview_filename();
826 #ifdef WITH_GNOME_VFS
827 if ( fileName.empty() && gnome_vfs_initialized() ) {
828 fileName = get_preview_uri();
829 }
830 #endif
832 if (fileName.empty()) {
833 return;
834 }
836 svgPreview.set(fileName, dialogType);
837 }
840 /*#########################################################################
841 ### F I L E O P E N
842 #########################################################################*/
844 /**
845 * Our implementation class for the FileOpenDialog interface..
846 */
847 class FileOpenDialogImpl : public FileOpenDialog, public FileDialogBase
848 {
849 public:
851 FileOpenDialogImpl(const Glib::ustring &dir,
852 FileDialogType fileTypes,
853 const Glib::ustring &title);
855 virtual ~FileOpenDialogImpl();
857 bool show();
859 Inkscape::Extension::Extension *getSelectionType();
861 Glib::ustring getFilename();
863 std::vector<Glib::ustring> getFilenames ();
865 private:
867 /**
868 * Create a filter menu for this type of dialog
869 */
870 void createFilterMenu();
872 /**
873 * Filter name->extension lookup
874 */
875 std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;
877 /**
878 * The extension to use to write this file
879 */
880 Inkscape::Extension::Extension *extension;
882 /**
883 * Filename that was given
884 */
885 Glib::ustring myFilename;
887 };
895 void FileOpenDialogImpl::createFilterMenu()
896 {
897 //patterns added dynamically below
898 Gtk::FileFilter allImageFilter;
899 allImageFilter.set_name(_("All Images"));
900 extensionMap[Glib::ustring(_("All Images"))]=NULL;
901 add_filter(allImageFilter);
903 Gtk::FileFilter allFilter;
904 allFilter.set_name(_("All Files"));
905 extensionMap[Glib::ustring(_("All Files"))]=NULL;
906 allFilter.add_pattern("*");
907 add_filter(allFilter);
909 //patterns added dynamically below
910 Gtk::FileFilter allInkscapeFilter;
911 allInkscapeFilter.set_name(_("All Inkscape Files"));
912 extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
913 add_filter(allInkscapeFilter);
915 Inkscape::Extension::DB::InputList extension_list;
916 Inkscape::Extension::db.get_input_list(extension_list);
918 for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
919 current_item != extension_list.end(); current_item++)
920 {
921 Inkscape::Extension::Input * imod = *current_item;
923 // FIXME: would be nice to grey them out instead of not listing them
924 if (imod->deactivated()) continue;
926 Glib::ustring upattern("*");
927 Glib::ustring extension = imod->get_extension();
928 fileDialogExtensionToPattern(upattern, extension);
930 Gtk::FileFilter filter;
931 Glib::ustring uname(_(imod->get_filetypename()));
932 filter.set_name(uname);
933 filter.add_pattern(upattern);
934 add_filter(filter);
935 extensionMap[uname] = imod;
937 //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
938 allInkscapeFilter.add_pattern(upattern);
939 if ( strncmp("image", imod->get_mimetype(), 5)==0 )
940 allImageFilter.add_pattern(upattern);
941 }
943 return;
944 }
948 /**
949 * Constructor. Not called directly. Use the factory.
950 */
951 FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
952 FileDialogType fileTypes,
953 const Glib::ustring &title) :
954 FileDialogBase(title, fileTypes, "dialogs.open")
955 {
958 /* One file at a time */
959 /* And also Multiple Files */
960 set_select_multiple(true);
962 #ifdef WITH_GNOME_VFS
963 if (gnome_vfs_initialized()) {
964 set_local_only(false);
965 }
966 #endif
968 /* Initalize to Autodetect */
969 extension = NULL;
970 /* No filename to start out with */
971 myFilename = "";
973 /* Set our dialog type (open, import, etc...)*/
974 dialogType = fileTypes;
977 /* Set the pwd and/or the filename */
978 if (dir.size() > 0)
979 {
980 Glib::ustring udir(dir);
981 Glib::ustring::size_type len = udir.length();
982 // leaving a trailing backslash on the directory name leads to the infamous
983 // double-directory bug on win32
984 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
985 set_current_folder(udir.c_str());
986 }
989 set_extra_widget( previewCheckbox );
992 //###### Add the file types menu
993 createFilterMenu();
996 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
997 set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
998 }
1004 /**
1005 * Public factory. Called by file.cpp, among others.
1006 */
1007 FileOpenDialog *FileOpenDialog::create(const Glib::ustring &path,
1008 FileDialogType fileTypes,
1009 const Glib::ustring &title)
1010 {
1011 FileOpenDialog *dialog = new FileOpenDialogImpl(path, fileTypes, title);
1012 return dialog;
1013 }
1018 /**
1019 * Destructor
1020 */
1021 FileOpenDialogImpl::~FileOpenDialogImpl()
1022 {
1024 }
1027 /**
1028 * Show this dialog modally. Return true if user hits [OK]
1029 */
1030 bool
1031 FileOpenDialogImpl::show()
1032 {
1033 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
1034 if (s.length() == 0)
1035 s = getcwd (NULL, 0);
1036 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
1037 set_modal (TRUE); //Window
1038 sp_transientize((GtkWidget *)gobj()); //Make transient
1039 gint b = run(); //Dialog
1040 svgPreview.showNoPreview();
1041 hide();
1043 if (b == Gtk::RESPONSE_OK)
1044 {
1045 //This is a hack, to avoid the warning messages that
1046 //Gtk::FileChooser::get_filter() returns
1047 //should be: Gtk::FileFilter *filter = get_filter();
1048 GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
1049 GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
1050 if (filter)
1051 {
1052 //Get which extension was chosen, if any
1053 extension = extensionMap[gtk_file_filter_get_name(filter)];
1054 }
1055 myFilename = get_filename();
1056 #ifdef WITH_GNOME_VFS
1057 if (myFilename.empty() && gnome_vfs_initialized())
1058 myFilename = get_uri();
1059 #endif
1060 cleanup( true );
1061 return TRUE;
1062 }
1063 else
1064 {
1065 cleanup( false );
1066 return FALSE;
1067 }
1068 }
1073 /**
1074 * Get the file extension type that was selected by the user. Valid after an [OK]
1075 */
1076 Inkscape::Extension::Extension *
1077 FileOpenDialogImpl::getSelectionType()
1078 {
1079 return extension;
1080 }
1083 /**
1084 * Get the file name chosen by the user. Valid after an [OK]
1085 */
1086 Glib::ustring
1087 FileOpenDialogImpl::getFilename (void)
1088 {
1089 return g_strdup(myFilename.c_str());
1090 }
1093 /**
1094 * To Get Multiple filenames selected at-once.
1095 */
1096 std::vector<Glib::ustring>FileOpenDialogImpl::getFilenames()
1097 {
1098 std::vector<Glib::ustring> result = get_filenames();
1099 #ifdef WITH_GNOME_VFS
1100 if (result.empty() && gnome_vfs_initialized())
1101 result = get_uris();
1102 #endif
1103 return result;
1104 }
1111 //########################################################################
1112 //# F I L E S A V E
1113 //########################################################################
1115 class FileType
1116 {
1117 public:
1118 FileType() {}
1119 ~FileType() {}
1120 Glib::ustring name;
1121 Glib::ustring pattern;
1122 Inkscape::Extension::Extension *extension;
1123 };
1125 /**
1126 * Our implementation of the FileSaveDialog interface.
1127 */
1128 class FileSaveDialogImpl : public FileSaveDialog, public FileDialogBase
1129 {
1131 public:
1132 FileSaveDialogImpl(const Glib::ustring &dir,
1133 FileDialogType fileTypes,
1134 const Glib::ustring &title,
1135 const Glib::ustring &default_key);
1137 virtual ~FileSaveDialogImpl();
1139 bool show();
1141 Inkscape::Extension::Extension *getSelectionType();
1142 virtual void setSelectionType( Inkscape::Extension::Extension * key );
1144 Glib::ustring getFilename();
1146 void change_title(const Glib::ustring& title);
1147 void change_path(const Glib::ustring& path);
1148 void updateNameAndExtension();
1150 private:
1152 /**
1153 * Fix to allow the user to type the file name
1154 */
1155 Gtk::Entry *fileNameEntry;
1158 /**
1159 * Allow the specification of the output file type
1160 */
1161 Gtk::ComboBoxText fileTypeComboBox;
1164 /**
1165 * Data mirror of the combo box
1166 */
1167 std::vector<FileType> fileTypes;
1169 //# Child widgets
1170 Gtk::HBox childBox;
1171 Gtk::VBox checksBox;
1173 Gtk::CheckButton fileTypeCheckbox;
1175 /**
1176 * Callback for user input into fileNameEntry
1177 */
1178 void fileTypeChangedCallback();
1180 /**
1181 * Create a filter menu for this type of dialog
1182 */
1183 void createFileTypeMenu();
1186 /**
1187 * The extension to use to write this file
1188 */
1189 Inkscape::Extension::Extension *extension;
1191 /**
1192 * Callback for user input into fileNameEntry
1193 */
1194 void fileNameEntryChangedCallback();
1196 /**
1197 * Filename that was given
1198 */
1199 Glib::ustring myFilename;
1201 /**
1202 * List of known file extensions.
1203 */
1204 std::set<Glib::ustring> knownExtensions;
1205 };
1210 /**
1211 * Callback for fileNameEntry widget
1212 */
1213 void FileSaveDialogImpl::fileNameEntryChangedCallback()
1214 {
1215 if (!fileNameEntry)
1216 return;
1218 Glib::ustring fileName = fileNameEntry->get_text();
1219 if (!Glib::get_charset()) //If we are not utf8
1220 fileName = Glib::filename_to_utf8(fileName);
1222 //g_message("User hit return. Text is '%s'\n", fileName.c_str());
1224 if (!Glib::path_is_absolute(fileName)) {
1225 //try appending to the current path
1226 // not this way: fileName = get_current_folder() + "/" + fileName;
1227 std::vector<Glib::ustring> pathSegments;
1228 pathSegments.push_back( get_current_folder() );
1229 pathSegments.push_back( fileName );
1230 fileName = Glib::build_filename(pathSegments);
1231 }
1233 //g_message("path:'%s'\n", fileName.c_str());
1235 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1236 set_current_folder(fileName);
1237 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1238 //dialog with either (1) select a regular file or (2) cd to dir
1239 //simulate an 'OK'
1240 set_filename(fileName);
1241 response(Gtk::RESPONSE_OK);
1242 }
1243 }
1247 /**
1248 * Callback for fileNameEntry widget
1249 */
1250 void FileSaveDialogImpl::fileTypeChangedCallback()
1251 {
1252 int sel = fileTypeComboBox.get_active_row_number();
1253 if (sel<0 || sel >= (int)fileTypes.size())
1254 return;
1255 FileType type = fileTypes[sel];
1256 //g_message("selected: %s\n", type.name.c_str());
1258 extension = type.extension;
1259 Gtk::FileFilter filter;
1260 filter.add_pattern(type.pattern);
1261 set_filter(filter);
1263 updateNameAndExtension();
1264 }
1268 void FileSaveDialogImpl::createFileTypeMenu()
1269 {
1270 Inkscape::Extension::DB::OutputList extension_list;
1271 Inkscape::Extension::db.get_output_list(extension_list);
1272 knownExtensions.clear();
1274 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1275 current_item != extension_list.end(); current_item++)
1276 {
1277 Inkscape::Extension::Output * omod = *current_item;
1279 // FIXME: would be nice to grey them out instead of not listing them
1280 if (omod->deactivated()) continue;
1282 FileType type;
1283 type.name = (_(omod->get_filetypename()));
1284 type.pattern = "*";
1285 Glib::ustring extension = omod->get_extension();
1286 knownExtensions.insert( extension.casefold() );
1287 fileDialogExtensionToPattern (type.pattern, extension);
1288 type.extension= omod;
1289 fileTypeComboBox.append_text(type.name);
1290 fileTypes.push_back(type);
1291 }
1293 //#Let user choose
1294 FileType guessType;
1295 guessType.name = _("Guess from extension");
1296 guessType.pattern = "*";
1297 guessType.extension = NULL;
1298 fileTypeComboBox.append_text(guessType.name);
1299 fileTypes.push_back(guessType);
1302 fileTypeComboBox.set_active(0);
1303 fileTypeChangedCallback(); //call at least once to set the filter
1304 }
1308 /**
1309 * Constructor
1310 */
1311 FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir,
1312 FileDialogType fileTypes,
1313 const Glib::ustring &title,
1314 const Glib::ustring &default_key) :
1315 FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")
1316 {
1317 /* One file at a time */
1318 set_select_multiple(false);
1320 #ifdef WITH_GNOME_VFS
1321 if (gnome_vfs_initialized()) {
1322 set_local_only(false);
1323 }
1324 #endif
1326 /* Initalize to Autodetect */
1327 extension = NULL;
1328 /* No filename to start out with */
1329 myFilename = "";
1331 /* Set our dialog type (save, export, etc...)*/
1332 dialogType = fileTypes;
1334 /* Set the pwd and/or the filename */
1335 if (dir.size() > 0)
1336 {
1337 Glib::ustring udir(dir);
1338 Glib::ustring::size_type len = udir.length();
1339 // leaving a trailing backslash on the directory name leads to the infamous
1340 // double-directory bug on win32
1341 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1342 myFilename = udir;
1343 }
1345 //###### Add the file types menu
1346 //createFilterMenu();
1348 //###### Do we want the .xxx extension automatically added?
1349 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
1350 fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.save_as",
1351 "append_extension", 1) );
1353 createFileTypeMenu();
1354 fileTypeComboBox.set_size_request(200,40);
1355 fileTypeComboBox.signal_changed().connect(
1356 sigc::mem_fun(*this, &FileSaveDialogImpl::fileTypeChangedCallback) );
1359 childBox.pack_start( checksBox );
1360 childBox.pack_end( fileTypeComboBox );
1361 checksBox.pack_start( fileTypeCheckbox );
1362 checksBox.pack_start( previewCheckbox );
1364 set_extra_widget( childBox );
1366 //Let's do some customization
1367 fileNameEntry = NULL;
1368 Gtk::Container *cont = get_toplevel();
1369 std::vector<Gtk::Entry *> entries;
1370 findEntryWidgets(cont, entries);
1371 //g_message("Found %d entry widgets\n", entries.size());
1372 if (entries.size() >=1 )
1373 {
1374 //Catch when user hits [return] on the text field
1375 fileNameEntry = entries[0];
1376 fileNameEntry->signal_activate().connect(
1377 sigc::mem_fun(*this, &FileSaveDialogImpl::fileNameEntryChangedCallback) );
1378 }
1380 //Let's do more customization
1381 std::vector<Gtk::Expander *> expanders;
1382 findExpanderWidgets(cont, expanders);
1383 //g_message("Found %d expander widgets\n", expanders.size());
1384 if (expanders.size() >=1 )
1385 {
1386 //Always show the file list
1387 Gtk::Expander *expander = expanders[0];
1388 expander->set_expanded(true);
1389 }
1392 //if (extension == NULL)
1393 // checkbox.set_sensitive(FALSE);
1395 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1396 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
1398 show_all_children();
1399 }
1403 /**
1404 * Public factory method. Used in file.cpp
1405 */
1406 FileSaveDialog *FileSaveDialog::create(const Glib::ustring &path,
1407 FileDialogType fileTypes,
1408 const Glib::ustring &title,
1409 const Glib::ustring &default_key)
1410 {
1411 FileSaveDialog *dialog = new FileSaveDialogImpl(path, fileTypes, title, default_key);
1412 return dialog;
1413 }
1419 /**
1420 * Destructor
1421 */
1422 FileSaveDialogImpl::~FileSaveDialogImpl()
1423 {
1424 }
1428 /**
1429 * Show this dialog modally. Return true if user hits [OK]
1430 */
1431 bool
1432 FileSaveDialogImpl::show()
1433 {
1434 change_path(myFilename);
1435 set_modal (TRUE); //Window
1436 sp_transientize((GtkWidget *)gobj()); //Make transient
1437 gint b = run(); //Dialog
1438 svgPreview.showNoPreview();
1439 hide();
1441 if (b == Gtk::RESPONSE_OK)
1442 {
1443 updateNameAndExtension();
1445 // Store changes of the "Append filename automatically" checkbox back to preferences.
1446 prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active());
1448 // Store the last used save-as filetype to preferences.
1449 prefs_set_string_attribute("dialogs.save_as", "default",
1450 ( extension != NULL ? extension->get_id() : "" ));
1452 cleanup( true );
1454 return TRUE;
1455 }
1456 else
1457 {
1458 cleanup( false );
1460 return FALSE;
1461 }
1462 }
1465 /**
1466 * Get the file extension type that was selected by the user. Valid after an [OK]
1467 */
1468 Inkscape::Extension::Extension *
1469 FileSaveDialogImpl::getSelectionType()
1470 {
1471 return extension;
1472 }
1474 void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
1475 {
1476 // If no pointer to extension is passed in, look up based on filename extension.
1477 if ( !key ) {
1478 // Not quite UTF-8 here.
1479 gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
1480 for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
1481 Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
1482 if ( ext && ext->get_extension() ) {
1483 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
1484 if ( g_str_has_suffix(filenameLower, extensionLower) ) {
1485 key = fileTypes[i].extension;
1486 }
1487 g_free(extensionLower);
1488 }
1489 }
1490 g_free(filenameLower);
1491 }
1493 // Ensure the proper entry in the combo box is selected.
1494 if ( key ) {
1495 extension = key;
1496 gchar const * extensionID = extension->get_id();
1497 if ( extensionID ) {
1498 for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
1499 Inkscape::Extension::Extension *ext = fileTypes[i].extension;
1500 if ( ext ) {
1501 gchar const * id = ext->get_id();
1502 if ( id && ( strcmp(extensionID, id) == 0) ) {
1503 int oldSel = fileTypeComboBox.get_active_row_number();
1504 if ( i != oldSel ) {
1505 fileTypeComboBox.set_active(i);
1506 }
1507 break;
1508 }
1509 }
1510 }
1511 }
1512 }
1513 }
1516 /**
1517 * Get the file name chosen by the user. Valid after an [OK]
1518 */
1519 Glib::ustring
1520 FileSaveDialogImpl::getFilename()
1521 {
1522 return myFilename;
1523 }
1526 void
1527 FileSaveDialogImpl::change_title(const Glib::ustring& title)
1528 {
1529 this->set_title(title);
1530 }
1532 /**
1533 * Change the default save path location.
1534 */
1535 void
1536 FileSaveDialogImpl::change_path(const Glib::ustring& path)
1537 {
1538 myFilename = path;
1539 if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
1540 //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
1541 set_current_folder(myFilename);
1542 } else {
1543 //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
1544 if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
1545 set_filename(myFilename);
1546 } else {
1547 std::string dirName = Glib::path_get_dirname( myFilename );
1548 if ( dirName != get_current_folder() ) {
1549 set_current_folder(dirName);
1550 }
1551 }
1552 Glib::ustring basename = Glib::path_get_basename(myFilename);
1553 //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
1554 try {
1555 set_current_name( Glib::filename_to_utf8(basename) );
1556 } catch ( Glib::ConvertError& e ) {
1557 g_warning( "Error converting save filename to UTF-8." );
1558 // try a fallback.
1559 set_current_name( basename );
1560 }
1561 }
1562 }
1564 void FileSaveDialogImpl::updateNameAndExtension()
1565 {
1566 // Pick up any changes the user has typed in.
1567 Glib::ustring tmp = get_filename();
1568 #ifdef WITH_GNOME_VFS
1569 if ( tmp.empty() && gnome_vfs_initialized() ) {
1570 tmp = get_uri();
1571 }
1572 #endif
1573 if ( !tmp.empty() ) {
1574 myFilename = tmp;
1575 }
1577 Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
1578 if ( fileTypeCheckbox.get_active() && newOut ) {
1579 try {
1580 bool appendExtension = true;
1581 Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
1582 Glib::ustring::size_type pos = utf8Name.rfind('.');
1583 if ( pos != Glib::ustring::npos ) {
1584 Glib::ustring trail = utf8Name.substr( pos );
1585 Glib::ustring foldedTrail = trail.casefold();
1586 if ( (trail == ".")
1587 | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()
1588 && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {
1589 utf8Name = utf8Name.erase( pos );
1590 } else {
1591 appendExtension = false;
1592 }
1593 }
1595 if (appendExtension) {
1596 utf8Name = utf8Name + newOut->get_extension();
1597 myFilename = Glib::filename_from_utf8( utf8Name );
1598 change_path(myFilename);
1599 }
1600 } catch ( Glib::ConvertError& e ) {
1601 // ignore
1602 }
1603 }
1604 }
1608 //########################################################################
1609 //# F I L E E X P O R T
1610 //########################################################################
1613 /**
1614 * Our implementation of the FileExportDialog interface.
1615 */
1616 class FileExportDialogImpl : public FileExportDialog, public FileDialogBase
1617 {
1619 public:
1620 FileExportDialogImpl(const Glib::ustring &dir,
1621 FileDialogType fileTypes,
1622 const Glib::ustring &title,
1623 const Glib::ustring &default_key);
1625 virtual ~FileExportDialogImpl();
1627 bool show();
1629 Inkscape::Extension::Extension *getSelectionType();
1631 Glib::ustring getFilename();
1634 /**
1635 * Return the scope of the export. One of the enumerated types
1636 * in ScopeType
1637 */
1638 ScopeType getScope()
1639 {
1640 if (pageButton.get_active())
1641 return SCOPE_PAGE;
1642 else if (selectionButton.get_active())
1643 return SCOPE_SELECTION;
1644 else if (customButton.get_active())
1645 return SCOPE_CUSTOM;
1646 else
1647 return SCOPE_DOCUMENT;
1649 }
1651 /**
1652 * Return left side of the exported region
1653 */
1654 double getSourceX()
1655 { return sourceX0Spinner.getValue(); }
1657 /**
1658 * Return the top of the exported region
1659 */
1660 double getSourceY()
1661 { return sourceY1Spinner.getValue(); }
1663 /**
1664 * Return the width of the exported region
1665 */
1666 double getSourceWidth()
1667 { return sourceWidthSpinner.getValue(); }
1669 /**
1670 * Return the height of the exported region
1671 */
1672 double getSourceHeight()
1673 { return sourceHeightSpinner.getValue(); }
1675 /**
1676 * Return the units of the coordinates of exported region
1677 */
1678 Glib::ustring getSourceUnits()
1679 { return sourceUnitsSpinner.getUnitAbbr(); }
1681 /**
1682 * Return the width of the destination document
1683 */
1684 double getDestinationWidth()
1685 { return destWidthSpinner.getValue(); }
1687 /**
1688 * Return the height of the destination document
1689 */
1690 double getDestinationHeight()
1691 { return destHeightSpinner.getValue(); }
1693 /**
1694 * Return the height of the exported region
1695 */
1696 Glib::ustring getDestinationUnits()
1697 { return destUnitsSpinner.getUnitAbbr(); }
1699 /**
1700 * Return the destination DPI image resulution, if bitmap
1701 */
1702 double getDestinationDPI()
1703 { return destDPISpinner.getValue(); }
1705 /**
1706 * Return whether we should use Cairo for rendering
1707 */
1708 bool getUseCairo()
1709 { return cairoButton.get_active(); }
1711 /**
1712 * Return whether we should use antialiasing
1713 */
1714 bool getUseAntialias()
1715 { return antiAliasButton.get_active(); }
1717 /**
1718 * Return the background color for exporting
1719 */
1720 unsigned long getBackground()
1721 { return backgroundButton.get_color().get_pixel(); }
1723 private:
1725 /**
1726 * Fix to allow the user to type the file name
1727 */
1728 Gtk::Entry *fileNameEntry;
1730 //##########################################
1731 //# EXTRA WIDGET -- SOURCE SIDE
1732 //##########################################
1734 Gtk::Frame sourceFrame;
1735 Gtk::VBox sourceBox;
1737 Gtk::HBox scopeBox;
1738 Gtk::RadioButtonGroup scopeGroup;
1739 Gtk::RadioButton documentButton;
1740 Gtk::RadioButton pageButton;
1741 Gtk::RadioButton selectionButton;
1742 Gtk::RadioButton customButton;
1744 Gtk::Table sourceTable;
1745 Inkscape::UI::Widget::Scalar sourceX0Spinner;
1746 Inkscape::UI::Widget::Scalar sourceY0Spinner;
1747 Inkscape::UI::Widget::Scalar sourceX1Spinner;
1748 Inkscape::UI::Widget::Scalar sourceY1Spinner;
1749 Inkscape::UI::Widget::Scalar sourceWidthSpinner;
1750 Inkscape::UI::Widget::Scalar sourceHeightSpinner;
1751 Inkscape::UI::Widget::UnitMenu sourceUnitsSpinner;
1754 //##########################################
1755 //# EXTRA WIDGET -- DESTINATION SIDE
1756 //##########################################
1758 Gtk::Frame destFrame;
1759 Gtk::VBox destBox;
1761 Gtk::Table destTable;
1762 Inkscape::UI::Widget::Scalar destWidthSpinner;
1763 Inkscape::UI::Widget::Scalar destHeightSpinner;
1764 Inkscape::UI::Widget::Scalar destDPISpinner;
1765 Inkscape::UI::Widget::UnitMenu destUnitsSpinner;
1767 Gtk::HBox otherOptionBox;
1768 Gtk::CheckButton cairoButton;
1769 Gtk::CheckButton antiAliasButton;
1770 Gtk::ColorButton backgroundButton;
1773 /**
1774 * 'Extra' widget that holds two boxes above
1775 */
1776 Gtk::HBox exportOptionsBox;
1779 //# Child widgets
1780 Gtk::CheckButton fileTypeCheckbox;
1782 /**
1783 * Allow the specification of the output file type
1784 */
1785 Gtk::ComboBoxText fileTypeComboBox;
1788 /**
1789 * Data mirror of the combo box
1790 */
1791 std::vector<FileType> fileTypes;
1795 /**
1796 * Callback for user input into fileNameEntry
1797 */
1798 void fileTypeChangedCallback();
1800 /**
1801 * Create a filter menu for this type of dialog
1802 */
1803 void createFileTypeMenu();
1806 bool append_extension;
1808 /**
1809 * The extension to use to write this file
1810 */
1811 Inkscape::Extension::Extension *extension;
1813 /**
1814 * Callback for user input into fileNameEntry
1815 */
1816 void fileNameEntryChangedCallback();
1818 /**
1819 * Filename that was given
1820 */
1821 Glib::ustring myFilename;
1822 };
1829 /**
1830 * Callback for fileNameEntry widget
1831 */
1832 void FileExportDialogImpl::fileNameEntryChangedCallback()
1833 {
1834 if (!fileNameEntry)
1835 return;
1837 Glib::ustring fileName = fileNameEntry->get_text();
1838 if (!Glib::get_charset()) //If we are not utf8
1839 fileName = Glib::filename_to_utf8(fileName);
1841 //g_message("User hit return. Text is '%s'\n", fileName.c_str());
1843 if (!Glib::path_is_absolute(fileName)) {
1844 //try appending to the current path
1845 // not this way: fileName = get_current_folder() + "/" + fileName;
1846 std::vector<Glib::ustring> pathSegments;
1847 pathSegments.push_back( get_current_folder() );
1848 pathSegments.push_back( fileName );
1849 fileName = Glib::build_filename(pathSegments);
1850 }
1852 //g_message("path:'%s'\n", fileName.c_str());
1854 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1855 set_current_folder(fileName);
1856 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1857 //dialog with either (1) select a regular file or (2) cd to dir
1858 //simulate an 'OK'
1859 set_filename(fileName);
1860 response(Gtk::RESPONSE_OK);
1861 }
1862 }
1866 /**
1867 * Callback for fileNameEntry widget
1868 */
1869 void FileExportDialogImpl::fileTypeChangedCallback()
1870 {
1871 int sel = fileTypeComboBox.get_active_row_number();
1872 if (sel<0 || sel >= (int)fileTypes.size())
1873 return;
1874 FileType type = fileTypes[sel];
1875 //g_message("selected: %s\n", type.name.c_str());
1876 Gtk::FileFilter filter;
1877 filter.add_pattern(type.pattern);
1878 set_filter(filter);
1879 }
1883 void FileExportDialogImpl::createFileTypeMenu()
1884 {
1885 Inkscape::Extension::DB::OutputList extension_list;
1886 Inkscape::Extension::db.get_output_list(extension_list);
1888 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1889 current_item != extension_list.end(); current_item++)
1890 {
1891 Inkscape::Extension::Output * omod = *current_item;
1893 // FIXME: would be nice to grey them out instead of not listing them
1894 if (omod->deactivated()) continue;
1896 FileType type;
1897 type.name = (_(omod->get_filetypename()));
1898 type.pattern = "*";
1899 Glib::ustring extension = omod->get_extension();
1900 fileDialogExtensionToPattern (type.pattern, extension);
1901 type.extension= omod;
1902 fileTypeComboBox.append_text(type.name);
1903 fileTypes.push_back(type);
1904 }
1906 //#Let user choose
1907 FileType guessType;
1908 guessType.name = _("Guess from extension");
1909 guessType.pattern = "*";
1910 guessType.extension = NULL;
1911 fileTypeComboBox.append_text(guessType.name);
1912 fileTypes.push_back(guessType);
1915 fileTypeComboBox.set_active(0);
1916 fileTypeChangedCallback(); //call at least once to set the filter
1917 }
1920 /**
1921 * Constructor
1922 */
1923 FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir,
1924 FileDialogType fileTypes,
1925 const Glib::ustring &title,
1926 const Glib::ustring &default_key) :
1927 FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),
1928 sourceX0Spinner("X0", _("Left edge of source")),
1929 sourceY0Spinner("Y0", _("Top edge of source")),
1930 sourceX1Spinner("X1", _("Right edge of source")),
1931 sourceY1Spinner("Y1", _("Bottom edge of source")),
1932 sourceWidthSpinner("Width", _("Source width")),
1933 sourceHeightSpinner("Height", _("Source height")),
1934 destWidthSpinner("Width", _("Destination width")),
1935 destHeightSpinner("Height", _("Destination height")),
1936 destDPISpinner("DPI", _("Resolution (dots per inch)"))
1937 {
1938 append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);
1940 /* One file at a time */
1941 set_select_multiple(false);
1943 #ifdef WITH_GNOME_VFS
1944 if (gnome_vfs_initialized()) {
1945 set_local_only(false);
1946 }
1947 #endif
1949 /* Initalize to Autodetect */
1950 extension = NULL;
1951 /* No filename to start out with */
1952 myFilename = "";
1954 /* Set our dialog type (save, export, etc...)*/
1955 dialogType = fileTypes;
1957 /* Set the pwd and/or the filename */
1958 if (dir.size()>0)
1959 {
1960 Glib::ustring udir(dir);
1961 Glib::ustring::size_type len = udir.length();
1962 // leaving a trailing backslash on the directory name leads to the infamous
1963 // double-directory bug on win32
1964 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1965 set_current_folder(udir.c_str());
1966 }
1968 //#########################################
1969 //## EXTRA WIDGET -- SOURCE SIDE
1970 //#########################################
1972 //##### Export options buttons/spinners, etc
1973 documentButton.set_label(_("Document"));
1974 scopeBox.pack_start(documentButton);
1975 scopeGroup = documentButton.get_group();
1977 pageButton.set_label(_("Page"));
1978 pageButton.set_group(scopeGroup);
1979 scopeBox.pack_start(pageButton);
1981 selectionButton.set_label(_("Selection"));
1982 selectionButton.set_group(scopeGroup);
1983 scopeBox.pack_start(selectionButton);
1985 customButton.set_label(_("Custom"));
1986 customButton.set_group(scopeGroup);
1987 scopeBox.pack_start(customButton);
1989 sourceBox.pack_start(scopeBox);
1993 //dimension buttons
1994 sourceTable.resize(3,3);
1995 sourceTable.attach(sourceX0Spinner, 0,1,0,1);
1996 sourceTable.attach(sourceY0Spinner, 1,2,0,1);
1997 sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
1998 sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);
1999 sourceTable.attach(sourceX1Spinner, 0,1,1,2);
2000 sourceTable.attach(sourceY1Spinner, 1,2,1,2);
2001 sourceTable.attach(sourceWidthSpinner, 0,1,2,3);
2002 sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
2004 sourceBox.pack_start(sourceTable);
2005 sourceFrame.set_label(_("Source"));
2006 sourceFrame.add(sourceBox);
2007 exportOptionsBox.pack_start(sourceFrame);
2010 //#########################################
2011 //## EXTRA WIDGET -- SOURCE SIDE
2012 //#########################################
2015 destTable.resize(3,3);
2016 destTable.attach(destWidthSpinner, 0,1,0,1);
2017 destTable.attach(destHeightSpinner, 1,2,0,1);
2018 destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
2019 destTable.attach(destUnitsSpinner, 2,3,0,1);
2020 destTable.attach(destDPISpinner, 0,1,1,2);
2022 destBox.pack_start(destTable);
2025 cairoButton.set_label(_("Cairo"));
2026 otherOptionBox.pack_start(cairoButton);
2028 antiAliasButton.set_label(_("Antialias"));
2029 otherOptionBox.pack_start(antiAliasButton);
2031 backgroundButton.set_label(_("Background"));
2032 otherOptionBox.pack_start(backgroundButton);
2034 destBox.pack_start(otherOptionBox);
2040 //###### File options
2041 //###### Do we want the .xxx extension automatically added?
2042 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
2043 fileTypeCheckbox.set_active(append_extension);
2044 destBox.pack_start(fileTypeCheckbox);
2046 //###### File type menu
2047 createFileTypeMenu();
2048 fileTypeComboBox.set_size_request(200,40);
2049 fileTypeComboBox.signal_changed().connect(
2050 sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
2052 destBox.pack_start(fileTypeComboBox);
2054 destFrame.set_label(_("Destination"));
2055 destFrame.add(destBox);
2056 exportOptionsBox.pack_start(destFrame);
2058 //##### Put the two boxes and their parent onto the dialog
2059 exportOptionsBox.pack_start(sourceFrame);
2060 exportOptionsBox.pack_start(destFrame);
2062 set_extra_widget(exportOptionsBox);
2067 //Let's do some customization
2068 fileNameEntry = NULL;
2069 Gtk::Container *cont = get_toplevel();
2070 std::vector<Gtk::Entry *> entries;
2071 findEntryWidgets(cont, entries);
2072 //g_message("Found %d entry widgets\n", entries.size());
2073 if (entries.size() >=1 )
2074 {
2075 //Catch when user hits [return] on the text field
2076 fileNameEntry = entries[0];
2077 fileNameEntry->signal_activate().connect(
2078 sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
2079 }
2081 //Let's do more customization
2082 std::vector<Gtk::Expander *> expanders;
2083 findExpanderWidgets(cont, expanders);
2084 //g_message("Found %d expander widgets\n", expanders.size());
2085 if (expanders.size() >=1 )
2086 {
2087 //Always show the file list
2088 Gtk::Expander *expander = expanders[0];
2089 expander->set_expanded(true);
2090 }
2093 //if (extension == NULL)
2094 // checkbox.set_sensitive(FALSE);
2096 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2097 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
2099 show_all_children();
2100 }
2104 /**
2105 * Public factory method. Used in file.cpp
2106 */
2107 FileExportDialog *FileExportDialog::create(const Glib::ustring &path,
2108 FileDialogType fileTypes,
2109 const Glib::ustring &title,
2110 const Glib::ustring &default_key)
2111 {
2112 FileExportDialog *dialog = new FileExportDialogImpl(path, fileTypes, title, default_key);
2113 return dialog;
2114 }
2120 /**
2121 * Destructor
2122 */
2123 FileExportDialogImpl::~FileExportDialogImpl()
2124 {
2125 }
2129 /**
2130 * Show this dialog modally. Return true if user hits [OK]
2131 */
2132 bool
2133 FileExportDialogImpl::show()
2134 {
2135 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
2136 if (s.length() == 0)
2137 s = getcwd (NULL, 0);
2138 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
2139 set_modal (TRUE); //Window
2140 sp_transientize((GtkWidget *)gobj()); //Make transient
2141 gint b = run(); //Dialog
2142 svgPreview.showNoPreview();
2143 hide();
2145 if (b == Gtk::RESPONSE_OK)
2146 {
2147 int sel = fileTypeComboBox.get_active_row_number ();
2148 if (sel>=0 && sel< (int)fileTypes.size())
2149 {
2150 FileType &type = fileTypes[sel];
2151 extension = type.extension;
2152 }
2153 myFilename = get_filename();
2154 #ifdef WITH_GNOME_VFS
2155 if ( myFilename.empty() && gnome_vfs_initialized() ) {
2156 myFilename = get_uri();
2157 }
2158 #endif
2160 /*
2162 // FIXME: Why do we have more code
2164 append_extension = checkbox.get_active();
2165 prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
2166 prefs_set_string_attribute("dialogs.save_as", "default",
2167 ( extension != NULL ? extension->get_id() : "" ));
2168 */
2169 return TRUE;
2170 }
2171 else
2172 {
2173 return FALSE;
2174 }
2175 }
2178 /**
2179 * Get the file extension type that was selected by the user. Valid after an [OK]
2180 */
2181 Inkscape::Extension::Extension *
2182 FileExportDialogImpl::getSelectionType()
2183 {
2184 return extension;
2185 }
2188 /**
2189 * Get the file name chosen by the user. Valid after an [OK]
2190 */
2191 Glib::ustring
2192 FileExportDialogImpl::getFilename()
2193 {
2194 return myFilename;
2195 }
2200 } //namespace Dialog
2201 } //namespace UI
2202 } //namespace Inkscape
2205 /*
2206 Local Variables:
2207 mode:c++
2208 c-file-style:"stroustrup"
2209 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2210 indent-tabs-mode:nil
2211 fill-column:99
2212 End:
2213 */
2214 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :