b76772c4056f454f44075dbcc37cbfdb23ce6cb8
1 /**\r
2 * Implementation of the file dialog interfaces defined in filedialogimpl.h\r
3 *\r
4 * Authors:\r
5 * Bob Jamison\r
6 * Joel Holdsworth\r
7 * Other dudes from The Inkscape Organization\r
8 *\r
9 * Copyright (C) 2004-2007 Bob Jamison\r
10 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>\r
11 * Copyright (C) 2004-2007 The Inkscape Organization\r
12 * Copyright (C) 2007 Joel Holdsworth\r
13 *\r
14 * Released under GNU GPL, read the file 'COPYING' for more information\r
15 */\r
16 \r
17 #ifdef HAVE_CONFIG_H\r
18 # include <config.h>\r
19 #endif\r
20 \r
21 #include "filedialogimpl-gtkmm.h"\r
22 #include "dialogs/dialog-events.h"\r
23 \r
24 //Routines from file.cpp\r
25 #undef INK_DUMP_FILENAME_CONV\r
26 \r
27 #ifdef INK_DUMP_FILENAME_CONV\r
28 void dump_str( const gchar* str, const gchar* prefix );\r
29 void dump_ustr( const Glib::ustring& ustr );\r
30 #endif\r
31 \r
32 \r
33 \r
34 namespace Inkscape\r
35 {\r
36 namespace UI\r
37 {\r
38 namespace Dialog\r
39 {\r
40 \r
41 \r
42 \r
43 \r
44 \r
45 //########################################################################\r
46 //### U T I L I T Y\r
47 //########################################################################\r
48 \r
49 /**\r
50 \brief A quick function to turn a standard extension into a searchable\r
51 pattern for the file dialogs\r
52 \param pattern The patter that the extension should be written to\r
53 \param in_file_extension The C string that represents the extension\r
54 \r
55 This function just goes through the string, and takes all characters\r
56 and puts a [<upper><lower>] so that both are searched and shown in\r
57 the file dialog. This function edits the pattern string to make\r
58 this happen.\r
59 */\r
60 static void\r
61 fileDialogExtensionToPattern(Glib::ustring &pattern,\r
62 Glib::ustring &extension)\r
63 {\r
64 for (unsigned int i = 0; i < extension.length(); i++ )\r
65 {\r
66 Glib::ustring::value_type ch = extension[i];\r
67 if ( Glib::Unicode::isalpha(ch) )\r
68 {\r
69 pattern += '[';\r
70 pattern += Glib::Unicode::toupper(ch);\r
71 pattern += Glib::Unicode::tolower(ch);\r
72 pattern += ']';\r
73 }\r
74 else\r
75 {\r
76 pattern += ch;\r
77 }\r
78 }\r
79 }\r
80 \r
81 \r
82 /**\r
83 * Hack: Find all entry widgets in a container\r
84 */\r
85 static void\r
86 findEntryWidgets(Gtk::Container *parent,\r
87 std::vector<Gtk::Entry *> &result)\r
88 {\r
89 if (!parent)\r
90 return;\r
91 std::vector<Gtk::Widget *> children = parent->get_children();\r
92 for (unsigned int i=0; i<children.size() ; i++)\r
93 {\r
94 Gtk::Widget *child = children[i];\r
95 GtkWidget *wid = child->gobj();\r
96 if (GTK_IS_ENTRY(wid))\r
97 result.push_back((Gtk::Entry *)child);\r
98 else if (GTK_IS_CONTAINER(wid))\r
99 findEntryWidgets((Gtk::Container *)child, result);\r
100 }\r
101 \r
102 }\r
103 \r
104 \r
105 \r
106 \r
107 /**\r
108 * Hack: Find all expander widgets in a container\r
109 */\r
110 static void\r
111 findExpanderWidgets(Gtk::Container *parent,\r
112 std::vector<Gtk::Expander *> &result)\r
113 {\r
114 if (!parent)\r
115 return;\r
116 std::vector<Gtk::Widget *> children = parent->get_children();\r
117 for (unsigned int i=0; i<children.size() ; i++)\r
118 {\r
119 Gtk::Widget *child = children[i];\r
120 GtkWidget *wid = child->gobj();\r
121 if (GTK_IS_EXPANDER(wid))\r
122 result.push_back((Gtk::Expander *)child);\r
123 else if (GTK_IS_CONTAINER(wid))\r
124 findExpanderWidgets((Gtk::Container *)child, result);\r
125 }\r
126 \r
127 }\r
128 \r
129 \r
130 /*#########################################################################\r
131 ### SVG Preview Widget\r
132 #########################################################################*/\r
133 \r
134 bool SVGPreview::setDocument(SPDocument *doc)\r
135 {\r
136 if (document)\r
137 sp_document_unref(document);\r
138 \r
139 sp_document_ref(doc);\r
140 document = doc;\r
141 \r
142 //This should remove it from the box, and free resources\r
143 if (viewerGtk)\r
144 gtk_widget_destroy(viewerGtk);\r
145 \r
146 viewerGtk = sp_svg_view_widget_new(doc);\r
147 GtkWidget *vbox = (GtkWidget *)gobj();\r
148 gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);\r
149 gtk_widget_show(viewerGtk);\r
150 \r
151 return true;\r
152 }\r
153 \r
154 \r
155 bool SVGPreview::setFileName(Glib::ustring &theFileName)\r
156 {\r
157 Glib::ustring fileName = theFileName;\r
158 \r
159 fileName = Glib::filename_to_utf8(fileName);\r
160 \r
161 /**\r
162 * I don't know why passing false to keepalive is bad. But it\r
163 * prevents the display of an svg with a non-ascii filename\r
164 */ \r
165 SPDocument *doc = sp_document_new (fileName.c_str(), true);\r
166 if (!doc) {\r
167 g_warning("SVGView: error loading document '%s'\n", fileName.c_str());\r
168 return false;\r
169 }\r
170 \r
171 setDocument(doc);\r
172 \r
173 sp_document_unref(doc);\r
174 \r
175 return true;\r
176 }\r
177 \r
178 \r
179 \r
180 bool SVGPreview::setFromMem(char const *xmlBuffer)\r
181 {\r
182 if (!xmlBuffer)\r
183 return false;\r
184 \r
185 gint len = (gint)strlen(xmlBuffer);\r
186 SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);\r
187 if (!doc) {\r
188 g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);\r
189 return false;\r
190 }\r
191 \r
192 setDocument(doc);\r
193 \r
194 sp_document_unref(doc);\r
195 \r
196 Inkscape::GC::request_early_collection();\r
197 \r
198 return true;\r
199 }\r
200 \r
201 \r
202 \r
203 void SVGPreview::showImage(Glib::ustring &theFileName)\r
204 {\r
205 Glib::ustring fileName = theFileName;\r
206 \r
207 \r
208 /*#####################################\r
209 # LET'S HAVE SOME FUN WITH SVG!\r
210 # Instead of just loading an image, why\r
211 # don't we make a lovely little svg and\r
212 # display it nicely?\r
213 #####################################*/\r
214 \r
215 //Arbitrary size of svg doc -- rather 'portrait' shaped\r
216 gint previewWidth = 400;\r
217 gint previewHeight = 600;\r
218 \r
219 //Get some image info. Smart pointer does not need to be deleted\r
220 Glib::RefPtr<Gdk::Pixbuf> img = Gdk::Pixbuf::create_from_file(fileName);\r
221 gint imgWidth = img->get_width();\r
222 gint imgHeight = img->get_height();\r
223 \r
224 //Find the minimum scale to fit the image inside the preview area\r
225 double scaleFactorX = (0.9 *(double)previewWidth) / ((double)imgWidth);\r
226 double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);\r
227 double scaleFactor = scaleFactorX;\r
228 if (scaleFactorX > scaleFactorY)\r
229 scaleFactor = scaleFactorY;\r
230 \r
231 //Now get the resized values\r
232 gint scaledImgWidth = (int) (scaleFactor * (double)imgWidth);\r
233 gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);\r
234 \r
235 //center the image on the area\r
236 gint imgX = (previewWidth - scaledImgWidth) / 2;\r
237 gint imgY = (previewHeight - scaledImgHeight) / 2;\r
238 \r
239 //wrap a rectangle around the image\r
240 gint rectX = imgX-1;\r
241 gint rectY = imgY-1;\r
242 gint rectWidth = scaledImgWidth +2;\r
243 gint rectHeight = scaledImgHeight+2;\r
244 \r
245 //Our template. Modify to taste\r
246 gchar const *xformat =\r
247 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\r
248 "<svg\n"\r
249 "xmlns=\"http://www.w3.org/2000/svg\"\n"\r
250 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"\r
251 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE\r
252 "<rect\n"\r
253 " style=\"fill:#eeeeee;stroke:none\"\n"\r
254 " x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"\r
255 "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"\r
256 "xlink:href=\"%s\"/>\n"\r
257 "<rect\n"\r
258 " style=\"fill:none;"\r
259 " stroke:#000000;stroke-width:1.0;"\r
260 " stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
261 " stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"\r
262 " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"\r
263 "<text\n"\r
264 " style=\"font-size:24.000000;font-style:normal;font-weight:normal;"\r
265 " fill:#000000;fill-opacity:1.0000000;stroke:none;"\r
266 " font-family:Bitstream Vera Sans\"\n"\r
267 " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE\r
268 "</svg>\n\n";\r
269 \r
270 //if (!Glib::get_charset()) //If we are not utf8\r
271 fileName = Glib::filename_to_utf8(fileName);\r
272 \r
273 //Fill in the template\r
274 /* FIXME: Do proper XML quoting for fileName. */\r
275 gchar *xmlBuffer = g_strdup_printf(xformat,\r
276 previewWidth, previewHeight,\r
277 imgX, imgY, scaledImgWidth, scaledImgHeight,\r
278 fileName.c_str(),\r
279 rectX, rectY, rectWidth, rectHeight,\r
280 imgWidth, imgHeight);\r
281 \r
282 //g_message("%s\n", xmlBuffer);\r
283 \r
284 //now show it!\r
285 setFromMem(xmlBuffer);\r
286 g_free(xmlBuffer);\r
287 }\r
288 \r
289 \r
290 \r
291 void SVGPreview::showNoPreview()\r
292 {\r
293 //Are we already showing it?\r
294 if (showingNoPreview)\r
295 return;\r
296 \r
297 //Arbitrary size of svg doc -- rather 'portrait' shaped\r
298 gint previewWidth = 300;\r
299 gint previewHeight = 600;\r
300 \r
301 //Our template. Modify to taste\r
302 gchar const *xformat =\r
303 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\r
304 "<svg\n"\r
305 "xmlns=\"http://www.w3.org/2000/svg\"\n"\r
306 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"\r
307 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE\r
308 "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"\r
309 "<path\n"\r
310 "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"\r
311 "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "\r
312 "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"\r
313 "id=\"whiteSpace\" />\n"\r
314 "<path\n"\r
315 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
316 "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "\r
317 "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "\r
318 "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"\r
319 "id=\"droplet01\" />\n"\r
320 "<path\n"\r
321 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
322 "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "\r
323 "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "\r
324 "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "\r
325 "287.18046 343.1206 286.46194 340.42914 z \"\n"\r
326 "id=\"droplet02\" />\n"\r
327 "<path\n"\r
328 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
329 "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "\r
330 "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "\r
331 "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"\r
332 "id=\"droplet03\" />\n"\r
333 "<path\n"\r
334 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
335 "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "\r
336 "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "\r
337 "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "\r
338 "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "\r
339 "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "\r
340 "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "\r
341 "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "\r
342 "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "\r
343 "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "\r
344 "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "\r
345 "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "\r
346 "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "\r
347 "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "\r
348 "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "\r
349 "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "\r
350 "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "\r
351 "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "\r
352 "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "\r
353 "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "\r
354 "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "\r
355 "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "\r
356 "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "\r
357 "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "\r
358 "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "\r
359 "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "\r
360 "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "\r
361 "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "\r
362 "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"\r
363 "id=\"mountainDroplet\" />\n"\r
364 "</g> <g transform=\"translate(-20,0)\">\n"\r
365 "<text xml:space=\"preserve\"\n"\r
366 "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"\r
367 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"\r
368 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
369 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"\r
370 "x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE\r
371 "</svg>\n\n";\r
372 \r
373 //Fill in the template\r
374 gchar *xmlBuffer = g_strdup_printf(xformat,\r
375 previewWidth, previewHeight, _("No preview"));\r
376 \r
377 //g_message("%s\n", xmlBuffer);\r
378 \r
379 //now show it!\r
380 setFromMem(xmlBuffer);\r
381 g_free(xmlBuffer);\r
382 showingNoPreview = true;\r
383 \r
384 }\r
385 \r
386 \r
387 /**\r
388 * Inform the user that the svg file is too large to be displayed.\r
389 * This does not check for sizes of embedded images (yet) \r
390 */ \r
391 void SVGPreview::showTooLarge(long fileLength)\r
392 {\r
393 \r
394 //Arbitrary size of svg doc -- rather 'portrait' shaped\r
395 gint previewWidth = 300;\r
396 gint previewHeight = 600;\r
397 \r
398 //Our template. Modify to taste\r
399 gchar const *xformat =\r
400 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\r
401 "<svg\n"\r
402 "xmlns=\"http://www.w3.org/2000/svg\"\n"\r
403 "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"\r
404 "width=\"%d\" height=\"%d\">\n" //# VALUES HERE\r
405 "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"\r
406 "<path\n"\r
407 "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"\r
408 "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "\r
409 "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"\r
410 "id=\"whiteSpace\" />\n"\r
411 "<path\n"\r
412 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
413 "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "\r
414 "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "\r
415 "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"\r
416 "id=\"droplet01\" />\n"\r
417 "<path\n"\r
418 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
419 "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "\r
420 "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "\r
421 "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "\r
422 "287.18046 343.1206 286.46194 340.42914 z \"\n"\r
423 "id=\"droplet02\" />\n"\r
424 "<path\n"\r
425 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
426 "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "\r
427 "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "\r
428 "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"\r
429 "id=\"droplet03\" />\n"\r
430 "<path\n"\r
431 "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
432 "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "\r
433 "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "\r
434 "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "\r
435 "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "\r
436 "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "\r
437 "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "\r
438 "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "\r
439 "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "\r
440 "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "\r
441 "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "\r
442 "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "\r
443 "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "\r
444 "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "\r
445 "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "\r
446 "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "\r
447 "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "\r
448 "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "\r
449 "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "\r
450 "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "\r
451 "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "\r
452 "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "\r
453 "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "\r
454 "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "\r
455 "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "\r
456 "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "\r
457 "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "\r
458 "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "\r
459 "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"\r
460 "id=\"mountainDroplet\" />\n"\r
461 "</g>\n"\r
462 "<text xml:space=\"preserve\"\n"\r
463 "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"\r
464 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"\r
465 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
466 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"\r
467 "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE\r
468 "<text xml:space=\"preserve\"\n"\r
469 "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"\r
470 "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"\r
471 "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
472 "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"\r
473 "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE\r
474 "</svg>\n\n";\r
475 \r
476 //Fill in the template\r
477 double floatFileLength = ((double)fileLength) / 1048576.0;\r
478 //printf("%ld %f\n", fileLength, floatFileLength);\r
479 gchar *xmlBuffer = g_strdup_printf(xformat,\r
480 previewWidth, previewHeight, floatFileLength,\r
481 _("too large for preview"));\r
482 \r
483 //g_message("%s\n", xmlBuffer);\r
484 \r
485 //now show it!\r
486 setFromMem(xmlBuffer);\r
487 g_free(xmlBuffer);\r
488 \r
489 }\r
490 \r
491 \r
492 /**\r
493 * Return true if the string ends with the given suffix\r
494 */ \r
495 static bool\r
496 hasSuffix(Glib::ustring &str, Glib::ustring &ext)\r
497 {\r
498 int strLen = str.length();\r
499 int extLen = ext.length();\r
500 if (extLen > strLen)\r
501 return false;\r
502 int strpos = strLen-1;\r
503 for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)\r
504 {\r
505 Glib::ustring::value_type ch = str[strpos];\r
506 if (ch != ext[extpos])\r
507 {\r
508 if ( ((ch & 0xff80) != 0) ||\r
509 static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )\r
510 {\r
511 return false;\r
512 }\r
513 }\r
514 }\r
515 return true;\r
516 }\r
517 \r
518 \r
519 /**\r
520 * Return true if the image is loadable by Gdk, else false\r
521 */\r
522 static bool\r
523 isValidImageFile(Glib::ustring &fileName)\r
524 {\r
525 std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();\r
526 for (unsigned int i=0; i<formats.size(); i++)\r
527 {\r
528 Gdk::PixbufFormat format = formats[i];\r
529 std::vector<Glib::ustring>extensions = format.get_extensions();\r
530 for (unsigned int j=0; j<extensions.size(); j++)\r
531 {\r
532 Glib::ustring ext = extensions[j];\r
533 if (hasSuffix(fileName, ext))\r
534 return true;\r
535 }\r
536 }\r
537 return false;\r
538 }\r
539 \r
540 bool SVGPreview::set(Glib::ustring &fileName, int dialogType)\r
541 {\r
542 \r
543 if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))\r
544 return false;\r
545 \r
546 //g_message("fname:%s", fileName.c_str());\r
547 \r
548 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {\r
549 showNoPreview();\r
550 return false;\r
551 }\r
552 \r
553 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))\r
554 {\r
555 Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);\r
556 gchar *fName = (gchar *)fileNameUtf8.c_str();\r
557 struct stat info;\r
558 if (g_stat(fName, &info))\r
559 {\r
560 g_warning("SVGPreview::set() : %s : %s",\r
561 fName, strerror(errno));\r
562 return FALSE;\r
563 }\r
564 long fileLen = info.st_size;\r
565 if (fileLen > 0x150000L)\r
566 {\r
567 showingNoPreview = false;\r
568 showTooLarge(fileLen);\r
569 return FALSE;\r
570 }\r
571 }\r
572 \r
573 Glib::ustring svg = ".svg";\r
574 Glib::ustring svgz = ".svgz";\r
575 \r
576 if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&\r
577 (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) )\r
578 ) {\r
579 bool retval = setFileName(fileName);\r
580 showingNoPreview = false;\r
581 return retval;\r
582 } else if (isValidImageFile(fileName)) {\r
583 showImage(fileName);\r
584 showingNoPreview = false;\r
585 return true;\r
586 } else {\r
587 showNoPreview();\r
588 return false;\r
589 }\r
590 }\r
591 \r
592 \r
593 SVGPreview::SVGPreview()\r
594 {\r
595 if (!INKSCAPE)\r
596 inkscape_application_init("",false);\r
597 document = NULL;\r
598 viewerGtk = NULL;\r
599 set_size_request(150,150);\r
600 showingNoPreview = false;\r
601 }\r
602 \r
603 SVGPreview::~SVGPreview()\r
604 {\r
605 \r
606 }\r
607 \r
608 \r
609 /*#########################################################################\r
610 ### F I L E D I A L O G B A S E C L A S S\r
611 #########################################################################*/\r
612 \r
613 void FileDialogBaseGtk::internalSetup()\r
614 {\r
615 bool enablePreview = \r
616 (bool)prefs_get_int_attribute( preferenceBase.c_str(),\r
617 "enable_preview", 1 );\r
618 \r
619 previewCheckbox.set_label( Glib::ustring(_("Enable Preview")) );\r
620 previewCheckbox.set_active( enablePreview );\r
621 \r
622 previewCheckbox.signal_toggled().connect(\r
623 sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB) );\r
624 \r
625 //Catch selection-changed events, so we can adjust the text widget\r
626 signal_update_preview().connect(\r
627 sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback) );\r
628 \r
629 //###### Add a preview widget\r
630 set_preview_widget(svgPreview);\r
631 set_preview_widget_active( enablePreview );\r
632 set_use_preview_label (false);\r
633 \r
634 }\r
635 \r
636 \r
637 void FileDialogBaseGtk::cleanup( bool showConfirmed )\r
638 {\r
639 if ( showConfirmed )\r
640 prefs_set_int_attribute( preferenceBase.c_str(),\r
641 "enable_preview", previewCheckbox.get_active() );\r
642 }\r
643 \r
644 \r
645 void FileDialogBaseGtk::_previewEnabledCB()\r
646 {\r
647 bool enabled = previewCheckbox.get_active();\r
648 set_preview_widget_active(enabled);\r
649 if ( enabled ) {\r
650 _updatePreviewCallback();\r
651 }\r
652 }\r
653 \r
654 \r
655 \r
656 /**\r
657 * Callback for checking if the preview needs to be redrawn\r
658 */\r
659 void FileDialogBaseGtk::_updatePreviewCallback()\r
660 {\r
661 Glib::ustring fileName = get_preview_filename();\r
662 \r
663 #ifdef WITH_GNOME_VFS\r
664 if ( fileName.empty() && gnome_vfs_initialized() ) {\r
665 fileName = get_preview_uri();\r
666 }\r
667 #endif\r
668 \r
669 if (fileName.empty()) {\r
670 return;\r
671 }\r
672 \r
673 svgPreview.set(fileName, dialogType);\r
674 }\r
675 \r
676 \r
677 /*#########################################################################\r
678 ### F I L E O P E N\r
679 #########################################################################*/\r
680 \r
681 /**\r
682 * Constructor. Not called directly. Use the factory.\r
683 */\r
684 FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow, \r
685 const Glib::ustring &dir,\r
686 FileDialogType fileTypes,\r
687 const Glib::ustring &title) :\r
688 FileDialogBaseGtk(parentWindow, title, fileTypes, "dialogs.open")\r
689 {\r
690 \r
691 \r
692 /* One file at a time */\r
693 /* And also Multiple Files */\r
694 set_select_multiple(true);\r
695 \r
696 #ifdef WITH_GNOME_VFS\r
697 if (gnome_vfs_initialized()) {\r
698 set_local_only(false);\r
699 }\r
700 #endif\r
701 \r
702 /* Initalize to Autodetect */\r
703 extension = NULL;\r
704 /* No filename to start out with */\r
705 myFilename = "";\r
706 \r
707 /* Set our dialog type (open, import, etc...)*/\r
708 dialogType = fileTypes;\r
709 \r
710 \r
711 /* Set the pwd and/or the filename */\r
712 if (dir.size() > 0)\r
713 {\r
714 Glib::ustring udir(dir);\r
715 Glib::ustring::size_type len = udir.length();\r
716 // leaving a trailing backslash on the directory name leads to the infamous\r
717 // double-directory bug on win32\r
718 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);\r
719 set_current_folder(udir.c_str());\r
720 }\r
721 \r
722 \r
723 set_extra_widget( previewCheckbox );\r
724 \r
725 \r
726 //###### Add the file types menu\r
727 createFilterMenu();\r
728 \r
729 \r
730 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
731 set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));\r
732 }\r
733 \r
734 /**\r
735 * Destructor\r
736 */\r
737 FileOpenDialogImplGtk::~FileOpenDialogImplGtk()\r
738 {\r
739 \r
740 }\r
741 \r
742 void FileOpenDialogImplGtk::createFilterMenu()\r
743 {\r
744 Gtk::FileFilter allInkscapeFilter;\r
745 allInkscapeFilter.set_name(_("All Inkscape Files"));\r
746 extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;\r
747 add_filter(allInkscapeFilter);\r
748 \r
749 Gtk::FileFilter allFilter;\r
750 allFilter.set_name(_("All Files"));\r
751 extensionMap[Glib::ustring(_("All Files"))]=NULL;\r
752 allFilter.add_pattern("*");\r
753 add_filter(allFilter);\r
754 \r
755 Gtk::FileFilter allImageFilter;\r
756 allImageFilter.set_name(_("All Images"));\r
757 extensionMap[Glib::ustring(_("All Images"))]=NULL;\r
758 add_filter(allImageFilter);\r
759 \r
760 //patterns added dynamically below\r
761 Inkscape::Extension::DB::InputList extension_list;\r
762 Inkscape::Extension::db.get_input_list(extension_list);\r
763 \r
764 for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();\r
765 current_item != extension_list.end(); current_item++)\r
766 {\r
767 Inkscape::Extension::Input * imod = *current_item;\r
768 \r
769 // FIXME: would be nice to grey them out instead of not listing them\r
770 if (imod->deactivated()) continue;\r
771 \r
772 Glib::ustring upattern("*");\r
773 Glib::ustring extension = imod->get_extension();\r
774 fileDialogExtensionToPattern(upattern, extension);\r
775 \r
776 Gtk::FileFilter filter;\r
777 Glib::ustring uname(_(imod->get_filetypename()));\r
778 filter.set_name(uname);\r
779 filter.add_pattern(upattern);\r
780 add_filter(filter);\r
781 extensionMap[uname] = imod;\r
782 \r
783 //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());\r
784 allInkscapeFilter.add_pattern(upattern);\r
785 if ( strncmp("image", imod->get_mimetype(), 5)==0 )\r
786 allImageFilter.add_pattern(upattern);\r
787 }\r
788 \r
789 return;\r
790 }\r
791 \r
792 /**\r
793 * Show this dialog modally. Return true if user hits [OK]\r
794 */\r
795 bool\r
796 FileOpenDialogImplGtk::show()\r
797 {\r
798 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());\r
799 if (s.length() == 0) \r
800 s = getcwd (NULL, 0);\r
801 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing\r
802 set_modal (TRUE); //Window\r
803 sp_transientize((GtkWidget *)gobj()); //Make transient\r
804 gint b = run(); //Dialog\r
805 svgPreview.showNoPreview();\r
806 hide();\r
807 \r
808 if (b == Gtk::RESPONSE_OK)\r
809 {\r
810 //This is a hack, to avoid the warning messages that\r
811 //Gtk::FileChooser::get_filter() returns\r
812 //should be: Gtk::FileFilter *filter = get_filter();\r
813 GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();\r
814 GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);\r
815 if (filter)\r
816 {\r
817 //Get which extension was chosen, if any\r
818 extension = extensionMap[gtk_file_filter_get_name(filter)];\r
819 }\r
820 myFilename = get_filename();\r
821 #ifdef WITH_GNOME_VFS\r
822 if (myFilename.empty() && gnome_vfs_initialized())\r
823 myFilename = get_uri();\r
824 #endif\r
825 cleanup( true );\r
826 return TRUE;\r
827 }\r
828 else\r
829 {\r
830 cleanup( false );\r
831 return FALSE;\r
832 }\r
833 }\r
834 \r
835 \r
836 \r
837 \r
838 /**\r
839 * Get the file extension type that was selected by the user. Valid after an [OK]\r
840 */\r
841 Inkscape::Extension::Extension *\r
842 FileOpenDialogImplGtk::getSelectionType()\r
843 {\r
844 return extension;\r
845 }\r
846 \r
847 \r
848 /**\r
849 * Get the file name chosen by the user. Valid after an [OK]\r
850 */\r
851 Glib::ustring\r
852 FileOpenDialogImplGtk::getFilename (void)\r
853 {\r
854 return g_strdup(myFilename.c_str());\r
855 }\r
856 \r
857 \r
858 /**\r
859 * To Get Multiple filenames selected at-once.\r
860 */\r
861 std::vector<Glib::ustring>FileOpenDialogImplGtk::getFilenames()\r
862 { \r
863 std::vector<Glib::ustring> result = get_filenames();\r
864 #ifdef WITH_GNOME_VFS\r
865 if (result.empty() && gnome_vfs_initialized())\r
866 result = get_uris();\r
867 #endif\r
868 return result;\r
869 }\r
870 \r
871 \r
872 \r
873 \r
874 \r
875 \r
876 //########################################################################\r
877 //# F I L E S A V E\r
878 //########################################################################\r
879 \r
880 /**\r
881 * Constructor\r
882 */\r
883 FileSaveDialogImplGtk::FileSaveDialogImplGtk(Gtk::Window &parentWindow, \r
884 const Glib::ustring &dir,\r
885 FileDialogType fileTypes,\r
886 const Glib::ustring &title,\r
887 const Glib::ustring &default_key) :\r
888 FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")\r
889 {\r
890 /* One file at a time */\r
891 set_select_multiple(false);\r
892 \r
893 #ifdef WITH_GNOME_VFS\r
894 if (gnome_vfs_initialized()) {\r
895 set_local_only(false);\r
896 }\r
897 #endif\r
898 \r
899 /* Initalize to Autodetect */\r
900 extension = NULL;\r
901 /* No filename to start out with */\r
902 myFilename = "";\r
903 \r
904 /* Set our dialog type (save, export, etc...)*/\r
905 dialogType = fileTypes;\r
906 \r
907 /* Set the pwd and/or the filename */\r
908 if (dir.size() > 0)\r
909 {\r
910 Glib::ustring udir(dir);\r
911 Glib::ustring::size_type len = udir.length();\r
912 // leaving a trailing backslash on the directory name leads to the infamous\r
913 // double-directory bug on win32\r
914 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);\r
915 myFilename = udir;\r
916 }\r
917 \r
918 //###### Add the file types menu\r
919 //createFilterMenu();\r
920 \r
921 //###### Do we want the .xxx extension automatically added?\r
922 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));\r
923 fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.save_as",\r
924 "append_extension", 1) );\r
925 \r
926 createFileTypeMenu();\r
927 fileTypeComboBox.set_size_request(200,40);\r
928 fileTypeComboBox.signal_changed().connect(\r
929 sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback) );\r
930 \r
931 \r
932 childBox.pack_start( checksBox );\r
933 childBox.pack_end( fileTypeComboBox );\r
934 checksBox.pack_start( fileTypeCheckbox );\r
935 checksBox.pack_start( previewCheckbox );\r
936 \r
937 set_extra_widget( childBox );\r
938 \r
939 //Let's do some customization\r
940 fileNameEntry = NULL;\r
941 Gtk::Container *cont = get_toplevel();\r
942 std::vector<Gtk::Entry *> entries;\r
943 findEntryWidgets(cont, entries);\r
944 //g_message("Found %d entry widgets\n", entries.size());\r
945 if (entries.size() >=1 )\r
946 {\r
947 //Catch when user hits [return] on the text field\r
948 fileNameEntry = entries[0];\r
949 fileNameEntry->signal_activate().connect(\r
950 sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback) );\r
951 }\r
952 \r
953 //Let's do more customization\r
954 std::vector<Gtk::Expander *> expanders;\r
955 findExpanderWidgets(cont, expanders);\r
956 //g_message("Found %d expander widgets\n", expanders.size());\r
957 if (expanders.size() >=1 )\r
958 {\r
959 //Always show the file list\r
960 Gtk::Expander *expander = expanders[0];\r
961 expander->set_expanded(true);\r
962 }\r
963 \r
964 \r
965 //if (extension == NULL)\r
966 // checkbox.set_sensitive(FALSE);\r
967 \r
968 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
969 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));\r
970 \r
971 show_all_children();\r
972 }\r
973 \r
974 /**\r
975 * Destructor\r
976 */\r
977 FileSaveDialogImplGtk::~FileSaveDialogImplGtk()\r
978 {\r
979 }\r
980 \r
981 /**\r
982 * Callback for fileNameEntry widget\r
983 */\r
984 void FileSaveDialogImplGtk::fileNameEntryChangedCallback()\r
985 {\r
986 if (!fileNameEntry)\r
987 return;\r
988 \r
989 Glib::ustring fileName = fileNameEntry->get_text();\r
990 if (!Glib::get_charset()) //If we are not utf8\r
991 fileName = Glib::filename_to_utf8(fileName);\r
992 \r
993 //g_message("User hit return. Text is '%s'\n", fileName.c_str());\r
994 \r
995 if (!Glib::path_is_absolute(fileName)) {\r
996 //try appending to the current path\r
997 // not this way: fileName = get_current_folder() + "/" + fileName;\r
998 std::vector<Glib::ustring> pathSegments;\r
999 pathSegments.push_back( get_current_folder() );\r
1000 pathSegments.push_back( fileName );\r
1001 fileName = Glib::build_filename(pathSegments);\r
1002 }\r
1003 \r
1004 //g_message("path:'%s'\n", fileName.c_str());\r
1005 \r
1006 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {\r
1007 set_current_folder(fileName);\r
1008 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {\r
1009 //dialog with either (1) select a regular file or (2) cd to dir\r
1010 //simulate an 'OK'\r
1011 set_filename(fileName);\r
1012 response(Gtk::RESPONSE_OK);\r
1013 }\r
1014 }\r
1015 \r
1016 \r
1017 \r
1018 /**\r
1019 * Callback for fileNameEntry widget\r
1020 */\r
1021 void FileSaveDialogImplGtk::fileTypeChangedCallback()\r
1022 {\r
1023 int sel = fileTypeComboBox.get_active_row_number();\r
1024 if (sel<0 || sel >= (int)fileTypes.size())\r
1025 return;\r
1026 FileType type = fileTypes[sel];\r
1027 //g_message("selected: %s\n", type.name.c_str());\r
1028 \r
1029 extension = type.extension;\r
1030 Gtk::FileFilter filter;\r
1031 filter.add_pattern(type.pattern);\r
1032 set_filter(filter);\r
1033 \r
1034 updateNameAndExtension();\r
1035 }\r
1036 \r
1037 \r
1038 \r
1039 void FileSaveDialogImplGtk::createFileTypeMenu()\r
1040 {\r
1041 Inkscape::Extension::DB::OutputList extension_list;\r
1042 Inkscape::Extension::db.get_output_list(extension_list);\r
1043 knownExtensions.clear();\r
1044 \r
1045 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();\r
1046 current_item != extension_list.end(); current_item++)\r
1047 {\r
1048 Inkscape::Extension::Output * omod = *current_item;\r
1049 \r
1050 // FIXME: would be nice to grey them out instead of not listing them\r
1051 if (omod->deactivated()) continue;\r
1052 \r
1053 FileType type;\r
1054 type.name = (_(omod->get_filetypename()));\r
1055 type.pattern = "*";\r
1056 Glib::ustring extension = omod->get_extension();\r
1057 knownExtensions.insert( extension.casefold() );\r
1058 fileDialogExtensionToPattern (type.pattern, extension);\r
1059 type.extension= omod;\r
1060 fileTypeComboBox.append_text(type.name);\r
1061 fileTypes.push_back(type);\r
1062 }\r
1063 \r
1064 //#Let user choose\r
1065 FileType guessType;\r
1066 guessType.name = _("Guess from extension");\r
1067 guessType.pattern = "*";\r
1068 guessType.extension = NULL;\r
1069 fileTypeComboBox.append_text(guessType.name);\r
1070 fileTypes.push_back(guessType);\r
1071 \r
1072 \r
1073 fileTypeComboBox.set_active(0);\r
1074 fileTypeChangedCallback(); //call at least once to set the filter\r
1075 }\r
1076 \r
1077 \r
1078 \r
1079 \r
1080 \r
1081 /**\r
1082 * Show this dialog modally. Return true if user hits [OK]\r
1083 */\r
1084 bool\r
1085 FileSaveDialogImplGtk::show()\r
1086 {\r
1087 change_path(myFilename);\r
1088 set_modal (TRUE); //Window\r
1089 sp_transientize((GtkWidget *)gobj()); //Make transient\r
1090 gint b = run(); //Dialog\r
1091 svgPreview.showNoPreview();\r
1092 hide();\r
1093 \r
1094 if (b == Gtk::RESPONSE_OK)\r
1095 {\r
1096 updateNameAndExtension();\r
1097 \r
1098 // Store changes of the "Append filename automatically" checkbox back to preferences.\r
1099 prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active());\r
1100 \r
1101 // Store the last used save-as filetype to preferences.\r
1102 prefs_set_string_attribute("dialogs.save_as", "default",\r
1103 ( extension != NULL ? extension->get_id() : "" ));\r
1104 \r
1105 cleanup( true );\r
1106 \r
1107 return TRUE;\r
1108 }\r
1109 else\r
1110 {\r
1111 cleanup( false );\r
1112 \r
1113 return FALSE;\r
1114 }\r
1115 }\r
1116 \r
1117 \r
1118 /**\r
1119 * Get the file extension type that was selected by the user. Valid after an [OK]\r
1120 */\r
1121 Inkscape::Extension::Extension *\r
1122 FileSaveDialogImplGtk::getSelectionType()\r
1123 {\r
1124 return extension;\r
1125 }\r
1126 \r
1127 void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * key )\r
1128 {\r
1129 // If no pointer to extension is passed in, look up based on filename extension.\r
1130 if ( !key ) {\r
1131 // Not quite UTF-8 here.\r
1132 gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);\r
1133 for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {\r
1134 Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);\r
1135 if ( ext && ext->get_extension() ) {\r
1136 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );\r
1137 if ( g_str_has_suffix(filenameLower, extensionLower) ) {\r
1138 key = fileTypes[i].extension;\r
1139 }\r
1140 g_free(extensionLower);\r
1141 }\r
1142 }\r
1143 g_free(filenameLower);\r
1144 }\r
1145 \r
1146 // Ensure the proper entry in the combo box is selected.\r
1147 if ( key ) {\r
1148 extension = key;\r
1149 gchar const * extensionID = extension->get_id();\r
1150 if ( extensionID ) {\r
1151 for ( int i = 0; i < (int)fileTypes.size(); i++ ) {\r
1152 Inkscape::Extension::Extension *ext = fileTypes[i].extension;\r
1153 if ( ext ) {\r
1154 gchar const * id = ext->get_id();\r
1155 if ( id && ( strcmp(extensionID, id) == 0) ) {\r
1156 int oldSel = fileTypeComboBox.get_active_row_number();\r
1157 if ( i != oldSel ) {\r
1158 fileTypeComboBox.set_active(i);\r
1159 }\r
1160 break;\r
1161 }\r
1162 }\r
1163 }\r
1164 }\r
1165 }\r
1166 }\r
1167 \r
1168 \r
1169 /**\r
1170 * Get the file name chosen by the user. Valid after an [OK]\r
1171 */\r
1172 Glib::ustring\r
1173 FileSaveDialogImplGtk::getFilename()\r
1174 {\r
1175 return myFilename;\r
1176 }\r
1177 \r
1178 \r
1179 void \r
1180 FileSaveDialogImplGtk::change_title(const Glib::ustring& title)\r
1181 {\r
1182 this->set_title(title);\r
1183 }\r
1184 \r
1185 /**\r
1186 * Change the default save path location.\r
1187 */\r
1188 void \r
1189 FileSaveDialogImplGtk::change_path(const Glib::ustring& path)\r
1190 {\r
1191 myFilename = path;\r
1192 if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {\r
1193 //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());\r
1194 set_current_folder(myFilename);\r
1195 } else {\r
1196 //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());\r
1197 if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {\r
1198 set_filename(myFilename);\r
1199 } else {\r
1200 std::string dirName = Glib::path_get_dirname( myFilename );\r
1201 if ( dirName != get_current_folder() ) {\r
1202 set_current_folder(dirName);\r
1203 }\r
1204 }\r
1205 Glib::ustring basename = Glib::path_get_basename(myFilename);\r
1206 //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());\r
1207 try {\r
1208 set_current_name( Glib::filename_to_utf8(basename) );\r
1209 } catch ( Glib::ConvertError& e ) {\r
1210 g_warning( "Error converting save filename to UTF-8." );\r
1211 // try a fallback.\r
1212 set_current_name( basename );\r
1213 }\r
1214 }\r
1215 }\r
1216 \r
1217 void FileSaveDialogImplGtk::updateNameAndExtension()\r
1218 {\r
1219 // Pick up any changes the user has typed in.\r
1220 Glib::ustring tmp = get_filename();\r
1221 #ifdef WITH_GNOME_VFS\r
1222 if ( tmp.empty() && gnome_vfs_initialized() ) {\r
1223 tmp = get_uri();\r
1224 }\r
1225 #endif\r
1226 if ( !tmp.empty() ) {\r
1227 myFilename = tmp;\r
1228 }\r
1229 \r
1230 Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;\r
1231 if ( fileTypeCheckbox.get_active() && newOut ) {\r
1232 try {\r
1233 bool appendExtension = true;\r
1234 Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );\r
1235 Glib::ustring::size_type pos = utf8Name.rfind('.');\r
1236 if ( pos != Glib::ustring::npos ) {\r
1237 Glib::ustring trail = utf8Name.substr( pos );\r
1238 Glib::ustring foldedTrail = trail.casefold();\r
1239 if ( (trail == ".") \r
1240 | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()\r
1241 && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {\r
1242 utf8Name = utf8Name.erase( pos );\r
1243 } else {\r
1244 appendExtension = false;\r
1245 }\r
1246 }\r
1247 \r
1248 if (appendExtension) {\r
1249 utf8Name = utf8Name + newOut->get_extension();\r
1250 myFilename = Glib::filename_from_utf8( utf8Name );\r
1251 change_path(myFilename);\r
1252 }\r
1253 } catch ( Glib::ConvertError& e ) {\r
1254 // ignore\r
1255 }\r
1256 }\r
1257 }\r
1258 \r
1259 \r
1260 //########################################################################\r
1261 //# F I L E E X P O R T\r
1262 //########################################################################\r
1263 \r
1264 /**\r
1265 * Callback for fileNameEntry widget\r
1266 */\r
1267 void FileExportDialogImpl::fileNameEntryChangedCallback()\r
1268 {\r
1269 if (!fileNameEntry)\r
1270 return;\r
1271 \r
1272 Glib::ustring fileName = fileNameEntry->get_text();\r
1273 if (!Glib::get_charset()) //If we are not utf8\r
1274 fileName = Glib::filename_to_utf8(fileName);\r
1275 \r
1276 //g_message("User hit return. Text is '%s'\n", fileName.c_str());\r
1277 \r
1278 if (!Glib::path_is_absolute(fileName)) {\r
1279 //try appending to the current path\r
1280 // not this way: fileName = get_current_folder() + "/" + fileName;\r
1281 std::vector<Glib::ustring> pathSegments;\r
1282 pathSegments.push_back( get_current_folder() );\r
1283 pathSegments.push_back( fileName );\r
1284 fileName = Glib::build_filename(pathSegments);\r
1285 }\r
1286 \r
1287 //g_message("path:'%s'\n", fileName.c_str());\r
1288 \r
1289 if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {\r
1290 set_current_folder(fileName);\r
1291 } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {\r
1292 //dialog with either (1) select a regular file or (2) cd to dir\r
1293 //simulate an 'OK'\r
1294 set_filename(fileName);\r
1295 response(Gtk::RESPONSE_OK);\r
1296 }\r
1297 }\r
1298 \r
1299 \r
1300 \r
1301 /**\r
1302 * Callback for fileNameEntry widget\r
1303 */\r
1304 void FileExportDialogImpl::fileTypeChangedCallback()\r
1305 {\r
1306 int sel = fileTypeComboBox.get_active_row_number();\r
1307 if (sel<0 || sel >= (int)fileTypes.size())\r
1308 return;\r
1309 FileType type = fileTypes[sel];\r
1310 //g_message("selected: %s\n", type.name.c_str());\r
1311 Gtk::FileFilter filter;\r
1312 filter.add_pattern(type.pattern);\r
1313 set_filter(filter);\r
1314 }\r
1315 \r
1316 \r
1317 \r
1318 void FileExportDialogImpl::createFileTypeMenu()\r
1319 {\r
1320 Inkscape::Extension::DB::OutputList extension_list;\r
1321 Inkscape::Extension::db.get_output_list(extension_list);\r
1322 \r
1323 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();\r
1324 current_item != extension_list.end(); current_item++)\r
1325 {\r
1326 Inkscape::Extension::Output * omod = *current_item;\r
1327 \r
1328 // FIXME: would be nice to grey them out instead of not listing them\r
1329 if (omod->deactivated()) continue;\r
1330 \r
1331 FileType type;\r
1332 type.name = (_(omod->get_filetypename()));\r
1333 type.pattern = "*";\r
1334 Glib::ustring extension = omod->get_extension();\r
1335 fileDialogExtensionToPattern (type.pattern, extension);\r
1336 type.extension= omod;\r
1337 fileTypeComboBox.append_text(type.name);\r
1338 fileTypes.push_back(type);\r
1339 }\r
1340 \r
1341 //#Let user choose\r
1342 FileType guessType;\r
1343 guessType.name = _("Guess from extension");\r
1344 guessType.pattern = "*";\r
1345 guessType.extension = NULL;\r
1346 fileTypeComboBox.append_text(guessType.name);\r
1347 fileTypes.push_back(guessType);\r
1348 \r
1349 \r
1350 fileTypeComboBox.set_active(0);\r
1351 fileTypeChangedCallback(); //call at least once to set the filter\r
1352 }\r
1353 \r
1354 \r
1355 /**\r
1356 * Constructor\r
1357 */\r
1358 FileExportDialogImpl::FileExportDialogImpl(Gtk::Window& parentWindow,\r
1359 const Glib::ustring &dir,\r
1360 FileDialogType fileTypes,\r
1361 const Glib::ustring &title,\r
1362 const Glib::ustring &default_key) :\r
1363 FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),\r
1364 sourceX0Spinner("X0", _("Left edge of source")),\r
1365 sourceY0Spinner("Y0", _("Top edge of source")),\r
1366 sourceX1Spinner("X1", _("Right edge of source")),\r
1367 sourceY1Spinner("Y1", _("Bottom edge of source")),\r
1368 sourceWidthSpinner("Width", _("Source width")),\r
1369 sourceHeightSpinner("Height", _("Source height")),\r
1370 destWidthSpinner("Width", _("Destination width")),\r
1371 destHeightSpinner("Height", _("Destination height")),\r
1372 destDPISpinner("DPI", _("Resolution (dots per inch)"))\r
1373 {\r
1374 append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);\r
1375 \r
1376 /* One file at a time */\r
1377 set_select_multiple(false);\r
1378 \r
1379 #ifdef WITH_GNOME_VFS\r
1380 if (gnome_vfs_initialized()) {\r
1381 set_local_only(false);\r
1382 }\r
1383 #endif\r
1384 \r
1385 /* Initalize to Autodetect */\r
1386 extension = NULL;\r
1387 /* No filename to start out with */\r
1388 myFilename = "";\r
1389 \r
1390 /* Set our dialog type (save, export, etc...)*/\r
1391 dialogType = fileTypes;\r
1392 \r
1393 /* Set the pwd and/or the filename */\r
1394 if (dir.size()>0)\r
1395 {\r
1396 Glib::ustring udir(dir);\r
1397 Glib::ustring::size_type len = udir.length();\r
1398 // leaving a trailing backslash on the directory name leads to the infamous\r
1399 // double-directory bug on win32\r
1400 if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);\r
1401 set_current_folder(udir.c_str());\r
1402 }\r
1403 \r
1404 //#########################################\r
1405 //## EXTRA WIDGET -- SOURCE SIDE\r
1406 //#########################################\r
1407 \r
1408 //##### Export options buttons/spinners, etc\r
1409 documentButton.set_label(_("Document"));\r
1410 scopeBox.pack_start(documentButton);\r
1411 scopeGroup = documentButton.get_group();\r
1412 \r
1413 pageButton.set_label(_("Page"));\r
1414 pageButton.set_group(scopeGroup);\r
1415 scopeBox.pack_start(pageButton);\r
1416 \r
1417 selectionButton.set_label(_("Selection"));\r
1418 selectionButton.set_group(scopeGroup);\r
1419 scopeBox.pack_start(selectionButton);\r
1420 \r
1421 customButton.set_label(_("Custom"));\r
1422 customButton.set_group(scopeGroup);\r
1423 scopeBox.pack_start(customButton);\r
1424 \r
1425 sourceBox.pack_start(scopeBox);\r
1426 \r
1427 \r
1428 \r
1429 //dimension buttons\r
1430 sourceTable.resize(3,3);\r
1431 sourceTable.attach(sourceX0Spinner, 0,1,0,1);\r
1432 sourceTable.attach(sourceY0Spinner, 1,2,0,1);\r
1433 sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);\r
1434 sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);\r
1435 sourceTable.attach(sourceX1Spinner, 0,1,1,2);\r
1436 sourceTable.attach(sourceY1Spinner, 1,2,1,2);\r
1437 sourceTable.attach(sourceWidthSpinner, 0,1,2,3);\r
1438 sourceTable.attach(sourceHeightSpinner, 1,2,2,3);\r
1439 \r
1440 sourceBox.pack_start(sourceTable);\r
1441 sourceFrame.set_label(_("Source"));\r
1442 sourceFrame.add(sourceBox);\r
1443 exportOptionsBox.pack_start(sourceFrame);\r
1444 \r
1445 \r
1446 //#########################################\r
1447 //## EXTRA WIDGET -- SOURCE SIDE\r
1448 //#########################################\r
1449 \r
1450 \r
1451 destTable.resize(3,3);\r
1452 destTable.attach(destWidthSpinner, 0,1,0,1);\r
1453 destTable.attach(destHeightSpinner, 1,2,0,1);\r
1454 destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);\r
1455 destTable.attach(destUnitsSpinner, 2,3,0,1);\r
1456 destTable.attach(destDPISpinner, 0,1,1,2);\r
1457 \r
1458 destBox.pack_start(destTable);\r
1459 \r
1460 \r
1461 cairoButton.set_label(_("Cairo"));\r
1462 otherOptionBox.pack_start(cairoButton);\r
1463 \r
1464 antiAliasButton.set_label(_("Antialias"));\r
1465 otherOptionBox.pack_start(antiAliasButton);\r
1466 \r
1467 backgroundButton.set_label(_("Background"));\r
1468 otherOptionBox.pack_start(backgroundButton);\r
1469 \r
1470 destBox.pack_start(otherOptionBox);\r
1471 \r
1472 \r
1473 \r
1474 \r
1475 \r
1476 //###### File options\r
1477 //###### Do we want the .xxx extension automatically added?\r
1478 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));\r
1479 fileTypeCheckbox.set_active(append_extension);\r
1480 destBox.pack_start(fileTypeCheckbox);\r
1481 \r
1482 //###### File type menu\r
1483 createFileTypeMenu();\r
1484 fileTypeComboBox.set_size_request(200,40);\r
1485 fileTypeComboBox.signal_changed().connect(\r
1486 sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );\r
1487 \r
1488 destBox.pack_start(fileTypeComboBox);\r
1489 \r
1490 destFrame.set_label(_("Destination"));\r
1491 destFrame.add(destBox);\r
1492 exportOptionsBox.pack_start(destFrame);\r
1493 \r
1494 //##### Put the two boxes and their parent onto the dialog \r
1495 exportOptionsBox.pack_start(sourceFrame);\r
1496 exportOptionsBox.pack_start(destFrame);\r
1497 \r
1498 set_extra_widget(exportOptionsBox);\r
1499 \r
1500 \r
1501 \r
1502 \r
1503 //Let's do some customization\r
1504 fileNameEntry = NULL;\r
1505 Gtk::Container *cont = get_toplevel();\r
1506 std::vector<Gtk::Entry *> entries;\r
1507 findEntryWidgets(cont, entries);\r
1508 //g_message("Found %d entry widgets\n", entries.size());\r
1509 if (entries.size() >=1 )\r
1510 {\r
1511 //Catch when user hits [return] on the text field\r
1512 fileNameEntry = entries[0];\r
1513 fileNameEntry->signal_activate().connect(\r
1514 sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );\r
1515 }\r
1516 \r
1517 //Let's do more customization\r
1518 std::vector<Gtk::Expander *> expanders;\r
1519 findExpanderWidgets(cont, expanders);\r
1520 //g_message("Found %d expander widgets\n", expanders.size());\r
1521 if (expanders.size() >=1 )\r
1522 {\r
1523 //Always show the file list\r
1524 Gtk::Expander *expander = expanders[0];\r
1525 expander->set_expanded(true);\r
1526 }\r
1527 \r
1528 \r
1529 //if (extension == NULL)\r
1530 // checkbox.set_sensitive(FALSE);\r
1531 \r
1532 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
1533 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));\r
1534 \r
1535 show_all_children();\r
1536 }\r
1537 \r
1538 /**\r
1539 * Destructor\r
1540 */\r
1541 FileExportDialogImpl::~FileExportDialogImpl()\r
1542 {\r
1543 }\r
1544 \r
1545 \r
1546 \r
1547 /**\r
1548 * Show this dialog modally. Return true if user hits [OK]\r
1549 */\r
1550 bool\r
1551 FileExportDialogImpl::show()\r
1552 {\r
1553 Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());\r
1554 if (s.length() == 0) \r
1555 s = getcwd (NULL, 0);\r
1556 set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing\r
1557 set_modal (TRUE); //Window\r
1558 sp_transientize((GtkWidget *)gobj()); //Make transient\r
1559 gint b = run(); //Dialog\r
1560 svgPreview.showNoPreview();\r
1561 hide();\r
1562 \r
1563 if (b == Gtk::RESPONSE_OK)\r
1564 {\r
1565 int sel = fileTypeComboBox.get_active_row_number ();\r
1566 if (sel>=0 && sel< (int)fileTypes.size())\r
1567 {\r
1568 FileType &type = fileTypes[sel];\r
1569 extension = type.extension;\r
1570 }\r
1571 myFilename = get_filename();\r
1572 #ifdef WITH_GNOME_VFS\r
1573 if ( myFilename.empty() && gnome_vfs_initialized() ) {\r
1574 myFilename = get_uri();\r
1575 }\r
1576 #endif\r
1577 \r
1578 /*\r
1579 \r
1580 // FIXME: Why do we have more code\r
1581 \r
1582 append_extension = checkbox.get_active();\r
1583 prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);\r
1584 prefs_set_string_attribute("dialogs.save_as", "default",\r
1585 ( extension != NULL ? extension->get_id() : "" ));\r
1586 */\r
1587 return TRUE;\r
1588 }\r
1589 else\r
1590 {\r
1591 return FALSE;\r
1592 }\r
1593 }\r
1594 \r
1595 \r
1596 /**\r
1597 * Get the file extension type that was selected by the user. Valid after an [OK]\r
1598 */\r
1599 Inkscape::Extension::Extension *\r
1600 FileExportDialogImpl::getSelectionType()\r
1601 {\r
1602 return extension;\r
1603 }\r
1604 \r
1605 \r
1606 /**\r
1607 * Get the file name chosen by the user. Valid after an [OK]\r
1608 */\r
1609 Glib::ustring\r
1610 FileExportDialogImpl::getFilename()\r
1611 {\r
1612 return myFilename;\r
1613 }\r
1614 \r
1615 \r
1616 \r
1617 \r
1618 //########################################################################\r
1619 //# F I L E E X P O R T T O O C A L\r
1620 //########################################################################\r
1621 \r
1622 \r
1623 \r
1624 /**\r
1625 * Callback for fileNameEntry widget\r
1626 */\r
1627 void FileExportToOCALDialogImpl::fileNameEntryChangedCallback()\r
1628 {\r
1629 if (!fileNameEntry)\r
1630 return;\r
1631 \r
1632 Glib::ustring fileName = fileNameEntry->get_text();\r
1633 if (!Glib::get_charset()) //If we are not utf8\r
1634 fileName = Glib::filename_to_utf8(fileName);\r
1635 \r
1636 //g_message("User hit return. Text is '%s'\n", fileName.c_str());\r
1637 \r
1638 myFilename = fileName;\r
1639 response(Gtk::RESPONSE_OK);\r
1640 }\r
1641 \r
1642 \r
1643 \r
1644 /**\r
1645 * Callback for fileNameEntry widget\r
1646 */\r
1647 void FileExportToOCALDialogImpl::fileTypeChangedCallback()\r
1648 {\r
1649 int sel = fileTypeComboBox.get_active_row_number();\r
1650 if (sel<0 || sel >= (int)fileTypes.size())\r
1651 return;\r
1652 FileType type = fileTypes[sel];\r
1653 \r
1654 extension = type.extension;\r
1655 updateNameAndExtension();\r
1656 }\r
1657 \r
1658 \r
1659 \r
1660 void FileExportToOCALDialogImpl::createFileTypeMenu()\r
1661 {\r
1662 Inkscape::Extension::DB::OutputList extension_list;\r
1663 Inkscape::Extension::db.get_output_list(extension_list);\r
1664 knownExtensions.clear();\r
1665 \r
1666 for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();\r
1667 current_item != extension_list.end(); current_item++)\r
1668 {\r
1669 Inkscape::Extension::Output * omod = *current_item;\r
1670 \r
1671 // FIXME: would be nice to grey them out instead of not listing them\r
1672 if (omod->deactivated()) continue;\r
1673 \r
1674 FileType type;\r
1675 type.name = (_(omod->get_filetypename()));\r
1676 type.pattern = "*";\r
1677 Glib::ustring extension = omod->get_extension();\r
1678 knownExtensions.insert( extension.casefold() );\r
1679 fileDialogExtensionToPattern (type.pattern, extension);\r
1680 type.extension= omod;\r
1681 fileTypeComboBox.append_text(type.name);\r
1682 fileTypes.push_back(type);\r
1683 }\r
1684 \r
1685 //#Let user choose\r
1686 FileType guessType;\r
1687 guessType.name = _("Guess from extension");\r
1688 guessType.pattern = "*";\r
1689 guessType.extension = NULL;\r
1690 fileTypeComboBox.append_text(guessType.name);\r
1691 fileTypes.push_back(guessType);\r
1692 \r
1693 \r
1694 fileTypeComboBox.set_active(0);\r
1695 fileTypeChangedCallback(); //call at least once to set the filter\r
1696 }\r
1697 \r
1698 \r
1699 \r
1700 /**\r
1701 * Constructor\r
1702 */\r
1703 FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow,\r
1704 FileDialogType fileTypes,\r
1705 const Glib::ustring &title,\r
1706 const Glib::ustring &default_key) :\r
1707 FileDialogExportBase(title)\r
1708 {\r
1709 /*\r
1710 * Start Taking the vertical Box and putting a Label\r
1711 * and a Entry to take the filename\r
1712 * Later put the extension selection and checkbox (?)\r
1713 */\r
1714 /* Initalize to Autodetect */\r
1715 extension = NULL;\r
1716 /* No filename to start out with */\r
1717 myFilename = "";\r
1718 \r
1719 /* Set our dialog type (save, export, etc...)*/\r
1720 dialogType = fileTypes;\r
1721 Gtk::VBox *vbox = get_vbox();\r
1722 //Gtk::HBox fileBox;\r
1723 \r
1724 Gtk::Label *fileLabel = new Gtk::Label(_("File"));\r
1725 \r
1726 fileNameEntry = new Gtk::Entry();\r
1727 fileNameEntry->set_text(myFilename);\r
1728 fileNameEntry->set_max_length(252); // I am giving the extension approach.\r
1729 fileBox.pack_start(*fileLabel);\r
1730 fileBox.pack_start(*fileNameEntry, Gtk::PACK_EXPAND_WIDGET, 3);\r
1731 vbox->pack_start(fileBox);\r
1732 \r
1733 //###### Do we want the .xxx extension automatically added?\r
1734 fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));\r
1735 fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.export",\r
1736 "append_extension", 1) );\r
1737 \r
1738 createFileTypeMenu();\r
1739 \r
1740 fileTypeComboBox.set_size_request(200,40);\r
1741 fileTypeComboBox.signal_changed().connect(\r
1742 sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileTypeChangedCallback) );\r
1743 \r
1744 checksBox.pack_start( fileTypeCheckbox );\r
1745 vbox->pack_start( checksBox );\r
1746 \r
1747 vbox->pack_end( fileTypeComboBox );\r
1748 \r
1749 //Let's do some customization\r
1750 fileNameEntry = NULL;\r
1751 Gtk::Container *cont = get_toplevel();\r
1752 std::vector<Gtk::Entry *> entries;\r
1753 findEntryWidgets(cont, entries);\r
1754 //g_message("Found %d entry widgets\n", entries.size());\r
1755 if (entries.size() >=1 )\r
1756 {\r
1757 //Catch when user hits [return] on the text field\r
1758 fileNameEntry = entries[0];\r
1759 fileNameEntry->signal_activate().connect(\r
1760 sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileNameEntryChangedCallback) );\r
1761 }\r
1762 \r
1763 //Let's do more customization\r
1764 std::vector<Gtk::Expander *> expanders;\r
1765 findExpanderWidgets(cont, expanders);\r
1766 //g_message("Found %d expander widgets\n", expanders.size());\r
1767 if (expanders.size() >=1 )\r
1768 {\r
1769 //Always show the file list\r
1770 Gtk::Expander *expander = expanders[0];\r
1771 expander->set_expanded(true);\r
1772 }\r
1773 \r
1774 \r
1775 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
1776 set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));\r
1777 \r
1778 show_all_children();\r
1779 }\r
1780 \r
1781 \r
1782 \r
1783 /**\r
1784 * Destructor\r
1785 */\r
1786 FileExportToOCALDialogImpl::~FileExportToOCALDialogImpl()\r
1787 {\r
1788 }\r
1789 \r
1790 \r
1791 \r
1792 /**\r
1793 * Show this dialog modally. Return true if user hits [OK]\r
1794 */\r
1795 bool\r
1796 FileExportToOCALDialogImpl::show()\r
1797 {\r
1798 set_modal (TRUE); //Window\r
1799 sp_transientize((GtkWidget *)gobj()); //Make transient\r
1800 gint b = run(); //Dialog\r
1801 hide();\r
1802 \r
1803 if (b == Gtk::RESPONSE_OK)\r
1804 {\r
1805 updateNameAndExtension();\r
1806 \r
1807 return TRUE;\r
1808 }\r
1809 else\r
1810 {\r
1811 return FALSE;\r
1812 }\r
1813 }\r
1814 \r
1815 \r
1816 /**\r
1817 * Get the file extension type that was selected by the user. Valid after an [OK]\r
1818 */\r
1819 Inkscape::Extension::Extension *\r
1820 FileExportToOCALDialogImpl::getSelectionType()\r
1821 {\r
1822 return extension;\r
1823 }\r
1824 \r
1825 void FileExportToOCALDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )\r
1826 {\r
1827 // If no pointer to extension is passed in, look up based on filename extension.\r
1828 if ( !key ) {\r
1829 // Not quite UTF-8 here.\r
1830 gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);\r
1831 for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {\r
1832 Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);\r
1833 if ( ext && ext->get_extension() ) {\r
1834 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );\r
1835 if ( g_str_has_suffix(filenameLower, extensionLower) ) {\r
1836 key = fileTypes[i].extension;\r
1837 }\r
1838 g_free(extensionLower);\r
1839 }\r
1840 }\r
1841 g_free(filenameLower);\r
1842 }\r
1843 \r
1844 // Ensure the proper entry in the combo box is selected.\r
1845 if ( key ) {\r
1846 extension = key;\r
1847 gchar const * extensionID = extension->get_id();\r
1848 if ( extensionID ) {\r
1849 for ( int i = 0; i < (int)fileTypes.size(); i++ ) {\r
1850 Inkscape::Extension::Extension *ext = fileTypes[i].extension;\r
1851 if ( ext ) {\r
1852 gchar const * id = ext->get_id();\r
1853 if ( id && ( strcmp(extensionID, id) == 0) ) {\r
1854 int oldSel = fileTypeComboBox.get_active_row_number();\r
1855 if ( i != oldSel ) {\r
1856 fileTypeComboBox.set_active(i);\r
1857 }\r
1858 break;\r
1859 }\r
1860 }\r
1861 }\r
1862 }\r
1863 }\r
1864 }\r
1865 \r
1866 \r
1867 /**\r
1868 * Get the file name chosen by the user. Valid after an [OK]\r
1869 */\r
1870 Glib::ustring\r
1871 FileExportToOCALDialogImpl::getFilename()\r
1872 {\r
1873 myFilename = fileNameEntry->get_text();\r
1874 updateNameAndExtension();\r
1875 return myFilename;\r
1876 }\r
1877 \r
1878 \r
1879 void \r
1880 FileExportToOCALDialogImpl::change_title(const Glib::ustring& title)\r
1881 {\r
1882 this->set_title(title);\r
1883 }\r
1884 \r
1885 void FileExportToOCALDialogImpl::updateNameAndExtension()\r
1886 {\r
1887 // Pick up any changes the user has typed in.\r
1888 Glib::ustring tmp = myFilename; // get_filename();\r
1889 \r
1890 Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;\r
1891 if ( fileTypeCheckbox.get_active() && newOut ) {\r
1892 try {\r
1893 bool appendExtension = true;\r
1894 Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );\r
1895 Glib::ustring::size_type pos = utf8Name.rfind('.');\r
1896 if ( pos != Glib::ustring::npos ) {\r
1897 Glib::ustring trail = utf8Name.substr( pos );\r
1898 Glib::ustring foldedTrail = trail.casefold();\r
1899 if ( (trail == ".") \r
1900 | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()\r
1901 && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {\r
1902 utf8Name = utf8Name.erase( pos );\r
1903 } else {\r
1904 appendExtension = false;\r
1905 }\r
1906 }\r
1907 \r
1908 if (appendExtension) {\r
1909 utf8Name = utf8Name + newOut->get_extension();\r
1910 myFilename = Glib::filename_from_utf8( utf8Name );\r
1911 \r
1912 }\r
1913 } catch ( Glib::ConvertError& e ) {\r
1914 // ignore\r
1915 }\r
1916 }\r
1917 }\r
1918 \r
1919 \r
1920 } //namespace Dialog\r
1921 } //namespace UI\r
1922 } //namespace Inkscape\r
1923 \r
1924 /*\r
1925 Local Variables:\r
1926 mode:c++\r
1927 c-file-style:"stroustrup"\r
1928 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
1929 indent-tabs-mode:nil\r
1930 fill-column:99\r
1931 End:\r
1932 */\r
1933 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r