Code

07052559d38fa5a281149d648d739f55545b3088
[inkscape.git] / src / ui / dialog / filedialog.cpp
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 The Inkscape Organization
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
19 //Temporary ugly hack
20 //Remove these after the get_filter() calls in
21 //show() on both classes are fixed
22 #include <gtk/gtkfilechooser.h>
24 //Another hack
25 #include <gtk/gtkentry.h>
26 #include <gtk/gtkexpander.h>
28 #include <unistd.h>
29 #include <sys/stat.h>
30 #include <glibmm/i18n.h>
31 #include <gtkmm/box.h>
32 #include <gtkmm/filechooserdialog.h>
33 #include <gtkmm/menubar.h>
34 #include <gtkmm/menu.h>
35 #include <gtkmm/entry.h>
36 #include <gtkmm/expander.h>
37 #include <gtkmm/comboboxtext.h>
38 #include <gtkmm/stock.h>
39 #include <gdkmm/pixbuf.h>
41 #include "prefs-utils.h"
42 #include <dialogs/dialog-events.h>
43 #include <extension/input.h>
44 #include <extension/output.h>
45 #include <extension/db.h>
46 #include "inkscape.h"
47 #include "svg-view-widget.h"
48 #include "filedialog.h"
49 #include "gc-core.h"
51 #undef INK_DUMP_FILENAME_CONV
53 #ifdef INK_DUMP_FILENAME_CONV
54 void dump_str( const gchar* str, const gchar* prefix );
55 void dump_ustr( const Glib::ustring& ustr );
56 #endif
58 namespace Inkscape {
59 namespace UI {
60 namespace Dialog {
62 void FileDialogExtensionToPattern (Glib::ustring &pattern, gchar * in_file_extension);
64 /*#########################################################################
65 ### SVG Preview Widget
66 #########################################################################*/
67 /**
68  * Simple class for displaying an SVG file in the "preview widget."
69  * Currently, this is just a wrapper of the sp_svg_view Gtk widget.
70  * Hopefully we will eventually replace with a pure Gtkmm widget.
71  */
72 class SVGPreview : public Gtk::VBox
73 {
74 public:
75     SVGPreview();
76     ~SVGPreview();
78     bool setDocument(SPDocument *doc);
80     bool setFileName(Glib::ustring &fileName);
82     bool setFromMem(char const *xmlBuffer);
84     bool set(Glib::ustring &fileName, int dialogType);
86     bool setURI(URI &uri);
88     /**
89      * Show image embedded in SVG
90      */
91     void showImage(Glib::ustring &fileName);
93     /**
94      * Show the "No preview" image
95      */
96     void showNoPreview();
98     /**
99      * Show the "Too large" image
100      */
101     void showTooLarge(long fileLength);
103 private:
104     /**
105      * The svg document we are currently showing
106      */
107     SPDocument *document;
109     /**
110      * The sp_svg_view widget
111      */
112     GtkWidget *viewerGtk;
114     /**
115      * are we currently showing the "no preview" image?
116      */
117     bool showingNoPreview;
119 };
122 bool SVGPreview::setDocument(SPDocument *doc)
124     if (document)
125         sp_document_unref(document);
127     sp_document_ref(doc);
128     document = doc;
130     //This should remove it from the box, and free resources
131     if (viewerGtk) {
132         gtk_widget_destroy(viewerGtk);
133     }
135     viewerGtk  = sp_svg_view_widget_new(doc);
136     GtkWidget *vbox = (GtkWidget *)gobj();
137     gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);
138     gtk_widget_show(viewerGtk);
140     return true;
143 bool SVGPreview::setFileName(Glib::ustring &theFileName)
145     Glib::ustring fileName = theFileName;
147     fileName = Glib::filename_to_utf8(fileName);
149     SPDocument *doc = sp_document_new (fileName.c_str(), 0);
150     if (!doc) {
151         g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
152         return false;
153     }
155     setDocument(doc);
157     sp_document_unref(doc);
159     return true;
164 bool SVGPreview::setFromMem(char const *xmlBuffer)
166     if (!xmlBuffer)
167         return false;
169     gint len = (gint)strlen(xmlBuffer);
170     SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);
171     if (!doc) {
172         g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);
173         return false;
174     }
176     setDocument(doc);
178     sp_document_unref(doc);
180     Inkscape::GC::request_early_collection();
182     return true;
187 void SVGPreview::showImage(Glib::ustring &theFileName)
189     Glib::ustring fileName = theFileName;
192     /*#####################################
193     # LET'S HAVE SOME FUN WITH SVG!
194     # Instead of just loading an image, why
195     # don't we make a lovely little svg and
196     # display it nicely?
197     #####################################*/
199     //Arbitrary size of svg doc -- rather 'portrait' shaped
200     gint previewWidth  = 400;
201     gint previewHeight = 600;
203     //Get some image info. Smart pointer does not need to be deleted
204     Glib::RefPtr<Gdk::Pixbuf> img = Gdk::Pixbuf::create_from_file(fileName);
205     gint imgWidth  = img->get_width();
206     gint imgHeight = img->get_height();
208     //Find the minimum scale to fit the image inside the preview area
209     double scaleFactorX = (0.9 *(double)previewWidth)  / ((double)imgWidth);
210     double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);
211     double scaleFactor = scaleFactorX;
212     if (scaleFactorX > scaleFactorY)
213         scaleFactor = scaleFactorY;
215     //Now get the resized values
216     gint scaledImgWidth  = (int) (scaleFactor * (double)imgWidth);
217     gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);
219     //center the image on the area
220     gint imgX = (previewWidth  - scaledImgWidth)  / 2;
221     gint imgY = (previewHeight - scaledImgHeight) / 2;
223     //wrap a rectangle around the image
224     gint rectX      = imgX-1;
225     gint rectY      = imgY-1;
226     gint rectWidth  = scaledImgWidth +2;
227     gint rectHeight = scaledImgHeight+2;
229     //Our template.  Modify to taste
230     gchar const *xformat =
231           "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
232           "<svg\n"
233           "xmlns=\"http://www.w3.org/2000/svg\"\n"
234           "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
235           "width=\"%d\" height=\"%d\">\n"
236           "<rect\n"
237           "  style=\"fill:#eeeeee;stroke:none\"\n"
238           "  x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
239           "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
240           "xlink:href=\"%s\"/>\n"
241           "<rect\n"
242           "  style=\"fill:none;"
243           "    stroke:#000000;stroke-width:1.0;"
244           "    stroke-linejoin:miter;stroke-opacity:1.0000000;"
245           "    stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
246           "  x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
247           "<text\n"
248           "  style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
249           "    fill:#000000;fill-opacity:1.0000000;stroke:none;"
250           "    font-family:Bitstream Vera Sans\"\n"
251           "  x=\"10\" y=\"26\">%d x %d</text>\n"
252           "</svg>\n\n";
254     //if (!Glib::get_charset()) //If we are not utf8
255     fileName = Glib::filename_to_utf8(fileName);
257     //Fill in the template
258     /* FIXME: Do proper XML quoting for fileName. */
259     gchar *xmlBuffer = g_strdup_printf(xformat,
260            previewWidth, previewHeight,
261            imgX, imgY, scaledImgWidth, scaledImgHeight,
262            fileName.c_str(),
263            rectX, rectY, rectWidth, rectHeight,
264            imgWidth, imgHeight);
266     //g_message("%s\n", xmlBuffer);
268     //now show it!
269     setFromMem(xmlBuffer);
270     g_free(xmlBuffer);
275 void SVGPreview::showNoPreview()
277     //Are we already showing it?
278     if (showingNoPreview)
279         return;
281     //Arbitrary size of svg doc -- rather 'portrait' shaped
282     gint previewWidth  = 300;
283     gint previewHeight = 600;
285     //Our template.  Modify to taste
286     gchar const *xformat =
287           "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
288           "<svg\n"
289           "xmlns=\"http://www.w3.org/2000/svg\"\n"
290           "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
291           "width=\"%d\" height=\"%d\">\n"
292           "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
293           "<path\n"
294           "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
295           "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
296           "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
297           "id=\"whiteSpace\" />\n"
298           "<path\n"
299           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
300           "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
301           "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
302           "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
303           "id=\"droplet01\" />\n"
304           "<path\n"
305           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
306           "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
307           "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
308           "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
309           "287.18046 343.1206 286.46194 340.42914 z \"\n"
310           "id=\"droplet02\" />\n"
311           "<path\n"
312           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
313           "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
314           "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
315           "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
316           "id=\"droplet03\" />\n"
317           "<path\n"
318           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
319           "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
320           "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
321           "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
322           "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
323           "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
324           "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
325           "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
326           "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
327           "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
328           "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
329           "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
330           "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
331           "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
332           "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
333           "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
334           "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
335           "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
336           "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
337           "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
338           "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
339           "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
340           "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
341           "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
342           "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
343           "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
344           "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
345           "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
346           "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
347           "id=\"mountainDroplet\" />\n"
348           "</g> <g transform=\"translate(-20,0)\">\n"
349           "<text xml:space=\"preserve\"\n"
350           "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
351           "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
352           "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
353           "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
354           "x=\"190\" y=\"240\">%s</text></g>\n"
355           "</svg>\n\n";
357     //Fill in the template
358     gchar *xmlBuffer = g_strdup_printf(xformat,
359            previewWidth, previewHeight, _("No preview"));
361     //g_message("%s\n", xmlBuffer);
363     //now show it!
364     setFromMem(xmlBuffer);
365     g_free(xmlBuffer);
366     showingNoPreview = true;
370 void SVGPreview::showTooLarge(long fileLength)
373     //Arbitrary size of svg doc -- rather 'portrait' shaped
374     gint previewWidth  = 300;
375     gint previewHeight = 600;
377     //Our template.  Modify to taste
378     gchar const *xformat =
379           "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
380           "<svg\n"
381           "xmlns=\"http://www.w3.org/2000/svg\"\n"
382           "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
383           "width=\"%d\" height=\"%d\">\n"
384           "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
385           "<path\n"
386           "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
387           "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
388           "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
389           "id=\"whiteSpace\" />\n"
390           "<path\n"
391           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
392           "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
393           "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
394           "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
395           "id=\"droplet01\" />\n"
396           "<path\n"
397           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
398           "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
399           "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
400           "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
401           "287.18046 343.1206 286.46194 340.42914 z \"\n"
402           "id=\"droplet02\" />\n"
403           "<path\n"
404           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
405           "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
406           "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
407           "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
408           "id=\"droplet03\" />\n"
409           "<path\n"
410           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
411           "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
412           "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
413           "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
414           "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
415           "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
416           "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
417           "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
418           "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
419           "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
420           "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
421           "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
422           "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
423           "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
424           "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
425           "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
426           "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
427           "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
428           "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
429           "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
430           "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
431           "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
432           "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
433           "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
434           "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
435           "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
436           "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
437           "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
438           "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
439           "id=\"mountainDroplet\" />\n"
440           "</g>\n"
441           "<text xml:space=\"preserve\"\n"
442           "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
443           "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
444           "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
445           "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
446           "x=\"170\" y=\"215\">%5.1f MB</text>\n"
447           "<text xml:space=\"preserve\"\n"
448           "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
449           "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
450           "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
451           "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
452           "x=\"180\" y=\"245\">%s</text>\n"
453           "</svg>\n\n";
455     //Fill in the template
456     double floatFileLength = ((double)fileLength) / 1048576.0;
457     //printf("%ld %f\n", fileLength, floatFileLength);
458     gchar *xmlBuffer = g_strdup_printf(xformat,
459            previewWidth, previewHeight, floatFileLength,
460            _("too large for preview"));
462     //g_message("%s\n", xmlBuffer);
464     //now show it!
465     setFromMem(xmlBuffer);
466     g_free(xmlBuffer);
470 static bool
471 hasSuffix(Glib::ustring &str, Glib::ustring &ext)
473     int strLen = str.length();
474     int extLen = ext.length();
475     if (extLen > strLen)
476     {
477         return false;
478     }
479     int strpos = strLen-1;
480     for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)
481     {
482         Glib::ustring::value_type ch = str[strpos];
483         if (ch != ext[extpos])
484         {
485             if ( ((ch & 0xff80) != 0) ||
486                  static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )
487             {
488                 return false;
489             }
490         }
491     }
492     return true;
496 /**
497  * Return true if the image is loadable by Gdk, else false
498  */
499 static bool
500 isValidImageFile(Glib::ustring &fileName)
502     std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();
503     for (unsigned int i=0; i<formats.size(); i++)
504         {
505         Gdk::PixbufFormat format = formats[i];
506         std::vector<Glib::ustring>extensions = format.get_extensions();
507         for (unsigned int j=0; j<extensions.size(); j++)
508             {
509             Glib::ustring ext = extensions[j];
510             if (hasSuffix(fileName, ext))
511                 {
512                 return true;
513                 }
514             }
515         }
516     return false;
519 bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
522     if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
523         return false;
525     gchar *fName = (gchar *)fileName.c_str();
526     //g_message("fname:%s\n", fName);
529     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
530         {
531         struct stat info;
532         if (stat(fName, &info))
533             {
534             return FALSE;
535             }
536         long fileLen = info.st_size;
537         if (fileLen > 0x150000L)
538             {
539             showingNoPreview = false;
540             showTooLarge(fileLen);
541             return FALSE;
542             }
543         }
545     Glib::ustring svg = ".svg";
546     Glib::ustring svgz = ".svgz";
548     if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
549            (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz)   )
550          )
551         {
552         bool retval = setFileName(fileName);
553         showingNoPreview = false;
554         return retval;
555         }
556     else if (isValidImageFile(fileName))
557         {
558         showImage(fileName);
559         showingNoPreview = false;
560         return true;
561         }
562     else
563         {
564         showNoPreview();
565         return false;
566         }
570 SVGPreview::SVGPreview()
572     if (!INKSCAPE)
573         inkscape_application_init("",false);
574     document = NULL;
575     viewerGtk = NULL;
576     set_size_request(150,150);
577     showingNoPreview = false;
580 SVGPreview::~SVGPreview()
589 /*#########################################################################
590 ### F I L E    O P E N
591 #########################################################################*/
593 /**
594  * Our implementation class for the FileOpenDialog interface..
595  */
596 class FileOpenDialogImpl : public FileOpenDialog, public Gtk::FileChooserDialog
598 public:
599     FileOpenDialogImpl(char const *dir,
600                        FileDialogType fileTypes,
601                        char const *title);
603     virtual ~FileOpenDialogImpl();
605     bool show();
607     Inkscape::Extension::Extension *getSelectionType();
609     gchar *getFilename();
611     Glib::SListHandle<Glib::ustring> getFilenames ();
612 protected:
616 private:
619     /**
620      * What type of 'open' are we? (open, import, place, etc)
621      */
622     FileDialogType dialogType;
624     /**
625      * Our svg preview widget
626      */
627     SVGPreview svgPreview;
629     /**
630      * Callback for seeing if the preview needs to be drawn
631      */
632     void updatePreviewCallback();
634     /**
635      * Fix to allow the user to type the file name
636      */
637     Gtk::Entry fileNameEntry;
639     /**
640      *  Create a filter menu for this type of dialog
641      */
642     void createFilterMenu();
644     /**
645      * Callback for user input into fileNameEntry
646      */
647     void fileNameEntryChangedCallback();
649     /**
650      * Callback for user changing which item is selected on the list
651      */
652     void fileSelectedCallback();
655     /**
656      * Filter name->extension lookup
657      */
658     std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;
660     /**
661      * The extension to use to write this file
662      */
663     Inkscape::Extension::Extension *extension;
665     /**
666      * Filename that was given
667      */
668     Glib::ustring myFilename;
670 };
676 /**
677  * Callback for checking if the preview needs to be redrawn
678  */
679 void FileOpenDialogImpl::updatePreviewCallback()
681     Glib::ustring fileName = get_preview_filename();
682     if (fileName.length() < 1)
683         return;
684     svgPreview.set(fileName, dialogType);
691 /**
692  * Callback for fileNameEntry widget
693  */
694 void FileOpenDialogImpl::fileNameEntryChangedCallback()
696     Glib::ustring fileName = fileNameEntry.get_text();
698     // TODO remove this leak
699     fileName = Glib::filename_from_utf8(fileName);
701     //g_message("User hit return.  Text is '%s'\n", fName.c_str());
703     if (!Glib::path_is_absolute(fileName)) {
704         //try appending to the current path
705         // not this way: fileName = get_current_folder() + "/" + fName;
706         std::vector<Glib::ustring> pathSegments;
707         pathSegments.push_back( get_current_folder() );
708         pathSegments.push_back( fileName );
709         fileName = Glib::build_filename(pathSegments);
710     }
712     //g_message("path:'%s'\n", fName.c_str());
714     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
715         set_current_folder(fileName);
716     } else if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) {
717         //dialog with either (1) select a regular file or (2) cd to dir
718         //simulate an 'OK'
719         set_filename(fileName);
720         response(Gtk::RESPONSE_OK);
721     }
728 /**
729  * Callback for fileNameEntry widget
730  */
731 void FileOpenDialogImpl::fileSelectedCallback()
733     Glib::ustring fileName     = get_filename();
734     if (!Glib::get_charset()) //If we are not utf8
735         fileName = Glib::filename_to_utf8(fileName);
736     //g_message("User selected '%s'\n",
737     //       filename().c_str());
739 #ifdef INK_DUMP_FILENAME_CONV
740     ::dump_ustr( get_filename() );
741 #endif
742     fileNameEntry.set_text(fileName);
748 void FileOpenDialogImpl::createFilterMenu()
750     //patterns added dynamically below
751     Gtk::FileFilter allImageFilter;
752     allImageFilter.set_name(_("All Images"));
753     extensionMap[Glib::ustring(_("All Images"))]=NULL;
754     add_filter(allImageFilter);
756     Gtk::FileFilter allFilter;
757     allFilter.set_name(_("All Files"));
758     extensionMap[Glib::ustring(_("All Files"))]=NULL;
759     allFilter.add_pattern("*");
760     add_filter(allFilter);
762     //patterns added dynamically below
763     Gtk::FileFilter allInkscapeFilter;
764     allInkscapeFilter.set_name(_("All Inkscape Files"));
765     extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
766     add_filter(allInkscapeFilter);
768     Inkscape::Extension::DB::InputList extension_list;
769     Inkscape::Extension::db.get_input_list(extension_list);
771     for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
772          current_item != extension_list.end(); current_item++)
773     {
774         Inkscape::Extension::Input * imod = *current_item;
776         // FIXME: would be nice to grey them out instead of not listing them
777         if (imod->deactivated()) continue;
779         Glib::ustring upattern("*");
780         FileDialogExtensionToPattern (upattern, imod->get_extension());
782         Gtk::FileFilter filter;
783         Glib::ustring uname(_(imod->get_filetypename()));
784         filter.set_name(uname);
785         filter.add_pattern(upattern);
786         add_filter(filter);
787         extensionMap[uname] = imod;
789         //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
790         allInkscapeFilter.add_pattern(upattern);
791         if ( strncmp("image", imod->get_mimetype(), 5)==0 )
792             allImageFilter.add_pattern(upattern);
793     }
795     return;
800 /**
801  * Constructor.  Not called directly.  Use the factory.
802  */
803 FileOpenDialogImpl::FileOpenDialogImpl(char const *dir,
804                                        FileDialogType fileTypes,
805                                        char const *title) :
806                  Gtk::FileChooserDialog(Glib::ustring(title))
810     /* One file at a time */
811     /* And also Multiple Files */
812     set_select_multiple(true);
814     /* Initalize to Autodetect */
815     extension = NULL;
816     /* No filename to start out with */
817     myFilename = "";
819     /* Set our dialog type (open, import, etc...)*/
820     dialogType = fileTypes;
823     /* Set the pwd and/or the filename */
824     if (dir != NULL)
825     {
826         Glib::ustring udir(dir);
827         Glib::ustring::size_type len = udir.length();
828         // leaving a trailing backslash on the directory name leads to the infamous
829         // double-directory bug on win32
830         if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
831         set_current_folder(udir.c_str());
832     }
834     //###### Add the file types menu
835     createFilterMenu();
837     //###### Add a preview widget
838     set_preview_widget(svgPreview);
839     set_preview_widget_active(true);
840     set_use_preview_label (false);
842     //Catch selection-changed events, so we can adjust the text widget
843     signal_update_preview().connect(
844          sigc::mem_fun(*this, &FileOpenDialogImpl::updatePreviewCallback) );
847     //###### Add a text entry bar, and tie it to file chooser events
848     fileNameEntry.set_text(get_current_folder());
849     set_extra_widget(fileNameEntry);
850     fileNameEntry.grab_focus();
852     //Catch when user hits [return] on the text field
853     fileNameEntry.signal_activate().connect(
854          sigc::mem_fun(*this, &FileOpenDialogImpl::fileNameEntryChangedCallback) );
856     //Catch selection-changed events, so we can adjust the text widget
857     signal_selection_changed().connect(
858          sigc::mem_fun(*this, &FileOpenDialogImpl::fileSelectedCallback) );
860     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
861     add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK);
869 /**
870  * Public factory.  Called by file.cpp, among others.
871  */
872 FileOpenDialog *FileOpenDialog::create(char const *path,
873                                        FileDialogType fileTypes,
874                                        char const *title)
876     FileOpenDialog *dialog = new FileOpenDialogImpl(path, fileTypes, title);
877     return dialog;
883 /**
884  * Destructor
885  */
886 FileOpenDialogImpl::~FileOpenDialogImpl()
892 /**
893  * Show this dialog modally.  Return true if user hits [OK]
894  */
895 bool
896 FileOpenDialogImpl::show()
898     Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
899     if (s.length() == 0) 
900         s = getcwd (NULL, 0);
901     set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
902     set_modal (TRUE);                      //Window
903     sp_transientize((GtkWidget *)gobj());  //Make transient
904     gint b = run();                        //Dialog
905     svgPreview.showNoPreview();
906     hide();
908     if (b == Gtk::RESPONSE_OK)
909         {
910         //This is a hack, to avoid the warning messages that
911         //Gtk::FileChooser::get_filter() returns
912         //should be:  Gtk::FileFilter *filter = get_filter();
913         GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
914         GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
915         if (filter)
916             {
917             //Get which extension was chosen, if any
918             extension = extensionMap[gtk_file_filter_get_name(filter)];
919             }
920         myFilename = get_filename();
921         return TRUE;
922         }
923     else
924        {
925        return FALSE;
926        }
932 /**
933  * Get the file extension type that was selected by the user. Valid after an [OK]
934  */
935 Inkscape::Extension::Extension *
936 FileOpenDialogImpl::getSelectionType()
938     return extension;
942 /**
943  * Get the file name chosen by the user.   Valid after an [OK]
944  */
945 gchar *
946 FileOpenDialogImpl::getFilename (void)
948     return g_strdup(myFilename.c_str());
952 /**
953  * To Get Multiple filenames selected at-once.
954  */
955 Glib::SListHandle<Glib::ustring>FileOpenDialogImpl::getFilenames()
956 {    
957     return get_filenames();
965 /*#########################################################################
966 # F I L E    S A V E
967 #########################################################################*/
969 class FileType
971     public:
972     FileType() {}
973     ~FileType() {}
974     Glib::ustring name;
975     Glib::ustring pattern;
976     Inkscape::Extension::Extension *extension;
977 };
979 /**
980  * Our implementation of the FileSaveDialog interface.
981  */
982 class FileSaveDialogImpl : public FileSaveDialog, public Gtk::FileChooserDialog
985 public:
986     FileSaveDialogImpl(char const *dir,
987                        FileDialogType fileTypes,
988                        char const *title,
989                        char const *default_key);
991     virtual ~FileSaveDialogImpl();
993     bool show();
995     Inkscape::Extension::Extension *getSelectionType();
997     gchar *getFilename();
1000 private:
1002     /**
1003      * What type of 'open' are we? (save, export, etc)
1004      */
1005     FileDialogType dialogType;
1007     /**
1008      * Our svg preview widget
1009      */
1010     SVGPreview svgPreview;
1012     /**
1013      * Fix to allow the user to type the file name
1014      */
1015     Gtk::Entry *fileNameEntry;
1017     /**
1018      * Callback for seeing if the preview needs to be drawn
1019      */
1020     void updatePreviewCallback();
1024     /**
1025      * Allow the specification of the output file type
1026      */
1027     Gtk::HBox fileTypeBox;
1029     /**
1030      * Allow the specification of the output file type
1031      */
1032     Gtk::ComboBoxText fileTypeComboBox;
1035     /**
1036      *  Data mirror of the combo box
1037      */
1038     std::vector<FileType> fileTypes;
1040     //# Child widgets
1041     Gtk::CheckButton fileTypeCheckbox;
1044     /**
1045      * Callback for user input into fileNameEntry
1046      */
1047     void fileTypeChangedCallback();
1049     /**
1050      *  Create a filter menu for this type of dialog
1051      */
1052     void createFileTypeMenu();
1055     bool append_extension;
1057     /**
1058      * The extension to use to write this file
1059      */
1060     Inkscape::Extension::Extension *extension;
1062     /**
1063      * Callback for user input into fileNameEntry
1064      */
1065     void fileNameEntryChangedCallback();
1067     /**
1068      * Filename that was given
1069      */
1070     Glib::ustring myFilename;
1071 };
1078 /**
1079  * Callback for checking if the preview needs to be redrawn
1080  */
1081 void FileSaveDialogImpl::updatePreviewCallback()
1083     Glib::ustring fileName = get_preview_filename();
1084     if (!fileName.c_str())
1085         return;
1086     bool retval = svgPreview.set(fileName, dialogType);
1087     set_preview_widget_active(retval);
1092 /**
1093  * Callback for fileNameEntry widget
1094  */
1095 void FileSaveDialogImpl::fileNameEntryChangedCallback()
1097     if (!fileNameEntry)
1098         return;
1100     Glib::ustring fileName = fileNameEntry->get_text();
1101     if (!Glib::get_charset()) //If we are not utf8
1102         fileName = Glib::filename_to_utf8(fileName);
1104     //g_message("User hit return.  Text is '%s'\n", fileName.c_str());
1106     if (!Glib::path_is_absolute(fileName)) {
1107         //try appending to the current path
1108         // not this way: fileName = get_current_folder() + "/" + fileName;
1109         std::vector<Glib::ustring> pathSegments;
1110         pathSegments.push_back( get_current_folder() );
1111         pathSegments.push_back( fileName );
1112         fileName = Glib::build_filename(pathSegments);
1113     }
1115     //g_message("path:'%s'\n", fileName.c_str());
1117     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1118         set_current_folder(fileName);
1119     } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1120         //dialog with either (1) select a regular file or (2) cd to dir
1121         //simulate an 'OK'
1122         set_filename(fileName);
1123         response(Gtk::RESPONSE_OK);
1124     }
1129 /**
1130  * Callback for fileNameEntry widget
1131  */
1132 void FileSaveDialogImpl::fileTypeChangedCallback()
1134     int sel = fileTypeComboBox.get_active_row_number();
1135     if (sel<0 || sel >= (int)fileTypes.size())
1136         return;
1137     FileType type = fileTypes[sel];
1138     //g_message("selected: %s\n", type.name.c_str());
1139     Gtk::FileFilter filter;
1140     filter.add_pattern(type.pattern);
1141     set_filter(filter);
1146 void FileSaveDialogImpl::createFileTypeMenu()
1148     Inkscape::Extension::DB::OutputList extension_list;
1149     Inkscape::Extension::db.get_output_list(extension_list);
1151     for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1152          current_item != extension_list.end(); current_item++)
1153     {
1154         Inkscape::Extension::Output * omod = *current_item;
1156         // FIXME: would be nice to grey them out instead of not listing them
1157         if (omod->deactivated()) continue;
1159         FileType type;
1160         type.name     = (_(omod->get_filetypename()));
1161         type.pattern  = "*";
1162         FileDialogExtensionToPattern (type.pattern, omod->get_extension());
1163         type.extension= omod;
1164         fileTypeComboBox.append_text(type.name);
1165         fileTypes.push_back(type);
1166     }
1168     //#Let user choose
1169     FileType guessType;
1170     guessType.name = _("Guess from extension");
1171     guessType.pattern = "*";
1172     guessType.extension = NULL;
1173     fileTypeComboBox.append_text(guessType.name);
1174     fileTypes.push_back(guessType);
1177     fileTypeComboBox.set_active(0);
1178     fileTypeChangedCallback(); //call at least once to set the filter
1182 void findEntryWidgets(Gtk::Container *parent, std::vector<Gtk::Entry *> &result)
1184     if (!parent)
1185         return;
1186     std::vector<Gtk::Widget *> children = parent->get_children();
1187     for (unsigned int i=0; i<children.size() ; i++)
1188         {
1189         Gtk::Widget *child = children[i];
1190         GtkWidget *wid = child->gobj();
1191         if (GTK_IS_ENTRY(wid))
1192            result.push_back((Gtk::Entry *)child);
1193         else if (GTK_IS_CONTAINER(wid))
1194             findEntryWidgets((Gtk::Container *)child, result);
1195         }
1199 void findExpanderWidgets(Gtk::Container *parent, std::vector<Gtk::Expander *> &result)
1201     if (!parent)
1202         return;
1203     std::vector<Gtk::Widget *> children = parent->get_children();
1204     for (unsigned int i=0; i<children.size() ; i++)
1205         {
1206         Gtk::Widget *child = children[i];
1207         GtkWidget *wid = child->gobj();
1208         if (GTK_IS_EXPANDER(wid))
1209            result.push_back((Gtk::Expander *)child);
1210         else if (GTK_IS_CONTAINER(wid))
1211             findExpanderWidgets((Gtk::Container *)child, result);
1212         }
1217 /**
1218  * Constructor
1219  */
1220 FileSaveDialogImpl::FileSaveDialogImpl(char const *dir,
1221                                        FileDialogType fileTypes,
1222                                        char const *title,
1223                                        char const *default_key) :
1224                                        Gtk::FileChooserDialog(Glib::ustring(title),
1225                                            Gtk::FILE_CHOOSER_ACTION_SAVE)
1227     append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);
1229     /* One file at a time */
1230     set_select_multiple(false);
1232     /* Initalize to Autodetect */
1233     extension = NULL;
1234     /* No filename to start out with */
1235     myFilename = "";
1237     /* Set our dialog type (save, export, etc...)*/
1238     dialogType = fileTypes;
1240     /* Set the pwd and/or the filename */
1241     if (dir != NULL)
1242     {
1243         Glib::ustring udir(dir);
1244         Glib::ustring::size_type len = udir.length();
1245         // leaving a trailing backslash on the directory name leads to the infamous
1246         // double-directory bug on win32
1247         if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1248         set_current_folder(udir.c_str());
1249     }
1251     //###### Add the file types menu
1252     //createFilterMenu();
1254     //###### Do we want the .xxx extension automatically added?
1255     fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
1256     fileTypeCheckbox.set_active(append_extension);
1258     fileTypeBox.pack_start(fileTypeCheckbox);
1259     createFileTypeMenu();
1260     fileTypeComboBox.set_size_request(200,40);
1261     fileTypeComboBox.signal_changed().connect(
1262          sigc::mem_fun(*this, &FileSaveDialogImpl::fileTypeChangedCallback) );
1264     fileTypeBox.pack_start(fileTypeComboBox);
1266     set_extra_widget(fileTypeBox);
1267     //get_vbox()->pack_start(fileTypeBox, false, false, 0);
1268     //get_vbox()->reorder_child(fileTypeBox, 2);
1270     //###### Add a preview widget
1271     set_preview_widget(svgPreview);
1272     set_preview_widget_active(true);
1273     set_use_preview_label (false);
1275     //Catch selection-changed events, so we can adjust the text widget
1276     signal_update_preview().connect(
1277          sigc::mem_fun(*this, &FileSaveDialogImpl::updatePreviewCallback) );
1280     //Let's do some customization
1281     fileNameEntry = NULL;
1282     Gtk::Container *cont = get_toplevel();
1283     std::vector<Gtk::Entry *> entries;
1284     findEntryWidgets(cont, entries);
1285     //g_message("Found %d entry widgets\n", entries.size());
1286     if (entries.size() >=1 )
1287         {
1288         //Catch when user hits [return] on the text field
1289         fileNameEntry = entries[0];
1290         fileNameEntry->signal_activate().connect(
1291              sigc::mem_fun(*this, &FileSaveDialogImpl::fileNameEntryChangedCallback) );
1292         }
1294     //Let's do more customization
1295     std::vector<Gtk::Expander *> expanders;
1296     findExpanderWidgets(cont, expanders);
1297     //g_message("Found %d expander widgets\n", expanders.size());
1298     if (expanders.size() >=1 )
1299         {
1300         //Always show the file list
1301         Gtk::Expander *expander = expanders[0];
1302         expander->set_expanded(true);
1303         }
1306     //if (extension == NULL)
1307     //    checkbox.set_sensitive(FALSE);
1309     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1310     add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK);
1312     show_all_children();
1317 /**
1318  * Public factory method.  Used in file.cpp
1319  */
1320 FileSaveDialog *FileSaveDialog::create(char const *path,
1321                                        FileDialogType fileTypes,
1322                                        char const *title,
1323                                        char const *default_key)
1325     FileSaveDialog *dialog = new FileSaveDialogImpl(path, fileTypes, title, default_key);
1326     return dialog;
1333 /**
1334  * Destructor
1335  */
1336 FileSaveDialogImpl::~FileSaveDialogImpl()
1342 /**
1343  * Show this dialog modally.  Return true if user hits [OK]
1344  */
1345 bool
1346 FileSaveDialogImpl::show()
1348     Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
1349     if (s.length() == 0) 
1350         s = getcwd (NULL, 0);
1351     set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
1352     set_modal (TRUE);                      //Window
1353     sp_transientize((GtkWidget *)gobj());  //Make transient
1354     gint b = run();                        //Dialog
1355     svgPreview.showNoPreview();
1356     hide();
1358     if (b == Gtk::RESPONSE_OK)
1359         {
1360         int sel = fileTypeComboBox.get_active_row_number ();
1361         if (sel>=0 && sel< (int)fileTypes.size())
1362             {
1363             FileType &type = fileTypes[sel];
1364             extension = type.extension;
1365             }
1366         myFilename = get_filename();
1368         /*
1370         // FIXME: Why do we have more code
1372         append_extension = checkbox.get_active();
1373         prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
1374         prefs_set_string_attribute("dialogs.save_as", "default",
1375                   ( extension != NULL ? extension->get_id() : "" ));
1376         */
1377         return TRUE;
1378         }
1379     else
1380         {
1381         return FALSE;
1382         }
1386 /**
1387  * Get the file extension type that was selected by the user. Valid after an [OK]
1388  */
1389 Inkscape::Extension::Extension *
1390 FileSaveDialogImpl::getSelectionType()
1392     return extension;
1396 /**
1397  * Get the file name chosen by the user.   Valid after an [OK]
1398  */
1399 gchar *
1400 FileSaveDialogImpl::getFilename()
1402     return g_strdup(myFilename.c_str());
1405 /**
1406     \brief  A quick function to turn a standard extension into a searchable
1407             pattern for the file dialogs
1408     \param  pattern  The patter that the extension should be written to
1409     \param  in_file_extension  The C string that represents the extension
1411     This function just goes through the string, and takes all characters
1412     and puts a [<upper><lower>] so that both are searched and shown in
1413     the file dialog.  This function edits the pattern string to make
1414     this happen.
1415 */
1416 void
1417 FileDialogExtensionToPattern (Glib::ustring &pattern, gchar * in_file_extension)
1419     Glib::ustring tmp(in_file_extension);
1421     for ( guint i = 0; i < tmp.length(); i++ ) {
1422         Glib::ustring::value_type ch = tmp.at(i);
1423         if ( Glib::Unicode::isalpha(ch) ) {
1424             pattern += '[';
1425             pattern += Glib::Unicode::toupper(ch);
1426             pattern += Glib::Unicode::tolower(ch);
1427             pattern += ']';
1428         } else {
1429             pattern += ch;
1430         }
1431     }
1434 } //namespace Dialog
1435 } //namespace UI
1436 } //namespace Inkscape
1439 /*
1440   Local Variables:
1441   mode:c++
1442   c-file-style:"stroustrup"
1443   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1444   indent-tabs-mode:nil
1445   fill-column:99
1446   End:
1447 */
1448 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :