Code

From trunk
[inkscape.git] / src / ui / dialog / filedialog.h
1 /** @file
2  * @brief Virtual base definitions for native file dialogs
3  */
4 /* Authors:
5  *   Bob Jamison <rwjj@earthlink.net>
6  *   Joel Holdsworth
7  *   Inkscape Guys
8  *
9  * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
10  * Copyright (C) 2007-2008 Joel Holdsworth
11  * Copyright (C) 2004-2008, Inkscape Authors
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifndef __FILE_DIALOG_H__
17 #define __FILE_DIALOG_H__
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
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,
166                                   const gchar *docTitle);
169     /**
170      * Destructor.
171      * Perform any necessary cleanups.
172      */
173     virtual ~FileSaveDialog() {};
176     /**
177      * Show an SaveAs file selector.
178      * @return the selected path if user selected one, else NULL
179      */
180     virtual bool show() =0;
182     /**
183      * Return the 'key' (filetype) of the selection, if any
184      * @return a pointer to a string if successful (which must
185      * be later freed with g_free(), else NULL.
186      */
187     virtual Inkscape::Extension::Extension * getSelectionType() = 0;
189     virtual void setSelectionType( Inkscape::Extension::Extension * key ) = 0;
191     /**
192      * Get the file name chosen by the user.   Valid after an [OK]
193      */
194     Glib::ustring getFilename ();
196     /**
197      * Get the document title chosen by the user.   Valid after an [OK]
198      */
199     Glib::ustring getDocTitle ();
201     virtual Glib::ustring getCurrentDirectory() = 0;
203 protected:
205     /**
206      * Filename that was given
207      */
208     Glib::ustring myFilename;
210     /**
211      * Doc Title that was given
212      */
213     Glib::ustring myDocTitle;
215     /**
216      * List of known file extensions.
217      */
218     std::set<Glib::ustring> knownExtensions;
221     void appendExtension(Glib::ustring& path, Inkscape::Extension::Output* outputExtension);
223 }; //FileSaveDialog
228 /**
229  * This class provides an implementation-independent API for
230  * file "Export" dialogs.  Saving as these types will not affect
231  * the original file.
232  */
233 class FileExportDialog
235 public:
237     typedef enum
238         {
239         SCOPE_DOCUMENT,
240         SCOPE_PAGE,
241         SCOPE_SELECTION,
242         SCOPE_CUSTOM
243         } ScopeType;
245     /**
246      * Constructor.  Do not call directly .   Use the factory.
247      * @param path the directory where to start searching
248      * @param fileTypes one of FileDialogTypes
249      * @param title the title of the dialog
250      * @param key a list of file types from which the user can select
251      */
252     FileExportDialog()
253         {}
255     /**
256      * Factory.
257      * @param path the directory where to start searching
258      * @param fileTypes one of FileDialogTypes
259      * @param title the title of the dialog
260      * @param key a list of file types from which the user can select
261      */
262     static FileExportDialog *create(Gtk::Window& parentWindow,
263                                     const Glib::ustring &path,
264                                     FileDialogType fileTypes,
265                                     const char *title,
266                                     const Glib::ustring &default_key);
269     /**
270      * Destructor.
271      * Perform any necessary cleanups.
272      */
273     virtual ~FileExportDialog () {};
276     /**
277      * Show an SaveAs file selector.
278      * @return the selected path if user selected one, else NULL
279      */
280     virtual bool show() =0;
282     /**
283      * Return the 'key' (filetype) of the selection, if any
284      * @return a pointer to a string if successful (which must
285      * be later freed with g_free(), else NULL.
286      */
287     virtual Inkscape::Extension::Extension * getSelectionType() = 0;
289     /**
290      * Return the selected filename, if any.  If not, return ""
291      */
292     virtual Glib::ustring getFilename () =0;
294     /**
295      * Return the scope of the export.  One of the enumerated types
296      * in ScopeType
297      */
298     virtual ScopeType getScope() = 0;
300     /**
301      * Return left side of the exported region
302      */
303     virtual double getSourceX() = 0;
305     /**
306      * Return the top of the exported region
307      */
308     virtual double getSourceY() = 0;
310     /**
311      * Return the width of the exported region
312      */
313     virtual double getSourceWidth() = 0;
315     /**
316      * Return the height of the exported region
317      */
318     virtual double getSourceHeight() = 0;
320     /**
321      * Return the units of the coordinates of exported region
322      */
323     virtual Glib::ustring getSourceUnits() = 0;
325     /**
326      * Return the width of the destination document
327      */
328     virtual double getDestinationWidth() = 0;
330     /**
331      * Return the height of the destination document
332      */
333     virtual double getDestinationHeight() = 0;
335     /**
336      * Return the height of the exported region
337      */
338     virtual Glib::ustring getDestinationUnits() = 0;
340     /**
341      * Return the destination DPI image resulution, if bitmap
342      */
343     virtual double getDestinationDPI() = 0;
345     /**
346      * Return whether we should use Cairo for rendering
347      */
348     virtual bool getUseCairo() = 0;
350     /**
351      * Return whether we should use antialiasing
352      */
353     virtual bool getUseAntialias() = 0;
355     /**
356      * Return the background color for exporting
357      */
358     virtual unsigned long getBackground() = 0;
362 }; //FileExportDialog
365 } //namespace Dialog
366 } //namespace UI
367 } //namespace Inkscape
370 #endif /* __FILE_DIALOG_H__ */
372 /*
373   Local Variables:
374   mode:c++
375   c-file-style:"stroustrup"
376   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
377   indent-tabs-mode:nil
378   fill-column:99
379   End:
380 */
381 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :