2 * arch-tag: Implementation of linear, looping navigation method
4 * Copyright (C) 2003 Jeffrey Yasskin <jyasskin@mail.utexas.edu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "rb-play-order-linear-loop.h"
26 #include "eel-gconf-extensions.h"
28 static void rb_linear_play_order_loop_class_init (RBLinearPlayOrderLoopClass
*klass
);
30 static RhythmDBEntry
* rb_linear_play_order_loop_get_next (RBPlayOrder
* method
);
31 static RhythmDBEntry
* rb_linear_play_order_loop_get_previous (RBPlayOrder
* method
);
33 G_DEFINE_TYPE (RBLinearPlayOrderLoop
, rb_linear_play_order_loop
, RB_TYPE_PLAY_ORDER
)
36 rb_linear_play_order_loop_new (RBShellPlayer
*player
)
38 RBLinearPlayOrderLoop
*lorder
;
40 lorder
= g_object_new (RB_TYPE_LINEAR_PLAY_ORDER_LOOP
,
44 return RB_PLAY_ORDER (lorder
);
48 rb_linear_play_order_loop_class_init (RBLinearPlayOrderLoopClass
*klass
)
50 RBPlayOrderClass
*porder
= RB_PLAY_ORDER_CLASS (klass
);
51 porder
->has_next
= rb_play_order_model_not_empty
;
52 porder
->has_previous
= rb_play_order_model_not_empty
;
53 porder
->get_next
= rb_linear_play_order_loop_get_next
;
54 porder
->get_previous
= rb_linear_play_order_loop_get_previous
;
58 rb_linear_play_order_loop_init (RBLinearPlayOrderLoop
*porder
)
62 static RhythmDBEntry
*
63 rb_linear_play_order_loop_get_next (RBPlayOrder
*porder
)
65 RhythmDBQueryModel
*model
;
68 g_return_val_if_fail (porder
!= NULL
, NULL
);
69 g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER_LOOP (porder
), NULL
);
71 model
= rb_play_order_get_query_model (porder
);
75 g_object_get (porder
, "playing-entry", &entry
, NULL
);
80 next
= rhythmdb_query_model_get_next_from_entry (model
, entry
);
81 rhythmdb_entry_unref (entry
);
86 /* loop back to (or start from) the first entry */
88 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model
), &iter
))
90 return rhythmdb_query_model_iter_to_entry (model
, &iter
);
96 static RhythmDBEntry
*
97 rb_linear_play_order_loop_get_previous (RBPlayOrder
*porder
)
99 RhythmDBQueryModel
*model
;
100 RhythmDBEntry
*entry
;
101 RhythmDBEntry
*prev
= NULL
;
103 g_return_val_if_fail (porder
!= NULL
, NULL
);
104 g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER_LOOP (porder
), NULL
);
106 model
= rb_play_order_get_query_model (porder
);
110 g_object_get (porder
, "playing-entry", &entry
, NULL
);
112 prev
= rhythmdb_query_model_get_previous_from_entry (model
, entry
);
113 rhythmdb_entry_unref (entry
);
117 /* loop to last entry */
119 gint num_entries
= gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model
), NULL
);
120 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (model
), &iter
, NULL
, num_entries
-1))
122 prev
= rhythmdb_query_model_iter_to_entry (model
, &iter
);