2008-10-22 15:13:48 UTC
previous
next
/* Echo Media Player
* Copyright (C) 2008 Shane O'Connell
*
* [ The original file includes a copyright header in this location describing
* the file as being released under the terms of the GNU General Public
* License. It has been removed in order to display the file as part of the
* archive. ]
*/
#include <boost/intrusive_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
// Forward Decelerations
class PlaySource;
typedef boost::shared_ptr<PlaySource> PlaySourceRef;
class ModPlaySource;
typedef boost::shared_ptr<ModPlaySource> ModPlaySourceRef;
class Artist;
typedef boost::intrusive_ptr<Artist> ArtistRef;
typedef boost::shared_ptr<std::vector<ArtistRef> > ArtistListRef;
class Album;
typedef boost::intrusive_ptr<Album> AlbumRef;
typedef boost::shared_ptr<std::vector<AlbumRef> > AlbumListRef;
#ifndef PLAYSOURCE_H_
#define PLAYSOURCE_H_
#include "Track.h"
#include "PlaySourceFilter.h"
#include <gtkmm.h>
#include <giomm.h>
#include <list>
class PlaySource
{
public:
virtual const Glib::ustring& get_name() const = 0;
virtual const Glib::ustring& get_icon() const = 0;
virtual int get_num_tracks() const = 0;
virtual TrackRef get_track(int index) const = 0;
virtual ~PlaySource() {}
// ------------ Signals ------------
public:
sigc::signal<void, int>& signal_track_removed()
{ return _signal_track_removed; }
sigc::signal<void, int>& signal_track_inserted()
{ return _signal_track_inserted; }
sigc::signal<void, int>& signal_track_changed()
{ return _signal_track_changed; }
private:
sigc::signal<void, int> _signal_track_removed;
sigc::signal<void, int> _signal_track_inserted;
sigc::signal<void, int> _signal_track_changed;
};
class ModPlaySource : public PlaySource
{
public:
virtual void insert_track(int index, TrackRef track) = 0;
virtual void remove_track(int index) = 0;
virtual void move_track(int old_index, int new_index) = 0;
int insert_from_uri(int index, const std::string& uri, bool playlists_ok = true, bool directories_ok = true);
int insert_from_uris(int index, const std::list<std::string>& uris);
private:
int insert_m3u_playlist(int index, Glib::RefPtr<Gio::File> file);
static bool caseless_sort(const Glib::ustring& one, const Glib::ustring& two)
{ return (one.casefold() < two.casefold()); }
};
class Artist : public PlaySource, private boost::noncopyable
{
public:
Artist(const Glib::ustring& name) :
m_name(name), m_ref_count(0)
{}
virtual const Glib::ustring& get_name() const
{ return m_name; }
virtual const Glib::ustring& get_icon() const
{ return m_icon; }
virtual int get_num_tracks() const
{ return 0; }
virtual TrackRef get_track(int index) const
{ return TrackRef(); }
private:
Glib::ustring m_name;
Glib::ustring m_icon;
sigc::signal<TrackListRef, const ArtistRef> m_callback;
int m_ref_count;
friend void intrusive_ptr_add_ref(Artist* p) { p->m_ref_count++; }
friend void intrusive_ptr_release(Artist* p) { if (!(--p->m_ref_count)) delete p; }
};
class Album : public PlaySource, private boost::noncopyable
{
public:
Album(ArtistRef artist, const Glib::ustring& name) :
m_artist(artist), m_name(name), m_ref_count(0)
{}
virtual const Glib::ustring& get_name() const
{ return m_name; }
virtual const Glib::ustring& get_icon() const
{ return m_icon; }
virtual int get_num_tracks() const
{ return 0; }
virtual TrackRef get_track(int index) const
{ return TrackRef(); }
ArtistRef get_artist() const
{ return m_artist; }
private:
ArtistRef m_artist;
Glib::ustring m_name;
Glib::ustring m_icon;
sigc::signal<TrackListRef, AlbumRef> m_callback;
int m_ref_count;
friend void intrusive_ptr_add_ref(Album* p) { p->m_ref_count++; }
friend void intrusive_ptr_release(Album* p) { if (!(--p->m_ref_count)) delete p; }
};
#endif /* PLAYSOURCE_H_ */