125 lines
2.6 KiB
C++
125 lines
2.6 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/library.h>
|
|
#include <core/playlist.h>
|
|
#include <core/tags/track.h>
|
|
#include <lib/colmgr.h>
|
|
#include <lib/lib.h>
|
|
#include <gtkmm.h>
|
|
|
|
|
|
class CollectionColumns : public Gtk::TreeModelColumnRecord {
|
|
public:
|
|
Gtk::TreeModelColumn<unsigned int> c_id;
|
|
Gtk::TreeModelColumn<bool> c_enabled;
|
|
Gtk::TreeModelColumn<unsigned int> c_size;
|
|
Gtk::TreeModelColumn<Glib::ustring> c_path;
|
|
|
|
CollectionColumns()
|
|
{
|
|
add(c_id);
|
|
add(c_enabled);
|
|
add(c_size);
|
|
add(c_path);
|
|
}
|
|
};
|
|
|
|
|
|
static CollectionColumns c_cols;
|
|
static Glib::RefPtr<Gtk::ListStore> c_list;
|
|
|
|
|
|
static Library *find_library(const Gtk::TreeModel::Row &row)
|
|
{
|
|
return tags :: get_library(row[c_cols.c_id]);
|
|
}
|
|
|
|
static void list_path(Library *lib)
|
|
{
|
|
Gtk::TreeModel::Row row;
|
|
|
|
if (!lib)
|
|
return;
|
|
row = *(c_list->append());
|
|
|
|
row[c_cols.c_id] = lib->index();
|
|
row[c_cols.c_enabled] = lib->enabled();
|
|
row[c_cols.c_size] = lib->size();
|
|
row[c_cols.c_path] = lib->primary_key();
|
|
}
|
|
|
|
static void remove_banned_tracks()
|
|
{
|
|
std::set<unsigned int>::iterator it;
|
|
IndexEntry *ent = playlist :: get_tracks("Banned");
|
|
|
|
if (!ent)
|
|
return;
|
|
|
|
for (it = ent->begin(); it != ent->end(); it++)
|
|
library :: get_queue()->del(tags :: get_track(*it));
|
|
}
|
|
|
|
void colmgr :: init()
|
|
{
|
|
Library *library;
|
|
|
|
c_list = lib :: get_object<Gtk::ListStore>("colmgr_list");
|
|
c_list->set_sort_column(c_cols.c_path, Gtk::SORT_ASCENDING);
|
|
|
|
for (unsigned int i = 0; i < tags :: library_size(); i++) {
|
|
library = tags :: get_library(i);
|
|
if (library)
|
|
list_path(library);
|
|
}
|
|
}
|
|
|
|
void colmgr :: add_path(const std::string &path)
|
|
{
|
|
list_path(library :: add(path));
|
|
}
|
|
|
|
void colmgr :: del_path(const Gtk::TreePath &path)
|
|
{
|
|
Gtk::TreeModel::Row row = *(c_list->get_iter(path));
|
|
Library *lib = find_library(row);
|
|
library :: remove(lib);
|
|
c_list->erase(row);
|
|
}
|
|
|
|
void colmgr :: update_path(const Gtk::TreePath &path)
|
|
{
|
|
Gtk::TreeModel::Row row = *(c_list->get_iter(path));
|
|
library :: update(find_library(row));
|
|
}
|
|
|
|
void colmgr :: update_paths()
|
|
{
|
|
Library *lib;
|
|
Gtk::TreeModel::Children::iterator it;
|
|
|
|
for (it = c_list->children().begin(); it != c_list->children().end(); it++) {
|
|
lib = find_library(*it);
|
|
if (lib)
|
|
(*it)[c_cols.c_size] = lib->size();
|
|
}
|
|
}
|
|
|
|
Glib::ustring colmgr :: get_path(const Gtk::TreePath &path)
|
|
{
|
|
Gtk::TreeModel::Row row = *(c_list->get_iter(path));
|
|
return row[c_cols.c_path];
|
|
}
|
|
|
|
void colmgr :: toggle_path_enabled(const Gtk::TreePath &path)
|
|
{
|
|
Gtk::TreeModel::Row row = *(c_list->get_iter(path));
|
|
Library *lib = find_library(row);
|
|
row[c_cols.c_enabled] = !row[c_cols.c_enabled];
|
|
library :: set_enabled(lib, row[c_cols.c_enabled]);
|
|
|
|
if (row[c_cols.c_enabled])
|
|
remove_banned_tracks();
|
|
}
|