[banshee: 29/61] [InternetArchive] SearchSource not a PrimarySource
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee: 29/61] [InternetArchive] SearchSource not a PrimarySource
- Date: Tue, 3 Nov 2009 06:30:17 +0000 (UTC)
commit 13b822e14de50d3c8c03cca7f0a50a685631cdd1
Author: Gabriel Burt <gabriel burt gmail com>
Date: Mon Oct 12 17:38:31 2009 -0700
[InternetArchive] SearchSource not a PrimarySource
Use a memory model, and implement a custom track list view. This will
let us more easily handle row-activated etc, and not be confused for a
track list model.
.../Banshee.InternetArchive/Actions.cs | 15 +-
.../Banshee.InternetArchive/Item.cs | 2 +
.../Banshee.InternetArchive/SearchSource.cs | 154 ++++----------------
.../Banshee.InternetArchive/SearchView.cs | 139 ++++++++++++++++++
.../InternetArchive/Details.cs | 8 +
.../InternetArchive/SearchResult.cs | 4 +
src/Extensions/Banshee.InternetArchive/Makefile.am | 1 +
7 files changed, 189 insertions(+), 134 deletions(-)
---
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs
index 93b8df6..e80daef 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs
@@ -43,11 +43,10 @@ namespace Banshee.InternetArchive
{
Add (
new ActionEntry ("ViewItemDetails", null, Catalog.GetString ("View Item Details"), null, null, (o, a) => {
- var item = source.TrackModel.FocusedItem;
- if (item != null && item.Uri != null) {
- string [] bits = item.Uri.AbsoluteUri.Split ('/');
- string id = bits[bits.Length - 1];
- var src = new DetailsSource (id, item.TrackTitle);
+ var item = source.FocusedItem;
+ if (item != null && item.Id != null) {
+ string id = item.Id;
+ var src = new DetailsSource (id, item.Title);
source.AddChildSource (src);
Banshee.ServiceStack.ServiceManager.SourceManager.SetActiveSource (src);
}
@@ -58,9 +57,9 @@ namespace Banshee.InternetArchive
if (src != null) {
uri = src.Item.Details.WebpageUrl;
} else {
- var item = source.TrackModel.FocusedItem;
- if (item != null && item.Uri != null) {
- uri = item.Uri.AbsoluteUri;
+ var item = source.FocusedItem;
+ if (item != null) {
+ uri = item.WebpageUrl;
}
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
index 8c2fd40..ebe58d7 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
@@ -102,6 +102,8 @@ namespace Banshee.InternetArchive
{
if (Details == null) {
Details = new IA.Details (Id, DetailsJson);
+ DetailsJson = Details.Json;
+ Provider.Save (this);
}
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
index 77b6c2c..1b4f481 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
@@ -33,7 +33,7 @@ using System.Linq;
using Mono.Unix;
using Hyena.Collections;
-using Hyena.Data.Sqlite;
+using Hyena.Data;
using Banshee.Base;
using Banshee.Collection;
@@ -53,9 +53,10 @@ using IA=InternetArchive;
namespace Banshee.InternetArchive
{
- public class SearchSource : Banshee.Sources.PrimarySource
+ public class SearchSource : Banshee.Sources.Source, IDisposable
{
private static string name = Catalog.GetString ("Internet Archive");
+ private MemoryListModel<IA.SearchResult> model = new MemoryListModel<IA.SearchResult> ();
private Actions actions;
private Gtk.Widget header_widget;
@@ -64,78 +65,47 @@ namespace Banshee.InternetArchive
public IA.Search Search { get { return search; } }
- public SearchSource () : base (name, name, "internet-archive", 190)
+ public IListModel<IA.SearchResult> Model { get { return model; } }
+
+ public IA.SearchResult FocusedItem {
+ get {
+ int focus = model.Selection.FocusedIndex;
+ if (focus >= 0 && focus < model.Count) {
+ return model[focus];
+ }
+
+ return null;
+ }
+ }
+
+ public SearchSource () : base (name, name, 190, "internet-archive")
{
IA.Search.UserAgent = Banshee.Web.Browser.UserAgent;
IA.Search.TimeoutMs = 12*1000;
search = new IA.Search ();
- IsLocal = false;
- // TODO Should probably support normal playlists at some point (but not smart playlists)
- SupportsPlaylists = false;
//Properties.SetStringList ("Icon.Name", "video-x-generic", "video", "source-library");
- Properties.SetString ("TrackView.ColumnControllerXml", String.Format (@"
- <column-controller>
- <add-default column=""TitleColumn"" />
- <add-default column=""ArtistColumn"" />
- <add-default column=""ComposerColumn"" />
- <add-default column=""CommentColumn"" />
- <add-default column=""RatingColumn"" />
- <add-default column=""YearColumn"" />
- <add-default column=""PlayCountColumn"" />
- <add-default column=""MimeTypeColumn"" />
- <add-default column=""LicenseUriColumn"" />
- <column modify-default=""TitleColumn"">
- <width>0.50</width>
- </column>
- <column modify-default=""ArtistColumn"">
- <width>0.25</width>
- <title>{0}</title><long-title>{0}</long-title>
- </column>
- <column modify-default=""PlayCountColumn"">
- <title>{1}</title><long-title>{1}</long-title>
- </column>
- <column modify-default=""RatingColumn""><visible>true</visible></column>
- <column modify-default=""YearColumn""><visible>true</visible></column>
- <column modify-default=""PlayCountColumn""><visible>true</visible></column>
- <column modify-default=""LicenseUriColumn""><visible>true</visible></column>
- <column modify-default=""CommentColumn"">
- <title>{2}</title><long-title>{2}</long-title>
- <visible>false</visible>
- </column>
- <column modify-default=""ComposerColumn"">
- <title>{3}</title><long-title>{3}</long-title>
- <visible>false</visible>
- </column>
- </column-controller>",
- Catalog.GetString ("Creator"), Catalog.GetString ("Downloads"),
- Catalog.GetString ("Description"), Catalog.GetString ("Publisher")
- ));
-
Properties.SetString ("ActiveSourceUIResource", "SearchSourceActiveUI.xml");
Properties.SetString ("GtkActionPath", "/IaSearchSourcePopup");
actions = new Actions (this);
- AfterInitialized ();
-
- DatabaseTrackModel.ForcedSortQuery = "CoreTracks.TrackID ASC";
- DatabaseTrackModel.CanReorder = false;
-
if (header_widget == null) {
header_widget = new HeaderFilters (this);
header_widget.ShowAll ();
Properties.Set<Gtk.Widget> ("Nereid.SourceContents.HeaderWidget", header_widget);
}
+ Properties.Set<Gtk.Widget> ("Nereid.SourceContents", new SearchView (this));
+
foreach (var item in Item.LoadAll ()) {
AddChildSource (new DetailsSource (item));
}
}
- public override void Reload ()
+ public void Reload ()
{
ThreadAssist.SpawnFromMain (ThreadedReload);
}
@@ -165,45 +135,24 @@ namespace Banshee.InternetArchive
if (results != null) {
try {
- ServiceManager.DbConnection.BeginTransaction ();
-
- ServiceManager.DbConnection.Execute ("DELETE FROM CoreTracks WHERE PrimarySourceID = ?", this.DbId);
- DatabaseTrackModel.Clear ();
+ model.Clear ();
foreach (var result in results) {
- var track = new DatabaseTrackInfo () {
- PrimarySource = this,
- ArtistName = result.Creator ?? "",
- Comment = Hyena.StringUtil.RemoveHtml (result.Description),
- Composer = result.Publisher ?? "",
- LicenseUri = result.LicenseUrl,
- PlayCount = result.Downloads,
- Rating = (int) Math.Round (result.AvgRating),
- TrackTitle = result.Title,
- Uri = new Banshee.Base.SafeUri (result.WebpageUrl),
- MimeType = result.Format,
- Year = result.Year
- };
+ model.Add (result);
// HACK to remove ugly empty description
- if (track.Comment == "There is currently no description for this item.")
- track.Comment = null;
-
- track.Save (false);
+ //if (track.Comment == "There is currently no description for this item.")
+ //track.Comment = null;
}
- ServiceManager.DbConnection.CommitTransaction ();
success = true;
} catch (Exception e) {
- ServiceManager.DbConnection.RollbackTransaction ();
Hyena.Log.Exception ("Error searching the Internet Archive", e);
}
}
if (success) {
- base.Reload ();
-
- int count = DatabaseTrackModel.Count;
+ int count = model.Count;
if (total_results == 0) {
ThreadAssist.ProxyToMain (delegate {
SetStatus (Catalog.GetString ("No matches. Try another search?"), false, false, "gtk-info");
@@ -222,6 +171,8 @@ namespace Banshee.InternetArchive
SetStatus (Catalog.GetString ("Error searching the Internet Archive"), true);
});
}
+
+ model.Reload ();
}
public override int Count {
@@ -240,60 +191,11 @@ namespace Banshee.InternetArchive
return false;
}*/
- // DatabaseSource overrides
-
- public override bool ShowBrowser {
- get { return false; }
- }
-
- public override bool CanShuffle {
- get { return false; }
- }
-
- public override bool CanAddTracks {
- get { return false; }
- }
-
- public override bool CanRemoveTracks {
- get { return false; }
- }
-
- public override bool CanDeleteTracks {
- get { return false; }
- }
-
- protected override bool HasArtistAlbum {
- get { return false; }
- }
-
- public override bool HasEditableTrackProperties {
- get { return false; }
- }
-
- public override bool HasViewableTrackProperties {
- get { return false; }
- }
-
- public override bool CanSearch {
- get { return false; }
- }
-
- protected override void Initialize ()
- {
- base.Initialize ();
-
- //InstallPreferences ();
- }
-
- public override void Dispose ()
+ public void Dispose ()
{
if (actions != null) {
actions.Dispose ();
}
-
- base.Dispose ();
-
- //UninstallPreferences ();
}
}
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchView.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchView.cs
new file mode 100644
index 0000000..b947078
--- /dev/null
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchView.cs
@@ -0,0 +1,139 @@
+//
+// SearchView.cs
+//
+// Authors:
+// Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2009 Novell, Inc.
+//
+// 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.Generic;
+using System.Linq;
+
+using Mono.Unix;
+using Gtk;
+
+using Hyena.Collections;
+using Hyena.Data.Sqlite;
+
+using Hyena.Data;
+using Hyena.Data.Gui;
+using Hyena.Widgets;
+
+using Banshee.Base;
+using Banshee.Collection;
+using Banshee.Collection.Gui;
+using Banshee.Collection.Database;
+using Banshee.Configuration;
+using Banshee.Database;
+using Banshee.Gui;
+using Banshee.Library;
+using Banshee.MediaEngine;
+using Banshee.PlaybackController;
+using Banshee.Playlist;
+using Banshee.Preferences;
+using Banshee.ServiceStack;
+using Banshee.Sources;
+
+using IA=InternetArchive;
+
+namespace Banshee.InternetArchive
+{
+ public class SearchView : Gtk.HBox, Banshee.Sources.Gui.ISourceContents
+ {
+ private SearchSource source;
+ private ListView<IA.SearchResult> list_view;
+
+ public SearchView (SearchSource source)
+ {
+ this.source = source;
+
+ list_view = new ListView<IA.SearchResult> () {
+ RulesHint = true,
+ IsEverReorderable = false,
+ ColumnController = new ColumnController ()
+ };
+ AddColumns ();
+
+ var sw = new Gtk.ScrolledWindow ();
+ sw.Child = list_view;
+
+ PackStart (sw, true, true, 0);
+ ShowAll ();
+
+ list_view.SetModel (source.Model);
+ }
+
+ private void AddColumns ()
+ {
+ var cols = new SortableColumn [] {
+ Create ("Title", Catalog.GetString ("Title"), 0.9, true, new ColumnCellText (null, true)),
+ Create ("Creator", Catalog.GetString ("Creator"), 0.15, true, new ColumnCellText (null, true)),
+ Create ("Producer", Catalog.GetString ("Producer"), 0.15, false, new ColumnCellText (null, true)),
+ Create ("Description", Catalog.GetString ("Description"), 0.35, false, new ColumnCellText (null, true)),
+ Create ("AvgRatingInt", Catalog.GetString ("Rating"), 0.15, true, new ColumnCellRating (null, true) { ReadOnly = true }),
+ Create ("Year", Catalog.GetString ("Year"), 0.15, true, new ColumnCellPositiveInt (null, true, 4, 4) { CultureFormatted = false }),
+ Create ("Downloads", Catalog.GetString ("Downloads"), 0.15, true, new ColumnCellPositiveInt (null, true, 2, 5)),
+ Create ("Format", Catalog.GetString ("Formats"), 0.15, false, new ColumnCellText (null, true)),
+ Create ("LicenseUrl", Catalog.GetString ("License"), 0.15, true, new ColumnCellCreativeCommons (null, true))
+ };
+
+ foreach (var col in cols) {
+ list_view.ColumnController.Add (col);
+ }
+ }
+
+ private SortableColumn Create (string property, string label, double width, bool visible, ColumnCell cell)
+ {
+ cell.Property = property;
+ return new SortableColumn (label, cell, width, property, visible);
+ }
+
+#region ISourceContents
+
+ public bool SetSource (ISource source)
+ {
+ this.source = source as SearchSource;
+
+ if (this.source != null) {
+ list_view.SetModel (this.source.Model);
+ return true;
+ }
+
+ return false;
+ }
+
+ public void ResetSource ()
+ {
+ list_view.SetModel (null);
+ source = null;
+ }
+
+ public ISource Source { get { return source; } }
+
+ public Widget Widget { get { return this; } }
+
+#endregion
+
+ }
+}
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/Details.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/Details.cs
index 0457643..abe6e89 100644
--- a/src/Extensions/Banshee.InternetArchive/InternetArchive/Details.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/Details.cs
@@ -163,6 +163,10 @@ namespace InternetArchive
get { return review_info.Get<double> ("avg_rating"); }
}
+ public int AvgRatingInt {
+ get { return (int) Math.Round (AvgRating); }
+ }
+
public int NumReviews {
get { return review_info.Get<int> ("num_reviews"); }
}
@@ -171,6 +175,10 @@ namespace InternetArchive
get { return String.Format ("http://www.archive.org/details/{0}", id); }
}
+ public string Json {
+ get { return json; }
+ }
+
#endregion
private void LoadDetails ()
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/SearchResult.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/SearchResult.cs
index 2187695..5a5741a 100644
--- a/src/Extensions/Banshee.InternetArchive/InternetArchive/SearchResult.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/SearchResult.cs
@@ -75,6 +75,10 @@ namespace InternetArchive
get { return Get<double> (Field.AvgRating); }
}
+ public int AvgRatingInt {
+ get { return (int) Math.Round (AvgRating); }
+ }
+
public string Title {
get { return Get<string> (Field.Title); }
}
diff --git a/src/Extensions/Banshee.InternetArchive/Makefile.am b/src/Extensions/Banshee.InternetArchive/Makefile.am
index 1517be5..b420bd7 100644
--- a/src/Extensions/Banshee.InternetArchive/Makefile.am
+++ b/src/Extensions/Banshee.InternetArchive/Makefile.am
@@ -10,6 +10,7 @@ SOURCES = \
Banshee.InternetArchive/HeaderFilters.cs \
Banshee.InternetArchive/Item.cs \
Banshee.InternetArchive/SearchSource.cs \
+ Banshee.InternetArchive/SearchView.cs \
InternetArchive/Collection.cs \
InternetArchive/Details.cs \
InternetArchive/DetailsFile.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]