[Banshee-List] Browser for 0_10_4
- From: Ulas Sahin <ulas arttek com tr>
- To: banshee-list gnome org
- Cc: mail slomosnail de
- Subject: [Banshee-List] Browser for 0_10_4
- Date: Sat, 28 Jan 2006 19:28:42 +0200
Hi Banshee Lovers.
Attached is the browser patch for 0_10_4.
Synced for BANSHEE_0_10_4
Addresses performance issues during imports and removal of songs.
Works with any kind of source (including DAPs, playlists..)(well, should
work).
Have fun.
Index: src/PlayerInterface.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/PlayerInterface.cs,v
retrieving revision 1.134
diff -u -r1.134 PlayerInterface.cs
--- src/PlayerInterface.cs 17 Jan 2006 16:51:14 -0000 1.134
+++ src/PlayerInterface.cs 28 Jan 2006 16:52:33 -0000
@@ -59,6 +59,8 @@
[Widget] private Gtk.Label LabelInfo;
[Widget] private HPaned SourceSplitter;
[Widget] private Button HeaderCycleButton;
+ [Widget] private Expander CustomExpander;
+ [Widget] private Gtk.VBox DisclosureBox;
private PlaylistModel playlistModel;
@@ -75,6 +77,7 @@
private Tooltips toolTips;
private Hashtable playlistMenuMap;
private Viewport sourceViewLoadingVP;
+ private BrowserBox browser;
private MultiStateToggleButton repeat_toggle_button;
private MultiStateToggleButton shuffle_toggle_button;
@@ -165,6 +168,7 @@
DapCore.DapAdded += OnDapCoreDeviceAdded;
LogCore.Instance.Updated += OnLogCoreUpdated;
ImportManager.Instance.ImportRequested += OnImportManagerImportRequested;
+ ImportManager.Instance.ImportFinished += OnImportManagerImportFinished;
InitialLoadTimeout();
WindowPlayer.Show();
@@ -452,6 +456,14 @@
gxml["SearchLabel"].Sensitive = false;
searchEntry.Sensitive = false;
+
+ // Custom Expander and browser related stuff.
+ CustomExpander = ((Expander)gxml["CustomExpander"]);
+ DisclosureBox = ((VBox)gxml["DisclosureBox"]);
+ browser = new BrowserBox();
+ DisclosureBox.Add(browser);
+ CustomExpander.Activated += OnExpandAreaClicked;
+ browser.BrowserSearchActivated += OnBrowserSearchActivated;
// Repeat/Shuffle buttons
@@ -823,6 +835,17 @@
handled = true;
}
break;
+ case Gdk.Key.F5:
+ if((args.Event.State & Gdk.ModifierType.ControlMask) != 0) {
+ if (CustomExpander.Expanded) {
+ CustomExpander.Expanded = false;
+ } else {
+ CustomExpander.Expanded = true;
+ }
+ OnExpandAreaClicked(this, new EventArgs());
+ handled = true;
+ }
+ break;
}
args.RetVal = handled;
@@ -1103,7 +1126,7 @@
if(playlistModel.Count() == 0 && args.Source.Count > 0) {
playlistModel.ReloadSource();
}
- }
+ }
}
private void OnSourceTrackAdded(object o, TrackEventArgs args)
@@ -1255,6 +1278,8 @@
}
OnPlaylistViewSelectionChanged(playlistView.Selection, new EventArgs());
+
+ browser.BrowserReset();
}
private void UpdateDapDiskUsageBar(DapSource dapSource)
@@ -1566,20 +1591,34 @@
playlistModel.Clear();
if(!searchEntry.IsQueryAvailable) {
- playlistModel.ReloadSource();
+ if (browser.BrowserHasFilter()) {
+ playlistModel.SearchSource(null,null);
+ } else {
+ playlistModel.ReloadSource();
+ }
return;
}
- foreach(TrackInfo track in SourceManager.ActiveSource.Tracks) {
- try {
- if(DoesTrackMatchSearch(track)) {
- playlistModel.AddTrack(track);
- }
- } catch(Exception) {
- continue;
- }
- }
- }
+ ArrayList filteredlist = new ArrayList();
+ filteredlist.Clear();
+ if (browser.BrowserHasFilter()) {
+ filteredlist.AddRange(playlistModel.GetBrowsedTracks());
+ } else {
+ foreach(TrackInfo track in SourceManager.ActiveSource.Tracks) {
+ filteredlist.Add(track);
+ }
+ }
+
+ foreach(TrackInfo ti in filteredlist) {
+ try {
+ if(DoesTrackMatchSearch(ti)) {
+ playlistModel.AddTrack(ti);
+ }
+ } catch(Exception) {
+ continue;
+ }
+ }
+ }
// PlaylistView DnD
@@ -2003,6 +2042,14 @@
}
}
+ private void OnImportManagerImportFinished(object o, ImportEventArgs args)
+ {
+ ThreadAssist.ProxyToMain(delegate {
+ browser.BrowserUpdate();
+ browser.BrowserFilter();
+ });
+ }
+
private void DeleteSong(TrackInfo ti)
{
try {
@@ -2091,6 +2138,16 @@
SourceManager.ActiveSource.Commit();
sourceView.QueueDraw();
playlistView.QueueDraw();
+ browser.BrowserUpdate();
+ }
+
+ private void OnBrowserSearchActivated(object o, BrowserSearchEventArgs args)
+ {
+ browser.BrowserSetFilter(true);
+ playlistModel.SearchSource(args.artist, args.album);
+ if(searchEntry.IsQueryAvailable) {
+ OnSimpleSearch(o, new EventArgs());
+ }
}
private void OnLibraryTrackRemoveFinished(object o, EventArgs args)
@@ -2451,6 +2508,17 @@
log_viewer.Show();
}
+
+ // --- Expander ---
+
+ private void OnExpandAreaClicked (object sender, EventArgs args)
+ {
+ if (CustomExpander.Expanded) {
+ DisclosureBox.Visible = true;
+ } else {
+ DisclosureBox.Visible = false;
+ }
+ }
// --- Help Menu ---
Index: src/PlaylistModel.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/PlaylistModel.cs,v
retrieving revision 1.32
diff -u -r1.32 PlaylistModel.cs
--- src/PlaylistModel.cs 9 Jan 2006 06:51:48 -0000 1.32
+++ src/PlaylistModel.cs 28 Jan 2006 16:52:37 -0000
@@ -50,6 +50,7 @@
private TimeSpan totalDuration = new TimeSpan(0);
private ArrayList trackInfoQueue;
+ private ArrayList browsedTracks;
private bool trackInfoQueueLocked = false;
private TreeIter playingIter;
@@ -68,6 +69,7 @@
public PlaylistModel() : base(typeof(TrackInfo))
{
trackInfoQueue = new ArrayList();
+ browsedTracks = new ArrayList();
GLib.Timeout.Add(300, new GLib.TimeoutHandler(OnIdle));
SourceManager.ActiveSourceChanged += delegate(SourceEventArgs args) {
ReloadSource();
@@ -158,6 +160,67 @@
SyncPlayingIter();
}
+
+ public void SearchSource(BrowserEventInfo beiArtist, BrowserEventInfo beiAlbum)
+ {
+ ClearModel();
+ if (beiArtist != null && beiAlbum!= null) {
+ browsedTracks.Clear();
+ IEnumerable collection = SourceManager.ActiveSource.Tracks;
+ foreach(TrackInfo ti in collection) {
+ try {
+ if(DoesTrackMatchSearch(ti, beiArtist, beiAlbum)) {
+ AddTrack(ti);
+ browsedTracks.Add(ti);
+ }
+ } catch(Exception) {
+ continue;
+ }
+ }
+
+ } else {
+ foreach(TrackInfo ti in browsedTracks) {
+ try {
+ AddTrack(ti);
+ } catch(Exception) {
+ continue;
+ }
+ }
+ }
+ }
+
+ public ICollection GetBrowsedTracks()
+ {
+ return browsedTracks;
+ }
+
+ private bool DoesTrackMatchSearch(TrackInfo ti, BrowserEventInfo Artist, BrowserEventInfo Album)
+ {
+ string artist = Artist.StrData.ToLower();
+ string album = Album.StrData.ToLower();
+ string ti_artist = ti.Artist.ToString().ToLower();
+ string ti_album = ti.Album.ToString().ToLower();
+ int artist_index = Artist.IntIndex;
+ int album_index = Album.IntIndex;
+
+ if (artist_index == 0 && album_index == 0) {
+ return true;
+ } else if (artist_index == 0) {
+ if (album.Equals(ti_album)) {
+ return true;
+ }
+ } else if (album_index == 0) {
+ if (artist.Equals(ti_artist)) {
+ return true;
+ }
+ } else if (album_index != 0 && artist_index != 0) {
+ if (artist.Equals(ti_artist) && album.Equals(ti_album)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
// --- Helper Methods ---
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/banshee/src/Makefile.am,v
retrieving revision 1.86
diff -u -r1.86 Makefile.am
--- src/Makefile.am 14 Jan 2006 09:11:03 -0000 1.86
+++ src/Makefile.am 28 Jan 2006 16:52:37 -0000
@@ -58,6 +58,7 @@
ExceptionDialog.cs \
VersionInformationDialog.cs \
LogCoreViewer.cs \
+ SourceBrowser.cs \
ToggleStates.cs
banshee_resources = \
Index: data/banshee.glade
===================================================================
RCS file: /cvs/gnome/banshee/data/banshee.glade,v
retrieving revision 1.6
diff -u -r1.6 banshee.glade
--- data/banshee.glade 14 Jan 2006 09:11:02 -0000 1.6
+++ data/banshee.glade 28 Jan 2006 16:52:45 -0000
@@ -249,22 +249,38 @@
<property name="spacing">5</property>
<child>
- <widget class="GtkLabel" id="ViewNameLabel">
+ <widget class="GtkExpander" id="CustomExpander">
<property name="visible">True</property>
- <property name="label" translatable="yes"><b>Loading...</b></property>
- <property name="use_underline">False</property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">4</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
+ <property name="can_focus">True</property>
+ <property name="expanded">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <placeholder/>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="ViewNameLabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Loading...</b></property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">4</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="type">label_item</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="padding">0</property>
@@ -373,30 +389,57 @@
</child>
<child>
- <widget class="GtkAlignment" id="LibraryAlignment">
+ <widget class="GtkVPaned" id="VPane">
<property name="visible">True</property>
- <property name="xalign">0.5</property>
- <property name="yalign">0.5</property>
- <property name="xscale">1</property>
- <property name="yscale">1</property>
- <property name="top_padding">0</property>
- <property name="bottom_padding">0</property>
- <property name="left_padding">0</property>
- <property name="right_padding">0</property>
+ <property name="can_focus">True</property>
+ <property name="position">200</property>
<child>
- <widget class="GtkScrolledWindow" id="LibraryContainer">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
- <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
- <property name="shadow_type">GTK_SHADOW_IN</property>
- <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+ <widget class="GtkVBox" id="DisclosureBox">
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
<child>
<placeholder/>
</child>
</widget>
+ <packing>
+ <property name="shrink">False</property>
+ <property name="resize">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkAlignment" id="LibraryAlignment">
+ <property name="visible">True</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xscale">1</property>
+ <property name="yscale">1</property>
+ <property name="top_padding">0</property>
+ <property name="bottom_padding">0</property>
+ <property name="left_padding">0</property>
+ <property name="right_padding">0</property>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="LibraryContainer">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="shrink">True</property>
+ <property name="resize">True</property>
+ </packing>
</child>
</widget>
<packing>
Index: src/Banshee.Base/ImportManager.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Base/ImportManager.cs,v
retrieving revision 1.4
diff -u -r1.4 ImportManager.cs
--- src/Banshee.Base/ImportManager.cs 21 Dec 2005 06:34:05 -0000 1.4
+++ src/Banshee.Base/ImportManager.cs 28 Jan 2006 16:52:45 -0000
@@ -71,6 +71,7 @@
private bool processing_queue = false;
public event ImportEventHandler ImportRequested;
+ public event ImportEventHandler ImportFinished;
private ImportManager()
{
@@ -231,6 +232,11 @@
}
}
+ //Fire ImportFinished Event for browser to update
+ ImportEventHandler finishhandler = ImportFinished;
+ ImportEventArgs finishargs = new ImportEventArgs();
+ finishhandler(this, finishargs);
+
path_queue.Clear();
processing_queue = false;
--- src/SourceBrowser.cs 2006-01-07 19:25:49.000000000 +0200
+++ src/SourceBrowser.cs 2006-01-07 19:20:22.000000000 +0200
@@ -0,0 +1,450 @@
+/* -*- Mode: csharp; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: t -*- */
+/***************************************************************************
+ * SourceBrowser.cs
+ *
+ *
+ * Written by Aydemir Ulas Sahin (ulas arttek com tr)
+ ****************************************************************************/
+
+/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using GLib;
+using Gtk;
+using Mono.Unix;
+
+using Banshee.Base;
+using Banshee.Sources;
+
+namespace Banshee
+{
+ public delegate void BrowserSearchEventHandler(object o, BrowserSearchEventArgs args);
+
+ public class BrowserEventInfo
+ {
+ private string strdata;
+ private int index;
+
+ public BrowserEventInfo(string str_data, int int_index)
+ {
+ this.StrData = str_data;
+ this.IntIndex = int_index;
+ }
+
+
+ public string StrData
+ {
+ get {
+ return this.strdata;
+ }
+ set {
+ this.strdata = value;
+ }
+ }
+
+ public int IntIndex
+ {
+ get {
+ return this.index;
+ }
+ set {
+ this.index = value;
+ }
+ }
+ }
+
+
+ public class BrowserSearchEventArgs : EventArgs
+ {
+ public BrowserEventInfo artist;
+ public BrowserEventInfo album;
+
+ public BrowserSearchEventArgs(BrowserEventInfo beiArtist, BrowserEventInfo beiAlbum)
+ {
+ this.artist = beiArtist;
+ this.album = beiAlbum;
+ }
+ }
+
+ public class SourceBrowser : VBox
+ {
+ private Gtk.HBox main_box = new Gtk.HBox();
+ private Gtk.ScrolledWindow artist_scroller = new Gtk.ScrolledWindow();
+ private Gtk.ScrolledWindow album_scroller = new Gtk.ScrolledWindow();
+ private Gtk.TreeView artist_tree = new Gtk.TreeView();
+ private Gtk.TreeView album_tree = new Gtk.TreeView();
+
+ private ListStore artist_store;
+ private ListStore album_store;
+
+ private string artist_selected = "none";
+ private string album_selected = "none";
+
+ private int artist_selection_index = 0;
+ private int album_selection_index = 0;
+
+ private int [] ResetSelectPath = {0};
+
+ public event BrowserSearchEventHandler BrowserClicked;
+
+ private bool hasfilter;
+
+ public SourceBrowser() : base()
+ {
+ BuildUI();
+ }
+
+ private void BuildUI()
+ {
+ artist_scroller.HscrollbarPolicy = PolicyType.Automatic;
+ artist_scroller.VscrollbarPolicy = PolicyType.Always;
+ artist_scroller.ShadowType = ShadowType.EtchedIn;
+ artist_scroller.BorderWidth = 3;
+
+ album_scroller.HscrollbarPolicy = PolicyType.Automatic;
+ album_scroller.VscrollbarPolicy = PolicyType.Always;
+ album_scroller.ShadowType = ShadowType.EtchedIn;
+ album_scroller.BorderWidth = 3;
+
+ artist_tree.HeadersVisible = true;
+ artist_tree.AppendColumn(Catalog.GetString("Artist"), new CellRendererText(), "text", 0);
+ artist_store = CreateStore();
+ artist_tree.Model = artist_store;
+ artist_tree.CursorChanged += OnArtistCursorChanged;
+ artist_scroller.Add(artist_tree);
+
+ album_tree.HeadersVisible = true;
+ album_tree.AppendColumn(Catalog.GetString("Album"), new CellRendererText(), "text", 0);
+ album_store = CreateStore();
+ album_tree.Model = album_store;
+ album_tree.CursorChanged += OnAlbumCursorChanged;
+ album_scroller.Add(album_tree);
+
+ main_box.PackStart(artist_scroller, true, true, 0);
+ main_box.PackStart(album_scroller, true, true, 0);
+
+ PackStart(main_box, true, true, 0);
+ Spacing = 5;
+
+ this.ShowAll();
+ }
+
+ public void Reset()
+ {
+ ResetArtistList();
+ ResetAlbumList();
+ PopulateAlbumStore(false);
+ }
+
+ public void Update(bool isFiltered)
+ {
+ PopulateArtistStore(true);
+ PopulateAlbumStore(true);
+ if(isFiltered) {
+ RunSearch();
+ }
+ }
+
+ public bool Filter
+ {
+ get {
+ UpdateFilterStatus();
+ return hasfilter;
+ }
+ set {
+ hasfilter = value;
+ }
+ }
+
+ private void UpdateFilterStatus()
+ {
+ if(artist_selection_index == 0 && album_selection_index == 0) {
+ hasfilter = false;
+ }
+ }
+
+ private ListStore CreateStore()
+ {
+ ListStore store = new ListStore(typeof(string));
+ return store;
+ }
+
+ private ICollection SortTracks(IEnumerable collection, TrackInfoComparer.Types type)
+ {
+ ArrayList sortedlist = new ArrayList();
+ foreach(TrackInfo track in collection) {
+ sortedlist.Add(track);
+ }
+ sortedlist.Sort(new TrackInfoComparer(type));
+ return sortedlist;
+ }
+
+ private void PopulateArtistStore(bool isUpdate)
+ {
+ artist_store.Clear();
+ StringCollection artistlist = new StringCollection();
+
+ try
+ {
+ ICollection collection = SortTracks(SourceManager.ActiveSource.Tracks,
+ TrackInfoComparer.Types.artist);
+ foreach(TrackInfo track in collection) {
+ if (!artistlist.Contains(track.Artist)) {
+ artistlist.Add(track.Artist as string);
+ }
+ }
+ } catch(Exception) {
+
+ }
+
+ AddEntry("All", true, artist_store);
+ foreach(string entry in artistlist) {
+ AddEntry(entry, false, artist_store);
+ }
+
+ if (isUpdate) {
+ UpdateArtistList();
+ } else {
+ ResetArtistList();
+ }
+ }
+
+ private void PopulateAlbumStore(bool isUpdate)
+ {
+ album_store.Clear();
+ StringCollection albumlist = new StringCollection();
+
+ try
+ {
+ ICollection collection = SortTracks(SourceManager.ActiveSource.Tracks,
+ TrackInfoComparer.Types.album);
+ if (artist_selection_index == 0) {
+ foreach(TrackInfo track in collection) {
+ if (!albumlist.Contains(track.Album)) {
+ albumlist.Add(track.Album as string);
+ }
+ }
+ } else {
+ foreach(TrackInfo track in collection) {
+ if (!albumlist.Contains(track.Album)) {
+ if (track.Artist.Equals(artist_selected)) {
+ albumlist.Add(track.Album as string);
+ }
+ }
+ }
+ }
+ } catch(Exception) {
+
+ }
+
+ AddEntry("All", true, album_store);
+ foreach(string entry in albumlist) {
+ AddEntry(entry, false, album_store);
+ }
+
+ if (isUpdate) {
+ UpdateAlbumList();
+ } else {
+ ResetAlbumList();
+ }
+ }
+
+ private void UpdateAlbumList()
+ {
+ int [] UpdateSelectPath = {album_selection_index };
+ album_tree.Selection.SelectPath(new TreePath(UpdateSelectPath));
+ }
+
+ private void UpdateArtistList()
+ {
+ int [] UpdateSelectPath = {artist_selection_index };
+ artist_tree.Selection.SelectPath(new TreePath(UpdateSelectPath));
+ }
+
+ private void ResetAlbumList()
+ {
+ album_tree.Selection.SelectPath(new TreePath(ResetSelectPath));
+ TreePath[] treeIndex = album_tree.Selection.GetSelectedRows();
+ album_selection_index = treeIndex[0].Indices[0];
+ }
+
+ private void ResetArtistList()
+ {
+ artist_tree.Selection.SelectPath(new TreePath(ResetSelectPath));
+ TreePath[] treeIndex = artist_tree.Selection.GetSelectedRows();
+ artist_selection_index = treeIndex[0].Indices[0];
+ }
+
+ private void AddEntry(string entry, bool prepend,ListStore store)
+ {
+ TreeIter iter = prepend ? store.Insert(0) : store.Append();
+ store.SetValue(iter, 0, entry);
+ }
+
+ private void OnArtistCursorChanged(object o, EventArgs args)
+ {
+ TreeIter iter;
+ if(!artist_tree.Selection.GetSelected(out iter)) {
+ return;
+ }
+
+ object artist_name = artist_store.GetValue(iter, 0);
+ artist_selected = (artist_name as string);
+
+ TreePath[] treeIndex = artist_tree.Selection.GetSelectedRows();
+ artist_selection_index = treeIndex[0].Indices[0];
+
+ if(artist_name == null) {
+ return;
+ }
+
+ PopulateAlbumStore(false);
+ RunSearch();
+ }
+
+ private void OnAlbumCursorChanged(object o, EventArgs args)
+ {
+ TreeIter iter;
+ if(!album_tree.Selection.GetSelected(out iter)) {
+ return;
+ }
+
+ object album_name = album_store.GetValue(iter, 0);
+ album_selected = (album_name as string);
+
+ TreePath[] treeIndex = album_tree.Selection.GetSelectedRows();
+ album_selection_index = treeIndex[0].Indices[0];
+
+ if(album_name == null) {
+ return;
+ }
+
+ RunSearch();
+ }
+
+ private void RunSearch()
+ {
+ BrowserSearchEventHandler handler = BrowserClicked;
+ BrowserEventInfo bei_artist = new BrowserEventInfo(artist_selected, artist_selection_index);
+ BrowserEventInfo bei_album = new BrowserEventInfo(album_selected, album_selection_index);
+ BrowserSearchEventArgs browserArgs = new BrowserSearchEventArgs(bei_artist, bei_album);
+ if(handler != null)
+ {
+ handler(this, browserArgs);
+ }
+ }
+ }
+
+ public class TrackInfoComparer : IComparer
+ {
+ public enum Types : int { artist = 0, album = 1 };
+
+ private int type = (int) TrackInfoComparer.Types.artist;
+
+ public TrackInfoComparer() {}
+
+ public TrackInfoComparer(Types type) { this.type = (int) type; }
+
+ public int Compare(object x, object y)
+ {
+ try {
+ string xstring;
+ string ystring;
+
+ if(this.type == 0) {
+ xstring = ((TrackInfo)x).Artist;
+ ystring = ((TrackInfo)y).Artist;
+ } else {
+ xstring = ((TrackInfo)x).Album;
+ ystring = ((TrackInfo)y).Album;
+ }
+ return xstring.CompareTo(ystring);
+ } catch (Exception){
+ return 0;
+ }
+ }
+ }
+
+ public class BrowserBox : VBox
+ {
+ private SourceBrowser browser;
+
+ public event BrowserSearchEventHandler BrowserSearchActivated;
+
+ public BrowserBox() : base()
+ {
+ BuildUI();
+ }
+
+ private void BuildUI()
+ {
+ browser = new SourceBrowser();
+ browser.HeightRequest = 150;
+ browser.BrowserClicked += OnBrowserClicked;
+
+ PackStart(browser,true,true,0);
+
+ ShowAll();
+ }
+
+ private void OnBrowserClicked(object o, BrowserSearchEventArgs args)
+ {
+ BrowserSearchEventHandler handler = BrowserSearchActivated;
+ if(handler != null)
+ handler(this, args);
+ }
+
+ public void BrowserReset()
+ {
+ browser.Update(false);
+ browser.Reset();
+ }
+
+ public void BrowserUpdate()
+ {
+ Console.WriteLine("BROWSER UPDATED");
+ browser.Update(false);
+ }
+
+ public void BrowserFilter()
+ {
+ browser.Update(true);
+ }
+
+ public bool BrowserHasFilter()
+ {
+ return browser.Filter;
+ }
+
+ public void BrowserSetFilter(bool filterstatus)
+ {
+ browser.Filter = filterstatus;
+ }
+
+ public void Active(bool status)
+ {
+ this.Sensitive = status;
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]