13
0

freesound: cosmetic tweaks

Disable the "More" button when search parameters change.  The button is
supposed to continue the current search, but if any of the search
parameters (tags, sort, or licence) have changed, that doesn't really
make sense. Just disable it if the user changes any of them.

Make sure that filenames in the freesound results list are escaped
properly for the tooltip, and append the full licence URL returned to the
tooltip too.

Make the filename column Gtk::TREE_VIEW_COLUMN_FIXED, so that it doesn't
expand to the width of the longest filename in the results and push the
columns to the right out of view. Resizing the import dialogue larger
still allows longer file names to be seen, and it's still possible to
manually resize the filename column as well.

Only show the hours & minutes in the duration column if they're non-zero,
and justify them right.
This commit is contained in:
Colin Fletcher 2022-05-27 12:09:49 +01:00
parent eae1673ff1
commit 0eb8b6aa85
2 changed files with 41 additions and 17 deletions

View File

@ -810,28 +810,37 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
vbox->pack_start (*passbox, PACK_SHRINK);
vbox->pack_start (*scroll);
freesound_list_view.append_column(_("ID") , freesound_list_columns.id);
freesound_list_view.append_column(_("Filename"), freesound_list_columns.filename);
// freesound_list_view.append_column(_("URI") , freesound_list_columns.uri);
freesound_list_view.append_column(_("Duration"), freesound_list_columns.duration);
freesound_list_view.append_column(_("Size"), freesound_list_columns.filesize);
freesound_list_view.append_column(_("ID") , freesound_list_columns.id);
freesound_list_view.append_column(_("Filename"), freesound_list_columns.filename);
freesound_list_view.append_column(_("Duration"), freesound_list_columns.duration);
freesound_list_view.append_column(_("Size"), freesound_list_columns.filesize);
freesound_list_view.append_column(_("Sample rate"), freesound_list_columns.smplrate);
freesound_list_view.append_column(_("License"), freesound_list_columns.license);
freesound_list_view.get_column(0)->set_alignment(0.5);
freesound_list_view.get_column(1)->set_expand(true); // filename
freesound_list_view.get_column(1)->set_resizable(true); // filename
freesound_list_view.get_column(2)->set_alignment(0.5);
freesound_list_view.get_column(3)->set_alignment(0.5);
freesound_list_view.get_column(4)->set_alignment(0.5);
freesound_list_view.get_column(5)->set_alignment(0.0);
freesound_list_view.append_column(_("License"), freesound_list_columns.license);
// filename
freesound_list_view.get_column(1)->set_expand(true);
freesound_list_view.get_column(1)->set_resizable(true);
freesound_list_view.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
// duration: justify contents right
CellRendererText* renderer = dynamic_cast<CellRendererText*> (freesound_list_view.get_column(2)->get_first_cell ());
if (renderer) {
renderer->property_xalign () = 1.0;
}
freesound_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_list_view_selected));
freesound_list_view.set_tooltip_column(1);
freesound_list_view.set_tooltip_column(7);
freesound_list_view.get_selection()->set_mode (SELECTION_MULTIPLE);
freesound_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &SoundFileBrowser::freesound_list_view_activated));
freesound_search_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
freesound_entry.signal_activate().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
/* disable "More" button when search parameters change */
freesound_entry.signal_changed().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_params_changed));
freesound_sort.signal_changed().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_params_changed));
freesound_licence.signal_changed().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_params_changed));
freesound_more_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_more_clicked));
freesound_similar_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_similar_clicked));
notebook.append_page (*vbox, _("Search Freesound"));
@ -1198,6 +1207,13 @@ SoundFileBrowser::freesound_more_clicked ()
freesound_list_view.scroll_to_row(Gtk::TreePath(row_path), 0);
}
void
SoundFileBrowser::freesound_search_params_changed ()
{
freesound_page = 1;
freesound_more_btn.set_sensitive(false);
}
void
SoundFileBrowser::freesound_similar_clicked ()
{
@ -1357,9 +1373,13 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
} else {
s = modf(duration_seconds/60, &m) * 60;
m = modf(m/60, &h) * 60;
sprintf(duration_hhmmss, "%02.fh:%02.fm:%04.1fs",
h, m, s
);
if (h > 0) {
sprintf(duration_hhmmss, "%2.fh:%02.fm:%04.1fs", h, m, s);
} else if (m > 0) {
sprintf(duration_hhmmss, "%2.fm:%04.1fs", m, s);
} else {
sprintf(duration_hhmmss, "%4.1fs", s);
}
}
double size_bytes = atof(filesize);
@ -1401,6 +1421,7 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
row[freesound_list_columns.filesize] = bsize;
row[freesound_list_columns.smplrate] = samplerate;
row[freesound_list_columns.license ] = shortlicense;
row[freesound_list_columns.tooltip ] = Gtkmm2ext::markup_escape_text(filename) + "\n" + licence;
matches++;
} else {
error << _("Failed to retrieve XML for file") << std::endl;

View File

@ -157,6 +157,7 @@ private:
Gtk::TreeModelColumn<std::string> filesize;
Gtk::TreeModelColumn<std::string> smplrate;
Gtk::TreeModelColumn<std::string> license;
Gtk::TreeModelColumn<std::string> tooltip;
Gtk::TreeModelColumn<bool> downloading;
FreesoundColumns() {
@ -167,6 +168,7 @@ private:
add(filesize);
add(smplrate);
add(license);
add(tooltip);
add(downloading);
}
};
@ -251,6 +253,7 @@ protected:
void freesound_search_clicked ();
void freesound_more_clicked ();
void freesound_similar_clicked ();
void freesound_search_params_changed ();
int freesound_page;
std::string freesound_token; // keep oauth token while ardour is running