1 #ifndef __OCAL_DIALOG_H__
2 #define __OCAL_DIALOG_H__
3 /**
4 * Defines the FileExportToOCALDialog, FileImportFromOCALDialog and
5 * FileExportToOCALPasswordDialog and their supporting classes.
6 *
7 * Authors:
8 * Bruno Dilly <bruno.dilly@gmail.com>
9 * Inkscape Guys
10 *
11 * Copyright (C) 2007 Bruno Dilly <bruno.dilly@gmail.com>
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include <glibmm.h>
17 #include <vector>
18 #include <gtkmm.h>
19 #include "filedialogimpl-gtkmm.h"
21 //General includes
22 #include <unistd.h>
23 #include <sys/stat.h>
24 #include <errno.h>
25 #include <set>
26 #include <libxml/parser.h>
27 #include <libxml/tree.h>
30 //Gtk includes
31 #include <glibmm/i18n.h>
32 #include <glib/gstdio.h>
34 //Temporary ugly hack
35 //Remove this after the get_filter() calls in
36 //show() on both classes are fixed
37 #include <gtk/gtkfilechooser.h>
39 //Another hack
40 #include <gtk/gtkentry.h>
41 #include <gtk/gtkexpander.h>
42 #ifdef WITH_GNOME_VFS
43 #include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized
44 #include<libgnomevfs/gnome-vfs.h>
45 #endif
47 //Inkscape includes
48 #include "prefs-utils.h"
49 #include <extension/input.h>
50 #include <extension/output.h>
51 #include <extension/db.h>
52 #include "inkscape.h"
53 #include "svg-view-widget.h"
54 #include "gc-core.h"
56 //For export dialog
57 #include "ui/widget/scalar-unit.h"
60 namespace Inkscape
61 {
62 namespace UI
63 {
64 namespace Dialog
65 {
68 /**
69 * This class provides an implementation-independent API for
70 * file "ExportToOCAL" dialogs.
71 */
72 class FileExportToOCALDialog
73 {
74 public:
76 /**
77 * Constructor. Do not call directly . Use the factory.
78 * @param fileTypes one of FileDialogTypes
79 * @param title the title of the dialog
80 * @param key a list of file types from which the user can select
81 */
82 FileExportToOCALDialog ()
83 {};
85 /**
86 * Factory.
87 * @param fileTypes one of FileDialogTypes
88 * @param title the title of the dialog
89 * @param key a list of file types from which the user can select
90 */
91 static FileExportToOCALDialog *create(Gtk::Window& parentWindow,
92 FileDialogType fileTypes,
93 const Glib::ustring &title,
94 const Glib::ustring &default_key);
97 /**
98 * Destructor.
99 * Perform any necessary cleanups.
100 */
101 virtual ~FileExportToOCALDialog() {};
104 /**
105 * Show an SaveAs 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 virtual void setSelectionType( Inkscape::Extension::Extension * key ) = 0;
119 virtual Glib::ustring getFilename () =0;
121 /**
122 * Change the window title.
123 */
124 virtual void change_title(const Glib::ustring& title) =0;
127 }; //FileExportToOCAL
129 /**
130 * This class provides an implementation-independent API for
131 * file "ExportToOCALPassword" dialogs.
132 */
133 class FileExportToOCALPasswordDialog
134 {
135 public:
137 /**
138 * Constructor. Do not call directly . Use the factory.
139 * @param title the title of the dialog
140 */
141 FileExportToOCALPasswordDialog ()
142 {};
144 /**
145 * Factory.
146 * @param title the title of the dialog
147 */
148 static FileExportToOCALPasswordDialog *create(Gtk::Window& parentWindow,
149 const Glib::ustring &title);
152 /**
153 * Destructor.
154 * Perform any necessary cleanups.
155 */
156 virtual ~FileExportToOCALPasswordDialog() {};
159 /**
160 * Show 2 entry to input username and password.
161 */
162 virtual bool show() =0;
164 virtual Glib::ustring getUsername () =0;
165 virtual Glib::ustring getPassword () =0;
167 /**
168 * Change the window title.
169 */
170 virtual void change_title(const Glib::ustring& title) =0;
173 }; //FileExportToOCALPassword
177 /**
178 * This class provides an implementation-independent API for
179 * file "ImportFromOCAL" dialogs.
180 */
181 class FileImportFromOCALDialog
182 {
183 public:
186 /**
187 * Constructor .. do not call directly
188 * @param path the directory where to start searching
189 * @param fileTypes one of FileDialogTypes
190 * @param title the title of the dialog
191 */
192 FileImportFromOCALDialog()
193 {};
195 /**
196 * Factory.
197 * @param path the directory where to start searching
198 * @param fileTypes one of FileDialogTypes
199 * @param title the title of the dialog
200 */
201 static FileImportFromOCALDialog *create(Gtk::Window& parentWindow,
202 const Glib::ustring &path,
203 FileDialogType fileTypes,
204 const Glib::ustring &title);
207 /**
208 * Destructor.
209 * Perform any necessary cleanups.
210 */
211 virtual ~FileImportFromOCALDialog() {};
213 /**
214 * Show an OpenFile file selector.
215 * @return the selected path if user selected one, else NULL
216 */
217 virtual bool show() =0;
219 /**
220 * Return the 'key' (filetype) of the selection, if any
221 * @return a pointer to a string if successful (which must
222 * be later freed with g_free(), else NULL.
223 */
224 virtual Inkscape::Extension::Extension * getSelectionType() = 0;
226 virtual Glib::ustring getFilename () =0;
228 }; //FileImportFromOCALDialog
231 /*#########################################################################
232 ### F I L E D I A L O G O C A L B A S E C L A S S
233 #########################################################################*/
235 /**
236 * This class is the base implementation for export to OCAL.
237 */
238 class FileDialogOCALBase : public Gtk::Dialog
239 {
240 public:
242 /**
243 *
244 */
245 FileDialogOCALBase(const Glib::ustring &title) : Gtk::Dialog(title,true)
246 {}
247 /*
248 *
249 */
250 virtual ~FileDialogOCALBase()
251 {}
253 protected:
254 void cleanup( bool showConfirmed );
256 //Glib::ustring preferenceBase;
257 /**
258 * What type of 'open' are we? (open, import, place, etc)
259 */
260 FileDialogType dialogType;
261 };
266 //########################################################################
267 //# F I L E E X P O R T T O O C A L
268 //########################################################################
272 /**
273 * Our implementation of the FileExportToOCALDialog interface.
274 */
275 class FileExportToOCALDialogImpl : public FileExportToOCALDialog, public FileDialogOCALBase
276 {
278 public:
279 FileExportToOCALDialogImpl(Gtk::Window& parentWindow,
280 FileDialogType fileTypes,
281 const Glib::ustring &title,
282 const Glib::ustring &default_key);
284 virtual ~FileExportToOCALDialogImpl();
286 bool show();
288 Inkscape::Extension::Extension *getSelectionType();
289 virtual void setSelectionType( Inkscape::Extension::Extension * key );
291 Glib::ustring getFilename();
293 Glib::ustring myFilename;
295 void change_title(const Glib::ustring& title);
296 void updateNameAndExtension();
298 private:
300 /**
301 * Fix to allow the user to type the file name
302 */
303 Gtk::Entry *fileNameEntry;
306 /**
307 * Allow the specification of the output file type
308 */
309 Gtk::ComboBoxText fileTypeComboBox;
312 /**
313 * Data mirror of the combo box
314 */
315 std::vector<FileType> fileTypes;
317 // Child widgets
318 Gtk::HBox childBox;
319 Gtk::VBox checksBox;
320 Gtk::HBox fileBox;
322 Gtk::CheckButton fileTypeCheckbox;
324 /**
325 * Callback for user choose a fileType
326 */
327 void fileTypeChangedCallback();
329 /**
330 * Create a filter menu for this type of dialog
331 */
332 void createFileTypeMenu();
335 /**
336 * The extension to use to write this file
337 */
338 Inkscape::Extension::Extension *extension;
340 /**
341 * Callback for user input into fileNameEntry
342 */
343 void fileNameEntryChangedCallback();
345 /**
346 * List of known file extensions.
347 */
348 std::set<Glib::ustring> knownExtensions;
349 };
352 //########################################################################
353 //# F I L E E X P O R T T O O C A L P A S S W O R D
354 //########################################################################
357 /**
358 * Our implementation of the FileExportToOCALPasswordDialog interface.
359 */
360 class FileExportToOCALPasswordDialogImpl : public FileExportToOCALPasswordDialog, public FileDialogOCALBase
361 {
363 public:
364 FileExportToOCALPasswordDialogImpl(Gtk::Window& parentWindow,
365 const Glib::ustring &title);
367 virtual ~FileExportToOCALPasswordDialogImpl();
369 bool show();
371 Glib::ustring getUsername();
372 Glib::ustring getPassword();
374 Glib::ustring myUsername;
375 Glib::ustring myPassword;
377 void change_title(const Glib::ustring& title);
379 private:
381 /**
382 * Fix to allow the user to type the file name
383 */
384 Gtk::Entry *usernameEntry;
385 Gtk::Entry *passwordEntry;
387 // Child widgets
388 Gtk::VBox entriesBox;
389 Gtk::HBox userBox;
390 Gtk::HBox passBox;
392 };
397 //#########################################################################
398 //### F I L E I M P O R T F R O M O C A L
399 //#########################################################################
401 /**
402 * Our implementation class for filesListView
403 */
404 class FileListViewText : public Gtk::ListViewText
405 {
406 public:
407 FileListViewText(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description):ListViewText(columns_count)
408 {
409 myPreview = &filesPreview;
410 myLabel = &description;
411 }
412 Glib::ustring getFilename();
413 protected:
414 void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
415 private:
416 Glib::ustring myFilename;
417 SVGPreview *myPreview;
418 Gtk::Label *myLabel;
419 };
421 /**
422 * Our implementation class for the FileImportFromOCALDialog interface..
423 */
424 class FileImportFromOCALDialogImplGtk : public FileImportFromOCALDialog, public FileDialogOCALBase
425 {
426 public:
428 FileImportFromOCALDialogImplGtk(Gtk::Window& parentWindow,
429 const Glib::ustring &dir,
430 FileDialogType fileTypes,
431 const Glib::ustring &title);
433 virtual ~FileImportFromOCALDialogImplGtk();
435 bool show();
437 Inkscape::Extension::Extension *getSelectionType();
439 Glib::ustring getFilename();
441 private:
443 /**
444 * Allow the user to type the tag to be searched
445 */
446 Gtk::Entry *searchTagEntry;
447 FileListViewText *filesList;
448 SVGPreview *filesPreview;
449 Gtk::Label *notFoundLabel;
450 Gtk::Label *descriptionLabel;
451 Gtk::Button *searchButton;
453 // Child widgets
454 Gtk::HBox tagBox;
455 Gtk::HBox filesBox;
456 Gtk::HBox messageBox;
457 Gtk::HBox descriptionBox;
458 Gtk::ScrolledWindow listScrolledWindow;
459 Glib::RefPtr<Gtk::TreeSelection> selection;
461 /**
462 * Callback for user input into searchTagEntry
463 */
464 void searchTagEntryChangedCallback();
467 /**
468 * Prints the names of the all the xml elements
469 * that are siblings or children of a given xml node
470 */
471 void print_xml_element_names(xmlNode * a_node);
473 /**
474 * The extension to use to write this file
475 */
476 Inkscape::Extension::Extension *extension;
477 };
482 } //namespace Dialog
483 } //namespace UI
484 } //namespace Inkscape
487 #endif /* __OCAL_DIALOG_H__ */
489 /*
490 Local Variables:
491 mode:c++
492 c-file-style:"stroustrup"
493 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
494 indent-tabs-mode:nil
495 fill-column:99
496 End:
497 */
498 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :