1 /** @file
2 * @brief Open Clip Art Library integration dialogs
3 */
4 /* Authors:
5 * Bruno Dilly <bruno.dilly@gmail.com>
6 * Inkscape Guys
7 *
8 * Copyright (C) 2007 Bruno Dilly <bruno.dilly@gmail.com>
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #ifndef __OCAL_DIALOG_H__
13 #define __OCAL_DIALOG_H__
15 #include <glibmm.h>
16 #include <vector>
17 #include <gtkmm.h>
18 #include "filedialogimpl-gtkmm.h"
20 //General includes
21 #include <unistd.h>
22 #include <sys/stat.h>
23 #include <errno.h>
24 #include <set>
25 #include <libxml/parser.h>
26 #include <libxml/tree.h>
29 //Gtk includes
30 #include <glibmm/i18n.h>
31 #include <glib/gstdio.h>
33 //Temporary ugly hack
34 //Remove this after the get_filter() calls in
35 //show() on both classes are fixed
36 #include <gtk/gtkfilechooser.h>
38 //Another hack
39 #include <gtk/gtkentry.h>
40 #include <gtk/gtkexpander.h>
41 #ifdef WITH_GNOME_VFS
42 #include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized
43 #include<libgnomevfs/gnome-vfs.h>
44 #endif
46 //Inkscape includes
47 #include <extension/input.h>
48 #include <extension/output.h>
49 #include <extension/db.h>
50 #include "inkscape.h"
51 #include "svg-view-widget.h"
52 #include "gc-core.h"
54 //For export dialog
55 #include "ui/widget/scalar-unit.h"
58 namespace Inkscape
59 {
60 namespace UI
61 {
62 namespace Dialog
63 {
65 /*#########################################################################
66 ### F I L E D I A L O G O C A L B A S E C L A S S
67 #########################################################################*/
69 /**
70 * This class is the base implementation for export to OCAL.
71 */
72 class FileDialogOCALBase : public Gtk::Dialog
73 {
74 public:
76 /**
77 * Constructor
78 */
79 FileDialogOCALBase(const Glib::ustring &title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true)
80 {}
82 /*
83 * Destructor
84 */
85 virtual ~FileDialogOCALBase()
86 {}
88 protected:
89 void cleanup( bool showConfirmed );
91 /**
92 * What type of 'open' are we? (open, import, place, etc)
93 */
94 FileDialogType dialogType;
95 };
100 //########################################################################
101 //# F I L E E X P O R T T O O C A L
102 //########################################################################
105 /**
106 * Our implementation of the FileExportToOCALDialog interface.
107 */
108 class FileExportToOCALDialog : public FileDialogOCALBase
109 {
111 public:
112 /**
113 * Constructor
114 * @param fileTypes one of FileDialogTypes
115 * @param title the title of the dialog
116 * @param key a list of file types from which the user can select
117 */
118 FileExportToOCALDialog(Gtk::Window& parentWindow,
119 FileDialogType fileTypes,
120 const Glib::ustring &title);
122 /**
123 * Destructor.
124 * Perform any necessary cleanups.
125 */
126 ~FileExportToOCALDialog();
128 /**
129 * Show an SaveAs file selector.
130 * @return the selected path if user selected one, else NULL
131 */
132 bool show();
134 Glib::ustring getFilename();
136 Glib::ustring myFilename;
138 /**
139 * Change the window title.
140 */
141 void change_title(const Glib::ustring& title);
143 private:
145 /**
146 * Fix to allow the user to type the file name
147 */
148 Gtk::Entry *fileNameEntry;
150 /**
151 * Data mirror of the combo box
152 */
153 std::vector<FileType> fileTypes;
155 // Child widgets
156 Gtk::HBox childBox;
157 Gtk::VBox checksBox;
158 Gtk::HBox fileBox;
160 /**
161 * The extension to use to write this file
162 */
163 Inkscape::Extension::Extension *extension;
165 /**
166 * Callback for user input into fileNameEntry
167 */
168 void fileNameEntryChangedCallback();
170 /**
171 * List of known file extensions.
172 */
173 std::set<Glib::ustring> knownExtensions;
175 }; //FileExportToOCAL
178 //########################################################################
179 //# F I L E E X P O R T T O O C A L P A S S W O R D
180 //########################################################################
183 /**
184 * Our implementation of the FileExportToOCALPasswordDialog interface.
185 */
186 class FileExportToOCALPasswordDialog : public FileDialogOCALBase
187 {
189 public:
190 /**
191 * Constructor
192 * @param title the title of the dialog
193 */
194 FileExportToOCALPasswordDialog(Gtk::Window& parentWindow,
195 const Glib::ustring &title);
197 /**
198 * Destructor.
199 * Perform any necessary cleanups.
200 */
201 ~FileExportToOCALPasswordDialog();
204 /**
205 * Show 2 entry to input username and password.
206 */
207 bool show();
209 Glib::ustring getUsername();
210 Glib::ustring getPassword();
212 /**
213 * Change the window title.
214 */
215 void change_title(const Glib::ustring& title);
217 Glib::ustring myUsername;
218 Glib::ustring myPassword;
220 private:
222 /**
223 * Fix to allow the user to type the file name
224 */
225 Gtk::Entry *usernameEntry;
226 Gtk::Entry *passwordEntry;
228 // Child widgets
229 Gtk::VBox entriesBox;
230 Gtk::HBox userBox;
231 Gtk::HBox passBox;
233 }; //FileExportToOCALPassword
237 //#########################################################################
238 //### F I L E I M P O R T F R O M O C A L
239 //#########################################################################
241 /**
242 * Our implementation class for filesListView
243 */
244 class FileListViewText : public Gtk::ListViewText
245 {
246 public:
247 FileListViewText(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton)
248 :ListViewText(columns_count)
249 {
250 myPreview = &filesPreview;
251 myLabel = &description;
252 myButton = &okButton;
253 }
254 Glib::ustring getFilename();
255 protected:
256 void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
257 void on_cursor_changed();
258 private:
259 Glib::ustring myFilename;
260 SVGPreview *myPreview;
261 Gtk::Label *myLabel;
262 Gtk::Button *myButton;
263 };
265 /**
266 * Our implementation class for the FileImportFromOCALDialog interface..
267 */
268 class FileImportFromOCALDialog : public FileDialogOCALBase
269 {
270 public:
271 /**
272 * Constructor
273 * @param path the directory where to start searching
274 * @param fileTypes one of FileDialogTypes
275 * @param title the title of the dialog
276 */
277 FileImportFromOCALDialog(Gtk::Window& parentWindow,
278 const Glib::ustring &dir,
279 FileDialogType fileTypes,
280 const Glib::ustring &title);
282 /**
283 * Destructor.
284 * Perform any necessary cleanups.
285 */
286 ~FileImportFromOCALDialog();
288 /**
289 * Show an OpenFile file selector.
290 * @return the selected path if user selected one, else NULL
291 */
292 bool show();
294 /**
295 * Return the 'key' (filetype) of the selection, if any
296 * @return a pointer to a string if successful (which must
297 * be later freed with g_free(), else NULL.
298 */
299 Inkscape::Extension::Extension *getSelectionType();
301 Glib::ustring getFilename();
303 private:
305 /**
306 * Allow the user to type the tag to be searched
307 */
308 Gtk::Entry *searchTagEntry;
309 FileListViewText *filesList;
310 SVGPreview *filesPreview;
311 Gtk::Label *notFoundLabel;
312 Gtk::Label *descriptionLabel;
313 Gtk::Button *searchButton;
314 Gtk::Button *okButton;
316 // Child widgets
317 Gtk::HBox tagBox;
318 Gtk::HBox filesBox;
319 Gtk::HBox messageBox;
320 Gtk::HBox descriptionBox;
321 Gtk::ScrolledWindow listScrolledWindow;
322 Glib::RefPtr<Gtk::TreeSelection> selection;
324 /**
325 * Callback for user input into searchTagEntry
326 */
327 void searchTagEntryChangedCallback();
330 /**
331 * Prints the names of the all the xml elements
332 * that are siblings or children of a given xml node
333 */
334 void print_xml_element_names(xmlNode * a_node);
336 /**
337 * The extension to use to write this file
338 */
339 Inkscape::Extension::Extension *extension;
341 }; //FileImportFromOCALDialog
344 } //namespace Dialog
345 } //namespace UI
346 } //namespace Inkscape
349 #endif /* __OCAL_DIALOG_H__ */
351 /*
352 Local Variables:
353 mode:c++
354 c-file-style:"stroustrup"
355 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
356 indent-tabs-mode:nil
357 fill-column:99
358 End:
359 */
360 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :