diff options
| author | Bruno Dilly <bruno.dilly@gmail.com> | 2007-08-16 12:19:21 +0000 |
|---|---|---|
| committer | bdilly <bdilly@users.sourceforge.net> | 2007-08-16 12:19:21 +0000 |
| commit | b8881635446b32cac3a089968b59f515fbd9dfec (patch) | |
| tree | 951fefd97a6318206c302edc606e7a5c046f0671 | |
| parent | updated Slovak translation in trunk (diff) | |
| download | inkscape-b8881635446b32cac3a089968b59f515fbd9dfec.tar.gz inkscape-b8881635446b32cac3a089968b59f515fbd9dfec.zip | |
add import from ocal feature
(bzr r3476)
| -rw-r--r-- | src/file.cpp | 113 | ||||
| -rw-r--r-- | src/file.h | 18 | ||||
| -rw-r--r-- | src/preferences-skeleton.h | 2 | ||||
| -rw-r--r-- | src/ui/dialog/filedialog.cpp | 16 | ||||
| -rw-r--r-- | src/ui/dialog/filedialog.h | 53 | ||||
| -rw-r--r-- | src/ui/dialog/filedialogimpl-gtkmm.cpp | 373 | ||||
| -rw-r--r-- | src/ui/dialog/filedialogimpl-gtkmm.h | 92 |
7 files changed, 575 insertions, 92 deletions
diff --git a/src/file.cpp b/src/file.cpp index ebeef462e..95dc9d07f 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -497,9 +497,6 @@ sp_file_vacuum() /** * This 'save' function called by the others below - * It was divided in file_save_local and file_save_remote - * to support remote saving too. - * Now file_save is calling only local saving, but it will be solved. * * \param official whether to set :output_module and :modified in the * document; is true for normal save, false for temporary saves @@ -511,31 +508,6 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, if (!doc || uri.size()<1) //Safety check return false; -#ifdef WITH_GNOME_VFS - -// if (gnome_vfs_initialized() && !gnome_vfs_uri_is_local(gnome_vfs_uri_new(uri.c_str()))) { -// // Use VFS for this -// bool success = file_save_remote(doc, uri, key, saveas, official); -// if (!success) { -// g_warning("Error: Could not save file '%s' with VFS\n", uri.c_str()); -// return false; -// } -// else -// return true; -// } -// else - return file_save_local(parentWindow, doc, uri, key, saveas, official); -#else - - return file_save_local(parentWindow, doc, uri, key, saveas, official); - -#endif -} - -bool -file_save_local(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, - Inkscape::Extension::Extension *key, bool saveas, bool official) -{ try { Inkscape::Extension::save(key, doc, uri.c_str(), false, @@ -564,9 +536,6 @@ file_save_local(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring return true; } - - - /* * Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp. */ @@ -618,12 +587,9 @@ file_save_remote(SPDocument *doc, const Glib::ustring &uri, return false; } - ///g_warning("file_save_remote: temp dir: %s",fileName.c_str()); - while (1) { result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read); - //g_warning("bytes lidos: %d",bytes_read); if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){ result = gnome_vfs_close (from_handle); @@ -631,15 +597,11 @@ file_save_remote(SPDocument *doc, const Glib::ustring &uri, return true; } - //g_warning("while: %s", gnome_vfs_result_to_string(result)); - if (result != GNOME_VFS_OK) { g_warning("%s", gnome_vfs_result_to_string(result)); return false; } - //g_warning("%s",buffer); result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written); - //g_warning("escritos: %d",bytes_written); if (result != GNOME_VFS_OK) { g_warning("%s", gnome_vfs_result_to_string(result)); return false; @@ -1043,6 +1005,7 @@ sp_file_import(Gtk::Window &parentWindow) else g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" ); + import_path = fileName; if (import_path.size()>0) import_path.append(G_DIR_SEPARATOR_S); @@ -1175,16 +1138,8 @@ sp_file_export_dialog(void *widget) return false; } - - - - - - #else - - /** * */ @@ -1201,12 +1156,6 @@ sp_file_export_dialog(void *widget) ## E X P O R T T O O C A L ######################*/ - -/** - * Export the current document to OCAL - */ - - /** * Display an Export dialog, export as the selected type if OK pressed */ @@ -1238,7 +1187,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) Inkscape::Extension::Output *extension; - //# Get the default extension name + // Get the default extension name Glib::ustring default_extension; char *attr = (char *)repr->attribute("inkscape:output_extension"); if (!attr) @@ -1268,7 +1217,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) if ( export_path_local.size() > 0) export_path = export_path_local; - //# Show the Export To OCAL dialog + // Show the Export To OCAL dialog if (!exportDialogInstance) exportDialogInstance = Inkscape::UI::Dialog::FileExportToOCALDialog::create( parentWindow, @@ -1306,7 +1255,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) return success; } - /* Start now the submition */ + // Start now the submition // Create the uri Glib::ustring uri = "dav://"; @@ -1329,7 +1278,9 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) return success; } - +/** + * Export the current document to OCAL + */ void sp_file_export_to_ocal(Gtk::Window &parentWindow) { @@ -1348,19 +1299,55 @@ sp_file_export_to_ocal(Gtk::Window &parentWindow) ######################*/ /** - * Import a document from OCAL + * Display an ImportToOcal Dialog, and the selected document from OCAL */ void sp_file_import_from_ocal(Gtk::Window &parentWindow) { - // Try to execute the new code and return; - if (!SP_ACTIVE_DOCUMENT) + static Glib::ustring import_path; + + SPDocument *doc = SP_ACTIVE_DOCUMENT; + if (!doc) return; - //bool success = sp_file_import_from_ocal_dialog(parentWindow); - //if (success) - // SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Document imported...")); -} + static Inkscape::UI::Dialog::FileImportFromOCALDialog *importDialogInstance = NULL; + + if (!importDialogInstance) { + importDialogInstance = + Inkscape::UI::Dialog::FileImportFromOCALDialog::create( + parentWindow, + import_path, + Inkscape::UI::Dialog::IMPORT_TYPES, + (char const *)_("Import From OCAL")); + } + + bool success = importDialogInstance->show(); + if (!success) + return; + + // Get file name and extension type + Glib::ustring fileName = importDialogInstance->getFilename(); + Inkscape::Extension::Extension *selection = + importDialogInstance->getSelectionType(); + + if (fileName.size() > 0) { + + Glib::ustring newFileName = Glib::filename_to_utf8(fileName); + + if ( newFileName.size() > 0) + fileName = newFileName; + else + g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" ); + + import_path = fileName; + if (import_path.size()>0) + import_path.append(G_DIR_SEPARATOR_S); + + file_import(doc, fileName, selection); + } + + return; +} /*###################### ## P R I N T diff --git a/src/file.h b/src/file.h index c5a854922..7f960ab65 100644 --- a/src/file.h +++ b/src/file.h @@ -80,22 +80,12 @@ void sp_file_revert_dialog (); ######################*/ /* - * Added to make only the local savings. - */ - -bool file_save_local(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, - Inkscape::Extension::Extension *key, bool saveas, bool official); - - -/* * Added to make only the remote savings. */ bool file_save_remote(SPDocument *doc, const Glib::ustring &uri, Inkscape::Extension::Extension *key, bool saveas, bool official); - - /** * */ @@ -178,14 +168,6 @@ bool sp_file_export_to_ocal_dialog (void *widget); void sp_file_import_from_ocal (Gtk::Window &parentWindow ); -/** - * Import a document from OCAL - */ -//bool sp_file_import_from_ocal_dialog (void *widget); - - - - /*###################### ## P R I N T ######################*/ diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 8a04640e1..9e5514565 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -214,7 +214,7 @@ static char const preferences_skeleton[] = " <group id=\"blurquality\" value=\"0\"/>\n" " <group id=\"startmode\" outline=\"0\"/>\n" " <group id=\"outlinemode\" value=\"0\"/>\n" -" <group id=\"ocalurl\" str=\"test.webdav.org/dav/\"/>\n" +" <group id=\"ocalurl\" str=\"openclipart.org\"/>\n" " <group id=\"ocalusername\" str=\"\"/>\n" " <group id=\"ocalpassword\" str=\"\"/>\n" " <group id=\"wireframecolors\" " diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp index 63bb98b4b..88ba32679 100644 --- a/src/ui/dialog/filedialog.cpp +++ b/src/ui/dialog/filedialog.cpp @@ -94,6 +94,21 @@ FileSaveDialog *FileSaveDialog::create(Gtk::Window& parentWindow, return dialog; } +//######################################################################### +//### F I L E I M P O R T F R O M O C A L +//######################################################################### + +/** + * Public factory. Called by file.cpp. + */ +FileImportFromOCALDialog *FileImportFromOCALDialog::create(Gtk::Window &parentWindow, + const Glib::ustring &path, + FileDialogType fileTypes, + const Glib::ustring &title) +{ + FileImportFromOCALDialog *dialog = new FileImportFromOCALDialogImplGtk(parentWindow, path, fileTypes, title); + return dialog; +} } //namespace Dialog @@ -101,6 +116,7 @@ FileSaveDialog *FileSaveDialog::create(Gtk::Window& parentWindow, } //namespace Inkscape + /* Local Variables: mode:c++ diff --git a/src/ui/dialog/filedialog.h b/src/ui/dialog/filedialog.h index 06d68fa72..d98c37a28 100644 --- a/src/ui/dialog/filedialog.h +++ b/src/ui/dialog/filedialog.h @@ -391,6 +391,59 @@ public: }; //FileExportToOCAL +/** + * This class provides an implementation-independent API for + * file "ImportFromOCAL" dialogs. + */ +class FileImportFromOCALDialog +{ +public: + + + /** + * Constructor .. do not call directly + * @param path the directory where to start searching + * @param fileTypes one of FileDialogTypes + * @param title the title of the dialog + */ + FileImportFromOCALDialog() + {}; + + /** + * Factory. + * @param path the directory where to start searching + * @param fileTypes one of FileDialogTypes + * @param title the title of the dialog + */ + static FileImportFromOCALDialog *create(Gtk::Window& parentWindow, + const Glib::ustring &path, + FileDialogType fileTypes, + const Glib::ustring &title); + + + /** + * Destructor. + * Perform any necessary cleanups. + */ + virtual ~FileImportFromOCALDialog() {}; + + /** + * Show an OpenFile file selector. + * @return the selected path if user selected one, else NULL + */ + virtual bool show() =0; + + /** + * Return the 'key' (filetype) of the selection, if any + * @return a pointer to a string if successful (which must + * be later freed with g_free(), else NULL. + */ + virtual Inkscape::Extension::Extension * getSelectionType() = 0; + + virtual Glib::ustring getFilename () =0; + +}; //FileImportFromOCALDialog + } //namespace Dialog } //namespace UI diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 61d37e918..3357561b5 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -4,6 +4,7 @@ * Authors:
* Bob Jamison
* Joel Holdsworth
+ * Bruno Dilly
* Other dudes from The Inkscape Organization
*
* Copyright (C) 2004-2007 Bob Jamison
@@ -21,6 +22,10 @@ #include "filedialogimpl-gtkmm.h"
#include "dialogs/dialog-events.h"
+#ifdef WITH_GNOME_VFS
+# include <libgnomevfs/gnome-vfs.h>
+#endif
+
//Routines from file.cpp
#undef INK_DUMP_FILENAME_CONV
@@ -1634,8 +1639,6 @@ void FileExportToOCALDialogImpl::fileNameEntryChangedCallback() if (!Glib::get_charset()) //If we are not utf8
fileName = Glib::filename_to_utf8(fileName);
- //g_message("User hit return. Text is '%s'\n", fileName.c_str());
-
myFilename = fileName;
response(Gtk::RESPONSE_OK);
}
@@ -1705,7 +1708,7 @@ FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key) :
- FileDialogExportBase(title)
+ FileDialogOCALBase(title)
{
/*
* Start Taking the vertical Box and putting a Label
@@ -1720,7 +1723,6 @@ FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow /* Set our dialog type (save, export, etc...)*/
dialogType = fileTypes;
Gtk::VBox *vbox = get_vbox();
- //Gtk::HBox fileBox;
Gtk::Label *fileLabel = new Gtk::Label(_("File"));
@@ -1917,6 +1919,369 @@ void FileExportToOCALDialogImpl::updateNameAndExtension() }
}
+//#########################################################################
+//### F I L E I M P O R T F R O M O C A L
+//#########################################################################
+
+/*
+ * Callback for row activated
+ */
+void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column)
+{
+ // create file path
+ myFilename = Glib::get_tmp_dir();
+ myFilename.append(G_DIR_SEPARATOR_S);
+ std::vector<int> posArray(1);
+ posArray = path.get_indices();
+ myFilename.append(get_text(posArray[0], 2));
+
+#ifdef WITH_GNOME_VFS
+ gnome_vfs_init();
+ GnomeVFSHandle *from_handle = NULL;
+ GnomeVFSHandle *to_handle = NULL;
+ GnomeVFSFileSize bytes_read;
+ GnomeVFSFileSize bytes_written;
+ GnomeVFSResult result;
+ guint8 buffer[8192];
+
+ //get file url
+ Glib::ustring fileUrl = get_text(posArray[0], 1); //http url
+
+ //Glib::ustring fileUrl = "dav://"; //dav url
+ //fileUrl.append(prefs_get_string_attribute("options.ocalurl", "str"));
+ //fileUrl.append("/dav/");
+ //fileUrl.append(get_text(posArray[0], 3)); //author dir
+ //fileUrl.append("/");
+ //fileUrl.append(get_text(posArray[0], 2)); //filename
+
+ if (!Glib::get_charset()) //If we are not utf8
+ fileUrl = Glib::filename_to_utf8(fileUrl);
+
+ // verifies if the file wasn't previously downloaded
+ if(gnome_vfs_open(&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_READ) == GNOME_VFS_ERROR_NOT_FOUND)
+ {
+ // open the temp file to receive
+ result = gnome_vfs_open (&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_WRITE);
+ if (result == GNOME_VFS_ERROR_NOT_FOUND){
+ result = gnome_vfs_create (&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
+ }
+ if (result != GNOME_VFS_OK) {
+ g_warning("Error creating temp file: %s", gnome_vfs_result_to_string(result));
+ return;
+ }
+ result = gnome_vfs_open (&from_handle, fileUrl.c_str(), GNOME_VFS_OPEN_READ);
+ if (result != GNOME_VFS_OK) {
+ g_warning("Could not find the file in Open Clip Art Library.");
+ return;
+ }
+ // copy the file
+ while (1) {
+ result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
+ if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
+ result = gnome_vfs_close (from_handle);
+ result = gnome_vfs_close (to_handle);
+ break;
+ }
+ if (result != GNOME_VFS_OK) {
+ g_warning("%s", gnome_vfs_result_to_string(result));
+ return;
+ }
+ result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
+ if (result != GNOME_VFS_OK) {
+ g_warning("%s", gnome_vfs_result_to_string(result));
+ return;
+ }
+ if (bytes_read != bytes_written){
+ g_warning("Bytes read not equal to bytes written");
+ return;
+ }
+ }
+ }
+ else
+ {
+ gnome_vfs_close(to_handle);
+ }
+ myPreview->showImage(myFilename);
+#endif
+}
+
+
+/*
+ * Returns the selected filename
+ */
+Glib::ustring FileListViewText::getFilename()
+{
+ return myFilename;
+}
+
+/**
+ * Callback for user input into searchTagEntry
+ */
+void FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback()
+{
+ if (!searchTagEntry)
+ return;
+
+ notFoundLabel->hide();
+
+ Glib::ustring searchTag = searchTagEntry->get_text();
+ // create the ocal uri to get rss feed
+ Glib::ustring uri = "http://www.";
+ uri.append(prefs_get_string_attribute("options.ocalurl", "str"));
+ uri.append("/media/feed/rss/");
+ uri.append(searchTag);
+ if (!Glib::get_charset()) //If we are not utf8
+ uri = Glib::filename_to_utf8(uri);
+
+#ifdef WITH_GNOME_VFS
+
+ // get the rss feed
+ gnome_vfs_init();
+ GnomeVFSHandle *from_handle = NULL;
+ GnomeVFSHandle *to_handle = NULL;
+ GnomeVFSFileSize bytes_read;
+ GnomeVFSFileSize bytes_written;
+ GnomeVFSResult result;
+ guint8 buffer[8192];
+
+ // create the temp file name
+ Glib::ustring fileName = Glib::get_tmp_dir ();
+ fileName.append(G_DIR_SEPARATOR_S);
+ fileName.append("ocalfeed.xml");
+
+ // open the temp file to receive
+ result = gnome_vfs_open (&to_handle, fileName.c_str(), GNOME_VFS_OPEN_WRITE);
+ if (result == GNOME_VFS_ERROR_NOT_FOUND){
+ result = gnome_vfs_create (&to_handle, fileName.c_str(), GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
+ }
+ if (result != GNOME_VFS_OK) {
+ g_warning("Error creating temp file: %s", gnome_vfs_result_to_string(result));
+ return;
+ }
+
+ // open the rss feed
+ result = gnome_vfs_open (&from_handle, uri.c_str(), GNOME_VFS_OPEN_READ);
+ if (result != GNOME_VFS_OK) {
+ g_warning("Could not find the Open Clip Art Library rss feed. Verify if the OCAL url is correct in Configuration");
+ return;
+ }
+
+ // copy the file
+ while (1) {
+
+ result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read);
+
+ if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){
+ result = gnome_vfs_close (from_handle);
+ result = gnome_vfs_close (to_handle);
+ break;
+ }
+
+ if (result != GNOME_VFS_OK) {
+ g_warning("%s", gnome_vfs_result_to_string(result));
+ return;
+ }
+ result = gnome_vfs_write (to_handle, buffer, bytes_read, &bytes_written);
+ if (result != GNOME_VFS_OK) {
+ g_warning("%s", gnome_vfs_result_to_string(result));
+ return;
+ }
+
+ if (bytes_read != bytes_written){
+ g_warning("Bytes read not equal to bytes written");
+ return;
+ }
+
+ }
+
+ // create the resulting xml document tree
+ // this initialize the library and test mistakes between compiled and shared library used
+ LIBXML_TEST_VERSION
+ xmlDoc *doc = NULL;
+ xmlNode *root_element = NULL;
+ doc = xmlReadFile(fileName.c_str(), NULL, 0);
+ if (doc == NULL) {
+ g_warning("Failed to parse %s\n", fileName.c_str());
+ return;
+ }
+
+ // get the root element node
+ root_element = xmlDocGetRootElement(doc);
+
+ // clear the fileslist
+ filesList->clear_items();
+ filesList->set_sensitive(false);
+
+ // print all xml the element names
+ print_xml_element_names(root_element);
+
+ if (filesList->size() == 0)
+ {
+ notFoundLabel->show();
+ filesList->set_sensitive(false);
+ }
+ else
+ filesList->set_sensitive(true);
+
+ // free the document
+ xmlFreeDoc(doc);
+ // free the global variables that may have been allocated by the parser
+ xmlCleanupParser();
+ return;
+#endif
+}
+
+/**
+ * Prints the names of the all the xml elements
+ * that are siblings or children of a given xml node
+ */
+void FileImportFromOCALDialogImplGtk::print_xml_element_names(xmlNode * a_node)
+{
+ xmlNode *cur_node = NULL;
+ guint row_num = 0;
+ for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
+ // get itens information
+ if (strcmp((const char*)cur_node->name, "rss")) //avoid the root
+ if (cur_node->type == XML_ELEMENT_NODE && !strcmp((const char*)cur_node->parent->name, "item"))
+ {
+ if (!strcmp((const char*)cur_node->name, "title"))
+ {
+ xmlChar *title = xmlNodeGetContent(cur_node);
+ row_num = filesList->append_text((const char*)title);
+ xmlFree(title);
+ }
+#ifdef WITH_GNOME_VFS
+ else if (!strcmp((const char*)cur_node->name, "enclosure"))
+ {
+ xmlChar *urlattribute = xmlGetProp(cur_node, (xmlChar*)"url");
+ filesList->set_text(row_num, 1, (const char*)urlattribute);
+ gchar *tmp_file;
+ tmp_file = gnome_vfs_uri_extract_short_path_name(gnome_vfs_uri_new((const char*)urlattribute));
+ filesList->set_text(row_num, 2, (const char*)tmp_file);
+ xmlFree(urlattribute);
+ }
+ else if (!strcmp((const char*)cur_node->name, "creator"))
+ {
+ filesList->set_text(row_num, 3, (const char*)xmlNodeGetContent(cur_node));
+ }
+#endif
+ }
+ print_xml_element_names(cur_node->children);
+ }
+}
+
+/**
+ * Constructor. Not called directly. Use the factory.
+ */
+FileImportFromOCALDialogImplGtk::FileImportFromOCALDialogImplGtk(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title) :
+ FileDialogOCALBase(title)
+{
+
+ // Initalize to Autodetect
+ extension = NULL;
+ // No filename to start out with
+ Glib::ustring searchTag = "";
+
+ dialogType = fileTypes;
+ Gtk::VBox *vbox = get_vbox();
+ Gtk::Label *tagLabel = new Gtk::Label(_("Search Tag"));
+ notFoundLabel = new Gtk::Label(_("No files matched your search"));
+ messageBox.pack_start(*notFoundLabel);
+ searchTagEntry = new Gtk::Entry();
+ searchTagEntry->set_text(searchTag);
+ searchTagEntry->set_max_length(252); // I am giving the extension approach.
+ tagBox.pack_start(*tagLabel);
+ tagBox.pack_start(*searchTagEntry, Gtk::PACK_EXPAND_WIDGET, 3);
+ filesPreview = new SVGPreview();
+ filesPreview->showNoPreview();
+ filesList = new FileListViewText(4, *filesPreview);
+ filesList->set_sensitive(false);
+ // add the listview inside a ScrolledWindow
+ listScrolledWindow.add(*filesList);
+ // only show the scrollbars when they are necessary:
+ listScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ filesList->set_column_title(0, _("Files Found"));
+ listScrolledWindow.set_size_request(200, 180);
+ filesList->get_column(1)->set_visible(false); // file url
+ filesList->get_column(2)->set_visible(false); // tmp file path
+ filesList->get_column(3)->set_visible(false); // author dir
+ filesBox.pack_start(listScrolledWindow);
+ filesBox.pack_start(*filesPreview);
+ vbox->pack_start(tagBox);
+ vbox->pack_start(messageBox);
+ vbox->pack_start(filesBox);
+
+ //Let's do some customization
+ searchTagEntry = NULL;
+ Gtk::Container *cont = get_toplevel();
+ std::vector<Gtk::Entry *> entries;
+ findEntryWidgets(cont, entries);
+ if (entries.size() >=1 )
+ {
+ //Catch when user hits [return] on the text field
+ searchTagEntry = entries[0];
+ searchTagEntry->signal_activate().connect(
+ sigc::mem_fun(*this, &FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback));
+ }
+
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
+
+ show_all_children();
+ notFoundLabel->hide();
+}
+
+/**
+ * Destructor
+ */
+FileImportFromOCALDialogImplGtk::~FileImportFromOCALDialogImplGtk()
+{
+
+}
+
+/**
+ * Show this dialog modally. Return true if user hits [OK]
+ */
+bool
+FileImportFromOCALDialogImplGtk::show()
+{
+ set_modal (TRUE); //Window
+ sp_transientize((GtkWidget *)gobj()); //Make transient
+ gint b = run(); //Dialog
+ hide();
+
+ if (b == Gtk::RESPONSE_OK)
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+
+/**
+ * Get the file extension type that was selected by the user. Valid after an [OK]
+ */
+Inkscape::Extension::Extension *
+FileImportFromOCALDialogImplGtk::getSelectionType()
+{
+ return extension;
+}
+
+
+/**
+ * Get the file name chosen by the user. Valid after an [OK]
+ */
+Glib::ustring
+FileImportFromOCALDialogImplGtk::getFilename (void)
+{
+ return filesList->getFilename();
+}
} //namespace Dialog
} //namespace UI
diff --git a/src/ui/dialog/filedialogimpl-gtkmm.h b/src/ui/dialog/filedialogimpl-gtkmm.h index fa8edda85..375ec23ad 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.h +++ b/src/ui/dialog/filedialogimpl-gtkmm.h @@ -4,6 +4,7 @@ * Authors:
* Bob Jamison
* Joel Holdsworth
+ * Bruno Dilly
* Other dudes from The Inkscape Organization
*
* Copyright (C) 2004-2007 Bob Jamison
@@ -21,6 +22,9 @@ #include <sys/stat.h>
#include <errno.h>
#include <set>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
//Gtk includes
#include <glibmm/i18n.h>
@@ -565,25 +569,25 @@ private: /*#########################################################################
-### F I L E D I A L O G E X P O R T B A S E C L A S S
+### F I L E D I A L O G O C A L B A S E C L A S S
#########################################################################*/
/**
* This class is the base implementation for export to OCAL.
*/
-class FileDialogExportBase : public Gtk::Dialog
+class FileDialogOCALBase : public Gtk::Dialog
{
public:
/**
*
*/
- FileDialogExportBase(const Glib::ustring &title) : Gtk::Dialog(title,true)
+ FileDialogOCALBase(const Glib::ustring &title) : Gtk::Dialog(title,true)
{}
/*
*
*/
- virtual ~FileDialogExportBase()
+ virtual ~FileDialogOCALBase()
{}
protected:
@@ -608,7 +612,7 @@ protected: /**
* Our implementation of the FileExportToOCALDialog interface.
*/
-class FileExportToOCALDialogImpl : public FileExportToOCALDialog, public FileDialogExportBase
+class FileExportToOCALDialogImpl : public FileExportToOCALDialog, public FileDialogOCALBase
{
public:
@@ -650,7 +654,7 @@ private: */
std::vector<FileType> fileTypes;
- //# Child widgets
+ // Child widgets
Gtk::HBox childBox;
Gtk::VBox checksBox;
Gtk::HBox fileBox;
@@ -685,6 +689,82 @@ private: };
+//#########################################################################
+//### F I L E I M P O R T F R O M O C A L
+//#########################################################################
+
+/**
+ * Our implementation class for filesListView
+ */
+class FileListViewText : public Gtk::ListViewText
+{
+public:
+ FileListViewText(guint columns_count, SVGPreview& filesPreview):ListViewText(columns_count)
+ {
+ myPreview = &filesPreview;
+ }
+ Glib::ustring getFilename();
+protected:
+ void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
+private:
+ Glib::ustring myFilename;
+ SVGPreview *myPreview;
+};
+
+/**
+ * Our implementation class for the FileImportFromOCALDialog interface..
+ */
+class FileImportFromOCALDialogImplGtk : public FileImportFromOCALDialog, public FileDialogOCALBase
+{
+public:
+
+ FileImportFromOCALDialogImplGtk(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title);
+
+ virtual ~FileImportFromOCALDialogImplGtk();
+
+ bool show();
+
+ Inkscape::Extension::Extension *getSelectionType();
+
+ Glib::ustring getFilename();
+
+private:
+
+ /**
+ * Allow the user to type the tag to be searched
+ */
+ Gtk::Entry *searchTagEntry;
+ FileListViewText *filesList;
+ SVGPreview *filesPreview;
+ Gtk::Label *notFoundLabel;
+
+ // Child widgets
+ Gtk::HBox tagBox;
+ Gtk::HBox filesBox;
+ Gtk::HBox messageBox;
+ Gtk::ScrolledWindow listScrolledWindow;
+ Glib::RefPtr<Gtk::TreeSelection> selection;
+
+ /**
+ * Callback for user input into searchTagEntry
+ */
+ void searchTagEntryChangedCallback();
+
+
+ /**
+ * Prints the names of the all the xml elements
+ * that are siblings or children of a given xml node
+ */
+ void print_xml_element_names(xmlNode * a_node);
+
+ /**
+ * The extension to use to write this file
+ */
+ Inkscape::Extension::Extension *extension;
+};
}
}
|
