From 6a8d2d6d621e4ec4391d37fc3188198645743dce Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 11 Mar 2011 17:45:35 +0000 Subject: Added 12px border to dialog Set better default size Removed 'Search for:' label Made Search button not EXPAND and FILL (bzr r10092.1.1) --- src/ui/dialog/ocaldialogs.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 2ae7d6989..e30d819ce 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -562,8 +562,11 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, Glib::ustring searchTag = ""; dialogType = fileTypes; + // Dialog + set_border_width(12); + set_default_size(480, 350); + // Gtk::VBox *vbox = get_vbox(); - Gtk::Label *tagLabel = new Gtk::Label(_("Search for:")); notFoundLabel = new Gtk::Label(_("No files matched your search")); descriptionLabel = new Gtk::Label(); descriptionLabel->set_max_width_chars(260); @@ -576,9 +579,8 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, searchTagEntry->set_text(searchTag); searchTagEntry->set_max_length(255); searchButton = new Gtk::Button(_("Search")); - tagBox.pack_start(*tagLabel); tagBox.pack_start(*searchTagEntry, Gtk::PACK_EXPAND_WIDGET, 3); - tagBox.pack_start(*searchButton); + tagBox.pack_start(*searchButton, false, false); filesPreview = new SVGPreview(); filesPreview->showNoPreview(); // add the buttons in the bottom of the dialog -- cgit v1.2.3 From aaf0e368bc01f41c4803547a8493792dc498e6f2 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 11 Mar 2011 18:20:38 +0000 Subject: Fixed padding and packing Removed message and description labels (bzr r10092.1.2) --- src/ui/dialog/ocaldialogs.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index e30d819ce..8b9d5274a 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -562,25 +562,30 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, Glib::ustring searchTag = ""; dialogType = fileTypes; + // Dialog set_border_width(12); set_default_size(480, 350); - // + // VBox Gtk::VBox *vbox = get_vbox(); + vbox->set_spacing(12); notFoundLabel = new Gtk::Label(_("No files matched your search")); descriptionLabel = new Gtk::Label(); descriptionLabel->set_max_width_chars(260); descriptionLabel->set_size_request(500, -1); descriptionLabel->set_single_line_mode(false); descriptionLabel->set_line_wrap(true); - messageBox.pack_start(*notFoundLabel); - descriptionBox.pack_start(*descriptionLabel); + messageBox.pack_start(*notFoundLabel, false, false); + descriptionBox.pack_start(*descriptionLabel, false, false); searchTagEntry = new Gtk::Entry(); searchTagEntry->set_text(searchTag); searchTagEntry->set_max_length(255); searchButton = new Gtk::Button(_("Search")); - tagBox.pack_start(*searchTagEntry, Gtk::PACK_EXPAND_WIDGET, 3); - tagBox.pack_start(*searchButton, false, false); + Gtk::HButtonBox* searchButtonBox = new Gtk::HButtonBox(); + searchButtonBox->pack_start(*searchButton, false, false); + tagBox.set_spacing(6); + tagBox.pack_start(*searchTagEntry, true, true); + tagBox.pack_start(*searchButtonBox, false, false); filesPreview = new SVGPreview(); filesPreview->showNoPreview(); // add the buttons in the bottom of the dialog @@ -600,12 +605,13 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, filesList->get_column(2)->set_visible(false); // tmp file path filesList->get_column(3)->set_visible(false); // author dir filesList->get_column(4)->set_visible(false); // file description - filesBox.pack_start(listScrolledWindow); - filesBox.pack_start(*filesPreview); + filesBox.set_spacing(12); + filesBox.pack_start(listScrolledWindow, true, true); + filesBox.pack_start(*filesPreview, true, true); vbox->pack_start(tagBox, false, false); - vbox->pack_start(messageBox); - vbox->pack_start(filesBox); - vbox->pack_start(descriptionBox); + vbox->pack_start(messageBox, false, false); + vbox->pack_start(filesBox, true, true); + vbox->pack_start(descriptionBox, false, false); //Let's do some customization searchTagEntry = NULL; -- cgit v1.2.3 From fb2752c017015772576421f87085b7099dafbf60 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 11 Mar 2011 18:26:59 +0000 Subject: organise GUI code into sections (bzr r10092.1.3) --- src/ui/dialog/ocaldialogs.cpp | 54 ++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 8b9d5274a..24e2ee4fc 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -562,50 +562,55 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, Glib::ustring searchTag = ""; dialogType = fileTypes; - - // Dialog - set_border_width(12); - set_default_size(480, 350); - // VBox + + // Creation Gtk::VBox *vbox = get_vbox(); - vbox->set_spacing(12); notFoundLabel = new Gtk::Label(_("No files matched your search")); descriptionLabel = new Gtk::Label(); + searchTagEntry = new Gtk::Entry(); + searchButton = new Gtk::Button(_("Search")); + Gtk::HButtonBox* searchButtonBox = new Gtk::HButtonBox(); + filesPreview = new SVGPreview(); + /// Add the buttons in the bottom of the dialog + add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + okButton = add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + filesList = new FileListViewText(5, *filesPreview, *descriptionLabel, *okButton); + + // Properties + set_border_width(12); + set_default_size(480, 350); + vbox->set_spacing(12); descriptionLabel->set_max_width_chars(260); descriptionLabel->set_size_request(500, -1); descriptionLabel->set_single_line_mode(false); descriptionLabel->set_line_wrap(true); - messageBox.pack_start(*notFoundLabel, false, false); - descriptionBox.pack_start(*descriptionLabel, false, false); - searchTagEntry = new Gtk::Entry(); searchTagEntry->set_text(searchTag); searchTagEntry->set_max_length(255); - searchButton = new Gtk::Button(_("Search")); - Gtk::HButtonBox* searchButtonBox = new Gtk::HButtonBox(); - searchButtonBox->pack_start(*searchButton, false, false); tagBox.set_spacing(6); - tagBox.pack_start(*searchTagEntry, true, true); - tagBox.pack_start(*searchButtonBox, false, false); - filesPreview = new SVGPreview(); filesPreview->showNoPreview(); - // add the buttons in the bottom of the dialog - add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - okButton = add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); - // sets the okbutton to default set_default(*okButton); - filesList = new FileListViewText(5, *filesPreview, *descriptionLabel, *okButton); filesList->set_sensitive(false); - // add the listview inside a ScrolledWindow + /// Add the listview inside a ScrolledWindow listScrolledWindow.add(*filesList); - // only show the scrollbars when they are necessary: + /// 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(400, 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 filesList->get_column(4)->set_visible(false); // file description + filesBox.set_spacing(12); + notFoundLabel->hide(); + + // Packing + messageBox.pack_start(*notFoundLabel, false, false); + descriptionBox.pack_start(*descriptionLabel, false, false); + searchButtonBox->pack_start(*searchButton, false, false); + tagBox.pack_start(*searchTagEntry, true, true); + tagBox.pack_start(*searchButtonBox, false, false); filesBox.pack_start(listScrolledWindow, true, true); filesBox.pack_start(*filesPreview, true, true); vbox->pack_start(tagBox, false, false); @@ -613,11 +618,13 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, vbox->pack_start(filesBox, true, true); vbox->pack_start(descriptionBox, false, false); - //Let's do some customization + // Let's do some customization searchTagEntry = NULL; Gtk::Container *cont = get_toplevel(); std::vector entries; findEntryWidgets(cont, entries); + + // Signals if (entries.size() >=1 ) { //Catch when user hits [return] on the text field @@ -630,7 +637,6 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, sigc::mem_fun(*this, &FileImportFromOCALDialog::searchTagEntryChangedCallback)); show_all_children(); - notFoundLabel->hide(); } /** -- cgit v1.2.3 From db034d36e3cc13c9a9a28283f7d7630bd0e40df2 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 11 Mar 2011 19:01:27 +0000 Subject: converted to use var_name from CamelCase removed erroneous size_request (bzr r10092.1.4) --- src/file.cpp | 34 +++++----- src/ui/dialog/ocaldialogs.cpp | 147 +++++++++++++++++++++--------------------- src/ui/dialog/ocaldialogs.h | 37 ++++++----- 3 files changed, 108 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/file.cpp b/src/file.cpp index 2816b0434..d997a72f7 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1444,7 +1444,7 @@ sp_file_export_to_ocal(Gtk::Window &parentWindow) * Display an ImportToOcal Dialog, and the selected document from OCAL */ void -sp_file_import_from_ocal(Gtk::Window &parentWindow) +sp_file_import_from_ocal(Gtk::Window &parent_window) { static Glib::ustring import_path; @@ -1452,44 +1452,44 @@ sp_file_import_from_ocal(Gtk::Window &parentWindow) if (!doc) return; - Inkscape::UI::Dialog::FileImportFromOCALDialog *importDialogInstance = NULL; + Inkscape::UI::Dialog::FileImportFromOCALDialog *import_dialog = NULL; - if (!importDialogInstance) { - importDialogInstance = new + if (!import_dialog) { + import_dialog = new Inkscape::UI::Dialog::FileImportFromOCALDialog( - parentWindow, + parent_window, import_path, Inkscape::UI::Dialog::IMPORT_TYPES, (char const *)_("Import From Open Clip Art Library")); } - bool success = importDialogInstance->show(); + bool success = import_dialog->show(); if (!success) { - delete importDialogInstance; + delete import_dialog; return; } // Get file name and extension type - Glib::ustring fileName = importDialogInstance->getFilename(); - Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType(); + Glib::ustring file_name = import_dialog->get_filename(); + Inkscape::Extension::Extension *selection = import_dialog->get_selection_type(); - delete importDialogInstance; - importDialogInstance = NULL; + delete import_dialog; + import_dialog = NULL; - if (fileName.size() > 0) { + if (file_name.size() > 0) { - Glib::ustring newFileName = Glib::filename_to_utf8(fileName); + Glib::ustring new_file_name = Glib::filename_to_utf8(file_name); - if ( newFileName.size() > 0) - fileName = newFileName; + if (new_file_name.size() > 0) + file_name = new_file_name; else g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" ); - import_path = fileName; + import_path = file_name; if (import_path.size()>0) import_path.append(G_DIR_SEPARATOR_S); - file_import(doc, fileName, selection); + file_import(doc, file_name, selection); } return; diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 24e2ee4fc..ba999788b 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -146,7 +146,7 @@ FileExportToOCALDialog::show() */ /* Glib::ustring -FileExportToOCALDialog::getFilename() +FileExportToOCALDialog::get_filename() { myFilename = fileNameEntry->get_text(); if (!Glib::get_charset()) //If we are not utf8 @@ -398,7 +398,7 @@ void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& /*path*/, Gt /* * Returns the selected filename */ -Glib::ustring FileListViewText::getFilename() +Glib::ustring FileListViewText::get_filename() { return myFilename; } @@ -429,23 +429,23 @@ static int vfs_read_callback (GnomeVFSHandle *handle, char* buf, int nb) /** - * Callback for user input into searchTagEntry + * Callback for user input into entry_search */ -void FileImportFromOCALDialog::searchTagEntryChangedCallback() +void FileImportFromOCALDialog::on_entry_search_changed() { - if (!searchTagEntry) + if (!entry_search) return; - notFoundLabel->hide(); - descriptionLabel->set_text(""); + label_not_found->hide(); + label_description->set_text(""); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring searchTag = searchTagEntry->get_text(); + Glib::ustring search_keywords = entry_search->get_text(); // create the ocal uri to get rss feed Glib::ustring uri = "http://"; uri.append(prefs->getString("/options/ocalurl/str")); uri.append("/media/feed/rss/"); - uri.append(searchTag); + uri.append(search_keywords); if (!Glib::get_charset()) //If we are not utf8 uri = Glib::filename_to_utf8(uri); @@ -480,20 +480,20 @@ void FileImportFromOCALDialog::searchTagEntryChangedCallback() // get the root element node root_element = xmlDocGetRootElement(doc); - // clear the fileslist - filesList->clear_items(); - filesList->set_sensitive(false); + // clear the list_files + list_files->clear_items(); + list_files->set_sensitive(false); // print all xml the element names print_xml_element_names(root_element); - if (filesList->size() == 0) + if (list_files->size() == 0) { - notFoundLabel->show(); - filesList->set_sensitive(false); + label_not_found->show(); + list_files->set_sensitive(false); } else - filesList->set_sensitive(true); + list_files->set_sensitive(true); // free the document xmlFreeDoc(doc); @@ -520,26 +520,26 @@ void FileImportFromOCALDialog::print_xml_element_names(xmlNode * a_node) if (!strcmp((const char*)cur_node->name, "title")) { xmlChar *title = xmlNodeGetContent(cur_node); - row_num = filesList->append_text((const char*)title); + row_num = list_files->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); + list_files->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); + list_files->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)); + list_files->set_text(row_num, 3, (const char*)xmlNodeGetContent(cur_node)); } else if (!strcmp((const char*)cur_node->name, "description")) { - filesList->set_text(row_num, 4, (const char*)xmlNodeGetContent(cur_node)); + list_files->set_text(row_num, 4, (const char*)xmlNodeGetContent(cur_node)); } #endif } @@ -550,76 +550,75 @@ void FileImportFromOCALDialog::print_xml_element_names(xmlNode * a_node) /** * Constructor. Not called directly. Use the factory. */ -FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, +FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, const Glib::ustring &/*dir*/, - FileDialogType fileTypes, + FileDialogType file_types, const Glib::ustring &title) : - FileDialogOCALBase(title, parentWindow) + FileDialogOCALBase(title, parent_window) { // Initalize to Autodetect extension = NULL; // No filename to start out with - Glib::ustring searchTag = ""; + Glib::ustring search_keywords = ""; - dialogType = fileTypes; + dialogType = file_types; // Creation Gtk::VBox *vbox = get_vbox(); - notFoundLabel = new Gtk::Label(_("No files matched your search")); - descriptionLabel = new Gtk::Label(); - searchTagEntry = new Gtk::Entry(); - searchButton = new Gtk::Button(_("Search")); - Gtk::HButtonBox* searchButtonBox = new Gtk::HButtonBox(); - filesPreview = new SVGPreview(); + label_not_found = new Gtk::Label(_("No files matched your search")); + label_description = new Gtk::Label(); + entry_search = new Gtk::Entry(); + button_search = new Gtk::Button(_("Search")); + Gtk::HButtonBox* hbuttonbox_search = new Gtk::HButtonBox(); + preview_files = new SVGPreview(); /// Add the buttons in the bottom of the dialog add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - okButton = add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); - filesList = new FileListViewText(5, *filesPreview, *descriptionLabel, *okButton); + button_ok = add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + list_files = new FileListViewText(5, *preview_files, *label_description, *button_ok); // Properties set_border_width(12); set_default_size(480, 350); vbox->set_spacing(12); - descriptionLabel->set_max_width_chars(260); - descriptionLabel->set_size_request(500, -1); - descriptionLabel->set_single_line_mode(false); - descriptionLabel->set_line_wrap(true); - searchTagEntry->set_text(searchTag); - searchTagEntry->set_max_length(255); - tagBox.set_spacing(6); - filesPreview->showNoPreview(); - set_default(*okButton); - filesList->set_sensitive(false); + label_description->set_max_width_chars(260); + label_description->set_size_request(500, -1); + label_description->set_single_line_mode(false); + label_description->set_line_wrap(true); + entry_search->set_text(search_keywords); + entry_search->set_max_length(255); + hbox_tags.set_spacing(6); + preview_files->showNoPreview(); + set_default(*button_ok); + list_files->set_sensitive(false); /// Add the listview inside a ScrolledWindow - listScrolledWindow.add(*filesList); + scrolledwindow_list.add(*list_files); /// 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(400, 180); + scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + list_files->set_column_title(0, _("Files found")); - 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 - filesList->get_column(4)->set_visible(false); // file description + list_files->get_column(1)->set_visible(false); // file url + list_files->get_column(2)->set_visible(false); // tmp file path + list_files->get_column(3)->set_visible(false); // author dir + list_files->get_column(4)->set_visible(false); // file description - filesBox.set_spacing(12); - notFoundLabel->hide(); + hbox_files.set_spacing(12); + label_not_found->hide(); // Packing - messageBox.pack_start(*notFoundLabel, false, false); - descriptionBox.pack_start(*descriptionLabel, false, false); - searchButtonBox->pack_start(*searchButton, false, false); - tagBox.pack_start(*searchTagEntry, true, true); - tagBox.pack_start(*searchButtonBox, false, false); - filesBox.pack_start(listScrolledWindow, true, true); - filesBox.pack_start(*filesPreview, true, true); - vbox->pack_start(tagBox, false, false); - vbox->pack_start(messageBox, false, false); - vbox->pack_start(filesBox, true, true); - vbox->pack_start(descriptionBox, false, false); + hbox_message.pack_start(*label_not_found, false, false); + hbox_description.pack_start(*label_description, false, false); + hbuttonbox_search->pack_start(*button_search, false, false); + hbox_tags.pack_start(*entry_search, true, true); + hbox_tags.pack_start(*hbuttonbox_search, false, false); + hbox_files.pack_start(scrolledwindow_list, true, true); + hbox_files.pack_start(*preview_files, true, true); + vbox->pack_start(hbox_tags, false, false); + vbox->pack_start(hbox_message, false, false); + vbox->pack_start(hbox_files, true, true); + vbox->pack_start(hbox_description, false, false); // Let's do some customization - searchTagEntry = NULL; + entry_search = NULL; Gtk::Container *cont = get_toplevel(); std::vector entries; findEntryWidgets(cont, entries); @@ -628,13 +627,13 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parentWindow, if (entries.size() >=1 ) { //Catch when user hits [return] on the text field - searchTagEntry = entries[0]; - searchTagEntry->signal_activate().connect( - sigc::mem_fun(*this, &FileImportFromOCALDialog::searchTagEntryChangedCallback)); + entry_search = entries[0]; + entry_search->signal_activate().connect( + sigc::mem_fun(*this, &FileImportFromOCALDialog::on_entry_search_changed)); } - searchButton->signal_clicked().connect( - sigc::mem_fun(*this, &FileImportFromOCALDialog::searchTagEntryChangedCallback)); + button_search->signal_clicked().connect( + sigc::mem_fun(*this, &FileImportFromOCALDialog::on_entry_search_changed)); show_all_children(); } @@ -673,7 +672,7 @@ FileImportFromOCALDialog::show() * Get the file extension type that was selected by the user. Valid after an [OK] */ Inkscape::Extension::Extension * -FileImportFromOCALDialog::getSelectionType() +FileImportFromOCALDialog::get_selection_type() { return extension; } @@ -683,9 +682,9 @@ FileImportFromOCALDialog::getSelectionType() * Get the file name chosen by the user. Valid after an [OK] */ Glib::ustring -FileImportFromOCALDialog::getFilename (void) +FileImportFromOCALDialog::get_filename (void) { - return filesList->getFilename(); + return list_files->get_filename(); } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 85aefade8..2826e0fdd 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -269,7 +269,7 @@ public: myLabel = &description; myButton = &okButton; } - Glib::ustring getFilename(); + Glib::ustring get_filename(); protected: void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void on_cursor_changed(); @@ -292,9 +292,9 @@ public: * @param fileTypes one of FileDialogTypes * @param title the title of the dialog */ - FileImportFromOCALDialog(Gtk::Window& parentWindow, + FileImportFromOCALDialog(Gtk::Window& parent_window, const Glib::ustring &dir, - FileDialogType fileTypes, + FileDialogType file_types, const Glib::ustring &title); /** @@ -314,36 +314,35 @@ public: * @return a pointer to a string if successful (which must * be later freed with g_free(), else NULL. */ - Inkscape::Extension::Extension *getSelectionType(); + Inkscape::Extension::Extension *get_selection_type(); - Glib::ustring getFilename(); + Glib::ustring get_filename(); private: /** * Allow the user to type the tag to be searched */ - Gtk::Entry *searchTagEntry; - FileListViewText *filesList; - SVGPreview *filesPreview; - Gtk::Label *notFoundLabel; - Gtk::Label *descriptionLabel; - Gtk::Button *searchButton; - Gtk::Button *okButton; + Gtk::Entry *entry_search; + FileListViewText *list_files; + SVGPreview *preview_files; + Gtk::Label *label_not_found; + Gtk::Label *label_description; + Gtk::Button *button_search; + Gtk::Button *button_ok; // Child widgets - Gtk::HBox tagBox; - Gtk::HBox filesBox; - Gtk::HBox messageBox; - Gtk::HBox descriptionBox; - Gtk::ScrolledWindow listScrolledWindow; + Gtk::HBox hbox_tags; + Gtk::HBox hbox_files; + Gtk::HBox hbox_message; + Gtk::HBox hbox_description; + Gtk::ScrolledWindow scrolledwindow_list; Glib::RefPtr selection; /** * Callback for user input into searchTagEntry */ - void searchTagEntryChangedCallback(); - + void on_entry_search_changed(); /** * Prints the names of the all the xml elements -- cgit v1.2.3 From 7094db0b168d665a5ba16a16e6da4f8b5376ed96 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 11 Mar 2011 19:35:36 +0000 Subject: added back size request :) added shadow, made vscrollbar always appear, and removed column headers from the file list (bzr r10092.1.5) --- src/ui/dialog/ocaldialogs.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index ba999788b..bfbeed2cd 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -592,10 +592,13 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, list_files->set_sensitive(false); /// Add the listview inside a ScrolledWindow scrolledwindow_list.add(*list_files); + scrolledwindow_list.set_shadow_type(Gtk::SHADOW_IN); /// Only show the scrollbars when they are necessary - scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS); list_files->set_column_title(0, _("Files found")); + scrolledwindow_list.set_size_request(400, 180); + list_files->set_headers_visible(false); list_files->get_column(1)->set_visible(false); // file url list_files->get_column(2)->set_visible(false); // tmp file path list_files->get_column(3)->set_visible(false); // author dir @@ -616,17 +619,15 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, vbox->pack_start(hbox_message, false, false); vbox->pack_start(hbox_files, true, true); vbox->pack_start(hbox_description, false, false); - - // Let's do some customization + + // Signals entry_search = NULL; Gtk::Container *cont = get_toplevel(); std::vector entries; findEntryWidgets(cont, entries); - // Signals - if (entries.size() >=1 ) - { - //Catch when user hits [return] on the text field + if (entries.size() >=1 ) { + /// Catch when user hits [return] on the text field entry_search = entries[0]; entry_search->signal_activate().connect( sigc::mem_fun(*this, &FileImportFromOCALDialog::on_entry_search_changed)); -- cgit v1.2.3 From 9a4cab47277be3893b646bb9a6396fe3048c7b15 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 11 Mar 2011 20:18:59 +0000 Subject: removed message and description labels (bzr r10092.1.6) --- src/ui/dialog/ocaldialogs.cpp | 23 +++++++---------------- src/ui/dialog/ocaldialogs.h | 4 +--- 2 files changed, 8 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index bfbeed2cd..0b2d3a299 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -437,7 +437,6 @@ void FileImportFromOCALDialog::on_entry_search_changed() return; label_not_found->hide(); - label_description->set_text(""); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring search_keywords = entry_search->get_text(); @@ -565,7 +564,7 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, // Creation Gtk::VBox *vbox = get_vbox(); - label_not_found = new Gtk::Label(_("No files matched your search")); + label_not_found = new Gtk::Label(); label_description = new Gtk::Label(); entry_search = new Gtk::Entry(); button_search = new Gtk::Button(_("Search")); @@ -573,30 +572,26 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, preview_files = new SVGPreview(); /// Add the buttons in the bottom of the dialog add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - button_ok = add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); - list_files = new FileListViewText(5, *preview_files, *label_description, *button_ok); + button_import = add_button(_("Import"), Gtk::RESPONSE_OK); + list_files = new FileListViewText(5, *preview_files, *label_description, *button_import); // Properties set_border_width(12); - set_default_size(480, 350); + set_default_size(480, 320); vbox->set_spacing(12); - label_description->set_max_width_chars(260); - label_description->set_size_request(500, -1); - label_description->set_single_line_mode(false); - label_description->set_line_wrap(true); entry_search->set_text(search_keywords); entry_search->set_max_length(255); hbox_tags.set_spacing(6); preview_files->showNoPreview(); - set_default(*button_ok); + set_default(*button_import); list_files->set_sensitive(false); /// Add the listview inside a ScrolledWindow scrolledwindow_list.add(*list_files); scrolledwindow_list.set_shadow_type(Gtk::SHADOW_IN); /// Only show the scrollbars when they are necessary - scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS); + scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); list_files->set_column_title(0, _("Files found")); - scrolledwindow_list.set_size_request(400, 180); + scrolledwindow_list.set_size_request(310, 230); list_files->set_headers_visible(false); list_files->get_column(1)->set_visible(false); // file url @@ -608,17 +603,13 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, label_not_found->hide(); // Packing - hbox_message.pack_start(*label_not_found, false, false); - hbox_description.pack_start(*label_description, false, false); hbuttonbox_search->pack_start(*button_search, false, false); hbox_tags.pack_start(*entry_search, true, true); hbox_tags.pack_start(*hbuttonbox_search, false, false); hbox_files.pack_start(scrolledwindow_list, true, true); hbox_files.pack_start(*preview_files, true, true); vbox->pack_start(hbox_tags, false, false); - vbox->pack_start(hbox_message, false, false); vbox->pack_start(hbox_files, true, true); - vbox->pack_start(hbox_description, false, false); // Signals entry_search = NULL; diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 2826e0fdd..ddb8c1499 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -329,13 +329,11 @@ private: Gtk::Label *label_not_found; Gtk::Label *label_description; Gtk::Button *button_search; - Gtk::Button *button_ok; + Gtk::Button *button_import; // Child widgets Gtk::HBox hbox_tags; Gtk::HBox hbox_files; - Gtk::HBox hbox_message; - Gtk::HBox hbox_description; Gtk::ScrolledWindow scrolledwindow_list; Glib::RefPtr selection; -- cgit v1.2.3 From d643c9d4c725c32f7084e7d59d60e6e897819c89 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sun, 13 Mar 2011 07:55:20 +0000 Subject: Added OCAL namespace within Dialog namespace (bzr r10092.1.7) --- src/file.cpp | 8 ++--- src/ui/dialog/ocaldialogs.cpp | 76 +++++++++++++++++++++---------------------- src/ui/dialog/ocaldialogs.h | 40 ++++++++++++----------- 3 files changed, 63 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/file.cpp b/src/file.cpp index d997a72f7..967c59b08 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1328,8 +1328,8 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) export_path = export_path_local; // Show the Export To OCAL dialog - Inkscape::UI::Dialog::FileExportToOCALDialog *exportDialogInstance = - new Inkscape::UI::Dialog::FileExportToOCALDialog( + Inkscape::UI::Dialog::OCAL:ExportDialog *exportDialogInstance = + new Inkscape::UI::Dialog::OCAL:ExportDialog parentWindow, Inkscape::UI::Dialog::EXPORT_TYPES, (char const *) _("Select file to export to") @@ -1452,11 +1452,11 @@ sp_file_import_from_ocal(Gtk::Window &parent_window) if (!doc) return; - Inkscape::UI::Dialog::FileImportFromOCALDialog *import_dialog = NULL; + Inkscape::UI::Dialog::OCAL::ImportDialog *import_dialog = NULL; if (!import_dialog) { import_dialog = new - Inkscape::UI::Dialog::FileImportFromOCALDialog( + Inkscape::UI::Dialog::OCAL::ImportDialog( parent_window, import_path, Inkscape::UI::Dialog::IMPORT_TYPES, diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 0b2d3a299..9662cc08b 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -33,6 +33,8 @@ namespace UI { namespace Dialog { +namespace OCAL +{ //######################################################################## //# F I L E E X P O R T T O O C A L @@ -42,7 +44,7 @@ namespace Dialog * Callback for fileNameEntry widget */ /* -void FileExportToOCALDialog::fileNameEntryChangedCallback() +void ExportDialog::fileNameEntryChangedCallback() { if (!fileNameEntry) return; @@ -59,10 +61,10 @@ void FileExportToOCALDialog::fileNameEntryChangedCallback() * Constructor */ /* -FileExportToOCALDialog::FileExportToOCALDialog(Gtk::Window &parentWindow, +ExportDialog::ExportDialog(Gtk::Window &parentWindow, FileDialogType fileTypes, const Glib::ustring &title) : - FileDialogOCALBase(title, parentWindow) + FileDialogBase(title, parentWindow) { */ /* @@ -102,7 +104,7 @@ FileExportToOCALDialog::FileExportToOCALDialog(Gtk::Window &parentWindow, //Catch when user hits [return] on the text field fileNameEntry = entries[0]; fileNameEntry->signal_activate().connect( - sigc::mem_fun(*this, &FileExportToOCALDialog::fileNameEntryChangedCallback) ); + sigc::mem_fun(*this, &ExportDialog::fileNameEntryChangedCallback) ); } add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); @@ -115,7 +117,7 @@ FileExportToOCALDialog::FileExportToOCALDialog(Gtk::Window &parentWindow, * Destructor */ /* -FileExportToOCALDialog::~FileExportToOCALDialog() +ExportDialog::~ExportDialog() { } */ @@ -124,7 +126,7 @@ FileExportToOCALDialog::~FileExportToOCALDialog() */ /* bool -FileExportToOCALDialog::show() +ExportDialog::show() { set_modal (TRUE); //Window sp_transientize((GtkWidget *)gobj()); //Make transient @@ -146,7 +148,7 @@ FileExportToOCALDialog::show() */ /* Glib::ustring -FileExportToOCALDialog::get_filename() +ExportDialog::get_filename() { myFilename = fileNameEntry->get_text(); if (!Glib::get_charset()) //If we are not utf8 @@ -157,7 +159,7 @@ FileExportToOCALDialog::get_filename() void -FileExportToOCALDialog::change_title(const Glib::ustring& title) +ExportDialog::change_title(const Glib::ustring& title) { this->set_title(title); } @@ -172,8 +174,8 @@ FileExportToOCALDialog::change_title(const Glib::ustring& title) * Constructor */ /* -FileExportToOCALPasswordDialog::FileExportToOCALPasswordDialog(Gtk::Window &parentWindow, - const Glib::ustring &title) : FileDialogOCALBase(title, parentWindow) +ExportPasswordDialog::ExportPasswordDialog(Gtk::Window &parentWindow, + const Glib::ustring &title) : FileDialogBase(title, parentWindow) { */ /* @@ -220,7 +222,7 @@ FileExportToOCALPasswordDialog::FileExportToOCALPasswordDialog(Gtk::Window &pare * Destructor */ /* -FileExportToOCALPasswordDialog::~FileExportToOCALPasswordDialog() +ExportPasswordDialog::~ExportPasswordDialog() { } */ @@ -229,7 +231,7 @@ FileExportToOCALPasswordDialog::~FileExportToOCALPasswordDialog() */ /* bool -FileExportToOCALPasswordDialog::show() +ExportPasswordDialog::show() { set_modal (TRUE); //Window sp_transientize((GtkWidget *)gobj()); //Make transient @@ -251,7 +253,7 @@ FileExportToOCALPasswordDialog::show() */ /* Glib::ustring -FileExportToOCALPasswordDialog::getUsername() +ExportPasswordDialog::getUsername() { myUsername = usernameEntry->get_text(); return myUsername; @@ -262,14 +264,14 @@ FileExportToOCALPasswordDialog::getUsername() */ /* Glib::ustring -FileExportToOCALPasswordDialog::getPassword() +ExportPasswordDialog::getPassword() { myPassword = passwordEntry->get_text(); return myPassword; } void -FileExportToOCALPasswordDialog::change_title(const Glib::ustring& title) +ExportPasswordDialog::change_title(const Glib::ustring& title) { this->set_title(title); } @@ -280,7 +282,7 @@ FileExportToOCALPasswordDialog::change_title(const Glib::ustring& title) //######################################################################### /* - * Calalback for cursor chage + * Callback for cursor chage */ void FileListViewText::on_cursor_changed() { @@ -329,9 +331,9 @@ void FileListViewText::on_cursor_changed() //Glib::ustring fileUrl = "dav://"; //dav url //fileUrl.append(prefs->getString("/options/ocalurl/str")); //fileUrl.append("/dav.php/"); - //fileUrl.append(get_text(posArray[0], 3)); //author dir + //fileUrl.append(row[results_columns.CREATOR]); //author dir //fileUrl.append("/"); - //fileUrl.append(get_text(posArray[0], 2)); //filename + //fileUrl.append(row[results_columns.FILENAME]); //filename if (!Glib::get_charset()) //If we are not utf8 fileUrl = Glib::filename_to_utf8(fileUrl); @@ -431,7 +433,7 @@ static int vfs_read_callback (GnomeVFSHandle *handle, char* buf, int nb) /** * Callback for user input into entry_search */ -void FileImportFromOCALDialog::on_entry_search_changed() +void ImportDialog::on_entry_search_changed() { if (!entry_search) return; @@ -452,8 +454,8 @@ void FileImportFromOCALDialog::on_entry_search_changed() // open the rss feed gnome_vfs_init(); - GnomeVFSHandle *from_handle = NULL; - GnomeVFSResult result; + GnomeVFSHandle *from_handle = NULL; + GnomeVFSResult result; result = gnome_vfs_open (&from_handle, uri.c_str(), GNOME_VFS_OPEN_READ); if (result != GNOME_VFS_OK) { @@ -486,13 +488,12 @@ void FileImportFromOCALDialog::on_entry_search_changed() // print all xml the element names print_xml_element_names(root_element); - if (list_files->size() == 0) - { + if (list_files->size() == 0) { label_not_found->show(); list_files->set_sensitive(false); - } - else + } else { list_files->set_sensitive(true); + } // free the document xmlFreeDoc(doc); @@ -507,13 +508,13 @@ void FileImportFromOCALDialog::on_entry_search_changed() * Prints the names of the all the xml elements * that are siblings or children of a given xml node */ -void FileImportFromOCALDialog::print_xml_element_names(xmlNode * a_node) +void ImportDialog::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 + // Get items 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")) @@ -549,11 +550,11 @@ void FileImportFromOCALDialog::print_xml_element_names(xmlNode * a_node) /** * Constructor. Not called directly. Use the factory. */ -FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, +ImportDialog::ImportDialog(Gtk::Window& parent_window, const Glib::ustring &/*dir*/, FileDialogType file_types, const Glib::ustring &title) : - FileDialogOCALBase(title, parent_window) + FileDialogBase(title, parent_window) { // Initalize to Autodetect extension = NULL; @@ -621,11 +622,11 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, /// Catch when user hits [return] on the text field entry_search = entries[0]; entry_search->signal_activate().connect( - sigc::mem_fun(*this, &FileImportFromOCALDialog::on_entry_search_changed)); + sigc::mem_fun(*this, &ImportDialog::on_entry_search_changed)); } button_search->signal_clicked().connect( - sigc::mem_fun(*this, &FileImportFromOCALDialog::on_entry_search_changed)); + sigc::mem_fun(*this, &ImportDialog::on_entry_search_changed)); show_all_children(); } @@ -633,7 +634,7 @@ FileImportFromOCALDialog::FileImportFromOCALDialog(Gtk::Window& parent_window, /** * Destructor */ -FileImportFromOCALDialog::~FileImportFromOCALDialog() +ImportDialog::~ImportDialog() { } @@ -642,7 +643,7 @@ FileImportFromOCALDialog::~FileImportFromOCALDialog() * Show this dialog modally. Return true if user hits [OK] */ bool -FileImportFromOCALDialog::show() +ImportDialog::show() { set_modal (TRUE); //Window sp_transientize((GtkWidget *)gobj()); //Make transient @@ -664,7 +665,7 @@ FileImportFromOCALDialog::show() * Get the file extension type that was selected by the user. Valid after an [OK] */ Inkscape::Extension::Extension * -FileImportFromOCALDialog::get_selection_type() +ImportDialog::get_selection_type() { return extension; } @@ -674,18 +675,17 @@ FileImportFromOCALDialog::get_selection_type() * Get the file name chosen by the user. Valid after an [OK] */ Glib::ustring -FileImportFromOCALDialog::get_filename (void) +ImportDialog::get_filename (void) { return list_files->get_filename(); } +} //namespace OCAL } //namespace Dialog } //namespace UI } //namespace Inkscape - - /* Local Variables: mode:c++ diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index ddb8c1499..7ec2841ae 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -61,7 +61,8 @@ namespace UI { namespace Dialog { - +namespace OCAL +{ /*######################################################################### ### F I L E D I A L O G O C A L B A S E C L A S S #########################################################################*/ @@ -69,20 +70,20 @@ namespace Dialog /** * This class is the base implementation for export to OCAL. */ -class FileDialogOCALBase : public Gtk::Dialog +class FileDialogBase : public Gtk::Dialog { public: /** * Constructor */ - FileDialogOCALBase(const Glib::ustring &title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true) + FileDialogBase(const Glib::ustring &title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true) {} /* * Destructor */ - virtual ~FileDialogOCALBase() + virtual ~FileDialogBase() {} protected: @@ -103,10 +104,10 @@ protected: /** - * Our implementation of the FileExportToOCALDialog interface. + * Our implementation of the ExportDialog interface. */ /* -class FileExportToOCALDialog : public FileDialogOCALBase +class ExportDialog : public FileDialogBase { public: @@ -118,7 +119,7 @@ public: * @param key a list of file types from which the user can select */ /* - FileExportToOCALDialog(Gtk::Window& parentWindow, + ExportDialog(Gtk::Window& parentWindow, FileDialogType fileTypes, const Glib::ustring &title); */ @@ -127,7 +128,7 @@ public: * Perform any necessary cleanups. */ /* - ~FileExportToOCALDialog(); + ~ExportDialog(); */ /** * Show an SaveAs file selector. @@ -183,7 +184,7 @@ private: /* std::set knownExtensions; -}; //FileExportToOCAL +}; //ExportDialog */ //######################################################################## @@ -192,10 +193,10 @@ private: /** - * Our implementation of the FileExportToOCALPasswordDialog interface. + * Our implementation of the ExportPasswordDialog interface. */ /* -class FileExportToOCALPasswordDialog : public FileDialogOCALBase +class ExportPasswordDialog : public FileDialogBase { public: @@ -205,7 +206,7 @@ public: * @param title the title of the dialog */ /* - FileExportToOCALPasswordDialog(Gtk::Window& parentWindow, + ExportPasswordDialog(Gtk::Window& parentWindow, const Glib::ustring &title); */ /** @@ -213,7 +214,7 @@ public: * Perform any necessary cleanups. */ /* - ~FileExportToOCALPasswordDialog(); + ~ExportPasswordDialog(); */ /** @@ -248,7 +249,7 @@ private: Gtk::HBox userBox; Gtk::HBox passBox; -}; //FileExportToOCALPassword +}; //ExportPasswordDialog */ @@ -281,9 +282,9 @@ private: }; /** - * Our implementation class for the FileImportFromOCALDialog interface.. + * Our implementation class for the ImportDialog interface.. */ -class FileImportFromOCALDialog : public FileDialogOCALBase +class ImportDialog : public FileDialogBase { public: /** @@ -292,7 +293,7 @@ public: * @param fileTypes one of FileDialogTypes * @param title the title of the dialog */ - FileImportFromOCALDialog(Gtk::Window& parent_window, + ImportDialog(Gtk::Window& parent_window, const Glib::ustring &dir, FileDialogType file_types, const Glib::ustring &title); @@ -301,7 +302,7 @@ public: * Destructor. * Perform any necessary cleanups. */ - ~FileImportFromOCALDialog(); + ~ImportDialog(); /** * Show an OpenFile file selector. @@ -353,9 +354,10 @@ private: */ Inkscape::Extension::Extension *extension; -}; //FileImportFromOCALDialog +}; //ImportDialog +} //namespace OCAL } //namespace Dialog } //namespace UI } //namespace Inkscape -- cgit v1.2.3 From fe1dae30f8afa73420ea6df150de776965e7c71d Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sun, 13 Mar 2011 13:05:13 +0000 Subject: changed name to SearchResultList moved around some SearchResultList stuff into its constructor use an enum instead of arbitrary ints Use markup to diaplay information in list collect more data (date, thumbnail) (bzr r10092.1.8) --- src/ui/dialog/ocaldialogs.cpp | 131 +++++++++++++++++++++++++++++++----------- src/ui/dialog/ocaldialogs.h | 27 +++++---- 2 files changed, 114 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 9662cc08b..d44d655ec 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -281,10 +281,35 @@ ExportPasswordDialog::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### +SearchResultList::SearchResultList(guint columns_count, SVGPreview& filesPreview, + Gtk::Label& description, Gtk::Button& okButton) : ListViewText(columns_count) +{ + myPreview = &filesPreview; + myLabel = &description; + myButton = &okButton; + + set_headers_visible(false); + set_column_title(RESULTS_COLUMN_MARKUP, _("Clipart found")); + + Gtk::CellRenderer* cr_markup = get_column_cell_renderer(RESULTS_COLUMN_MARKUP); + cr_markup->set_property("ellipsize", Pango::ELLIPSIZE_END); + get_column(RESULTS_COLUMN_MARKUP)->clear_attributes(*cr_markup); + get_column(RESULTS_COLUMN_MARKUP)->add_attribute(*cr_markup, + "markup", RESULTS_COLUMN_MARKUP); + + get_column(RESULTS_COLUMN_TITLE)->set_visible(false); + get_column(RESULTS_COLUMN_DESCRIPTION)->set_visible(false); + get_column(RESULTS_COLUMN_CREATOR)->set_visible(false); + get_column(RESULTS_COLUMN_DATE)->set_visible(false); + get_column(RESULTS_COLUMN_FILENAME)->set_visible(false); + get_column(RESULTS_COLUMN_URL)->set_visible(false); + get_column(RESULTS_COLUMN_THUMBNAIL_URL)->set_visible(false); +} + /* * Callback for cursor chage */ -void FileListViewText::on_cursor_changed() +void SearchResultList::on_cursor_changed() { std::vector pathlist; pathlist = this->get_selection()->get_selected_rows(); @@ -316,7 +341,7 @@ void FileListViewText::on_cursor_changed() // make sure we don't collide with other users on the same machine myFilename = tmpname; myFilename.append("-"); - myFilename.append(get_text(posArray[0], 2)); + myFilename.append(get_text(posArray[0], RESULTS_COLUMN_FILENAME)); // rename based on original image's name, retaining extension if (rename(tmpname.c_str(),myFilename.c_str())<0) { unlink(tmpname.c_str()); @@ -325,7 +350,7 @@ void FileListViewText::on_cursor_changed() } //get file url - fileUrl = get_text(posArray[0], 1); //http url + fileUrl = get_text(posArray[0], RESULTS_COLUMN_URL); //http url //Inkscape::Preferences *prefs = Inkscape::Preferences::get(); //Glib::ustring fileUrl = "dav://"; //dav url @@ -377,7 +402,7 @@ void FileListViewText::on_cursor_changed() } } myPreview->showImage(myFilename); - myLabel->set_text(get_text(posArray[0], 4)); + myLabel->set_text(get_text(posArray[0], RESULTS_COLUMN_TITLE)); #endif return; fail: @@ -390,7 +415,7 @@ failquit: /* * Callback for row activated */ -void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& /*path*/, Gtk::TreeViewColumn* /*column*/) +void SearchResultList::on_row_activated(const Gtk::TreeModel::Path& /*path*/, Gtk::TreeViewColumn* /*column*/) { this->on_cursor_changed(); myButton->activate(); @@ -400,7 +425,7 @@ void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& /*path*/, Gt /* * Returns the selected filename */ -Glib::ustring FileListViewText::get_filename() +Glib::ustring SearchResultList::get_filename() { return myFilename; } @@ -481,18 +506,25 @@ void ImportDialog::on_entry_search_changed() // get the root element node root_element = xmlDocGetRootElement(doc); - // clear the list_files - list_files->clear_items(); - list_files->set_sensitive(false); + // clear the list_results + list_results->clear_items(); + list_results->set_sensitive(false); // print all xml the element names print_xml_element_names(root_element); - if (list_files->size() == 0) { + if (list_results->size() == 0) { label_not_found->show(); - list_files->set_sensitive(false); + list_results->set_sensitive(false); } else { - list_files->set_sensitive(true); + for (guint i = 0; i <= list_results->size() - 1; i++) { + Glib::ustring title = list_results->get_text(i, RESULTS_COLUMN_TITLE); + Glib::ustring description = list_results->get_text(i, RESULTS_COLUMN_DESCRIPTION); + char* markup = g_markup_printf_escaped("%s\n%s", + title.c_str(), description.c_str()); + list_results->set_text(i, RESULTS_COLUMN_MARKUP, markup); + } + list_results->set_sensitive(true); } // free the document @@ -512,6 +544,7 @@ void ImportDialog::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 items information if (strcmp((const char*)cur_node->name, "rss")) // Avoid the root @@ -519,27 +552,63 @@ void ImportDialog::print_xml_element_names(xmlNode * a_node) { if (!strcmp((const char*)cur_node->name, "title")) { - xmlChar *title = xmlNodeGetContent(cur_node); - row_num = list_files->append_text((const char*)title); + row_num = list_results->append_text(""); + xmlChar *xml_title = xmlNodeGetContent(cur_node); + char* title = (char*) xml_title; + + list_results->set_text(row_num, RESULTS_COLUMN_TITLE, title); xmlFree(title); } #ifdef WITH_GNOME_VFS - else if (!strcmp((const char*)cur_node->name, "enclosure")) + else if (!strcmp((const char*)cur_node->name, "pubDate")) { - xmlChar *urlattribute = xmlGetProp(cur_node, (xmlChar*)"url"); - list_files->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)); - list_files->set_text(row_num, 2, (const char*)tmp_file); - xmlFree(urlattribute); + xmlChar *xml_date = xmlNodeGetContent(cur_node); + char* date = (char*) xml_date; + + list_results->set_text(row_num, RESULTS_COLUMN_DATE, date); + xmlFree(xml_date); } else if (!strcmp((const char*)cur_node->name, "creator")) { - list_files->set_text(row_num, 3, (const char*)xmlNodeGetContent(cur_node)); + xmlChar *xml_creator = xmlNodeGetContent(cur_node); + char* creator = (char*) xml_creator; + + list_results->set_text(row_num, RESULTS_COLUMN_CREATOR, creator); + xmlFree(xml_creator); } else if (!strcmp((const char*)cur_node->name, "description")) { - list_files->set_text(row_num, 4, (const char*)xmlNodeGetContent(cur_node)); + xmlChar *xml_description = xmlNodeGetContent(cur_node); + //char* final_description; + char* stripped_description = g_strstrip((char*) xml_description); + + if (!strcmp(stripped_description, "")) { + stripped_description = _("No description"); + } + + //GRegex* regex = g_regex_new(g_regex_escape_string(stripped_description, -1)); + //final_description = g_regex_replace_literal(regex, "\n", -1, 0, " "); + + list_results->set_text(row_num, RESULTS_COLUMN_DESCRIPTION, stripped_description); + xmlFree(xml_description); + } + else if (!strcmp((const char*)cur_node->name, "enclosure")) + { + xmlChar *xml_url = xmlGetProp(cur_node, (xmlChar*) "url"); + char* url = (char*) xml_url; + char* filename = gnome_vfs_uri_extract_short_path_name(gnome_vfs_uri_new(url)); + + list_results->set_text(row_num, RESULTS_COLUMN_URL, url); + list_results->set_text(row_num, RESULTS_COLUMN_FILENAME, filename); + xmlFree(xml_url); + } + else if (!strcmp((const char*)cur_node->name, "thumbnail")) + { + xmlChar *xml_thumbnail_url = xmlGetProp(cur_node, (xmlChar*) "url"); + char* thumbnail_url = (char*) xml_thumbnail_url; + + list_results->set_text(row_num, RESULTS_COLUMN_THUMBNAIL_URL, thumbnail_url); + xmlFree(xml_thumbnail_url); } #endif } @@ -574,7 +643,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, /// Add the buttons in the bottom of the dialog add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); button_import = add_button(_("Import"), Gtk::RESPONSE_OK); - list_files = new FileListViewText(5, *preview_files, *label_description, *button_import); + list_results = new SearchResultList(RESULTS_COLUMN_LENGTH, + *preview_files, *label_description, *button_import); // Properties set_border_width(12); @@ -585,21 +655,14 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, hbox_tags.set_spacing(6); preview_files->showNoPreview(); set_default(*button_import); - list_files->set_sensitive(false); + list_results->set_sensitive(false); /// Add the listview inside a ScrolledWindow - scrolledwindow_list.add(*list_files); + scrolledwindow_list.add(*list_results); scrolledwindow_list.set_shadow_type(Gtk::SHADOW_IN); /// Only show the scrollbars when they are necessary scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - list_files->set_column_title(0, _("Files found")); scrolledwindow_list.set_size_request(310, 230); - list_files->set_headers_visible(false); - list_files->get_column(1)->set_visible(false); // file url - list_files->get_column(2)->set_visible(false); // tmp file path - list_files->get_column(3)->set_visible(false); // author dir - list_files->get_column(4)->set_visible(false); // file description - hbox_files.set_spacing(12); label_not_found->hide(); @@ -677,7 +740,7 @@ ImportDialog::get_selection_type() Glib::ustring ImportDialog::get_filename (void) { - return list_files->get_filename(); + return list_results->get_filename(); } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 7ec2841ae..8d844cd26 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -257,19 +257,26 @@ private: //### F I L E I M P O R T F R O M O C A L //######################################################################### +enum { + RESULTS_COLUMN_MARKUP, + RESULTS_COLUMN_TITLE, + RESULTS_COLUMN_DESCRIPTION, + RESULTS_COLUMN_CREATOR, + RESULTS_COLUMN_DATE, + RESULTS_COLUMN_FILENAME, + RESULTS_COLUMN_URL, + RESULTS_COLUMN_THUMBNAIL_URL, + RESULTS_COLUMN_LENGTH, +}; + /** - * Our implementation class for filesListView + * The TreeView which holds the search results */ -class FileListViewText : public Gtk::ListViewText +class SearchResultList : public Gtk::ListViewText { public: - FileListViewText(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton) - :ListViewText(columns_count) - { - myPreview = &filesPreview; - myLabel = &description; - myButton = &okButton; - } + SearchResultList(guint columns_count, SVGPreview& filesPreview, + Gtk::Label& description, Gtk::Button& okButton); Glib::ustring get_filename(); protected: void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); @@ -325,7 +332,7 @@ private: * Allow the user to type the tag to be searched */ Gtk::Entry *entry_search; - FileListViewText *list_files; + SearchResultList *list_results; SVGPreview *preview_files; Gtk::Label *label_not_found; Gtk::Label *label_description; -- cgit v1.2.3 From 26f03fdf9866c4d8dc61c7827e04f0c6ef6a83eb Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sun, 13 Mar 2011 13:34:25 +0000 Subject: make print_xml_element_names an instance method of the SearchResultsList remove uneeded comments (bzr r10092.1.9) --- src/ui/dialog/ocaldialogs.cpp | 165 +++++++++++++++++++++--------------------- src/ui/dialog/ocaldialogs.h | 22 +----- 2 files changed, 86 insertions(+), 101 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index d44d655ec..ff1eeefa0 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -430,6 +430,86 @@ Glib::ustring SearchResultList::get_filename() return myFilename; } +/** + * Prints the names of the all the xml elements + * that are siblings or children of a given xml node + */ +void SearchResultList::populate_from_xml(xmlNode * a_node) +{ + xmlNode *cur_node = NULL; + guint row_num = 0; + + for (cur_node = a_node; cur_node; cur_node = cur_node->next) { + // Get items 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")) + { + row_num = append_text(""); + xmlChar *xml_title = xmlNodeGetContent(cur_node); + char* title = (char*) xml_title; + + set_text(row_num, RESULTS_COLUMN_TITLE, title); + xmlFree(title); + } +#ifdef WITH_GNOME_VFS + else if (!strcmp((const char*)cur_node->name, "pubDate")) + { + xmlChar *xml_date = xmlNodeGetContent(cur_node); + char* date = (char*) xml_date; + + set_text(row_num, RESULTS_COLUMN_DATE, date); + xmlFree(xml_date); + } + else if (!strcmp((const char*)cur_node->name, "creator")) + { + xmlChar *xml_creator = xmlNodeGetContent(cur_node); + char* creator = (char*) xml_creator; + + set_text(row_num, RESULTS_COLUMN_CREATOR, creator); + xmlFree(xml_creator); + } + else if (!strcmp((const char*)cur_node->name, "description")) + { + xmlChar *xml_description = xmlNodeGetContent(cur_node); + //char* final_description; + char* stripped_description = g_strstrip((char*) xml_description); + + if (!strcmp(stripped_description, "")) { + stripped_description = _("No description"); + } + + //GRegex* regex = g_regex_new(g_regex_escape_string(stripped_description, -1)); + //final_description = g_regex_replace_literal(regex, "\n", -1, 0, " "); + + set_text(row_num, RESULTS_COLUMN_DESCRIPTION, stripped_description); + xmlFree(xml_description); + } + else if (!strcmp((const char*)cur_node->name, "enclosure")) + { + xmlChar *xml_url = xmlGetProp(cur_node, (xmlChar*) "url"); + char* url = (char*) xml_url; + char* filename = gnome_vfs_uri_extract_short_path_name(gnome_vfs_uri_new(url)); + + set_text(row_num, RESULTS_COLUMN_URL, url); + set_text(row_num, RESULTS_COLUMN_FILENAME, filename); + xmlFree(xml_url); + } + else if (!strcmp((const char*)cur_node->name, "thumbnail")) + { + xmlChar *xml_thumbnail_url = xmlGetProp(cur_node, (xmlChar*) "url"); + char* thumbnail_url = (char*) xml_thumbnail_url; + + set_text(row_num, RESULTS_COLUMN_THUMBNAIL_URL, thumbnail_url); + xmlFree(xml_thumbnail_url); + } +#endif + } + populate_from_xml(cur_node->children); + } +} + #ifdef WITH_GNOME_VFS /** @@ -510,13 +590,13 @@ void ImportDialog::on_entry_search_changed() list_results->clear_items(); list_results->set_sensitive(false); - // print all xml the element names - print_xml_element_names(root_element); + list_results->populate_from_xml(root_element); if (list_results->size() == 0) { label_not_found->show(); list_results->set_sensitive(false); } else { + // Populate the MARKUP column with the title & description of the clipart for (guint i = 0; i <= list_results->size() - 1; i++) { Glib::ustring title = list_results->get_text(i, RESULTS_COLUMN_TITLE); Glib::ustring description = list_results->get_text(i, RESULTS_COLUMN_DESCRIPTION); @@ -535,87 +615,6 @@ void ImportDialog::on_entry_search_changed() #endif } - -/** - * Prints the names of the all the xml elements - * that are siblings or children of a given xml node - */ -void ImportDialog::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 items 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")) - { - row_num = list_results->append_text(""); - xmlChar *xml_title = xmlNodeGetContent(cur_node); - char* title = (char*) xml_title; - - list_results->set_text(row_num, RESULTS_COLUMN_TITLE, title); - xmlFree(title); - } -#ifdef WITH_GNOME_VFS - else if (!strcmp((const char*)cur_node->name, "pubDate")) - { - xmlChar *xml_date = xmlNodeGetContent(cur_node); - char* date = (char*) xml_date; - - list_results->set_text(row_num, RESULTS_COLUMN_DATE, date); - xmlFree(xml_date); - } - else if (!strcmp((const char*)cur_node->name, "creator")) - { - xmlChar *xml_creator = xmlNodeGetContent(cur_node); - char* creator = (char*) xml_creator; - - list_results->set_text(row_num, RESULTS_COLUMN_CREATOR, creator); - xmlFree(xml_creator); - } - else if (!strcmp((const char*)cur_node->name, "description")) - { - xmlChar *xml_description = xmlNodeGetContent(cur_node); - //char* final_description; - char* stripped_description = g_strstrip((char*) xml_description); - - if (!strcmp(stripped_description, "")) { - stripped_description = _("No description"); - } - - //GRegex* regex = g_regex_new(g_regex_escape_string(stripped_description, -1)); - //final_description = g_regex_replace_literal(regex, "\n", -1, 0, " "); - - list_results->set_text(row_num, RESULTS_COLUMN_DESCRIPTION, stripped_description); - xmlFree(xml_description); - } - else if (!strcmp((const char*)cur_node->name, "enclosure")) - { - xmlChar *xml_url = xmlGetProp(cur_node, (xmlChar*) "url"); - char* url = (char*) xml_url; - char* filename = gnome_vfs_uri_extract_short_path_name(gnome_vfs_uri_new(url)); - - list_results->set_text(row_num, RESULTS_COLUMN_URL, url); - list_results->set_text(row_num, RESULTS_COLUMN_FILENAME, filename); - xmlFree(xml_url); - } - else if (!strcmp((const char*)cur_node->name, "thumbnail")) - { - xmlChar *xml_thumbnail_url = xmlGetProp(cur_node, (xmlChar*) "url"); - char* thumbnail_url = (char*) xml_thumbnail_url; - - list_results->set_text(row_num, RESULTS_COLUMN_THUMBNAIL_URL, thumbnail_url); - xmlFree(xml_thumbnail_url); - } -#endif - } - print_xml_element_names(cur_node->children); - } -} - /** * Constructor. Not called directly. Use the factory. */ diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 8d844cd26..3e5d1effb 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -278,6 +278,7 @@ public: SearchResultList(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton); Glib::ustring get_filename(); + void populate_from_xml(xmlNode* a_node); protected: void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void on_cursor_changed(); @@ -289,7 +290,7 @@ private: }; /** - * Our implementation class for the ImportDialog interface.. + * The Import Dialog */ class ImportDialog : public FileDialogBase { @@ -300,10 +301,8 @@ public: * @param fileTypes one of FileDialogTypes * @param title the title of the dialog */ - ImportDialog(Gtk::Window& parent_window, - const Glib::ustring &dir, - FileDialogType file_types, - const Glib::ustring &title); + ImportDialog(Gtk::Window& parent_window, const Glib::ustring &dir, + FileDialogType file_types, const Glib::ustring &title); /** * Destructor. @@ -327,10 +326,6 @@ public: Glib::ustring get_filename(); private: - - /** - * Allow the user to type the tag to be searched - */ Gtk::Entry *entry_search; SearchResultList *list_results; SVGPreview *preview_files; @@ -345,17 +340,8 @@ private: Gtk::ScrolledWindow scrolledwindow_list; Glib::RefPtr selection; - /** - * Callback for user input into searchTagEntry - */ void on_entry_search_changed(); - /** - * 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 */ -- cgit v1.2.3 From f2f99f7bd1d90a1139bf218e3f8a715256fe95c7 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Wed, 16 Mar 2011 17:36:59 +0000 Subject: Added OCAL logo overlay (bzr r10092.1.10) --- src/ui/dialog/ocaldialogs.cpp | 70 +++++++++++++++++++++++++++++++++++++++---- src/ui/dialog/ocaldialogs.h | 21 +++++++++++-- 2 files changed, 83 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index ff1eeefa0..3e0887164 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -4,6 +4,7 @@ /* Authors: * Bruno Dilly * Other dudes from The Inkscape Organization + * Andrew Higginson * * Copyright (C) 2007 Bruno Dilly * @@ -281,6 +282,62 @@ ExportPasswordDialog::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### +LogoDrawingArea::LogoDrawingArea() : Gtk::DrawingArea() +{ + logo_mask = Cairo::ImageSurface::create_from_png("/home/andrew/Software/Launchpad/inkscape/ocal-dialog/share/icons/OCAL.png"); + signal_expose_event().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_expose_event)); + signal_style_changed().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_style_set)); +} + +void LogoDrawingArea::_on_style_set(const Glib::RefPtr& previous_style) +{ + Gdk::Color color = get_style()->get_mid(get_state()); + layout = this->create_pango_layout(""); + Glib::ustring markup = Glib::ustring::compose("%2", + color.to_string(), _("powered by")); + + layout->set_markup(markup); +} + +bool LogoDrawingArea::_on_expose_event(GdkEventExpose* event) +{ + Cairo::RefPtr cr = get_window()->create_cairo_context(); + + // Draw background and shadow + int width = get_allocation().get_width(); + int height = get_allocation().get_height(); + Gdk::Color background_fill = get_style()->get_base(get_state()); + + cr->rectangle(0, 0, width, height); + Gdk::Cairo::set_source_color(cr, background_fill); + cr->fill(); + + get_style()->paint_shadow(get_window(), get_state(), Gtk::SHADOW_IN, + Gdk::Rectangle(0, 0, width, height), + *this, Glib::ustring::ustring("viewport"), 0, 0, width, height); + + // Draw logo + Gdk::Color logo_fill = get_style()->get_mid(get_state()); + int x_logo = width - 12 - 127; + int y_logo = height - 12 - 44; + + Gdk::Cairo::set_source_color(cr, logo_fill); + cr->mask(logo_mask, x_logo, y_logo); + + // Draw text + Pango::Rectangle extents = layout->get_pixel_logical_extents(); + int text_width = extents.get_width(); + int text_height = extents.get_height(); + + int x_text = x_logo - text_width - 12; + int y_text = height - text_height - 12; + + get_style()->paint_layout(get_window(), get_state(), true, + Gdk::Rectangle(0, 0, width, height), *this, "", x_text, y_text, layout); + + return false; +} + SearchResultList::SearchResultList(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton) : ListViewText(columns_count) { @@ -538,7 +595,7 @@ static int vfs_read_callback (GnomeVFSHandle *handle, char* buf, int nb) /** * Callback for user input into entry_search */ -void ImportDialog::on_entry_search_changed() +void ImportDialog::on_entry_search_activated() { if (!entry_search) return; @@ -643,7 +700,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); button_import = add_button(_("Import"), Gtk::RESPONSE_OK); list_results = new SearchResultList(RESULTS_COLUMN_LENGTH, - *preview_files, *label_description, *button_import); + *preview_files, *label_description, *button_import); + LogoDrawingArea *drawingarea_logo = new LogoDrawingArea(); // Properties set_border_width(12); @@ -661,6 +719,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, /// Only show the scrollbars when they are necessary scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); scrolledwindow_list.set_size_request(310, 230); + drawingarea_logo->set_size_request(310, 230); hbox_files.set_spacing(12); label_not_found->hide(); @@ -669,7 +728,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, hbuttonbox_search->pack_start(*button_search, false, false); hbox_tags.pack_start(*entry_search, true, true); hbox_tags.pack_start(*hbuttonbox_search, false, false); - hbox_files.pack_start(scrolledwindow_list, true, true); + //hbox_files.pack_start(scrolledwindow_list, true, true); + hbox_files.pack_start(*drawingarea_logo, true, true); hbox_files.pack_start(*preview_files, true, true); vbox->pack_start(hbox_tags, false, false); vbox->pack_start(hbox_files, true, true); @@ -684,11 +744,11 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, /// Catch when user hits [return] on the text field entry_search = entries[0]; entry_search->signal_activate().connect( - sigc::mem_fun(*this, &ImportDialog::on_entry_search_changed)); + sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); } button_search->signal_clicked().connect( - sigc::mem_fun(*this, &ImportDialog::on_entry_search_changed)); + sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); show_all_children(); } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 3e5d1effb..8003e7fb8 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -4,6 +4,7 @@ /* Authors: * Bruno Dilly * Inkscape Guys + * Andrew Higginson * * Copyright (C) 2007 Bruno Dilly * Released under GNU GPL, read the file 'COPYING' for more information @@ -257,6 +258,21 @@ private: //### F I L E I M P O R T F R O M O C A L //######################################################################### + +/** + * A box which paints an overlay of the OCAL logo + */ +class LogoDrawingArea : public Gtk::DrawingArea +{ +public: + LogoDrawingArea(); +private: + bool _on_expose_event(GdkEventExpose* event); + void _on_style_set(const Glib::RefPtr& previous_style); + Cairo::RefPtr logo_mask; + Glib::RefPtr layout; +}; + enum { RESULTS_COLUMN_MARKUP, RESULTS_COLUMN_TITLE, @@ -279,10 +295,9 @@ public: Gtk::Label& description, Gtk::Button& okButton); Glib::ustring get_filename(); void populate_from_xml(xmlNode* a_node); -protected: +private: void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void on_cursor_changed(); -private: Glib::ustring myFilename; SVGPreview *myPreview; Gtk::Label *myLabel; @@ -340,7 +355,7 @@ private: Gtk::ScrolledWindow scrolledwindow_list; Glib::RefPtr selection; - void on_entry_search_changed(); + void on_entry_search_activated(); /** * The extension to use to write this file -- cgit v1.2.3 From 7fe65c9e6811f9c01e5c0f36f531ec258ccb21c6 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Thu, 17 Mar 2011 18:56:21 +0000 Subject: added custom searchentry (bzr r10092.1.11) --- src/ui/dialog/ocaldialogs.cpp | 95 ++++++++++++++++++++++++++++++++++++------- src/ui/dialog/ocaldialogs.h | 25 +++++++++++- 2 files changed, 104 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 3e0887164..f7f4095d5 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -282,6 +282,79 @@ ExportPasswordDialog::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### +SearchEntry::SearchEntry(Glib::ustring hint_string) : Gtk::Entry() +{ + signal_icon_press().connect(sigc::mem_fun(*this, &SearchEntry::_on_icon_pressed)); + signal_focus_in_event().connect(sigc::mem_fun(*this, &SearchEntry::_on_focus_in_event)); + signal_focus_out_event().connect(sigc::mem_fun(*this, &SearchEntry::_on_focus_out_event)); + + set_icon_from_stock(Gtk::Stock::FIND, Gtk::ENTRY_ICON_PRIMARY); + set_icon_from_stock(0, Gtk::ENTRY_ICON_SECONDARY); + + this->hint_string = hint_string; + + normal_text_colour = get_style()->get_text(get_state()); + hinted_text_colour = get_style()->get_text_aa(get_state()); + + hint(); +} + +void SearchEntry::hint() { + set_text(hint_string); + + modify_text(get_state(), hinted_text_colour); + + Pango::FontDescription* italic = new Pango::FontDescription("italic"); + modify_font(*italic); +} + +void SearchEntry::unhint() { + set_text(""); + + modify_text(get_state(), normal_text_colour); + + Pango::FontDescription* normal = new Pango::FontDescription("italic"); + modify_font(*normal); +} + +void SearchEntry::_on_icon_pressed(Gtk::EntryIconPosition icon_position, + const GdkEventButton* event) +{ + if (icon_position == Gtk::ENTRY_ICON_SECONDARY) { + grab_focus(); + set_text(""); + } else if (icon_position == Gtk::ENTRY_ICON_PRIMARY) { + select_region(0, -1); + grab_focus(); + } +} + + +bool SearchEntry::_on_focus_in_event(GdkEventFocus* event) +{ + if (get_text() == hint_string) { + unhint(); + } + return false; +} + +bool SearchEntry::_on_focus_out_event(GdkEventFocus* event) +{ + if (get_text().empty()) { + unhint(); + } + return false; +} + +void SearchEntry::_on_changed() +{ + if ((get_text() == hint_string) | get_text().empty()) { + set_icon_from_stock(0, Gtk::ENTRY_ICON_SECONDARY); + } else { + set_icon_from_stock(Gtk::Stock::CLEAR, Gtk::ENTRY_ICON_SECONDARY); + } +} + LogoDrawingArea::LogoDrawingArea() : Gtk::DrawingArea() { logo_mask = Cairo::ImageSurface::create_from_png("/home/andrew/Software/Launchpad/inkscape/ocal-dialog/share/icons/OCAL.png"); @@ -294,7 +367,7 @@ void LogoDrawingArea::_on_style_set(const Glib::RefPtr& previous_sty Gdk::Color color = get_style()->get_mid(get_state()); layout = this->create_pango_layout(""); Glib::ustring markup = Glib::ustring::compose("%2", - color.to_string(), _("powered by")); + color.to_string(), _("Powered by")); layout->set_markup(markup); } @@ -316,7 +389,8 @@ bool LogoDrawingArea::_on_expose_event(GdkEventExpose* event) Gdk::Rectangle(0, 0, width, height), *this, Glib::ustring::ustring("viewport"), 0, 0, width, height); - // Draw logo + // Draw logo, we mask [read fill] it with the mid colour from the + // user's GTK theme Gdk::Color logo_fill = get_style()->get_mid(get_state()); int x_logo = width - 12 - 127; int y_logo = height - 12 - 44; @@ -692,7 +766,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, Gtk::VBox *vbox = get_vbox(); label_not_found = new Gtk::Label(); label_description = new Gtk::Label(); - entry_search = new Gtk::Entry(); + entry_search = new SearchEntry(_("Enter keywords here...")); button_search = new Gtk::Button(_("Search")); Gtk::HButtonBox* hbuttonbox_search = new Gtk::HButtonBox(); preview_files = new SVGPreview(); @@ -707,7 +781,6 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, set_border_width(12); set_default_size(480, 320); vbox->set_spacing(12); - entry_search->set_text(search_keywords); entry_search->set_max_length(255); hbox_tags.set_spacing(6); preview_files->showNoPreview(); @@ -735,22 +808,14 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, vbox->pack_start(hbox_files, true, true); // Signals - entry_search = NULL; - Gtk::Container *cont = get_toplevel(); - std::vector entries; - findEntryWidgets(cont, entries); - - if (entries.size() >=1 ) { - /// Catch when user hits [return] on the text field - entry_search = entries[0]; - entry_search->signal_activate().connect( - sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); - } + entry_search->signal_activate().connect( + sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); button_search->signal_clicked().connect( sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); show_all_children(); + entry_search->grab_focus(); } /** diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 8003e7fb8..c6e31fa33 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -259,6 +259,29 @@ private: //######################################################################### +/** + * A Gtk::Entry with a grey hint text in it, and search & clear icons + */ +class SearchEntry : public Gtk::Entry +{ +public: + SearchEntry(Glib::ustring hint_string); + +private: + void _on_icon_pressed(Gtk::EntryIconPosition icon_position, const GdkEventButton* event); + void _on_changed(); + bool _on_focus_in_event(GdkEventFocus* event); + bool _on_focus_out_event(GdkEventFocus* event); + + void hint(); + void unhint(); + + Gdk::Color hinted_text_colour; + Gdk::Color normal_text_colour; + Glib::ustring hint_string; + +}; + /** * A box which paints an overlay of the OCAL logo */ @@ -341,7 +364,7 @@ public: Glib::ustring get_filename(); private: - Gtk::Entry *entry_search; + SearchEntry *entry_search; SearchResultList *list_results; SVGPreview *preview_files; Gtk::Label *label_not_found; -- cgit v1.2.3 From ed9e69f79cfdbd722e1b62dff38c04e5855cf64a Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 18 Mar 2011 16:49:58 +0000 Subject: Remove SearchEntry hinting ability (not appropriate/useful in this scenario) Get clearing of icon to work (bzr r10092.1.12) --- src/ui/dialog/ocaldialogs.cpp | 102 ++++++++++++------------------------------ src/ui/dialog/ocaldialogs.h | 22 +++++---- 2 files changed, 39 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index f7f4095d5..0294c5baa 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -282,43 +282,16 @@ ExportPasswordDialog::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### -SearchEntry::SearchEntry(Glib::ustring hint_string) : Gtk::Entry() +SearchEntry::SearchEntry() : Gtk::Entry() { + signal_changed().connect(sigc::mem_fun(*this, &SearchEntry::_on_changed)); signal_icon_press().connect(sigc::mem_fun(*this, &SearchEntry::_on_icon_pressed)); - signal_focus_in_event().connect(sigc::mem_fun(*this, &SearchEntry::_on_focus_in_event)); - signal_focus_out_event().connect(sigc::mem_fun(*this, &SearchEntry::_on_focus_out_event)); set_icon_from_stock(Gtk::Stock::FIND, Gtk::ENTRY_ICON_PRIMARY); - set_icon_from_stock(0, Gtk::ENTRY_ICON_SECONDARY); - - this->hint_string = hint_string; - - normal_text_colour = get_style()->get_text(get_state()); - hinted_text_colour = get_style()->get_text_aa(get_state()); - - hint(); -} - -void SearchEntry::hint() { - set_text(hint_string); - - modify_text(get_state(), hinted_text_colour); - - Pango::FontDescription* italic = new Pango::FontDescription("italic"); - modify_font(*italic); -} - -void SearchEntry::unhint() { - set_text(""); - - modify_text(get_state(), normal_text_colour); - - Pango::FontDescription* normal = new Pango::FontDescription("italic"); - modify_font(*normal); + gtk_entry_set_icon_from_stock(gobj(), GTK_ENTRY_ICON_SECONDARY, NULL); } -void SearchEntry::_on_icon_pressed(Gtk::EntryIconPosition icon_position, - const GdkEventButton* event) +void SearchEntry::_on_icon_pressed(Gtk::EntryIconPosition icon_position, const GdkEventButton* event) { if (icon_position == Gtk::ENTRY_ICON_SECONDARY) { grab_focus(); @@ -329,27 +302,10 @@ void SearchEntry::_on_icon_pressed(Gtk::EntryIconPosition icon_position, } } - -bool SearchEntry::_on_focus_in_event(GdkEventFocus* event) -{ - if (get_text() == hint_string) { - unhint(); - } - return false; -} - -bool SearchEntry::_on_focus_out_event(GdkEventFocus* event) -{ - if (get_text().empty()) { - unhint(); - } - return false; -} - void SearchEntry::_on_changed() { - if ((get_text() == hint_string) | get_text().empty()) { - set_icon_from_stock(0, Gtk::ENTRY_ICON_SECONDARY); + if (get_text().empty()) { + gtk_entry_set_icon_from_stock(gobj(), GTK_ENTRY_ICON_SECONDARY, NULL); } else { set_icon_from_stock(Gtk::Stock::CLEAR, Gtk::ENTRY_ICON_SECONDARY); } @@ -671,10 +627,8 @@ static int vfs_read_callback (GnomeVFSHandle *handle, char* buf, int nb) */ void ImportDialog::on_entry_search_activated() { - if (!entry_search) - return; + notebook_content->set_current_page(NOTEBOOK_PAGE_LOGO); - label_not_found->hide(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring search_keywords = entry_search->get_text(); @@ -719,23 +673,21 @@ void ImportDialog::on_entry_search_activated() // clear the list_results list_results->clear_items(); - list_results->set_sensitive(false); list_results->populate_from_xml(root_element); if (list_results->size() == 0) { - label_not_found->show(); - list_results->set_sensitive(false); + notebook_content->set_current_page(NOTEBOOK_PAGE_NOT_FOUND); } else { // Populate the MARKUP column with the title & description of the clipart for (guint i = 0; i <= list_results->size() - 1; i++) { Glib::ustring title = list_results->get_text(i, RESULTS_COLUMN_TITLE); Glib::ustring description = list_results->get_text(i, RESULTS_COLUMN_DESCRIPTION); - char* markup = g_markup_printf_escaped("%s\n%s", + char* markup = g_markup_printf_escaped("%s\n%s", title.c_str(), description.c_str()); list_results->set_text(i, RESULTS_COLUMN_MARKUP, markup); } - list_results->set_sensitive(true); + notebook_content->set_current_page(NOTEBOOK_PAGE_RESULTS); } // free the document @@ -766,7 +718,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, Gtk::VBox *vbox = get_vbox(); label_not_found = new Gtk::Label(); label_description = new Gtk::Label(); - entry_search = new SearchEntry(_("Enter keywords here...")); + entry_search = new SearchEntry(); button_search = new Gtk::Button(_("Search")); Gtk::HButtonBox* hbuttonbox_search = new Gtk::HButtonBox(); preview_files = new SVGPreview(); @@ -775,7 +727,21 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, button_import = add_button(_("Import"), Gtk::RESPONSE_OK); list_results = new SearchResultList(RESULTS_COLUMN_LENGTH, *preview_files, *label_description, *button_import); - LogoDrawingArea *drawingarea_logo = new LogoDrawingArea(); + drawingarea_logo = new LogoDrawingArea(); + notebook_content = new Gtk::Notebook(); + + // Packing + hbuttonbox_search->pack_start(*button_search, false, false); + hbox_tags.pack_start(*entry_search, true, true); + hbox_tags.pack_start(*hbuttonbox_search, false, false); + hbox_files.pack_start(*notebook_content, true, true); + hbox_files.pack_start(*preview_files, true, true); + vbox->pack_start(hbox_tags, false, false); + vbox->pack_start(hbox_files, true, true); + + notebook_content->insert_page(*drawingarea_logo, NOTEBOOK_PAGE_LOGO); + notebook_content->insert_page(scrolledwindow_list, NOTEBOOK_PAGE_RESULTS); + notebook_content->insert_page(*label_not_found, NOTEBOOK_PAGE_NOT_FOUND); // Properties set_border_width(12); @@ -785,7 +751,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, hbox_tags.set_spacing(6); preview_files->showNoPreview(); set_default(*button_import); - list_results->set_sensitive(false); + notebook_content->set_current_page(NOTEBOOK_PAGE_LOGO); /// Add the listview inside a ScrolledWindow scrolledwindow_list.add(*list_results); scrolledwindow_list.set_shadow_type(Gtk::SHADOW_IN); @@ -793,19 +759,9 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); scrolledwindow_list.set_size_request(310, 230); drawingarea_logo->set_size_request(310, 230); - hbox_files.set_spacing(12); - label_not_found->hide(); - - // Packing - hbuttonbox_search->pack_start(*button_search, false, false); - hbox_tags.pack_start(*entry_search, true, true); - hbox_tags.pack_start(*hbuttonbox_search, false, false); - //hbox_files.pack_start(scrolledwindow_list, true, true); - hbox_files.pack_start(*drawingarea_logo, true, true); - hbox_files.pack_start(*preview_files, true, true); - vbox->pack_start(hbox_tags, false, false); - vbox->pack_start(hbox_files, true, true); + notebook_content->set_show_tabs(false); + notebook_content->set_show_border(false); // Signals entry_search->signal_activate().connect( diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index c6e31fa33..89da69357 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -260,26 +260,16 @@ private: /** - * A Gtk::Entry with a grey hint text in it, and search & clear icons + * A Gtk::Entry with search & clear icons */ class SearchEntry : public Gtk::Entry { public: - SearchEntry(Glib::ustring hint_string); + SearchEntry(); private: void _on_icon_pressed(Gtk::EntryIconPosition icon_position, const GdkEventButton* event); void _on_changed(); - bool _on_focus_in_event(GdkEventFocus* event); - bool _on_focus_out_event(GdkEventFocus* event); - - void hint(); - void unhint(); - - Gdk::Color hinted_text_colour; - Gdk::Color normal_text_colour; - Glib::ustring hint_string; - }; /** @@ -308,6 +298,12 @@ enum { RESULTS_COLUMN_LENGTH, }; +enum { + NOTEBOOK_PAGE_LOGO, + NOTEBOOK_PAGE_RESULTS, + NOTEBOOK_PAGE_NOT_FOUND, +}; + /** * The TreeView which holds the search results */ @@ -365,6 +361,7 @@ public: private: SearchEntry *entry_search; + LogoDrawingArea *drawingarea_logo; SearchResultList *list_results; SVGPreview *preview_files; Gtk::Label *label_not_found; @@ -373,6 +370,7 @@ private: Gtk::Button *button_import; // Child widgets + Gtk::Notebook *notebook_content; Gtk::HBox hbox_tags; Gtk::HBox hbox_files; Gtk::ScrolledWindow scrolledwindow_list; -- cgit v1.2.3 From 31c699b8be09102d194e7468f4305ae6353c8e1f Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 18 Mar 2011 17:13:34 +0000 Subject: Get the OCAL logo form a proper path Degrade gracefully if the logo can't be found (bzr r10092.1.13) --- src/ui/dialog/ocaldialogs.cpp | 51 ++++++++++++++++++++++++++----------------- src/ui/dialog/ocaldialogs.h | 1 + 2 files changed, 32 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 0294c5baa..e4a7a6ac8 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -20,6 +20,7 @@ #include // errno #include // strerror() +#include "path-prefix.h" #include "ocaldialogs.h" #include "filedialogimpl-gtkmm.h" #include "interface.h" @@ -313,7 +314,15 @@ void SearchEntry::_on_changed() LogoDrawingArea::LogoDrawingArea() : Gtk::DrawingArea() { - logo_mask = Cairo::ImageSurface::create_from_png("/home/andrew/Software/Launchpad/inkscape/ocal-dialog/share/icons/OCAL.png"); + // Try to load the OCAL logo, but if the file is not found, degrade gracefully + try { + std::string logo_path = Glib::build_filename(INKSCAPE_PIXMAPDIR, "OCAL.png"); + logo_mask = Cairo::ImageSurface::create_from_png(logo_path); + draw_logo = true; + } catch( Cairo::logic_error ) { + logo_mask = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 1,1); + draw_logo = false; + } signal_expose_event().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_expose_event)); signal_style_changed().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_style_set)); } @@ -345,25 +354,27 @@ bool LogoDrawingArea::_on_expose_event(GdkEventExpose* event) Gdk::Rectangle(0, 0, width, height), *this, Glib::ustring::ustring("viewport"), 0, 0, width, height); - // Draw logo, we mask [read fill] it with the mid colour from the - // user's GTK theme - Gdk::Color logo_fill = get_style()->get_mid(get_state()); - int x_logo = width - 12 - 127; - int y_logo = height - 12 - 44; - - Gdk::Cairo::set_source_color(cr, logo_fill); - cr->mask(logo_mask, x_logo, y_logo); - - // Draw text - Pango::Rectangle extents = layout->get_pixel_logical_extents(); - int text_width = extents.get_width(); - int text_height = extents.get_height(); - - int x_text = x_logo - text_width - 12; - int y_text = height - text_height - 12; - - get_style()->paint_layout(get_window(), get_state(), true, - Gdk::Rectangle(0, 0, width, height), *this, "", x_text, y_text, layout); + if (draw_logo) { + // Draw logo, we mask [read fill] it with the mid colour from the + // user's GTK theme + Gdk::Color logo_fill = get_style()->get_mid(get_state()); + int x_logo = width - 12 - 127; + int y_logo = height - 12 - 44; + + Gdk::Cairo::set_source_color(cr, logo_fill); + cr->mask(logo_mask, x_logo, y_logo); + + // Draw text + Pango::Rectangle extents = layout->get_pixel_logical_extents(); + int text_width = extents.get_width(); + int text_height = extents.get_height(); + + int x_text = x_logo - text_width - 12; + int y_text = height - text_height - 12; + + get_style()->paint_layout(get_window(), get_state(), true, + Gdk::Rectangle(0, 0, width, height), *this, "", x_text, y_text, layout); + } return false; } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 89da69357..5bcee4a3c 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -282,6 +282,7 @@ public: private: bool _on_expose_event(GdkEventExpose* event); void _on_style_set(const Glib::RefPtr& previous_style); + bool draw_logo; Cairo::RefPtr logo_mask; Glib::RefPtr layout; }; -- cgit v1.2.3 From 1103ef1da293b798fab7d6e8b1501a5142ce7045 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sat, 19 Mar 2011 16:40:09 +0000 Subject: Remove depreciated GNOMEVFS from XML downloading and parsing and replace with GIO - Made these methods async so the UI is not blocked (bzr r10092.1.14) --- src/ui/dialog/ocaldialogs.cpp | 54 +++++++++++++++++++++---------------------- src/ui/dialog/ocaldialogs.h | 9 ++++++++ 2 files changed, 35 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index e4a7a6ac8..e5f714d08 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -509,7 +509,6 @@ failquit: myFilename = ""; } - /* * Callback for row activated */ @@ -519,7 +518,6 @@ void SearchResultList::on_row_activated(const Gtk::TreeModel::Path& /*path*/, Gt myButton->activate(); } - /* * Returns the selected filename */ @@ -551,7 +549,6 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) set_text(row_num, RESULTS_COLUMN_TITLE, title); xmlFree(title); } -#ifdef WITH_GNOME_VFS else if (!strcmp((const char*)cur_node->name, "pubDate")) { xmlChar *xml_date = xmlNodeGetContent(cur_node); @@ -588,7 +585,7 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) { xmlChar *xml_url = xmlGetProp(cur_node, (xmlChar*) "url"); char* url = (char*) xml_url; - char* filename = gnome_vfs_uri_extract_short_path_name(gnome_vfs_uri_new(url)); + char* filename = g_path_get_basename(url); set_text(row_num, RESULTS_COLUMN_URL, url); set_text(row_num, RESULTS_COLUMN_FILENAME, filename); @@ -602,7 +599,6 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) set_text(row_num, RESULTS_COLUMN_THUMBNAIL_URL, thumbnail_url); xmlFree(xml_thumbnail_url); } -#endif } populate_from_xml(cur_node->children); } @@ -643,39 +639,43 @@ void ImportDialog::on_entry_search_activated() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring search_keywords = entry_search->get_text(); - // create the ocal uri to get rss feed - Glib::ustring uri = "http://"; - uri.append(prefs->getString("/options/ocalurl/str")); - uri.append("/media/feed/rss/"); - uri.append(search_keywords); - if (!Glib::get_charset()) //If we are not utf8 - uri = Glib::filename_to_utf8(uri); - -#ifdef WITH_GNOME_VFS + + // Create the URI to the OCAL RSS feed + xml_uri = Glib::ustring::compose("http://%1/media/feed/rss/%2", + prefs->getString("/options/ocalurl/str"), search_keywords); + // If we are not UTF8 + if (!Glib::get_charset()) { + xml_uri = Glib::filename_to_utf8(xml_uri); + } - // open the rss feed - gnome_vfs_init(); - GnomeVFSHandle *from_handle = NULL; - GnomeVFSResult result; + // Open the rss feed + xml_file = Gio::File::create_for_uri(xml_uri); + xml_file->load_contents_async(sigc::mem_fun(*this, &ImportDialog::on_xml_file_read)); +} - result = gnome_vfs_open (&from_handle, uri.c_str(), GNOME_VFS_OPEN_READ); - if (result != GNOME_VFS_OK) { +void ImportDialog::on_xml_file_read(const Glib::RefPtr& result) +{ + char* data; + gsize length; + + bool sucess = xml_file->load_contents_finish(result, data, length); + if (!sucess) { sp_ui_error_dialog(_("Failed to receive the Open Clip Art Library RSS feed. Verify if the server name is correct in Configuration->Import/Export (e.g.: openclipart.org)")); return; } - // create the resulting xml document tree - // this initialize the library and test mistakes between compiled and shared library used + // Create the resulting xml document tree + // Initialize libxml and test mistakes between compiled and shared library used LIBXML_TEST_VERSION xmlDoc *doc = NULL; xmlNode *root_element = NULL; - doc = xmlReadIO ((xmlInputReadCallback) vfs_read_callback, - (xmlInputCloseCallback) gnome_vfs_close, from_handle, uri.c_str(), NULL, - XML_PARSE_RECOVER + XML_PARSE_NOWARNING + XML_PARSE_NOERROR); + doc = xmlReadMemory(data, (int) length, xml_uri.c_str(), NULL, + XML_PARSE_RECOVER + XML_PARSE_NOWARNING + XML_PARSE_NOERROR); + if (doc == NULL) { sp_ui_error_dialog(_("Server supplied malformed Clip Art feed")); - g_warning("Failed to parse %s\n", uri.c_str()); + g_warning("Failed to parse %s\n", xml_uri.c_str()); return; } @@ -705,8 +705,6 @@ void ImportDialog::on_entry_search_activated() xmlFreeDoc(doc); // free the global variables that may have been allocated by the parser xmlCleanupParser(); - return; -#endif } /** diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 5bcee4a3c..859451c39 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -377,7 +377,16 @@ private: Gtk::ScrolledWindow scrolledwindow_list; Glib::RefPtr selection; + // XML + Glib::RefPtr xml_file; + Glib::RefPtr xml_stream; + Glib::ustring xml_uri; + char xml_buffer[8192]; + void on_entry_search_activated(); + void on_xml_file_read(const Glib::RefPtr& result); + void on_xml_stream_read(const Glib::RefPtr& result); + /** * The extension to use to write this file -- cgit v1.2.3 From 4f352374bb8cd8fe758733790d64a750ec9721ef Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sat, 19 Mar 2011 19:14:33 +0000 Subject: Fix issue with text of overlay Remove more GNOMEVFS code Add in proper no result message (bzr r10092.1.15) --- src/ui/dialog/ocaldialogs.cpp | 54 ++++++++++++++++--------------------------- src/ui/dialog/ocaldialogs.h | 3 ++- 2 files changed, 22 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index e5f714d08..070e0ba29 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -324,10 +324,10 @@ LogoDrawingArea::LogoDrawingArea() : Gtk::DrawingArea() draw_logo = false; } signal_expose_event().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_expose_event)); - signal_style_changed().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_style_set)); + signal_realize().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_realize)); } -void LogoDrawingArea::_on_style_set(const Glib::RefPtr& previous_style) +void LogoDrawingArea::_on_realize() { Gdk::Color color = get_style()->get_mid(get_state()); layout = this->create_pango_layout(""); @@ -414,8 +414,6 @@ void SearchResultList::on_cursor_changed() std::vector posArray(1); posArray = pathlist[0].get_indices(); -#ifdef WITH_GNOME_VFS - gnome_vfs_init(); GnomeVFSHandle *from_handle = NULL; GnomeVFSHandle *to_handle = NULL; GnomeVFSFileSize bytes_read; @@ -426,8 +424,8 @@ void SearchResultList::on_cursor_changed() // FIXME: this would be better as a per-user OCAL cache of files // instead of filling /tmp with downloads. - // - // create file path + + // Create file path const std::string tmptemplate = "ocal-"; std::string tmpname; int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate); @@ -501,7 +499,6 @@ void SearchResultList::on_cursor_changed() } myPreview->showImage(myFilename); myLabel->set_text(get_text(posArray[0], RESULTS_COLUMN_TITLE)); -#endif return; fail: unlink(myFilename.c_str()); @@ -604,31 +601,6 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) } } - -#ifdef WITH_GNOME_VFS -/** - * Read callback for xmlReadIO(), used below - */ -static int vfs_read_callback (GnomeVFSHandle *handle, char* buf, int nb) -{ - GnomeVFSFileSize ndone; - GnomeVFSResult result; - - result = gnome_vfs_read (handle, buf, nb, &ndone); - - if (result == GNOME_VFS_OK) { - return (int)ndone; - } else { - if (result != GNOME_VFS_ERROR_EOF) { - sp_ui_error_dialog(_("Error while reading the Open Clip Art RSS feed")); - g_warning("%s\n", gnome_vfs_result_to_string(result)); - } - return -1; - } -} -#endif - - /** * Callback for user input into entry_search */ @@ -689,6 +661,7 @@ void ImportDialog::on_xml_file_read(const Glib::RefPtr& result if (list_results->size() == 0) { notebook_content->set_current_page(NOTEBOOK_PAGE_NOT_FOUND); + update_label_no_search_results(); } else { // Populate the MARKUP column with the title & description of the clipart for (guint i = 0; i <= list_results->size() - 1; i++) { @@ -707,6 +680,20 @@ void ImportDialog::on_xml_file_read(const Glib::RefPtr& result xmlCleanupParser(); } + +void ImportDialog::update_label_no_search_results() +{ + const char* keywords = entry_search->get_text().c_str(); + Gdk::Color grey = entry_search->get_style()->get_text_aa(entry_search->get_state()); + + char* markup = g_markup_printf_escaped( + "%s%s%s\n%s", + _("No clipart named "), keywords, _(" was found."), grey.to_string().c_str(), + _("Please make sure all keywords are spelled correctly, or try again with different keywords.")); + + label_not_found->set_markup(markup); +} + /** * Constructor. Not called directly. Use the factory. */ @@ -794,8 +781,7 @@ ImportDialog::~ImportDialog() /** * Show this dialog modally. Return true if user hits [OK] */ -bool -ImportDialog::show() +bool ImportDialog::show() { set_modal (TRUE); //Window sp_transientize((GtkWidget *)gobj()); //Make transient diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 859451c39..7293ab4ac 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -281,7 +281,7 @@ public: LogoDrawingArea(); private: bool _on_expose_event(GdkEventExpose* event); - void _on_style_set(const Glib::RefPtr& previous_style); + void _on_realize(); bool draw_logo; Cairo::RefPtr logo_mask; Glib::RefPtr layout; @@ -383,6 +383,7 @@ private: Glib::ustring xml_uri; char xml_buffer[8192]; + void update_label_no_search_results(); void on_entry_search_activated(); void on_xml_file_read(const Glib::RefPtr& result); void on_xml_stream_read(const Glib::RefPtr& result); -- cgit v1.2.3 From ff6f3e741926c2ac1c8d630217da0b73c9688e35 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sun, 20 Mar 2011 08:36:05 +0000 Subject: Remove all GNOMEVFS code Move some SearchResultlist methods to ImportDialog (bzr r10092.1.16) --- src/ui/dialog/ocaldialogs.cpp | 118 +++++++++++++----------------------------- src/ui/dialog/ocaldialogs.h | 16 +++--- 2 files changed, 43 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 070e0ba29..c830b679a 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -382,10 +382,6 @@ bool LogoDrawingArea::_on_expose_event(GdkEventExpose* event) SearchResultList::SearchResultList(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton) : ListViewText(columns_count) { - myPreview = &filesPreview; - myLabel = &description; - myButton = &okButton; - set_headers_visible(false); set_column_title(RESULTS_COLUMN_MARKUP, _("Clipart found")); @@ -407,25 +403,21 @@ SearchResultList::SearchResultList(guint columns_count, SVGPreview& filesPreview /* * Callback for cursor chage */ -void SearchResultList::on_cursor_changed() +void ImportDialog::on_list_results_cursor_changed() { std::vector pathlist; - pathlist = this->get_selection()->get_selected_rows(); + pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); posArray = pathlist[0].get_indices(); - GnomeVFSHandle *from_handle = NULL; - GnomeVFSHandle *to_handle = NULL; - GnomeVFSFileSize bytes_read; - GnomeVFSFileSize bytes_written; - GnomeVFSResult result; - guint8 buffer[8192]; - Glib::ustring fileUrl; - // FIXME: this would be better as a per-user OCAL cache of files // instead of filling /tmp with downloads. - // Create file path + // Get Remote File URL + Glib::ustring url = list_results->get_text(posArray[0], RESULTS_COLUMN_URL); + file_remote = Gio::File::create_for_uri(url.c_str()); + + // Create local file const std::string tmptemplate = "ocal-"; std::string tmpname; int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate); @@ -437,90 +429,47 @@ void SearchResultList::on_cursor_changed() // make sure we don't collide with other users on the same machine myFilename = tmpname; myFilename.append("-"); - myFilename.append(get_text(posArray[0], RESULTS_COLUMN_FILENAME)); + myFilename.append(list_results->get_text(posArray[0], RESULTS_COLUMN_FILENAME)); // rename based on original image's name, retaining extension if (rename(tmpname.c_str(),myFilename.c_str())<0) { unlink(tmpname.c_str()); g_warning("Error creating destination file '%s': %s", myFilename.c_str(), strerror(errno)); - goto failquit; } + file_local = Gio::File::create_for_path(myFilename.c_str()); - //get file url - fileUrl = get_text(posArray[0], RESULTS_COLUMN_URL); //http url - - //Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - //Glib::ustring fileUrl = "dav://"; //dav url - //fileUrl.append(prefs->getString("/options/ocalurl/str")); - //fileUrl.append("/dav.php/"); - //fileUrl.append(row[results_columns.CREATOR]); //author dir - //fileUrl.append("/"); - //fileUrl.append(row[results_columns.FILENAME]); //filename - - if (!Glib::get_charset()) //If we are not utf8 - fileUrl = Glib::filename_to_utf8(fileUrl); - - { - // 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': %s", myFilename.c_str(), gnome_vfs_result_to_string(result)); - goto fail; - } - 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."); - goto fail; - } - // 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)); - goto fail; - } - 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)); - goto fail; - } - if (bytes_read != bytes_written){ - g_warning("Bytes read not equal to bytes written"); - goto fail; - } - } + + //If we are not UTF8 + if (!Glib::get_charset()) { + url = Glib::filename_to_utf8(url); } - myPreview->showImage(myFilename); - myLabel->set_text(get_text(posArray[0], RESULTS_COLUMN_TITLE)); - return; -fail: - unlink(myFilename.c_str()); -failquit: - myFilename = ""; + + file_remote->copy_async(file_local, sigc::mem_fun(*this, &ImportDialog::on_file_copied), + Gio::FILE_COPY_OVERWRITE); } /* * Callback for row activated */ -void SearchResultList::on_row_activated(const Gtk::TreeModel::Path& /*path*/, Gtk::TreeViewColumn* /*column*/) +void ImportDialog::on_file_copied(const Glib::RefPtr& result) { - this->on_cursor_changed(); - myButton->activate(); + bool success = file_remote->copy_finish(result); + + if (success) { + preview_files->showImage(myFilename); + //update_label_no_search_results(list_results->get_text(posArray[0], RESULTS_COLUMN_TITLE)); + } else { + myFilename = ""; + } } /* - * Returns the selected filename + * Callback for row activated */ -Glib::ustring SearchResultList::get_filename() +void ImportDialog::on_list_results_row_activated(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column) { - return myFilename; + on_list_results_cursor_changed(); + button_import->activate(); } /** @@ -762,9 +711,12 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, // Signals entry_search->signal_activate().connect( sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); - button_search->signal_clicked().connect( sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); + list_results->signal_cursor_changed().connect( + sigc::mem_fun(*this, &ImportDialog::on_list_results_cursor_changed)); + list_results->signal_row_activated().connect( + sigc::mem_fun(*this, &ImportDialog::on_list_results_row_activated)); show_all_children(); entry_search->grab_focus(); @@ -815,7 +767,7 @@ ImportDialog::get_selection_type() Glib::ustring ImportDialog::get_filename (void) { - return list_results->get_filename(); + return myFilename; } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 7293ab4ac..4e61265cd 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -315,13 +315,6 @@ public: Gtk::Label& description, Gtk::Button& okButton); Glib::ustring get_filename(); void populate_from_xml(xmlNode* a_node); -private: - void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); - void on_cursor_changed(); - Glib::ustring myFilename; - SVGPreview *myPreview; - Gtk::Label *myLabel; - Gtk::Button *myButton; }; /** @@ -361,6 +354,7 @@ public: Glib::ustring get_filename(); private: + Glib::ustring myFilename; SearchEntry *entry_search; LogoDrawingArea *drawingarea_logo; SearchResultList *list_results; @@ -383,10 +377,16 @@ private: Glib::ustring xml_uri; char xml_buffer[8192]; + // File + Glib::RefPtr file_local; + Glib::RefPtr file_remote; + void update_label_no_search_results(); + void on_list_results_cursor_changed(); + void on_list_results_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void on_entry_search_activated(); + void on_file_copied(const Glib::RefPtr& result); void on_xml_file_read(const Glib::RefPtr& result); - void on_xml_stream_read(const Glib::RefPtr& result); /** -- cgit v1.2.3 From 7ab46bc54ee3aaa87282dfd35d8f6000fe811750 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Tue, 22 Mar 2011 17:14:49 +0000 Subject: Split OCALDialog code in fill.cpp into two, so we can have async stuff working Added StatusWidget to show status of operations in dialog Styled no search results label appropriately Corrected callbacks for buttons Start to get image downloading working (bzr r10092.1.17) --- src/file.cpp | 52 +++--- src/file.h | 7 + src/ui/dialog/ocaldialogs.cpp | 357 +++++++++++++++++++++++++++++------------- src/ui/dialog/ocaldialogs.h | 71 +++++++-- 4 files changed, 335 insertions(+), 152 deletions(-) (limited to 'src') diff --git a/src/file.cpp b/src/file.cpp index 967c59b08..bfb10e6d6 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1441,8 +1441,19 @@ sp_file_export_to_ocal(Gtk::Window &parentWindow) ######################*/ /** - * Display an ImportToOcal Dialog, and the selected document from OCAL + * Display an ImportFromOcal Dialog, and the selected document from OCAL */ +void on_import_from_ocal_response(Glib::ustring filename, + Inkscape::UI::Dialog::OCAL::ImportDialog* import_dialog) +{ + SPDocument *doc = SP_ACTIVE_DOCUMENT; + + if (!filename.empty()) { + Inkscape::Extension::Extension *selection = import_dialog->get_selection_type(); + file_import(doc, filename, selection); + } +} + void sp_file_import_from_ocal(Gtk::Window &parent_window) { @@ -1452,7 +1463,7 @@ sp_file_import_from_ocal(Gtk::Window &parent_window) if (!doc) return; - Inkscape::UI::Dialog::OCAL::ImportDialog *import_dialog = NULL; + Inkscape::UI::Dialog::OCAL::ImportDialog* import_dialog = NULL; if (!import_dialog) { import_dialog = new @@ -1463,36 +1474,13 @@ sp_file_import_from_ocal(Gtk::Window &parent_window) (char const *)_("Import From Open Clip Art Library")); } - bool success = import_dialog->show(); - if (!success) { - delete import_dialog; - return; - } - - // Get file name and extension type - Glib::ustring file_name = import_dialog->get_filename(); - Inkscape::Extension::Extension *selection = import_dialog->get_selection_type(); - - delete import_dialog; - import_dialog = NULL; - - if (file_name.size() > 0) { - - Glib::ustring new_file_name = Glib::filename_to_utf8(file_name); - - if (new_file_name.size() > 0) - file_name = new_file_name; - else - g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" ); - - import_path = file_name; - if (import_path.size()>0) - import_path.append(G_DIR_SEPARATOR_S); - - file_import(doc, file_name, selection); - } - - return; + import_dialog->signal_response().connect( + sigc::bind( + sigc::ptr_fun(&on_import_from_ocal_response), + import_dialog) + ); + + import_dialog->show_all(); } /*###################### diff --git a/src/file.h b/src/file.h index 97d1bd5f8..c6f43e905 100644 --- a/src/file.h +++ b/src/file.h @@ -19,6 +19,7 @@ #include #include +#include "ui/dialog/ocaldialogs.h" #include "extension/extension-forward.h" #include "extension/system.h" @@ -164,6 +165,12 @@ bool sp_file_export_dialog (Gtk::Window &parentWindow); ## I M P O R T F R O M O C A L ######################*/ +/** + * Import a document from OCAL + */ +void on_import_from_ocal_response(Glib::ustring filename, + Inkscape::UI::Dialog::OCAL::ImportDialog* import_dialog); + /** * Import a document from OCAL */ diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index c830b679a..854456e8f 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -283,6 +283,55 @@ ExportPasswordDialog::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### +StatusWidget::StatusWidget() : Gtk::HBox(false, 6) +{ + image = new Gtk::Image(Gtk::Stock::DIALOG_ERROR, Gtk::ICON_SIZE_MENU); + spinner = new Gtk::Spinner(); + label = new Gtk::Label(); + + image->set_no_show_all(true); + spinner->set_no_show_all(true); + label->set_no_show_all(true); + + pack_start(*image, false, false); + pack_start(*spinner, false, false); + pack_start(*label, false, false); +} + +void StatusWidget::clear() +{ + spinner->hide(); + image->hide(); + label->hide(); +} + +void StatusWidget::set_error(Glib::ustring text) +{ + spinner->hide(); + image->show(); + label->show(); + image->set(Gtk::Stock::DIALOG_ERROR, Gtk::ICON_SIZE_MENU); + label->set_text(text); +} + +void StatusWidget::start_process(Glib::ustring text) +{ + image->hide(); + spinner->show(); + label->show(); + label->set_text(text); + spinner->start(); + show_all(); +} + +void StatusWidget::end_process() +{ + spinner->stop(); + spinner->hide(); + label->hide(); + clear(); +} + SearchEntry::SearchEntry() : Gtk::Entry() { signal_changed().connect(sigc::mem_fun(*this, &SearchEntry::_on_changed)); @@ -312,7 +361,35 @@ void SearchEntry::_on_changed() } } -LogoDrawingArea::LogoDrawingArea() : Gtk::DrawingArea() +BaseBox::BaseBox() : Gtk::EventBox() +{ + signal_expose_event().connect(sigc::mem_fun(*this, &BaseBox::_on_expose_event), false); + set_visible_window(false); +} + +bool BaseBox::_on_expose_event(GdkEventExpose* event) +{ + Cairo::RefPtr cr = get_window()->create_cairo_context(); + + // Draw background and shadow + int x = get_allocation().get_x(); + int y = get_allocation().get_y(); + int width = get_allocation().get_width(); + int height = get_allocation().get_height(); + Gdk::Color background_fill = get_style()->get_base(get_state()); + + cr->rectangle(x, y, width, height); + Gdk::Cairo::set_source_color(cr, background_fill); + cr->fill(); + + get_style()->paint_shadow(get_window(), get_state(), Gtk::SHADOW_IN, + Gdk::Rectangle(x, y, width, height), + *this, Glib::ustring::ustring("viewport"), x, y, width, height); + + return false; +} + +LogoArea::LogoArea() : Gtk::EventBox() { // Try to load the OCAL logo, but if the file is not found, degrade gracefully try { @@ -323,11 +400,12 @@ LogoDrawingArea::LogoDrawingArea() : Gtk::DrawingArea() logo_mask = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 1,1); draw_logo = false; } - signal_expose_event().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_expose_event)); - signal_realize().connect(sigc::mem_fun(*this, &LogoDrawingArea::_on_realize)); + signal_expose_event().connect(sigc::mem_fun(*this, &LogoArea::_on_expose_event)); + signal_realize().connect(sigc::mem_fun(*this, &LogoArea::_on_realize)); + set_visible_window(false); } -void LogoDrawingArea::_on_realize() +void LogoArea::_on_realize() { Gdk::Color color = get_style()->get_mid(get_state()); layout = this->create_pango_layout(""); @@ -337,29 +415,21 @@ void LogoDrawingArea::_on_realize() layout->set_markup(markup); } -bool LogoDrawingArea::_on_expose_event(GdkEventExpose* event) +bool LogoArea::_on_expose_event(GdkEventExpose* event) { - Cairo::RefPtr cr = get_window()->create_cairo_context(); - - // Draw background and shadow - int width = get_allocation().get_width(); - int height = get_allocation().get_height(); - Gdk::Color background_fill = get_style()->get_base(get_state()); - - cr->rectangle(0, 0, width, height); - Gdk::Cairo::set_source_color(cr, background_fill); - cr->fill(); - - get_style()->paint_shadow(get_window(), get_state(), Gtk::SHADOW_IN, - Gdk::Rectangle(0, 0, width, height), - *this, Glib::ustring::ustring("viewport"), 0, 0, width, height); - if (draw_logo) { + int x = get_allocation().get_x(); + int y = get_allocation().get_y(); + int width = get_allocation().get_width(); + int height = get_allocation().get_height(); + + Cairo::RefPtr cr = get_window()->create_cairo_context(); + // Draw logo, we mask [read fill] it with the mid colour from the // user's GTK theme Gdk::Color logo_fill = get_style()->get_mid(get_state()); - int x_logo = width - 12 - 127; - int y_logo = height - 12 - 44; + int x_logo = x + width - 12 - 127; + int y_logo = y + height - 12 - 44; Gdk::Cairo::set_source_color(cr, logo_fill); cr->mask(logo_mask, x_logo, y_logo); @@ -370,10 +440,10 @@ bool LogoDrawingArea::_on_expose_event(GdkEventExpose* event) int text_height = extents.get_height(); int x_text = x_logo - text_width - 12; - int y_text = height - text_height - 12; + int y_text = y + height - text_height - 12; get_style()->paint_layout(get_window(), get_state(), true, - Gdk::Rectangle(0, 0, width, height), *this, "", x_text, y_text, layout); + Gdk::Rectangle(x, y, width, height), *this, "", x_text, y_text, layout); } return false; @@ -400,6 +470,59 @@ SearchResultList::SearchResultList(guint columns_count, SVGPreview& filesPreview get_column(RESULTS_COLUMN_THUMBNAIL_URL)->set_visible(false); } + +void ImportDialog::on_button_import_clicked() { + std::vector pathlist; + pathlist = list_results->get_selection()->get_selected_rows(); + std::vector posArray(1); + posArray = pathlist[0].get_indices(); + int row = posArray[0]; + + download_image(row); +} + +void ImportDialog::download_image(int row) +{ + // Get Remote File URL + Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_URL); + file_remote = Gio::File::create_for_uri(url.c_str()); + + // Create local file + const std::string tmptemplate = "ocal-"; + std::string tmpname; + int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate); + if (fd < 0) { + widget_status->set_error(_("Could not create image file")); + return; + } + close(fd); + // make sure we don't collide with other users on the same machine + filename_image = tmpname; + filename_image.append("-"); + filename_image.append(list_results->get_text(row, RESULTS_COLUMN_FILENAME)); + // rename based on original image's name, retaining extension + if (rename(tmpname.c_str(), filename_image.c_str()) < 0) { + unlink(tmpname.c_str()); + widget_status->set_error(_("Could not create image file")); + } + file_local = Gio::File::create_for_path(filename_image.c_str()); + + file_remote->copy_async(file_local, sigc::mem_fun(*this, + &ImportDialog::on_thumbnail_image_downloaded), Gio::FILE_COPY_OVERWRITE); +} + +void ImportDialog::on_image_downloaded(const Glib::RefPtr& result) +{ + bool success = file_thumbnail_remote->copy_finish(result); + + if (success) { + m_signal_response.emit(filename_image); + } else { + filename_image = ""; + } +} + + /* * Callback for cursor chage */ @@ -409,56 +532,66 @@ void ImportDialog::on_list_results_cursor_changed() pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); posArray = pathlist[0].get_indices(); + int row = posArray[0]; // FIXME: this would be better as a per-user OCAL cache of files // instead of filling /tmp with downloads. + update_preview(row); + download_thumbnail_image(row); + + +} +void ImportDialog::update_preview(int row) +{ + Glib::ustring title = list_results->get_text(row, RESULTS_COLUMN_TITLE); + Glib::ustring description = list_results->get_text(row, RESULTS_COLUMN_DESCRIPTION); + Glib::ustring creator = list_results->get_text(row, RESULTS_COLUMN_CREATOR); + Glib::ustring date = list_results->get_text(row, RESULTS_COLUMN_DATE); +} + +void ImportDialog::download_thumbnail_image(int row) +{ // Get Remote File URL - Glib::ustring url = list_results->get_text(posArray[0], RESULTS_COLUMN_URL); - file_remote = Gio::File::create_for_uri(url.c_str()); + Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); + file_thumbnail_remote = Gio::File::create_for_uri(url.c_str()); // Create local file const std::string tmptemplate = "ocal-"; std::string tmpname; int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate); - if (fd<0) { - g_warning("Error creating temp file"); + if (fd < 0) { + widget_status->set_error(_("Could not create thumbnail file")); return; } close(fd); // make sure we don't collide with other users on the same machine - myFilename = tmpname; - myFilename.append("-"); - myFilename.append(list_results->get_text(posArray[0], RESULTS_COLUMN_FILENAME)); + filename_thumbnail = tmpname; + filename_thumbnail.append("-"); + filename_thumbnail.append(list_results->get_text(row, RESULTS_COLUMN_FILENAME)); // rename based on original image's name, retaining extension - if (rename(tmpname.c_str(),myFilename.c_str())<0) { + if (rename(tmpname.c_str(), filename_thumbnail.c_str()) < 0) { unlink(tmpname.c_str()); - g_warning("Error creating destination file '%s': %s", myFilename.c_str(), strerror(errno)); + widget_status->set_error(_("Could not create thumbnail file")); } - file_local = Gio::File::create_for_path(myFilename.c_str()); + file_thumbnail_local = Gio::File::create_for_path(filename_thumbnail.c_str()); - - //If we are not UTF8 - if (!Glib::get_charset()) { - url = Glib::filename_to_utf8(url); - } - - file_remote->copy_async(file_local, sigc::mem_fun(*this, &ImportDialog::on_file_copied), - Gio::FILE_COPY_OVERWRITE); + file_thumbnail_remote->copy_async(file_thumbnail_local, sigc::mem_fun(*this, + &ImportDialog::on_thumbnail_image_downloaded), Gio::FILE_COPY_OVERWRITE); } /* * Callback for row activated */ -void ImportDialog::on_file_copied(const Glib::RefPtr& result) +void ImportDialog::on_thumbnail_image_downloaded(const Glib::RefPtr& result) { - bool success = file_remote->copy_finish(result); + bool success = file_thumbnail_remote->copy_finish(result); if (success) { - preview_files->showImage(myFilename); - //update_label_no_search_results(list_results->get_text(posArray[0], RESULTS_COLUMN_TITLE)); + preview_files->showImage(filename_thumbnail); } else { - myFilename = ""; + widget_status->set_error(_("Could not download thumbnail file")); + filename_thumbnail = ""; } } @@ -469,7 +602,7 @@ void ImportDialog::on_list_results_row_activated(const Gtk::TreeModel::Path& pat Gtk::TreeViewColumn* column) { on_list_results_cursor_changed(); - button_import->activate(); + button_import->signal_clicked(); } /** @@ -550,11 +683,21 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) } } +/** + * Callback for user input into entry_search + */ +void ImportDialog::on_button_search_clicked() +{ + on_entry_search_activated(); +} + /** * Callback for user input into entry_search */ void ImportDialog::on_entry_search_activated() { + widget_status->start_process(_("Searching clipart...")); + notebook_content->set_current_page(NOTEBOOK_PAGE_LOGO); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -576,12 +719,14 @@ void ImportDialog::on_entry_search_activated() void ImportDialog::on_xml_file_read(const Glib::RefPtr& result) { + widget_status->end_process(); + char* data; gsize length; bool sucess = xml_file->load_contents_finish(result, data, length); if (!sucess) { - sp_ui_error_dialog(_("Failed to receive the Open Clip Art Library RSS feed. Verify if the server name is correct in Configuration->Import/Export (e.g.: openclipart.org)")); + widget_status->set_error(_("Could not connect to the Open Clip Art Library")); return; } @@ -595,33 +740,32 @@ void ImportDialog::on_xml_file_read(const Glib::RefPtr& result XML_PARSE_RECOVER + XML_PARSE_NOWARNING + XML_PARSE_NOERROR); if (doc == NULL) { - sp_ui_error_dialog(_("Server supplied malformed Clip Art feed")); - g_warning("Failed to parse %s\n", xml_uri.c_str()); + // If nothing is returned, no results could be found + if (length == 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")); + } return; } - // get the root element node + // Get the root element node root_element = xmlDocGetRootElement(doc); - // clear the list_results + // Clear and populate the list_results list_results->clear_items(); - list_results->populate_from_xml(root_element); - if (list_results->size() == 0) { - notebook_content->set_current_page(NOTEBOOK_PAGE_NOT_FOUND); - update_label_no_search_results(); - } else { - // Populate the MARKUP column with the title & description of the clipart - for (guint i = 0; i <= list_results->size() - 1; i++) { - Glib::ustring title = list_results->get_text(i, RESULTS_COLUMN_TITLE); - Glib::ustring description = list_results->get_text(i, RESULTS_COLUMN_DESCRIPTION); - char* markup = g_markup_printf_escaped("%s\n%s", - title.c_str(), description.c_str()); - list_results->set_text(i, RESULTS_COLUMN_MARKUP, markup); - } - notebook_content->set_current_page(NOTEBOOK_PAGE_RESULTS); + // Populate the MARKUP column with the title & description of the clipart + for (guint i = 0; i <= list_results->size() - 1; i++) { + Glib::ustring title = list_results->get_text(i, RESULTS_COLUMN_TITLE); + Glib::ustring description = list_results->get_text(i, RESULTS_COLUMN_DESCRIPTION); + char* markup = g_markup_printf_escaped("%s\n%s", + title.c_str(), description.c_str()); + list_results->set_text(i, RESULTS_COLUMN_MARKUP, markup); } + notebook_content->set_current_page(NOTEBOOK_PAGE_RESULTS); // free the document xmlFreeDoc(doc); @@ -632,12 +776,12 @@ void ImportDialog::on_xml_file_read(const Glib::RefPtr& result void ImportDialog::update_label_no_search_results() { - const char* keywords = entry_search->get_text().c_str(); + Glib::ustring keywords = Glib::Markup::escape_text(entry_search->get_text()); Gdk::Color grey = entry_search->get_style()->get_text_aa(entry_search->get_state()); - char* markup = g_markup_printf_escaped( - "%s%s%s\n%s", - _("No clipart named "), keywords, _(" was found."), grey.to_string().c_str(), + Glib::ustring markup = Glib::ustring::compose( + "%1 %2 %3\n%5", + _("No clipart named"), keywords, _("was found."), grey.to_string(), _("Please make sure all keywords are spelled correctly, or try again with different keywords.")); label_not_found->set_markup(markup); @@ -660,7 +804,11 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, dialogType = file_types; // Creation - Gtk::VBox *vbox = get_vbox(); + Gtk::VBox *vbox = new Gtk::VBox(false, 0); + Gtk::HButtonBox *hbuttonbox_bottom = new Gtk::HButtonBox(); + Gtk::HBox *hbox_bottom = new Gtk::HBox(false, 12); + BaseBox *basebox_logo = new BaseBox(); + BaseBox *basebox_no_search_results = new BaseBox(); label_not_found = new Gtk::Label(); label_description = new Gtk::Label(); entry_search = new SearchEntry(); @@ -668,34 +816,45 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, Gtk::HButtonBox* hbuttonbox_search = new Gtk::HButtonBox(); preview_files = new SVGPreview(); /// Add the buttons in the bottom of the dialog - add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - button_import = add_button(_("Import"), Gtk::RESPONSE_OK); + button_cancel = new Gtk::Button(Gtk::Stock::CANCEL); + button_import = new Gtk::Button(_("Import")); list_results = new SearchResultList(RESULTS_COLUMN_LENGTH, *preview_files, *label_description, *button_import); - drawingarea_logo = new LogoDrawingArea(); + drawingarea_logo = new LogoArea(); notebook_content = new Gtk::Notebook(); + widget_status = new StatusWidget(); // Packing + this->add(*vbox); + vbox->pack_start(hbox_tags, false, false); + vbox->pack_start(hbox_files, true, true); + vbox->pack_start(*hbox_bottom, false, false); + basebox_logo->add(*drawingarea_logo); + basebox_no_search_results->add(*label_not_found); + hbox_bottom->pack_start(*widget_status, true, true); + hbox_bottom->pack_start(*hbuttonbox_bottom, true, true); + hbuttonbox_bottom->pack_start(*button_cancel, false, false); + hbuttonbox_bottom->pack_start(*button_import, false, false); hbuttonbox_search->pack_start(*button_search, false, false); hbox_tags.pack_start(*entry_search, true, true); hbox_tags.pack_start(*hbuttonbox_search, false, false); hbox_files.pack_start(*notebook_content, true, true); hbox_files.pack_start(*preview_files, true, true); - vbox->pack_start(hbox_tags, false, false); - vbox->pack_start(hbox_files, true, true); - notebook_content->insert_page(*drawingarea_logo, NOTEBOOK_PAGE_LOGO); + notebook_content->insert_page(*basebox_logo, NOTEBOOK_PAGE_LOGO); notebook_content->insert_page(scrolledwindow_list, NOTEBOOK_PAGE_RESULTS); - notebook_content->insert_page(*label_not_found, NOTEBOOK_PAGE_NOT_FOUND); + notebook_content->insert_page(*basebox_no_search_results, NOTEBOOK_PAGE_NOT_FOUND); // Properties set_border_width(12); set_default_size(480, 320); vbox->set_spacing(12); + hbuttonbox_bottom->set_spacing(6); + hbuttonbox_bottom->set_layout(Gtk::BUTTONBOX_END); + button_import->set_sensitive(false); entry_search->set_max_length(255); hbox_tags.set_spacing(6); preview_files->showNoPreview(); - set_default(*button_import); notebook_content->set_current_page(NOTEBOOK_PAGE_LOGO); /// Add the listview inside a ScrolledWindow scrolledwindow_list.add(*list_results); @@ -705,14 +864,20 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, scrolledwindow_list.set_size_request(310, 230); drawingarea_logo->set_size_request(310, 230); hbox_files.set_spacing(12); + label_not_found->set_line_wrap(true); + label_not_found->set_line_wrap_mode(Pango::WRAP_WORD); + label_not_found->set_justify(Gtk::JUSTIFY_CENTER); + label_not_found->set_size_request(260, -1); notebook_content->set_show_tabs(false); notebook_content->set_show_border(false); // Signals entry_search->signal_activate().connect( sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); + button_import->signal_clicked().connect( + sigc::mem_fun(*this, &ImportDialog::on_button_import_clicked)); button_search->signal_clicked().connect( - sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); + sigc::mem_fun(*this, &ImportDialog::on_button_search_clicked)); list_results->signal_cursor_changed().connect( sigc::mem_fun(*this, &ImportDialog::on_list_results_cursor_changed)); list_results->signal_row_activated().connect( @@ -730,27 +895,6 @@ ImportDialog::~ImportDialog() } -/** - * Show this dialog modally. Return true if user hits [OK] - */ -bool ImportDialog::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] */ @@ -760,14 +904,9 @@ ImportDialog::get_selection_type() return extension; } - -/** - * Get the file name chosen by the user. Valid after an [OK] - */ -Glib::ustring -ImportDialog::get_filename (void) +ImportDialog::type_signal_response ImportDialog::signal_response() { - return myFilename; + return m_signal_response; } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 4e61265cd..5085ad232 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -55,6 +55,7 @@ //For export dialog #include "ui/widget/scalar-unit.h" +#include namespace Inkscape { @@ -71,15 +72,20 @@ namespace OCAL /** * This class is the base implementation for export to OCAL. */ -class FileDialogBase : public Gtk::Dialog +class FileDialogBase : public Gtk::Window { public: /** * Constructor */ - FileDialogBase(const Glib::ustring &title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true) - {} + FileDialogBase(const Glib::ustring &title, Gtk::Window& parent) : Gtk::Window(Gtk::WINDOW_TOPLEVEL) + { + set_title(title); + + //set_modal(TRUE); + //sp_transientize((GtkWidget*) gobj()); + } /* * Destructor @@ -259,6 +265,24 @@ private: //######################################################################### +/** + * A Widget that contains an status icon and a message + */ +class StatusWidget : public Gtk::HBox +{ +public: + StatusWidget(); + + void clear(); + void set_error(Glib::ustring text); + void start_process(Glib::ustring text); + void end_process(); + + Gtk::Spinner* spinner; + Gtk::Image* image; + Gtk::Label* label; +}; + /** * A Gtk::Entry with search & clear icons */ @@ -275,10 +299,10 @@ private: /** * A box which paints an overlay of the OCAL logo */ -class LogoDrawingArea : public Gtk::DrawingArea +class LogoArea : public Gtk::EventBox { public: - LogoDrawingArea(); + LogoArea(); private: bool _on_expose_event(GdkEventExpose* event); void _on_realize(); @@ -287,6 +311,17 @@ private: Glib::RefPtr layout; }; +/** + * A box filled with the Base colour from the user's GTK theme, and a border + */ +class BaseBox : public Gtk::EventBox +{ +public: + BaseBox(); +private: + bool _on_expose_event(GdkEventExpose* event); +}; + enum { RESULTS_COLUMN_MARKUP, RESULTS_COLUMN_TITLE, @@ -313,7 +348,6 @@ class SearchResultList : public Gtk::ListViewText public: SearchResultList(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton); - Glib::ustring get_filename(); void populate_from_xml(xmlNode* a_node); }; @@ -350,19 +384,26 @@ public: * be later freed with g_free(), else NULL. */ Inkscape::Extension::Extension *get_selection_type(); - - Glib::ustring get_filename(); + + typedef sigc::signal type_signal_response; + type_signal_response signal_response(); + +protected: + type_signal_response m_signal_response; private: - Glib::ustring myFilename; + Glib::ustring filename_image; + Glib::ustring filename_thumbnail; SearchEntry *entry_search; - LogoDrawingArea *drawingarea_logo; + LogoArea *drawingarea_logo; SearchResultList *list_results; SVGPreview *preview_files; Gtk::Label *label_not_found; Gtk::Label *label_description; Gtk::Button *button_search; Gtk::Button *button_import; + Gtk::Button *button_cancel; + StatusWidget *widget_status; // Child widgets Gtk::Notebook *notebook_content; @@ -380,12 +421,20 @@ private: // File Glib::RefPtr file_local; Glib::RefPtr file_remote; + Glib::RefPtr file_thumbnail_local; + Glib::RefPtr file_thumbnail_remote; void update_label_no_search_results(); + void update_preview(int row); void on_list_results_cursor_changed(); + void download_thumbnail_image(int row); + void on_thumbnail_image_downloaded(const Glib::RefPtr& result); + void download_image(int row); + void on_image_downloaded(const Glib::RefPtr& result); void on_list_results_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); + void on_button_import_clicked(); + void on_button_search_clicked(); void on_entry_search_activated(); - void on_file_copied(const Glib::RefPtr& result); void on_xml_file_read(const Glib::RefPtr& result); -- cgit v1.2.3 From 002481162f050709a125e38dc60145ef77c10c98 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Thu, 24 Mar 2011 19:14:21 +0000 Subject: Made dialog's state persistant Cleanup of code Made download of image work Put all images into a /tmp/openclipart directory Use GUID for filename (bzr r10092.1.18) --- src/file.cpp | 26 ++--- src/file.h | 3 +- src/io/sys.cpp | 9 ++ src/io/sys.h | 2 + src/ui/dialog/ocaldialogs.cpp | 236 +++++++++++++++++++++++++++--------------- src/ui/dialog/ocaldialogs.h | 29 ++++-- 6 files changed, 195 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/file.cpp b/src/file.cpp index bfb10e6d6..cee5280c0 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1113,7 +1113,7 @@ sp_file_import(Gtk::Window &parentWindow) return; } - //# Get file name and extension type + // Get file name and extension type Glib::ustring fileName = importDialogInstance->getFilename(); Inkscape::Extension::Extension *selection = importDialogInstance->getSelectionType(); @@ -1440,16 +1440,17 @@ sp_file_export_to_ocal(Gtk::Window &parentWindow) ## I M P O R T F R O M O C A L ######################*/ +Inkscape::UI::Dialog::OCAL::ImportDialog* import_ocal_dialog = NULL; + /** * Display an ImportFromOcal Dialog, and the selected document from OCAL */ -void on_import_from_ocal_response(Glib::ustring filename, - Inkscape::UI::Dialog::OCAL::ImportDialog* import_dialog) +void on_import_from_ocal_response(Glib::ustring filename) { SPDocument *doc = SP_ACTIVE_DOCUMENT; if (!filename.empty()) { - Inkscape::Extension::Extension *selection = import_dialog->get_selection_type(); + Inkscape::Extension::Extension *selection = import_ocal_dialog->get_selection_type(); file_import(doc, filename, selection); } } @@ -1463,24 +1464,19 @@ sp_file_import_from_ocal(Gtk::Window &parent_window) if (!doc) return; - Inkscape::UI::Dialog::OCAL::ImportDialog* import_dialog = NULL; - - if (!import_dialog) { - import_dialog = new + if (import_ocal_dialog == NULL) { + import_ocal_dialog = new Inkscape::UI::Dialog::OCAL::ImportDialog( parent_window, import_path, Inkscape::UI::Dialog::IMPORT_TYPES, (char const *)_("Import From Open Clip Art Library")); - } - import_dialog->signal_response().connect( - sigc::bind( - sigc::ptr_fun(&on_import_from_ocal_response), - import_dialog) - ); + import_ocal_dialog->signal_response().connect( + sigc::ptr_fun(&on_import_from_ocal_response)); + } - import_dialog->show_all(); + import_ocal_dialog->show_all(); } /*###################### diff --git a/src/file.h b/src/file.h index c6f43e905..4a2b1f91f 100644 --- a/src/file.h +++ b/src/file.h @@ -168,8 +168,7 @@ bool sp_file_export_dialog (Gtk::Window &parentWindow); /** * Import a document from OCAL */ -void on_import_from_ocal_response(Glib::ustring filename, - Inkscape::UI::Dialog::OCAL::ImportDialog* import_dialog); +void on_import_from_ocal_response(Glib::ustring filename); /** * Import a document from OCAL diff --git a/src/io/sys.cpp b/src/io/sys.cpp index a68d02707..e7fdfaa2d 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -365,6 +365,15 @@ gchar* Inkscape::IO::sanitizeString( gchar const * str ) return result; } +/* + * Returns the file extension of a path/filename + */ +Glib::ustring Inkscape::IO::get_file_extension(Glib::ustring path) +{ + Glib::ustring::size_type period_location = path.find_last_of("."); + return path.substr(period_location); +} + /* Local Variables: mode:c++ diff --git a/src/io/sys.h b/src/io/sys.h index 8623f6be9..8ece3b84a 100644 --- a/src/io/sys.h +++ b/src/io/sys.h @@ -61,6 +61,8 @@ void spawn_async_with_pipes (const std::string& working_directory, int* standard_output, int* standard_error); +Glib::ustring get_file_extension(Glib::ustring path); + } } diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 854456e8f..3abce1a0b 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -305,6 +305,15 @@ void StatusWidget::clear() label->hide(); } +void StatusWidget::set_info(Glib::ustring text) +{ + spinner->hide(); + image->show(); + label->show(); + image->set(Gtk::Stock::DIALOG_INFO, Gtk::ICON_SIZE_MENU); + label->set_text(text); +} + void StatusWidget::set_error(Glib::ustring text) { spinner->hide(); @@ -396,7 +405,7 @@ LogoArea::LogoArea() : Gtk::EventBox() std::string logo_path = Glib::build_filename(INKSCAPE_PIXMAPDIR, "OCAL.png"); logo_mask = Cairo::ImageSurface::create_from_png(logo_path); draw_logo = true; - } catch( Cairo::logic_error ) { + } catch(Cairo::logic_error) { logo_mask = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 1,1); draw_logo = false; } @@ -461,13 +470,12 @@ SearchResultList::SearchResultList(guint columns_count, SVGPreview& filesPreview get_column(RESULTS_COLUMN_MARKUP)->add_attribute(*cr_markup, "markup", RESULTS_COLUMN_MARKUP); - get_column(RESULTS_COLUMN_TITLE)->set_visible(false); - get_column(RESULTS_COLUMN_DESCRIPTION)->set_visible(false); - get_column(RESULTS_COLUMN_CREATOR)->set_visible(false); - get_column(RESULTS_COLUMN_DATE)->set_visible(false); - get_column(RESULTS_COLUMN_FILENAME)->set_visible(false); - get_column(RESULTS_COLUMN_URL)->set_visible(false); - get_column(RESULTS_COLUMN_THUMBNAIL_URL)->set_visible(false); + // Hide all columns except for the MARKUP column + for (int i = 0; i < RESULTS_COLUMN_LENGTH; i++) { + if (i != RESULTS_COLUMN_MARKUP) { + get_column(i)->set_visible(false); + } + } } @@ -479,50 +487,9 @@ void ImportDialog::on_button_import_clicked() { int row = posArray[0]; download_image(row); + widget_status->start_process(_("Downloading image...")); } -void ImportDialog::download_image(int row) -{ - // Get Remote File URL - Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_URL); - file_remote = Gio::File::create_for_uri(url.c_str()); - - // Create local file - const std::string tmptemplate = "ocal-"; - std::string tmpname; - int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate); - if (fd < 0) { - widget_status->set_error(_("Could not create image file")); - return; - } - close(fd); - // make sure we don't collide with other users on the same machine - filename_image = tmpname; - filename_image.append("-"); - filename_image.append(list_results->get_text(row, RESULTS_COLUMN_FILENAME)); - // rename based on original image's name, retaining extension - if (rename(tmpname.c_str(), filename_image.c_str()) < 0) { - unlink(tmpname.c_str()); - widget_status->set_error(_("Could not create image file")); - } - file_local = Gio::File::create_for_path(filename_image.c_str()); - - file_remote->copy_async(file_local, sigc::mem_fun(*this, - &ImportDialog::on_thumbnail_image_downloaded), Gio::FILE_COPY_OVERWRITE); -} - -void ImportDialog::on_image_downloaded(const Glib::RefPtr& result) -{ - bool success = file_thumbnail_remote->copy_finish(result); - - if (success) { - m_signal_response.emit(filename_image); - } else { - filename_image = ""; - } -} - - /* * Callback for cursor chage */ @@ -550,48 +517,125 @@ void ImportDialog::update_preview(int row) Glib::ustring date = list_results->get_text(row, RESULTS_COLUMN_DATE); } -void ImportDialog::download_thumbnail_image(int row) + +std::string ImportDialog::get_temporary_dir(DownloadType type) +{ + std::string ocal_tmp_dir = Glib::build_filename(Glib::get_tmp_dir(), + "openclipart"); + + if (type == TYPE_THUMBNAIL) { + return Glib::build_filename(ocal_tmp_dir, "thumbnails"); + } else { + return Glib::build_filename(ocal_tmp_dir, "images"); + } +} + +void ImportDialog::create_temporary_dirs() +{ + // Make sure the temporary directories exists, if not, create them + std::string ocal_tmp_thumbnail_dir = get_temporary_dir(TYPE_THUMBNAIL); + std::string ocal_tmp_image_dir = get_temporary_dir(TYPE_IMAGE); + + if (!Glib::file_test(ocal_tmp_thumbnail_dir, Glib::FILE_TEST_EXISTS)) { + Glib::RefPtr directory = Gio::File::create_for_path(ocal_tmp_thumbnail_dir); + directory->make_directory_with_parents(); + } + + if (!Glib::file_test(ocal_tmp_image_dir, Glib::FILE_TEST_EXISTS)) { + Glib::RefPtr directory = Gio::File::create_for_path(ocal_tmp_image_dir); + directory->make_directory_with_parents(); + } +} + +void ImportDialog::download_image(int row) { // Get Remote File URL - Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); - file_thumbnail_remote = Gio::File::create_for_uri(url.c_str()); - - // Create local file - const std::string tmptemplate = "ocal-"; - std::string tmpname; - int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate); - if (fd < 0) { - widget_status->set_error(_("Could not create thumbnail file")); - return; + Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_URL); + Glib::RefPtr file_remote = Gio::File::create_for_uri(url.c_str()); + + std::string ocal_tmp_image_dir = get_temporary_dir(TYPE_IMAGE); + + // Make a unique filename for the clipart, in the form 'GUID.extension' + Glib::ustring guid = list_results->get_text(row, RESULTS_COLUMN_GUID); + Glib::ustring original_filename = list_results->get_text(row, RESULTS_COLUMN_FILENAME); + Glib::ustring extension = Inkscape::IO::get_file_extension(original_filename); + + Glib::ustring filename = Glib::ustring::compose("%1%2", guid, extension); + std::string path = Glib::build_filename(ocal_tmp_image_dir, filename.c_str()); + + // Download it asynchronously + Glib::RefPtr file_local = Gio::File::create_for_path(path); + file_remote->copy_async(file_local, + sigc::bind , Glib::ustring>( + sigc::mem_fun(*this, &ImportDialog::on_image_downloaded), + file_remote, path), + Gio::FILE_COPY_OVERWRITE); +} + +void ImportDialog::on_image_downloaded(const Glib::RefPtr& result, + Glib::RefPtr file_remote, Glib::ustring path) +{ + // Try to show the the thumbnail in the Preview widget + bool success = file_remote->copy_finish(result); + + try { + widget_status->clear(); + m_signal_response.emit(path); + widget_status->set_info(_("Clipart downloaded successfully")); + } catch(Glib::Error) { + success = false; } - close(fd); - // make sure we don't collide with other users on the same machine - filename_thumbnail = tmpname; - filename_thumbnail.append("-"); - filename_thumbnail.append(list_results->get_text(row, RESULTS_COLUMN_FILENAME)); - // rename based on original image's name, retaining extension - if (rename(tmpname.c_str(), filename_thumbnail.c_str()) < 0) { - unlink(tmpname.c_str()); - widget_status->set_error(_("Could not create thumbnail file")); + + // If anything went wrong, show an error message + if (!success) { + widget_status->set_error(_("Could not download image")); + path = ""; } - file_thumbnail_local = Gio::File::create_for_path(filename_thumbnail.c_str()); +} + +void ImportDialog::download_thumbnail_image(int row) +{ + // Get Remote File URL + Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); + Glib::RefPtr file_thumbnail_remote = Gio::File::create_for_uri(url); + + std::string ocal_tmp_thumbnail_dir = get_temporary_dir(TYPE_THUMBNAIL); + + // Make a unique filename for the clipart, in the form 'GUID.extension' + Glib::ustring guid = list_results->get_text(row, RESULTS_COLUMN_GUID); + Glib::ustring original_filename = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_FILENAME); + Glib::ustring extension = Inkscape::IO::get_file_extension(original_filename); - file_thumbnail_remote->copy_async(file_thumbnail_local, sigc::mem_fun(*this, - &ImportDialog::on_thumbnail_image_downloaded), Gio::FILE_COPY_OVERWRITE); + Glib::ustring filename_thumbnail = Glib::ustring::compose("%1%2", guid, extension); + std::string path_thumbnail = Glib::build_filename(ocal_tmp_thumbnail_dir, filename_thumbnail.c_str()); + + // Download it asynchronously + Glib::RefPtr file_thumbnail_local = Gio::File::create_for_path(path_thumbnail); + file_thumbnail_remote->copy_async(file_thumbnail_local, + sigc::bind , Glib::ustring>( + sigc::mem_fun(*this, &ImportDialog::on_thumbnail_image_downloaded), + file_thumbnail_remote, path_thumbnail), + Gio::FILE_COPY_OVERWRITE); } -/* - * Callback for row activated - */ -void ImportDialog::on_thumbnail_image_downloaded(const Glib::RefPtr& result) + +void ImportDialog::on_thumbnail_image_downloaded(const Glib::RefPtr& result, + Glib::RefPtr file_thumbnail_remote, Glib::ustring path_thumbnail) { + // Try to show the the thumbnail in the Preview widget bool success = file_thumbnail_remote->copy_finish(result); - if (success) { - preview_files->showImage(filename_thumbnail); - } else { + try { + widget_status->clear(); + preview_files->showImage(path_thumbnail); + } catch(Glib::Error) { + success = false; + } + + // If anything went wrong, show an error message + if (!success) { widget_status->set_error(_("Could not download thumbnail file")); - filename_thumbnail = ""; + path_thumbnail = ""; } } @@ -674,10 +718,21 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) { xmlChar *xml_thumbnail_url = xmlGetProp(cur_node, (xmlChar*) "url"); char* thumbnail_url = (char*) xml_thumbnail_url; + char* thumbnail_filename = g_path_get_basename(thumbnail_url); set_text(row_num, RESULTS_COLUMN_THUMBNAIL_URL, thumbnail_url); + set_text(row_num, RESULTS_COLUMN_THUMBNAIL_FILENAME, thumbnail_filename); xmlFree(xml_thumbnail_url); } + else if (!strcmp((const char*)cur_node->name, "guid")) + { + xmlChar *xml_guid = xmlNodeGetContent(cur_node); + char* guid_url = (char*) xml_guid; + char* guid = g_path_get_basename(guid_url); + + set_text(row_num, RESULTS_COLUMN_GUID, guid); + xmlFree(xml_guid); + } } populate_from_xml(cur_node->children); } @@ -691,6 +746,12 @@ void ImportDialog::on_button_search_clicked() on_entry_search_activated(); } + +void ImportDialog::on_button_close_clicked() +{ + hide_all(); +} + /** * Callback for user input into entry_search */ @@ -817,6 +878,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, preview_files = new SVGPreview(); /// Add the buttons in the bottom of the dialog button_cancel = new Gtk::Button(Gtk::Stock::CANCEL); + button_close = new Gtk::Button(_("Close")); button_import = new Gtk::Button(_("Import")); list_results = new SearchResultList(RESULTS_COLUMN_LENGTH, *preview_files, *label_description, *button_import); @@ -834,6 +896,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, hbox_bottom->pack_start(*widget_status, true, true); hbox_bottom->pack_start(*hbuttonbox_bottom, true, true); hbuttonbox_bottom->pack_start(*button_cancel, false, false); + hbuttonbox_bottom->pack_start(*button_close, false, false); hbuttonbox_bottom->pack_start(*button_import, false, false); hbuttonbox_search->pack_start(*button_search, false, false); hbox_tags.pack_start(*entry_search, true, true); @@ -851,7 +914,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, vbox->set_spacing(12); hbuttonbox_bottom->set_spacing(6); hbuttonbox_bottom->set_layout(Gtk::BUTTONBOX_END); - button_import->set_sensitive(false); + //button_import->set_sensitive(false); entry_search->set_max_length(255); hbox_tags.set_spacing(6); preview_files->showNoPreview(); @@ -870,12 +933,18 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, label_not_found->set_size_request(260, -1); notebook_content->set_show_tabs(false); notebook_content->set_show_border(false); + button_cancel->set_no_show_all(true); + button_close->set_no_show_all(true); + button_close->show(); + button_cancel->hide(); // Signals entry_search->signal_activate().connect( sigc::mem_fun(*this, &ImportDialog::on_entry_search_activated)); button_import->signal_clicked().connect( sigc::mem_fun(*this, &ImportDialog::on_button_import_clicked)); + button_close->signal_clicked().connect( + sigc::mem_fun(*this, &ImportDialog::on_button_close_clicked)); button_search->signal_clicked().connect( sigc::mem_fun(*this, &ImportDialog::on_button_search_clicked)); list_results->signal_cursor_changed().connect( @@ -885,6 +954,9 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, show_all_children(); entry_search->grab_focus(); + + // Make sure the temporary directories needed later exist + create_temporary_dirs(); } /** diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 5085ad232..0850c64e1 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -82,9 +82,7 @@ public: FileDialogBase(const Glib::ustring &title, Gtk::Window& parent) : Gtk::Window(Gtk::WINDOW_TOPLEVEL) { set_title(title); - - //set_modal(TRUE); - //sp_transientize((GtkWidget*) gobj()); + sp_transientize((GtkWidget*) gobj()); } /* @@ -275,6 +273,7 @@ public: void clear(); void set_error(Glib::ustring text); + void set_info(Glib::ustring text); void start_process(Glib::ustring text); void end_process(); @@ -329,8 +328,10 @@ enum { RESULTS_COLUMN_CREATOR, RESULTS_COLUMN_DATE, RESULTS_COLUMN_FILENAME, + RESULTS_COLUMN_THUMBNAIL_FILENAME, RESULTS_COLUMN_URL, RESULTS_COLUMN_THUMBNAIL_URL, + RESULTS_COLUMN_GUID, RESULTS_COLUMN_LENGTH, }; @@ -340,6 +341,11 @@ enum { NOTEBOOK_PAGE_NOT_FOUND, }; +enum DownloadType { + TYPE_THUMBNAIL, + TYPE_IMAGE, +}; + /** * The TreeView which holds the search results */ @@ -402,6 +408,7 @@ private: Gtk::Label *label_description; Gtk::Button *button_search; Gtk::Button *button_import; + Gtk::Button *button_close; Gtk::Button *button_cancel; StatusWidget *widget_status; @@ -418,24 +425,24 @@ private: Glib::ustring xml_uri; char xml_buffer[8192]; - // File - Glib::RefPtr file_local; - Glib::RefPtr file_remote; - Glib::RefPtr file_thumbnail_local; - Glib::RefPtr file_thumbnail_remote; - void update_label_no_search_results(); void update_preview(int row); void on_list_results_cursor_changed(); void download_thumbnail_image(int row); - void on_thumbnail_image_downloaded(const Glib::RefPtr& result); + void on_thumbnail_image_downloaded(const Glib::RefPtr& result, + Glib::RefPtr file_thumbnail_remote, Glib::ustring path_thumbnail); void download_image(int row); - void on_image_downloaded(const Glib::RefPtr& result); + void on_image_downloaded(const Glib::RefPtr& result, + Glib::RefPtr file_remote, Glib::ustring filename_image); void on_list_results_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void on_button_import_clicked(); + void on_button_close_clicked(); + void on_button_cancel_clicked(); void on_button_search_clicked(); void on_entry_search_activated(); void on_xml_file_read(const Glib::RefPtr& result); + void create_temporary_dirs(); + std::string get_temporary_dir(DownloadType type); /** -- cgit v1.2.3 From 0faa205b30f7e71d0420bc6f963a93aaeb0160ee Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 25 Mar 2011 19:51:14 +0000 Subject: Improving preview widget (bzr r10092.1.19) --- src/ui/dialog/ocaldialogs.cpp | 181 +++++++++++++++++++++++++++++++++++++++--- src/ui/dialog/ocaldialogs.h | 41 +++++++++- 2 files changed, 209 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 3abce1a0b..6fd8137ff 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -283,6 +283,164 @@ ExportPasswordDialog::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### +LoadingBox::LoadingBox() : Gtk::EventBox() +{ + set_visible_window(false); + draw_spinner = false; + spinner_step = 0; + signal_expose_event().connect(sigc::mem_fun(*this, &LoadingBox::_on_expose_event), false); +} + +bool LoadingBox::_on_expose_event(GdkEventExpose* event) +{ + Cairo::RefPtr cr = get_window()->create_cairo_context(); + + // Draw shadow + int x = get_allocation().get_x(); + int y = get_allocation().get_y(); + int width = get_allocation().get_width(); + int height = get_allocation().get_height(); + + get_style()->paint_shadow(get_window(), get_state(), Gtk::SHADOW_IN, + Gdk::Rectangle(x, y, width, height), + *this, Glib::ustring::ustring("viewport"), x, y, width, height); + + if (draw_spinner) { + + int spinner_size = 16; + int spinner_x = x + (width - spinner_size) / 2; + int spinner_y = y + (height - spinner_size) / 2; + + // FIXME: Gtk::Style::paint_spinner not yet in gtkmm + gtk_paint_spinner(gtk_widget_get_style(GTK_WIDGET(gobj())), + gtk_widget_get_window(GTK_WIDGET(gobj())), + gtk_widget_get_state(GTK_WIDGET(gobj())), NULL, GTK_WIDGET(gobj()), + NULL, spinner_step, spinner_x, spinner_y, spinner_size, spinner_size); + } + + return false; +} + +void LoadingBox::start() +{ + // Timeout hasn't been stopped, so must be disconnected + if ((draw_spinner != false) & (timeout != NULL)) { + timeout.disconnect(); + } + + draw_spinner = true; + timeout = Glib::signal_timeout().connect(sigc::mem_fun(*this, &LoadingBox::on_timeout), 80); +} + +void LoadingBox::stop() +{ + draw_spinner = false; +} + +bool LoadingBox::on_timeout() { + if (draw_spinner) { + + if (spinner_step == 11) { + spinner_step = 0; + } else { + spinner_step ++; + } + + queue_draw(); + return true; + } + return false; +} + + +PreviewWidget::PreviewWidget() : Gtk::VBox(false, 12) +{ + box_loading = new LoadingBox(); + image = new Gtk::Image(); + + label_title = new Gtk::Label(); + label_description = new Gtk::Label(); + label_time = new Gtk::Label(); + + pack_start(*box_loading, false, false); + pack_start(*image, false, false); + pack_start(*label_title, false, false); + pack_start(*label_description, false, false); + pack_start(*label_time, false, false); + + label_title->set_line_wrap(true); + label_title->set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + label_description->set_line_wrap(true); + label_description->set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + label_time->set_line_wrap(true); + label_time->set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + + label_title->set_size_request(90, -1); + label_description->set_size_request(90, -1); + label_time->set_size_request(90, -1); + box_loading->set_size_request(90, 90); + set_border_width(12); + + signal_expose_event().connect(sigc::mem_fun(*this, &PreviewWidget::_on_expose_event), false); +} + +void PreviewWidget::set_metadata(Glib::ustring description, Glib::ustring creator, + Glib::ustring time) +{ + label_title->set_markup(g_markup_printf_escaped("%s", description.c_str())); + label_description->set_markup(g_markup_printf_escaped("%s", creator.c_str())); + label_time->set_markup(g_markup_printf_escaped("%s", time.c_str())); + + show_box_loading(); +} + +void PreviewWidget::show_box_loading() +{ + box_loading->show(); + box_loading->start(); +} + +void PreviewWidget::hide_box_loading() +{ + box_loading->hide(); + box_loading->stop(); +} + +void PreviewWidget::set_image(std::string path) +{ + image->set(path); + hide_box_loading(); + image->show(); +} + +void PreviewWidget::clear() +{ + label_title->set_markup(""); + label_description->set_markup(""); + label_time->set_markup(""); + + box_loading->hide(); + image->hide(); +} + +bool PreviewWidget::_on_expose_event(GdkEventExpose* event) +{ + Cairo::RefPtr cr = get_window()->create_cairo_context(); + + // Draw background + int x = get_allocation().get_x(); + int y = get_allocation().get_y(); + int width = get_allocation().get_width(); + int height = get_allocation().get_height(); + Gdk::Color background_fill = get_style()->get_base(get_state()); + + cr->rectangle(x, y, width, height); + Gdk::Cairo::set_source_color(cr, background_fill); + cr->fill(); + + return false; +} + StatusWidget::StatusWidget() : Gtk::HBox(false, 6) { image = new Gtk::Image(Gtk::Stock::DIALOG_ERROR, Gtk::ICON_SIZE_MENU); @@ -458,8 +616,7 @@ bool LogoArea::_on_expose_event(GdkEventExpose* event) return false; } -SearchResultList::SearchResultList(guint columns_count, SVGPreview& filesPreview, - Gtk::Label& description, Gtk::Button& okButton) : ListViewText(columns_count) +SearchResultList::SearchResultList(guint columns_count) : ListViewText(columns_count) { set_headers_visible(false); set_column_title(RESULTS_COLUMN_MARKUP, _("Clipart found")); @@ -491,7 +648,7 @@ void ImportDialog::on_button_import_clicked() { } /* - * Callback for cursor chage + * Callback for cursor change */ void ImportDialog::on_list_results_cursor_changed() { @@ -511,10 +668,12 @@ void ImportDialog::on_list_results_cursor_changed() } void ImportDialog::update_preview(int row) { - Glib::ustring title = list_results->get_text(row, RESULTS_COLUMN_TITLE); Glib::ustring description = list_results->get_text(row, RESULTS_COLUMN_DESCRIPTION); Glib::ustring creator = list_results->get_text(row, RESULTS_COLUMN_CREATOR); Glib::ustring date = list_results->get_text(row, RESULTS_COLUMN_DATE); + + preview_files->clear(); + preview_files->set_metadata(description, creator, date); } @@ -627,7 +786,7 @@ void ImportDialog::on_thumbnail_image_downloaded(const Glib::RefPtrclear(); - preview_files->showImage(path_thumbnail); + preview_files->set_image(path_thumbnail); } catch(Glib::Error) { success = false; } @@ -875,13 +1034,13 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, entry_search = new SearchEntry(); button_search = new Gtk::Button(_("Search")); Gtk::HButtonBox* hbuttonbox_search = new Gtk::HButtonBox(); - preview_files = new SVGPreview(); + Gtk::ScrolledWindow* scrolledwindow_preview = new Gtk::ScrolledWindow(); + preview_files = new PreviewWidget(); /// Add the buttons in the bottom of the dialog button_cancel = new Gtk::Button(Gtk::Stock::CANCEL); button_close = new Gtk::Button(_("Close")); button_import = new Gtk::Button(_("Import")); - list_results = new SearchResultList(RESULTS_COLUMN_LENGTH, - *preview_files, *label_description, *button_import); + list_results = new SearchResultList(RESULTS_COLUMN_LENGTH); drawingarea_logo = new LogoArea(); notebook_content = new Gtk::Notebook(); widget_status = new StatusWidget(); @@ -902,7 +1061,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, hbox_tags.pack_start(*entry_search, true, true); hbox_tags.pack_start(*hbuttonbox_search, false, false); hbox_files.pack_start(*notebook_content, true, true); - hbox_files.pack_start(*preview_files, true, true); + scrolledwindow_preview->add(*preview_files); + hbox_files.pack_start(*scrolledwindow_preview, true, true); notebook_content->insert_page(*basebox_logo, NOTEBOOK_PAGE_LOGO); notebook_content->insert_page(scrolledwindow_list, NOTEBOOK_PAGE_RESULTS); @@ -917,7 +1077,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, //button_import->set_sensitive(false); entry_search->set_max_length(255); hbox_tags.set_spacing(6); - preview_files->showNoPreview(); + preview_files->clear(); notebook_content->set_current_page(NOTEBOOK_PAGE_LOGO); /// Add the listview inside a ScrolledWindow scrolledwindow_list.add(*list_results); @@ -931,6 +1091,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, label_not_found->set_line_wrap_mode(Pango::WRAP_WORD); label_not_found->set_justify(Gtk::JUSTIFY_CENTER); label_not_found->set_size_request(260, -1); + scrolledwindow_preview->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); notebook_content->set_show_tabs(false); notebook_content->set_show_border(false); button_cancel->set_no_show_all(true); diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 0850c64e1..d0784dfb6 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -262,6 +262,42 @@ private: //### F I L E I M P O R T F R O M O C A L //######################################################################### +class LoadingBox : public Gtk::EventBox +{ +public: + LoadingBox(); + + void start(); + void stop(); + +private: + uint spinner_step; + sigc::connection timeout; + bool draw_spinner; + bool _on_expose_event(GdkEventExpose* event); + bool on_timeout(); +}; + +class PreviewWidget : public Gtk::VBox +{ +public: + PreviewWidget(); + + void set_metadata(Glib::ustring description, Glib::ustring creator, Glib::ustring time); + void show_box_loading(); + void hide_box_loading(); + void set_image(std::string path); + void clear(); + bool _on_expose_event(GdkEventExpose* event); + +private: + LoadingBox* box_loading; + Gtk::Image* image; + + Gtk::Label* label_title; + Gtk::Label* label_description; + Gtk::Label* label_time; +}; /** * A Widget that contains an status icon and a message @@ -352,8 +388,7 @@ enum DownloadType { class SearchResultList : public Gtk::ListViewText { public: - SearchResultList(guint columns_count, SVGPreview& filesPreview, - Gtk::Label& description, Gtk::Button& okButton); + SearchResultList(guint columns_count); void populate_from_xml(xmlNode* a_node); }; @@ -403,7 +438,7 @@ private: SearchEntry *entry_search; LogoArea *drawingarea_logo; SearchResultList *list_results; - SVGPreview *preview_files; + PreviewWidget *preview_files; Gtk::Label *label_not_found; Gtk::Label *label_description; Gtk::Button *button_search; -- cgit v1.2.3 From d039527800711fd1b7a86f1670b8ab45cd8b8cea Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 25 Mar 2011 19:53:27 +0000 Subject: Change menutems and title to "Import Clip Art" (bzr r10092.1.20) --- src/file.cpp | 2 +- src/ui/dialog/ocaldialogs.cpp | 1 - src/verbs.cpp | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/file.cpp b/src/file.cpp index cee5280c0..76e1e9d6d 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1470,7 +1470,7 @@ sp_file_import_from_ocal(Gtk::Window &parent_window) parent_window, import_path, Inkscape::UI::Dialog::IMPORT_TYPES, - (char const *)_("Import From Open Clip Art Library")); + (char const *)_("Import Clip Art")); import_ocal_dialog->signal_response().connect( sigc::ptr_fun(&on_import_from_ocal_response)); diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 6fd8137ff..0a65ffb47 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -352,7 +352,6 @@ bool LoadingBox::on_timeout() { return false; } - PreviewWidget::PreviewWidget() : Gtk::VBox(false, 12) { box_loading = new LoadingBox(); diff --git a/src/verbs.cpp b/src/verbs.cpp index 1ad68b792..db0659d2c 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2257,7 +2257,7 @@ Verb *Verb::_base_verbs[] = { N_("Import a bitmap or SVG image into this document"), INKSCAPE_ICON_DOCUMENT_IMPORT), new FileVerb(SP_VERB_FILE_EXPORT, "FileExport", N_("_Export Bitmap..."), N_("Export this document or a selection as a bitmap image"), INKSCAPE_ICON_DOCUMENT_EXPORT), - new FileVerb(SP_VERB_FILE_IMPORT_FROM_OCAL, "FileImportFromOCAL", N_("Import From Open Clip Art Library"), N_("Import a document from Open Clip Art Library"), INKSCAPE_ICON_DOCUMENT_IMPORT_OCAL), + new FileVerb(SP_VERB_FILE_IMPORT_FROM_OCAL, "FileImportFromOCAL", N_("Import Clip Art"), N_("Import clipart from Open Clip Art Library"), INKSCAPE_ICON_DOCUMENT_IMPORT_OCAL), // new FileVerb(SP_VERB_FILE_EXPORT_TO_OCAL, "FileExportToOCAL", N_("Export To Open Clip Art Library"), N_("Export this document to Open Clip Art Library"), INKSCAPE_ICON_DOCUMENT_EXPORT_OCAL), new FileVerb(SP_VERB_FILE_NEXT_DESKTOP, "NextWindow", N_("N_ext Window"), N_("Switch to the next document window"), INKSCAPE_ICON_WINDOW_NEXT), -- cgit v1.2.3 From f560bad9a92209e596e8394023b4af96d630d8e1 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 25 Mar 2011 20:08:46 +0000 Subject: Increased size of OCAL logo and removed "Powered by" text Removed border of LoadingBox on startup (bzr r10092.1.21) --- src/ui/dialog/ocaldialogs.cpp | 30 ++++++------------------------ src/ui/dialog/ocaldialogs.h | 2 -- src/verbs.cpp | 2 +- 3 files changed, 7 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 0a65ffb47..75b5e077a 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -374,6 +374,8 @@ PreviewWidget::PreviewWidget() : Gtk::VBox(false, 12) label_time->set_line_wrap(true); label_time->set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + box_loading->set_no_show_all(true); + image->set_no_show_all(true); label_title->set_size_request(90, -1); label_description->set_size_request(90, -1); label_time->set_size_request(90, -1); @@ -381,6 +383,8 @@ PreviewWidget::PreviewWidget() : Gtk::VBox(false, 12) set_border_width(12); signal_expose_event().connect(sigc::mem_fun(*this, &PreviewWidget::_on_expose_event), false); + + clear(); } void PreviewWidget::set_metadata(Glib::ustring description, Glib::ustring creator, @@ -567,20 +571,9 @@ LogoArea::LogoArea() : Gtk::EventBox() draw_logo = false; } signal_expose_event().connect(sigc::mem_fun(*this, &LogoArea::_on_expose_event)); - signal_realize().connect(sigc::mem_fun(*this, &LogoArea::_on_realize)); set_visible_window(false); } -void LogoArea::_on_realize() -{ - Gdk::Color color = get_style()->get_mid(get_state()); - layout = this->create_pango_layout(""); - Glib::ustring markup = Glib::ustring::compose("%2", - color.to_string(), _("Powered by")); - - layout->set_markup(markup); -} - bool LogoArea::_on_expose_event(GdkEventExpose* event) { if (draw_logo) { @@ -588,28 +581,17 @@ bool LogoArea::_on_expose_event(GdkEventExpose* event) int y = get_allocation().get_y(); int width = get_allocation().get_width(); int height = get_allocation().get_height(); + int x_logo = x + (width - 220) / 2; + int y_logo = y + (height - 76) / 2; Cairo::RefPtr cr = get_window()->create_cairo_context(); // Draw logo, we mask [read fill] it with the mid colour from the // user's GTK theme Gdk::Color logo_fill = get_style()->get_mid(get_state()); - int x_logo = x + width - 12 - 127; - int y_logo = y + height - 12 - 44; Gdk::Cairo::set_source_color(cr, logo_fill); cr->mask(logo_mask, x_logo, y_logo); - - // Draw text - Pango::Rectangle extents = layout->get_pixel_logical_extents(); - int text_width = extents.get_width(); - int text_height = extents.get_height(); - - int x_text = x_logo - text_width - 12; - int y_text = y + height - text_height - 12; - - get_style()->paint_layout(get_window(), get_state(), true, - Gdk::Rectangle(x, y, width, height), *this, "", x_text, y_text, layout); } return false; diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index d0784dfb6..40cd3e867 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -340,10 +340,8 @@ public: LogoArea(); private: bool _on_expose_event(GdkEventExpose* event); - void _on_realize(); bool draw_logo; Cairo::RefPtr logo_mask; - Glib::RefPtr layout; }; /** diff --git a/src/verbs.cpp b/src/verbs.cpp index db0659d2c..f31a3df58 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2257,7 +2257,7 @@ Verb *Verb::_base_verbs[] = { N_("Import a bitmap or SVG image into this document"), INKSCAPE_ICON_DOCUMENT_IMPORT), new FileVerb(SP_VERB_FILE_EXPORT, "FileExport", N_("_Export Bitmap..."), N_("Export this document or a selection as a bitmap image"), INKSCAPE_ICON_DOCUMENT_EXPORT), - new FileVerb(SP_VERB_FILE_IMPORT_FROM_OCAL, "FileImportFromOCAL", N_("Import Clip Art"), N_("Import clipart from Open Clip Art Library"), INKSCAPE_ICON_DOCUMENT_IMPORT_OCAL), + new FileVerb(SP_VERB_FILE_IMPORT_FROM_OCAL, "FileImportFromOCAL", N_("Import Clip Art..."), N_("Import clipart from Open Clip Art Library"), INKSCAPE_ICON_DOCUMENT_IMPORT_OCAL), // new FileVerb(SP_VERB_FILE_EXPORT_TO_OCAL, "FileExportToOCAL", N_("Export To Open Clip Art Library"), N_("Export this document to Open Clip Art Library"), INKSCAPE_ICON_DOCUMENT_EXPORT_OCAL), new FileVerb(SP_VERB_FILE_NEXT_DESKTOP, "NextWindow", N_("N_ext Window"), N_("Switch to the next document window"), INKSCAPE_ICON_WINDOW_NEXT), -- cgit v1.2.3 From 15efa741213c01b0b01f63877978b90054672a96 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sat, 26 Mar 2011 08:22:37 +0000 Subject: Sorted wrapping of labels (bzr r10092.1.22) --- src/file.cpp | 1 - src/ui/dialog/ocaldialogs.cpp | 33 ++++++++++++++++++++++----------- src/ui/dialog/ocaldialogs.h | 28 +++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/file.cpp b/src/file.cpp index 76e1e9d6d..6fda8052b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1468,7 +1468,6 @@ sp_file_import_from_ocal(Gtk::Window &parent_window) import_ocal_dialog = new Inkscape::UI::Dialog::OCAL::ImportDialog( parent_window, - import_path, Inkscape::UI::Dialog::IMPORT_TYPES, (char const *)_("Import Clip Art")); diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 75b5e077a..2f90d09a2 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -283,6 +283,17 @@ ExportPasswordDialog::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### +WrapLabel::WrapLabel() : Gtk::Label() +{ + signal_size_allocate().connect(sigc::mem_fun(*this, &WrapLabel::_on_size_allocate)); +} + +void WrapLabel::_on_size_allocate(Gtk::Allocation& allocation) +{ + set_size_request(allocation.get_width(), -1); +} + + LoadingBox::LoadingBox() : Gtk::EventBox() { set_visible_window(false); @@ -306,7 +317,6 @@ bool LoadingBox::_on_expose_event(GdkEventExpose* event) *this, Glib::ustring::ustring("viewport"), x, y, width, height); if (draw_spinner) { - int spinner_size = 16; int spinner_x = x + (width - spinner_size) / 2; int spinner_y = y + (height - spinner_size) / 2; @@ -357,9 +367,9 @@ PreviewWidget::PreviewWidget() : Gtk::VBox(false, 12) box_loading = new LoadingBox(); image = new Gtk::Image(); - label_title = new Gtk::Label(); - label_description = new Gtk::Label(); - label_time = new Gtk::Label(); + label_title = new WrapLabel(); + label_description = new WrapLabel(); + label_time = new WrapLabel(); pack_start(*box_loading, false, false); pack_start(*image, false, false); @@ -369,10 +379,13 @@ PreviewWidget::PreviewWidget() : Gtk::VBox(false, 12) label_title->set_line_wrap(true); label_title->set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + label_title->set_justify(Gtk::JUSTIFY_CENTER); label_description->set_line_wrap(true); label_description->set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + label_description->set_justify(Gtk::JUSTIFY_CENTER); label_time->set_line_wrap(true); label_time->set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + label_time->set_justify(Gtk::JUSTIFY_CENTER); box_loading->set_no_show_all(true); image->set_no_show_all(true); @@ -889,7 +902,7 @@ void ImportDialog::on_button_search_clicked() void ImportDialog::on_button_close_clicked() { - hide_all(); + hide(); } /** @@ -897,6 +910,7 @@ void ImportDialog::on_button_close_clicked() */ void ImportDialog::on_entry_search_activated() { + preview_files->clear(); widget_status->start_process(_("Searching clipart...")); notebook_content->set_current_page(NOTEBOOK_PAGE_LOGO); @@ -991,9 +1005,7 @@ void ImportDialog::update_label_no_search_results() /** * Constructor. Not called directly. Use the factory. */ -ImportDialog::ImportDialog(Gtk::Window& parent_window, - const Glib::ustring &/*dir*/, - FileDialogType file_types, +ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types, const Glib::ustring &title) : FileDialogBase(title, parent_window) { @@ -1027,7 +1039,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, widget_status = new StatusWidget(); // Packing - this->add(*vbox); + add(*vbox); vbox->pack_start(hbox_tags, false, false); vbox->pack_start(hbox_files, true, true); vbox->pack_start(*hbox_bottom, false, false); @@ -1065,8 +1077,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, scrolledwindow_list.set_shadow_type(Gtk::SHADOW_IN); /// Only show the scrollbars when they are necessary scrolledwindow_list.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - scrolledwindow_list.set_size_request(310, 230); - drawingarea_logo->set_size_request(310, 230); + preview_files->set_size_request(120, -1); hbox_files.set_spacing(12); label_not_found->set_line_wrap(true); label_not_found->set_line_wrap_mode(Pango::WRAP_WORD); diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 40cd3e867..cceff1c8e 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -83,6 +83,15 @@ public: { set_title(title); sp_transientize((GtkWidget*) gobj()); + + // Allow shrinking of window so labels wrap correctly + set_resizable(true); + + Gdk::Geometry geom; + geom.min_width = 480; + geom.min_height = 320; + + set_geometry_hints(*this, geom, Gdk::HINT_MIN_SIZE); } /* @@ -262,6 +271,15 @@ private: //### F I L E I M P O R T F R O M O C A L //######################################################################### +class WrapLabel : public Gtk::Label +{ +public: + WrapLabel(); + +private: + void _on_size_allocate(Gtk::Allocation& allocation); +}; + class LoadingBox : public Gtk::EventBox { public: @@ -294,9 +312,9 @@ private: LoadingBox* box_loading; Gtk::Image* image; - Gtk::Label* label_title; - Gtk::Label* label_description; - Gtk::Label* label_time; + WrapLabel* label_title; + WrapLabel* label_description; + WrapLabel* label_time; }; /** @@ -402,8 +420,8 @@ public: * @param fileTypes one of FileDialogTypes * @param title the title of the dialog */ - ImportDialog(Gtk::Window& parent_window, const Glib::ustring &dir, - FileDialogType file_types, const Glib::ustring &title); + ImportDialog(Gtk::Window& parent_window, FileDialogType file_types, + const Glib::ustring &title); /** * Destructor. -- cgit v1.2.3 From 74936820470b96c834dfff8a997d35fc05f260c5 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sat, 26 Mar 2011 13:11:21 +0000 Subject: Starting disabling widgets at certain times Cleanup of XML variables (bzr r10092.1.23) --- src/ui/dialog/ocaldialogs.cpp | 37 ++++++++++++++++++++++++++++++------- src/ui/dialog/ocaldialogs.h | 7 +------ 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 2f90d09a2..88b1fede0 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -629,6 +629,17 @@ SearchResultList::SearchResultList(guint columns_count) : ListViewText(columns_c } } +void ImportDialog::on_list_results_selection_changed() +{ + Glib::ustring guid = list_results->get_text(row, RESULTS_COLUMN_GUID); + + printf("Selected text is: %s", guid.c_str()); + + bool item_selected = (!guid.empty()); + + button_import.set_sensitive(item_selected); +} + void ImportDialog::on_button_import_clicked() { std::vector pathlist; @@ -638,6 +649,9 @@ void ImportDialog::on_button_import_clicked() { int row = posArray[0]; download_image(row); + button_import->set_sensitive(false); + button_close->hide(); + button_cancel->show(); widget_status->start_process(_("Downloading image...")); } @@ -657,8 +671,6 @@ void ImportDialog::on_list_results_cursor_changed() update_preview(row); download_thumbnail_image(row); - - } void ImportDialog::update_preview(int row) { @@ -744,6 +756,10 @@ void ImportDialog::on_image_downloaded(const Glib::RefPtr& res widget_status->set_error(_("Could not download image")); path = ""; } + + button_import->set_sensitive(true); + button_close->show(); + button_cancel->hide(); } void ImportDialog::download_thumbnail_image(int row) @@ -920,7 +936,7 @@ void ImportDialog::on_entry_search_activated() Glib::ustring search_keywords = entry_search->get_text(); // Create the URI to the OCAL RSS feed - xml_uri = Glib::ustring::compose("http://%1/media/feed/rss/%2", + Glib::ustring xml_uri = Glib::ustring::compose("http://%1/media/feed/rss/%2", prefs->getString("/options/ocalurl/str"), search_keywords); // If we are not UTF8 if (!Glib::get_charset()) { @@ -928,11 +944,16 @@ void ImportDialog::on_entry_search_activated() } // Open the rss feed - xml_file = Gio::File::create_for_uri(xml_uri); - xml_file->load_contents_async(sigc::mem_fun(*this, &ImportDialog::on_xml_file_read)); + Glib::RefPtr xml_file = Gio::File::create_for_uri(xml_uri); + xml_file->load_contents_async( + sigc::bind, Glib::ustring>( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_read), + xml_file, xml_uri), + ); } -void ImportDialog::on_xml_file_read(const Glib::RefPtr& result) +void ImportDialog::on_xml_file_read(const Glib::RefPtr& result, + Glib::RefPtr xml_file, Glib::ustring xml_uri) { widget_status->end_process(); @@ -1067,7 +1088,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types vbox->set_spacing(12); hbuttonbox_bottom->set_spacing(6); hbuttonbox_bottom->set_layout(Gtk::BUTTONBOX_END); - //button_import->set_sensitive(false); + button_import->set_sensitive(false); entry_search->set_max_length(255); hbox_tags.set_spacing(6); preview_files->clear(); @@ -1104,6 +1125,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types sigc::mem_fun(*this, &ImportDialog::on_list_results_cursor_changed)); list_results->signal_row_activated().connect( sigc::mem_fun(*this, &ImportDialog::on_list_results_row_activated)); + list_results->get_selection()->signal_changed().connect( + sigc::mem_fun(*this, &ImportDialog::on_list_results_selection_changed)); show_all_children(); entry_search->grab_focus(); diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index cceff1c8e..61ae72a82 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -470,12 +470,6 @@ private: Gtk::ScrolledWindow scrolledwindow_list; Glib::RefPtr selection; - // XML - Glib::RefPtr xml_file; - Glib::RefPtr xml_stream; - Glib::ustring xml_uri; - char xml_buffer[8192]; - void update_label_no_search_results(); void update_preview(int row); void on_list_results_cursor_changed(); @@ -491,6 +485,7 @@ private: void on_button_cancel_clicked(); void on_button_search_clicked(); void on_entry_search_activated(); + void on_list_results_selection_changed(); void on_xml_file_read(const Glib::RefPtr& result); void create_temporary_dirs(); std::string get_temporary_dir(DownloadType type); -- cgit v1.2.3 From d70282bd1469a9c4f7130a9fa3d89cd90b573cbb Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sun, 27 Mar 2011 18:31:44 +0100 Subject: fix errors (bzr r10092.1.24) --- src/ui/dialog/ocaldialogs.cpp | 17 ++++++++++++----- src/ui/dialog/ocaldialogs.h | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 88b1fede0..49f302f06 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -631,13 +631,19 @@ SearchResultList::SearchResultList(guint columns_count) : ListViewText(columns_c void ImportDialog::on_list_results_selection_changed() { + std::vector pathlist; + pathlist = list_results->get_selection()->get_selected_rows(); + std::vector posArray(1); + posArray = pathlist[0].get_indices(); + int row = posArray[0]; + Glib::ustring guid = list_results->get_text(row, RESULTS_COLUMN_GUID); printf("Selected text is: %s", guid.c_str()); bool item_selected = (!guid.empty()); - button_import.set_sensitive(item_selected); + button_import->set_sensitive(item_selected); } @@ -943,12 +949,13 @@ void ImportDialog::on_entry_search_activated() xml_uri = Glib::filename_to_utf8(xml_uri); } - // Open the rss feed + // Open the RSS feed Glib::RefPtr xml_file = Gio::File::create_for_uri(xml_uri); + xml_file->load_contents_async( - sigc::bind, Glib::ustring>( - sigc::mem_fun(*this, &ImportDialog::on_xml_file_read), - xml_file, xml_uri), + sigc::bind , Glib::ustring>( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_read), + xml_file, xml_uri) ); } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 61ae72a82..ffaad9757 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -486,7 +486,8 @@ private: void on_button_search_clicked(); void on_entry_search_activated(); void on_list_results_selection_changed(); - void on_xml_file_read(const Glib::RefPtr& result); + void on_xml_file_read(const Glib::RefPtr& result, + Glib::RefPtr xml_file, Glib::ustring xml_uri); void create_temporary_dirs(); std::string get_temporary_dir(DownloadType type); -- cgit v1.2.3 From 5172e7175375982a2d4727826b9061f74b0c2bee Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Mon, 28 Mar 2011 18:18:59 +0100 Subject: Don't re-download resources downloaded previously (bzr r10092.1.25) --- src/ui/dialog/ocaldialogs.cpp | 42 +++++++++++++++++++++++++++++++----------- src/ui/dialog/ocaldialogs.h | 2 ++ 2 files changed, 33 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 49f302f06..c296454d5 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -638,11 +638,8 @@ void ImportDialog::on_list_results_selection_changed() int row = posArray[0]; Glib::ustring guid = list_results->get_text(row, RESULTS_COLUMN_GUID); - - printf("Selected text is: %s", guid.c_str()); bool item_selected = (!guid.empty()); - button_import->set_sensitive(item_selected); } @@ -654,11 +651,11 @@ void ImportDialog::on_button_import_clicked() { posArray = pathlist[0].get_indices(); int row = posArray[0]; - download_image(row); button_import->set_sensitive(false); button_close->hide(); button_cancel->show(); widget_status->start_process(_("Downloading image...")); + download_image(row); } /* @@ -734,6 +731,12 @@ void ImportDialog::download_image(int row) Glib::ustring filename = Glib::ustring::compose("%1%2", guid, extension); std::string path = Glib::build_filename(ocal_tmp_image_dir, filename.c_str()); + // If the file has already been downloaded, use it + if (Glib::file_test(path, Glib::FILE_TEST_EXISTS)) { + handle_image(path, true); + return; + } + // Download it asynchronously Glib::RefPtr file_local = Gio::File::create_for_path(path); file_remote->copy_async(file_local, @@ -746,9 +749,14 @@ void ImportDialog::download_image(int row) void ImportDialog::on_image_downloaded(const Glib::RefPtr& result, Glib::RefPtr file_remote, Glib::ustring path) { - // Try to show the the thumbnail in the Preview widget + // Try to import the image bool success = file_remote->copy_finish(result); + handle_image(path, success); +} + +void ImportDialog::handle_image(Glib::ustring path, bool success) +{ try { widget_status->clear(); m_signal_response.emit(path); @@ -768,12 +776,10 @@ void ImportDialog::on_image_downloaded(const Glib::RefPtr& res button_cancel->hide(); } + void ImportDialog::download_thumbnail_image(int row) { - // Get Remote File URL - Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); - Glib::RefPtr file_thumbnail_remote = Gio::File::create_for_uri(url); - + // Get Temporary Directory std::string ocal_tmp_thumbnail_dir = get_temporary_dir(TYPE_THUMBNAIL); // Make a unique filename for the clipart, in the form 'GUID.extension' @@ -783,9 +789,19 @@ void ImportDialog::download_thumbnail_image(int row) Glib::ustring filename_thumbnail = Glib::ustring::compose("%1%2", guid, extension); std::string path_thumbnail = Glib::build_filename(ocal_tmp_thumbnail_dir, filename_thumbnail.c_str()); + Glib::RefPtr file_thumbnail_local = Gio::File::create_for_path(path_thumbnail); + + // If the file has already been downloaded, use it + if (Glib::file_test(path_thumbnail, Glib::FILE_TEST_EXISTS)) { + handle_thumbnail(path_thumbnail, true); + return; + } + + // Get Remote File URL + Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); + Glib::RefPtr file_thumbnail_remote = Gio::File::create_for_uri(url); // Download it asynchronously - Glib::RefPtr file_thumbnail_local = Gio::File::create_for_path(path_thumbnail); file_thumbnail_remote->copy_async(file_thumbnail_local, sigc::bind , Glib::ustring>( sigc::mem_fun(*this, &ImportDialog::on_thumbnail_image_downloaded), @@ -793,13 +809,17 @@ void ImportDialog::download_thumbnail_image(int row) Gio::FILE_COPY_OVERWRITE); } - void ImportDialog::on_thumbnail_image_downloaded(const Glib::RefPtr& result, Glib::RefPtr file_thumbnail_remote, Glib::ustring path_thumbnail) { // Try to show the the thumbnail in the Preview widget bool success = file_thumbnail_remote->copy_finish(result); + handle_thumbnail(path_thumbnail, success); +} + +void ImportDialog::handle_thumbnail(Glib::ustring path_thumbnail, bool success) +{ try { widget_status->clear(); preview_files->set_image(path_thumbnail); diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index ffaad9757..1db386591 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -476,6 +476,8 @@ private: void download_thumbnail_image(int row); void on_thumbnail_image_downloaded(const Glib::RefPtr& result, Glib::RefPtr file_thumbnail_remote, Glib::ustring path_thumbnail); + void handle_thumbnail(Glib::ustring path_thumbnail, bool success); + void handle_image(Glib::ustring path, bool success); void download_image(int row); void on_image_downloaded(const Glib::RefPtr& result, Glib::RefPtr file_remote, Glib::ustring filename_image); -- cgit v1.2.3 From cfc0d59d2d366158f89217164b6abfdcc842f181 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Mon, 28 Mar 2011 18:57:36 +0100 Subject: Merge thumbnail and image downloading into one set of functions :) (bzr r10092.1.26) --- src/ui/dialog/ocaldialogs.cpp | 114 ++++++++++++++++-------------------------- src/ui/dialog/ocaldialogs.h | 18 +++---- 2 files changed, 52 insertions(+), 80 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index c296454d5..6b1390863 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -655,7 +655,7 @@ void ImportDialog::on_button_import_clicked() { button_close->hide(); button_cancel->show(); widget_status->start_process(_("Downloading image...")); - download_image(row); + download_resource(TYPE_IMAGE, row); } /* @@ -669,11 +669,8 @@ void ImportDialog::on_list_results_cursor_changed() posArray = pathlist[0].get_indices(); int row = posArray[0]; - // FIXME: this would be better as a per-user OCAL cache of files - // instead of filling /tmp with downloads. - update_preview(row); - download_thumbnail_image(row); + download_resource(TYPE_THUMBNAIL, row); } void ImportDialog::update_preview(int row) { @@ -686,7 +683,7 @@ void ImportDialog::update_preview(int row) } -std::string ImportDialog::get_temporary_dir(DownloadType type) +std::string ImportDialog::get_temporary_dir(ResourceType type) { std::string ocal_tmp_dir = Glib::build_filename(Glib::get_tmp_dir(), "openclipart"); @@ -715,47 +712,68 @@ void ImportDialog::create_temporary_dirs() } } -void ImportDialog::download_image(int row) +void ImportDialog::download_resource(ResourceType type, int row) { - // Get Remote File URL - Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_URL); - Glib::RefPtr file_remote = Gio::File::create_for_uri(url.c_str()); - - std::string ocal_tmp_image_dir = get_temporary_dir(TYPE_IMAGE); + // Get Temporary Directory + std::string ocal_tmp_dir = get_temporary_dir(type); // Make a unique filename for the clipart, in the form 'GUID.extension' Glib::ustring guid = list_results->get_text(row, RESULTS_COLUMN_GUID); - Glib::ustring original_filename = list_results->get_text(row, RESULTS_COLUMN_FILENAME); + Glib::ustring original_filename; + + if (type == TYPE_IMAGE) { + original_filename = list_results->get_text(row, RESULTS_COLUMN_FILENAME); + } else { + original_filename = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_FILENAME); + } Glib::ustring extension = Inkscape::IO::get_file_extension(original_filename); Glib::ustring filename = Glib::ustring::compose("%1%2", guid, extension); - std::string path = Glib::build_filename(ocal_tmp_image_dir, filename.c_str()); + std::string path = Glib::build_filename(ocal_tmp_dir, filename.c_str()); + Glib::RefPtr file_local = Gio::File::create_for_path(path); // If the file has already been downloaded, use it if (Glib::file_test(path, Glib::FILE_TEST_EXISTS)) { - handle_image(path, true); + if (type == TYPE_IMAGE) { + on_image_downloaded(path, true); + } else { + on_thumbnail_downloaded(path, true); + } return; } + // Get Remote File URL + Glib::ustring url; + + if (type == TYPE_IMAGE) { + url = list_results->get_text(row, RESULTS_COLUMN_URL); + } else { + url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); + } + + Glib::RefPtr file_remote = Gio::File::create_for_uri(url); + // Download it asynchronously - Glib::RefPtr file_local = Gio::File::create_for_path(path); file_remote->copy_async(file_local, - sigc::bind , Glib::ustring>( - sigc::mem_fun(*this, &ImportDialog::on_image_downloaded), - file_remote, path), + sigc::bind, Glib::ustring, ResourceType>( + sigc::mem_fun(*this, &ImportDialog::on_resource_downloaded), + file_remote, path, type), Gio::FILE_COPY_OVERWRITE); } -void ImportDialog::on_image_downloaded(const Glib::RefPtr& result, - Glib::RefPtr file_remote, Glib::ustring path) +void ImportDialog::on_resource_downloaded(const Glib::RefPtr& result, + Glib::RefPtr file_remote, Glib::ustring path, ResourceType resource) { - // Try to import the image bool success = file_remote->copy_finish(result); - handle_image(path, success); + if (resource == TYPE_IMAGE) { + on_image_downloaded(path, success); + } else { + on_thumbnail_downloaded(path, success); + } } -void ImportDialog::handle_image(Glib::ustring path, bool success) +void ImportDialog::on_image_downloaded(Glib::ustring path, bool success) { try { widget_status->clear(); @@ -768,7 +786,6 @@ void ImportDialog::handle_image(Glib::ustring path, bool success) // If anything went wrong, show an error message if (!success) { widget_status->set_error(_("Could not download image")); - path = ""; } button_import->set_sensitive(true); @@ -776,53 +793,11 @@ void ImportDialog::handle_image(Glib::ustring path, bool success) button_cancel->hide(); } - -void ImportDialog::download_thumbnail_image(int row) -{ - // Get Temporary Directory - std::string ocal_tmp_thumbnail_dir = get_temporary_dir(TYPE_THUMBNAIL); - - // Make a unique filename for the clipart, in the form 'GUID.extension' - Glib::ustring guid = list_results->get_text(row, RESULTS_COLUMN_GUID); - Glib::ustring original_filename = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_FILENAME); - Glib::ustring extension = Inkscape::IO::get_file_extension(original_filename); - - Glib::ustring filename_thumbnail = Glib::ustring::compose("%1%2", guid, extension); - std::string path_thumbnail = Glib::build_filename(ocal_tmp_thumbnail_dir, filename_thumbnail.c_str()); - Glib::RefPtr file_thumbnail_local = Gio::File::create_for_path(path_thumbnail); - - // If the file has already been downloaded, use it - if (Glib::file_test(path_thumbnail, Glib::FILE_TEST_EXISTS)) { - handle_thumbnail(path_thumbnail, true); - return; - } - - // Get Remote File URL - Glib::ustring url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); - Glib::RefPtr file_thumbnail_remote = Gio::File::create_for_uri(url); - - // Download it asynchronously - file_thumbnail_remote->copy_async(file_thumbnail_local, - sigc::bind , Glib::ustring>( - sigc::mem_fun(*this, &ImportDialog::on_thumbnail_image_downloaded), - file_thumbnail_remote, path_thumbnail), - Gio::FILE_COPY_OVERWRITE); -} - -void ImportDialog::on_thumbnail_image_downloaded(const Glib::RefPtr& result, - Glib::RefPtr file_thumbnail_remote, Glib::ustring path_thumbnail) -{ - // Try to show the the thumbnail in the Preview widget - bool success = file_thumbnail_remote->copy_finish(result); - - handle_thumbnail(path_thumbnail, success); -} - -void ImportDialog::handle_thumbnail(Glib::ustring path_thumbnail, bool success) +void ImportDialog::on_thumbnail_downloaded(Glib::ustring path, bool success) { try { widget_status->clear(); - preview_files->set_image(path_thumbnail); + preview_files->set_image(path); } catch(Glib::Error) { success = false; } @@ -830,7 +805,6 @@ void ImportDialog::handle_thumbnail(Glib::ustring path_thumbnail, bool success) // If anything went wrong, show an error message if (!success) { widget_status->set_error(_("Could not download thumbnail file")); - path_thumbnail = ""; } } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 1db386591..27f699190 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -393,7 +393,7 @@ enum { NOTEBOOK_PAGE_NOT_FOUND, }; -enum DownloadType { +enum ResourceType { TYPE_THUMBNAIL, TYPE_IMAGE, }; @@ -473,14 +473,12 @@ private: void update_label_no_search_results(); void update_preview(int row); void on_list_results_cursor_changed(); - void download_thumbnail_image(int row); - void on_thumbnail_image_downloaded(const Glib::RefPtr& result, - Glib::RefPtr file_thumbnail_remote, Glib::ustring path_thumbnail); - void handle_thumbnail(Glib::ustring path_thumbnail, bool success); - void handle_image(Glib::ustring path, bool success); - void download_image(int row); - void on_image_downloaded(const Glib::RefPtr& result, - Glib::RefPtr file_remote, Glib::ustring filename_image); + + void download_resource(ResourceType type, int row); + void on_resource_downloaded(const Glib::RefPtr& result, + Glib::RefPtr file_remote, Glib::ustring path, ResourceType resource); + void on_image_downloaded(Glib::ustring path, bool success); + void on_thumbnail_downloaded(Glib::ustring path, bool success); void on_list_results_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void on_button_import_clicked(); void on_button_close_clicked(); @@ -491,7 +489,7 @@ private: void on_xml_file_read(const Glib::RefPtr& result, Glib::RefPtr xml_file, Glib::ustring xml_uri); void create_temporary_dirs(); - std::string get_temporary_dir(DownloadType type); + std::string get_temporary_dir(ResourceType type); /** -- cgit v1.2.3 From 4eac3bc8085a091a3fc97fcdbfeb0a688bfe3c3d Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Mon, 4 Apr 2011 07:33:55 +0100 Subject: implement cancelling (bzr r10092.1.27) --- src/ui/dialog/ocaldialogs.cpp | 48 ++++++++++++++++++++++++++++++++++--------- src/ui/dialog/ocaldialogs.h | 4 ++++ 2 files changed, 42 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 6b1390863..889bd6776 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -669,7 +669,13 @@ void ImportDialog::on_list_results_cursor_changed() posArray = pathlist[0].get_indices(); int row = posArray[0]; + if (downloading_thumbnail) { + printf("Downloading thumbnail \n"); + cancellable_thumbnail->cancel(); + } + update_preview(row); + downloading_thumbnail = true; download_resource(TYPE_THUMBNAIL, row); } void ImportDialog::update_preview(int row) @@ -742,13 +748,18 @@ void ImportDialog::download_resource(ResourceType type, int row) return; } - // Get Remote File URL + // Get Remote File URL and get the respective cancellable object Glib::ustring url; + Glib::RefPtr cancellable; if (type == TYPE_IMAGE) { url = list_results->get_text(row, RESULTS_COLUMN_URL); + cancellable_image = Gio::Cancellable::create(); + cancellable = cancellable_image; } else { url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL); + cancellable_thumbnail = Gio::Cancellable::create(); + cancellable = cancellable_thumbnail; } Glib::RefPtr file_remote = Gio::File::create_for_uri(url); @@ -757,14 +768,20 @@ void ImportDialog::download_resource(ResourceType type, int row) file_remote->copy_async(file_local, sigc::bind, Glib::ustring, ResourceType>( sigc::mem_fun(*this, &ImportDialog::on_resource_downloaded), - file_remote, path, type), + file_remote, path, type), cancellable, Gio::FILE_COPY_OVERWRITE); } void ImportDialog::on_resource_downloaded(const Glib::RefPtr& result, Glib::RefPtr file_remote, Glib::ustring path, ResourceType resource) { - bool success = file_remote->copy_finish(result); + bool success; + + try { + success = file_remote->copy_finish(result); + } catch(Glib::Error) { + success = false; + } if (resource == TYPE_IMAGE) { on_image_downloaded(path, success); @@ -783,8 +800,8 @@ void ImportDialog::on_image_downloaded(Glib::ustring path, bool success) success = false; } - // If anything went wrong, show an error message - if (!success) { + // If anything went wrong, show an error message if the user didn't do it + if (!success && !cancellable_image->is_cancelled()) { widget_status->set_error(_("Could not download image")); } @@ -802,10 +819,12 @@ void ImportDialog::on_thumbnail_downloaded(Glib::ustring path, bool success) success = false; } - // If anything went wrong, show an error message - if (!success) { + // If anything went wrong, show an error message if the user didn't do it + if (!success && !cancellable_image->is_cancelled()) { widget_status->set_error(_("Could not download thumbnail file")); } + + downloading_thumbnail = false; } /* @@ -915,12 +934,17 @@ void ImportDialog::on_button_search_clicked() on_entry_search_activated(); } - void ImportDialog::on_button_close_clicked() { hide(); } +void ImportDialog::on_button_cancel_clicked() +{ + printf("On_button_cancel_clicked \n"); + cancellable_image->cancel(); +} + /** * Callback for user input into entry_search */ @@ -1059,6 +1083,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types drawingarea_logo = new LogoArea(); notebook_content = new Gtk::Notebook(); widget_status = new StatusWidget(); + + downloading_thumbnail = false; // Packing add(*vbox); @@ -1085,7 +1111,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types // Properties set_border_width(12); - set_default_size(480, 320); + set_default_size(480, 330); vbox->set_spacing(12); hbuttonbox_bottom->set_spacing(6); hbuttonbox_bottom->set_layout(Gtk::BUTTONBOX_END); @@ -1120,6 +1146,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types sigc::mem_fun(*this, &ImportDialog::on_button_import_clicked)); button_close->signal_clicked().connect( sigc::mem_fun(*this, &ImportDialog::on_button_close_clicked)); + button_cancel->signal_clicked().connect( + sigc::mem_fun(*this, &ImportDialog::on_button_cancel_clicked)); button_search->signal_clicked().connect( sigc::mem_fun(*this, &ImportDialog::on_button_search_clicked)); list_results->signal_cursor_changed().connect( @@ -1132,7 +1160,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types show_all_children(); entry_search->grab_focus(); - // Make sure the temporary directories needed later exist + // Create the temporary directories that will be needed later create_temporary_dirs(); } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 27f699190..6e99605da 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -470,6 +470,10 @@ private: Gtk::ScrolledWindow scrolledwindow_list; Glib::RefPtr selection; + Glib::RefPtr cancellable_image; + Glib::RefPtr cancellable_thumbnail; + bool downloading_thumbnail; + void update_label_no_search_results(); void update_preview(int row); void on_list_results_cursor_changed(); -- cgit v1.2.3 From 4b0e5d6817b03d642728a5789b623b39b9f4014a Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Mon, 4 Apr 2011 07:34:30 +0100 Subject: remove debugging stuff (bzr r10092.1.28) --- src/ui/dialog/ocaldialogs.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 889bd6776..9e81a90e8 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -670,7 +670,6 @@ void ImportDialog::on_list_results_cursor_changed() int row = posArray[0]; if (downloading_thumbnail) { - printf("Downloading thumbnail \n"); cancellable_thumbnail->cancel(); } @@ -941,7 +940,6 @@ void ImportDialog::on_button_close_clicked() void ImportDialog::on_button_cancel_clicked() { - printf("On_button_cancel_clicked \n"); cancellable_image->cancel(); } -- cgit v1.2.3 From 2ed10cd8a37a4582b2a0e07d921087b90f0b4572 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Fri, 8 Apr 2011 09:07:25 +0100 Subject: uint > unsigned int (so windows builds work) (bzr r10092.1.30) --- src/ui/dialog/ocaldialogs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 6e99605da..7fb937c81 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -289,7 +289,7 @@ public: void stop(); private: - uint spinner_step; + unsigned int spinner_step; sigc::connection timeout; bool draw_spinner; bool _on_expose_event(GdkEventExpose* event); -- cgit v1.2.3 From 96fe0edbc762c3b616ae1b2b9651392d58f20ae5 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Mon, 18 Apr 2011 17:42:15 +0100 Subject: Remove some GNOME_VFS checks Try to use read_async instead of load_contents_async, not working at the moment :( (bzr r10092.1.31) --- src/menus-skeleton.h | 2 -- src/ui/dialog/ocaldialogs.cpp | 69 +++++++++++++++++++++++++++++++++++++------ src/ui/dialog/ocaldialogs.h | 4 +++ 3 files changed, 64 insertions(+), 11 deletions(-) (limited to 'src') 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[] = " \n" " \n" " \n" -#ifdef WITH_GNOME_VFS " \n" //" \n" -#endif " \n" " \n" " \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 xml_file = Gio::File::create_for_uri(xml_uri); - xml_file->load_contents_async( + xml_file->read_async( sigc::bind , 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& result, Glib::RefPtr xml_file, Glib::ustring xml_uri) { - widget_status->end_process(); + Glib::RefPtr 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 >( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), + stream) + ); + + return; + } + + stream->read_async(buffer, 8192, + sigc::bind, 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& result, + Glib::RefPtr 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 >( + 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& 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 >( + 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& result xmlFreeDoc(doc); // free the global variables that may have been allocated by the parser xmlCleanupParser(); + + stream->close_async( + sigc::bind< Glib::RefPtr >( + sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), + stream) + ); } +void ImportDialog::on_xml_file_stream_closed(const Glib::RefPtr& result, + Glib::RefPtr 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& result, Glib::RefPtr xml_file, Glib::ustring xml_uri); + void on_xml_file_stream_read(const Glib::RefPtr& result, + Glib::RefPtr stream, char* buffer, Glib::ustring xml_uri); + void on_xml_file_stream_closed(const Glib::RefPtr& result, + Glib::RefPtr stream); void create_temporary_dirs(); std::string get_temporary_dir(ResourceType type); -- cgit v1.2.3 From cb90d1d5a804cc46a9067999d1c227872fb3b516 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sun, 26 Jun 2011 09:18:58 +0100 Subject: Revert changing to read_async (bzr r10092.1.32) --- src/ui/dialog/ocaldialogs.cpp | 69 ++++++------------------------------------- src/ui/dialog/ocaldialogs.h | 4 --- 2 files changed, 9 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index f4317cdd0..9e81a90e8 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 xml_file = Gio::File::create_for_uri(xml_uri); - xml_file->read_async( + xml_file->load_contents_async( sigc::bind , Glib::ustring>( sigc::mem_fun(*this, &ImportDialog::on_xml_file_read), xml_file, xml_uri) @@ -978,45 +978,14 @@ void ImportDialog::on_entry_search_activated() void ImportDialog::on_xml_file_read(const Glib::RefPtr& result, Glib::RefPtr xml_file, Glib::ustring xml_uri) { - Glib::RefPtr stream; - char* buffer[8192]; + widget_status->end_process(); - 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 >( - sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), - stream) - ); - - return; - } - - stream->read_async(buffer, 8192, - sigc::bind, 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& result, - Glib::RefPtr stream, char* buffer, Glib::ustring xml_uri) -{ - gssize success = stream->read_finish(result); - - if (success == -1) { + char* data; + gsize length; + + bool sucess = xml_file->load_contents_finish(result, data, length); + if (!sucess) { widget_status->set_error(_("Could not connect to the Open Clip Art Library")); - - stream->close_async( - sigc::bind< Glib::RefPtr >( - sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), - stream) - ); - return; } @@ -1026,26 +995,17 @@ void ImportDialog::on_xml_file_stream_read(const Glib::RefPtr& xmlDoc *doc = NULL; xmlNode *root_element = NULL; - printf("%f\n", (double) success); - - doc = xmlReadMemory(buffer, 8192, xml_uri.c_str(), NULL, + doc = xmlReadMemory(data, (int) length, 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 (success == 0) { + if (length == 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 >( - sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), - stream) - ); - return; } @@ -1070,19 +1030,8 @@ void ImportDialog::on_xml_file_stream_read(const Glib::RefPtr& xmlFreeDoc(doc); // free the global variables that may have been allocated by the parser xmlCleanupParser(); - - stream->close_async( - sigc::bind< Glib::RefPtr >( - sigc::mem_fun(*this, &ImportDialog::on_xml_file_stream_closed), - stream) - ); } -void ImportDialog::on_xml_file_stream_closed(const Glib::RefPtr& result, - Glib::RefPtr 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 2891efbe4..7fb937c81 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -492,10 +492,6 @@ private: void on_list_results_selection_changed(); void on_xml_file_read(const Glib::RefPtr& result, Glib::RefPtr xml_file, Glib::ustring xml_uri); - void on_xml_file_stream_read(const Glib::RefPtr& result, - Glib::RefPtr stream, char* buffer, Glib::ustring xml_uri); - void on_xml_file_stream_closed(const Glib::RefPtr& result, - Glib::RefPtr stream); void create_temporary_dirs(); std::string get_temporary_dir(ResourceType type); -- cgit v1.2.3 From 28751002e981c82cc0f99d4532a2e7b5aae491da Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sun, 26 Jun 2011 09:59:54 +0100 Subject: Correct ustring syntax (bzr r10092.1.33) --- src/ui/dialog/ocaldialogs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 9e81a90e8..3194046b8 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -314,7 +314,7 @@ bool LoadingBox::_on_expose_event(GdkEventExpose* event) get_style()->paint_shadow(get_window(), get_state(), Gtk::SHADOW_IN, Gdk::Rectangle(x, y, width, height), - *this, Glib::ustring::ustring("viewport"), x, y, width, height); + *this, Glib::ustring("viewport"), x, y, width, height); if (draw_spinner) { int spinner_size = 16; @@ -567,7 +567,7 @@ bool BaseBox::_on_expose_event(GdkEventExpose* event) get_style()->paint_shadow(get_window(), get_state(), Gtk::SHADOW_IN, Gdk::Rectangle(x, y, width, height), - *this, Glib::ustring::ustring("viewport"), x, y, width, height); + *this, Glib::ustring("viewport"), x, y, width, height); return false; } -- cgit v1.2.3 From 9ac541ca23d1205cb01eb42fcd47ae9c4a08ad64 Mon Sep 17 00:00:00 2001 From: "Andrew rugby471@gmail.com" <> Date: Sat, 2 Jul 2011 17:33:13 +0100 Subject: Fixed issues with cancelling downloading of thumbnails and images, all should be well now :) (bzr r10092.1.34) --- src/ui/dialog/ocaldialogs.cpp | 49 +++++++++++++++++++++++++++++-------------- src/ui/dialog/ocaldialogs.h | 2 ++ 2 files changed, 35 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 3194046b8..1295b7fe6 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -671,6 +671,7 @@ void ImportDialog::on_list_results_cursor_changed() if (downloading_thumbnail) { cancellable_thumbnail->cancel(); + cancelled_thumbnail = true; } update_preview(row); @@ -791,6 +792,19 @@ void ImportDialog::on_resource_downloaded(const Glib::RefPtr& void ImportDialog::on_image_downloaded(Glib::ustring path, bool success) { + button_import->set_sensitive(true); + button_close->show(); + button_cancel->hide(); + + // If anything went wrong, show an error message if the user didn't do it + if (!success && !cancelled_image) { + widget_status->set_error(_("Could not download image")); + } + if (!success) { + widget_status->clear(); + return; + } + try { widget_status->clear(); m_signal_response.emit(path); @@ -798,32 +812,32 @@ void ImportDialog::on_image_downloaded(Glib::ustring path, bool success) } catch(Glib::Error) { success = false; } - - // If anything went wrong, show an error message if the user didn't do it - if (!success && !cancellable_image->is_cancelled()) { - widget_status->set_error(_("Could not download image")); - } - - button_import->set_sensitive(true); - button_close->show(); - button_cancel->hide(); + + cancelled_image = false; } void ImportDialog::on_thumbnail_downloaded(Glib::ustring path, bool success) { + downloading_thumbnail = false; + + // If anything went wrong, show an error message if the user didn't do it + if (!success && !cancelled_thumbnail) { + widget_status->set_error(_("Could not download thumbnail file")); + return; + } + if (!success) { + widget_status->clear(); + return; + } + try { widget_status->clear(); preview_files->set_image(path); } catch(Glib::Error) { success = false; } - - // If anything went wrong, show an error message if the user didn't do it - if (!success && !cancellable_image->is_cancelled()) { - widget_status->set_error(_("Could not download thumbnail file")); - } - - downloading_thumbnail = false; + + cancelled_thumbnail = false; } /* @@ -941,6 +955,7 @@ void ImportDialog::on_button_close_clicked() void ImportDialog::on_button_cancel_clicked() { cancellable_image->cancel(); + cancelled_image = true; } /** @@ -1083,6 +1098,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types widget_status = new StatusWidget(); downloading_thumbnail = false; + cancelled_thumbnail = false; + cancelled_image = false; // Packing add(*vbox); diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 7fb937c81..2ca71d5f7 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -473,6 +473,8 @@ private: Glib::RefPtr cancellable_image; Glib::RefPtr cancellable_thumbnail; bool downloading_thumbnail; + bool cancelled_thumbnail; + bool cancelled_image; void update_label_no_search_results(); void update_preview(int row); -- cgit v1.2.3 From 4289d2acf14b2b1077e07ec838c1fb0afa065bc2 Mon Sep 17 00:00:00 2001 From: Andrew Higginson Date: Tue, 27 Dec 2011 19:48:59 +0000 Subject: try to fix bug (bzr r10092.1.35) --- src/ui/dialog/ocaldialogs.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 1295b7fe6..f9c0e7212 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -634,6 +634,9 @@ void ImportDialog::on_list_results_selection_changed() std::vector pathlist; pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); + + printf("%s", "on_list_results_selection_changed"); + posArray = pathlist[0].get_indices(); int row = posArray[0]; @@ -648,6 +651,9 @@ void ImportDialog::on_button_import_clicked() { std::vector pathlist; pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); + + printf("%s", "on_button_import_clicked"); + posArray = pathlist[0].get_indices(); int row = posArray[0]; @@ -666,6 +672,9 @@ void ImportDialog::on_list_results_cursor_changed() std::vector pathlist; pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); + + printf("%s", "on_list_results_cursor_changed"); + posArray = pathlist[0].get_indices(); int row = posArray[0]; -- cgit v1.2.3 From cb9093c7d864ef914d7b1fea6596108e4ac8aa04 Mon Sep 17 00:00:00 2001 From: Andrew Higginson Date: Tue, 27 Dec 2011 21:05:11 +0000 Subject: fixed crash! (bzr r10092.1.37) --- src/ui/dialog/ocaldialogs.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index db3d1272a..3ec1f687e 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -636,8 +636,10 @@ void ImportDialog::on_list_results_selection_changed() pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); - printf("%s", "on_list_results_selection_changed\n"); - + // If nothing is selected, then return + if (((int) pathlist.size()) < 1) { + return; + } posArray = pathlist[0].get_indices(); int row = posArray[0]; @@ -653,8 +655,10 @@ void ImportDialog::on_button_import_clicked() { pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); - printf("%s", "on_button_import_clicked\n"); - + // If nothing is selected, then return + if (((int) pathlist.size()) < 1) { + return; + } posArray = pathlist[0].get_indices(); int row = posArray[0]; @@ -674,8 +678,10 @@ void ImportDialog::on_list_results_cursor_changed() pathlist = list_results->get_selection()->get_selected_rows(); std::vector posArray(1); - printf("%s", "on_list_results_cursor_changed\n"); - + // If nothing is selected, then return + if (((int) pathlist.size()) < 1) { + return; + } posArray = pathlist[0].get_indices(); int row = posArray[0]; -- cgit v1.2.3