1 #ifndef __FILE_DIALOG_H__
2 #define __FILE_DIALOG_H__
3 /**
4 * Defines the FileOpenDialog, FileSaveDialog, and FileExportDialog
5 * and their supporting classes.
6 *
7 * Authors:
8 * Bob Jamison <rwjj@earthlink.net>
9 * Joel Holdsworth
10 * Inkscape Guys
11 *
12 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
13 * Copyright (C) 2007-2008 Joel Holdsworth
14 * Copyright (C) 2004-2008, Inkscape Authors
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
19 #include <glibmm.h>
20 #include <vector>
21 #include <set>
22 #include <gtkmm.h>
24 namespace Inkscape {
25 namespace Extension {
26 class Extension;
27 class Output;
28 }
29 }
31 namespace Inkscape
32 {
33 namespace UI
34 {
35 namespace Dialog
36 {
38 /**
39 * Used for setting filters and options, and
40 * reading them back from user selections.
41 */
42 typedef enum {
43 SVG_TYPES,
44 IMPORT_TYPES,
45 EXPORT_TYPES
46 } FileDialogType;
48 /**
49 * Used for returning the type selected in a SaveAs
50 */
51 typedef enum {
52 SVG_NAMESPACE,
53 SVG_NAMESPACE_WITH_EXTENSIONS
54 } FileDialogSelectionType;
57 /**
58 * Return true if the string ends with the given suffix
59 */
60 bool hasSuffix(const Glib::ustring &str, const Glib::ustring &ext);
62 /**
63 * Return true if the image is loadable by Gdk, else false
64 */
65 bool isValidImageFile(const Glib::ustring &fileName);
67 /**
68 * This class provides an implementation-independent API for
69 * file "Open" dialogs. Using a standard interface obviates the need
70 * for ugly #ifdefs in file open code
71 */
72 class FileOpenDialog
73 {
74 public:
77 /**
78 * Constructor .. do not call directly
79 * @param path the directory where to start searching
80 * @param fileTypes one of FileDialogTypes
81 * @param title the title of the dialog
82 */
83 FileOpenDialog()
84 {};
86 /**
87 * Factory.
88 * @param path the directory where to start searching
89 * @param fileTypes one of FileDialogTypes
90 * @param title the title of the dialog
91 */
92 static FileOpenDialog *create(Gtk::Window& parentWindow,
93 const Glib::ustring &path,
94 FileDialogType fileTypes,
95 const char *title);
98 /**
99 * Destructor.
100 * Perform any necessary cleanups.
101 */
102 virtual ~FileOpenDialog() {};
104 /**
105 * Show an OpenFile file selector.
106 * @return the selected path if user selected one, else NULL
107 */
108 virtual bool show() = 0;
110 /**
111 * Return the 'key' (filetype) of the selection, if any
112 * @return a pointer to a string if successful (which must
113 * be later freed with g_free(), else NULL.
114 */
115 virtual Inkscape::Extension::Extension * getSelectionType() = 0;
117 Glib::ustring getFilename();
119 virtual std::vector<Glib::ustring> getFilenames() = 0;
121 virtual Glib::ustring getCurrentDirectory() = 0;
123 protected:
124 /**
125 * Filename that was given
126 */
127 Glib::ustring myFilename;
129 }; //FileOpenDialog
136 /**
137 * This class provides an implementation-independent API for
138 * file "Save" dialogs.
139 */
140 class FileSaveDialog
141 {
142 public:
144 /**
145 * Constructor. Do not call directly . Use the factory.
146 * @param path the directory where to start searching
147 * @param fileTypes one of FileDialogTypes
148 * @param title the title of the dialog
149 * @param key a list of file types from which the user can select
150 */
151 FileSaveDialog ()
152 {};
154 /**
155 * Factory.
156 * @param path the directory where to start searching
157 * @param fileTypes one of FileDialogTypes
158 * @param title the title of the dialog
159 * @param key a list of file types from which the user can select
160 */
161 static FileSaveDialog *create(Gtk::Window& parentWindow,
162 const Glib::ustring &path,
163 FileDialogType fileTypes,
164 const char *title,
165 const Glib::ustring &default_key);
168 /**
169 * Destructor.
170 * Perform any necessary cleanups.
171 */
172 virtual ~FileSaveDialog() {};
175 /**
176 * Show an SaveAs file selector.
177 * @return the selected path if user selected one, else NULL
178 */
179 virtual bool show() =0;
181 /**
182 * Return the 'key' (filetype) of the selection, if any
183 * @return a pointer to a string if successful (which must
184 * be later freed with g_free(), else NULL.
185 */
186 virtual Inkscape::Extension::Extension * getSelectionType() = 0;
188 virtual void setSelectionType( Inkscape::Extension::Extension * key ) = 0;
190 /**
191 * Get the file name chosen by the user. Valid after an [OK]
192 */
193 Glib::ustring getFilename ();
195 virtual Glib::ustring getCurrentDirectory() = 0;
197 protected:
199 /**
200 * Filename that was given
201 */
202 Glib::ustring myFilename;
204 /**
205 * List of known file extensions.
206 */
207 std::set<Glib::ustring> knownExtensions;
210 void appendExtension(Glib::ustring& path, Inkscape::Extension::Output* outputExtension);
212 }; //FileSaveDialog
217 /**
218 * This class provides an implementation-independent API for
219 * file "Export" dialogs. Saving as these types will not affect
220 * the original file.
221 */
222 class FileExportDialog
223 {
224 public:
226 typedef enum
227 {
228 SCOPE_DOCUMENT,
229 SCOPE_PAGE,
230 SCOPE_SELECTION,
231 SCOPE_CUSTOM
232 } ScopeType;
234 /**
235 * Constructor. Do not call directly . Use the factory.
236 * @param path the directory where to start searching
237 * @param fileTypes one of FileDialogTypes
238 * @param title the title of the dialog
239 * @param key a list of file types from which the user can select
240 */
241 FileExportDialog()
242 {}
244 /**
245 * Factory.
246 * @param path the directory where to start searching
247 * @param fileTypes one of FileDialogTypes
248 * @param title the title of the dialog
249 * @param key a list of file types from which the user can select
250 */
251 static FileExportDialog *create(Gtk::Window& parentWindow,
252 const Glib::ustring &path,
253 FileDialogType fileTypes,
254 const char *title,
255 const Glib::ustring &default_key);
258 /**
259 * Destructor.
260 * Perform any necessary cleanups.
261 */
262 virtual ~FileExportDialog () {};
265 /**
266 * Show an SaveAs file selector.
267 * @return the selected path if user selected one, else NULL
268 */
269 virtual bool show() =0;
271 /**
272 * Return the 'key' (filetype) of the selection, if any
273 * @return a pointer to a string if successful (which must
274 * be later freed with g_free(), else NULL.
275 */
276 virtual Inkscape::Extension::Extension * getSelectionType() = 0;
278 /**
279 * Return the selected filename, if any. If not, return ""
280 */
281 virtual Glib::ustring getFilename () =0;
283 /**
284 * Return the scope of the export. One of the enumerated types
285 * in ScopeType
286 */
287 virtual ScopeType getScope() = 0;
289 /**
290 * Return left side of the exported region
291 */
292 virtual double getSourceX() = 0;
294 /**
295 * Return the top of the exported region
296 */
297 virtual double getSourceY() = 0;
299 /**
300 * Return the width of the exported region
301 */
302 virtual double getSourceWidth() = 0;
304 /**
305 * Return the height of the exported region
306 */
307 virtual double getSourceHeight() = 0;
309 /**
310 * Return the units of the coordinates of exported region
311 */
312 virtual Glib::ustring getSourceUnits() = 0;
314 /**
315 * Return the width of the destination document
316 */
317 virtual double getDestinationWidth() = 0;
319 /**
320 * Return the height of the destination document
321 */
322 virtual double getDestinationHeight() = 0;
324 /**
325 * Return the height of the exported region
326 */
327 virtual Glib::ustring getDestinationUnits() = 0;
329 /**
330 * Return the destination DPI image resulution, if bitmap
331 */
332 virtual double getDestinationDPI() = 0;
334 /**
335 * Return whether we should use Cairo for rendering
336 */
337 virtual bool getUseCairo() = 0;
339 /**
340 * Return whether we should use antialiasing
341 */
342 virtual bool getUseAntialias() = 0;
344 /**
345 * Return the background color for exporting
346 */
347 virtual unsigned long getBackground() = 0;
351 }; //FileExportDialog
354 } //namespace Dialog
355 } //namespace UI
356 } //namespace Inkscape
359 #endif /* __FILE_DIALOG_H__ */
361 /*
362 Local Variables:
363 mode:c++
364 c-file-style:"stroustrup"
365 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
366 indent-tabs-mode:nil
367 fill-column:99
368 End:
369 */
370 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :