16383b4dade97733090cd3393fead5bc21cd59ed
1 #ifndef __FILE_DIALOGIMPL_H__
2 #define __FILE_DIALOGIMPL_H__
3 /**\r
4 * Implementation of the file dialog interfaces defined in filedialogimpl.h\r
5 *\r
6 * Authors:\r
7 * Bob Jamison\r
8 * Joel Holdsworth\r
9 * Bruno Dilly\r
10 * Other dudes from The Inkscape Organization\r
11 *\r
12 * Copyright (C) 2004-2007 Bob Jamison\r
13 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>\r
14 * Copyright (C) 2004-2007 The Inkscape Organization\r
15 * Copyright (C) 2007 Joel Holdsworth\r
16 *\r
17 * Released under GNU GPL, read the file 'COPYING' for more information\r
18 */\r
19 \r
20 #include "filedialog.h"\r
21 \r
22 //General includes\r
23 #include <unistd.h>\r
24 #include <sys/stat.h>\r
25 #include <errno.h>\r
26 #include <set>\r
27 #include <libxml/parser.h>\r
28 #include <libxml/tree.h>\r
29 \r
30 \r
31 //Gtk includes\r
32 #include <glibmm/i18n.h>\r
33 #include <glib/gstdio.h>\r
34 \r
35 //Temporary ugly hack\r
36 //Remove this after the get_filter() calls in\r
37 //show() on both classes are fixed\r
38 #include <gtk/gtkfilechooser.h>\r
39 \r
40 //Another hack\r
41 #include <gtk/gtkentry.h>\r
42 #include <gtk/gtkexpander.h>\r
43 #ifdef WITH_GNOME_VFS\r
44 # include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized\r
45 #endif\r
46 \r
47 //Inkscape includes\r
48 #include "prefs-utils.h"\r
49 #include <extension/input.h>\r
50 #include <extension/output.h>\r
51 #include <extension/db.h>\r
52 #include "inkscape.h"\r
53 #include "svg-view-widget.h"\r
54 #include "gc-core.h"\r
55 \r
56 //For export dialog\r
57 #include "ui/widget/scalar-unit.h"\r
58 \r
59 namespace Inkscape\r
60 {\r
61 namespace UI\r
62 {\r
63 namespace Dialog\r
64 {
66 /*#########################################################################\r
67 ### Utility\r
68 #########################################################################*/
69 void\r
70 fileDialogExtensionToPattern(Glib::ustring &pattern,\r
71 Glib::ustring &extension);
72 \r
73 void\r
74 findEntryWidgets(Gtk::Container *parent,\r
75 std::vector<Gtk::Entry *> &result);
77 void\r
78 findExpanderWidgets(Gtk::Container *parent,\r
79 std::vector<Gtk::Expander *> &result);\r
80 \r
81 /*#########################################################################\r
82 ### SVG Preview Widget\r
83 #########################################################################*/
85 class FileType\r
86 {\r
87 public:\r
88 FileType() {}\r
89 ~FileType() {}\r
90 Glib::ustring name;\r
91 Glib::ustring pattern;\r
92 Inkscape::Extension::Extension *extension;\r
93 };\r
94 \r
95 /**\r
96 * Simple class for displaying an SVG file in the "preview widget."\r
97 * Currently, this is just a wrapper of the sp_svg_view Gtk widget.\r
98 * Hopefully we will eventually replace with a pure Gtkmm widget.\r
99 */\r
100 class SVGPreview : public Gtk::VBox\r
101 {\r
102 public:\r
103 \r
104 SVGPreview();\r
105 \r
106 ~SVGPreview();\r
107 \r
108 bool setDocument(SPDocument *doc);\r
109 \r
110 bool setFileName(Glib::ustring &fileName);\r
111 \r
112 bool setFromMem(char const *xmlBuffer);\r
113 \r
114 bool set(Glib::ustring &fileName, int dialogType);\r
115 \r
116 bool setURI(URI &uri);\r
117 \r
118 /**\r
119 * Show image embedded in SVG\r
120 */\r
121 void showImage(Glib::ustring &fileName);\r
122 \r
123 /**\r
124 * Show the "No preview" image\r
125 */\r
126 void showNoPreview();\r
127 \r
128 /**\r
129 * Show the "Too large" image\r
130 */\r
131 void showTooLarge(long fileLength);\r
132 \r
133 private:\r
134 /**\r
135 * The svg document we are currently showing\r
136 */\r
137 SPDocument *document;\r
138 \r
139 /**\r
140 * The sp_svg_view widget\r
141 */\r
142 GtkWidget *viewerGtk;\r
143 \r
144 /**\r
145 * are we currently showing the "no preview" image?\r
146 */\r
147 bool showingNoPreview;\r
148 \r
149 };\r
150 \r
151 /*#########################################################################\r
152 ### F I L E D I A L O G B A S E C L A S S\r
153 #########################################################################*/\r
154 \r
155 /**\r
156 * This class is the base implementation for the others. This\r
157 * reduces redundancies and bugs.\r
158 */\r
159 class FileDialogBaseGtk : public Gtk::FileChooserDialog\r
160 {\r
161 public:\r
162 \r
163 /**\r
164 *\r
165 */\r
166 FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title,\r
167 FileDialogType type, gchar const* preferenceBase) :\r
168 Gtk::FileChooserDialog(parentWindow, title),\r
169 preferenceBase(preferenceBase ? preferenceBase : "unknown"),\r
170 dialogType(type)\r
171 {\r
172 internalSetup();\r
173 }\r
174 \r
175 /**\r
176 *\r
177 */\r
178 FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title,\r
179 Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :\r
180 Gtk::FileChooserDialog(parentWindow, title, dialogType),\r
181 preferenceBase(preferenceBase ? preferenceBase : "unknown"),\r
182 dialogType(type)\r
183 {\r
184 internalSetup();\r
185 }\r
186 \r
187 /**\r
188 *\r
189 */\r
190 virtual ~FileDialogBaseGtk()\r
191 {}\r
192 \r
193 protected:\r
194 void cleanup( bool showConfirmed );\r
195 \r
196 Glib::ustring preferenceBase;\r
197 /**\r
198 * What type of 'open' are we? (open, import, place, etc)\r
199 */\r
200 FileDialogType dialogType;\r
201 \r
202 /**\r
203 * Our svg preview widget\r
204 */\r
205 SVGPreview svgPreview;\r
206 \r
207 //# Child widgets\r
208 Gtk::CheckButton previewCheckbox;\r
209 \r
210 private:\r
211 void internalSetup();\r
212 \r
213 /**\r
214 * Callback for user changing preview checkbox\r
215 */\r
216 void _previewEnabledCB();\r
217 \r
218 /**\r
219 * Callback for seeing if the preview needs to be drawn\r
220 */\r
221 void _updatePreviewCallback();\r
222 };\r
223 \r
224 \r
225 \r
226 \r
227 /*#########################################################################\r
228 ### F I L E O P E N\r
229 #########################################################################*/\r
230 \r
231 /**\r
232 * Our implementation class for the FileOpenDialog interface..\r
233 */\r
234 class FileOpenDialogImplGtk : public FileOpenDialog, public FileDialogBaseGtk\r
235 {\r
236 public:\r
237 \r
238 FileOpenDialogImplGtk(Gtk::Window& parentWindow,\r
239 const Glib::ustring &dir,\r
240 FileDialogType fileTypes,\r
241 const Glib::ustring &title);\r
242 \r
243 virtual ~FileOpenDialogImplGtk();\r
244 \r
245 bool show();\r
246 \r
247 Inkscape::Extension::Extension *getSelectionType();\r
248 \r
249 Glib::ustring getFilename();\r
250 \r
251 std::vector<Glib::ustring> getFilenames ();\r
252 \r
253 private:\r
254 \r
255 /**\r
256 * Create a filter menu for this type of dialog\r
257 */\r
258 void createFilterMenu();\r
259 \r
260 /**\r
261 * Filter name->extension lookup\r
262 */\r
263 std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;\r
264 \r
265 /**\r
266 * The extension to use to write this file\r
267 */\r
268 Inkscape::Extension::Extension *extension;\r
269 \r
270 /**\r
271 * Filename that was given\r
272 */\r
273 Glib::ustring myFilename;\r
274 \r
275 };\r
276 \r
277 \r
278 \r
279 //########################################################################\r
280 //# F I L E S A V E\r
281 //########################################################################\r
282 \r
283 /**\r
284 * Our implementation of the FileSaveDialog interface.\r
285 */\r
286 class FileSaveDialogImplGtk : public FileSaveDialog, public FileDialogBaseGtk\r
287 {\r
288 \r
289 public:\r
290 FileSaveDialogImplGtk(Gtk::Window &parentWindow, \r
291 const Glib::ustring &dir,\r
292 FileDialogType fileTypes,\r
293 const Glib::ustring &title,\r
294 const Glib::ustring &default_key);\r
295 \r
296 virtual ~FileSaveDialogImplGtk();\r
297 \r
298 bool show();\r
299 \r
300 Inkscape::Extension::Extension *getSelectionType();\r
301 virtual void setSelectionType( Inkscape::Extension::Extension * key );\r
302 \r
303 Glib::ustring getFilename();\r
304 \r
305 void change_title(const Glib::ustring& title);\r
306 void change_path(const Glib::ustring& path);\r
307 void updateNameAndExtension();\r
308 \r
309 private:\r
310 \r
311 /**\r
312 * Fix to allow the user to type the file name\r
313 */\r
314 Gtk::Entry *fileNameEntry;\r
315 \r
316 \r
317 /**\r
318 * Allow the specification of the output file type\r
319 */\r
320 Gtk::ComboBoxText fileTypeComboBox;\r
321 \r
322 \r
323 /**\r
324 * Data mirror of the combo box\r
325 */\r
326 std::vector<FileType> fileTypes;\r
327 \r
328 //# Child widgets\r
329 Gtk::HBox childBox;\r
330 Gtk::VBox checksBox;\r
331 \r
332 Gtk::CheckButton fileTypeCheckbox;\r
333 \r
334 /**\r
335 * Callback for user input into fileNameEntry\r
336 */\r
337 void fileTypeChangedCallback();\r
338 \r
339 /**\r
340 * Create a filter menu for this type of dialog\r
341 */\r
342 void createFileTypeMenu();\r
343 \r
344 \r
345 /**\r
346 * The extension to use to write this file\r
347 */\r
348 Inkscape::Extension::Extension *extension;\r
349 \r
350 /**\r
351 * Callback for user input into fileNameEntry\r
352 */\r
353 void fileNameEntryChangedCallback();\r
354 \r
355 /**\r
356 * Filename that was given\r
357 */\r
358 Glib::ustring myFilename;\r
359 \r
360 /**\r
361 * List of known file extensions.\r
362 */\r
363 std::set<Glib::ustring> knownExtensions;\r
364 };\r
365 \r
366 \r
367 \r
368 \r
369 //########################################################################\r
370 //# F I L E E X P O R T\r
371 //########################################################################\r
372 \r
373 /**\r
374 * Our implementation of the FileExportDialog interface.\r
375 */\r
376 class FileExportDialogImpl : public FileExportDialog, public FileDialogBaseGtk\r
377 {\r
378 \r
379 public:\r
380 FileExportDialogImpl(Gtk::Window& parentWindow,\r
381 const Glib::ustring &dir,\r
382 FileDialogType fileTypes,\r
383 const Glib::ustring &title,\r
384 const Glib::ustring &default_key);\r
385 \r
386 virtual ~FileExportDialogImpl();\r
387 \r
388 bool show();\r
389 \r
390 Inkscape::Extension::Extension *getSelectionType();\r
391 \r
392 Glib::ustring getFilename();\r
393 \r
394 \r
395 /**\r
396 * Return the scope of the export. One of the enumerated types\r
397 * in ScopeType \r
398 */\r
399 ScopeType getScope()\r
400 { \r
401 if (pageButton.get_active())\r
402 return SCOPE_PAGE;\r
403 else if (selectionButton.get_active())\r
404 return SCOPE_SELECTION;\r
405 else if (customButton.get_active())\r
406 return SCOPE_CUSTOM;\r
407 else\r
408 return SCOPE_DOCUMENT;\r
409 \r
410 }\r
411 \r
412 /**\r
413 * Return left side of the exported region\r
414 */\r
415 double getSourceX()\r
416 { return sourceX0Spinner.getValue(); }\r
417 \r
418 /**\r
419 * Return the top of the exported region\r
420 */\r
421 double getSourceY()\r
422 { return sourceY1Spinner.getValue(); }\r
423 \r
424 /**\r
425 * Return the width of the exported region\r
426 */\r
427 double getSourceWidth()\r
428 { return sourceWidthSpinner.getValue(); }\r
429 \r
430 /**\r
431 * Return the height of the exported region\r
432 */\r
433 double getSourceHeight()\r
434 { return sourceHeightSpinner.getValue(); }\r
435 \r
436 /**\r
437 * Return the units of the coordinates of exported region\r
438 */\r
439 Glib::ustring getSourceUnits()\r
440 { return sourceUnitsSpinner.getUnitAbbr(); }\r
441 \r
442 /**\r
443 * Return the width of the destination document\r
444 */\r
445 double getDestinationWidth()\r
446 { return destWidthSpinner.getValue(); }\r
447 \r
448 /**\r
449 * Return the height of the destination document\r
450 */\r
451 double getDestinationHeight()\r
452 { return destHeightSpinner.getValue(); }\r
453 \r
454 /**\r
455 * Return the height of the exported region\r
456 */\r
457 Glib::ustring getDestinationUnits()\r
458 { return destUnitsSpinner.getUnitAbbr(); }\r
459 \r
460 /**\r
461 * Return the destination DPI image resulution, if bitmap\r
462 */\r
463 double getDestinationDPI()\r
464 { return destDPISpinner.getValue(); }\r
465 \r
466 /**\r
467 * Return whether we should use Cairo for rendering\r
468 */\r
469 bool getUseCairo()\r
470 { return cairoButton.get_active(); }\r
471 \r
472 /**\r
473 * Return whether we should use antialiasing\r
474 */\r
475 bool getUseAntialias()\r
476 { return antiAliasButton.get_active(); }\r
477 \r
478 /**\r
479 * Return the background color for exporting\r
480 */\r
481 unsigned long getBackground()\r
482 { return backgroundButton.get_color().get_pixel(); }\r
483 \r
484 private:\r
485 \r
486 /**\r
487 * Fix to allow the user to type the file name\r
488 */\r
489 Gtk::Entry *fileNameEntry;\r
490 \r
491 //##########################################\r
492 //# EXTRA WIDGET -- SOURCE SIDE\r
493 //##########################################\r
494 \r
495 Gtk::Frame sourceFrame;\r
496 Gtk::VBox sourceBox;\r
497 \r
498 Gtk::HBox scopeBox;\r
499 Gtk::RadioButtonGroup scopeGroup;\r
500 Gtk::RadioButton documentButton;\r
501 Gtk::RadioButton pageButton;\r
502 Gtk::RadioButton selectionButton;\r
503 Gtk::RadioButton customButton;\r
504 \r
505 Gtk::Table sourceTable;\r
506 Inkscape::UI::Widget::Scalar sourceX0Spinner;\r
507 Inkscape::UI::Widget::Scalar sourceY0Spinner;\r
508 Inkscape::UI::Widget::Scalar sourceX1Spinner;\r
509 Inkscape::UI::Widget::Scalar sourceY1Spinner;\r
510 Inkscape::UI::Widget::Scalar sourceWidthSpinner;\r
511 Inkscape::UI::Widget::Scalar sourceHeightSpinner;\r
512 Inkscape::UI::Widget::UnitMenu sourceUnitsSpinner;\r
513 \r
514 \r
515 //##########################################\r
516 //# EXTRA WIDGET -- DESTINATION SIDE\r
517 //##########################################\r
518 \r
519 Gtk::Frame destFrame;\r
520 Gtk::VBox destBox;\r
521 \r
522 Gtk::Table destTable;\r
523 Inkscape::UI::Widget::Scalar destWidthSpinner;\r
524 Inkscape::UI::Widget::Scalar destHeightSpinner;\r
525 Inkscape::UI::Widget::Scalar destDPISpinner;\r
526 Inkscape::UI::Widget::UnitMenu destUnitsSpinner;\r
527 \r
528 Gtk::HBox otherOptionBox;\r
529 Gtk::CheckButton cairoButton;\r
530 Gtk::CheckButton antiAliasButton;\r
531 Gtk::ColorButton backgroundButton;\r
532 \r
533 \r
534 /**\r
535 * 'Extra' widget that holds two boxes above\r
536 */\r
537 Gtk::HBox exportOptionsBox;\r
538 \r
539 \r
540 //# Child widgets\r
541 Gtk::CheckButton fileTypeCheckbox;\r
542 \r
543 /**\r
544 * Allow the specification of the output file type\r
545 */\r
546 Gtk::ComboBoxText fileTypeComboBox;\r
547 \r
548 \r
549 /**\r
550 * Data mirror of the combo box\r
551 */\r
552 std::vector<FileType> fileTypes;\r
553 \r
554 \r
555 \r
556 /**\r
557 * Callback for user input into fileNameEntry\r
558 */\r
559 void fileTypeChangedCallback();\r
560 \r
561 /**\r
562 * Create a filter menu for this type of dialog\r
563 */\r
564 void createFileTypeMenu();\r
565 \r
566 \r
567 bool append_extension;\r
568 \r
569 /**\r
570 * The extension to use to write this file\r
571 */\r
572 Inkscape::Extension::Extension *extension;\r
573 \r
574 /**\r
575 * Callback for user input into fileNameEntry\r
576 */\r
577 void fileNameEntryChangedCallback();\r
578 \r
579 /**\r
580 * Filename that was given\r
581 */\r
582 Glib::ustring myFilename;\r
583 };\r
584 \r
585 \r
587 }\r
588 }\r
589 }\r
590 \r
591 #endif /*__FILE_DIALOGIMPL_H__*/
593 /*\r
594 Local Variables:\r
595 mode:c++\r
596 c-file-style:"stroustrup"\r
597 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
598 indent-tabs-mode:nil\r
599 fill-column:99\r
600 End:\r
601 */\r
602 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r