2006-12-12 James Livingston <doclivingston@gmail.com>
[rhythmbox.git] / shell / rb-play-order-linear.c
blob14d39f2469ca28797ca12d9b18b3405915ddbbde
1 /*
2 * arch-tag: Implementation of linear 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 "config.h"
24 #include "rb-play-order-linear.h"
26 #include "rb-debug.h"
27 #include "rb-preferences.h"
28 #include "eel-gconf-extensions.h"
30 static void rb_linear_play_order_class_init (RBLinearPlayOrderClass *klass);
32 static RhythmDBEntry *rb_linear_play_order_get_next (RBPlayOrder *method);
33 static RhythmDBEntry *rb_linear_play_order_get_previous (RBPlayOrder *method);
35 G_DEFINE_TYPE (RBLinearPlayOrder, rb_linear_play_order, RB_TYPE_PLAY_ORDER)
37 RBPlayOrder *
38 rb_linear_play_order_new (RBShellPlayer *player)
40 RBLinearPlayOrder *lorder;
42 lorder = g_object_new (RB_TYPE_LINEAR_PLAY_ORDER,
43 "player", player,
44 NULL);
46 return RB_PLAY_ORDER (lorder);
49 static void
50 rb_linear_play_order_class_init (RBLinearPlayOrderClass *klass)
52 RBPlayOrderClass *porder = RB_PLAY_ORDER_CLASS (klass);
53 porder->get_next = rb_linear_play_order_get_next;
54 porder->get_previous = rb_linear_play_order_get_previous;
57 static void
58 rb_linear_play_order_init (RBLinearPlayOrder *porder)
62 static RhythmDBEntry *
63 rb_linear_play_order_get_next (RBPlayOrder *porder)
65 RhythmDBQueryModel *model;
66 RhythmDBEntry *entry;
68 g_return_val_if_fail (porder != NULL, NULL);
69 g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER (porder), NULL);
71 model = rb_play_order_get_query_model (porder);
72 if (model == NULL)
73 return NULL;
75 entry = rb_play_order_get_playing_entry (porder);
76 if (entry != NULL) {
77 RhythmDBEntry *next;
78 next = rhythmdb_query_model_get_next_from_entry (model, entry);
79 rhythmdb_entry_unref (entry);
80 return next;
81 } else {
82 GtkTreeIter iter;
83 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
84 return NULL;
85 return rhythmdb_query_model_iter_to_entry (model, &iter);
89 static RhythmDBEntry *
90 rb_linear_play_order_get_previous (RBPlayOrder *porder)
92 RhythmDBQueryModel *model;
93 RhythmDBEntry *entry, *prev;
95 g_return_val_if_fail (porder != NULL, NULL);
96 g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER (porder), NULL);
98 model = rb_play_order_get_query_model (porder);
99 if (model == NULL)
100 return NULL;
102 entry = rb_play_order_get_playing_entry (porder);
103 if (entry == NULL)
104 return NULL;
106 prev = rhythmdb_query_model_get_previous_from_entry (model, entry);
107 rhythmdb_entry_unref (entry);
109 return prev;