Turn off library paths

I set the "visible" field to "false" and then remove each track from the
library playlist.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-05-23 07:48:10 -04:00
parent f5181c50b1
commit 4afce6300c
4 changed files with 80 additions and 15 deletions

View File

@ -39,6 +39,10 @@ namespace libsaria
void delete_path(Path *);
void update_path(Path *);
void save_path(Path *);
void hide_path(Path *);
void show_path(Path *);
Track *lookup(unsigned int, unsigned int);
Playlist *get_playlist();

View File

@ -88,8 +88,10 @@ void read_path(ifstream &stream)
}
notify_path_updated(path_ptr);
lib_playlist.add_tracks(tracks);
libsaria::ban::get_banned_plist()->add_tracks(banned);
if (path.visible) {
lib_playlist.add_tracks(tracks);
libsaria::ban::get_banned_plist()->add_tracks(banned);
}
}
unsigned int schedule_load()

View File

@ -107,6 +107,34 @@ namespace libsaria
do_update_path(&(*it));
}
void library::hide_path(Path *path)
{
list<Track *> tracks;
list<Track>::iterator it;
for (it = path->tracks.begin(); it != path->tracks.end(); it++)
tracks.push_back(&(*it));
path->visible = false;
path->data_state = DIRTY;
save_path(path);
lib_playlist.remove_tracks(tracks);
notify_path_updated(path);
}
void library::show_path(Path *path)
{
list<Track *> tracks;
list<Track>::iterator it;
for (it = path->tracks.begin(); it != path->tracks.end(); it++)
tracks.push_back(&(*it));
path->visible = true;
path->data_state = DIRTY;
save_path(path);
lib_playlist.add_tracks(tracks);
notify_path_updated(path);
}
Track *library::lookup(unsigned int libid, unsigned int trackid)
{
list<Path>::iterator p_it;

View File

@ -29,7 +29,7 @@ static LibraryDriver driver;
static GtkListStore *path_list;
static struct library_info columns[] = {
library_info("Pointer", G_TYPE_POINTER, false),
library_info("Enabled", G_TYPE_BOOLEAN, true),
library_info("Filepath", G_TYPE_STRING, true),
library_info("Size", G_TYPE_UINT, true),
};
@ -60,9 +60,10 @@ void LibraryDriver::path_updated(libsaria::library::Path *path)
return;
gtk_list_store_set(path_list, &iter,
1, path->path.c_str(),
2, path->tracks.size(),
-1);
1, path->visible,
2, path->path.c_str(),
3, path->tracks.size(),
-1);
}
void LibraryDriver::path_added(libsaria::library::Path *path)
@ -72,8 +73,9 @@ void LibraryDriver::path_added(libsaria::library::Path *path)
gtk_list_store_append(path_list, &iter);
gtk_list_store_set(path_list, &iter,
0, path,
1, path->path.c_str(),
2, path->tracks.size(),
1, path->visible,
2, path->path.c_str(),
3, path->tracks.size(),
-1);
}
@ -123,6 +125,21 @@ static libsaria::library::Path *get_selected_path(GtkWidget *treeview)
return path;
}
static void path_toggled(GtkCellRendererToggle *toggle, gchar *path, gpointer data)
{
GtkTreeIter iter;
libsaria::library::Path *lib_path = NULL;
if (!gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(path_list), &iter, path))
return;
gtk_tree_model_get(GTK_TREE_MODEL(path_list), &iter, 0, &lib_path, -1);
if (gtk_cell_renderer_toggle_get_active(toggle))
libsaria::library::hide_path(lib_path);
else
libsaria::library::show_path(lib_path);
}
static void show_rc_menu(GtkWidget *widget, GdkEvent *event, gpointer data)
{
}
@ -164,20 +181,34 @@ static void setup_liststore(GtkWidget *treeview)
{
GtkTreeViewColumn *col;
GtkCellRenderer *textcell = gtk_cell_renderer_text_new();
GType types[NUM_COLUMNS];
GtkCellRenderer *checkcell = gtk_cell_renderer_toggle_new();
GType types[NUM_COLUMNS + 1];
types[0] = G_TYPE_POINTER;
for (unsigned int i = 0; i < NUM_COLUMNS; i++)
types[i] = columns[i].type;
types[i + 1] = columns[i].type;
path_list = gtk_list_store_newv(NUM_COLUMNS + 1, types);
path_list = gtk_list_store_newv(NUM_COLUMNS, types);
gtk_cell_renderer_text_set_fixed_height_from_font(GTK_CELL_RENDERER_TEXT(textcell), 1);
g_signal_connect(checkcell, "toggled", G_CALLBACK(path_toggled), NULL);
for (unsigned int i = 0; i < NUM_COLUMNS; i++) {
if (columns[i].type == G_TYPE_POINTER)
continue;
string attribute;
GtkCellRenderer *renderer;
if (columns[i].type == G_TYPE_BOOLEAN) {
renderer = checkcell;
attribute = "active";
} else {
renderer = textcell;
attribute = "text";
}
col = gtk_tree_view_column_new_with_attributes(columns[i].name,
textcell,
"text", i,
renderer,
attribute.c_str(),
i + 1,
NULL);
gtk_tree_view_column_set_visible(col, columns[i].visible);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);