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 {
67 /*#########################################################################
68 ### F I L E D I A L O G O C A L B A S E C L A S S
69 #########################################################################*/
71 /**
72 * This class is the base implementation for export to OCAL.
73 */
74 class FileDialogOCALBase : public Gtk::Dialog
75 {
76 public:
78 /**
79 * Constructor
80 */
81 FileDialogOCALBase(const Glib::ustring &title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true)
82 {}
84 /*
85 * Destructor
86 */
87 virtual ~FileDialogOCALBase()
88 {}
90 protected:
91 void cleanup( bool showConfirmed );
93 /**
94 * What type of 'open' are we? (open, import, place, etc)
95 */
96 FileDialogType dialogType;
97 };
102 //########################################################################
103 //# F I L E E X P O R T T O O C A L
104 //########################################################################
107 /**
108 * Our implementation of the FileExportToOCALDialog interface.
109 */
110 class FileExportToOCALDialog : public FileDialogOCALBase
111 {
113 public:
114 /**
115 * Constructor
116 * @param fileTypes one of FileDialogTypes
117 * @param title the title of the dialog
118 * @param key a list of file types from which the user can select
119 */
120 FileExportToOCALDialog(Gtk::Window& parentWindow,
121 FileDialogType fileTypes,
122 const Glib::ustring &title);
124 /**
125 * Destructor.
126 * Perform any necessary cleanups.
127 */
128 ~FileExportToOCALDialog();
130 /**
131 * Show an SaveAs file selector.
132 * @return the selected path if user selected one, else NULL
133 */
134 bool show();
136 Glib::ustring getFilename();
138 Glib::ustring myFilename;
140 /**
141 * Change the window title.
142 */
143 void change_title(const Glib::ustring& title);
145 private:
147 /**
148 * Fix to allow the user to type the file name
149 */
150 Gtk::Entry *fileNameEntry;
152 /**
153 * Data mirror of the combo box
154 */
155 std::vector<FileType> fileTypes;
157 // Child widgets
158 Gtk::HBox childBox;
159 Gtk::VBox checksBox;
160 Gtk::HBox fileBox;
162 /**
163 * The extension to use to write this file
164 */
165 Inkscape::Extension::Extension *extension;
167 /**
168 * Callback for user input into fileNameEntry
169 */
170 void fileNameEntryChangedCallback();
172 /**
173 * List of known file extensions.
174 */
175 std::set<Glib::ustring> knownExtensions;
177 }; //FileExportToOCAL
180 //########################################################################
181 //# F I L E E X P O R T T O O C A L P A S S W O R D
182 //########################################################################
185 /**
186 * Our implementation of the FileExportToOCALPasswordDialog interface.
187 */
188 class FileExportToOCALPasswordDialog : public FileDialogOCALBase
189 {
191 public:
192 /**
193 * Constructor
194 * @param title the title of the dialog
195 */
196 FileExportToOCALPasswordDialog(Gtk::Window& parentWindow,
197 const Glib::ustring &title);
199 /**
200 * Destructor.
201 * Perform any necessary cleanups.
202 */
203 ~FileExportToOCALPasswordDialog();
206 /**
207 * Show 2 entry to input username and password.
208 */
209 bool show();
211 Glib::ustring getUsername();
212 Glib::ustring getPassword();
214 /**
215 * Change the window title.
216 */
217 void change_title(const Glib::ustring& title);
219 Glib::ustring myUsername;
220 Glib::ustring myPassword;
222 private:
224 /**
225 * Fix to allow the user to type the file name
226 */
227 Gtk::Entry *usernameEntry;
228 Gtk::Entry *passwordEntry;
230 // Child widgets
231 Gtk::VBox entriesBox;
232 Gtk::HBox userBox;
233 Gtk::HBox passBox;
235 }; //FileExportToOCALPassword
239 //#########################################################################
240 //### F I L E I M P O R T F R O M O C A L
241 //#########################################################################
243 /**
244 * Our implementation class for filesListView
245 */
246 class FileListViewText : public Gtk::ListViewText
247 {
248 public:
249 FileListViewText(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton)
250 :ListViewText(columns_count)
251 {
252 myPreview = &filesPreview;
253 myLabel = &description;
254 myButton = &okButton;
255 }
256 Glib::ustring getFilename();
257 protected:
258 void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
259 void on_cursor_changed();
260 private:
261 Glib::ustring myFilename;
262 SVGPreview *myPreview;
263 Gtk::Label *myLabel;
264 Gtk::Button *myButton;
265 };
267 /**
268 * Our implementation class for the FileImportFromOCALDialog interface..
269 */
270 class FileImportFromOCALDialog : public FileDialogOCALBase
271 {
272 public:
273 /**
274 * Constructor
275 * @param path the directory where to start searching
276 * @param fileTypes one of FileDialogTypes
277 * @param title the title of the dialog
278 */
279 FileImportFromOCALDialog(Gtk::Window& parentWindow,
280 const Glib::ustring &dir,
281 FileDialogType fileTypes,
282 const Glib::ustring &title);
284 /**
285 * Destructor.
286 * Perform any necessary cleanups.
287 */
288 ~FileImportFromOCALDialog();
290 /**
291 * Show an OpenFile file selector.
292 * @return the selected path if user selected one, else NULL
293 */
294 bool show();
296 /**
297 * Return the 'key' (filetype) of the selection, if any
298 * @return a pointer to a string if successful (which must
299 * be later freed with g_free(), else NULL.
300 */
301 Inkscape::Extension::Extension *getSelectionType();
303 Glib::ustring getFilename();
305 private:
307 /**
308 * Allow the user to type the tag to be searched
309 */
310 Gtk::Entry *searchTagEntry;
311 FileListViewText *filesList;
312 SVGPreview *filesPreview;
313 Gtk::Label *notFoundLabel;
314 Gtk::Label *descriptionLabel;
315 Gtk::Button *searchButton;
316 Gtk::Button *okButton;
318 // Child widgets
319 Gtk::HBox tagBox;
320 Gtk::HBox filesBox;
321 Gtk::HBox messageBox;
322 Gtk::HBox descriptionBox;
323 Gtk::ScrolledWindow listScrolledWindow;
324 Glib::RefPtr<Gtk::TreeSelection> selection;
326 /**
327 * Callback for user input into searchTagEntry
328 */
329 void searchTagEntryChangedCallback();
332 /**
333 * Prints the names of the all the xml elements
334 * that are siblings or children of a given xml node
335 */
336 void print_xml_element_names(xmlNode * a_node);
338 /**
339 * The extension to use to write this file
340 */
341 Inkscape::Extension::Extension *extension;
343 }; //FileImportFromOCALDialog
346 } //namespace Dialog
347 } //namespace UI
348 } //namespace Inkscape
351 #endif /* __OCAL_DIALOG_H__ */
353 /*
354 Local Variables:
355 mode:c++
356 c-file-style:"stroustrup"
357 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
358 indent-tabs-mode:nil
359 fill-column:99
360 End:
361 */
362 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :