Code

894129795fc885e40b72de19b79bff1c8e29df44
[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) 2006 Johan Engelen <johan@shouraizou.nl>
9  * Copyright (C) 2004-2006 The Inkscape Organization
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
20 //Temporary ugly hack
21 //Remove these after the get_filter() calls in
22 //show() on both classes are fixed
23 #include <gtk/gtkfilechooser.h>
25 //Another hack
26 #include <gtk/gtkentry.h>
27 #include <gtk/gtkexpander.h>
29 #include <unistd.h>
30 #include <sys/stat.h>
31 #include <set>
32 #include <glibmm/i18n.h>
33 #include <gtkmm/box.h>
34 #include <gtkmm/colorbutton.h>
35 #include <gtkmm/frame.h>
36 #include <gtkmm/filechooserdialog.h>
37 #include <gtkmm/menubar.h>
38 #include <gtkmm/menu.h>
39 #include <gtkmm/entry.h>
40 #include <gtkmm/expander.h>
41 #include <gtkmm/comboboxtext.h>
42 #include <gtkmm/stock.h>
43 #include <gdkmm/pixbuf.h>
45 #include "prefs-utils.h"
46 #include <dialogs/dialog-events.h>
47 #include <extension/input.h>
48 #include <extension/output.h>
49 #include <extension/db.h>
50 #include "inkscape.h"
51 #include "svg-view-widget.h"
52 #include "filedialog.h"
53 #include "gc-core.h"
55 //For export dialog
56 #include "ui/widget/scalar-unit.h"
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
66 namespace Inkscape
67 {
68 namespace UI
69 {
70 namespace Dialog
71 {
77 //########################################################################
78 //### U T I L I T Y
79 //########################################################################
81 /**
82     \brief  A quick function to turn a standard extension into a searchable
83             pattern for the file dialogs
84     \param  pattern  The patter that the extension should be written to
85     \param  in_file_extension  The C string that represents the extension
87     This function just goes through the string, and takes all characters
88     and puts a [<upper><lower>] so that both are searched and shown in
89     the file dialog.  This function edits the pattern string to make
90     this happen.
91 */
92 static void
93 fileDialogExtensionToPattern(Glib::ustring &pattern,
94                       Glib::ustring &extension)
95 {
96     for (unsigned int i = 0; i < extension.length(); i++ )
97         {
98         Glib::ustring::value_type ch = extension[i];
99         if ( Glib::Unicode::isalpha(ch) )
100             {
101             pattern += '[';
102             pattern += Glib::Unicode::toupper(ch);
103             pattern += Glib::Unicode::tolower(ch);
104             pattern += ']';
105             }
106         else
107             {
108             pattern += ch;
109             }
110         }
114 /**
115  *  Hack:  Find all entry widgets in a container
116  */
117 static void
118 findEntryWidgets(Gtk::Container *parent,
119                  std::vector<Gtk::Entry *> &result)
121     if (!parent)
122         return;
123     std::vector<Gtk::Widget *> children = parent->get_children();
124     for (unsigned int i=0; i<children.size() ; i++)
125         {
126         Gtk::Widget *child = children[i];
127         GtkWidget *wid = child->gobj();
128         if (GTK_IS_ENTRY(wid))
129            result.push_back((Gtk::Entry *)child);
130         else if (GTK_IS_CONTAINER(wid))
131             findEntryWidgets((Gtk::Container *)child, result);
132         }
139 /**
140  *  Hack:  Find all expander widgets in a container
141  */
142 static void
143 findExpanderWidgets(Gtk::Container *parent,
144                     std::vector<Gtk::Expander *> &result)
146     if (!parent)
147         return;
148     std::vector<Gtk::Widget *> children = parent->get_children();
149     for (unsigned int i=0; i<children.size() ; i++)
150         {
151         Gtk::Widget *child = children[i];
152         GtkWidget *wid = child->gobj();
153         if (GTK_IS_EXPANDER(wid))
154            result.push_back((Gtk::Expander *)child);
155         else if (GTK_IS_CONTAINER(wid))
156             findExpanderWidgets((Gtk::Container *)child, result);
157         }
162 /*#########################################################################
163 ### SVG Preview Widget
164 #########################################################################*/
166 /**
167  * Simple class for displaying an SVG file in the "preview widget."
168  * Currently, this is just a wrapper of the sp_svg_view Gtk widget.
169  * Hopefully we will eventually replace with a pure Gtkmm widget.
170  */
171 class SVGPreview : public Gtk::VBox
173 public:
175     SVGPreview();
177     ~SVGPreview();
179     bool setDocument(SPDocument *doc);
181     bool setFileName(Glib::ustring &fileName);
183     bool setFromMem(char const *xmlBuffer);
185     bool set(Glib::ustring &fileName, int dialogType);
187     bool setURI(URI &uri);
189     /**
190      * Show image embedded in SVG
191      */
192     void showImage(Glib::ustring &fileName);
194     /**
195      * Show the "No preview" image
196      */
197     void showNoPreview();
199     /**
200      * Show the "Too large" image
201      */
202     void showTooLarge(long fileLength);
204 private:
205     /**
206      * The svg document we are currently showing
207      */
208     SPDocument *document;
210     /**
211      * The sp_svg_view widget
212      */
213     GtkWidget *viewerGtk;
215     /**
216      * are we currently showing the "no preview" image?
217      */
218     bool showingNoPreview;
220 };
223 bool SVGPreview::setDocument(SPDocument *doc)
225     if (document)
226         sp_document_unref(document);
228     sp_document_ref(doc);
229     document = doc;
231     //This should remove it from the box, and free resources
232     if (viewerGtk)
233         gtk_widget_destroy(viewerGtk);
235     viewerGtk  = sp_svg_view_widget_new(doc);
236     GtkWidget *vbox = (GtkWidget *)gobj();
237     gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);
238     gtk_widget_show(viewerGtk);
240     return true;
243 bool SVGPreview::setFileName(Glib::ustring &theFileName)
245     Glib::ustring fileName = theFileName;
247     fileName = Glib::filename_to_utf8(fileName);
249     SPDocument *doc = sp_document_new (fileName.c_str(), 0);
250     if (!doc) {
251         g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
252         return false;
253     }
255     setDocument(doc);
257     sp_document_unref(doc);
259     return true;
264 bool SVGPreview::setFromMem(char const *xmlBuffer)
266     if (!xmlBuffer)
267         return false;
269     gint len = (gint)strlen(xmlBuffer);
270     SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);
271     if (!doc) {
272         g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);
273         return false;
274     }
276     setDocument(doc);
278     sp_document_unref(doc);
280     Inkscape::GC::request_early_collection();
282     return true;
287 void SVGPreview::showImage(Glib::ustring &theFileName)
289     Glib::ustring fileName = theFileName;
292     /*#####################################
293     # LET'S HAVE SOME FUN WITH SVG!
294     # Instead of just loading an image, why
295     # don't we make a lovely little svg and
296     # display it nicely?
297     #####################################*/
299     //Arbitrary size of svg doc -- rather 'portrait' shaped
300     gint previewWidth  = 400;
301     gint previewHeight = 600;
303     //Get some image info. Smart pointer does not need to be deleted
304     Glib::RefPtr<Gdk::Pixbuf> img = Gdk::Pixbuf::create_from_file(fileName);
305     gint imgWidth  = img->get_width();
306     gint imgHeight = img->get_height();
308     //Find the minimum scale to fit the image inside the preview area
309     double scaleFactorX = (0.9 *(double)previewWidth)  / ((double)imgWidth);
310     double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);
311     double scaleFactor = scaleFactorX;
312     if (scaleFactorX > scaleFactorY)
313         scaleFactor = scaleFactorY;
315     //Now get the resized values
316     gint scaledImgWidth  = (int) (scaleFactor * (double)imgWidth);
317     gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);
319     //center the image on the area
320     gint imgX = (previewWidth  - scaledImgWidth)  / 2;
321     gint imgY = (previewHeight - scaledImgHeight) / 2;
323     //wrap a rectangle around the image
324     gint rectX      = imgX-1;
325     gint rectY      = imgY-1;
326     gint rectWidth  = scaledImgWidth +2;
327     gint rectHeight = scaledImgHeight+2;
329     //Our template.  Modify to taste
330     gchar const *xformat =
331           "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
332           "<svg\n"
333           "xmlns=\"http://www.w3.org/2000/svg\"\n"
334           "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
335           "width=\"%d\" height=\"%d\">\n"
336           "<rect\n"
337           "  style=\"fill:#eeeeee;stroke:none\"\n"
338           "  x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
339           "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
340           "xlink:href=\"%s\"/>\n"
341           "<rect\n"
342           "  style=\"fill:none;"
343           "    stroke:#000000;stroke-width:1.0;"
344           "    stroke-linejoin:miter;stroke-opacity:1.0000000;"
345           "    stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
346           "  x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
347           "<text\n"
348           "  style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
349           "    fill:#000000;fill-opacity:1.0000000;stroke:none;"
350           "    font-family:Bitstream Vera Sans\"\n"
351           "  x=\"10\" y=\"26\">%d x %d</text>\n"
352           "</svg>\n\n";
354     //if (!Glib::get_charset()) //If we are not utf8
355     fileName = Glib::filename_to_utf8(fileName);
357     //Fill in the template
358     /* FIXME: Do proper XML quoting for fileName. */
359     gchar *xmlBuffer = g_strdup_printf(xformat,
360            previewWidth, previewHeight,
361            imgX, imgY, scaledImgWidth, scaledImgHeight,
362            fileName.c_str(),
363            rectX, rectY, rectWidth, rectHeight,
364            imgWidth, imgHeight);
366     //g_message("%s\n", xmlBuffer);
368     //now show it!
369     setFromMem(xmlBuffer);
370     g_free(xmlBuffer);
375 void SVGPreview::showNoPreview()
377     //Are we already showing it?
378     if (showingNoPreview)
379         return;
381     //Arbitrary size of svg doc -- rather 'portrait' shaped
382     gint previewWidth  = 300;
383     gint previewHeight = 600;
385     //Our template.  Modify to taste
386     gchar const *xformat =
387           "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
388           "<svg\n"
389           "xmlns=\"http://www.w3.org/2000/svg\"\n"
390           "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
391           "width=\"%d\" height=\"%d\">\n"
392           "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
393           "<path\n"
394           "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
395           "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
396           "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
397           "id=\"whiteSpace\" />\n"
398           "<path\n"
399           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
400           "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
401           "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
402           "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
403           "id=\"droplet01\" />\n"
404           "<path\n"
405           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
406           "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
407           "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
408           "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
409           "287.18046 343.1206 286.46194 340.42914 z \"\n"
410           "id=\"droplet02\" />\n"
411           "<path\n"
412           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
413           "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
414           "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
415           "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
416           "id=\"droplet03\" />\n"
417           "<path\n"
418           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
419           "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
420           "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
421           "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
422           "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
423           "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
424           "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
425           "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
426           "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
427           "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
428           "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
429           "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
430           "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
431           "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
432           "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
433           "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
434           "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
435           "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
436           "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
437           "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
438           "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
439           "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
440           "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
441           "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
442           "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
443           "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
444           "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
445           "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
446           "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
447           "id=\"mountainDroplet\" />\n"
448           "</g> <g transform=\"translate(-20,0)\">\n"
449           "<text xml:space=\"preserve\"\n"
450           "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
451           "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
452           "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
453           "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
454           "x=\"190\" y=\"240\">%s</text></g>\n"
455           "</svg>\n\n";
457     //Fill in the template
458     gchar *xmlBuffer = g_strdup_printf(xformat,
459            previewWidth, previewHeight, _("No preview"));
461     //g_message("%s\n", xmlBuffer);
463     //now show it!
464     setFromMem(xmlBuffer);
465     g_free(xmlBuffer);
466     showingNoPreview = true;
470 void SVGPreview::showTooLarge(long fileLength)
473     //Arbitrary size of svg doc -- rather 'portrait' shaped
474     gint previewWidth  = 300;
475     gint previewHeight = 600;
477     //Our template.  Modify to taste
478     gchar const *xformat =
479           "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
480           "<svg\n"
481           "xmlns=\"http://www.w3.org/2000/svg\"\n"
482           "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
483           "width=\"%d\" height=\"%d\">\n"
484           "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
485           "<path\n"
486           "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
487           "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
488           "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
489           "id=\"whiteSpace\" />\n"
490           "<path\n"
491           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
492           "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
493           "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
494           "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
495           "id=\"droplet01\" />\n"
496           "<path\n"
497           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
498           "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
499           "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
500           "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
501           "287.18046 343.1206 286.46194 340.42914 z \"\n"
502           "id=\"droplet02\" />\n"
503           "<path\n"
504           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
505           "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
506           "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
507           "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
508           "id=\"droplet03\" />\n"
509           "<path\n"
510           "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
511           "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
512           "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
513           "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
514           "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
515           "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
516           "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
517           "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
518           "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
519           "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
520           "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
521           "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
522           "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
523           "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
524           "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
525           "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
526           "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
527           "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
528           "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
529           "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
530           "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
531           "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
532           "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
533           "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
534           "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
535           "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
536           "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
537           "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
538           "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
539           "id=\"mountainDroplet\" />\n"
540           "</g>\n"
541           "<text xml:space=\"preserve\"\n"
542           "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
543           "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
544           "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
545           "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
546           "x=\"170\" y=\"215\">%5.1f MB</text>\n"
547           "<text xml:space=\"preserve\"\n"
548           "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
549           "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
550           "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
551           "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
552           "x=\"180\" y=\"245\">%s</text>\n"
553           "</svg>\n\n";
555     //Fill in the template
556     double floatFileLength = ((double)fileLength) / 1048576.0;
557     //printf("%ld %f\n", fileLength, floatFileLength);
558     gchar *xmlBuffer = g_strdup_printf(xformat,
559            previewWidth, previewHeight, floatFileLength,
560            _("too large for preview"));
562     //g_message("%s\n", xmlBuffer);
564     //now show it!
565     setFromMem(xmlBuffer);
566     g_free(xmlBuffer);
571 /**
572  * Return true if the string ends with the given suffix
573  */ 
574 static bool
575 hasSuffix(Glib::ustring &str, Glib::ustring &ext)
577     int strLen = str.length();
578     int extLen = ext.length();
579     if (extLen > strLen)
580         return false;
581     int strpos = strLen-1;
582     for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)
583         {
584         Glib::ustring::value_type ch = str[strpos];
585         if (ch != ext[extpos])
586             {
587             if ( ((ch & 0xff80) != 0) ||
588                  static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )
589                 {
590                 return false;
591                 }
592             }
593         }
594     return true;
598 /**
599  * Return true if the image is loadable by Gdk, else false
600  */
601 static bool
602 isValidImageFile(Glib::ustring &fileName)
604     std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();
605     for (unsigned int i=0; i<formats.size(); i++)
606         {
607         Gdk::PixbufFormat format = formats[i];
608         std::vector<Glib::ustring>extensions = format.get_extensions();
609         for (unsigned int j=0; j<extensions.size(); j++)
610             {
611             Glib::ustring ext = extensions[j];
612             if (hasSuffix(fileName, ext))
613                 return true;
614             }
615         }
616     return false;
619 bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
622     if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
623         return false;
625     gchar *fName = (gchar *)fileName.c_str();
626     //g_message("fname:%s\n", fName);
628     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
629         showNoPreview();
630         return false;
631     }
633     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
634         {
635         struct stat info;
636         if (stat(fName, &info))
637             {
638             return FALSE;
639             }
640         long fileLen = info.st_size;
641         if (fileLen > 0x150000L)
642             {
643             showingNoPreview = false;
644             showTooLarge(fileLen);
645             return FALSE;
646             }
647         }
649     Glib::ustring svg = ".svg";
650     Glib::ustring svgz = ".svgz";
652     if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
653            (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz)   )
654         ) {
655         bool retval = setFileName(fileName);
656         showingNoPreview = false;
657         return retval;
658     } else if (isValidImageFile(fileName)) {
659         showImage(fileName);
660         showingNoPreview = false;
661         return true;
662     } else {
663         showNoPreview();
664         return false;
665     }
669 SVGPreview::SVGPreview()
671     if (!INKSCAPE)
672         inkscape_application_init("",false);
673     document = NULL;
674     viewerGtk = NULL;
675     set_size_request(150,150);
676     showingNoPreview = false;
679 SVGPreview::~SVGPreview()
688 /*#########################################################################
689 ### F I L E     D I A L O G    B A S E    C L A S S
690 #########################################################################*/
692 /**
693  * This class is the base implementation for the others.  This
694  * reduces redundancies and bugs.
695  */
696 class FileDialogBase : public Gtk::FileChooserDialog
698 public:
700     /**
701      *
702      */
703     FileDialogBase(const Glib::ustring &title) :
704                         Gtk::FileChooserDialog(title)
705         {
706         }
708     /**
709      *
710      */
711     FileDialogBase(const Glib::ustring &title,
712                    Gtk::FileChooserAction dialogType) :
713                    Gtk::FileChooserDialog(title, dialogType)
714         {
715         }
717     /**
718      *
719      */
720     virtual ~FileDialogBase()
721         {}
723 };
727 /*#########################################################################
728 ### F I L E    O P E N
729 #########################################################################*/
731 /**
732  * Our implementation class for the FileOpenDialog interface..
733  */
734 class FileOpenDialogImpl : public FileOpenDialog, public FileDialogBase
736 public:
738     FileOpenDialogImpl(const Glib::ustring &dir,
739                        FileDialogType fileTypes,
740                        const Glib::ustring &title);
742     virtual ~FileOpenDialogImpl();
744     bool show();
746     Inkscape::Extension::Extension *getSelectionType();
748     Glib::ustring getFilename();
750     std::vector<Glib::ustring> getFilenames ();
752 protected:
756 private:
759     /**
760      * What type of 'open' are we? (open, import, place, etc)
761      */
762     FileDialogType dialogType;
764     /**
765      * Our svg preview widget
766      */
767     SVGPreview svgPreview;
769     /**
770      * Callback for seeing if the preview needs to be drawn
771      */
772     void updatePreviewCallback();
774     /**
775      *  Create a filter menu for this type of dialog
776      */
777     void createFilterMenu();
779     /**
780      * Filter name->extension lookup
781      */
782     std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;
784     /**
785      * The extension to use to write this file
786      */
787     Inkscape::Extension::Extension *extension;
789     /**
790      * Filename that was given
791      */
792     Glib::ustring myFilename;
794 };
800 /**
801  * Callback for checking if the preview needs to be redrawn
802  */
803 void FileOpenDialogImpl::updatePreviewCallback()
805     Glib::ustring fileName = get_preview_filename();
806 #ifdef WITH_GNOME_VFS
807     if (fileName.length() < 1)
808         fileName = get_preview_uri();
809 #endif
810     if (fileName.length() < 1)
811         return;
812     svgPreview.set(fileName, dialogType);
821 void FileOpenDialogImpl::createFilterMenu()
823     //patterns added dynamically below
824     Gtk::FileFilter allImageFilter;
825     allImageFilter.set_name(_("All Images"));
826     extensionMap[Glib::ustring(_("All Images"))]=NULL;
827     add_filter(allImageFilter);
829     Gtk::FileFilter allFilter;
830     allFilter.set_name(_("All Files"));
831     extensionMap[Glib::ustring(_("All Files"))]=NULL;
832     allFilter.add_pattern("*");
833     add_filter(allFilter);
835     //patterns added dynamically below
836     Gtk::FileFilter allInkscapeFilter;
837     allInkscapeFilter.set_name(_("All Inkscape Files"));
838     extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
839     add_filter(allInkscapeFilter);
841     Inkscape::Extension::DB::InputList extension_list;
842     Inkscape::Extension::db.get_input_list(extension_list);
844     for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
845          current_item != extension_list.end(); current_item++)
846     {
847         Inkscape::Extension::Input * imod = *current_item;
849         // FIXME: would be nice to grey them out instead of not listing them
850         if (imod->deactivated()) continue;
852         Glib::ustring upattern("*");
853         Glib::ustring extension = imod->get_extension();
854         fileDialogExtensionToPattern(upattern, extension);
856         Gtk::FileFilter filter;
857         Glib::ustring uname(_(imod->get_filetypename()));
858         filter.set_name(uname);
859         filter.add_pattern(upattern);
860         add_filter(filter);
861         extensionMap[uname] = imod;
863         //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
864         allInkscapeFilter.add_pattern(upattern);
865         if ( strncmp("image", imod->get_mimetype(), 5)==0 )
866             allImageFilter.add_pattern(upattern);
867     }
869     return;
874 /**
875  * Constructor.  Not called directly.  Use the factory.
876  */
877 FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
878                                        FileDialogType fileTypes,
879                                        const Glib::ustring &title) :
880                                        FileDialogBase(title)
884     /* One file at a time */
885     /* And also Multiple Files */
886     set_select_multiple(true);
888 #ifdef WITH_GNOME_VFS
889     set_local_only(false);
890 #endif
892     /* Initalize to Autodetect */
893     extension = NULL;
894     /* No filename to start out with */
895     myFilename = "";
897     /* Set our dialog type (open, import, etc...)*/
898     dialogType = fileTypes;
901     /* Set the pwd and/or the filename */
902     if (dir.size() > 0)
903         {
904         Glib::ustring udir(dir);
905         Glib::ustring::size_type len = udir.length();
906         // leaving a trailing backslash on the directory name leads to the infamous
907         // double-directory bug on win32
908         if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
909         set_current_folder(udir.c_str());
910         }
912     //###### Add the file types menu
913     createFilterMenu();
915     //###### Add a preview widget
916     set_preview_widget(svgPreview);
917     set_preview_widget_active(true);
918     set_use_preview_label (false);
920     //Catch selection-changed events, so we can adjust the text widget
921     signal_update_preview().connect(
922          sigc::mem_fun(*this, &FileOpenDialogImpl::updatePreviewCallback) );
924     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
925     set_default(*add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK));
933 /**
934  * Public factory.  Called by file.cpp, among others.
935  */
936 FileOpenDialog *FileOpenDialog::create(const Glib::ustring &path,
937                                        FileDialogType fileTypes,
938                                        const Glib::ustring &title)
940     FileOpenDialog *dialog = new FileOpenDialogImpl(path, fileTypes, title);
941     return dialog;
947 /**
948  * Destructor
949  */
950 FileOpenDialogImpl::~FileOpenDialogImpl()
956 /**
957  * Show this dialog modally.  Return true if user hits [OK]
958  */
959 bool
960 FileOpenDialogImpl::show()
962     Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
963     if (s.length() == 0) 
964         s = getcwd (NULL, 0);
965     set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
966     set_modal (TRUE);                      //Window
967     sp_transientize((GtkWidget *)gobj());  //Make transient
968     gint b = run();                        //Dialog
969     svgPreview.showNoPreview();
970     hide();
972     if (b == Gtk::RESPONSE_OK)
973         {
974         //This is a hack, to avoid the warning messages that
975         //Gtk::FileChooser::get_filter() returns
976         //should be:  Gtk::FileFilter *filter = get_filter();
977         GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
978         GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
979         if (filter)
980             {
981             //Get which extension was chosen, if any
982             extension = extensionMap[gtk_file_filter_get_name(filter)];
983             }
984         myFilename = get_filename();
985 #ifdef WITH_GNOME_VFS
986         if (myFilename.length() < 1)
987             myFilename = get_uri();
988 #endif
989         return TRUE;
990         }
991     else
992        {
993        return FALSE;
994        }
1000 /**
1001  * Get the file extension type that was selected by the user. Valid after an [OK]
1002  */
1003 Inkscape::Extension::Extension *
1004 FileOpenDialogImpl::getSelectionType()
1006     return extension;
1010 /**
1011  * Get the file name chosen by the user.   Valid after an [OK]
1012  */
1013 Glib::ustring
1014 FileOpenDialogImpl::getFilename (void)
1016     return g_strdup(myFilename.c_str());
1020 /**
1021  * To Get Multiple filenames selected at-once.
1022  */
1023 std::vector<Glib::ustring>FileOpenDialogImpl::getFilenames()
1024 {    
1025     std::vector<Glib::ustring> result = get_filenames();
1026 #ifdef WITH_GNOME_VFS
1027     if (result.empty())
1028         result = get_uris();
1029 #endif
1030     return result;
1038 //########################################################################
1039 //# F I L E    S A V E
1040 //########################################################################
1042 class FileType
1044     public:
1045     FileType() {}
1046     ~FileType() {}
1047     Glib::ustring name;
1048     Glib::ustring pattern;
1049     Inkscape::Extension::Extension *extension;
1050 };
1052 /**
1053  * Our implementation of the FileSaveDialog interface.
1054  */
1055 class FileSaveDialogImpl : public FileSaveDialog, public FileDialogBase
1058 public:
1059     FileSaveDialogImpl(const Glib::ustring &dir,
1060                        FileDialogType fileTypes,
1061                        const Glib::ustring &title,
1062                        const Glib::ustring &default_key);
1064     virtual ~FileSaveDialogImpl();
1066     bool show();
1068     Inkscape::Extension::Extension *getSelectionType();
1069     virtual void setSelectionType( Inkscape::Extension::Extension * key );
1071     Glib::ustring getFilename();
1073     void change_title(const Glib::ustring& title);
1074     void change_path(const Glib::ustring& dir);
1077 private:
1079     /**
1080      * What type of 'open' are we? (save, export, etc)
1081      */
1082     FileDialogType dialogType;
1084     /**
1085      * Our svg preview widget
1086      */
1087     SVGPreview svgPreview;
1089     /**
1090      * Fix to allow the user to type the file name
1091      */
1092     Gtk::Entry *fileNameEntry;
1094     /**
1095      * Callback for seeing if the preview needs to be drawn
1096      */
1097     void updatePreviewCallback();
1101     /**
1102      * Allow the specification of the output file type
1103      */
1104     Gtk::HBox fileTypeBox;
1106     /**
1107      * Allow the specification of the output file type
1108      */
1109     Gtk::ComboBoxText fileTypeComboBox;
1112     /**
1113      *  Data mirror of the combo box
1114      */
1115     std::vector<FileType> fileTypes;
1117     //# Child widgets
1119     /**
1120      * Callback for user input into fileNameEntry
1121      */
1122     void fileTypeChangedCallback();
1124     /**
1125      *  Create a filter menu for this type of dialog
1126      */
1127     void createFileTypeMenu();
1130     /**
1131      * The extension to use to write this file
1132      */
1133     Inkscape::Extension::Extension *extension;
1135     /**
1136      * Callback for user input into fileNameEntry
1137      */
1138     void fileNameEntryChangedCallback();
1140     /**
1141      * Filename that was given
1142      */
1143     Glib::ustring myFilename;
1145     /**
1146      * List of known file extensions.
1147      */
1148     std::set<Glib::ustring> knownExtensions;
1149 };
1156 /**
1157  * Callback for checking if the preview needs to be redrawn
1158  */
1159 void FileSaveDialogImpl::updatePreviewCallback()
1161     Glib::ustring fileName = get_preview_filename();
1162 #ifdef WITH_GNOME_VFS
1163     if (fileName.length() < 1)
1164         fileName = get_preview_uri();
1165 #endif
1166     if (!fileName.c_str())
1167         return;
1168     bool retval = svgPreview.set(fileName, dialogType);
1169     set_preview_widget_active(retval);
1174 /**
1175  * Callback for fileNameEntry widget
1176  */
1177 void FileSaveDialogImpl::fileNameEntryChangedCallback()
1179     if (!fileNameEntry)
1180         return;
1182     Glib::ustring fileName = fileNameEntry->get_text();
1183     if (!Glib::get_charset()) //If we are not utf8
1184         fileName = Glib::filename_to_utf8(fileName);
1186     //g_message("User hit return.  Text is '%s'\n", fileName.c_str());
1188     if (!Glib::path_is_absolute(fileName)) {
1189         //try appending to the current path
1190         // not this way: fileName = get_current_folder() + "/" + fileName;
1191         std::vector<Glib::ustring> pathSegments;
1192         pathSegments.push_back( get_current_folder() );
1193         pathSegments.push_back( fileName );
1194         fileName = Glib::build_filename(pathSegments);
1195     }
1197     //g_message("path:'%s'\n", fileName.c_str());
1199     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1200         set_current_folder(fileName);
1201     } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1202         //dialog with either (1) select a regular file or (2) cd to dir
1203         //simulate an 'OK'
1204         set_filename(fileName);
1205         response(Gtk::RESPONSE_OK);
1206     }
1211 /**
1212  * Callback for fileNameEntry widget
1213  */
1214 void FileSaveDialogImpl::fileTypeChangedCallback()
1216     int sel = fileTypeComboBox.get_active_row_number();
1217     if (sel<0 || sel >= (int)fileTypes.size())
1218         return;
1219     FileType type = fileTypes[sel];
1220     //g_message("selected: %s\n", type.name.c_str());
1222     extension = type.extension;
1223     Gtk::FileFilter filter;
1224     filter.add_pattern(type.pattern);
1225     set_filter(filter);
1227     // Pick up any changes the user has typed in.
1228     Glib::ustring tmp = get_filename();
1229 #ifdef WITH_GNOME_VFS
1230     if ( tmp.empty() ) {
1231         tmp = get_uri();
1232     }
1233 #endif
1234     if ( !tmp.empty() ) {
1235         myFilename = tmp;
1236     }
1238     Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
1239     bool appendExtension = true;
1240     if ( newOut ) {
1241         try {
1242             Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
1243             size_t pos = utf8Name.rfind('.');
1244             if ( pos != Glib::ustring::npos ) {
1245                 Glib::ustring trail = utf8Name.substr( pos );
1246                 Glib::ustring foldedTrail = trail.casefold();
1247                 if ( (trail == ".") 
1248                     | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()
1249                      && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {
1250                     utf8Name = utf8Name.erase( pos );
1251                 } else {
1252                     appendExtension = false;
1253                 }
1254             }
1256             if (appendExtension) {
1257                 utf8Name = utf8Name + newOut->get_extension();
1258                 myFilename = Glib::filename_from_utf8( utf8Name );
1259                 change_path(myFilename);
1260             }
1261         } catch ( Glib::ConvertError& e ) {
1262             // ignore
1263         }
1264     }
1269 void FileSaveDialogImpl::createFileTypeMenu()
1271     Inkscape::Extension::DB::OutputList extension_list;
1272     Inkscape::Extension::db.get_output_list(extension_list);
1273     knownExtensions.clear();
1275     for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1276          current_item != extension_list.end(); current_item++)
1277     {
1278         Inkscape::Extension::Output * omod = *current_item;
1280         // FIXME: would be nice to grey them out instead of not listing them
1281         if (omod->deactivated()) continue;
1283         FileType type;
1284         type.name     = (_(omod->get_filetypename()));
1285         type.pattern  = "*";
1286         Glib::ustring extension = omod->get_extension();
1287         knownExtensions.insert( extension.casefold() );
1288         fileDialogExtensionToPattern (type.pattern, extension);
1289         type.extension= omod;
1290         fileTypeComboBox.append_text(type.name);
1291         fileTypes.push_back(type);
1292     }
1294     //#Let user choose
1295     FileType guessType;
1296     guessType.name = _("Guess from extension");
1297     guessType.pattern = "*";
1298     guessType.extension = NULL;
1299     fileTypeComboBox.append_text(guessType.name);
1300     fileTypes.push_back(guessType);
1303     fileTypeComboBox.set_active(0);
1304     fileTypeChangedCallback(); //call at least once to set the filter
1309 /**
1310  * Constructor
1311  */
1312 FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir,
1313             FileDialogType fileTypes,
1314             const Glib::ustring &title,
1315             const Glib::ustring &default_key) :
1316             FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE)
1318     /* One file at a time */
1319     set_select_multiple(false);
1321 #ifdef WITH_GNOME_VFS
1322     set_local_only(false);
1323 #endif
1325     /* Initalize to Autodetect */
1326     extension = NULL;
1327     /* No filename to start out with */
1328     myFilename = "";
1330     /* Set our dialog type (save, export, etc...)*/
1331     dialogType = fileTypes;
1333     /* Set the pwd and/or the filename */
1334     if (dir.size() > 0)
1335         {
1336         Glib::ustring udir(dir);
1337         Glib::ustring::size_type len = udir.length();
1338         // leaving a trailing backslash on the directory name leads to the infamous
1339         // double-directory bug on win32
1340         if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1341         myFilename = udir;
1342         }
1344     //###### Add the file types menu
1345     //createFilterMenu();
1347     createFileTypeMenu();
1348     fileTypeComboBox.set_size_request(200,40);
1349     fileTypeComboBox.signal_changed().connect(
1350          sigc::mem_fun(*this, &FileSaveDialogImpl::fileTypeChangedCallback) );
1352     fileTypeBox.pack_start(fileTypeComboBox);
1354     set_extra_widget(fileTypeBox);
1355     //get_vbox()->pack_start(fileTypeBox, false, false, 0);
1356     //get_vbox()->reorder_child(fileTypeBox, 2);
1358     //###### Add a preview widget
1359     set_preview_widget(svgPreview);
1360     set_preview_widget_active(true);
1361     set_use_preview_label (false);
1363     //Catch selection-changed events, so we can adjust the text widget
1364     signal_update_preview().connect(
1365          sigc::mem_fun(*this, &FileSaveDialogImpl::updatePreviewCallback) );
1368     //Let's do some customization
1369     fileNameEntry = NULL;
1370     Gtk::Container *cont = get_toplevel();
1371     std::vector<Gtk::Entry *> entries;
1372     findEntryWidgets(cont, entries);
1373     //g_message("Found %d entry widgets\n", entries.size());
1374     if (entries.size() >=1 )
1375         {
1376         //Catch when user hits [return] on the text field
1377         fileNameEntry = entries[0];
1378         fileNameEntry->signal_activate().connect(
1379              sigc::mem_fun(*this, &FileSaveDialogImpl::fileNameEntryChangedCallback) );
1380         }
1382     //Let's do more customization
1383     std::vector<Gtk::Expander *> expanders;
1384     findExpanderWidgets(cont, expanders);
1385     //g_message("Found %d expander widgets\n", expanders.size());
1386     if (expanders.size() >=1 )
1387         {
1388         //Always show the file list
1389         Gtk::Expander *expander = expanders[0];
1390         expander->set_expanded(true);
1391         }
1394     //if (extension == NULL)
1395     //    checkbox.set_sensitive(FALSE);
1397     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1398     set_default(*add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK));
1400     show_all_children();
1405 /**
1406  * Public factory method.  Used in file.cpp
1407  */
1408 FileSaveDialog *FileSaveDialog::create(const Glib::ustring &path,
1409                                        FileDialogType fileTypes,
1410                                        const Glib::ustring &title,
1411                                        const Glib::ustring &default_key)
1413     FileSaveDialog *dialog = new FileSaveDialogImpl(path, fileTypes, title, default_key);
1414     return dialog;
1421 /**
1422  * Destructor
1423  */
1424 FileSaveDialogImpl::~FileSaveDialogImpl()
1430 /**
1431  * Show this dialog modally.  Return true if user hits [OK]
1432  */
1433 bool
1434 FileSaveDialogImpl::show()
1436     change_path(myFilename);
1437     set_modal (TRUE);                      //Window
1438     sp_transientize((GtkWidget *)gobj());  //Make transient
1439     gint b = run();                        //Dialog
1440     svgPreview.showNoPreview();
1441     hide();
1443     if (b == Gtk::RESPONSE_OK)
1444         {
1445         myFilename = get_filename();
1446 #ifdef WITH_GNOME_VFS
1447         if (myFilename.length() < 1)
1448             myFilename = get_uri();
1449 #endif
1451         return TRUE;
1452         }
1453     else
1454         {
1455         return FALSE;
1456         }
1460 /**
1461  * Get the file extension type that was selected by the user. Valid after an [OK]
1462  */
1463 Inkscape::Extension::Extension *
1464 FileSaveDialogImpl::getSelectionType()
1466     return extension;
1469 void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
1471     extension = key;
1473     // If no pointer to extension is passed in, look up based on filename extension.
1474     if ( !extension ) {
1475         // Not quite UTF-8 here.
1476         gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
1477         for ( int i = 0; !extension && (i < (int)fileTypes.size()); i++ ) {
1478             Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
1479             if ( ext && ext->get_extension() ) {
1480                 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
1481                 if ( g_str_has_suffix(filenameLower, extensionLower) ) {
1482                     extension = fileTypes[i].extension;
1483                 }
1484                 g_free(extensionLower);
1485             }
1486         }
1487         g_free(filenameLower);
1488     }
1490     // Ensure the proper entry in the combo box is selected.
1491     if ( extension ) {
1492         gchar const * extensionID = extension->get_id();
1493         if ( extensionID ) {
1494             for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
1495                 Inkscape::Extension::Extension *ext = fileTypes[i].extension;
1496                 if ( ext ) {
1497                     gchar const * id = ext->get_id();
1498                     if ( id && ( strcmp(extensionID, id) == 0) ) {
1499                         int oldSel = fileTypeComboBox.get_active_row_number();
1500                         if ( i != oldSel ) {
1501                             fileTypeComboBox.set_active(i);
1502                         }
1503                         break;
1504                     }
1505                 }
1506             }
1507         }
1508     }
1512 /**
1513  * Get the file name chosen by the user.   Valid after an [OK]
1514  */
1515 Glib::ustring
1516 FileSaveDialogImpl::getFilename()
1518     return myFilename;
1522 void 
1523 FileSaveDialogImpl::change_title(const Glib::ustring& title)
1525     this->set_title(title);
1528 /**
1529   * Change the default save path location.
1530   */
1531 void 
1532 FileSaveDialogImpl::change_path(const Glib::ustring& path)
1534     myFilename = path;
1535     if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
1536         //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
1537         set_current_folder(myFilename);
1538     } else {
1539         //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
1540         if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
1541             set_filename(myFilename);
1542         } else {
1543             std::string dirName = Glib::path_get_dirname( myFilename  );
1544             if ( dirName != get_current_folder() ) {
1545                 set_current_folder(dirName);
1546             }
1547         }
1548         Glib::ustring basename = Glib::path_get_basename(myFilename);
1549         //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
1550         try {
1551             set_current_name( Glib::filename_to_utf8(basename) );
1552         } catch ( Glib::ConvertError& e ) {
1553             g_warning( "Error converting save filename to UTF-8." );
1554             // try a fallback.
1555             set_current_name( basename );
1556         }
1557     }
1565 //########################################################################
1566 //# F I L E     E X P O R T
1567 //########################################################################
1570 /**
1571  * Our implementation of the FileExportDialog interface.
1572  */
1573 class FileExportDialogImpl : public FileExportDialog, public FileDialogBase
1576 public:
1577     FileExportDialogImpl(const Glib::ustring &dir,
1578                        FileDialogType fileTypes,
1579                        const Glib::ustring &title,
1580                        const Glib::ustring &default_key);
1582     virtual ~FileExportDialogImpl();
1584     bool show();
1586     Inkscape::Extension::Extension *getSelectionType();
1588     Glib::ustring getFilename();
1591     /**
1592      * Return the scope of the export.  One of the enumerated types
1593      * in ScopeType     
1594      */
1595     ScopeType getScope()
1596         { 
1597         if (pageButton.get_active())
1598             return SCOPE_PAGE;
1599         else if (selectionButton.get_active())
1600             return SCOPE_SELECTION;
1601         else if (customButton.get_active())
1602             return SCOPE_CUSTOM;
1603         else
1604             return SCOPE_DOCUMENT;
1606         }
1607     
1608     /**
1609      * Return left side of the exported region
1610      */
1611     double getSourceX()
1612         { return sourceX0Spinner.getValue(); }
1613     
1614     /**
1615      * Return the top of the exported region
1616      */
1617     double getSourceY()
1618         { return sourceY1Spinner.getValue(); }
1619     
1620     /**
1621      * Return the width of the exported region
1622      */
1623     double getSourceWidth()
1624         { return sourceWidthSpinner.getValue(); }
1625     
1626     /**
1627      * Return the height of the exported region
1628      */
1629     double getSourceHeight()
1630         { return sourceHeightSpinner.getValue(); }
1632     /**
1633      * Return the units of the coordinates of exported region
1634      */
1635     Glib::ustring getSourceUnits()
1636         { return sourceUnitsSpinner.getUnitAbbr(); }
1638     /**
1639      * Return the width of the destination document
1640      */
1641     double getDestinationWidth()
1642         { return destWidthSpinner.getValue(); }
1644     /**
1645      * Return the height of the destination document
1646      */
1647     double getDestinationHeight()
1648         { return destHeightSpinner.getValue(); }
1650     /**
1651      * Return the height of the exported region
1652      */
1653     Glib::ustring getDestinationUnits()
1654         { return destUnitsSpinner.getUnitAbbr(); }
1656     /**
1657      * Return the destination DPI image resulution, if bitmap
1658      */
1659     double getDestinationDPI()
1660         { return destDPISpinner.getValue(); }
1662     /**
1663      * Return whether we should use Cairo for rendering
1664      */
1665     bool getUseCairo()
1666         { return cairoButton.get_active(); }
1668     /**
1669      * Return whether we should use antialiasing
1670      */
1671     bool getUseAntialias()
1672         { return antiAliasButton.get_active(); }
1674     /**
1675      * Return the background color for exporting
1676      */
1677     unsigned long getBackground()
1678         { return backgroundButton.get_color().get_pixel(); }
1680 private:
1682     /**
1683      * What type of 'open' are we? (save, export, etc)
1684      */
1685     FileDialogType dialogType;
1687     /**
1688      * Our svg preview widget
1689      */
1690     SVGPreview svgPreview;
1692     /**
1693      * Fix to allow the user to type the file name
1694      */
1695     Gtk::Entry *fileNameEntry;
1697     /**
1698      * Callback for seeing if the preview needs to be drawn
1699      */
1700     void updatePreviewCallback();
1702     //##########################################
1703     //# EXTRA WIDGET -- SOURCE SIDE
1704     //##########################################
1706     Gtk::Frame            sourceFrame;
1707     Gtk::VBox             sourceBox;
1709     Gtk::HBox             scopeBox;
1710     Gtk::RadioButtonGroup scopeGroup;
1711     Gtk::RadioButton      documentButton;
1712     Gtk::RadioButton      pageButton;
1713     Gtk::RadioButton      selectionButton;
1714     Gtk::RadioButton      customButton;
1716     Gtk::Table                      sourceTable;
1717     Inkscape::UI::Widget::Scalar    sourceX0Spinner;
1718     Inkscape::UI::Widget::Scalar    sourceY0Spinner;
1719     Inkscape::UI::Widget::Scalar    sourceX1Spinner;
1720     Inkscape::UI::Widget::Scalar    sourceY1Spinner;
1721     Inkscape::UI::Widget::Scalar    sourceWidthSpinner;
1722     Inkscape::UI::Widget::Scalar    sourceHeightSpinner;
1723     Inkscape::UI::Widget::UnitMenu  sourceUnitsSpinner;
1726     //##########################################
1727     //# EXTRA WIDGET -- DESTINATION SIDE
1728     //##########################################
1730     Gtk::Frame       destFrame;
1731     Gtk::VBox        destBox;
1733     Gtk::Table                      destTable;
1734     Inkscape::UI::Widget::Scalar    destWidthSpinner;
1735     Inkscape::UI::Widget::Scalar    destHeightSpinner;
1736     Inkscape::UI::Widget::Scalar    destDPISpinner;
1737     Inkscape::UI::Widget::UnitMenu  destUnitsSpinner;
1739     Gtk::HBox        otherOptionBox;
1740     Gtk::CheckButton cairoButton;
1741     Gtk::CheckButton antiAliasButton;
1742     Gtk::ColorButton backgroundButton;
1745     /**
1746      * 'Extra' widget that holds two boxes above
1747      */
1748     Gtk::HBox exportOptionsBox;
1751     //# Child widgets
1752     Gtk::CheckButton fileTypeCheckbox;
1754     /**
1755      * Allow the specification of the output file type
1756      */
1757     Gtk::ComboBoxText fileTypeComboBox;
1760     /**
1761      *  Data mirror of the combo box
1762      */
1763     std::vector<FileType> fileTypes;
1767     /**
1768      * Callback for user input into fileNameEntry
1769      */
1770     void fileTypeChangedCallback();
1772     /**
1773      *  Create a filter menu for this type of dialog
1774      */
1775     void createFileTypeMenu();
1778     bool append_extension;
1780     /**
1781      * The extension to use to write this file
1782      */
1783     Inkscape::Extension::Extension *extension;
1785     /**
1786      * Callback for user input into fileNameEntry
1787      */
1788     void fileNameEntryChangedCallback();
1790     /**
1791      * Filename that was given
1792      */
1793     Glib::ustring myFilename;
1794 };
1801 /**
1802  * Callback for checking if the preview needs to be redrawn
1803  */
1804 void FileExportDialogImpl::updatePreviewCallback()
1806     Glib::ustring fileName = get_preview_filename();
1807 #ifdef WITH_GNOME_VFS
1808     if (fileName.length() < 1)
1809         fileName = get_preview_uri();
1810 #endif
1811     if (!fileName.c_str())
1812         return;
1813     bool retval = svgPreview.set(fileName, dialogType);
1814     set_preview_widget_active(retval);
1819 /**
1820  * Callback for fileNameEntry widget
1821  */
1822 void FileExportDialogImpl::fileNameEntryChangedCallback()
1824     if (!fileNameEntry)
1825         return;
1827     Glib::ustring fileName = fileNameEntry->get_text();
1828     if (!Glib::get_charset()) //If we are not utf8
1829         fileName = Glib::filename_to_utf8(fileName);
1831     //g_message("User hit return.  Text is '%s'\n", fileName.c_str());
1833     if (!Glib::path_is_absolute(fileName)) {
1834         //try appending to the current path
1835         // not this way: fileName = get_current_folder() + "/" + fileName;
1836         std::vector<Glib::ustring> pathSegments;
1837         pathSegments.push_back( get_current_folder() );
1838         pathSegments.push_back( fileName );
1839         fileName = Glib::build_filename(pathSegments);
1840     }
1842     //g_message("path:'%s'\n", fileName.c_str());
1844     if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1845         set_current_folder(fileName);
1846     } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1847         //dialog with either (1) select a regular file or (2) cd to dir
1848         //simulate an 'OK'
1849         set_filename(fileName);
1850         response(Gtk::RESPONSE_OK);
1851     }
1856 /**
1857  * Callback for fileNameEntry widget
1858  */
1859 void FileExportDialogImpl::fileTypeChangedCallback()
1861     int sel = fileTypeComboBox.get_active_row_number();
1862     if (sel<0 || sel >= (int)fileTypes.size())
1863         return;
1864     FileType type = fileTypes[sel];
1865     //g_message("selected: %s\n", type.name.c_str());
1866     Gtk::FileFilter filter;
1867     filter.add_pattern(type.pattern);
1868     set_filter(filter);
1873 void FileExportDialogImpl::createFileTypeMenu()
1875     Inkscape::Extension::DB::OutputList extension_list;
1876     Inkscape::Extension::db.get_output_list(extension_list);
1878     for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1879          current_item != extension_list.end(); current_item++)
1880     {
1881         Inkscape::Extension::Output * omod = *current_item;
1883         // FIXME: would be nice to grey them out instead of not listing them
1884         if (omod->deactivated()) continue;
1886         FileType type;
1887         type.name     = (_(omod->get_filetypename()));
1888         type.pattern  = "*";
1889         Glib::ustring extension = omod->get_extension();
1890         fileDialogExtensionToPattern (type.pattern, extension);
1891         type.extension= omod;
1892         fileTypeComboBox.append_text(type.name);
1893         fileTypes.push_back(type);
1894     }
1896     //#Let user choose
1897     FileType guessType;
1898     guessType.name = _("Guess from extension");
1899     guessType.pattern = "*";
1900     guessType.extension = NULL;
1901     fileTypeComboBox.append_text(guessType.name);
1902     fileTypes.push_back(guessType);
1905     fileTypeComboBox.set_active(0);
1906     fileTypeChangedCallback(); //call at least once to set the filter
1910 /**
1911  * Constructor
1912  */
1913 FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir,
1914             FileDialogType fileTypes,
1915             const Glib::ustring &title,
1916             const Glib::ustring &default_key) :
1917             FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE),
1918             sourceX0Spinner("X0",         _("Left edge of source")),
1919             sourceY0Spinner("Y0",         _("Top edge of source")),
1920             sourceX1Spinner("X1",         _("Right edge of source")),
1921             sourceY1Spinner("Y1",         _("Bottom edge of source")),
1922             sourceWidthSpinner("Width",   _("Source width")),
1923             sourceHeightSpinner("Height", _("Source height")),
1924             destWidthSpinner("Width",     _("Destination width")),
1925             destHeightSpinner("Height",   _("Destination height")),
1926             destDPISpinner("DPI",         _("Resolution (dots per inch)"))
1928     append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);
1930     /* One file at a time */
1931     set_select_multiple(false);
1933 #ifdef WITH_GNOME_VFS
1934     set_local_only(false);
1935 #endif
1937     /* Initalize to Autodetect */
1938     extension = NULL;
1939     /* No filename to start out with */
1940     myFilename = "";
1942     /* Set our dialog type (save, export, etc...)*/
1943     dialogType = fileTypes;
1945     /* Set the pwd and/or the filename */
1946     if (dir.size()>0)
1947         {
1948         Glib::ustring udir(dir);
1949         Glib::ustring::size_type len = udir.length();
1950         // leaving a trailing backslash on the directory name leads to the infamous
1951         // double-directory bug on win32
1952         if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1953         set_current_folder(udir.c_str());
1954         }
1956     //#########################################
1957     //## EXTRA WIDGET -- SOURCE SIDE
1958     //#########################################
1960     //##### Export options buttons/spinners, etc
1961     documentButton.set_label(_("Document"));
1962     scopeBox.pack_start(documentButton);
1963     scopeGroup = documentButton.get_group();
1965     pageButton.set_label(_("Page"));
1966     pageButton.set_group(scopeGroup);
1967     scopeBox.pack_start(pageButton);
1969     selectionButton.set_label(_("Selection"));
1970     selectionButton.set_group(scopeGroup);
1971     scopeBox.pack_start(selectionButton);
1973     customButton.set_label(_("Custom"));
1974     customButton.set_group(scopeGroup);
1975     scopeBox.pack_start(customButton);
1977     sourceBox.pack_start(scopeBox);
1981     //dimension buttons
1982     sourceTable.resize(3,3);
1983     sourceTable.attach(sourceX0Spinner,     0,1,0,1);
1984     sourceTable.attach(sourceY0Spinner,     1,2,0,1);
1985     sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
1986     sourceTable.attach(sourceUnitsSpinner,  2,3,0,1);
1987     sourceTable.attach(sourceX1Spinner,     0,1,1,2);
1988     sourceTable.attach(sourceY1Spinner,     1,2,1,2);
1989     sourceTable.attach(sourceWidthSpinner,  0,1,2,3);
1990     sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
1992     sourceBox.pack_start(sourceTable);
1993     sourceFrame.set_label(_("Source"));
1994     sourceFrame.add(sourceBox);
1995     exportOptionsBox.pack_start(sourceFrame);
1998     //#########################################
1999     //## EXTRA WIDGET -- SOURCE SIDE
2000     //#########################################
2003     destTable.resize(3,3);
2004     destTable.attach(destWidthSpinner,    0,1,0,1);
2005     destTable.attach(destHeightSpinner,   1,2,0,1);
2006     destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
2007     destTable.attach(destUnitsSpinner,    2,3,0,1);
2008     destTable.attach(destDPISpinner,      0,1,1,2);
2010     destBox.pack_start(destTable);
2013     cairoButton.set_label(_("Cairo"));
2014     otherOptionBox.pack_start(cairoButton);
2016     antiAliasButton.set_label(_("Antialias"));
2017     otherOptionBox.pack_start(antiAliasButton);
2019     backgroundButton.set_label(_("Background"));
2020     otherOptionBox.pack_start(backgroundButton);
2022     destBox.pack_start(otherOptionBox);
2028     //###### File options
2029     //###### Do we want the .xxx extension automatically added?
2030     fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
2031     fileTypeCheckbox.set_active(append_extension);
2032     destBox.pack_start(fileTypeCheckbox);
2034     //###### File type menu
2035     createFileTypeMenu();
2036     fileTypeComboBox.set_size_request(200,40);
2037     fileTypeComboBox.signal_changed().connect(
2038          sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
2040     destBox.pack_start(fileTypeComboBox);
2042     destFrame.set_label(_("Destination"));
2043     destFrame.add(destBox);
2044     exportOptionsBox.pack_start(destFrame);
2046     //##### Put the two boxes and their parent onto the dialog    
2047     exportOptionsBox.pack_start(sourceFrame);
2048     exportOptionsBox.pack_start(destFrame);
2050     set_extra_widget(exportOptionsBox);
2055     //###### PREVIEW WIDGET
2056     set_preview_widget(svgPreview);
2057     set_preview_widget_active(true);
2058     set_use_preview_label (false);
2060     //Catch selection-changed events, so we can adjust the text widget
2061     signal_update_preview().connect(
2062          sigc::mem_fun(*this, &FileExportDialogImpl::updatePreviewCallback) );
2065     //Let's do some customization
2066     fileNameEntry = NULL;
2067     Gtk::Container *cont = get_toplevel();
2068     std::vector<Gtk::Entry *> entries;
2069     findEntryWidgets(cont, entries);
2070     //g_message("Found %d entry widgets\n", entries.size());
2071     if (entries.size() >=1 )
2072         {
2073         //Catch when user hits [return] on the text field
2074         fileNameEntry = entries[0];
2075         fileNameEntry->signal_activate().connect(
2076              sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
2077         }
2079     //Let's do more customization
2080     std::vector<Gtk::Expander *> expanders;
2081     findExpanderWidgets(cont, expanders);
2082     //g_message("Found %d expander widgets\n", expanders.size());
2083     if (expanders.size() >=1 )
2084         {
2085         //Always show the file list
2086         Gtk::Expander *expander = expanders[0];
2087         expander->set_expanded(true);
2088         }
2091     //if (extension == NULL)
2092     //    checkbox.set_sensitive(FALSE);
2094     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2095     set_default(*add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK));
2097     show_all_children();
2102 /**
2103  * Public factory method.  Used in file.cpp
2104  */
2105 FileExportDialog *FileExportDialog::create(const Glib::ustring &path,
2106                                        FileDialogType fileTypes,
2107                                        const Glib::ustring &title,
2108                                        const Glib::ustring &default_key)
2110     FileExportDialog *dialog = new FileExportDialogImpl(path, fileTypes, title, default_key);
2111     return dialog;
2118 /**
2119  * Destructor
2120  */
2121 FileExportDialogImpl::~FileExportDialogImpl()
2127 /**
2128  * Show this dialog modally.  Return true if user hits [OK]
2129  */
2130 bool
2131 FileExportDialogImpl::show()
2133     Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
2134     if (s.length() == 0) 
2135         s = getcwd (NULL, 0);
2136     set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
2137     set_modal (TRUE);                      //Window
2138     sp_transientize((GtkWidget *)gobj());  //Make transient
2139     gint b = run();                        //Dialog
2140     svgPreview.showNoPreview();
2141     hide();
2143     if (b == Gtk::RESPONSE_OK)
2144         {
2145         int sel = fileTypeComboBox.get_active_row_number ();
2146         if (sel>=0 && sel< (int)fileTypes.size())
2147             {
2148             FileType &type = fileTypes[sel];
2149             extension = type.extension;
2150             }
2151         myFilename = get_filename();
2152 #ifdef WITH_GNOME_VFS
2153         if (myFilename.length() < 1)
2154             myFilename = get_uri();
2155 #endif
2157         /*
2159         // FIXME: Why do we have more code
2161         append_extension = checkbox.get_active();
2162         prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
2163         prefs_set_string_attribute("dialogs.save_as", "default",
2164                   ( extension != NULL ? extension->get_id() : "" ));
2165         */
2166         return TRUE;
2167         }
2168     else
2169         {
2170         return FALSE;
2171         }
2175 /**
2176  * Get the file extension type that was selected by the user. Valid after an [OK]
2177  */
2178 Inkscape::Extension::Extension *
2179 FileExportDialogImpl::getSelectionType()
2181     return extension;
2185 /**
2186  * Get the file name chosen by the user.   Valid after an [OK]
2187  */
2188 Glib::ustring
2189 FileExportDialogImpl::getFilename()
2191     return myFilename;
2197 } //namespace Dialog
2198 } //namespace UI
2199 } //namespace Inkscape
2202 /*
2203   Local Variables:
2204   mode:c++
2205   c-file-style:"stroustrup"
2206   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2207   indent-tabs-mode:nil
2208   fill-column:99
2209   End:
2210 */
2211 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :