initial functioning version for library mgmt
This commit is contained in:
parent
76f44c6025
commit
bb4b07cca6
@ -16,6 +16,7 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "pbd/i18n.h"
|
#include "pbd/i18n.h"
|
||||||
@ -40,15 +41,15 @@ LibraryDownloadDialog::LibraryDownloadDialog ()
|
|||||||
_display.append_column (_("Author"), _columns.author);
|
_display.append_column (_("Author"), _columns.author);
|
||||||
_display.append_column (_("License"), _columns.license);
|
_display.append_column (_("License"), _columns.license);
|
||||||
_display.append_column (_("Size"), _columns.size);
|
_display.append_column (_("Size"), _columns.size);
|
||||||
_display.append_column_editable (_("Installed"), _columns.installed);
|
_display.append_column (_("Installed"), _columns.installed);
|
||||||
|
_display.append_column_editable ("", _columns.install);
|
||||||
Gtk::CellRendererToggle *toggle = dynamic_cast<Gtk::CellRendererToggle *> (_display.get_column_cell_renderer (4));
|
append_progress_column ();
|
||||||
toggle->set_alignment (0.0, 0.5);
|
|
||||||
toggle->signal_toggled().connect (sigc::mem_fun (*this, &LibraryDownloadDialog::install_activated));
|
|
||||||
|
|
||||||
_display.set_headers_visible (true);
|
_display.set_headers_visible (true);
|
||||||
_display.set_tooltip_column (5); /* path */
|
_display.set_tooltip_column (5); /* path */
|
||||||
|
|
||||||
|
_display.signal_button_press_event().connect (sigc::mem_fun (*this, &LibraryDownloadDialog::display_button_press), false);
|
||||||
|
|
||||||
Gtk::HBox* h = new Gtk::HBox;
|
Gtk::HBox* h = new Gtk::HBox;
|
||||||
h->set_spacing (8);
|
h->set_spacing (8);
|
||||||
h->set_border_width (8);
|
h->set_border_width (8);
|
||||||
@ -63,6 +64,17 @@ LibraryDownloadDialog::LibraryDownloadDialog ()
|
|||||||
lf.foreach_description (boost::bind (&LibraryDownloadDialog::add_library, this, _1));
|
lf.foreach_description (boost::bind (&LibraryDownloadDialog::add_library, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LibraryDownloadDialog::append_progress_column ()
|
||||||
|
{
|
||||||
|
progress_renderer = new Gtk::CellRendererProgress();
|
||||||
|
progress_renderer->property_width() = 100;
|
||||||
|
Gtk::TreeViewColumn* tvc = manage (new Gtk::TreeViewColumn ("", *progress_renderer));
|
||||||
|
tvc->add_attribute (*progress_renderer, "value", _columns.progress);
|
||||||
|
_display.append_column (*tvc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LibraryDownloadDialog::add_library (ARDOUR::LibraryDescription const & ld)
|
LibraryDownloadDialog::add_library (ARDOUR::LibraryDescription const & ld)
|
||||||
{
|
{
|
||||||
@ -75,19 +87,39 @@ LibraryDownloadDialog::add_library (ARDOUR::LibraryDescription const & ld)
|
|||||||
(*i)[_columns.installed] = ld.installed();
|
(*i)[_columns.installed] = ld.installed();
|
||||||
(*i)[_columns.url] = ld.url();
|
(*i)[_columns.url] = ld.url();
|
||||||
|
|
||||||
|
if (ld.installed()) {
|
||||||
|
(*i)[_columns.install] = string();
|
||||||
|
} else {
|
||||||
|
(*i)[_columns.install] = string (_("Install"));
|
||||||
|
}
|
||||||
|
|
||||||
/* tooltip must be escape for pango markup, and we should strip all
|
/* tooltip must be escape for pango markup, and we should strip all
|
||||||
* duplicate spaces
|
* duplicate spaces
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(*i)[_columns.description] = Glib::Markup::escape_text (ld.description());
|
(*i)[_columns.description] = Glib::Markup::escape_text (ld.description());
|
||||||
std::cerr << "set descr to " << ld.description() << std::endl;
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LibraryDownloadDialog::install (std::string const & path, Gtk::TreePath const & treepath)
|
||||||
|
{
|
||||||
|
Gtk::TreeModel::iterator row = _model->get_iter (treepath);
|
||||||
|
LibraryFetcher lf;
|
||||||
|
|
||||||
|
if (lf.add (path) == 0) {
|
||||||
|
(*row)[_columns.installed] = true;
|
||||||
|
(*row)[_columns.install] = string();;
|
||||||
|
} else {
|
||||||
|
(*row)[_columns.installed] = false;
|
||||||
|
(*row)[_columns.install] = _("Install");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LibraryDownloadDialog::install_activated (std::string str)
|
LibraryDownloadDialog::download (Gtk::TreePath const & path)
|
||||||
{
|
{
|
||||||
Gtk::TreeModel::iterator row = _model->get_iter (Gtk::TreePath (str));
|
Gtk::TreeModel::iterator row = _model->get_iter (path);
|
||||||
std::string url = (*row)[_columns.url];
|
std::string url = (*row)[_columns.url];
|
||||||
|
|
||||||
std::cerr << "will download " << url << " to " << Config->get_clip_library_dir() << std::endl;
|
std::cerr << "will download " << url << " to " << Config->get_clip_library_dir() << std::endl;
|
||||||
@ -96,7 +128,7 @@ LibraryDownloadDialog::install_activated (std::string str)
|
|||||||
|
|
||||||
/* setup timer callback to update progressbar */
|
/* setup timer callback to update progressbar */
|
||||||
|
|
||||||
Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &LibraryDownloadDialog::dl_timer_callback), downloader, str), 40);
|
Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &LibraryDownloadDialog::dl_timer_callback), downloader, path), 40);
|
||||||
|
|
||||||
/* and go ... */
|
/* and go ... */
|
||||||
|
|
||||||
@ -104,22 +136,73 @@ LibraryDownloadDialog::install_activated (std::string str)
|
|||||||
|
|
||||||
(*row)[_columns.downloader] = downloader;
|
(*row)[_columns.downloader] = downloader;
|
||||||
|
|
||||||
/* and back to the GUI, though we're modal so not much is possible */
|
/* and back to the GUI event loop, though we're modal so not much is possible */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LibraryDownloadDialog::dl_timer_callback (Downloader* dl, std::string path_str)
|
LibraryDownloadDialog::dl_timer_callback (Downloader* dl, Gtk::TreePath treepath)
|
||||||
{
|
{
|
||||||
double prog = dl->progress();
|
Gtk::TreeModel::iterator row = _model->get_iter (treepath);
|
||||||
|
|
||||||
std::cerr << "prog: " << prog << std::endl;
|
/* zero status indicates still running; positive status indicates
|
||||||
|
* success; negative value indicates failure
|
||||||
|
*/
|
||||||
|
|
||||||
/* set something based on this */
|
if (dl->status() == 0) {
|
||||||
if (dl->status() != 0) {
|
(*row)[_columns.progress] = (int) round ((dl->progress() * 100.0));
|
||||||
delete dl;
|
return true; /* call again */
|
||||||
Gtk::TreeModel::iterator row = _model->get_iter (Gtk::TreePath (path_str));
|
}
|
||||||
|
|
||||||
|
(*row)[_columns.progress] = 0.;
|
||||||
(*row)[_columns.downloader] = 0;
|
(*row)[_columns.downloader] = 0;
|
||||||
|
|
||||||
|
if (dl->status() < 0) {
|
||||||
|
(*row)[_columns.install] = _("Install");;
|
||||||
|
} else {
|
||||||
|
(*row)[_columns.install] = _("Installing");
|
||||||
|
install (dl->download_path(), treepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete dl;
|
||||||
|
|
||||||
return false; /* no more calls, done or cancelled */
|
return false; /* no more calls, done or cancelled */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
LibraryDownloadDialog::display_button_press (GdkEventButton* ev)
|
||||||
|
{
|
||||||
|
if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 1)) {
|
||||||
|
|
||||||
|
Gtk::TreeModel::Path path;
|
||||||
|
Gtk::TreeViewColumn* column;
|
||||||
|
int cellx, celly;
|
||||||
|
|
||||||
|
if (!_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gtk::TreeIter iter = _model->get_iter (path);
|
||||||
|
|
||||||
|
std::cerr << "Click\n";
|
||||||
|
|
||||||
|
string cur = (*iter)[_columns.install];
|
||||||
|
if (cur == _("Install")) {
|
||||||
|
if (!(*iter)[_columns.installed]) {
|
||||||
|
(*iter)[_columns.install] = _("Cancel");
|
||||||
|
download (path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Downloader* dl = (*iter)[_columns.downloader];
|
||||||
|
|
||||||
|
if (dl) {
|
||||||
|
dl->cancel ();
|
||||||
|
}
|
||||||
|
|
||||||
|
(*iter)[_columns.install] = _("Install");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <gtkmm/cellrendererprogress.h>
|
||||||
#include <gtkmm/entry.h>
|
#include <gtkmm/entry.h>
|
||||||
#include <gtkmm/liststore.h>
|
#include <gtkmm/liststore.h>
|
||||||
#include <gtkmm/treeview.h>
|
#include <gtkmm/treeview.h>
|
||||||
@ -50,16 +51,23 @@ class LibraryDownloadDialog : public ArdourDialog
|
|||||||
add (installed);
|
add (installed);
|
||||||
add (description);
|
add (description);
|
||||||
add (url);
|
add (url);
|
||||||
|
add (install);
|
||||||
|
add (progress);
|
||||||
|
add (downloader);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gtk::TreeModelColumn<std::string> name;
|
Gtk::TreeModelColumn<std::string> name;
|
||||||
Gtk::TreeModelColumn<std::string> author;
|
Gtk::TreeModelColumn<std::string> author;
|
||||||
Gtk::TreeModelColumn<std::string> license;
|
Gtk::TreeModelColumn<std::string> license;
|
||||||
Gtk::TreeModelColumn<std::string> size;
|
Gtk::TreeModelColumn<std::string> size;
|
||||||
Gtk::TreeModelColumn<std::string> description;
|
Gtk::TreeModelColumn<std::string> install;
|
||||||
Gtk::TreeModelColumn<std::string> url;
|
|
||||||
Gtk::TreeModelColumn<bool> installed;
|
Gtk::TreeModelColumn<bool> installed;
|
||||||
|
/* these are not displayed */
|
||||||
|
Gtk::TreeModelColumn<std::string> url;
|
||||||
Gtk::TreeModelColumn<ARDOUR::Downloader*> downloader;
|
Gtk::TreeModelColumn<ARDOUR::Downloader*> downloader;
|
||||||
|
Gtk::TreeModelColumn<double> progress;
|
||||||
|
/* used as tooltip */
|
||||||
|
Gtk::TreeModelColumn<std::string> description;
|
||||||
};
|
};
|
||||||
|
|
||||||
Gtk::TreeView _display;
|
Gtk::TreeView _display;
|
||||||
@ -78,14 +86,15 @@ class LibraryDownloadDialog : public ArdourDialog
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tv_query_tooltip (int x, int y, bool kbd, const Glib::RefPtr<Gtk::Tooltip>& tooltip);
|
Gtk::CellRendererProgress* progress_renderer;
|
||||||
|
|
||||||
|
void append_progress_column ();
|
||||||
|
|
||||||
void setup_col (Gtk::TreeViewColumn*, int, Gtk::AlignmentEnum, const char*, const char*);
|
void download (Gtk::TreePath const &);
|
||||||
void setup_toggle (Gtk::TreeViewColumn*, sigc::slot<void, std::string>);
|
void install (std::string const & path, Gtk::TreePath const & treepath);
|
||||||
|
|
||||||
void install_activated (std::string str);
|
bool dl_timer_callback (ARDOUR::Downloader*, Gtk::TreePath);
|
||||||
bool dl_timer_callback (ARDOUR::Downloader*, std::string);
|
bool display_button_press (GdkEventButton* ev);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user