ocarina: Fill a songlist by inheriting from a SourceModel

The SourceModel declares an insert() function that is called when
filling the list.  I have defined this function in a way that the list
will be filled in through repeated calls to insert()
This commit is contained in:
Bryan Schumaker 2011-10-29 15:19:56 -04:00
parent 136f12bc7c
commit c727aaa526
3 changed files with 4 additions and 11 deletions

View File

@ -3,6 +3,7 @@
#include <ocarina/gtk.h>
#include <libsaria/track.h>
#include <libsaria/model.h>
#include <list>
#include <string>
@ -11,12 +12,11 @@ using namespace std;
/* Make this a class to inherit from? */
struct SongListFuncs
{
void (*for_each)(void (*)(Track &));
void (*insert_track)(Track &);
void (*for_each)(libsaria::SourceModel *);
unsigned int (*size)();
};
class SongList
class SongList : public libsaria::SourceModel
{
private:
int ins_next;

View File

@ -13,14 +13,12 @@ using namespace std;
static SongList library_list;
void ocarina_library_refresh();
static void library_insert(Track &);
struct SongListFuncs library_funcs;
void library_init()
{
library_funcs.for_each = libsaria::library::for_each;
library_funcs.insert_track = library_insert;
library_funcs.size = libsaria::library::size;
library_list.init("Library", &library_funcs);
@ -28,11 +26,6 @@ void library_init()
ocarina_library_refresh();
}
static void library_insert(Track &track)
{
library_list.insert(track);
}
void ocarina_library_refresh()
{
library_list.clear();

View File

@ -38,7 +38,7 @@ void SongList::fill()
{
freeze();
ins_next = 0;
list_funcs->for_each(list_funcs->insert_track);
list_funcs->for_each(this);
thaw();
set_label_text();
}