No issues found
1 /*
2 * Copyright (C) 2003 Jeffrey Yasskin <jyasskin@mail.utexas.edu>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * The Rhythmbox authors hereby grant permission for non-GPL compatible
10 * GStreamer plugins to be used and distributed together with GStreamer
11 * and Rhythmbox. This permission is above and beyond the permissions granted
12 * by the GPL license by which Rhythmbox is covered. If you modify this code
13 * you may extend this exception to your version of the code, but you are not
14 * obligated to do so. If you do not wish to do so, delete this exception
15 * statement from your version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25 *
26 */
27
28 #include "config.h"
29
30 #include "rb-play-order-linear.h"
31
32 #include "rb-debug.h"
33
34 static void rb_linear_play_order_class_init (RBLinearPlayOrderClass *klass);
35
36 static RhythmDBEntry *rb_linear_play_order_get_next (RBPlayOrder *method);
37 static RhythmDBEntry *rb_linear_play_order_get_previous (RBPlayOrder *method);
38
39 G_DEFINE_TYPE (RBLinearPlayOrder, rb_linear_play_order, RB_TYPE_PLAY_ORDER)
40
41 RBPlayOrder *
42 rb_linear_play_order_new (RBShellPlayer *player)
43 {
44 RBLinearPlayOrder *lorder;
45
46 lorder = g_object_new (RB_TYPE_LINEAR_PLAY_ORDER,
47 "player", player,
48 NULL);
49
50 return RB_PLAY_ORDER (lorder);
51 }
52
53 static void
54 rb_linear_play_order_class_init (RBLinearPlayOrderClass *klass)
55 {
56 RBPlayOrderClass *porder = RB_PLAY_ORDER_CLASS (klass);
57 porder->get_next = rb_linear_play_order_get_next;
58 porder->get_previous = rb_linear_play_order_get_previous;
59 }
60
61 static void
62 rb_linear_play_order_init (RBLinearPlayOrder *porder)
63 {
64 }
65
66 static RhythmDBEntry *
67 rb_linear_play_order_get_next (RBPlayOrder *porder)
68 {
69 RhythmDBQueryModel *model;
70 RhythmDBEntry *entry;
71
72 g_return_val_if_fail (porder != NULL, NULL);
73 g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER (porder), NULL);
74
75 model = rb_play_order_get_query_model (porder);
76 if (model == NULL)
77 return NULL;
78
79 entry = rb_play_order_get_playing_entry (porder);
80 if (entry != NULL) {
81 RhythmDBEntry *next;
82 next = rhythmdb_query_model_get_next_from_entry (model, entry);
83 rhythmdb_entry_unref (entry);
84 return next;
85 } else {
86 GtkTreeIter iter;
87 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
88 return NULL;
89 return rhythmdb_query_model_iter_to_entry (model, &iter);
90 }
91 }
92
93 static RhythmDBEntry *
94 rb_linear_play_order_get_previous (RBPlayOrder *porder)
95 {
96 RhythmDBQueryModel *model;
97 RhythmDBEntry *entry, *prev;
98
99 g_return_val_if_fail (porder != NULL, NULL);
100 g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER (porder), NULL);
101
102 model = rb_play_order_get_query_model (porder);
103 if (model == NULL)
104 return NULL;
105
106 entry = rb_play_order_get_playing_entry (porder);
107 if (entry == NULL)
108 return NULL;
109
110 prev = rhythmdb_query_model_get_previous_from_entry (model, entry);
111 rhythmdb_entry_unref (entry);
112
113 return prev;
114 }