Save playlist disabled status to file

This allows me to restore it when restarting ocarina.  I also need to
notify the renderer that the playlist status has changed so I can change
the button state.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-05-18 11:51:52 -04:00
parent 35d71efe58
commit 973b5d3d31
8 changed files with 37 additions and 9 deletions

View File

@ -25,7 +25,7 @@ namespace libsaria
void prev();
void init();
void new_playlist(list<Track *> &, PlaylistType, bool);
Playlist *new_playlist(list<Track *> &, PlaylistType, bool);
void delete_playlist(Playlist *);
unsigned int move_playlist(Playlist *, unsigned int);

View File

@ -23,6 +23,8 @@ namespace libsaria
bool is_static();
virtual void prepare_for_removal();
virtual void on_disable(bool);
virtual void goto_index(unsigned int);
virtual void modify_prepare();

View File

@ -43,6 +43,7 @@ namespace ocarina
void renumbered(int);
void refilter();
void prepare_for_removal();
void on_disable(bool);
void goto_index(unsigned int);

View File

@ -109,12 +109,12 @@ namespace libsaria
on_new_playlist = func;
}
void deck::new_playlist(list<Track *> &tracks, PlaylistType type, bool front)
Playlist *deck::new_playlist(list<Track *> &tracks, PlaylistType type, bool front)
{
Playlist *plist;
if (playlist_deck.size() == max_playlists)
return;
return NULL;
switch (type) {
case PLIST_SET:
@ -136,6 +136,7 @@ namespace libsaria
if (on_new_playlist)
on_new_playlist(plist);
plist->add_tracks(tracks);
return plist;
}
void deck::delete_playlist(Playlist *plist)

View File

@ -10,6 +10,8 @@
#include <sstream>
using namespace std;
#define PLAYLIST_CURRENT_VERSION 2
static string plistdir = "playlist";
static string number_to_filename(unsigned int id)
@ -29,11 +31,16 @@ void read_plist(ifstream &stream)
{
unsigned int version, type, size;
unsigned int libid, trackid;
bool disabled = false;
list<libsaria::Track *> tracks;
libsaria::Track *track;
libsaria::Playlist *plist;
stream >> version >> type >> size;
println("playlist type: %u size: %u", type, size);
if (version == 2)
stream >> disabled;
println("playlist type: %u size: %u disabled: %d", type, size, disabled);
for (unsigned int i = 0; i < size; i++) {
stream >> libid >> trackid;
@ -42,8 +49,10 @@ void read_plist(ifstream &stream)
tracks.push_back(track);
}
if (tracks.size() > 0)
libsaria::deck::new_playlist(tracks, (PlaylistType)type, false);
if (tracks.size() > 0) {
plist = libsaria::deck::new_playlist(tracks, (PlaylistType)type, false);
plist->set_disabled(disabled);
}
}
namespace libsaria
@ -52,8 +61,12 @@ namespace libsaria
void Playlist::save(ofstream &stream)
{
list<Track *>::iterator it;
stream << "1" << "\n";
stream << type << " " << plist.size() << "\n";
stream << PLAYLIST_CURRENT_VERSION << "\n";
stream << type << " ";
stream << plist.size() << " ";
stream << is_disabled() <<"\n";
for (it = plist.begin(); it != plist.end(); it++) {
stream << (*it)->get_libid() << " ";
stream << (*it)->get_id() << "\n";

View File

@ -38,6 +38,8 @@ namespace libsaria
flags |= PL_DISABLED;
else
flags &= ~PL_DISABLED;
schedule_save();
RENDER( on_disable(is_disabled()) );
}
void Playlist::prepare_for_removal()

View File

@ -42,6 +42,10 @@ namespace libsaria
{
}
void PlaylistRenderer::on_disable(bool disabled)
{
}
void PlaylistRenderer::modify_prepare()
{
}

View File

@ -222,6 +222,11 @@ namespace ocarina
void Playlist::prepare_for_removal()
{
body::remove_page(box);
};
}
void Playlist::on_disable(bool disabled)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_button), disabled);
}
}; /* Namespace: ocarina */