145 lines
3.1 KiB
C++
145 lines
3.1 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <callback.h>
|
|
#include <idle.h>
|
|
#include <library.h>
|
|
|
|
#include <ocarina.h>
|
|
#include <print.h>
|
|
|
|
static Glib::RefPtr<Gtk::Builder> builder;
|
|
void enable_idle();
|
|
|
|
|
|
/*
|
|
* Collection manager functions
|
|
*/
|
|
class CollectionColumns : public Gtk::TreeModelColumnRecord {
|
|
public:
|
|
CollectionColumns()
|
|
{ add(c_col_id); add(c_col_enabled); add(c_col_size); add(c_col_path); }
|
|
|
|
Gtk::TreeModelColumn<unsigned int> c_col_id;
|
|
Gtk::TreeModelColumn<bool> c_col_enabled;
|
|
Gtk::TreeModelColumn<unsigned int> c_col_size;
|
|
Gtk::TreeModelColumn<Glib::ustring> c_col_path;
|
|
};
|
|
static CollectionColumns collection_cols;
|
|
|
|
static void on_collection_ok()
|
|
{
|
|
std::string path;
|
|
|
|
Gtk::FileChooserWidget *chooser;
|
|
get_builder()->get_widget("o_collection_chooser", chooser);
|
|
path = chooser->get_filename();
|
|
library::add_path(path);
|
|
enable_idle();
|
|
}
|
|
|
|
static void on_collection_update()
|
|
{
|
|
library :: update_all();
|
|
enable_idle();
|
|
}
|
|
|
|
static void on_collection_import()
|
|
{
|
|
library :: import();
|
|
enable_idle();
|
|
}
|
|
|
|
static void on_library_add(unsigned int id, library :: Library *path)
|
|
{
|
|
Gtk::TreeModel::Row row;
|
|
Glib::RefPtr<Gtk::ListStore> list;
|
|
|
|
list = Glib::RefPtr<Gtk::ListStore>::cast_static(builder->get_object("o_collection_dirs"));
|
|
|
|
row = *(list->append());
|
|
row[collection_cols.c_col_id] = id;
|
|
row[collection_cols.c_col_enabled] = path->enabled;
|
|
row[collection_cols.c_col_size] = path->size;
|
|
row[collection_cols.c_col_path] = path->root_path;
|
|
}
|
|
|
|
static void on_library_update(unsigned int id, library :: Library *path)
|
|
{
|
|
Gtk::TreeModel::Row row;
|
|
Glib::RefPtr<Gtk::ListStore> list = Glib::RefPtr<Gtk::ListStore>::cast_static(builder->get_object("o_collection_dirs"));
|
|
Gtk::TreeModel::Children children = list->children();
|
|
|
|
for (Gtk::TreeModel::Children::iterator it = children.begin();
|
|
it != children.end(); it++) {
|
|
row = *it;
|
|
if (row[collection_cols.c_col_id] == id)
|
|
row[collection_cols.c_col_size] = path->size;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* Idle func
|
|
*/
|
|
bool on_idle()
|
|
{
|
|
Gtk::ProgressBar *prog;
|
|
bool ret = idle::run_task();
|
|
|
|
builder->get_widget("o_idle_progress", prog);
|
|
if (ret == false)
|
|
prog->hide();
|
|
else {
|
|
prog->show();
|
|
prog->set_fraction(idle::get_progress());
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void enable_idle()
|
|
{
|
|
Glib::signal_idle().connect(sigc::ptr_fun(on_idle));
|
|
}
|
|
|
|
|
|
/*
|
|
* Ocarina functions
|
|
*/
|
|
Glib::RefPtr<Gtk::Builder> &get_builder()
|
|
{
|
|
return builder;
|
|
}
|
|
|
|
Gtk::Button *get_button(const std::string &name)
|
|
{
|
|
Gtk::Button *button;
|
|
builder->get_widget(name, button);
|
|
return button;
|
|
}
|
|
|
|
static void connect_button(const std::string &name, void (*func)())
|
|
{
|
|
get_button(name)->signal_clicked().connect(sigc::ptr_fun(func));
|
|
}
|
|
|
|
Gtk::Window *connect_wires()
|
|
{
|
|
Gtk::Window *window;
|
|
struct Callbacks *cb = get_callbacks();
|
|
|
|
builder = Gtk::Builder::create();
|
|
builder->add_from_file("gui/ocarina6.glade");
|
|
builder->get_widget("o_window", window);
|
|
|
|
/* Collection manager */
|
|
cb->on_library_add = on_library_add;
|
|
cb->on_library_update = on_library_update;
|
|
connect_button("o_collection_ok", on_collection_ok);
|
|
connect_button("o_collection_update", on_collection_update);
|
|
connect_button("o_collection_import", on_collection_import);
|
|
|
|
return window;
|
|
}
|