4336b1f8b57b601b1088a1b3e4d493d47dcb5fa0
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(Gtk::Window& parentWindow, const Glib::ustring &title,
719 FileDialogType type, gchar const* preferenceBase) :
720 Gtk::FileChooserDialog(parentWindow, title),
721 preferenceBase(preferenceBase ? preferenceBase : "unknown"),
722 dialogType(type)
723 {
724 internalSetup();
725 }
727 /**
728 *
729 */
730 FileDialogBase(Gtk::Window& parentWindow, const Glib::ustring &title,
731 Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :
732 Gtk::FileChooserDialog(parentWindow, title, dialogType),
733 preferenceBase(preferenceBase ? preferenceBase : "unknown"),
734 dialogType(type)
735 {
736 internalSetup();
737 }
739 /**
740 *
741 */
742 virtual ~FileDialogBase()
743 {}
745 protected:
746 void cleanup( bool showConfirmed );
748 Glib::ustring preferenceBase;
749 /**
750 * What type of 'open' are we? (open, import, place, etc)
751 */
752 FileDialogType dialogType;
754 /**
755 * Our svg preview widget
756 */
757 SVGPreview svgPreview;
759 //# Child widgets
760 Gtk::CheckButton previewCheckbox;
762 private:
763 void internalSetup();
765 /**
766 * Callback for user changing preview checkbox
767 */
768 void _previewEnabledCB();
770 /**
771 * Callback for seeing if the preview needs to be drawn
772 */
773 void _updatePreviewCallback();
774 };
777 void FileDialogBase::internalSetup()
778 {
779 bool enablePreview =
780 (bool)prefs_get_int_attribute( preferenceBase.c_str(),
781 "enable_preview", 1 );
783 previewCheckbox.set_label( Glib::ustring(_("Enable Preview")) );
784 previewCheckbox.set_active( enablePreview );
786 previewCheckbox.signal_toggled().connect(
787 sigc::mem_fun(*this, &FileDialogBase::_previewEnabledCB) );
789 //Catch selection-changed events, so we can adjust the text widget
790 signal_update_preview().connect(
791 sigc::mem_fun(*this, &FileDialogBase::_updatePreviewCallback) );
793 //###### Add a preview widget
794 set_preview_widget(svgPreview);
795 set_preview_widget_active( enablePreview );
796 set_use_preview_label (false);
798 }
801 void FileDialogBase::cleanup( bool showConfirmed )
802 {
803 if ( showConfirmed )
804 prefs_set_int_attribute( preferenceBase.c_str(),
805 "enable_preview", previewCheckbox.get_active() );
806 }
809 void FileDialogBase::_previewEnabledCB()
810 {
811 bool enabled = previewCheckbox.get_active();
812 set_preview_widget_active(enabled);
813 if ( enabled ) {
814 _updatePreviewCallback();
815 }
816 }
820 /**
821 * Callback for checking if the preview needs to be redrawn
822 */
823 void FileDialogBase::_updatePreviewCallback()
824 {
825 Glib::ustring fileName = get_preview_filename();
827 #ifdef WITH_GNOME_VFS
828 if ( fileName.empty() && gnome_vfs_initialized() ) {
829 fileName = get_preview_uri();
830 }
831 #endif
833 if (fileName.empty()) {
834 return;
835 }
837 svgPreview.set(fileName, dialogType);
838 }
841 /*#########################################################################
842 ### F I L E O P E N
843 #########################################################################*/
845 /**
846 * Our implementation class for the FileOpenDialog interface..
847 */
848 class FileOpenDialogImpl : public FileOpenDialog, public FileDialogBase
849 {
850 public:
852 FileOpenDialogImpl(Gtk::Window& parentWindow,
853 const Glib::ustring &dir,
854 FileDialogType fileTypes,
855 const Glib::ustring &title);
857 virtual ~FileOpenDialogImpl();
859 bool show();
861 Inkscape::Extension::Extension *getSelectionType();
863 Glib::ustring getFilename();
865 std::vector<Glib::ustring> getFilenames ();
867 private:
869 /**
870 * Create a filter menu for this type of dialog
871 */
872 void createFilterMenu();
874 /**
875 * Filter name->extension lookup
876 */
877 std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;
879 /**
880 * The extension to use to write this file
881 */
882 Inkscape::Extension::Extension *extension;
884 /**
885 * Filename that was given
886 */
887 Glib::ustring myFilename;
889 };
897 void FileOpenDialogImpl::createFilterMenu()
898 {
899 Gtk::FileFilter allInkscapeFilter;
900 allInkscapeFilter.set_name(_("All Inkscape Files"));
901 extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
902 add_filter(allInkscapeFilter);
904 Gtk::FileFilter allFilter;
905 allFilter.set_name(_("All Files"));
906 extensionMap[Glib::ustring(_("All Files"))]=NULL;
907 allFilter.add_pattern("*");
908 add_filter(allFilter);
910 Gtk::FileFilter allImageFilter;
911 allImageFilter.set_name(_("All Images"));
912 extensionMap[Glib::ustring(_("All Images"))]=NULL;
913 add_filter(allImageFilter);
915 //patterns added dynamically below
916 Inkscape::Extension::DB::InputList extension_list;
917 Inkscape::Extension::db.get_input_list(extension_list);
919 for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
920 current_item != extension_list.end(); current_item++)
921 {
922 Inkscape::Extension::Input * imod = *current_item;
924 // FIXME: would be nice to grey them out instead of not listing them
925 if (imod->deactivated()) continue;
927 Glib::ustring upattern("*");
928 Glib::ustring extension = imod->get_extension();
929 fileDialogExtensionToPattern(upattern, extension);
931 Gtk::FileFilter filter;
932 Glib::ustring uname(_(imod->get_filetypename()));
933 filter.set_name(uname);
934 filter.add_pattern(upattern);
935 add_filter(filter);
936 extensionMap[uname] = imod;
938 //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
939 allInkscapeFilter.add_pattern(upattern);
940 if ( strncmp("image", imod->get_mimetype(), 5)==0 )
941 allImageFilter.add_pattern(upattern);
942 }
944 return;
945 }
949 /**
950 * Constructor. Not called directly. Use the factory.
951 */
952 FileOpenDialogImpl::FileOpenDialogImpl(Gtk::Window& parentWindow,
953 const Glib::ustring &dir,
954 FileDialogType fileTypes,
955 const Glib::ustring &title) :
956 FileDialogBase(parentWindow, title, fileTypes, "dialogs.open")
957 {
960 /* One file at a time */
961 /* And also Multiple Files */
962 set_select_multiple(true);
964 #ifdef WITH_GNOME_VFS
965 if (gnome_vfs_initialized()) {
966 set_local_only(false);
967 }
968 #endif
970 /* Initalize to Autodetect */
971 extension = NULL;
972 /* No filename to start out with */
973 myFilename = "";
975 /* Set our dialog type (open, import, etc...)*/
976 dialogType = fileTypes;
979 /* Set the pwd and/or the filename */
980 if (dir.size() > 0)
981 {
982 Glib::ustring udir(dir);
983 Glib::ustring::size_type len = udir.length();
984 // leaving a trailing backslash on the directory name leads to the infamous
985 // double-directory bug on win32
986 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
987 set_current_folder(udir.c_str());
988 }
991 set_extra_widget( previewCheckbox );
994 //###### Add the file types menu
995 createFilterMenu();
998 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
999 set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
1000 }
1006 /**
1007 * Public factory. Called by file.cpp, among others.
1008 */
1009 FileOpenDialog *FileOpenDialog::create(Gtk::Window &parentWindow,
1010 const Glib::ustring &path,
1011 FileDialogType fileTypes,
1012 const Glib::ustring &title)
1013 {
1014 FileOpenDialog *dialog = new FileOpenDialogImpl(parentWindow, path, fileTypes, title);
1015 return dialog;
1016 }
1021 /**
1022 * Destructor
1023 */
1024 FileOpenDialogImpl::~FileOpenDialogImpl()
1025 {
1027 }
1030 /**
1031 * Show this dialog modally. Return true if user hits [OK]
1032 */
1033 bool
1034 FileOpenDialogImpl::show()
1035 {
1036 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
1037 if (s.length() == 0)
1038 s = getcwd (NULL, 0);
1039 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
1040 set_modal (TRUE); //Window
1041 sp_transientize((GtkWidget *)gobj()); //Make transient
1042 gint b = run(); //Dialog
1043 svgPreview.showNoPreview();
1044 hide();
1046 if (b == Gtk::RESPONSE_OK)
1047 {
1048 //This is a hack, to avoid the warning messages that
1049 //Gtk::FileChooser::get_filter() returns
1050 //should be: Gtk::FileFilter *filter = get_filter();
1051 GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
1052 GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
1053 if (filter)
1054 {
1055 //Get which extension was chosen, if any
1056 extension = extensionMap[gtk_file_filter_get_name(filter)];
1057 }
1058 myFilename = get_filename();
1059 #ifdef WITH_GNOME_VFS
1060 if (myFilename.empty() && gnome_vfs_initialized())
1061 myFilename = get_uri();
1062 #endif
1063 cleanup( true );
1064 return TRUE;
1065 }
1066 else
1067 {
1068 cleanup( false );
1069 return FALSE;
1070 }
1071 }
1076 /**
1077 * Get the file extension type that was selected by the user. Valid after an [OK]
1078 */
1079 Inkscape::Extension::Extension *
1080 FileOpenDialogImpl::getSelectionType()
1081 {
1082 return extension;
1083 }
1086 /**
1087 * Get the file name chosen by the user. Valid after an [OK]
1088 */
1089 Glib::ustring
1090 FileOpenDialogImpl::getFilename (void)
1091 {
1092 return g_strdup(myFilename.c_str());
1093 }
1096 /**
1097 * To Get Multiple filenames selected at-once.
1098 */
1099 std::vector<Glib::ustring>FileOpenDialogImpl::getFilenames()
1100 {
1101 std::vector<Glib::ustring> result = get_filenames();
1102 #ifdef WITH_GNOME_VFS
1103 if (result.empty() && gnome_vfs_initialized())
1104 result = get_uris();
1105 #endif
1106 return result;
1107 }
1114 //########################################################################
1115 //# F I L E S A V E
1116 //########################################################################
1118 class FileType
1119 {
1120 public:
1121 FileType() {}
1122 ~FileType() {}
1123 Glib::ustring name;
1124 Glib::ustring pattern;
1125 Inkscape::Extension::Extension *extension;
1126 };
1128 /**
1129 * Our implementation of the FileSaveDialog interface.
1130 */
1131 class FileSaveDialogImpl : public FileSaveDialog, public FileDialogBase
1132 {
1134 public:
1135 FileSaveDialogImpl(Gtk::Window &parentWindow,
1136 const Glib::ustring &dir,
1137 FileDialogType fileTypes,
1138 const Glib::ustring &title,
1139 const Glib::ustring &default_key);
1141 virtual ~FileSaveDialogImpl();
1143 bool show();
1145 Inkscape::Extension::Extension *getSelectionType();
1146 virtual void setSelectionType( Inkscape::Extension::Extension * key );
1148 Glib::ustring getFilename();
1150 void change_title(const Glib::ustring& title);
1151 void change_path(const Glib::ustring& path);
1152 void updateNameAndExtension();
1154 private:
1156 /**
1157 * Fix to allow the user to type the file name
1158 */
1159 Gtk::Entry *fileNameEntry;
1162 /**
1163 * Allow the specification of the output file type
1164 */
1165 Gtk::ComboBoxText fileTypeComboBox;
1168 /**
1169 * Data mirror of the combo box
1170 */
1171 std::vector<FileType> fileTypes;
1173 //# Child widgets
1174 Gtk::HBox childBox;
1175 Gtk::VBox checksBox;
1177 Gtk::CheckButton fileTypeCheckbox;
1179 /**
1180 * Callback for user input into fileNameEntry
1181 */
1182 void fileTypeChangedCallback();
1184 /**
1185 * Create a filter menu for this type of dialog
1186 */
1187 void createFileTypeMenu();
1190 /**
1191 * The extension to use to write this file
1192 */
1193 Inkscape::Extension::Extension *extension;
1195 /**
1196 * Callback for user input into fileNameEntry
1197 */
1198 void fileNameEntryChangedCallback();
1200 /**
1201 * Filename that was given
1202 */
1203 Glib::ustring myFilename;
1205 /**
1206 * List of known file extensions.
1207 */
1208 std::set<Glib::ustring> knownExtensions;
1209 };
1214 /**
1215 * Callback for fileNameEntry widget
1216 */
1217 void FileSaveDialogImpl::fileNameEntryChangedCallback()
1218 {
1219 if (!fileNameEntry)
1220 return;
1222 Glib::ustring fileName = fileNameEntry->get_text();
1223 if (!Glib::get_charset()) //If we are not utf8
1224 fileName = Glib::filename_to_utf8(fileName);
1226 //g_message("User hit return. Text is '%s'\n", fileName.c_str());
1228 if (!Glib::path_is_absolute(fileName)) {
1229 //try appending to the current path
1230 // not this way: fileName = get_current_folder() + "/" + fileName;
1231 std::vector<Glib::ustring> pathSegments;
1232 pathSegments.push_back( get_current_folder() );
1233 pathSegments.push_back( fileName );
1234 fileName = Glib::build_filename(pathSegments);
1235 }
1237 //g_message("path:'%s'\n", fileName.c_str());
1239 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1240 set_current_folder(fileName);
1241 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1242 //dialog with either (1) select a regular file or (2) cd to dir
1243 //simulate an 'OK'
1244 set_filename(fileName);
1245 response(Gtk::RESPONSE_OK);
1246 }
1247 }
1251 /**
1252 * Callback for fileNameEntry widget
1253 */
1254 void FileSaveDialogImpl::fileTypeChangedCallback()
1255 {
1256 int sel = fileTypeComboBox.get_active_row_number();
1257 if (sel<0 || sel >= (int)fileTypes.size())
1258 return;
1259 FileType type = fileTypes[sel];
1260 //g_message("selected: %s\n", type.name.c_str());
1262 extension = type.extension;
1263 Gtk::FileFilter filter;
1264 filter.add_pattern(type.pattern);
1265 set_filter(filter);
1267 updateNameAndExtension();
1268 }
1272 void FileSaveDialogImpl::createFileTypeMenu()
1273 {
1274 Inkscape::Extension::DB::OutputList extension_list;
1275 Inkscape::Extension::db.get_output_list(extension_list);
1276 knownExtensions.clear();
1278 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1279 current_item != extension_list.end(); current_item++)
1280 {
1281 Inkscape::Extension::Output * omod = *current_item;
1283 // FIXME: would be nice to grey them out instead of not listing them
1284 if (omod->deactivated()) continue;
1286 FileType type;
1287 type.name = (_(omod->get_filetypename()));
1288 type.pattern = "*";
1289 Glib::ustring extension = omod->get_extension();
1290 knownExtensions.insert( extension.casefold() );
1291 fileDialogExtensionToPattern (type.pattern, extension);
1292 type.extension= omod;
1293 fileTypeComboBox.append_text(type.name);
1294 fileTypes.push_back(type);
1295 }
1297 //#Let user choose
1298 FileType guessType;
1299 guessType.name = _("Guess from extension");
1300 guessType.pattern = "*";
1301 guessType.extension = NULL;
1302 fileTypeComboBox.append_text(guessType.name);
1303 fileTypes.push_back(guessType);
1306 fileTypeComboBox.set_active(0);
1307 fileTypeChangedCallback(); //call at least once to set the filter
1308 }
1312 /**
1313 * Constructor
1314 */
1315 FileSaveDialogImpl::FileSaveDialogImpl(Gtk::Window &parentWindow,
1316 const Glib::ustring &dir,
1317 FileDialogType fileTypes,
1318 const Glib::ustring &title,
1319 const Glib::ustring &default_key) :
1320 FileDialogBase(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")
1321 {
1322 /* One file at a time */
1323 set_select_multiple(false);
1325 #ifdef WITH_GNOME_VFS
1326 if (gnome_vfs_initialized()) {
1327 set_local_only(false);
1328 }
1329 #endif
1331 /* Initalize to Autodetect */
1332 extension = NULL;
1333 /* No filename to start out with */
1334 myFilename = "";
1336 /* Set our dialog type (save, export, etc...)*/
1337 dialogType = fileTypes;
1339 /* Set the pwd and/or the filename */
1340 if (dir.size() > 0)
1341 {
1342 Glib::ustring udir(dir);
1343 Glib::ustring::size_type len = udir.length();
1344 // leaving a trailing backslash on the directory name leads to the infamous
1345 // double-directory bug on win32
1346 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1347 myFilename = udir;
1348 }
1350 //###### Add the file types menu
1351 //createFilterMenu();
1353 //###### Do we want the .xxx extension automatically added?
1354 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
1355 fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.save_as",
1356 "append_extension", 1) );
1358 createFileTypeMenu();
1359 fileTypeComboBox.set_size_request(200,40);
1360 fileTypeComboBox.signal_changed().connect(
1361 sigc::mem_fun(*this, &FileSaveDialogImpl::fileTypeChangedCallback) );
1364 childBox.pack_start( checksBox );
1365 childBox.pack_end( fileTypeComboBox );
1366 checksBox.pack_start( fileTypeCheckbox );
1367 checksBox.pack_start( previewCheckbox );
1369 set_extra_widget( childBox );
1371 //Let's do some customization
1372 fileNameEntry = NULL;
1373 Gtk::Container *cont = get_toplevel();
1374 std::vector<Gtk::Entry *> entries;
1375 findEntryWidgets(cont, entries);
1376 //g_message("Found %d entry widgets\n", entries.size());
1377 if (entries.size() >=1 )
1378 {
1379 //Catch when user hits [return] on the text field
1380 fileNameEntry = entries[0];
1381 fileNameEntry->signal_activate().connect(
1382 sigc::mem_fun(*this, &FileSaveDialogImpl::fileNameEntryChangedCallback) );
1383 }
1385 //Let's do more customization
1386 std::vector<Gtk::Expander *> expanders;
1387 findExpanderWidgets(cont, expanders);
1388 //g_message("Found %d expander widgets\n", expanders.size());
1389 if (expanders.size() >=1 )
1390 {
1391 //Always show the file list
1392 Gtk::Expander *expander = expanders[0];
1393 expander->set_expanded(true);
1394 }
1397 //if (extension == NULL)
1398 // checkbox.set_sensitive(FALSE);
1400 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1401 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
1403 show_all_children();
1404 }
1408 /**
1409 * Public factory method. Used in file.cpp
1410 */
1411 FileSaveDialog *FileSaveDialog::create(Gtk::Window& parentWindow,
1412 const Glib::ustring &path,
1413 FileDialogType fileTypes,
1414 const Glib::ustring &title,
1415 const Glib::ustring &default_key)
1416 {
1417 FileSaveDialog *dialog = new FileSaveDialogImpl(parentWindow, path, fileTypes, title, default_key);
1418 return dialog;
1419 }
1425 /**
1426 * Destructor
1427 */
1428 FileSaveDialogImpl::~FileSaveDialogImpl()
1429 {
1430 }
1434 /**
1435 * Show this dialog modally. Return true if user hits [OK]
1436 */
1437 bool
1438 FileSaveDialogImpl::show()
1439 {
1440 change_path(myFilename);
1441 set_modal (TRUE); //Window
1442 sp_transientize((GtkWidget *)gobj()); //Make transient
1443 gint b = run(); //Dialog
1444 svgPreview.showNoPreview();
1445 hide();
1447 if (b == Gtk::RESPONSE_OK)
1448 {
1449 updateNameAndExtension();
1451 // Store changes of the "Append filename automatically" checkbox back to preferences.
1452 prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active());
1454 // Store the last used save-as filetype to preferences.
1455 prefs_set_string_attribute("dialogs.save_as", "default",
1456 ( extension != NULL ? extension->get_id() : "" ));
1458 cleanup( true );
1460 return TRUE;
1461 }
1462 else
1463 {
1464 cleanup( false );
1466 return FALSE;
1467 }
1468 }
1471 /**
1472 * Get the file extension type that was selected by the user. Valid after an [OK]
1473 */
1474 Inkscape::Extension::Extension *
1475 FileSaveDialogImpl::getSelectionType()
1476 {
1477 return extension;
1478 }
1480 void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
1481 {
1482 // If no pointer to extension is passed in, look up based on filename extension.
1483 if ( !key ) {
1484 // Not quite UTF-8 here.
1485 gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
1486 for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
1487 Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
1488 if ( ext && ext->get_extension() ) {
1489 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
1490 if ( g_str_has_suffix(filenameLower, extensionLower) ) {
1491 key = fileTypes[i].extension;
1492 }
1493 g_free(extensionLower);
1494 }
1495 }
1496 g_free(filenameLower);
1497 }
1499 // Ensure the proper entry in the combo box is selected.
1500 if ( key ) {
1501 extension = key;
1502 gchar const * extensionID = extension->get_id();
1503 if ( extensionID ) {
1504 for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
1505 Inkscape::Extension::Extension *ext = fileTypes[i].extension;
1506 if ( ext ) {
1507 gchar const * id = ext->get_id();
1508 if ( id && ( strcmp(extensionID, id) == 0) ) {
1509 int oldSel = fileTypeComboBox.get_active_row_number();
1510 if ( i != oldSel ) {
1511 fileTypeComboBox.set_active(i);
1512 }
1513 break;
1514 }
1515 }
1516 }
1517 }
1518 }
1519 }
1522 /**
1523 * Get the file name chosen by the user. Valid after an [OK]
1524 */
1525 Glib::ustring
1526 FileSaveDialogImpl::getFilename()
1527 {
1528 return myFilename;
1529 }
1532 void
1533 FileSaveDialogImpl::change_title(const Glib::ustring& title)
1534 {
1535 this->set_title(title);
1536 }
1538 /**
1539 * Change the default save path location.
1540 */
1541 void
1542 FileSaveDialogImpl::change_path(const Glib::ustring& path)
1543 {
1544 myFilename = path;
1545 if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
1546 //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
1547 set_current_folder(myFilename);
1548 } else {
1549 //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
1550 if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
1551 set_filename(myFilename);
1552 } else {
1553 std::string dirName = Glib::path_get_dirname( myFilename );
1554 if ( dirName != get_current_folder() ) {
1555 set_current_folder(dirName);
1556 }
1557 }
1558 Glib::ustring basename = Glib::path_get_basename(myFilename);
1559 //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
1560 try {
1561 set_current_name( Glib::filename_to_utf8(basename) );
1562 } catch ( Glib::ConvertError& e ) {
1563 g_warning( "Error converting save filename to UTF-8." );
1564 // try a fallback.
1565 set_current_name( basename );
1566 }
1567 }
1568 }
1570 void FileSaveDialogImpl::updateNameAndExtension()
1571 {
1572 // Pick up any changes the user has typed in.
1573 Glib::ustring tmp = get_filename();
1574 #ifdef WITH_GNOME_VFS
1575 if ( tmp.empty() && gnome_vfs_initialized() ) {
1576 tmp = get_uri();
1577 }
1578 #endif
1579 if ( !tmp.empty() ) {
1580 myFilename = tmp;
1581 }
1583 Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
1584 if ( fileTypeCheckbox.get_active() && newOut ) {
1585 try {
1586 bool appendExtension = true;
1587 Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
1588 Glib::ustring::size_type pos = utf8Name.rfind('.');
1589 if ( pos != Glib::ustring::npos ) {
1590 Glib::ustring trail = utf8Name.substr( pos );
1591 Glib::ustring foldedTrail = trail.casefold();
1592 if ( (trail == ".")
1593 | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()
1594 && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {
1595 utf8Name = utf8Name.erase( pos );
1596 } else {
1597 appendExtension = false;
1598 }
1599 }
1601 if (appendExtension) {
1602 utf8Name = utf8Name + newOut->get_extension();
1603 myFilename = Glib::filename_from_utf8( utf8Name );
1604 change_path(myFilename);
1605 }
1606 } catch ( Glib::ConvertError& e ) {
1607 // ignore
1608 }
1609 }
1610 }
1614 //########################################################################
1615 //# F I L E E X P O R T
1616 //########################################################################
1619 /**
1620 * Our implementation of the FileExportDialog interface.
1621 */
1622 class FileExportDialogImpl : public FileExportDialog, public FileDialogBase
1623 {
1625 public:
1626 FileExportDialogImpl(Gtk::Window& parentWindow,
1627 const Glib::ustring &dir,
1628 FileDialogType fileTypes,
1629 const Glib::ustring &title,
1630 const Glib::ustring &default_key);
1632 virtual ~FileExportDialogImpl();
1634 bool show();
1636 Inkscape::Extension::Extension *getSelectionType();
1638 Glib::ustring getFilename();
1641 /**
1642 * Return the scope of the export. One of the enumerated types
1643 * in ScopeType
1644 */
1645 ScopeType getScope()
1646 {
1647 if (pageButton.get_active())
1648 return SCOPE_PAGE;
1649 else if (selectionButton.get_active())
1650 return SCOPE_SELECTION;
1651 else if (customButton.get_active())
1652 return SCOPE_CUSTOM;
1653 else
1654 return SCOPE_DOCUMENT;
1656 }
1658 /**
1659 * Return left side of the exported region
1660 */
1661 double getSourceX()
1662 { return sourceX0Spinner.getValue(); }
1664 /**
1665 * Return the top of the exported region
1666 */
1667 double getSourceY()
1668 { return sourceY1Spinner.getValue(); }
1670 /**
1671 * Return the width of the exported region
1672 */
1673 double getSourceWidth()
1674 { return sourceWidthSpinner.getValue(); }
1676 /**
1677 * Return the height of the exported region
1678 */
1679 double getSourceHeight()
1680 { return sourceHeightSpinner.getValue(); }
1682 /**
1683 * Return the units of the coordinates of exported region
1684 */
1685 Glib::ustring getSourceUnits()
1686 { return sourceUnitsSpinner.getUnitAbbr(); }
1688 /**
1689 * Return the width of the destination document
1690 */
1691 double getDestinationWidth()
1692 { return destWidthSpinner.getValue(); }
1694 /**
1695 * Return the height of the destination document
1696 */
1697 double getDestinationHeight()
1698 { return destHeightSpinner.getValue(); }
1700 /**
1701 * Return the height of the exported region
1702 */
1703 Glib::ustring getDestinationUnits()
1704 { return destUnitsSpinner.getUnitAbbr(); }
1706 /**
1707 * Return the destination DPI image resulution, if bitmap
1708 */
1709 double getDestinationDPI()
1710 { return destDPISpinner.getValue(); }
1712 /**
1713 * Return whether we should use Cairo for rendering
1714 */
1715 bool getUseCairo()
1716 { return cairoButton.get_active(); }
1718 /**
1719 * Return whether we should use antialiasing
1720 */
1721 bool getUseAntialias()
1722 { return antiAliasButton.get_active(); }
1724 /**
1725 * Return the background color for exporting
1726 */
1727 unsigned long getBackground()
1728 { return backgroundButton.get_color().get_pixel(); }
1730 private:
1732 /**
1733 * Fix to allow the user to type the file name
1734 */
1735 Gtk::Entry *fileNameEntry;
1737 //##########################################
1738 //# EXTRA WIDGET -- SOURCE SIDE
1739 //##########################################
1741 Gtk::Frame sourceFrame;
1742 Gtk::VBox sourceBox;
1744 Gtk::HBox scopeBox;
1745 Gtk::RadioButtonGroup scopeGroup;
1746 Gtk::RadioButton documentButton;
1747 Gtk::RadioButton pageButton;
1748 Gtk::RadioButton selectionButton;
1749 Gtk::RadioButton customButton;
1751 Gtk::Table sourceTable;
1752 Inkscape::UI::Widget::Scalar sourceX0Spinner;
1753 Inkscape::UI::Widget::Scalar sourceY0Spinner;
1754 Inkscape::UI::Widget::Scalar sourceX1Spinner;
1755 Inkscape::UI::Widget::Scalar sourceY1Spinner;
1756 Inkscape::UI::Widget::Scalar sourceWidthSpinner;
1757 Inkscape::UI::Widget::Scalar sourceHeightSpinner;
1758 Inkscape::UI::Widget::UnitMenu sourceUnitsSpinner;
1761 //##########################################
1762 //# EXTRA WIDGET -- DESTINATION SIDE
1763 //##########################################
1765 Gtk::Frame destFrame;
1766 Gtk::VBox destBox;
1768 Gtk::Table destTable;
1769 Inkscape::UI::Widget::Scalar destWidthSpinner;
1770 Inkscape::UI::Widget::Scalar destHeightSpinner;
1771 Inkscape::UI::Widget::Scalar destDPISpinner;
1772 Inkscape::UI::Widget::UnitMenu destUnitsSpinner;
1774 Gtk::HBox otherOptionBox;
1775 Gtk::CheckButton cairoButton;
1776 Gtk::CheckButton antiAliasButton;
1777 Gtk::ColorButton backgroundButton;
1780 /**
1781 * 'Extra' widget that holds two boxes above
1782 */
1783 Gtk::HBox exportOptionsBox;
1786 //# Child widgets
1787 Gtk::CheckButton fileTypeCheckbox;
1789 /**
1790 * Allow the specification of the output file type
1791 */
1792 Gtk::ComboBoxText fileTypeComboBox;
1795 /**
1796 * Data mirror of the combo box
1797 */
1798 std::vector<FileType> fileTypes;
1802 /**
1803 * Callback for user input into fileNameEntry
1804 */
1805 void fileTypeChangedCallback();
1807 /**
1808 * Create a filter menu for this type of dialog
1809 */
1810 void createFileTypeMenu();
1813 bool append_extension;
1815 /**
1816 * The extension to use to write this file
1817 */
1818 Inkscape::Extension::Extension *extension;
1820 /**
1821 * Callback for user input into fileNameEntry
1822 */
1823 void fileNameEntryChangedCallback();
1825 /**
1826 * Filename that was given
1827 */
1828 Glib::ustring myFilename;
1829 };
1836 /**
1837 * Callback for fileNameEntry widget
1838 */
1839 void FileExportDialogImpl::fileNameEntryChangedCallback()
1840 {
1841 if (!fileNameEntry)
1842 return;
1844 Glib::ustring fileName = fileNameEntry->get_text();
1845 if (!Glib::get_charset()) //If we are not utf8
1846 fileName = Glib::filename_to_utf8(fileName);
1848 //g_message("User hit return. Text is '%s'\n", fileName.c_str());
1850 if (!Glib::path_is_absolute(fileName)) {
1851 //try appending to the current path
1852 // not this way: fileName = get_current_folder() + "/" + fileName;
1853 std::vector<Glib::ustring> pathSegments;
1854 pathSegments.push_back( get_current_folder() );
1855 pathSegments.push_back( fileName );
1856 fileName = Glib::build_filename(pathSegments);
1857 }
1859 //g_message("path:'%s'\n", fileName.c_str());
1861 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1862 set_current_folder(fileName);
1863 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1864 //dialog with either (1) select a regular file or (2) cd to dir
1865 //simulate an 'OK'
1866 set_filename(fileName);
1867 response(Gtk::RESPONSE_OK);
1868 }
1869 }
1873 /**
1874 * Callback for fileNameEntry widget
1875 */
1876 void FileExportDialogImpl::fileTypeChangedCallback()
1877 {
1878 int sel = fileTypeComboBox.get_active_row_number();
1879 if (sel<0 || sel >= (int)fileTypes.size())
1880 return;
1881 FileType type = fileTypes[sel];
1882 //g_message("selected: %s\n", type.name.c_str());
1883 Gtk::FileFilter filter;
1884 filter.add_pattern(type.pattern);
1885 set_filter(filter);
1886 }
1890 void FileExportDialogImpl::createFileTypeMenu()
1891 {
1892 Inkscape::Extension::DB::OutputList extension_list;
1893 Inkscape::Extension::db.get_output_list(extension_list);
1895 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1896 current_item != extension_list.end(); current_item++)
1897 {
1898 Inkscape::Extension::Output * omod = *current_item;
1900 // FIXME: would be nice to grey them out instead of not listing them
1901 if (omod->deactivated()) continue;
1903 FileType type;
1904 type.name = (_(omod->get_filetypename()));
1905 type.pattern = "*";
1906 Glib::ustring extension = omod->get_extension();
1907 fileDialogExtensionToPattern (type.pattern, extension);
1908 type.extension= omod;
1909 fileTypeComboBox.append_text(type.name);
1910 fileTypes.push_back(type);
1911 }
1913 //#Let user choose
1914 FileType guessType;
1915 guessType.name = _("Guess from extension");
1916 guessType.pattern = "*";
1917 guessType.extension = NULL;
1918 fileTypeComboBox.append_text(guessType.name);
1919 fileTypes.push_back(guessType);
1922 fileTypeComboBox.set_active(0);
1923 fileTypeChangedCallback(); //call at least once to set the filter
1924 }
1927 /**
1928 * Constructor
1929 */
1930 FileExportDialogImpl::FileExportDialogImpl(Gtk::Window& parentWindow,
1931 const Glib::ustring &dir,
1932 FileDialogType fileTypes,
1933 const Glib::ustring &title,
1934 const Glib::ustring &default_key) :
1935 FileDialogBase(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),
1936 sourceX0Spinner("X0", _("Left edge of source")),
1937 sourceY0Spinner("Y0", _("Top edge of source")),
1938 sourceX1Spinner("X1", _("Right edge of source")),
1939 sourceY1Spinner("Y1", _("Bottom edge of source")),
1940 sourceWidthSpinner("Width", _("Source width")),
1941 sourceHeightSpinner("Height", _("Source height")),
1942 destWidthSpinner("Width", _("Destination width")),
1943 destHeightSpinner("Height", _("Destination height")),
1944 destDPISpinner("DPI", _("Resolution (dots per inch)"))
1945 {
1946 append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);
1948 /* One file at a time */
1949 set_select_multiple(false);
1951 #ifdef WITH_GNOME_VFS
1952 if (gnome_vfs_initialized()) {
1953 set_local_only(false);
1954 }
1955 #endif
1957 /* Initalize to Autodetect */
1958 extension = NULL;
1959 /* No filename to start out with */
1960 myFilename = "";
1962 /* Set our dialog type (save, export, etc...)*/
1963 dialogType = fileTypes;
1965 /* Set the pwd and/or the filename */
1966 if (dir.size()>0)
1967 {
1968 Glib::ustring udir(dir);
1969 Glib::ustring::size_type len = udir.length();
1970 // leaving a trailing backslash on the directory name leads to the infamous
1971 // double-directory bug on win32
1972 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1973 set_current_folder(udir.c_str());
1974 }
1976 //#########################################
1977 //## EXTRA WIDGET -- SOURCE SIDE
1978 //#########################################
1980 //##### Export options buttons/spinners, etc
1981 documentButton.set_label(_("Document"));
1982 scopeBox.pack_start(documentButton);
1983 scopeGroup = documentButton.get_group();
1985 pageButton.set_label(_("Page"));
1986 pageButton.set_group(scopeGroup);
1987 scopeBox.pack_start(pageButton);
1989 selectionButton.set_label(_("Selection"));
1990 selectionButton.set_group(scopeGroup);
1991 scopeBox.pack_start(selectionButton);
1993 customButton.set_label(_("Custom"));
1994 customButton.set_group(scopeGroup);
1995 scopeBox.pack_start(customButton);
1997 sourceBox.pack_start(scopeBox);
2001 //dimension buttons
2002 sourceTable.resize(3,3);
2003 sourceTable.attach(sourceX0Spinner, 0,1,0,1);
2004 sourceTable.attach(sourceY0Spinner, 1,2,0,1);
2005 sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
2006 sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);
2007 sourceTable.attach(sourceX1Spinner, 0,1,1,2);
2008 sourceTable.attach(sourceY1Spinner, 1,2,1,2);
2009 sourceTable.attach(sourceWidthSpinner, 0,1,2,3);
2010 sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
2012 sourceBox.pack_start(sourceTable);
2013 sourceFrame.set_label(_("Source"));
2014 sourceFrame.add(sourceBox);
2015 exportOptionsBox.pack_start(sourceFrame);
2018 //#########################################
2019 //## EXTRA WIDGET -- SOURCE SIDE
2020 //#########################################
2023 destTable.resize(3,3);
2024 destTable.attach(destWidthSpinner, 0,1,0,1);
2025 destTable.attach(destHeightSpinner, 1,2,0,1);
2026 destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
2027 destTable.attach(destUnitsSpinner, 2,3,0,1);
2028 destTable.attach(destDPISpinner, 0,1,1,2);
2030 destBox.pack_start(destTable);
2033 cairoButton.set_label(_("Cairo"));
2034 otherOptionBox.pack_start(cairoButton);
2036 antiAliasButton.set_label(_("Antialias"));
2037 otherOptionBox.pack_start(antiAliasButton);
2039 backgroundButton.set_label(_("Background"));
2040 otherOptionBox.pack_start(backgroundButton);
2042 destBox.pack_start(otherOptionBox);
2048 //###### File options
2049 //###### Do we want the .xxx extension automatically added?
2050 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
2051 fileTypeCheckbox.set_active(append_extension);
2052 destBox.pack_start(fileTypeCheckbox);
2054 //###### File type menu
2055 createFileTypeMenu();
2056 fileTypeComboBox.set_size_request(200,40);
2057 fileTypeComboBox.signal_changed().connect(
2058 sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
2060 destBox.pack_start(fileTypeComboBox);
2062 destFrame.set_label(_("Destination"));
2063 destFrame.add(destBox);
2064 exportOptionsBox.pack_start(destFrame);
2066 //##### Put the two boxes and their parent onto the dialog
2067 exportOptionsBox.pack_start(sourceFrame);
2068 exportOptionsBox.pack_start(destFrame);
2070 set_extra_widget(exportOptionsBox);
2075 //Let's do some customization
2076 fileNameEntry = NULL;
2077 Gtk::Container *cont = get_toplevel();
2078 std::vector<Gtk::Entry *> entries;
2079 findEntryWidgets(cont, entries);
2080 //g_message("Found %d entry widgets\n", entries.size());
2081 if (entries.size() >=1 )
2082 {
2083 //Catch when user hits [return] on the text field
2084 fileNameEntry = entries[0];
2085 fileNameEntry->signal_activate().connect(
2086 sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
2087 }
2089 //Let's do more customization
2090 std::vector<Gtk::Expander *> expanders;
2091 findExpanderWidgets(cont, expanders);
2092 //g_message("Found %d expander widgets\n", expanders.size());
2093 if (expanders.size() >=1 )
2094 {
2095 //Always show the file list
2096 Gtk::Expander *expander = expanders[0];
2097 expander->set_expanded(true);
2098 }
2101 //if (extension == NULL)
2102 // checkbox.set_sensitive(FALSE);
2104 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2105 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
2107 show_all_children();
2108 }
2112 /**
2113 * Public factory method. Used in file.cpp
2114 */
2115 FileExportDialog *FileExportDialog::create(Gtk::Window& parentWindow,
2116 const Glib::ustring &path,
2117 FileDialogType fileTypes,
2118 const Glib::ustring &title,
2119 const Glib::ustring &default_key)
2120 {
2121 FileExportDialog *dialog = new FileExportDialogImpl(parentWindow, path, fileTypes, title, default_key);
2122 return dialog;
2123 }
2129 /**
2130 * Destructor
2131 */
2132 FileExportDialogImpl::~FileExportDialogImpl()
2133 {
2134 }
2138 /**
2139 * Show this dialog modally. Return true if user hits [OK]
2140 */
2141 bool
2142 FileExportDialogImpl::show()
2143 {
2144 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
2145 if (s.length() == 0)
2146 s = getcwd (NULL, 0);
2147 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
2148 set_modal (TRUE); //Window
2149 sp_transientize((GtkWidget *)gobj()); //Make transient
2150 gint b = run(); //Dialog
2151 svgPreview.showNoPreview();
2152 hide();
2154 if (b == Gtk::RESPONSE_OK)
2155 {
2156 int sel = fileTypeComboBox.get_active_row_number ();
2157 if (sel>=0 && sel< (int)fileTypes.size())
2158 {
2159 FileType &type = fileTypes[sel];
2160 extension = type.extension;
2161 }
2162 myFilename = get_filename();
2163 #ifdef WITH_GNOME_VFS
2164 if ( myFilename.empty() && gnome_vfs_initialized() ) {
2165 myFilename = get_uri();
2166 }
2167 #endif
2169 /*
2171 // FIXME: Why do we have more code
2173 append_extension = checkbox.get_active();
2174 prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
2175 prefs_set_string_attribute("dialogs.save_as", "default",
2176 ( extension != NULL ? extension->get_id() : "" ));
2177 */
2178 return TRUE;
2179 }
2180 else
2181 {
2182 return FALSE;
2183 }
2184 }
2187 /**
2188 * Get the file extension type that was selected by the user. Valid after an [OK]
2189 */
2190 Inkscape::Extension::Extension *
2191 FileExportDialogImpl::getSelectionType()
2192 {
2193 return extension;
2194 }
2197 /**
2198 * Get the file name chosen by the user. Valid after an [OK]
2199 */
2200 Glib::ustring
2201 FileExportDialogImpl::getFilename()
2202 {
2203 return myFilename;
2204 }
2209 } //namespace Dialog
2210 } //namespace UI
2211 } //namespace Inkscape
2214 /*
2215 Local Variables:
2216 mode:c++
2217 c-file-style:"stroustrup"
2218 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2219 indent-tabs-mode:nil
2220 fill-column:99
2221 End:
2222 */
2223 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :