From: bdilly Date: Mon, 20 Aug 2007 01:24:18 +0000 (+0000) Subject: search and reset buttons added to ocal related features. fixed signals in import... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=83965d687aa02620e79151c91948d313bda9cbf1;p=inkscape.git search and reset buttons added to ocal related features. fixed signals in import from ocal dialog. --- diff --git a/src/file.cpp b/src/file.cpp index d5819cf0f..e8e9af9d3 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1183,24 +1183,12 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) if ((!doc->uri) && (!str)) return false; - - Inkscape::Extension::Output *extension; - - // Get the default extension name - Glib::ustring default_extension; - char *attr = (char *)repr->attribute("inkscape:output_extension"); - if (!attr) - attr = (char *)prefs_get_string_attribute("dialogs.save_as", "default"); - if (attr) - default_extension = attr; - + // Get the default extension name + Glib::ustring default_extension = "org.inkscape.output.svg.inkscape"; char formatBuf[256]; Glib::ustring filename_extension = ".svg"; - extension = dynamic_cast - (Inkscape::Extension::db.get(default_extension.c_str())); - if (extension) - filename_extension = extension->get_extension(); + selectionType = Inkscape::Extension::db.get(default_extension.c_str()); export_path = Glib::get_tmp_dir (); @@ -1221,8 +1209,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) exportDialogInstance = Inkscape::UI::Dialog::FileExportToOCALDialog::create( parentWindow, Inkscape::UI::Dialog::EXPORT_TYPES, - (char const *) _("Select file to export to"), - default_extension + (char const *) _("Select file to export to") ); success = exportDialogInstance->show(); @@ -1230,9 +1217,8 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) return success; fileName = exportDialogInstance->getFilename(); - - selectionType = exportDialogInstance->getSelectionType(); - + + fileName.append(filename_extension.c_str()); if (fileName.size() > 0) { Glib::ustring newFileName = Glib::filename_to_utf8(fileName); @@ -1250,7 +1236,9 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE); if (!success){ - g_warning( "Error saving a temporary copy." ); + gchar *text = g_strdup_printf(_("Error saving a temporary copy")); + sp_ui_error_dialog(text); + return success; } @@ -1287,7 +1275,10 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) success = file_save_remote(doc, uri, selectionType, FALSE, FALSE); remove(fileName.c_str()); if (!success) - g_warning( "Error exporting the document." ); + { + gchar *text = g_strdup_printf(_("Error exporting the document. Verify if the server name, username and password are correct. If the server have support for webdav and verify if you didn't forget to choose a license too.")); + sp_ui_error_dialog(text); + } else gotSuccess = true; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 506d9bb4a..296abe458 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -622,7 +622,7 @@ void InkscapePreferences::initPageMisc() _misc_overs_bitmap.set_size_request(_sb_width); _misc_overs_bitmap.init("options.bitmapoversample", "value", labels, values, num_items, 1); _page_misc.add_line( false, _("Oversample bitmaps:"), _misc_overs_bitmap, "", "", false); - _misc_ocal_url.init("options.ocalurl", "str", true); + _misc_ocal_url.init("options.ocalurl", "str", true, g_strdup_printf("openclipart.org")); _page_misc.add_line( false, _("Open Clip Art Library Server Name:"), _misc_ocal_url, "", _("The server name of the Open Clip Art Library webdav server. It's used by the Import and Export to OCAL function."), true); _misc_ocal_username.init("options.ocalusername", "str", true); _page_misc.add_line( false, _("Open Clip Art Library Username:"), _misc_ocal_username, "", _("The username used to log into Open Clip Art Library."), true); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index ea699e98f..8b355f28f 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -156,7 +156,7 @@ protected: PrefCheckButton _misc_imp_bitmap, _misc_comment, _misc_scripts; PrefCheckButton _misc_small_toolbar; PrefCombo _misc_overs_bitmap; - PrefEntry _misc_ocal_url; + PrefEntryButtonHBox _misc_ocal_url; PrefEntry _misc_ocal_username; PrefEntry _misc_ocal_password; diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index b99a48fa9..ae2dbd315 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -38,10 +38,9 @@ namespace Dialog FileExportToOCALDialog *FileExportToOCALDialog::create(Gtk::Window& parentWindow, FileDialogType fileTypes, - const Glib::ustring &title, - const Glib::ustring &default_key) + const Glib::ustring &title) { - FileExportToOCALDialog *dialog = new FileExportToOCALDialogImpl(parentWindow, fileTypes, title, default_key); + FileExportToOCALDialog *dialog = new FileExportToOCALDialogImpl(parentWindow, fileTypes, title); return dialog; } @@ -103,69 +102,13 @@ void FileExportToOCALDialogImpl::fileNameEntryChangedCallback() -/** - * Callback for fileNameEntry widget - */ -void FileExportToOCALDialogImpl::fileTypeChangedCallback() -{ - int sel = fileTypeComboBox.get_active_row_number(); - if (sel<0 || sel >= (int)fileTypes.size()) - return; - FileType type = fileTypes[sel]; - - extension = type.extension; - updateNameAndExtension(); -} - - - -void FileExportToOCALDialogImpl::createFileTypeMenu() -{ - Inkscape::Extension::DB::OutputList extension_list; - Inkscape::Extension::db.get_output_list(extension_list); - knownExtensions.clear(); - - for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin(); - current_item != extension_list.end(); current_item++) - { - Inkscape::Extension::Output * omod = *current_item; - - // FIXME: would be nice to grey them out instead of not listing them - if (omod->deactivated()) continue; - - FileType type; - type.name = (_(omod->get_filetypename())); - type.pattern = "*"; - Glib::ustring extension = omod->get_extension(); - knownExtensions.insert( extension.casefold() ); - fileDialogExtensionToPattern (type.pattern, extension); - type.extension= omod; - fileTypeComboBox.append_text(type.name); - fileTypes.push_back(type); - } - - //#Let user choose - FileType guessType; - guessType.name = _("Guess from extension"); - guessType.pattern = "*"; - guessType.extension = NULL; - fileTypeComboBox.append_text(guessType.name); - fileTypes.push_back(guessType); - - - fileTypeComboBox.set_active(0); - fileTypeChangedCallback(); //call at least once to set the filter -} - - /** * Constructor */ FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow, FileDialogType fileTypes, - const Glib::ustring &title, - const Glib::ustring &default_key) : + const Glib::ustring &title) : FileDialogOCALBase(title) { /* @@ -191,28 +134,11 @@ FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow fileBox.pack_start(*fileNameEntry, Gtk::PACK_EXPAND_WIDGET, 3); vbox->pack_start(fileBox); - //###### Do we want the .xxx extension automatically added? - fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically"))); - fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.export", - "append_extension", 1) ); - - createFileTypeMenu(); - - fileTypeComboBox.set_size_request(200,40); - fileTypeComboBox.signal_changed().connect( - sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileTypeChangedCallback) ); - - checksBox.pack_start( fileTypeCheckbox ); - vbox->pack_start( checksBox ); - - vbox->pack_end( fileTypeComboBox ); - //Let's do some customization fileNameEntry = NULL; Gtk::Container *cont = get_toplevel(); std::vector entries; findEntryWidgets(cont, entries); - //g_message("Found %d entry widgets\n", entries.size()); if (entries.size() >=1 ) { //Catch when user hits [return] on the text field @@ -221,18 +147,6 @@ FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileNameEntryChangedCallback) ); } - //Let's do more customization - std::vector expanders; - findExpanderWidgets(cont, expanders); - //g_message("Found %d expander widgets\n", expanders.size()); - if (expanders.size() >=1 ) - { - //Always show the file list - Gtk::Expander *expander = expanders[0]; - expander->set_expanded(true); - } - - add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK)); @@ -248,8 +162,6 @@ FileExportToOCALDialogImpl::~FileExportToOCALDialogImpl() { } - - /** * Show this dialog modally. Return true if user hits [OK] */ @@ -263,8 +175,6 @@ FileExportToOCALDialogImpl::show() if (b == Gtk::RESPONSE_OK) { - updateNameAndExtension(); - return TRUE; } else @@ -273,58 +183,6 @@ FileExportToOCALDialogImpl::show() } } - -/** - * Get the file extension type that was selected by the user. Valid after an [OK] - */ -Inkscape::Extension::Extension * -FileExportToOCALDialogImpl::getSelectionType() -{ - return extension; -} - -void FileExportToOCALDialogImpl::setSelectionType( Inkscape::Extension::Extension * key ) -{ - // If no pointer to extension is passed in, look up based on filename extension. - if ( !key ) { - // Not quite UTF-8 here. - gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1); - for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) { - Inkscape::Extension::Output *ext = dynamic_cast(fileTypes[i].extension); - if ( ext && ext->get_extension() ) { - gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 ); - if ( g_str_has_suffix(filenameLower, extensionLower) ) { - key = fileTypes[i].extension; - } - g_free(extensionLower); - } - } - g_free(filenameLower); - } - - // Ensure the proper entry in the combo box is selected. - if ( key ) { - extension = key; - gchar const * extensionID = extension->get_id(); - if ( extensionID ) { - for ( int i = 0; i < (int)fileTypes.size(); i++ ) { - Inkscape::Extension::Extension *ext = fileTypes[i].extension; - if ( ext ) { - gchar const * id = ext->get_id(); - if ( id && ( strcmp(extensionID, id) == 0) ) { - int oldSel = fileTypeComboBox.get_active_row_number(); - if ( i != oldSel ) { - fileTypeComboBox.set_active(i); - } - break; - } - } - } - } - } -} - - /** * Get the file name chosen by the user. Valid after an [OK] */ @@ -332,7 +190,9 @@ Glib::ustring FileExportToOCALDialogImpl::getFilename() { myFilename = fileNameEntry->get_text(); - updateNameAndExtension(); + if (!Glib::get_charset()) //If we are not utf8 + myFilename = Glib::filename_to_utf8(myFilename); + return myFilename; } @@ -343,40 +203,6 @@ FileExportToOCALDialogImpl::change_title(const Glib::ustring& title) this->set_title(title); } -void FileExportToOCALDialogImpl::updateNameAndExtension() -{ - // Pick up any changes the user has typed in. - Glib::ustring tmp = myFilename; // get_filename(); - - Inkscape::Extension::Output* newOut = extension ? dynamic_cast(extension) : 0; - if ( fileTypeCheckbox.get_active() && newOut ) { - try { - bool appendExtension = true; - Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename ); - Glib::ustring::size_type pos = utf8Name.rfind('.'); - if ( pos != Glib::ustring::npos ) { - Glib::ustring trail = utf8Name.substr( pos ); - Glib::ustring foldedTrail = trail.casefold(); - if ( (trail == ".") - | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold() - && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) { - utf8Name = utf8Name.erase( pos ); - } else { - appendExtension = false; - } - } - - if (appendExtension) { - utf8Name = utf8Name + newOut->get_extension(); - myFilename = Glib::filename_from_utf8( utf8Name ); - - } - } catch ( Glib::ConvertError& e ) { - // ignore - } - } -} - //######################################################################## //# F I L E E X P O R T T O O C A L P A S S W O R D @@ -405,14 +231,12 @@ FileExportToOCALPasswordDialogImpl::FileExportToOCALPasswordDialogImpl(Gtk::Wind usernameEntry = new Gtk::Entry(); usernameEntry->set_text(myUsername); usernameEntry->set_max_length(255); - //usernameEntry->set_alignment(1); passwordEntry = new Gtk::Entry(); passwordEntry->set_text(myPassword); passwordEntry->set_max_length(255); passwordEntry->set_invisible_char('*'); passwordEntry->set_visibility(false); - //passwordEntry->set_alignment(1); passwordEntry->set_activates_default(true); userBox.pack_start(*userLabel); @@ -489,19 +313,20 @@ FileExportToOCALPasswordDialogImpl::change_title(const Glib::ustring& title) //### F I L E I M P O R T F R O M O C A L //######################################################################### - /* - * Callback for row activated + * Calalback for cursor chage */ -void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) +void FileListViewText::on_cursor_changed() { // create file path myFilename = Glib::get_tmp_dir(); myFilename.append(G_DIR_SEPARATOR_S); + std::vector pathlist; + pathlist = this->get_selection()->get_selected_rows(); std::vector posArray(1); - posArray = path.get_indices(); + posArray = pathlist[0].get_indices(); myFilename.append(get_text(posArray[0], 2)); - + #ifdef WITH_GNOME_VFS gnome_vfs_init(); GnomeVFSHandle *from_handle = NULL; @@ -574,6 +399,16 @@ void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::T } +/* + * Callback for row activated + */ +void FileListViewText::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) +{ + this->on_cursor_changed(); + myButton->activate(); +} + + /* * Returns the selected filename */ @@ -762,6 +597,8 @@ FileImportFromOCALDialogImplGtk::FileImportFromOCALDialogImplGtk(Gtk::Window& pa Gtk::Label *tagLabel = new Gtk::Label(_("Search Tag")); notFoundLabel = new Gtk::Label(_("No files matched your search")); descriptionLabel = new Gtk::Label(); + descriptionLabel->set_max_width_chars(60); + descriptionLabel->set_single_line_mode(false); messageBox.pack_start(*notFoundLabel); descriptionBox.pack_start(*descriptionLabel); searchTagEntry = new Gtk::Entry(); @@ -773,7 +610,12 @@ FileImportFromOCALDialogImplGtk::FileImportFromOCALDialogImplGtk(Gtk::Window& pa tagBox.pack_start(*searchButton); filesPreview = new SVGPreview(); filesPreview->showNoPreview(); - filesList = new FileListViewText(5, *filesPreview, *descriptionLabel); + // 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 listScrolledWindow.add(*filesList); @@ -808,9 +650,6 @@ FileImportFromOCALDialogImplGtk::FileImportFromOCALDialogImplGtk(Gtk::Window& pa searchButton->signal_clicked().connect( sigc::mem_fun(*this, &FileImportFromOCALDialogImplGtk::searchTagEntryChangedCallback)); - add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK)); - show_all_children(); notFoundLabel->hide(); } diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index 4af282ee3..c7c8009de 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -90,8 +90,7 @@ public: */ static FileExportToOCALDialog *create(Gtk::Window& parentWindow, FileDialogType fileTypes, - const Glib::ustring &title, - const Glib::ustring &default_key); + const Glib::ustring &title); /** @@ -107,15 +106,6 @@ public: */ virtual bool show() =0; - /** - * Return the 'key' (filetype) of the selection, if any - * @return a pointer to a string if successful (which must - * be later freed with g_free(), else NULL. - */ - virtual Inkscape::Extension::Extension * getSelectionType() = 0; - - virtual void setSelectionType( Inkscape::Extension::Extension * key ) = 0; - virtual Glib::ustring getFilename () =0; /** @@ -278,22 +268,17 @@ class FileExportToOCALDialogImpl : public FileExportToOCALDialog, public FileDia public: FileExportToOCALDialogImpl(Gtk::Window& parentWindow, FileDialogType fileTypes, - const Glib::ustring &title, - const Glib::ustring &default_key); + const Glib::ustring &title); virtual ~FileExportToOCALDialogImpl(); bool show(); - Inkscape::Extension::Extension *getSelectionType(); - virtual void setSelectionType( Inkscape::Extension::Extension * key ); - Glib::ustring getFilename(); Glib::ustring myFilename; void change_title(const Glib::ustring& title); - void updateNameAndExtension(); private: @@ -302,13 +287,6 @@ private: */ Gtk::Entry *fileNameEntry; - - /** - * Allow the specification of the output file type - */ - Gtk::ComboBoxText fileTypeComboBox; - - /** * Data mirror of the combo box */ @@ -319,19 +297,6 @@ private: Gtk::VBox checksBox; Gtk::HBox fileBox; - Gtk::CheckButton fileTypeCheckbox; - - /** - * Callback for user choose a fileType - */ - void fileTypeChangedCallback(); - - /** - * Create a filter menu for this type of dialog - */ - void createFileTypeMenu(); - - /** * The extension to use to write this file */ @@ -404,18 +369,22 @@ private: class FileListViewText : public Gtk::ListViewText { public: - FileListViewText(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description):ListViewText(columns_count) + FileListViewText(guint columns_count, SVGPreview& filesPreview, Gtk::Label& description, Gtk::Button& okButton) + :ListViewText(columns_count) { myPreview = &filesPreview; myLabel = &description; + myButton = &okButton; } Glib::ustring getFilename(); protected: 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; + Gtk::Button *myButton; }; /** @@ -449,6 +418,7 @@ private: Gtk::Label *notFoundLabel; Gtk::Label *descriptionLabel; Gtk::Button *searchButton; + Gtk::Button *okButton; // Child widgets Gtk::HBox tagBox; diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index e1671e5b1..4de42f36f 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -267,6 +267,46 @@ void PrefCombo::on_changed() } } +void PrefEntryButtonHBox::init(const std::string& prefs_path, const std::string& attr, + bool visibility, gchar* default_string) +{ + _prefs_path = prefs_path; + _attr = attr; + _default_string = default_string; + relatedEntry = new Gtk::Entry(); + relatedButton = new Gtk::Button("Reset"); + relatedEntry->set_invisible_char('*'); + relatedEntry->set_visibility(visibility); + relatedEntry->set_text(prefs_get_string_attribute(_prefs_path.c_str(), _attr.c_str())); + this->pack_start(*relatedEntry); + this->pack_start(*relatedButton); + relatedButton->signal_clicked().connect( + sigc::mem_fun(*this, &PrefEntryButtonHBox::onRelatedButtonClickedCallback)); + relatedEntry->signal_changed().connect( + sigc::mem_fun(*this, &PrefEntryButtonHBox::onRelatedEntryChangedCallback)); +} + +void PrefEntryButtonHBox::onRelatedEntryChangedCallback() +{ + if (this->is_visible()) //only take action if user changed value + { + prefs_set_string_attribute(_prefs_path.c_str(), _attr.c_str(), + relatedEntry->get_text().c_str()); + } +} + +void PrefEntryButtonHBox::onRelatedButtonClickedCallback() +{ + if (this->is_visible()) //only take action if user changed value + { + prefs_set_string_attribute(_prefs_path.c_str(), _attr.c_str(), + _default_string); + relatedEntry->set_text(_default_string); + } +} + + + void PrefEntry::init(const std::string& prefs_path, const std::string& attr, bool visibility) { diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index 4ed0a35aa..b48672d39 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include //#include @@ -100,6 +101,21 @@ protected: void on_changed(); }; +class PrefEntryButtonHBox : public Gtk::HBox +{ +public: + void init(const std::string& prefs_path, const std::string& attr, + bool mask, gchar* default_string); +protected: + std::string _prefs_path; + std::string _attr; + gchar* _default_string; + Gtk::Button *relatedButton; + Gtk::Entry *relatedEntry; + void onRelatedEntryChangedCallback(); + void onRelatedButtonClickedCallback(); +}; + class DialogPage : public Gtk::Table { public: