[banshee] [WebBrowser] Abstract useful bits from amzn store
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] [WebBrowser] Abstract useful bits from amzn store
- Date: Wed, 14 Jul 2010 05:05:08 +0000 (UTC)
commit 30c2c8c6cf05ec900de343ad7fc130bf8c6e271c
Author: Gabriel Burt <gabriel burt gmail com>
Date: Tue Jul 13 21:27:51 2010 -0700
[WebBrowser] Abstract useful bits from amzn store
.../Banshee.WebBrowser/Banshee.WebBrowser.csproj | 3 +
.../Banshee.WebSource}/WebBrowserShell.cs | 63 ++++-----
.../Banshee.WebSource/WebSource.cs | 93 +++++++++++++
.../Banshee.WebSource/WebView.cs | 136 ++++++++++++++++++++
src/Core/Banshee.WebBrowser/Makefile.am | 10 +-
.../Banshee.WebBrowser}/Resources/loading.html | 0
.../Banshee.AmazonMp3.Store.csproj | 2 +-
.../Banshee.AmazonMp3.Store/StoreSource.cs | 54 +-------
.../Banshee.AmazonMp3.Store/StoreView.cs | 89 ++-----------
.../StoreWebBrowserShell.cs | 63 +++++++++
src/Extensions/Banshee.AmazonMp3.Store/Makefile.am | 5 +-
11 files changed, 349 insertions(+), 169 deletions(-)
---
diff --git a/src/Core/Banshee.WebBrowser/Banshee.WebBrowser.csproj b/src/Core/Banshee.WebBrowser/Banshee.WebBrowser.csproj
index 6519ef6..61a0196 100644
--- a/src/Core/Banshee.WebBrowser/Banshee.WebBrowser.csproj
+++ b/src/Core/Banshee.WebBrowser/Banshee.WebBrowser.csproj
@@ -102,5 +102,8 @@
<Compile Include="Banshee.WebBrowser\OssiferLoadStatus.cs" />
<Compile Include="Banshee.WebBrowser\OssiferCookie.cs" />
<Compile Include="Banshee.WebBrowser\OssiferSession.cs" />
+ <Compile Include="Banshee.WebSource\WebBrowserShell.cs" />
+ <Compile Include="Banshee.WebSource\WebSource.cs" />
+ <Compile Include="Banshee.WebSource\WebView.cs" />
</ItemGroup>
</Project>
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/WebBrowserShell.cs b/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebBrowserShell.cs
similarity index 66%
rename from src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/WebBrowserShell.cs
rename to src/Core/Banshee.WebBrowser/Banshee.WebSource/WebBrowserShell.cs
index e68f3d0..182ee53 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/WebBrowserShell.cs
+++ b/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebBrowserShell.cs
@@ -1,8 +1,9 @@
//
// WebBrowserShell.cs
//
-// Author:
+// Authors:
// Aaron Bockover <abockover novell com>
+// Gabriel Burt <gburt novell com>
//
// Copyright 2010 Novell, Inc.
//
@@ -32,25 +33,30 @@ using Mono.Unix;
using Banshee.Widgets;
using Banshee.WebBrowser;
-namespace Banshee.AmazonMp3.Store
+namespace Banshee.WebSource
{
public class WebBrowserShell : Table, Banshee.Gui.IDisableKeybindings
{
- private ScrolledWindow store_view_scroll = new ScrolledWindow ();
- private StoreView store_view = new StoreView ();
+ private string name;
+ private ScrolledWindow view_scroll = new ScrolledWindow ();
+ private WebView view;
private NavigationControl navigation_control = new NavigationControl ();
private Label title = new Label ();
- private Button sign_out_button = new Button (Catalog.GetString ("Sign out of Amazon")) { Relief = ReliefStyle.None };
private SearchEntry search_entry = new SearchEntry ();
private int search_clear_on_navigate_state;
- public WebBrowserShell () : base (2, 4, false)
+ public SearchEntry SearchEntry { get { return search_entry; } }
+
+ public WebBrowserShell (string name, WebView view) : base (2, 4, false)
{
+ this.name = name;
+ this.view = view;
+
RowSpacing = 5;
- store_view.LoadStatusChanged += (o, e) => {
- if (store_view.LoadStatus == OssiferLoadStatus.FirstVisuallyNonEmptyLayout) {
- UpdateTitle (store_view.Title);
+ view.LoadStatusChanged += (o, e) => {
+ if (view.LoadStatus == OssiferLoadStatus.FirstVisuallyNonEmptyLayout) {
+ UpdateTitle (view.Title);
switch (search_clear_on_navigate_state) {
case 1:
@@ -64,9 +70,9 @@ namespace Banshee.AmazonMp3.Store
}
};
- store_view.Ready += (o, e) => navigation_control.WebView = store_view;
+ view.Ready += (o, e) => navigation_control.WebView = view;
- navigation_control.GoHomeEvent += (o, e) => store_view.GoHome ();
+ navigation_control.GoHomeEvent += (o, e) => view.GoHome ();
Attach (navigation_control, 0, 1, 0, 1,
AttachOptions.Shrink,
@@ -82,24 +88,17 @@ namespace Banshee.AmazonMp3.Store
AttachOptions.Shrink,
0, 0);
- sign_out_button.Clicked += (o, e) => store_view.SignOut ();
-
- Attach (sign_out_button, 2, 3, 0, 1,
- AttachOptions.Shrink,
- AttachOptions.Shrink,
- 0, 0);
-
- search_entry.EmptyMessage = String.Format (Catalog.GetString ("Search the Amazon MP3 Store"));
+ //search_entry.EmptyMessage = String.Format (Catalog.GetString ("Search the Amazon MP3 Store"));
search_entry.SetSizeRequest (260, -1);
// FIXME: dummy option to make the "search" icon show up;
// we should probably fix this in the SearchEntry, but also
// add real filter options for searching Amazon MP3 (artist,
// album, genre, etc.)
- search_entry.AddFilterOption (0, Catalog.GetString ("Amazon MP3 Store"));
+ search_entry.AddFilterOption (0, name);
search_entry.Show ();
search_entry.Activated += (o, e) => {
- store_view.GoSearch (search_entry.Query);
- store_view.HasFocus = true;
+ view.GoSearch (search_entry.Query);
+ view.HasFocus = true;
search_clear_on_navigate_state = 1;
};
Attach (search_entry, 3, 4, 0, 1,
@@ -107,32 +106,24 @@ namespace Banshee.AmazonMp3.Store
AttachOptions.Shrink,
0, 0);
- store_view_scroll.Add (store_view);
- store_view_scroll.ShadowType = ShadowType.In;
+ view_scroll.Add (view);
+ view_scroll.ShadowType = ShadowType.In;
- Attach (store_view_scroll, 0, 4, 1, 2,
+ Attach (view_scroll, 0, 4, 1, 2,
AttachOptions.Expand | AttachOptions.Fill,
AttachOptions.Expand | AttachOptions.Fill,
0, 0);
- UpdateTitle (Catalog.GetString ("Loading Amazon MP3 Store..."));
+ UpdateTitle (String.Format (Catalog.GetString ("Loading {0}..."), name));
ShowAll ();
-
- store_view.SignInChanged += (o, e) => UpdateSignInButton ();
- UpdateSignInButton ();
- }
-
- private void UpdateSignInButton ()
- {
- sign_out_button.Visible = store_view.IsSignedIn;
}
private void UpdateTitle (string titleText)
{
- if (store_view.Uri != "about:blank") {
+ if (view.Uri != "about:blank") {
if (String.IsNullOrEmpty (titleText)) {
- titleText = Catalog.GetString ("Amazon MP3 Store");
+ titleText = name;
}
title.Markup = String.Format ("<b>{0}</b>", GLib.Markup.EscapeText (titleText));
}
diff --git a/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebSource.cs b/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebSource.cs
new file mode 100644
index 0000000..7859944
--- /dev/null
+++ b/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebSource.cs
@@ -0,0 +1,93 @@
+//
+// WebSource.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+//
+// Copyright 2010 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 Mono.Unix;
+
+using Hyena;
+
+using Banshee.Sources;
+using Banshee.Sources.Gui;
+using Banshee.WebBrowser;
+
+namespace Banshee.WebSource
+{
+ public abstract class WebSource : Source
+ {
+ private WebSourceContents source_contents;
+
+ public WebSource (string name, int order, string id) : base (name, name, order, id)
+ {
+ TypeUniqueId = id;
+ Properties.Set<bool> ("Nereid.SourceContents.HeaderVisible", false);
+ }
+
+ public override void Activate ()
+ {
+ if (source_contents == null) {
+ Properties.Set<ISourceContents> ("Nereid.SourceContents",
+ source_contents = new WebSourceContents (this, GetWidget ()));
+ }
+
+ base.Activate ();
+ }
+
+ protected abstract Gtk.Widget GetWidget ();
+
+ public override int Count {
+ get { return 0; }
+ }
+
+ private class WebSourceContents : ISourceContents
+ {
+ private WebSource source;
+ private Gtk.Widget widget;
+
+ public WebSourceContents (WebSource source, Gtk.Widget widget)
+ {
+ this.source = source;
+ this.widget = widget;
+ }
+
+ public bool SetSource (ISource source)
+ {
+ return true;
+ }
+
+ public void ResetSource ()
+ {
+ }
+
+ public Gtk.Widget Widget {
+ get { return widget; }
+ }
+
+ public ISource Source {
+ get { return source; }
+ }
+ }
+ }
+}
diff --git a/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebView.cs b/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebView.cs
new file mode 100644
index 0000000..786cbd2
--- /dev/null
+++ b/src/Core/Banshee.WebBrowser/Banshee.WebSource/WebView.cs
@@ -0,0 +1,136 @@
+//
+// WebView.cs
+//
+// Authors:
+// Aaron Bockover <abockover novell com>
+// Gabriel Burt <gburt novell com>
+//
+// Copyright 2010 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 Gtk;
+
+using Hyena;
+using Hyena.Downloader;
+
+using Banshee.Base;
+using Banshee.IO;
+using Banshee.WebBrowser;
+
+namespace Banshee.WebSource
+{
+ public abstract class WebView : OssiferWebView
+ {
+ protected string FixupJavascriptUrl { get; set; }
+ private string fixup_javascript;
+ private bool fixup_javascript_fetched;
+
+ public bool IsReady { get; private set; }
+ public bool CanSearch { get; protected set; }
+
+ public event EventHandler Ready;
+
+ public WebView ()
+ {
+ CanSearch = false;
+ }
+
+ protected override void OnLoadStatusChanged (OssiferLoadStatus status)
+ {
+ if ((status == OssiferLoadStatus.FirstVisuallyNonEmptyLayout ||
+ status == OssiferLoadStatus.Finished) && Uri != "about:blank") {
+ if (fixup_javascript != null) {
+ ExecuteScript (fixup_javascript);
+ }
+ }
+
+ base.OnLoadStatusChanged (status);
+ }
+
+ protected override OssiferNavigationResponse OnMimeTypePolicyDecisionRequested (string mimetype)
+ {
+ // We only explicitly accept (render) text/html -- everything else is ignored.
+ switch (mimetype) {
+ case "text/html": return OssiferNavigationResponse.Accept;
+ default:
+ Log.Debug ("OssiferWebView: ignoring mime type", mimetype);
+ return OssiferNavigationResponse.Ignore;
+ }
+ }
+
+ public abstract void GoHome ();
+
+ public virtual void GoSearch (string query)
+ {
+ }
+
+ public void FullReload ()
+ {
+ // This is an HTML5 Canvas/JS spinner icon. It is awesome
+ // and renders immediately, going away when the store loads.
+ LoadString (AssemblyResource.GetFileContents ("loading.html"),
+ "text/html", "UTF-8", null);
+
+ // Here we download and save for later injection some JavaScript
+ // to fix-up the Amazon pages. We don't store this locally since
+ // it may need to be updated if Amazon's page structure changes.
+ // We're mainly concerned about hiding the "You don't have Flash"
+ // messages, since we do the streaming of previews natively.
+ if (FixupJavascriptUrl != null && !fixup_javascript_fetched) {
+ fixup_javascript_fetched = true;
+ new Hyena.Downloader.HttpStringDownloader () {
+ Uri = new Uri (FixupJavascriptUrl),
+ Finished = (d) => {
+ if (d.State.Success) {
+ fixup_javascript = d.Content;
+ }
+ LoadHome ();
+ },
+ AcceptContentTypes = new [] { "text/javascript" }
+ }.Start ();
+ } else {
+ LoadHome ();
+ }
+ }
+
+ private void LoadHome ()
+ {
+ // We defer this to another main loop iteration, otherwise
+ // our load placeholder document will never be rendered.
+ GLib.Idle.Add (delegate {
+ GoHome ();
+
+ // Emit the Ready event once we are first allowed
+ // to load the home page (ensures we've downloaded
+ // the fixup javascript, etc.).
+ if (!IsReady) {
+ IsReady = true;
+ var handler = Ready;
+ if (handler != null) {
+ handler (this, EventArgs.Empty);
+ }
+ }
+ return false;
+ });
+ }
+ }
+}
diff --git a/src/Core/Banshee.WebBrowser/Makefile.am b/src/Core/Banshee.WebBrowser/Makefile.am
index 44a2f84..d795a3a 100644
--- a/src/Core/Banshee.WebBrowser/Makefile.am
+++ b/src/Core/Banshee.WebBrowser/Makefile.am
@@ -12,10 +12,16 @@ SOURCES = \
Banshee.WebBrowser/OssiferLoadStatus.cs \
Banshee.WebBrowser/OssiferNavigationResponse.cs \
Banshee.WebBrowser/OssiferSession.cs \
- Banshee.WebBrowser/OssiferWebView.cs
+ Banshee.WebBrowser/OssiferWebView.cs \
+ Banshee.WebSource/WebBrowserShell.cs \
+ Banshee.WebSource/WebSource.cs \
+ Banshee.WebSource/WebView.cs
+
+RESOURCES = \
+ Resources/loading.html
if HAVE_LIBWEBKIT
include $(top_srcdir)/build/build.mk
else
-EXTRA_DIST = $(SOURCES)
+EXTRA_DIST = $(SOURCES) $(RESOURCES)
endif
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Resources/loading.html b/src/Core/Banshee.WebBrowser/Resources/loading.html
similarity index 100%
rename from src/Extensions/Banshee.AmazonMp3.Store/Resources/loading.html
rename to src/Core/Banshee.WebBrowser/Resources/loading.html
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj
index ede303b..7d08a05 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj
@@ -115,6 +115,6 @@
<ItemGroup>
<Compile Include="Banshee.AmazonMp3.Store\StoreSource.cs" />
<Compile Include="Banshee.AmazonMp3.Store\StoreView.cs" />
- <Compile Include="Banshee.AmazonMp3.Store\WebBrowserShell.cs" />
+ <Compile Include="Banshee.AmazonMp3.Store\StoreWebBrowserShell.cs" />
</ItemGroup>
</Project>
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs
index 0404b0c..d91f478 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs
@@ -29,64 +29,18 @@ using Mono.Unix;
using Hyena;
-using Banshee.Sources;
-using Banshee.Sources.Gui;
-using Banshee.WebBrowser;
-
namespace Banshee.AmazonMp3.Store
{
- public class StoreSource : Source
+ public class StoreSource : Banshee.WebSource.WebSource
{
- private StoreSourceContents source_contents;
-
- public StoreSource () : base (Catalog.GetString ("Amazon MP3 Store"),
- Catalog.GetString ("Amazon MP3 Store"), 150, "amazon-mp3-store")
+ public StoreSource () : base (Catalog.GetString ("Amazon MP3 Store"), 150, "amazon-mp3-store")
{
- TypeUniqueId = "amazon-mp3-store";
Properties.SetString ("Icon.Name", "amazon-mp3-store-source");
- Properties.Set<bool> ("Nereid.SourceContents.HeaderVisible", false);
}
- public override void Activate ()
+ protected override Gtk.Widget GetWidget ()
{
- if (source_contents == null) {
- Properties.Set<ISourceContents> ("Nereid.SourceContents",
- source_contents = new StoreSourceContents (this));
- }
-
- base.Activate ();
- }
-
- public override int Count {
- get { return 0; }
- }
-
- private class StoreSourceContents : ISourceContents
- {
- private StoreSource source;
- private WebBrowserShell browser_shell = new WebBrowserShell ();
-
- public StoreSourceContents (StoreSource source)
- {
- this.source = source;
- }
-
- public bool SetSource (ISource source)
- {
- return true;
- }
-
- public void ResetSource ()
- {
- }
-
- public Gtk.Widget Widget {
- get { return browser_shell; }
- }
-
- public ISource Source {
- get { return source; }
- }
+ return new StoreWebBrowserShell (new StoreView ());
}
}
}
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs
index bd61ddf..45cb22b 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs
@@ -3,6 +3,7 @@
//
// Author:
// Aaron Bockover <abockover novell com>
+// Gabriel Burt <gburt novell com>
//
// Copyright 2010 Novell, Inc.
//
@@ -34,23 +35,22 @@ using Hyena.Downloader;
using Banshee.Base;
using Banshee.IO;
using Banshee.WebBrowser;
+using Banshee.WebSource;
using Banshee.AmazonMp3;
namespace Banshee.AmazonMp3.Store
{
- public class StoreView : OssiferWebView
+ public class StoreView : WebView
{
- private string fixup_javascript;
- private bool fixup_javascript_fetched;
+ public event EventHandler SignInChanged;
public bool IsSignedIn { get; private set; }
- public bool IsReady { get; private set; }
-
- public event EventHandler SignInChanged;
- public event EventHandler Ready;
public StoreView ()
{
+ CanSearch = true;
+ FixupJavascriptUrl = "http://amz-proxy.banshee.fm/amz-fixups.js";
+
OssiferSession.CookieChanged += (o, n) => CheckSignIn ();
// Ensure that Amazon knows a valid downloader is available,
@@ -64,31 +64,16 @@ namespace Banshee.AmazonMp3.Store
FullReload ();
}
- protected override void OnLoadStatusChanged (OssiferLoadStatus status)
- {
- if ((status == OssiferLoadStatus.FirstVisuallyNonEmptyLayout ||
- status == OssiferLoadStatus.Finished) && Uri != "about:blank") {
- // Hide "Install Flash" messages on Amazon since we
- // play content previews natively in Banshee
- if (fixup_javascript != null) {
- ExecuteScript (fixup_javascript);
- }
- }
-
- base.OnLoadStatusChanged (status);
- }
-
protected override OssiferNavigationResponse OnMimeTypePolicyDecisionRequested (string mimetype)
{
// We only explicitly accept (render) text/html types, and only
// download audio/x-amzxml - everything else is ignored.
switch (mimetype) {
- case "text/html": return OssiferNavigationResponse.Accept;
case "audio/x-mpegurl":
- case "audio/x-amzxml": return OssiferNavigationResponse.Download;
+ case "audio/x-amzxml":
+ return OssiferNavigationResponse.Download;
default:
- Log.Debug ("OssiferWebView: ignoring mime type", mimetype);
- return OssiferNavigationResponse.Ignore;
+ return base.OnMimeTypePolicyDecisionRequested (mimetype);
}
}
@@ -126,12 +111,12 @@ namespace Banshee.AmazonMp3.Store
}
}
- public void GoHome ()
+ public override void GoHome ()
{
LoadUri ("http://amz-proxy.banshee.fm/do/home/");
}
- public void GoSearch (string query)
+ public override void GoSearch (string query)
{
LoadUri (new Uri ("http://amz-proxy.banshee.fm/do/search/" + query).AbsoluteUri);
}
@@ -146,56 +131,6 @@ namespace Banshee.AmazonMp3.Store
FullReload ();
}
- public void FullReload ()
- {
- // This is an HTML5 Canvas/JS spinner icon. It is awesome
- // and renders immediately, going away when the store loads.
- LoadString (AssemblyResource.GetFileContents ("loading.html"),
- "text/html", "UTF-8", null);
-
- // Here we download and save for later injection some JavaScript
- // to fix-up the Amazon pages. We don't store this locally since
- // it may need to be updated if Amazon's page structure changes.
- // We're mainly concerned about hiding the "You don't have Flash"
- // messages, since we do the streaming of previews natively.
- if (!fixup_javascript_fetched) {
- fixup_javascript_fetched = true;
- new Hyena.Downloader.HttpStringDownloader () {
- Uri = new Uri ("http://amz-proxy.banshee.fm/amz-fixups.js"),
- Finished = (d) => {
- if (d.State.Success) {
- fixup_javascript = d.Content;
- }
- LoadHome ();
- },
- AcceptContentTypes = new [] { "text/javascript" }
- }.Start ();
- } else {
- LoadHome ();
- }
- }
-
- private void LoadHome ()
- {
- // We defer this to another main loop iteration, otherwise
- // our load placeholder document will never be rendered.
- GLib.Idle.Add (delegate {
- GoHome ();
-
- // Emit the Ready event once we are first allowed
- // to load the home page (ensures we've downloaded
- // the fixup javascript, etc.).
- if (!IsReady) {
- IsReady = true;
- var handler = Ready;
- if (handler != null) {
- handler (this, EventArgs.Empty);
- }
- }
- return false;
- });
- }
-
private void CheckSignIn ()
{
var signed_in = OssiferSession.GetCookie ("at-main", ".amazon.com", "/") != null;
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs
new file mode 100644
index 0000000..0218d23
--- /dev/null
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs
@@ -0,0 +1,63 @@
+//
+// StoreWebBrowserShell.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+//
+// Copyright 2010 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 Gtk;
+using Mono.Unix;
+
+using Banshee.WebBrowser;
+
+namespace Banshee.AmazonMp3.Store
+{
+ public class StoreWebBrowserShell : Banshee.WebSource.WebBrowserShell
+ {
+ private StoreView store_view;
+ private Button sign_out_button = new Button (Catalog.GetString ("Sign out of Amazon")) { Relief = ReliefStyle.None };
+
+ public StoreWebBrowserShell (StoreView store_view) : base (Catalog.GetString ("Amazon MP3 Store"), store_view)
+ {
+ this.store_view = store_view;
+ sign_out_button.Clicked += (o, e) => store_view.SignOut ();
+
+ Attach (sign_out_button, 2, 3, 0, 1,
+ AttachOptions.Shrink,
+ AttachOptions.Shrink,
+ 0, 0);
+
+ SearchEntry.EmptyMessage = String.Format (Catalog.GetString ("Search the Amazon MP3 Store"));
+
+ store_view.SignInChanged += (o, e) => UpdateSignInButton ();
+ ShowAll ();
+ UpdateSignInButton ();
+ }
+
+ private void UpdateSignInButton ()
+ {
+ sign_out_button.Visible = store_view.IsSignedIn;
+ }
+ }
+}
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am b/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am
index 109b107..ec43ba5 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am
@@ -6,11 +6,10 @@ INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
SOURCES = \
Banshee.AmazonMp3.Store/StoreSource.cs \
Banshee.AmazonMp3.Store/StoreView.cs \
- Banshee.AmazonMp3.Store/WebBrowserShell.cs
+ Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs
RESOURCES = \
- Banshee.AmazonMp3.Store.addin.xml \
- Resources/loading.html
+ Banshee.AmazonMp3.Store.addin.xml
if HAVE_LIBWEBKIT
include $(top_srcdir)/build/build.mk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]