[banshee: 16/61] [InternetArchive] Add view item's details action
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee: 16/61] [InternetArchive] Add view item's details action
- Date: Tue, 3 Nov 2009 06:29:11 +0000 (UTC)
commit 4dc5bd0e31ad11cc88e7d96817c0af3581a71eb0
Author: Gabriel Burt <gabriel burt gmail com>
Date: Thu Oct 8 15:22:03 2009 -0700
[InternetArchive] Add view item's details action
And actually load the JSON details from archive.org
.../Banshee.InternetArchive/Actions.cs | 10 ++
.../Banshee.InternetArchive/File.cs | 6 +-
.../Banshee.InternetArchive/Item.cs | 24 +++--
.../Banshee.InternetArchive/ItemSource.cs | 109 ++++++++------------
.../Banshee.InternetArchive/ItemSourceContents.cs | 93 ++++++++++++++---
.../Banshee.InternetArchive/Source.cs | 3 -
.../InternetArchive/Item.cs | 9 +--
.../Resources/ActiveSourceUI.xml | 1 +
8 files changed, 152 insertions(+), 103 deletions(-)
---
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs
index 3ee97cd..7d1feb6 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Actions.cs
@@ -42,6 +42,16 @@ namespace Banshee.InternetArchive
public Actions (Source source) : base ("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 ItemSource (item.TrackTitle, id);
+ source.AddChildSource (src);
+ Banshee.ServiceStack.ServiceManager.SourceManager.SetActiveSource (src);
+ }
+ }),
new ActionEntry ("OpenItemWebsite", Stock.JumpTo, Catalog.GetString ("Open Webpage"), null, null, (o, a) => {
var item = source.TrackModel.FocusedItem;
if (item != null && item.Uri != null) {
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/File.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/File.cs
index 1b99dc7..3f9182f 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/File.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/File.cs
@@ -42,10 +42,12 @@ namespace Banshee.InternetArchive
public class File
{
JsonObject file;
+ string location_root;
- public File (JsonObject file)
+ public File (JsonObject file, string location_root)
{
this.file = file;
+ this.location_root = location_root;
}
private long GetLong (string i)
@@ -79,7 +81,7 @@ namespace Banshee.InternetArchive
}
public string Location {
- get { return file.Get<string> ("location"); }
+ get { return location_root + file.Get<string> ("location"); }
}
public long Size {
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
index 63c11b7..d869bf8 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
@@ -60,6 +60,8 @@ namespace Banshee.InternetArchive
LoadDetails ();
}
+#region Properties stored in database columns
+
//[DatabaseColumn (PrimaryKey=true)]
public long DbId { get; set; }
@@ -72,6 +74,10 @@ namespace Banshee.InternetArchive
//[DatabaseColumn]
public bool IsHidden { get; set; }
+#endregion
+
+#region Properties from the JSON object
+
public string Title {
get { return metadata.GetJoined ("title", System.Environment.NewLine); }
}
@@ -90,13 +96,16 @@ namespace Banshee.InternetArchive
public IEnumerable<File> Files {
get {
+ string location_root = String.Format ("http://{0}{1}", details.Get<string> ("server"), details.Get<string> ("dir"));
var files = details["files"] as JsonObject;
foreach (JsonObject file in files.Values) {
- yield return new File (file);
+ yield return new File (file, location_root);
}
}
}
+#endregion
+
private bool LoadDetails ()
{
// First see if we already have the Hyena.JsonObject parsed
@@ -111,24 +120,25 @@ namespace Banshee.InternetArchive
}*/
- details = new Hyena.Json.Deserializer (System.IO.File.ReadAllText ("item.json")).Deserialize () as JsonObject;
+ /*details = new Hyena.Json.Deserializer (System.IO.File.ReadAllText ("item.json")).Deserialize () as JsonObject;
metadata = details["metadata"] as JsonObject;
- return details != null;
+ return details != null;*/
// We don't; grab it from archive.org and parse it
- /*string json_str = new IA.Item () { Id = Id }.GetDetails ();
+ string json_str = IA.Item.GetDetails (Id);
if (json_str != null) {
details = new Hyena.Json.Deserializer (json_str).Deserialize () as JsonObject;
+ metadata = details["metadata"] as JsonObject;
if (details != null) {
JsonDetails = json_str;
- Save ();
+ //Save ();
return true;
}
- }*/
+ }
- //return false;
+ return false;
}
}
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSource.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSource.cs
index 8b067ee..8d685d1 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSource.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSource.cs
@@ -53,94 +53,87 @@ using IA=InternetArchive;
namespace Banshee.InternetArchive
{
- public class ItemSource : Banshee.Sources.PrimarySource
+ public class ItemSource : Banshee.Sources.Source, ITrackModelSource, IDurationAggregator, IFileSizeAggregator
{
- //private Actions actions;
- //private Gtk.Widget header_widget;
- //private IA.Search search;
- private string status_text = "";
private Item item;
+ private MemoryTrackListModel track_model;
- public ItemSource (string name, string id) : base (name, name, "internet-archive-" + id, 210)
+ public ItemSource (string name, string id) : base (name, name, 40, "internet-archive-" + id)
{
item = Item.LoadOrCreate (id);
+ track_model = new MemoryTrackListModel ();
+ track_model.Reloaded += delegate { OnUpdated (); };
- IsLocal = false;
- SupportsPlaylists = false;
- //Properties.SetStringList ("Icon.Name", "video-x-generic", "video", "source-library");
-
- //Properties.SetString ("ActiveSourceUIResource", "ItemActiveSourceUI.xml");
- //Properties.Set<bool> ("ActiveSourceUIResourcePropagate", true);
-
- //actions = new Actions (this);
- //
- Properties.Set<Gtk.Widget> ("Nereid.SourceContents", new ItemSourceContents (item));
-
- AfterInitialized ();
-
- DatabaseTrackModel.CanReorder = false;
+ Properties.Set<Gtk.Widget> ("Nereid.SourceContents", new ItemSourceContents (this, item));
+ }
- if (item == null)
- Console.WriteLine ("foo");
+ public void Reload ()
+ {
+ }
- /*if (header_widget == null) {
- header_widget = new HeaderFilters (this);
- header_widget.ShowAll ();
- Properties.Set<Gtk.Widget> ("Nereid.SourceContents.HeaderWidget", header_widget);
- }*/
+ public override int Count {
+ get { return 0; }
}
- public override void Reload ()
- {
- ThreadAssist.SpawnFromMain (ThreadedReload);
+ public override int FilteredCount {
+ get { return track_model.Count; }
}
- private void ThreadedReload ()
- {
+ public TimeSpan Duration {
+ get {
+ TimeSpan duration = TimeSpan.Zero;
+ foreach (var t in track_model) {
+ duration += t.Duration;
+ }
+ return duration;
+ }
}
- public override int Count {
- get { return 0; }
+ public long FileSize {
+ get { return track_model.Sum (t => t.FileSize); }
}
- protected override int StatusFormatsCount { get { return 1; } }
+#region ITrackModelSource
- public override string GetStatusText ()
- {
- return status_text;
+ public TrackListModel TrackModel {
+ get { return track_model; }
}
- /*public override bool AcceptsInputFromSource (Source source)
- {
- return false;
- }*/
+ public bool HasDependencies { get { return false; } }
+
+ public void RemoveSelectedTracks () {}
+ public void DeleteSelectedTracks () {}
- // DatabaseSource overrides
+ public bool ConfirmRemoveTracks { get { return false; } }
- public override bool ShowBrowser {
+ public bool Indexable { get { return false; } }
+
+ public bool ShowBrowser {
get { return false; }
}
- public override bool CanShuffle {
+ public bool CanShuffle {
get { return false; }
}
- public override bool CanAddTracks {
+ public bool CanRepeat {
get { return false; }
}
- public override bool CanRemoveTracks {
+ public bool CanAddTracks {
get { return false; }
}
- public override bool CanDeleteTracks {
+ public bool CanRemoveTracks {
get { return false; }
}
- protected override bool HasArtistAlbum {
+ public bool CanDeleteTracks {
get { return false; }
}
+#endregion
+
public override bool HasEditableTrackProperties {
get { return false; }
}
@@ -152,23 +145,5 @@ namespace Banshee.InternetArchive
public override bool CanSearch {
get { return false; }
}
-
- protected override void Initialize ()
- {
- base.Initialize ();
-
- //InstallPreferences ();
- }
-
- public override void Dispose ()
- {
- /*if (actions != null) {
- actions.Dispose ();
- }*/
-
- base.Dispose ();
-
- //UninstallPreferences ();
- }
}
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSourceContents.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSourceContents.cs
index 03e1dfd..7dfa6db 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSourceContents.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/ItemSourceContents.cs
@@ -38,6 +38,7 @@ using Hyena.Data.Sqlite;
using Hyena.Data;
using Hyena.Data.Gui;
+using Hyena.Widgets;
using Banshee.Base;
using Banshee.Collection;
@@ -63,8 +64,9 @@ namespace Banshee.InternetArchive
private ItemSource source;
Item item;
- public ItemSourceContents (Item item)
+ public ItemSourceContents (ItemSource source, Item item)
{
+ this.source = source;
this.item = item;
Spacing = 6;
@@ -100,25 +102,32 @@ namespace Banshee.InternetArchive
vbox.Spacing = 6;
// Title
- var title = new Label () {
+ /*var title = new Label () {
+ Xalign = 0f,
Markup = String.Format ("<big><b>{0}</b></big>", GLib.Markup.EscapeText (item.Title))
- };
+ };*/
// Description
var desc = new Hyena.Widgets.WrapLabel () {
Markup = item.Description
};
- var desc_sw = new Gtk.ScrolledWindow ();
- desc_sw.AddWithViewport (desc);
+ //var expander = new Expander (Catalog.GetString ("Details"));
+ // A table w/ this info, inside the expander?
+ // Notes / DateCreated / venue / publisher / source / taper / lineage
+
+ //var desc_sw = new Gtk.ScrolledWindow ();
+ //desc_sw.AddWithViewport (desc);
// Reviews
var reviews = new Label () {
+ Xalign = 0f,
Markup = String.Format ("<big><b>{0}</b></big>", GLib.Markup.EscapeText (Catalog.GetString ("Reviews")))
};
- vbox.PackStart (title, false, false, 0);
- vbox.PackStart (desc_sw, true, true, 0);
+ //vbox.PackStart (title, false, false, 0);
+ //vbox.PackStart (desc_sw, true, true, 0);
+ vbox.PackStart (desc, true, true, 0);
vbox.PackStart (reviews, false, false, 0);
frame.Child = vbox;
@@ -133,18 +142,27 @@ namespace Banshee.InternetArchive
var format_list = new Hyena.Data.Gui.ListView<string> () {
HeaderVisible = false
};
- var format_sw = new Gtk.ScrolledWindow ();
- format_sw.Child = format_list;
+
+ format_list.SizeRequested += (o, a) => {
+ //a.Requisition.Height += (format_list.Model.Count * format_list.RowHeight);
+ var new_req = new Requisition () {
+ Width = a.Requisition.Width,
+ Height = a.Requisition.Height + (format_list.Model.Count * format_list.RowHeight)
+ };
+ a.Requisition = new_req;
+ };
+
var format_cols = new ColumnController ();
format_cols.Add (new Column ("format", new ColumnCellText (null, true), 1.0));
- format_list.ColumnController = format_cols;
- var file_list = new ListView<TrackInfo> () {
- HeaderVisible = false
+ var file_list = new BaseTrackListView () {
+ HeaderVisible = true,
+ IsEverReorderable = false
};
- var files_model = new MemoryTrackListModel ();
+ var files_model = source.TrackModel as MemoryTrackListModel;
var columns = new DefaultColumnController ();
+ columns.TrackColumn.Title = "#";
var file_columns = new ColumnController ();
file_columns.AddRange (
columns.IndicatorColumn,
@@ -158,14 +176,13 @@ namespace Banshee.InternetArchive
col.Visible = true;
}
- file_list.ColumnController = file_columns;
-
var file_sw = new Gtk.ScrolledWindow ();
file_sw.Child = file_list;
var format_model = new MemoryListModel<string> ();
var files = new List<TrackInfo> ();
+ string [] format_blacklist = new string [] { "zip", "m3u", "metadata", "fingerprint", "checksums", "text" };
foreach (var f in item.Files) {
var track = new TrackInfo () {
Uri = new SafeUri (f.Location),
@@ -181,7 +198,9 @@ namespace Banshee.InternetArchive
files.Add (track);
if (format_model.IndexOf (f.Format) == -1) {
- format_model.Add (f.Format);
+ if (!format_blacklist.Any (fmt => f.Format.ToLower ().Contains (fmt))) {
+ format_model.Add (f.Format);
+ }
}
}
@@ -194,6 +213,22 @@ namespace Banshee.InternetArchive
}
}
+ // Make these columns snugly fix their data
+ (columns.TrackColumn.GetCell (0) as ColumnCellText).SetMinMaxStrings (files.Max (f => f.TrackNumber));
+ (columns.FileSizeColumn.GetCell (0) as ColumnCellText).SetMinMaxStrings (files.Max (f => f.FileSize));
+ (columns.FileSizeColumn.GetCell (0) as ColumnCellText).Expand = false;
+ (columns.DurationColumn.GetCell (0) as ColumnCellText).SetMinMaxStrings (files.Max (f => f.Duration));
+
+ string max_title = "";
+ var sorted_by_title = files.OrderBy (f => f.TrackTitle == null ? 0 : f.TrackTitle.Length).ToList ();
+ //var nine_tenths = sorted_by_title[(int)Math.Floor (.90 * sorted_by_title.Count)].TrackTitle;
+ var max = sorted_by_title[sorted_by_title.Count - 1].TrackTitle;
+ //max_title = max.Length >= 2.0 * nine_tenths.Length ? nine_tenths : max;
+ max_title = max;//max.Length >= 2.0 * nine_tenths.Length ? nine_tenths : max;
+ (columns.TitleColumn.GetCell (0) as ColumnCellText).SetMinMaxStrings (sorted_by_title[0].TrackTitle, max_title);
+
+ file_list.ColumnController = file_columns;
+ format_list.ColumnController = format_cols;
file_list.SetModel (files_model);
format_list.SetModel (format_model);
@@ -210,8 +245,32 @@ namespace Banshee.InternetArchive
files_model.Reload ();
};
- vbox.PackStart (format_sw, false, false, 0);
+ if (format_model.IndexOf ("VBR MP3") != -1) {
+ format_list.Selection.Select (format_model.IndexOf ("VBR MP3"));
+ }
+
+
+ // Action buttons
+ var button = new Button ("Add to Library") {
+ Relief = ReliefStyle.None
+ };
+
+ /*var menu = new Menu ();
+ menu.Append (new MenuItem ("Add to Music Library"));
+ menu.Append (new MenuItem ("Add to Video Library"));
+ menu.Append (new MenuItem ("Add to Podcast Library"));
+ menu.ShowAll ();
+
+ var add_to_library = new MenuButton (button, menu, true);*/
+ //var action_frame = new RoundedFrame ();
+ var action_box = new HBox () { Spacing = 6 };
+ action_box.PackStart (button, false, false, 0);
+ //action_frame.Add (action_box);
+ action_box.ShowAll ();
+
+ vbox.PackStart (format_list, false, false, 0);
vbox.PackStart (file_sw, true, true, 0);
+ //vbox.PackStart (action_box, false, false, 0);
PackStart (vbox, true, true, 0);
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs
index f7740b7..a92aa37 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs
@@ -131,9 +131,6 @@ namespace Banshee.InternetArchive
header_widget.ShowAll ();
Properties.Set<Gtk.Widget> ("Nereid.SourceContents.HeaderWidget", header_widget);
}
-
- var src = new ItemSource ("Fake Name", "foo");
- AddChildSource (src);
}
public override void Reload ()
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/Item.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/Item.cs
index ee5e4e5..a4ffa65 100644
--- a/src/Extensions/Banshee.InternetArchive/InternetArchive/Item.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/Item.cs
@@ -52,21 +52,16 @@ namespace InternetArchive
get { return Get<string> (Field.Identifier); }
}
- private string JsonDetailsUrl {
- get { return String.Format ("{0}&output=json", WebpageUrl); }
- }
-
public string WebpageUrl {
get { return String.Format ("http://www.archive.org/details/{0}", Id); }
}
- public string GetDetails ()
+ public static string GetDetails (string id)
{
HttpWebResponse response = null;
- string url = null;
+ string url = String.Format ("http://www.archive.org/details/{0}&output=json", id);
try {
- url = JsonDetailsUrl;
Hyena.Log.Debug ("ArchiveSharp Getting Details", url);
var request = (HttpWebRequest) WebRequest.Create (url);
diff --git a/src/Extensions/Banshee.InternetArchive/Resources/ActiveSourceUI.xml b/src/Extensions/Banshee.InternetArchive/Resources/ActiveSourceUI.xml
index c7a7694..d4d420a 100644
--- a/src/Extensions/Banshee.InternetArchive/Resources/ActiveSourceUI.xml
+++ b/src/Extensions/Banshee.InternetArchive/Resources/ActiveSourceUI.xml
@@ -24,6 +24,7 @@
<popup name="TrackContextMenu" action="TrackContextMenuAction">
<placeholder name="BelowAddToPlaylist">
<separator />
+ <menuitem action="ViewItemDetails" />
<menuitem action="OpenItemWebsite" />
<separator />
</placeholder>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]