From 520b200d5420430d0f30d0f155766364d3ad3ff2 Mon Sep 17 00:00:00 2001 From: daniel g. siegel Date: Mon, 12 Oct 2009 18:53:57 +0200 Subject: [PATCH] add random mode to muine add a random button to both album and song windows, which either queues a random album when pressing the button or just selects an album, depending on whether the /schemas/apps/muine/queue_random key is set or not. --- data/glade/AddWindow.glade | 69 ++++++++++++++++++++++++++++++++++++++++++++ data/muine.schemas.in | 11 +++++++ src/AddWindow.cs | 25 ++++++++++++++- src/HandleView.cs | 23 ++++++++++++++- 4 files changed, 125 insertions(+), 3 deletions(-) diff --git a/data/glade/AddWindow.glade b/data/glade/AddWindow.glade index 4b3ef0e..df81eb9 100644 --- a/data/glade/AddWindow.glade +++ b/data/glade/AddWindow.glade @@ -46,6 +46,75 @@ + + True + True + True + GTK_RELIEF_NORMAL + True + 3 + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Random + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + + True False diff --git a/data/muine.schemas.in b/data/muine.schemas.in index 9b0c016..c6ba0a9 100644 --- a/data/muine.schemas.in +++ b/data/muine.schemas.in @@ -189,5 +189,16 @@ Whether or not the tray icon shows song change notifications + + /schemas/apps/muine/queue_random + /apps/muine/queue_random + muine + bool + 1 + + Queue Albums when pressing the Random button + Whether or not queue the album when pressing the Random button + + diff --git a/src/AddWindow.cs b/src/AddWindow.cs index 408c2da..467c986 100644 --- a/src/AddWindow.cs +++ b/src/AddWindow.cs @@ -31,7 +31,8 @@ namespace Muine Close = Gtk.ResponseType.Close, DeleteEvent = Gtk.ResponseType.DeleteEvent, Play = 1, - Queue = 2 + Queue = 2, + QueueRandom = 3 }; #endregion Enums.ResponseType #endregion Enums @@ -52,6 +53,8 @@ namespace Muine #region Constants private const uint search_timeout = 100; + private const string GConfKeyRandom = "/apps/muine/queue_random"; + private const bool GConfDefaultRandom = true; #endregion Constants @@ -63,6 +66,8 @@ namespace Muine [Glade.Widget] private Gtk.Image play_button_image; [Glade.Widget] private Gtk.Button queue_button; [Glade.Widget] private Gtk.Image queue_button_image; + [Glade.Widget] private Gtk.Button queuerandom_button; + [Glade.Widget] private Gtk.Image queuerandom_button_image; [Glade.Widget] private Gtk.ScrolledWindow scrolledwindow; private AddWindowEntry entry = new AddWindowEntry (); @@ -103,7 +108,10 @@ namespace Muine ("stock_media-play", Gtk.IconSize.Button); this.queue_button_image.SetFromStock - ("stock_timer", Gtk.IconSize.Button); + ("gtk-add", Gtk.IconSize.Button); + + this.queuerandom_button_image.SetFromStock + ("stock_shuffle", Gtk.IconSize.Button); // Cell Renderer this.text_renderer.Ellipsize = Pango.EllipsizeMode.End; @@ -510,6 +518,19 @@ namespace Muine list.SelectNext (); break; + case (int) ResponseType.QueueRandom: + list.SelectRandom (); + + bool queue = (bool) Config.Get (GConfKeyRandom, GConfDefaultRandom); + + if (queue) + if (QueueEvent != null) + QueueEvent (list.Selected); + + entry.GrabFocus (); + + break; + default: throw new ArgumentException (); diff --git a/src/HandleView.cs b/src/HandleView.cs index ca7fdb2..60ff6ff 100644 --- a/src/HandleView.cs +++ b/src/HandleView.cs @@ -29,6 +29,7 @@ namespace Muine { // Variables private HandleModel model; + private Random random; // Constructor public HandleView () @@ -39,7 +40,8 @@ namespace Muine RulesHint = true; EnableSearch = false; HeadersVisible = false; - FixedHeightMode = true; + FixedHeightMode = true; + this.random = new Random(); } // Properties @@ -117,6 +119,25 @@ namespace Muine SetCursor (path, Columns [0], false); } + + // Methods :: Public :: SelectRandom + public void SelectRandom () + { + int selected = random.Next(Model.Length); + + TreeIter iter; + if (!Model.IterNthChild (out iter, selected)) + { + SelectFirst (); + } + else + { + SetCursor (Model.GetPath(iter), Columns [0], true); + } + ScrollToCell (Model.GetPath(iter), Columns [0], true, 0.5f, 0.5f); + } + + // Methods :: Public :: ForwardKeyPress // Hack to forward key press events to the treeview public bool ForwardKeyPress (Widget orig_widget, Gdk.EventKey e) -- 1.6.5