Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[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 #include "extension/system.h"
26 class SPDocument;
28 namespace Inkscape {
29 namespace Extension {
30 class Extension;
31 class Output;
32 }
33 }
35 namespace Inkscape
36 {
37 namespace UI
38 {
39 namespace Dialog
40 {
42 /**
43  * Used for setting filters and options, and
44  * reading them back from user selections.
45  */
46 typedef enum {
47     SVG_TYPES,
48     IMPORT_TYPES,
49     EXPORT_TYPES
50     } FileDialogType;
52 /**
53  * Used for returning the type selected in a SaveAs
54  */
55 typedef enum {
56     SVG_NAMESPACE,
57     SVG_NAMESPACE_WITH_EXTENSIONS
58     } FileDialogSelectionType;
61 /**
62  * Return true if the string ends with the given suffix
63  */
64 bool hasSuffix(const Glib::ustring &str, const Glib::ustring &ext);
66 /**
67  * Return true if the image is loadable by Gdk, else false
68  */
69 bool isValidImageFile(const Glib::ustring &fileName);
71 /**
72  * This class provides an implementation-independent API for
73  * file "Open" dialogs.  Using a standard interface obviates the need
74  * for ugly #ifdefs in file open code
75  */
76 class FileOpenDialog
77 {
78 public:
81     /**
82      * Constructor ..  do not call directly
83      * @param path the directory where to start searching
84      * @param fileTypes one of FileDialogTypes
85      * @param title the title of the dialog
86      */
87     FileOpenDialog()
88         {};
90     /**
91      * Factory.
92      * @param path the directory where to start searching
93      * @param fileTypes one of FileDialogTypes
94      * @param title the title of the dialog
95      */
96     static FileOpenDialog *create(Gtk::Window& parentWindow,
97                                   const Glib::ustring &path,
98                                   FileDialogType fileTypes,
99                                   const char *title);
102     /**
103      * Destructor.
104      * Perform any necessary cleanups.
105      */
106     virtual ~FileOpenDialog() {};
108     /**
109      * Show an OpenFile file selector.
110      * @return the selected path if user selected one, else NULL
111      */
112     virtual bool show() = 0;
114     /**
115      * Return the 'key' (filetype) of the selection, if any
116      * @return a pointer to a string if successful (which must
117      * be later freed with g_free(), else NULL.
118      */
119     virtual Inkscape::Extension::Extension * getSelectionType() = 0;
121     Glib::ustring getFilename();
123     virtual std::vector<Glib::ustring> getFilenames() = 0;
125     virtual Glib::ustring getCurrentDirectory() = 0;
127 protected:
128     /**
129      * Filename that was given
130      */
131     Glib::ustring myFilename;
133 }; //FileOpenDialog
140 /**
141  * This class provides an implementation-independent API for
142  * file "Save" dialogs.
143  */
144 class FileSaveDialog
146 public:
148     /**
149      * Constructor.  Do not call directly .   Use the factory.
150      * @param path the directory where to start searching
151      * @param fileTypes one of FileDialogTypes
152      * @param title the title of the dialog
153      * @param key a list of file types from which the user can select
154      */
155     FileSaveDialog ()
156         {};
158     /**
159      * Factory.
160      * @param path the directory where to start searching
161      * @param fileTypes one of FileDialogTypes
162      * @param title the title of the dialog
163      * @param key a list of file types from which the user can select
164      */
165     static FileSaveDialog *create(Gtk::Window& parentWindow,
166                                   const Glib::ustring &path,
167                                   FileDialogType fileTypes,
168                                   const char *title,
169                                   const Glib::ustring &default_key,
170                                   const gchar *docTitle,
171                                   const Inkscape::Extension::FileSaveMethod save_method);
174     /**
175      * Destructor.
176      * Perform any necessary cleanups.
177      */
178     virtual ~FileSaveDialog() {};
181     /**
182      * Show an SaveAs file selector.
183      * @return the selected path if user selected one, else NULL
184      */
185     virtual bool show() =0;
187     /**
188      * Return the 'key' (filetype) of the selection, if any
189      * @return a pointer to a string if successful (which must
190      * be later freed with g_free(), else NULL.
191      */
192     virtual Inkscape::Extension::Extension * getSelectionType() = 0;
194     virtual void setSelectionType( Inkscape::Extension::Extension * key ) = 0;
196     /**
197      * Get the file name chosen by the user.   Valid after an [OK]
198      */
199     Glib::ustring getFilename ();
201     /**
202      * Get the document title chosen by the user.   Valid after an [OK]
203      */
204     Glib::ustring getDocTitle ();
206     virtual Glib::ustring getCurrentDirectory() = 0;
208 protected:
210     /**
211      * Filename that was given
212      */
213     Glib::ustring myFilename;
215     /**
216      * Doc Title that was given
217      */
218     Glib::ustring myDocTitle;
220     /**
221      * List of known file extensions.
222      */
223     std::set<Glib::ustring> knownExtensions;
226     void appendExtension(Glib::ustring& path, Inkscape::Extension::Output* outputExtension);
228 }; //FileSaveDialog
231 //#define NEW_EXPORT_DIALOG
233 #ifdef NEW_EXPORT_DIALOG
235 /**
236  * This class provides an implementation-independent API for
237  * file "Export" dialogs.  Saving as these types will not affect
238  * the original file.
239  */
240 class FileExportDialog
242 public:
244     typedef enum
245         {
246         SCOPE_DOCUMENT,
247         SCOPE_PAGE,
248         SCOPE_SELECTION,
249         SCOPE_CUSTOM
250         } ScopeType;
252     /**
253      * Constructor.  Do not call directly .   Use the factory.
254      * @param path the directory where to start searching
255      * @param fileTypes one of FileDialogTypes
256      * @param title the title of the dialog
257      * @param key a list of file types from which the user can select
258      */
259     FileExportDialog()
260         {}
262     /**
263      * Factory.
264      * @param path the directory where to start searching
265      * @param fileTypes one of FileDialogTypes
266      * @param title the title of the dialog
267      * @param key a list of file types from which the user can select
268      */
269     static FileExportDialog *create(Gtk::Window& parentWindow,
270                                     const Glib::ustring &path,
271                                     FileDialogType fileTypes,
272                                     const char *title,
273                                     const Glib::ustring &default_key);
276     /**
277      * Destructor.
278      * Perform any necessary cleanups.
279      */
280     virtual ~FileExportDialog () {};
283     /**
284      * Show an SaveAs file selector.
285      * @return the selected path if user selected one, else NULL
286      */
287     virtual bool show() =0;
289     /**
290      * Return the 'key' (filetype) of the selection, if any
291      * @return a pointer to a string if successful (which must
292      * be later freed with g_free(), else NULL.
293      */
294     virtual Inkscape::Extension::Extension * getSelectionType() = 0;
296     /**
297      * Return the selected filename, if any.  If not, return ""
298      */
299     virtual Glib::ustring getFilename () =0;
301     /**
302      * Return the scope of the export.  One of the enumerated types
303      * in ScopeType
304      */
305     virtual ScopeType getScope() = 0;
307     /**
308      * Return left side of the exported region
309      */
310     virtual double getSourceX() = 0;
312     /**
313      * Return the top of the exported region
314      */
315     virtual double getSourceY() = 0;
317     /**
318      * Return the width of the exported region
319      */
320     virtual double getSourceWidth() = 0;
322     /**
323      * Return the height of the exported region
324      */
325     virtual double getSourceHeight() = 0;
327     /**
328      * Return the units of the coordinates of exported region
329      */
330     virtual Glib::ustring getSourceUnits() = 0;
332     /**
333      * Return the width of the destination document
334      */
335     virtual double getDestinationWidth() = 0;
337     /**
338      * Return the height of the destination document
339      */
340     virtual double getDestinationHeight() = 0;
342     /**
343      * Return the height of the exported region
344      */
345     virtual Glib::ustring getDestinationUnits() = 0;
347     /**
348      * Return the destination DPI image resulution, if bitmap
349      */
350     virtual double getDestinationDPI() = 0;
352     /**
353      * Return whether we should use Cairo for rendering
354      */
355     virtual bool getUseCairo() = 0;
357     /**
358      * Return whether we should use antialiasing
359      */
360     virtual bool getUseAntialias() = 0;
362     /**
363      * Return the background color for exporting
364      */
365     virtual unsigned long getBackground() = 0;
369 }; //FileExportDialog
371 #endif // NEW_EXPORT_DIALOG
374 } //namespace Dialog
375 } //namespace UI
376 } //namespace Inkscape
378 #endif /* __FILE_DIALOG_H__ */
380 /*
381   Local Variables:
382   mode:c++
383   c-file-style:"stroustrup"
384   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
385   indent-tabs-mode:nil
386   fill-column:99
387   End:
388 */
389 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :