libsaria: Remove library paths
- Delete the library file - Remove tracks from each playlist - Notify the renderer that tracks have been removed - Notify library drivers that the path has been removed - Remove the path from the list Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
97fcff5c18
commit
6e97f04e85
|
@ -19,6 +19,7 @@ namespace libsaria
|
|||
Playlist *get_recent_plist();
|
||||
PlaylistRenderer *get_nth_renderer(unsigned int);
|
||||
void add_to_nth_plist(unsigned int, list<Track *> &);
|
||||
void tracks_removed(list<Track> &);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace libsaria
|
|||
void list_dir(string &, list<string> &);
|
||||
void mkdir(string);
|
||||
void mkdir();
|
||||
void rm(string);
|
||||
|
||||
void save(string, void (*)(ofstream &, void *), DataState *, void *);
|
||||
void read(string, void (*)(ifstream &));
|
||||
|
|
|
@ -31,10 +31,12 @@ namespace libsaria
|
|||
|
||||
virtual void path_added(Path *) = 0;
|
||||
virtual void path_updated(Path *) = 0;
|
||||
virtual void path_removed(Path *) = 0;
|
||||
};
|
||||
|
||||
void init();
|
||||
void add_path(string);
|
||||
void delete_path(Path *);
|
||||
Playlist *get_playlist();
|
||||
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ namespace libsaria
|
|||
PlaylistType get_type();
|
||||
|
||||
virtual void add_tracks(list<Track *> &) = 0;
|
||||
void remove_tracks(list<Track> &);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace libsaria
|
|||
|
||||
virtual void goto_index(unsigned int);
|
||||
|
||||
virtual void insert_prepare();
|
||||
virtual void modify_prepare();
|
||||
virtual void modify_done();
|
||||
virtual void insert(Track *, unsigned int);
|
||||
virtual void insert_done();
|
||||
|
||||
virtual void remove_index(unsigned int);
|
||||
};
|
||||
|
|
|
@ -83,6 +83,12 @@ namespace libsaria
|
|||
make_dir(d.c_str());
|
||||
}
|
||||
|
||||
void app::rm(string file)
|
||||
{
|
||||
string f = appdir + "/" + file;
|
||||
remove(f.c_str());
|
||||
}
|
||||
|
||||
void app::init(string name)
|
||||
{
|
||||
string home = getenv("HOME");
|
||||
|
|
|
@ -104,3 +104,9 @@ unsigned int schedule_load()
|
|||
|
||||
return atoi(paths.back().c_str()) + 1;
|
||||
}
|
||||
|
||||
void remove_file(libsaria::library::Path *path)
|
||||
{
|
||||
string file = id_to_filename(path->id);
|
||||
libsaria::app::rm(libdir + "/" + file);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,13 @@ void notify_path_updated(libsaria::library::Path *path)
|
|||
(*it)->path_updated(path);
|
||||
}
|
||||
|
||||
void notify_path_deleted(libsaria::library::Path *path)
|
||||
{
|
||||
list<libsaria::library::Driver *>::iterator it;
|
||||
for (it = driver_list.begin(); it != driver_list.end(); it++)
|
||||
(*it)->path_removed(path);
|
||||
}
|
||||
|
||||
libsaria::library::Path *push_path(libsaria::library::Path &path)
|
||||
{
|
||||
libsaria::library::Path *ptr;
|
||||
|
@ -36,6 +43,18 @@ libsaria::library::Path *push_path(libsaria::library::Path &path)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void pop_path(libsaria::library::Path *path)
|
||||
{
|
||||
list<libsaria::library::Path>::iterator it;
|
||||
for (it = path_list.begin(); it != path_list.end(); it++) {
|
||||
if ((*it).id == path->id) {
|
||||
notify_path_deleted(path);
|
||||
path_list.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -53,6 +72,16 @@ namespace libsaria
|
|||
update_path(path_ptr);
|
||||
}
|
||||
|
||||
void library::delete_path(Path *path)
|
||||
{
|
||||
list<Track>::iterator it;
|
||||
list<Path>::iterator p_it;
|
||||
|
||||
remove_file(path);
|
||||
deck::tracks_removed(path->tracks);
|
||||
pop_path(path);
|
||||
}
|
||||
|
||||
Playlist *library::get_playlist()
|
||||
{
|
||||
return &lib_playlist;
|
||||
|
|
|
@ -11,5 +11,6 @@ void notify_path_updated(struct libsaria::library::Path *);
|
|||
void save_path(struct libsaria::library::Path *);
|
||||
libsaria::library::Path *push_path(libsaria::library::Path &);
|
||||
unsigned int schedule_load();
|
||||
void remove_file(libsaria::library::Path *);
|
||||
|
||||
#endif /* LIBSARIA_LIBRARY_SOURCE_H */
|
||||
|
|
|
@ -13,6 +13,32 @@ static bool compare_tracks(libsaria::Track *one, libsaria::Track *two)
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
void Playlist::remove_tracks(list<Track> &tracks)
|
||||
{
|
||||
list<Track>::iterator t_it;
|
||||
list<Track *>::iterator p_it;
|
||||
unsigned int index = 0;
|
||||
|
||||
RENDER( modify_prepare() );
|
||||
|
||||
for (p_it = plist.begin(); p_it != plist.end(); p_it++) {
|
||||
|
||||
for (t_it = tracks.begin(); t_it != tracks.end(); t_it++) {
|
||||
if ((*p_it) == &(*t_it)) {
|
||||
p_it = plist.erase(p_it);
|
||||
p_it--;
|
||||
RENDER( remove_index(index) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (t_it == tracks.end())
|
||||
index++;
|
||||
}
|
||||
|
||||
RENDER( modify_done() );
|
||||
}
|
||||
|
||||
void Playlist::add_sorted(list<Track *> &tracks)
|
||||
{
|
||||
list<Track *> copy;
|
||||
|
@ -20,7 +46,7 @@ namespace libsaria
|
|||
unsigned int ins_index;
|
||||
bool update_cur = (plist.size() == 0);
|
||||
|
||||
RENDER(insert_prepare());
|
||||
RENDER(modify_prepare());
|
||||
tracks.sort(compare_tracks);
|
||||
|
||||
copy = tracks;
|
||||
|
@ -41,14 +67,14 @@ namespace libsaria
|
|||
if (update_cur)
|
||||
cur = plist.begin();
|
||||
|
||||
RENDER(insert_done());
|
||||
RENDER(modify_done());
|
||||
}
|
||||
|
||||
void Playlist::add_to_end(list<Track *> &tracks)
|
||||
{
|
||||
list<Track *>::iterator it;
|
||||
|
||||
RENDER(insert_prepare());
|
||||
RENDER(modify_prepare());
|
||||
|
||||
for (it = tracks.begin(); it != tracks.end(); it++) {
|
||||
plist.push_back(*it);
|
||||
|
@ -59,13 +85,13 @@ namespace libsaria
|
|||
if (plist.size() == tracks.size())
|
||||
cur = plist.begin();
|
||||
|
||||
RENDER(insert_done());
|
||||
RENDER(modify_done());
|
||||
}
|
||||
|
||||
void Playlist::add_to_front(list<Track *> &tracks)
|
||||
{
|
||||
list<Track *>::iterator it;
|
||||
RENDER(insert_prepare());
|
||||
RENDER(modify_prepare());
|
||||
|
||||
tracks.reverse();
|
||||
for (it = tracks.begin(); it != tracks.end(); it++) {
|
||||
|
@ -74,7 +100,7 @@ namespace libsaria
|
|||
RENDER( insert(*it, 0) );
|
||||
}
|
||||
|
||||
RENDER(insert_done());
|
||||
RENDER(modify_done());
|
||||
}
|
||||
|
||||
}; /* namespace: libsaria */
|
||||
|
|
|
@ -143,4 +143,11 @@ namespace libsaria
|
|||
plist->add_tracks(tracks);
|
||||
}
|
||||
|
||||
void deck::tracks_removed(list<Track> &tracks)
|
||||
{
|
||||
list<Playlist *>::iterator it;
|
||||
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++)
|
||||
(*it)->remove_tracks(tracks);
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
void PlaylistRenderer::insert_prepare()
|
||||
void PlaylistRenderer::modify_prepare()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
void PlaylistRenderer::insert_done()
|
||||
void PlaylistRenderer::modify_done()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue