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);
102 }
106 /**
107 * Callback for fileNameEntry widget
108 */
109 void FileExportToOCALDialogImpl::fileTypeChangedCallback()
110 {
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();
118 }
122 void FileExportToOCALDialogImpl::createFileTypeMenu()
123 {
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
158 }
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)
170 {
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();
240 }
244 /**
245 * Destructor
246 */
247 FileExportToOCALDialogImpl::~FileExportToOCALDialogImpl()
248 {
249 }
253 /**
254 * Show this dialog modally. Return true if user hits [OK]
255 */
256 bool
257 FileExportToOCALDialogImpl::show()
258 {
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 }
274 }
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()
282 {
283 return extension;
284 }
286 void FileExportToOCALDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
287 {
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 }
325 }
328 /**
329 * Get the file name chosen by the user. Valid after an [OK]
330 */
331 Glib::ustring
332 FileExportToOCALDialogImpl::getFilename()
333 {
334 myFilename = fileNameEntry->get_text();
335 updateNameAndExtension();
336 return myFilename;
337 }
340 void
341 FileExportToOCALDialogImpl::change_title(const Glib::ustring& title)
342 {
343 this->set_title(title);
344 }
346 void FileExportToOCALDialogImpl::updateNameAndExtension()
347 {
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 }
378 }
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)
391 {
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);
426 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
427 set_default(*add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK));
429 show_all_children();
430 }
433 /**
434 * Destructor
435 */
436 FileExportToOCALPasswordDialogImpl::~FileExportToOCALPasswordDialogImpl()
437 {
438 }
440 /**
441 * Show this dialog modally. Return true if user hits [OK]
442 */
443 bool
444 FileExportToOCALPasswordDialogImpl::show()
445 {
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 }
459 }
461 /**
462 * Get the username. Valid after an [OK]
463 */
464 Glib::ustring
465 FileExportToOCALPasswordDialogImpl::getUsername()
466 {
467 myUsername = usernameEntry->get_text();
468 return myUsername;
469 }
471 /**
472 * Get the password. Valid after an [OK]
473 */
474 Glib::ustring
475 FileExportToOCALPasswordDialogImpl::getPassword()
476 {
477 myPassword = passwordEntry->get_text();
478 return myPassword;
479 }
481 void
482 FileExportToOCALPasswordDialogImpl::change_title(const Glib::ustring& title)
483 {
484 this->set_title(title);
485 }
488 //#########################################################################
489 //### F I L E I M P O R T F R O M O C A L
490 //#########################################################################
493 /*
494 * Callback for row activated
495 */
496 void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column)
497 {
498 // create file path
499 myFilename = Glib::get_tmp_dir();
500 myFilename.append(G_DIR_SEPARATOR_S);
501 std::vector<int> posArray(1);
502 posArray = path.get_indices();
503 myFilename.append(get_text(posArray[0], 2));
505 #ifdef WITH_GNOME_VFS
506 gnome_vfs_init();
507 GnomeVFSHandle *from_handle = NULL;
508 GnomeVFSHandle *to_handle = NULL;
509 GnomeVFSFileSize bytes_read;
510 GnomeVFSFileSize bytes_written;
511 GnomeVFSResult result;
512 guint8 buffer[8192];
514 //get file url
515 Glib::ustring fileUrl = get_text(posArray[0], 1); //http url
517 //Glib::ustring fileUrl = "dav://"; //dav url
518 //fileUrl.append(prefs_get_string_attribute("options.ocalurl", "str"));
519 //fileUrl.append("/dav.php/");
520 //fileUrl.append(get_text(posArray[0], 3)); //author dir
521 //fileUrl.append("/");
522 //fileUrl.append(get_text(posArray[0], 2)); //filename
524 if (!Glib::get_charset()) //If we are not utf8
525 fileUrl = Glib::filename_to_utf8(fileUrl);
527 // verifies if the file wasn't previously downloaded
528 if(gnome_vfs_open(&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_READ) == GNOME_VFS_ERROR_NOT_FOUND)
529 {
530 // open the temp file to receive
531 result = gnome_vfs_open (&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_WRITE);
532 if (result == GNOME_VFS_ERROR_NOT_FOUND){
533 result = gnome_vfs_create (&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
534 }
535 if (result != GNOME_VFS_OK) {
536 g_warning("Error creating temp file: %s", gnome_vfs_result_to_string(result));
537 return;
538 }
539 result = gnome_vfs_open (&from_handle, fileUrl.c_str(), GNOME_VFS_OPEN_READ);
540 if (result != GNOME_VFS_OK) {
541 g_warning("Could not find the file in Open Clip Art Library.");
542 return;
543 }
544 // copy the file
545 while (1) {
546 result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
547 if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
548 result = gnome_vfs_close (from_handle);
549 result = gnome_vfs_close (to_handle);
550 break;
551 }
552 if (result != GNOME_VFS_OK) {
553 g_warning("%s", gnome_vfs_result_to_string(result));
554 return;
555 }
556 result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
557 if (result != GNOME_VFS_OK) {
558 g_warning("%s", gnome_vfs_result_to_string(result));
559 return;
560 }
561 if (bytes_read != bytes_written){
562 g_warning("Bytes read not equal to bytes written");
563 return;
564 }
565 }
566 }
567 else
568 {
569 gnome_vfs_close(to_handle);
570 }
571 myPreview->showImage(myFilename);
572 myLabel->set_text(get_text(posArray[0], 4));
573 #endif
574 }
577 /*
578 * Returns the selected filename
579 */
580 Glib::ustring FileListViewText::getFilename()
581 {
582 return myFilename;
583 }
585 /**
586 * Callback for user input into searchTagEntry
587 */
588 void FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback()
589 {
590 if (!searchTagEntry)
591 return;
593 notFoundLabel->hide();
594 descriptionLabel->set_text("");
596 Glib::ustring searchTag = searchTagEntry->get_text();
597 // create the ocal uri to get rss feed
598 Glib::ustring uri = "http://";
599 uri.append(prefs_get_string_attribute("options.ocalurl", "str"));
600 uri.append("/media/feed/rss/");
601 uri.append(searchTag);
602 if (!Glib::get_charset()) //If we are not utf8
603 uri = Glib::filename_to_utf8(uri);
605 #ifdef WITH_GNOME_VFS
607 // get the rss feed
608 gnome_vfs_init();
609 GnomeVFSHandle *from_handle = NULL;
610 GnomeVFSHandle *to_handle = NULL;
611 GnomeVFSFileSize bytes_read;
612 GnomeVFSFileSize bytes_written;
613 GnomeVFSResult result;
614 guint8 buffer[8192];
616 // create the temp file name
617 Glib::ustring fileName = Glib::get_tmp_dir ();
618 fileName.append(G_DIR_SEPARATOR_S);
619 fileName.append("ocalfeed.xml");
621 // open the temp file to receive
622 result = gnome_vfs_open (&to_handle, fileName.c_str(), GNOME_VFS_OPEN_WRITE);
623 if (result == GNOME_VFS_ERROR_NOT_FOUND){
624 result = gnome_vfs_create (&to_handle, fileName.c_str(), GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
625 }
626 if (result != GNOME_VFS_OK) {
627 g_warning("Error creating temp file: %s", gnome_vfs_result_to_string(result));
628 return;
629 }
631 // open the rss feed
632 result = gnome_vfs_open (&from_handle, uri.c_str(), GNOME_VFS_OPEN_READ);
633 if (result != GNOME_VFS_OK) {
634 sp_ui_error_dialog(_("Failed to receive the Open Clip Art Library RSS feed. Verify if the server name is correct in Configuration->Misc (e.g.: openclipart.org)"));
635 return;
636 }
638 // copy the file
639 while (1) {
641 result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
643 if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
644 result = gnome_vfs_close (from_handle);
645 result = gnome_vfs_close (to_handle);
646 break;
647 }
649 if (result != GNOME_VFS_OK) {
650 g_warning("%s", gnome_vfs_result_to_string(result));
651 return;
652 }
653 result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
654 if (result != GNOME_VFS_OK) {
655 g_warning("%s", gnome_vfs_result_to_string(result));
656 return;
657 }
659 if (bytes_read != bytes_written){
660 g_warning("Bytes read not equal to bytes written");
661 return;
662 }
664 }
666 // create the resulting xml document tree
667 // this initialize the library and test mistakes between compiled and shared library used
668 LIBXML_TEST_VERSION
669 xmlDoc *doc = NULL;
670 xmlNode *root_element = NULL;
671 doc = xmlReadFile(fileName.c_str(), NULL, 0);
672 if (doc == NULL) {
673 g_warning("Failed to parse %s\n", fileName.c_str());
674 return;
675 }
677 // get the root element node
678 root_element = xmlDocGetRootElement(doc);
680 // clear the fileslist
681 filesList->clear_items();
682 filesList->set_sensitive(false);
684 // print all xml the element names
685 print_xml_element_names(root_element);
687 if (filesList->size() == 0)
688 {
689 notFoundLabel->show();
690 filesList->set_sensitive(false);
691 }
692 else
693 filesList->set_sensitive(true);
695 // free the document
696 xmlFreeDoc(doc);
697 // free the global variables that may have been allocated by the parser
698 xmlCleanupParser();
699 return;
700 #endif
701 }
703 /**
704 * Prints the names of the all the xml elements
705 * that are siblings or children of a given xml node
706 */
707 void FileImportFromOCALDialogImplGtk::print_xml_element_names(xmlNode * a_node)
708 {
709 xmlNode *cur_node = NULL;
710 guint row_num = 0;
711 for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
712 // get itens information
713 if (strcmp((const char*)cur_node->name, "rss")) //avoid the root
714 if (cur_node->type == XML_ELEMENT_NODE && !strcmp((const char*)cur_node->parent->name, "item"))
715 {
716 if (!strcmp((const char*)cur_node->name, "title"))
717 {
718 xmlChar *title = xmlNodeGetContent(cur_node);
719 row_num = filesList->append_text((const char*)title);
720 xmlFree(title);
721 }
722 #ifdef WITH_GNOME_VFS
723 else if (!strcmp((const char*)cur_node->name, "enclosure"))
724 {
725 xmlChar *urlattribute = xmlGetProp(cur_node, (xmlChar*)"url");
726 filesList->set_text(row_num, 1, (const char*)urlattribute);
727 gchar *tmp_file;
728 tmp_file = gnome_vfs_uri_extract_short_path_name(gnome_vfs_uri_new((const char*)urlattribute));
729 filesList->set_text(row_num, 2, (const char*)tmp_file);
730 xmlFree(urlattribute);
731 }
732 else if (!strcmp((const char*)cur_node->name, "creator"))
733 {
734 filesList->set_text(row_num, 3, (const char*)xmlNodeGetContent(cur_node));
735 }
736 else if (!strcmp((const char*)cur_node->name, "description"))
737 {
738 filesList->set_text(row_num, 4, (const char*)xmlNodeGetContent(cur_node));
739 }
740 #endif
741 }
742 print_xml_element_names(cur_node->children);
743 }
744 }
746 /**
747 * Constructor. Not called directly. Use the factory.
748 */
749 FileImportFromOCALDialogImplGtk::FileImportFromOCALDialogImplGtk(Gtk::Window& parentWindow,
750 const Glib::ustring &dir,
751 FileDialogType fileTypes,
752 const Glib::ustring &title) :
753 FileDialogOCALBase(title)
754 {
755 // Initalize to Autodetect
756 extension = NULL;
757 // No filename to start out with
758 Glib::ustring searchTag = "";
760 dialogType = fileTypes;
761 Gtk::VBox *vbox = get_vbox();
762 Gtk::Label *tagLabel = new Gtk::Label(_("Search Tag"));
763 notFoundLabel = new Gtk::Label(_("No files matched your search"));
764 descriptionLabel = new Gtk::Label();
765 messageBox.pack_start(*notFoundLabel);
766 descriptionBox.pack_start(*descriptionLabel);
767 searchTagEntry = new Gtk::Entry();
768 searchTagEntry->set_text(searchTag);
769 searchTagEntry->set_max_length(255);
770 searchButton = new Gtk::Button(_("Search"));
771 tagBox.pack_start(*tagLabel);
772 tagBox.pack_start(*searchTagEntry, Gtk::PACK_EXPAND_WIDGET, 3);
773 tagBox.pack_start(*searchButton);
774 filesPreview = new SVGPreview();
775 filesPreview->showNoPreview();
776 filesList = new FileListViewText(5, *filesPreview, *descriptionLabel);
777 filesList->set_sensitive(false);
778 // add the listview inside a ScrolledWindow
779 listScrolledWindow.add(*filesList);
780 // only show the scrollbars when they are necessary:
781 listScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
782 filesList->set_column_title(0, _("Files Found"));
783 listScrolledWindow.set_size_request(400, 180);
784 filesList->get_column(1)->set_visible(false); // file url
785 filesList->get_column(2)->set_visible(false); // tmp file path
786 filesList->get_column(3)->set_visible(false); // author dir
787 filesList->get_column(4)->set_visible(false); // file description
788 filesBox.pack_start(listScrolledWindow);
789 filesBox.pack_start(*filesPreview);
790 vbox->pack_start(tagBox);
791 vbox->pack_start(messageBox);
792 vbox->pack_start(filesBox);
793 vbox->pack_start(descriptionBox);
795 //Let's do some customization
796 searchTagEntry = NULL;
797 Gtk::Container *cont = get_toplevel();
798 std::vector<Gtk::Entry *> entries;
799 findEntryWidgets(cont, entries);
800 if (entries.size() >=1 )
801 {
802 //Catch when user hits [return] on the text field
803 searchTagEntry = entries[0];
804 searchTagEntry->signal_activate().connect(
805 sigc::mem_fun(*this, &FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback));
806 }
808 searchButton->signal_clicked().connect(
809 sigc::mem_fun(*this, &FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback));
811 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
812 set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
814 show_all_children();
815 notFoundLabel->hide();
816 }
818 /**
819 * Destructor
820 */
821 FileImportFromOCALDialogImplGtk::~FileImportFromOCALDialogImplGtk()
822 {
824 }
826 /**
827 * Show this dialog modally. Return true if user hits [OK]
828 */
829 bool
830 FileImportFromOCALDialogImplGtk::show()
831 {
832 set_modal (TRUE); //Window
833 sp_transientize((GtkWidget *)gobj()); //Make transient
834 gint b = run(); //Dialog
835 hide();
837 if (b == Gtk::RESPONSE_OK)
838 {
839 return TRUE;
840 }
841 else
842 {
843 return FALSE;
844 }
845 }
848 /**
849 * Get the file extension type that was selected by the user. Valid after an [OK]
850 */
851 Inkscape::Extension::Extension *
852 FileImportFromOCALDialogImplGtk::getSelectionType()
853 {
854 return extension;
855 }
858 /**
859 * Get the file name chosen by the user. Valid after an [OK]
860 */
861 Glib::ustring
862 FileImportFromOCALDialogImplGtk::getFilename (void)
863 {
864 return filesList->getFilename();
865 }
868 } //namespace Dialog
869 } //namespace UI
870 } //namespace Inkscape
874 /*
875 Local Variables:
876 mode:c++
877 c-file-style:"stroustrup"
878 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
879 indent-tabs-mode:nil
880 fill-column:99
881 End:
882 */
883 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :