diff options
| author | Andrew rugby471@gmail.com <> | 2011-04-18 16:42:15 +0000 |
|---|---|---|
| committer | Andrew rugby471@gmail.com <> | 2011-04-18 16:42:15 +0000 |
| commit | 96fe0edbc762c3b616ae1b2b9651392d58f20ae5 (patch) | |
| tree | a40e2b8f835876c7f1c92217b0a52116f0abd785 /src | |
| parent | uint > unsigned int (so windows builds work) (diff) | |
| download | inkscape-96fe0edbc762c3b616ae1b2b9651392d58f20ae5.tar.gz inkscape-96fe0edbc762c3b616ae1b2b9651392d58f20ae5.zip | |
Remove some GNOME_VFS checks
Try to use read_async instead of load_contents_async, not working at the moment :(
(bzr r10092.1.31)
Diffstat (limited to 'src')
| -rw-r--r-- | src/menus-skeleton.h | 2 | ||||
| -rw-r--r-- | src/ui/dialog/ocaldialogs.cpp | 69 | ||||
| -rw-r--r-- | src/ui/dialog/ocaldialogs.h | 4 |
3 files changed, 64 insertions, 11 deletions
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index f1b633865..1bde67811 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -27,10 +27,8 @@ static char const menus_skeleton[] = " <separator/>\n" " <verb verb-id=\"FileImport\" />\n" " <verb verb-id=\"FileExport\" />\n" -#ifdef WITH_GNOME_VFS " <verb verb-id=\"FileImportFromOCAL\" />\n" //" <verb verb-id=\"FileExportToOCAL\" />\n" -#endif " <separator/>\n" " <verb verb-id=\"FilePrint\" />\n" " <separator/>\n" diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 9e81a90e8..f4317cdd0 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -968,7 +968,7 @@ void ImportDialog::on_entry_search_activated() // Open the RSS feed Glib::RefPtr<Gio::File> xml_file = Gio::File::create_for_uri(xml_uri); - xml_file->load_contents_async( + xml_file->read_async( sigc::bind<Glib::RefPtr<Gio::File> , Glib::ustring>( sigc::mem_fun(*this, &ImportDialog::on_xml_file_read), xml_file, xml_uri) @@ -978,14 +978,45 @@ void ImportDialog::on_entry_search_activated() void ImportDialog::on_xml_file_read(const Glib::RefPtr<Gio::AsyncResult>& result, Glib::RefPtr<Gio::File> xml_file, Glib::ustring xml_uri) { - widget_status->end_process(); + Glib::RefPtr<Gio::FileInputStream> stream; + char* buffer[8192]; - char* data; - gsize length; - - bool sucess = xml_file->load_contents_finish(result, data, length); - if (!sucess) { + try { + stream = xml_file->read_finish(result); + } catch(Glib::Error) { widget_status->set_error(_("Could not connect to the Open Clip Art Library")); + widget_status->end_process(); + + stream->close_async( + sigc::bind< Glib::RefPtr<Gio::FileInputStream> >( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), + stream) + ); + + return; + } + + stream->read_async(buffer, 8192, + sigc::bind<Glib::RefPtr<Gio::FileInputStream>, char*, Glib::ustring>( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_read), + stream, *buffer, xml_uri) + ); +} + +void ImportDialog::on_xml_file_stream_read(const Glib::RefPtr<Gio::AsyncResult>& result, + Glib::RefPtr<Gio::FileInputStream> stream, char* buffer, Glib::ustring xml_uri) +{ + gssize success = stream->read_finish(result); + + if (success == -1) { + widget_status->set_error(_("Could not connect to the Open Clip Art Library")); + + stream->close_async( + sigc::bind< Glib::RefPtr<Gio::FileInputStream> >( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), + stream) + ); + return; } @@ -995,17 +1026,26 @@ void ImportDialog::on_xml_file_read(const Glib::RefPtr<Gio::AsyncResult>& result xmlDoc *doc = NULL; xmlNode *root_element = NULL; - doc = xmlReadMemory(data, (int) length, xml_uri.c_str(), NULL, + printf("%f\n", (double) success); + + doc = xmlReadMemory(buffer, 8192, xml_uri.c_str(), NULL, XML_PARSE_RECOVER + XML_PARSE_NOWARNING + XML_PARSE_NOERROR); if (doc == NULL) { // If nothing is returned, no results could be found - if (length == 0) { + if (success == 0) { notebook_content->set_current_page(NOTEBOOK_PAGE_NOT_FOUND); update_label_no_search_results(); } else { widget_status->set_error(_("Could not parse search results")); } + + stream->close_async( + sigc::bind< Glib::RefPtr<Gio::FileInputStream> >( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), + stream) + ); + return; } @@ -1030,8 +1070,19 @@ void ImportDialog::on_xml_file_read(const Glib::RefPtr<Gio::AsyncResult>& result xmlFreeDoc(doc); // free the global variables that may have been allocated by the parser xmlCleanupParser(); + + stream->close_async( + sigc::bind< Glib::RefPtr<Gio::FileInputStream> >( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), + stream) + ); } +void ImportDialog::on_xml_file_stream_closed(const Glib::RefPtr<Gio::AsyncResult>& result, + Glib::RefPtr<Gio::FileInputStream> stream) +{ + stream->close_finish(result); +} void ImportDialog::update_label_no_search_results() { diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 7fb937c81..2891efbe4 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -492,6 +492,10 @@ private: void on_list_results_selection_changed(); void on_xml_file_read(const Glib::RefPtr<Gio::AsyncResult>& result, Glib::RefPtr<Gio::File> xml_file, Glib::ustring xml_uri); + void on_xml_file_stream_read(const Glib::RefPtr<Gio::AsyncResult>& result, + Glib::RefPtr<Gio::FileInputStream> stream, char* buffer, Glib::ustring xml_uri); + void on_xml_file_stream_closed(const Glib::RefPtr<Gio::AsyncResult>& result, + Glib::RefPtr<Gio::FileInputStream> stream); void create_temporary_dirs(); std::string get_temporary_dir(ResourceType type); |
