Archive / / / / / / PlaySourceTreeModel.h
2008-10-21 13:35:41 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. ] */ #ifndef PLAYSOURCETREEMODEL_H_ #define PLAYSOURCETREEMODEL_H_ #include <gtkmm.h> #include <cassert> #include "../../PlaySource.h" class PlaySourceTreeModel : public Glib::Object, public Gtk::TreeModel, public Gtk::TreeDragSource, public Gtk::TreeDragDest { public: static Glib::RefPtr<PlaySourceTreeModel> create(PlaySourceRef source); TrackRef get_track_from_path(const Gtk::TreePath& path) { assert(path.size() == 1); assert(path[0] >= 0); assert(path[0] < m_source->get_num_tracks()); return m_source->get_track(path[0]); } class PlaylistColumnRecord : public ColumnRecord { public: PlaylistColumnRecord() { add(title); add(artist); add(album); add(track_number); add(is_playing); } Gtk::TreeModelColumn<Glib::ustring> title; Gtk::TreeModelColumn<Glib::ustring> artist; Gtk::TreeModelColumn<Glib::ustring> album; Gtk::TreeModelColumn<int> track_number; Gtk::TreeModelColumn<bool> is_playing; }; PlaylistColumnRecord m_column_records; protected: PlaySourceTreeModel(PlaySourceRef source); PlaySourceRef m_source; int m_stamp; void on_source_row_deleted(int index); void on_source_row_inserted(int index); void on_source_row_changed(int index); void on_track_started(PlaySourceRef playlist, int index, bool was_paused); void on_track_stopped(PlaySourceRef playlist, int index, bool is_paused); virtual GType get_column_type_vfunc(int index) const; virtual bool get_iter_vfunc(const Gtk::TreePath& path, Gtk::TreeIter& iter) const; virtual Gtk::TreePath get_path_vfunc(const Gtk::TreeIter& iter) const; virtual void get_value_vfunc(const Gtk::TreeIter& iter, int column, Glib::ValueBase& value) const; virtual bool iter_next_vfunc(const Gtk::TreeIter& iter, Gtk::TreeIter& iter_next) const; virtual bool iter_nth_root_child_vfunc (int n, Gtk::TreeIter& iter) const; virtual bool iter_parent_vfunc(const Gtk::TreeIter& child, Gtk::TreeIter& iter) const { return false; } virtual int iter_n_children_vfunc(const Gtk::TreeIter& iter) const { return 0; } virtual bool iter_nth_child_vfunc(const Gtk::TreeIter& parent, int n, Gtk::TreeIter& iter) const { return false; } virtual bool iter_is_valid (const Gtk::TreeIter& iter) const { return iter.get_stamp() == m_stamp; } virtual bool iter_children_vfunc(const Gtk::TreeIter& parent, Gtk::TreeIter& iter) const { return false; } virtual bool iter_has_child_vfunc(const Gtk::TreeIter& iter) const { return false; } virtual int iter_n_root_children_vfunc() const { return m_source->get_num_tracks(); } virtual int get_n_columns_vfunc() const { return m_column_records.size(); } virtual Gtk::TreeModelFlags get_flags_vfunc() const { return Gtk::TreeModelFlags(0); } class DragData { public: DragData(PlaySourceRef playlist, int index) : playlist(playlist), index(index) {} PlaySourceRef playlist; int index; }; // TreeDragSource virtual bool drag_data_delete_vfunc (const Gtk::TreePath& path); virtual bool drag_data_get_vfunc (const Gtk::TreePath& path, Gtk::SelectionData& selection_data) const; virtual bool row_draggable_vfunc (const Gtk::TreePath& path) const; // TreeDragDest virtual bool drag_data_received_vfunc (const Gtk::TreePath& dest, const Gtk::SelectionData& selection_data); virtual bool row_drop_possible_vfunc (const Gtk::TreePath& dest, const Gtk::SelectionData& selection_data) const; }; #endif /* PLAYSOURCETREEMODEL_H_ */