Commit 064c380c authored by Jorn Baayen's avatar Jorn Baayen
Browse files

implement shuffle/repeat

parent b6554271
2002-06-10 Jorn Baayen <jorn@nl.linux.org>
* README: update cvs module name
* data/ui/rhythmbox-ui.xml.in:
* lib/rb-bonobo-helpers.c: (rb_bonobo_set_active),
(rb_bonobo_get_active):
* lib/rb-bonobo-helpers.h:
* lib/view/rb-view-player.c:
* lib/view/rb-view-player.h:
* lib/widgets/rb-node-view.c: (rb_node_view_get_first_node),
(rb_node_view_get_random_node):
* lib/widgets/rb-node-view.h:
* shell/main.c: (main):
* shell/rb-shell.c: (rb_shell_construct),
(rb_shell_set_window_title), (rb_shell_cmd_shuffle),
(rb_shell_cmd_repeat):
* tests/testview.c: (rb_test_view_player_init),
(rb_test_view_set_shuffle), (rb_test_view_set_repeat),
(rb_test_view_next), (rb_test_view_previous):
* tests/testview2.c: (rb_test_view_player_init):
implement shuffle/repeat
2002-06-10 Jorn Baayen <jorn@nl.linux.org>
* lib/widgets/rb-node-view.c: (rb_node_view_construct),
......
......@@ -15,7 +15,7 @@ Information about mailing lists can be found at:
Our IRC channel is #rhythmbox on GIMPnet (irc.gimp.org).
Rhythmbox CVS is hosted at gnome.org, rhythmbox-new module.
Rhythmbox CVS is hosted at gnome.org, rhythmbox module.
Installation
============
......
......@@ -31,6 +31,20 @@
pixname="rhythmbox-next"
_tip="Go to the next track"
priority="1"/>
<cmd name="Shuffle"
pixtype="stock"
pixname="rhythmbox-shuffle"
_tip="Random playing order"
priority="1"
type="toggle"/>
<cmd name="Repeat"
pixtype="stock"
pixname="rhythmbox-repeat"
_tip="Toggle repeat mode"
priority="1"
type="toggle"/>
</commands>
......@@ -102,8 +116,8 @@
<separator/>
<menuitem name="Shuffle" _label="_Shuffle" verb="Shuffle" type="toggle"/>
<menuitem name="Repeat" _label="_Repeat" verb="Repeat" type="toggle"/>
<menuitem name="Shuffle" _label="_Shuffle" verb="Shuffle"/>
<menuitem name="Repeat" _label="_Repeat" verb="Repeat"/>
</submenu>
......@@ -143,11 +157,7 @@
<separator/>
<toolitem name="Shuffle"
_label="Shuffle"
priority="1"
_tip="Shuffle playing order"
pixtype="stock" pixname="rhythmbox-shuffle"
verb="Shuffle"
type="toggle"/>
verb="Shuffle"/>
<separator/>
<toolitem name="Visuals"
_label="Visuals"
......
......@@ -18,6 +18,8 @@
* $Id$
*/
#include <stdlib.h>
#include "rb-bonobo-helpers.h"
void
......@@ -69,3 +71,18 @@ rb_bonobo_set_active (BonoboUIComponent *component,
bonobo_ui_component_set_prop (component, path, "state",
active ? "1" : "0", NULL);
}
gboolean
rb_bonobo_get_active (BonoboUIComponent *component,
const char *path)
{
gboolean ret = FALSE;
char *prop;
prop = bonobo_ui_component_get_prop (component, path, "state", NULL);
if (prop != NULL)
ret = atoi (prop);
g_free (prop);
return ret;
}
......@@ -25,24 +25,26 @@
G_BEGIN_DECLS
void rb_bonobo_set_label (BonoboUIComponent *component,
const char *path,
const char *label);
void rb_bonobo_set_tip (BonoboUIComponent *component,
const char *path,
const char *tip);
void rb_bonobo_set_icon (BonoboUIComponent *component,
const char *path,
const char *stock_icon);
void rb_bonobo_set_verb (BonoboUIComponent *component,
const char *path,
const char *verb);
void rb_bonobo_set_sensitive (BonoboUIComponent *component,
const char *path,
gboolean sensitive);
void rb_bonobo_set_active (BonoboUIComponent *component,
const char *path,
gboolean active);
void rb_bonobo_set_label (BonoboUIComponent *component,
const char *path,
const char *label);
void rb_bonobo_set_tip (BonoboUIComponent *component,
const char *path,
const char *tip);
void rb_bonobo_set_icon (BonoboUIComponent *component,
const char *path,
const char *stock_icon);
void rb_bonobo_set_verb (BonoboUIComponent *component,
const char *path,
const char *verb);
void rb_bonobo_set_sensitive (BonoboUIComponent *component,
const char *path,
gboolean sensitive);
void rb_bonobo_set_active (BonoboUIComponent *component,
const char *path,
gboolean active);
gboolean rb_bonobo_get_active (BonoboUIComponent *component,
const char *path);
G_END_DECLS
......
......@@ -90,22 +90,6 @@ rb_view_player_base_init (gpointer g_iface)
initialized = TRUE;
}
RBViewPlayerResult
rb_view_player_get_shuffle (RBViewPlayer *player)
{
RBViewPlayerIface *iface = RB_VIEW_PLAYER_GET_IFACE (player);
return iface->impl_get_shuffle (player);
}
RBViewPlayerResult
rb_view_player_get_repeat (RBViewPlayer *player)
{
RBViewPlayerIface *iface = RB_VIEW_PLAYER_GET_IFACE (player);
return iface->impl_get_repeat (player);
}
void
rb_view_player_set_shuffle (RBViewPlayer *player,
gboolean shuffle)
......
......@@ -49,9 +49,6 @@ typedef struct
void (*start_playing) (RBViewPlayer *player);
/* methods */
RBViewPlayerResult (*impl_get_shuffle) (RBViewPlayer *player);
RBViewPlayerResult (*impl_get_repeat) (RBViewPlayer *player);
void (*impl_set_shuffle) (RBViewPlayer *player,
gboolean shuffle);
void (*impl_set_repeat) (RBViewPlayer *player,
......@@ -79,9 +76,6 @@ typedef struct
GType rb_view_player_get_type (void);
RBViewPlayerResult rb_view_player_get_shuffle (RBViewPlayer *player);
RBViewPlayerResult rb_view_player_get_repeat (RBViewPlayer *player);
void rb_view_player_set_shuffle (RBViewPlayer *player,
gboolean shuffle);
void rb_view_player_set_repeat (RBViewPlayer *player,
......
......@@ -25,6 +25,7 @@
#include <libgnome/gnome-i18n.h>
#include <string.h>
#include <libxml/tree.h>
#include <stdlib.h>
#include "gtktreemodelfilter.h"
#include "rb-tree-model-node.h"
......@@ -635,6 +636,33 @@ rb_node_view_get_first_node (RBNodeView *view)
return rb_tree_model_node_node_from_iter (RB_TREE_MODEL_NODE (view->priv->nodemodel), &iter);
}
RBNode *
rb_node_view_get_random_node (RBNodeView *view)
{
GtkTreePath *path;
GtkTreeIter iter, iter2;
char *path_str;
int index;
index = random () % gtk_tree_model_iter_n_children (GTK_TREE_MODEL (view->priv->sortmodel), NULL);
path_str = g_strdup_printf ("%d", index);
path = gtk_tree_path_new_from_string (path_str);
g_free (path_str);
gtk_tree_model_get_iter (GTK_TREE_MODEL (view->priv->sortmodel),
&iter, path);
gtk_tree_path_free (path);
gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (view->priv->sortmodel),
&iter2, &iter);
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (view->priv->filtermodel),
&iter, &iter2);
return rb_tree_model_node_node_from_iter (RB_TREE_MODEL_NODE (view->priv->nodemodel), &iter);
}
static void
get_selection (GtkTreeModel *model,
GtkTreePath *path,
......
......@@ -70,6 +70,7 @@ RBNode *rb_node_view_get_playing_node (RBNodeView *view);
RBNode *rb_node_view_get_next_node (RBNodeView *view);
RBNode *rb_node_view_get_previous_node (RBNodeView *view);
RBNode *rb_node_view_get_first_node (RBNodeView *view);
RBNode *rb_node_view_get_random_node (RBNodeView *view);
GList *rb_node_view_get_selection (RBNodeView *view);
......
......@@ -24,6 +24,8 @@
#include <bonobo/bonobo-main.h>
#include <glade/glade-init.h>
#include <monkey-media.h>
#include <stdlib.h>
#include <time.h>
#include "config.h"
#include "rb-shell.h"
......@@ -64,6 +66,8 @@ main (int argc, char **argv)
CORBA_exception_init (&ev);
srandom (time (NULL));
rb_debug_init (debug);
rb_file_helpers_init ();
......
......@@ -43,6 +43,7 @@
#include "rb-shell-player.h"
#include "rb-shell-status.h"
#include "rb-shell-clipboard.h"
#include "rb-bonobo-helpers.h"
/* FIXME */
#include "testview.h"
#include "testview2.h"
......@@ -70,6 +71,15 @@ static void rb_shell_set_window_title (RBShell *shell,
static void rb_shell_player_window_title_changed_cb (RBShellPlayer *player,
const char *window_title,
RBShell *shell);
static void rb_shell_cmd_shuffle (BonoboUIComponent *component,
RBShell *shell,
const char *verbname);
static void rb_shell_cmd_repeat (BonoboUIComponent *component,
RBShell *shell,
const char *verbname);
#define CMD_PATH_SHUFFLE "/commands/Shuffle"
#define CMD_PATH_REPEAT "/commands/Repeat"
struct RBShellPrivate
{
......@@ -89,6 +99,13 @@ struct RBShellPrivate
RBShellClipboard *clipboard_shell;
};
static BonoboUIVerb rb_shell_verbs[] =
{
BONOBO_UI_VERB ("Shuffle", (BonoboUIVerbFn) rb_shell_cmd_shuffle),
BONOBO_UI_VERB ("Repeat", (BonoboUIVerbFn) rb_shell_cmd_repeat),
BONOBO_UI_VERB_END
};
static GObjectClass *parent_class;
GType
......@@ -284,6 +301,10 @@ rb_shell_construct (RBShell *shell)
"rhythmbox-ui.xml",
"rhythmbox", NULL);
bonobo_ui_component_add_verb_list_with_data (shell->priv->ui_component,
rb_shell_verbs,
shell);
/* initialize shell services */
shell->priv->player_shell = rb_shell_player_new (shell->priv->ui_component);
g_signal_connect (G_OBJECT (shell->priv->player_shell),
......@@ -489,3 +510,35 @@ rb_shell_set_window_title (RBShell *shell,
window_title);
}
}
static void
rb_shell_cmd_shuffle (BonoboUIComponent *component,
RBShell *shell,
const char *verbname)
{
gboolean shuffle = rb_bonobo_get_active (component, CMD_PATH_SHUFFLE);
GList *l;
for (l = shell->priv->views; l != NULL; l = g_list_next (l))
{
RBViewPlayer *player = RB_VIEW_PLAYER (l->data);
rb_view_player_set_shuffle (player, shuffle);
}
}
static void
rb_shell_cmd_repeat (BonoboUIComponent *component,
RBShell *shell,
const char *verbname)
{
gboolean repeat = rb_bonobo_get_active (component, CMD_PATH_REPEAT);
GList *l;
for (l = shell->priv->views; l != NULL; l = g_list_next (l))
{
RBViewPlayer *player = RB_VIEW_PLAYER (l->data);
rb_view_player_set_repeat (player, repeat);
}
}
......@@ -54,8 +54,6 @@ static void artist_node_selected_cb (RBNodeView *view,
RBNode *node,
RBTestView *testview);
static void rb_test_view_player_init (RBViewPlayerIface *iface);
static RBViewPlayerResult rb_test_view_get_shuffle (RBViewPlayer *player);
static RBViewPlayerResult rb_test_view_get_repeat (RBViewPlayer *player);
static void rb_test_view_set_shuffle (RBViewPlayer *player,
gboolean shuffle);
static void rb_test_view_set_repeat (RBViewPlayer *player,
......@@ -95,6 +93,9 @@ struct RBTestViewPrivate
MonkeyMediaAudioStream *playing_stream;
char *title;
gboolean shuffle;
gboolean repeat;
};
enum
......@@ -351,8 +352,6 @@ album_node_selected_cb (RBNodeView *view,
static void
rb_test_view_player_init (RBViewPlayerIface *iface)
{
iface->impl_get_shuffle = rb_test_view_get_shuffle;
iface->impl_get_repeat = rb_test_view_get_repeat;
iface->impl_set_shuffle = rb_test_view_set_shuffle;
iface->impl_set_repeat = rb_test_view_set_repeat;
iface->impl_have_next = rb_test_view_have_next;
......@@ -369,28 +368,22 @@ rb_test_view_player_init (RBViewPlayerIface *iface)
iface->impl_stop_playing = rb_test_view_stop_playing;
}
static RBViewPlayerResult
rb_test_view_get_shuffle (RBViewPlayer *player)
{
return RB_VIEW_PLAYER_NOT_SUPPORTED;
}
static RBViewPlayerResult
rb_test_view_get_repeat (RBViewPlayer *player)
{
return RB_VIEW_PLAYER_NOT_SUPPORTED;
}
static void
rb_test_view_set_shuffle (RBViewPlayer *player,
gboolean shuffle)
{
RBTestView *view = RB_TEST_VIEW (player);
view->priv->shuffle = shuffle;
}
static void
rb_test_view_set_repeat (RBViewPlayer *player,
gboolean repeat)
{
RBTestView *view = RB_TEST_VIEW (player);
view->priv->repeat = repeat;
}
static RBViewPlayerResult
......@@ -421,7 +414,16 @@ rb_test_view_next (RBViewPlayer *player)
RBTestView *view = RB_TEST_VIEW (player);
RBNode *node;
node = rb_node_view_get_next_node (view->priv->songs);
if (view->priv->shuffle == FALSE)
{
node = rb_node_view_get_next_node (view->priv->songs);
if (node == NULL && view->priv->repeat == TRUE)
{
node = rb_node_view_get_first_node (view->priv->songs);
}
}
else
node = rb_node_view_get_random_node (view->priv->songs);
rb_test_view_set_playing_node (view, node);
}
......@@ -432,7 +434,10 @@ rb_test_view_previous (RBViewPlayer *player)
RBTestView *view = RB_TEST_VIEW (player);
RBNode *node;
node = rb_node_view_get_previous_node (view->priv->songs);
if (view->priv->shuffle == FALSE)
node = rb_node_view_get_previous_node (view->priv->songs);
else
node = rb_node_view_get_random_node (view->priv->songs);
rb_test_view_set_playing_node (view, node);
}
......
......@@ -30,8 +30,6 @@ static void rb_test_view2_class_init (RBTestView2Class *klass);
static void rb_test_view2_init (RBTestView2 *view);
static void rb_test_view2_finalize (GObject *object);
static void rb_test_view_player_init (RBViewPlayerIface *iface);
static RBViewPlayerResult rb_test_view_get_shuffle (RBViewPlayer *player);
static RBViewPlayerResult rb_test_view_get_repeat (RBViewPlayer *player);
static void rb_test_view_set_shuffle (RBViewPlayer *player,
gboolean shuffle);
static void rb_test_view_set_repeat (RBViewPlayer *player,
......@@ -187,8 +185,6 @@ rb_test_view2_new (BonoboUIComponent *component)
static void
rb_test_view_player_init (RBViewPlayerIface *iface)
{
iface->impl_get_shuffle = rb_test_view_get_shuffle;
iface->impl_get_repeat = rb_test_view_get_repeat;
iface->impl_set_shuffle = rb_test_view_set_shuffle;
iface->impl_set_repeat = rb_test_view_set_repeat;
iface->impl_have_next = rb_test_view_have_next;
......@@ -205,18 +201,6 @@ rb_test_view_player_init (RBViewPlayerIface *iface)
iface->impl_stop_playing = rb_test_view_stop_playing;
}
static RBViewPlayerResult
rb_test_view_get_shuffle (RBViewPlayer *player)
{
return RB_VIEW_PLAYER_NOT_SUPPORTED;
}
static RBViewPlayerResult
rb_test_view_get_repeat (RBViewPlayer *player)
{
return RB_VIEW_PLAYER_NOT_SUPPORTED;
}
static void
rb_test_view_set_shuffle (RBViewPlayer *player,
gboolean shuffle)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment