Code

fixing the ocal dialogs bug
[inkscape.git] / src / ui / dialog / ocaldialogs.cpp
1 /**
2  * Implementation of the ocal dialog interfaces defined in ocaldialog.h
3  *
4  * Authors:
5  *   Bruno Dilly
6  *   Other dudes from The Inkscape Organization
7  *
8  * Copyright (C) 2007 Bruno Dilly <bruno.dilly@gmail.com>
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
17 #include "ocaldialogs.h"
18 #include "filedialogimpl-gtkmm.h"
19 #include "interface.h"
20 #include "gc-core.h"
21 #include <dialogs/dialog-events.h>
23 namespace Inkscape
24 {
25 namespace UI
26 {
27 namespace Dialog
28 {
30 //########################################################################
31 //# F I L E    E X P O R T   T O   O C A L
32 //########################################################################
35 /**
36  * Public factory method.  Used in file.cpp
37  */
39  FileExportToOCALDialog *FileExportToOCALDialog::create(Gtk::Window& parentWindow, 
40                                            FileDialogType fileTypes,
41                                            const Glib::ustring &title,
42                                            const Glib::ustring &default_key)
43 {
44     FileExportToOCALDialog *dialog = new FileExportToOCALDialogImpl(parentWindow, fileTypes, title, default_key);
45     return dialog;
46 }
48 //########################################################################
49 //# F I L E    E X P O R T   T O   O C A L   P A S S W O R D
50 //########################################################################
53 /**
54  * Public factory method.  Used in file.cpp
55  */
57 FileExportToOCALPasswordDialog *FileExportToOCALPasswordDialog::create(Gtk::Window& parentWindow,
58                                                         const Glib::ustring &title)
59 {
60     FileExportToOCALPasswordDialog *dialog = new FileExportToOCALPasswordDialogImpl(parentWindow, title);
61     return dialog;
62 }
65 //#########################################################################
66 //### F I L E    I M P O R T  F R O M  O C A L
67 //#########################################################################
69 /**
70  * Public factory.  Called by file.cpp.
71  */
72 FileImportFromOCALDialog *FileImportFromOCALDialog::create(Gtk::Window &parentWindow,
73                                        const Glib::ustring &path,
74                                        FileDialogType fileTypes,
75                                        const Glib::ustring &title)
76 {
77     FileImportFromOCALDialog *dialog = new FileImportFromOCALDialogImplGtk(parentWindow, path, fileTypes, title);
78     return dialog;
79 }
82 //########################################################################
83 //# F I L E    E X P O R T   T O   O C A L
84 //########################################################################
88 /**
89  * Callback for fileNameEntry widget
90  */
91 void FileExportToOCALDialogImpl::fileNameEntryChangedCallback()
92 {
93     if (!fileNameEntry)
94         return;
96     Glib::ustring fileName = fileNameEntry->get_text();
97     if (!Glib::get_charset()) //If we are not utf8
98         fileName = Glib::filename_to_utf8(fileName);
100     myFilename = fileName;
101     response(Gtk::RESPONSE_OK);
106 /**
107  * Callback for fileNameEntry widget
108  */
109 void FileExportToOCALDialogImpl::fileTypeChangedCallback()
111     int sel = fileTypeComboBox.get_active_row_number();
112     if (sel<0 || sel >= (int)fileTypes.size())
113         return;
114     FileType type = fileTypes[sel];
116     extension = type.extension;
117     updateNameAndExtension();
122 void FileExportToOCALDialogImpl::createFileTypeMenu()
124     Inkscape::Extension::DB::OutputList extension_list;
125     Inkscape::Extension::db.get_output_list(extension_list);
126     knownExtensions.clear();
128     for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
129          current_item != extension_list.end(); current_item++)
130     {
131         Inkscape::Extension::Output * omod = *current_item;
133         // FIXME: would be nice to grey them out instead of not listing them
134         if (omod->deactivated()) continue;
136         FileType type;
137         type.name     = (_(omod->get_filetypename()));
138         type.pattern  = "*";
139         Glib::ustring extension = omod->get_extension();
140         knownExtensions.insert( extension.casefold() );
141         fileDialogExtensionToPattern (type.pattern, extension);
142         type.extension= omod;
143         fileTypeComboBox.append_text(type.name);
144         fileTypes.push_back(type);
145     }
147     //#Let user choose
148     FileType guessType;
149     guessType.name = _("Guess from extension");
150     guessType.pattern = "*";
151     guessType.extension = NULL;
152     fileTypeComboBox.append_text(guessType.name);
153     fileTypes.push_back(guessType);
156     fileTypeComboBox.set_active(0);
157     fileTypeChangedCallback(); //call at least once to set the filter
162 /**
163  * Constructor
164  */
165 FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow,
166             FileDialogType fileTypes,
167             const Glib::ustring &title,
168             const Glib::ustring &default_key) :
169     FileDialogOCALBase(title)
171     /*
172      * Start Taking the vertical Box and putting a Label
173      * and a Entry to take the filename
174      * Later put the extension selection and checkbox (?)
175      */
176     /* Initalize to Autodetect */
177     extension = NULL;
178     /* No filename to start out with */
179     myFilename = "";
181     /* Set our dialog type (save, export, etc...)*/
182     dialogType = fileTypes;
183     Gtk::VBox *vbox = get_vbox();
185     Gtk::Label *fileLabel = new Gtk::Label(_("File"));
187     fileNameEntry = new Gtk::Entry();
188     fileNameEntry->set_text(myFilename);
189     fileNameEntry->set_max_length(252); // I am giving the extension approach.
190     fileBox.pack_start(*fileLabel);
191     fileBox.pack_start(*fileNameEntry, Gtk::PACK_EXPAND_WIDGET, 3);
192     vbox->pack_start(fileBox);
194     //###### Do we want the .xxx extension automatically added?
195     fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
196     fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.export",
197                                                                "append_extension", 1) );
199     createFileTypeMenu();
201     fileTypeComboBox.set_size_request(200,40);
202     fileTypeComboBox.signal_changed().connect(
203         sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileTypeChangedCallback) );
205     checksBox.pack_start( fileTypeCheckbox );
206     vbox->pack_start( checksBox );
208     vbox->pack_end( fileTypeComboBox );
210     //Let's do some customization
211     fileNameEntry = NULL;
212     Gtk::Container *cont = get_toplevel();
213     std::vector<Gtk::Entry *> entries;
214     findEntryWidgets(cont, entries);
215     //g_message("Found %d entry widgets\n", entries.size());
216     if (entries.size() >=1 )
217         {
218         //Catch when user hits [return] on the text field
219         fileNameEntry = entries[0];
220         fileNameEntry->signal_activate().connect(
221              sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileNameEntryChangedCallback) );
222         }
224     //Let's do more customization
225     std::vector<Gtk::Expander *> expanders;
226     findExpanderWidgets(cont, expanders);
227     //g_message("Found %d expander widgets\n", expanders.size());
228     if (expanders.size() >=1 )
229         {
230         //Always show the file list
231         Gtk::Expander *expander = expanders[0];
232         expander->set_expanded(true);
233         }
236     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
237     set_default(*add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_OK));
239     show_all_children();
244 /**
245  * Destructor
246  */
247 FileExportToOCALDialogImpl::~FileExportToOCALDialogImpl()
253 /**
254  * Show this dialog modally.  Return true if user hits [OK]
255  */
256 bool
257 FileExportToOCALDialogImpl::show()
259     set_modal (TRUE);                      //Window
260     sp_transientize((GtkWidget *)gobj());  //Make transient
261     gint b = run();                        //Dialog
262     hide();
264     if (b == Gtk::RESPONSE_OK)
265     {
266         updateNameAndExtension();
268         return TRUE;
269         }
270     else
271         {
272         return FALSE;
273         }
277 /**
278  * Get the file extension type that was selected by the user. Valid after an [OK]
279  */
280 Inkscape::Extension::Extension *
281 FileExportToOCALDialogImpl::getSelectionType()
283     return extension;
286 void FileExportToOCALDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
288     // If no pointer to extension is passed in, look up based on filename extension.
289     if ( !key ) {
290         // Not quite UTF-8 here.
291         gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
292         for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
293             Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
294             if ( ext && ext->get_extension() ) {
295                 gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
296                 if ( g_str_has_suffix(filenameLower, extensionLower) ) {
297                     key = fileTypes[i].extension;
298                 }
299                 g_free(extensionLower);
300             }
301         }
302         g_free(filenameLower);
303     }
305     // Ensure the proper entry in the combo box is selected.
306     if ( key ) {
307         extension = key;
308         gchar const * extensionID = extension->get_id();
309         if ( extensionID ) {
310             for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
311                 Inkscape::Extension::Extension *ext = fileTypes[i].extension;
312                 if ( ext ) {
313                     gchar const * id = ext->get_id();
314                     if ( id && ( strcmp(extensionID, id) == 0) ) {
315                         int oldSel = fileTypeComboBox.get_active_row_number();
316                         if ( i != oldSel ) {
317                             fileTypeComboBox.set_active(i);
318                         }
319                         break;
320                     }
321                 }
322             }
323         }
324     }
328 /**
329  * Get the file name chosen by the user.   Valid after an [OK]
330  */
331 Glib::ustring
332 FileExportToOCALDialogImpl::getFilename()
334     myFilename = fileNameEntry->get_text();
335     updateNameAndExtension();
336     return myFilename;
340 void
341 FileExportToOCALDialogImpl::change_title(const Glib::ustring& title)
343     this->set_title(title);
346 void FileExportToOCALDialogImpl::updateNameAndExtension()
348     // Pick up any changes the user has typed in.
349     Glib::ustring tmp = myFilename;   // get_filename();
351     Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
352     if ( fileTypeCheckbox.get_active() && newOut ) {
353         try {
354             bool appendExtension = true;
355             Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
356             Glib::ustring::size_type pos = utf8Name.rfind('.');
357             if ( pos != Glib::ustring::npos ) {
358                 Glib::ustring trail = utf8Name.substr( pos );
359                 Glib::ustring foldedTrail = trail.casefold();
360                 if ( (trail == ".")
361                      | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()
362                         && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {
363                     utf8Name = utf8Name.erase( pos );
364                 } else {
365                     appendExtension = false;
366                 }
367             }
369             if (appendExtension) {
370                 utf8Name = utf8Name + newOut->get_extension();
371                 myFilename = Glib::filename_from_utf8( utf8Name );
373             }
374         } catch ( Glib::ConvertError& e ) {
375             // ignore
376         }
377     }
381 //########################################################################
382 //# F I L E    E X P O R T   T O   O C A L   P A S S W O R D
383 //########################################################################
386 /**
387  * Constructor
388  */
389 FileExportToOCALPasswordDialogImpl::FileExportToOCALPasswordDialogImpl(Gtk::Window &parentWindow,
390                              const Glib::ustring &title) : FileDialogOCALBase(title)
392     /*
393      * Start Taking the vertical Box and putting 2 Labels
394      * and 2 Entries to take the username and password
395      */
396     /* No username and password to start out with */
397     myUsername = "";
398     myPassword = "";
400     Gtk::VBox *vbox = get_vbox();
402     Gtk::Label *userLabel = new Gtk::Label(_("Username:"));
403     Gtk::Label *passLabel = new Gtk::Label(_("Password:"));
405     usernameEntry = new Gtk::Entry();
406     usernameEntry->set_text(myUsername);
407     usernameEntry->set_max_length(255);
408     //usernameEntry->set_alignment(1);
410     passwordEntry = new Gtk::Entry();
411     passwordEntry->set_text(myPassword);
412     passwordEntry->set_max_length(255);
413     passwordEntry->set_invisible_char('*');
414     passwordEntry->set_visibility(false);
415     //passwordEntry->set_alignment(1);
416     passwordEntry->set_activates_default(true);
418     userBox.pack_start(*userLabel);
419     userBox.pack_start(*usernameEntry, Gtk::PACK_EXPAND_WIDGET, 3);
420     vbox->pack_start(userBox);
422     passBox.pack_start(*passLabel);
423     passBox.pack_start(*passwordEntry, Gtk::PACK_EXPAND_WIDGET, 3);
424     vbox->pack_start(passBox);
425     
426     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
427     set_default(*add_button(Gtk::Stock::OK,   Gtk::RESPONSE_OK));
429     show_all_children();
433 /**
434  * Destructor
435  */
436 FileExportToOCALPasswordDialogImpl::~FileExportToOCALPasswordDialogImpl()
440 /**
441  * Show this dialog modally.  Return true if user hits [OK]
442  */
443 bool
444 FileExportToOCALPasswordDialogImpl::show()
446     set_modal (TRUE);                      //Window
447     sp_transientize((GtkWidget *)gobj());  //Make transient
448     gint b = run();                        //Dialog
449     hide();
451     if (b == Gtk::RESPONSE_OK)
452     {
453         return TRUE;
454     }
455     else
456     {
457         return FALSE;
458     }
461 /**
462  * Get the username.   Valid after an [OK]
463  */
464 Glib::ustring
465 FileExportToOCALPasswordDialogImpl::getUsername()
467     myUsername = usernameEntry->get_text();
468     return myUsername;
471 /**
472  * Get the password.   Valid after an [OK]
473  */
474 Glib::ustring
475 FileExportToOCALPasswordDialogImpl::getPassword()
477     myPassword = passwordEntry->get_text();
478     return myPassword;
481 void
482 FileExportToOCALPasswordDialogImpl::change_title(const Glib::ustring& title)
484     this->set_title(title);
488 //#########################################################################
489 //### F I L E   I M P O R T   F R O M   O C A L
490 //#########################################################################
492 /*
493  * Callback for row activated
494  */
495 void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column)
497     // create file path
498     myFilename = Glib::get_tmp_dir();
499     myFilename.append(G_DIR_SEPARATOR_S);
500     std::vector<int> posArray(1);
501     posArray = path.get_indices();
502     myFilename.append(get_text(posArray[0], 2));
503     
504 #ifdef WITH_GNOME_VFS
505     gnome_vfs_init();
506     GnomeVFSHandle    *from_handle = NULL;
507     GnomeVFSHandle    *to_handle = NULL;
508     GnomeVFSFileSize  bytes_read;
509     GnomeVFSFileSize  bytes_written;
510     GnomeVFSResult    result;
511     guint8 buffer[8192];
513     //get file url
514     Glib::ustring fileUrl = get_text(posArray[0], 1); //http url
516     //Glib::ustring fileUrl = "dav://"; //dav url
517     //fileUrl.append(prefs_get_string_attribute("options.ocalurl", "str"));
518     //fileUrl.append("/dav/");
519     //fileUrl.append(get_text(posArray[0], 3)); //author dir
520     //fileUrl.append("/");
521     //fileUrl.append(get_text(posArray[0], 2)); //filename
523     if (!Glib::get_charset()) //If we are not utf8
524         fileUrl = Glib::filename_to_utf8(fileUrl);
526     // verifies if the file wasn't previously downloaded
527     if(gnome_vfs_open(&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_READ) == GNOME_VFS_ERROR_NOT_FOUND)
528     {
529         // open the temp file to receive
530         result = gnome_vfs_open (&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_WRITE);
531         if (result == GNOME_VFS_ERROR_NOT_FOUND){
532             result = gnome_vfs_create (&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
533         }
534         if (result != GNOME_VFS_OK) {
535             g_warning("Error creating temp file: %s", gnome_vfs_result_to_string(result));
536             return;
537         }
538         result = gnome_vfs_open (&from_handle, fileUrl.c_str(), GNOME_VFS_OPEN_READ);
539         if (result != GNOME_VFS_OK) {
540             g_warning("Could not find the file in Open Clip Art Library.");
541             return;
542         }
543         // copy the file
544         while (1) {
545             result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
546             if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
547                 result = gnome_vfs_close (from_handle);
548                 result = gnome_vfs_close (to_handle);
549                 break;
550             }
551             if (result != GNOME_VFS_OK) {
552                 g_warning("%s", gnome_vfs_result_to_string(result));
553                 return;
554             }
555             result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
556             if (result != GNOME_VFS_OK) {
557                 g_warning("%s", gnome_vfs_result_to_string(result));
558                 return;
559             }
560             if (bytes_read != bytes_written){
561                 g_warning("Bytes read not equal to bytes written");
562                 return;
563             }
564         }
565     }
566     else
567     {
568         gnome_vfs_close(to_handle);
569     }
570     myPreview->showImage(myFilename);
571 #endif
575 /*
576  * Returns the selected filename
577  */
578 Glib::ustring FileListViewText::getFilename()
580     return myFilename;
583 /**
584  * Callback for user input into searchTagEntry
585  */
586 void FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback()
588     if (!searchTagEntry)
589         return;
591     notFoundLabel->hide();
593     Glib::ustring searchTag = searchTagEntry->get_text();
594     // create the ocal uri to get rss feed
595     Glib::ustring uri = "http://www.";
596     uri.append(prefs_get_string_attribute("options.ocalurl", "str"));
597     uri.append("/media/feed/rss/");
598     uri.append(searchTag);
599     if (!Glib::get_charset()) //If we are not utf8
600         uri = Glib::filename_to_utf8(uri);
602 #ifdef WITH_GNOME_VFS
604     // get the rss feed
605     gnome_vfs_init();
606     GnomeVFSHandle    *from_handle = NULL;
607     GnomeVFSHandle    *to_handle = NULL;
608     GnomeVFSFileSize  bytes_read;
609     GnomeVFSFileSize  bytes_written;
610     GnomeVFSResult    result;
611     guint8 buffer[8192];
613     // create the temp file name
614     Glib::ustring fileName = Glib::get_tmp_dir ();
615     fileName.append(G_DIR_SEPARATOR_S);
616     fileName.append("ocalfeed.xml");
618     // open the temp file to receive
619     result = gnome_vfs_open (&to_handle, fileName.c_str(), GNOME_VFS_OPEN_WRITE);
620     if (result == GNOME_VFS_ERROR_NOT_FOUND){
621         result = gnome_vfs_create (&to_handle, fileName.c_str(), GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
622     }
623     if (result != GNOME_VFS_OK) {
624         g_warning("Error creating temp file: %s", gnome_vfs_result_to_string(result));
625         return;
626     }
628     // open the rss feed
629     result = gnome_vfs_open (&from_handle, uri.c_str(), GNOME_VFS_OPEN_READ);
630     if (result != GNOME_VFS_OK) {
631         sp_ui_error_dialog(_("Failed to receive the Open Clip Art Library RSS feed. Verify if the URL is correct in Configuration->Misc (e.g.: openclipart.org)"));
632         //g_warning("Could not find the Open Clip Art Library rss feed. Verify if the OCAL url is correct in Configuration");
633         return;
634     }
636     // copy the file
637     while (1) {
639         result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
641         if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
642             result = gnome_vfs_close (from_handle);
643             result = gnome_vfs_close (to_handle);
644             break;
645         }
647         if (result != GNOME_VFS_OK) {
648             g_warning("%s", gnome_vfs_result_to_string(result));
649             return;
650         }
651         result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
652         if (result != GNOME_VFS_OK) {
653             g_warning("%s", gnome_vfs_result_to_string(result));
654             return;
655         }
657         if (bytes_read != bytes_written){
658             g_warning("Bytes read not equal to bytes written");
659             return;
660         }
662     }
664     // create the resulting xml document tree
665     // this initialize the library and test mistakes between compiled and shared library used
666     LIBXML_TEST_VERSION 
667     xmlDoc *doc = NULL;
668     xmlNode *root_element = NULL;
669     doc = xmlReadFile(fileName.c_str(), NULL, 0);
670     if (doc == NULL) {
671         g_warning("Failed to parse %s\n", fileName.c_str());
672     return;
673     }
674     
675     // get the root element node
676     root_element = xmlDocGetRootElement(doc);
678     // clear the fileslist
679     filesList->clear_items();
680     filesList->set_sensitive(false);
682     // print all xml the element names
683     print_xml_element_names(root_element);
685     if (filesList->size() == 0)
686     {
687         notFoundLabel->show();
688         filesList->set_sensitive(false);
689     }
690     else
691         filesList->set_sensitive(true);
693     // free the document
694     xmlFreeDoc(doc);
695     // free the global variables that may have been allocated by the parser
696     xmlCleanupParser();
697     return;
698 #endif    
701 /**
702  * Prints the names of the all the xml elements 
703  * that are siblings or children of a given xml node
704  */
705 void FileImportFromOCALDialogImplGtk::print_xml_element_names(xmlNode * a_node)
707     xmlNode *cur_node = NULL;
708     guint row_num = 0;
709     for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
710         // get itens information
711         if (strcmp((const char*)cur_node->name, "rss")) //avoid the root
712             if (cur_node->type == XML_ELEMENT_NODE && !strcmp((const char*)cur_node->parent->name, "item"))
713             {
714                 if (!strcmp((const char*)cur_node->name, "title"))
715                 {
716                     xmlChar *title = xmlNodeGetContent(cur_node);
717                     row_num = filesList->append_text((const char*)title);
718                     xmlFree(title);
719                 }
720 #ifdef WITH_GNOME_VFS
721                 else if (!strcmp((const char*)cur_node->name, "enclosure"))
722                 {
723                     xmlChar *urlattribute = xmlGetProp(cur_node, (xmlChar*)"url");
724                     filesList->set_text(row_num, 1, (const char*)urlattribute);
725                     gchar *tmp_file;
726                     tmp_file = gnome_vfs_uri_extract_short_path_name(gnome_vfs_uri_new((const char*)urlattribute));
727                     filesList->set_text(row_num, 2, (const char*)tmp_file);
728                     xmlFree(urlattribute);
729                 }
730                 else if (!strcmp((const char*)cur_node->name, "creator"))
731                 {
732                     filesList->set_text(row_num, 3, (const char*)xmlNodeGetContent(cur_node));
733                 }
734 #endif
735             }
736         print_xml_element_names(cur_node->children);
737     }
740 /**
741  * Constructor.  Not called directly.  Use the factory.
742  */
743 FileImportFromOCALDialogImplGtk::FileImportFromOCALDialogImplGtk(Gtk::Window& parentWindow, 
744                                        const Glib::ustring &dir,
745                                        FileDialogType fileTypes,
746                                        const Glib::ustring &title) :
747      FileDialogOCALBase(title)
750     // Initalize to Autodetect
751     extension = NULL;
752     // No filename to start out with
753     Glib::ustring searchTag = "";
755     dialogType = fileTypes;
756     Gtk::VBox *vbox = get_vbox();
757     Gtk::Label *tagLabel = new Gtk::Label(_("Search Tag"));
758     notFoundLabel = new Gtk::Label(_("No files matched your search"));
759     messageBox.pack_start(*notFoundLabel);
760     searchTagEntry = new Gtk::Entry();
761     searchTagEntry->set_text(searchTag);
762     searchTagEntry->set_max_length(252); // I am giving the extension approach.
763     tagBox.pack_start(*tagLabel);
764     tagBox.pack_start(*searchTagEntry, Gtk::PACK_EXPAND_WIDGET, 3);
765     filesPreview = new SVGPreview();
766     filesPreview->showNoPreview();
767     filesList = new FileListViewText(4, *filesPreview);
768     filesList->set_sensitive(false);
769     // add the listview inside a ScrolledWindow
770     listScrolledWindow.add(*filesList);
771     // only show the scrollbars when they are necessary:
772     listScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
773     filesList->set_column_title(0, _("Files Found"));
774     listScrolledWindow.set_size_request(200, 180);
775     filesList->get_column(1)->set_visible(false); // file url
776     filesList->get_column(2)->set_visible(false); // tmp file path
777     filesList->get_column(3)->set_visible(false); // author dir
778     filesBox.pack_start(listScrolledWindow);
779     filesBox.pack_start(*filesPreview);
780     vbox->pack_start(tagBox);
781     vbox->pack_start(messageBox);
782     vbox->pack_start(filesBox);
784     //Let's do some customization
785     searchTagEntry = NULL;
786     Gtk::Container *cont = get_toplevel();
787     std::vector<Gtk::Entry *> entries;
788     findEntryWidgets(cont, entries);
789     if (entries.size() >=1 )
790     {
791     //Catch when user hits [return] on the text field
792         searchTagEntry = entries[0];
793         searchTagEntry->signal_activate().connect(
794               sigc::mem_fun(*this, &FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback));
795     }
797     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
798     set_default(*add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK));
800     show_all_children();
801     notFoundLabel->hide();
804 /**
805  * Destructor
806  */
807 FileImportFromOCALDialogImplGtk::~FileImportFromOCALDialogImplGtk()
812 /**
813  * Show this dialog modally.  Return true if user hits [OK]
814  */
815 bool
816 FileImportFromOCALDialogImplGtk::show()
818     set_modal (TRUE);                      //Window
819     sp_transientize((GtkWidget *)gobj());  //Make transient
820     gint b = run();                        //Dialog
821     hide();
823     if (b == Gtk::RESPONSE_OK)
824     {
825         return TRUE;
826     }
827     else
828     {
829         return FALSE;
830     }
834 /**
835  * Get the file extension type that was selected by the user. Valid after an [OK]
836  */
837 Inkscape::Extension::Extension *
838 FileImportFromOCALDialogImplGtk::getSelectionType()
840     return extension;
844 /**
845  * Get the file name chosen by the user.   Valid after an [OK]
846  */
847 Glib::ustring
848 FileImportFromOCALDialogImplGtk::getFilename (void)
850     return filesList->getFilename();
854 } //namespace Dialog
855 } //namespace UI
856 } //namespace Inkscape
860 /*
861   Local Variables:
862   mode:c++
863   c-file-style:"stroustrup"
864   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
865   indent-tabs-mode:nil
866   fill-column:99
867   End:
868 */
869 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :