plist: Move more playlist functions into lib/

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-07-27 11:39:08 -04:00
parent 97a8646977
commit 160d2ac3be
4 changed files with 25 additions and 14 deletions

View File

@ -12,7 +12,6 @@ Gtk::Window *ocarina_init(int *argc, char ***argv)
lib :: init(argc, argv, "ocarina6.glade"); lib :: init(argc, argv, "ocarina6.glade");
Gtk::Window *window = setup_gui(); Gtk::Window *window = setup_gui();
playlist :: select("Favorites");
post_init_tabs(); post_init_tabs();
return window; return window;
} }

View File

@ -6,7 +6,7 @@
#include <gui/tabs.h> #include <gui/tabs.h>
static Glib::ustring current_playlist(); static bool find_cur_path(Gtk::TreePath &path);
/** /**
* Playlist tab stuff * Playlist tab stuff
@ -37,14 +37,16 @@ PlaylistTab :: ~PlaylistTab()
bool PlaylistTab :: on_key_press_event(const std::string &key) bool PlaylistTab :: on_key_press_event(const std::string &key)
{ {
Gtk::TreePath path;
std::vector<unsigned int> ids; std::vector<unsigned int> ids;
if (key != "Delete") if (key != "Delete")
return Tab :: on_key_press_event(key); return Tab :: on_key_press_event(key);
tab_selected_ids(ids); if (find_cur_path(path)) {
for (unsigned int i = 0; i < ids.size(); i++) tab_selected_ids(ids);
playlist :: del(tagdb :: lookup(ids[i]), current_playlist()); plist :: del_path_ids(path, ids);
}
return true; return true;
} }
@ -63,18 +65,11 @@ static bool find_cur_path(Gtk::TreePath &path)
return !path.empty(); return !path.empty();
} }
static Glib::ustring current_playlist() static void on_playlist_cursor_changed()
{ {
Gtk::TreePath path; Gtk::TreePath path;
if (find_cur_path(path)) if (find_cur_path(path))
return plist :: get_path(path); plist :: select_path(path);
return "";
}
static void on_playlist_cursor_changed()
{
playlist::select(current_playlist());
} }
static bool on_playlist_clicked(GdkEventButton *button) static bool on_playlist_clicked(GdkEventButton *button)

View File

@ -13,6 +13,8 @@ namespace plist
void init(); void init();
Glib::ustring get_path(const Gtk::TreePath &); Glib::ustring get_path(const Gtk::TreePath &);
void select_path(const Gtk::TreePath &);
void del_path_ids(const Gtk::TreePath &, std::vector<unsigned int> &);
} }

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2014 (c) Anna Schumaker. * Copyright 2014 (c) Anna Schumaker.
*/ */
#include <core/playlist.h>
#include <lib/lib.h> #include <lib/lib.h>
#include <lib/plist.h> #include <lib/plist.h>
@ -30,3 +31,17 @@ Glib::ustring plist :: get_path(const Gtk::TreePath &path)
Gtk::TreeModel::Row row = *(p_list->get_iter(path)); Gtk::TreeModel::Row row = *(p_list->get_iter(path));
return row[p_cols.p_name]; return row[p_cols.p_name];
} }
void plist :: select_path(const Gtk::TreePath &path)
{
playlist :: select(get_path(path));
}
void plist :: del_path_ids(const Gtk::TreePath &path,
std::vector<unsigned int> &ids)
{
std::string name = plist :: get_path(path);
for (unsigned int i = 0; i < ids.size(); i++)
playlist :: del(tagdb :: lookup(ids[i]), name);
}