gui: Custom model fixes
- Initialize stamp with a random integer (this is how a Gtk::ListStore works) - Increment the stamp in a way that it will never be 0 (AKA: invalid) - iter_n_root_children() does not take any arguments, so fix up my function. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
b2b1620116
commit
444e48f93b
|
@ -6,15 +6,24 @@
|
|||
*/
|
||||
#include <audio.h>
|
||||
#include <ocarina.h>
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
|
||||
static unsigned int global_stamp = 1;
|
||||
|
||||
PlayqueueModel::PlayqueueModel(Playqueue *q)
|
||||
: Glib::ObjectBase( typeid(PlayqueueModel) ),
|
||||
Glib::Object(),
|
||||
stamp(global_stamp++), queue(q)
|
||||
Glib::Object(), queue(q)
|
||||
{
|
||||
do {
|
||||
stamp = rand();
|
||||
} while (stamp == 0);
|
||||
}
|
||||
|
||||
void PlayqueueModel::increment_stamp()
|
||||
{
|
||||
do {
|
||||
stamp++;
|
||||
} while (stamp == 0);
|
||||
}
|
||||
|
||||
void PlayqueueModel::on_row_inserted(unsigned int row)
|
||||
|
@ -23,7 +32,7 @@ void PlayqueueModel::on_row_inserted(unsigned int row)
|
|||
Gtk::TreeIter iter;
|
||||
|
||||
path.push_back(row);
|
||||
stamp++;
|
||||
increment_stamp();
|
||||
row_inserted(path, iter);
|
||||
}
|
||||
|
||||
|
@ -32,7 +41,7 @@ void PlayqueueModel::on_row_deleted(unsigned int row)
|
|||
Gtk::TreePath path;
|
||||
|
||||
path.push_back(row);
|
||||
stamp++;
|
||||
increment_stamp();
|
||||
row_deleted(path);
|
||||
}
|
||||
|
||||
|
@ -42,7 +51,7 @@ void PlayqueueModel::on_row_changed(unsigned int row)
|
|||
Gtk::TreeIter iter;
|
||||
|
||||
path.push_back(row);
|
||||
stamp++;
|
||||
increment_stamp();
|
||||
row_changed(path, iter);
|
||||
}
|
||||
|
||||
|
@ -184,13 +193,14 @@ bool PlayqueueModel::iter_next_vfunc(const Gtk::TreeIter &iter,
|
|||
Gtk::TreeIter &iter_next) const
|
||||
{
|
||||
unsigned int index;
|
||||
iter_next = Gtk::TreeIter();
|
||||
|
||||
if (!check_iter_validity(iter))
|
||||
if (!check_iter_validity(iter)) {
|
||||
iter_next = Gtk::TreeIter();
|
||||
return false;
|
||||
}
|
||||
|
||||
index = GPOINTER_TO_UINT(iter.gobj()->user_data);
|
||||
return iter_nth_root_child_vfunc(index + 1, iter_next);
|
||||
return iter_nth_root_child_vfunc(++index, iter_next);
|
||||
}
|
||||
|
||||
bool PlayqueueModel::iter_children_vfunc(const Gtk::TreeIter &parent,
|
||||
|
@ -206,31 +216,30 @@ bool PlayqueueModel::iter_has_child_vfunc(const Gtk::TreeIter &iter) const
|
|||
|
||||
int PlayqueueModel::iter_n_children_vfunc(const Gtk::TreeIter &iter) const
|
||||
{
|
||||
return iter_n_root_children_vfunc(iter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PlayqueueModel::iter_n_root_children_vfunc(const Gtk::TreeIter &iter) const
|
||||
int PlayqueueModel::iter_n_root_children_vfunc() const
|
||||
{
|
||||
if (!check_iter_validity(iter))
|
||||
return 0;
|
||||
return queue->size();
|
||||
}
|
||||
|
||||
bool PlayqueueModel::iter_nth_child_vfunc(const Gtk::TreeIter &parent,
|
||||
int n, Gtk::TreeIter &iter) const
|
||||
{
|
||||
return iter_nth_root_child_vfunc(n, iter);
|
||||
iter = Gtk::TreeIter();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PlayqueueModel::iter_nth_root_child_vfunc(int n, Gtk::TreeIter &iter) const
|
||||
{
|
||||
iter = Gtk::TreeIter();
|
||||
if ((unsigned int)n < queue->size()) {
|
||||
iter.set_stamp(stamp);
|
||||
iter.gobj()->user_data = GUINT_TO_POINTER(n);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (n >= (int)queue->size())
|
||||
return false;
|
||||
|
||||
iter.set_stamp(stamp);
|
||||
iter.gobj()->user_data = GUINT_TO_POINTER(n);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlayqueueModel::iter_parent_vfunc(const Gtk::TreeIter &child,
|
||||
|
@ -250,13 +259,13 @@ Gtk::TreeModel::Path PlayqueueModel::get_path_vfunc(const Gtk::TreeIter &iter) c
|
|||
}
|
||||
|
||||
bool PlayqueueModel::get_iter_vfunc(const Gtk::TreePath &path,
|
||||
Gtk::TreeIter &iter_next) const
|
||||
Gtk::TreeIter &iter) const
|
||||
{
|
||||
iter_next = Gtk::TreeIter();
|
||||
|
||||
if (path.size() != 1)
|
||||
if (path.size() != 1) {
|
||||
iter = Gtk::TreeIter();
|
||||
return false;
|
||||
return iter_nth_root_child_vfunc(path[0], iter_next);
|
||||
}
|
||||
return iter_nth_root_child_vfunc(path[0], iter);
|
||||
}
|
||||
|
||||
bool PlayqueueModel::check_iter_validity(const Gtk::TreeIter &iter) const
|
||||
|
|
|
@ -13,6 +13,7 @@ Gtk::Window *ocarina_init(int *, char ***);
|
|||
/* model.cpp */
|
||||
class PlayqueueModel : public Gtk::TreeModel, public Glib::Object {
|
||||
private:
|
||||
void increment_stamp();
|
||||
void get_value_uint(struct library::Song &, int, Glib::ValueBase &) const;
|
||||
void get_value_str(struct library::Song &, int, Glib::ValueBase &) const;
|
||||
bool check_iter_validity(const Gtk::TreeIter &) const;
|
||||
|
@ -27,7 +28,7 @@ protected:
|
|||
bool iter_children_vfunc(const Gtk::TreeIter &, Gtk::TreeIter &) const;
|
||||
bool iter_has_child_vfunc(const Gtk::TreeIter &) const;
|
||||
int iter_n_children_vfunc(const Gtk::TreeIter &) const;
|
||||
int iter_n_root_children_vfunc(const Gtk::TreeIter &) const;
|
||||
int iter_n_root_children_vfunc() const;
|
||||
bool iter_nth_child_vfunc(const Gtk::TreeIter &, int, Gtk::TreeIter &) const;
|
||||
bool iter_nth_root_child_vfunc(int, Gtk::TreeIter &) const;
|
||||
bool iter_parent_vfunc(const Gtk::TreeIter &, Gtk::TreeIter &) const;
|
||||
|
|
Loading…
Reference in New Issue