[banshee: 46/61] [InternetArchive] Fix search paging implementation



commit 6e2d072097dac51173172eade385b9fbb80f267c
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Tue Oct 13 18:33:09 2009 -0700

    [InternetArchive] Fix search paging implementation
    
    The prior paging code wasn't actually passing IA the page we want.
    Turns out they don't yet accept such a parameter.  But I've filed a
    patch with them, so hopefully they soon will.

 .../Banshee.InternetArchive/SearchSource.cs        |   17 +++++++++++++----
 .../InternetArchive/Search.cs                      |    2 ++
 2 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
index bafa503..524bebc 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
@@ -113,20 +113,26 @@ namespace Banshee.InternetArchive
         public void Reload ()
         {
             model.Clear ();
-            ThreadAssist.SpawnFromMain (ThreadedFetch);
+            ThreadAssist.SpawnFromMain (delegate {
+                ThreadedFetch (0);
+            });
         }
 
         public void FetchMore ()
         {
-            ThreadAssist.SpawnFromMain (ThreadedFetch);
+            ThreadAssist.SpawnFromMain (delegate {
+                ThreadedFetch (search.Page + 1);
+            });
         }
 
-        private void ThreadedFetch ()
+        private void ThreadedFetch (int page)
         {
             bool success = false;
             total_results = 0;
             status_text = "";
             Exception err = null;
+            int old_page = search.Page;
+            search.Page = page;
 
             ThreadAssist.ProxyToMain (delegate {
                 SetStatus (Catalog.GetString ("Searching the Internet Archive"), false, true, "gtk-find");
@@ -175,11 +181,14 @@ namespace Banshee.InternetArchive
                     );
                 }
             } else {
+                search.Page = old_page;
                 ThreadAssist.ProxyToMain (delegate {
                     var web_e = err as System.Net.WebException;
                     if (web_e != null && web_e.Status == System.Net.WebExceptionStatus.Timeout) {
                         SetStatus (Catalog.GetString ("Timed out searching the Internet Archive"), true);
-                        CurrentMessage.AddAction (new MessageAction (Catalog.GetString ("Try Again"), (o, a) => Reload ()));
+                        CurrentMessage.AddAction (new MessageAction (Catalog.GetString ("Try Again"), (o, a) => {
+                            if (page == 0) Reload (); else FetchMore ();
+                        }));
                     } else {
                         SetStatus (Catalog.GetString ("Error searching the Internet Archive"), true);
                     }
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/Search.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/Search.cs
index b420893..a843e3b 100644
--- a/src/Extensions/Banshee.InternetArchive/InternetArchive/Search.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/Search.cs
@@ -41,6 +41,7 @@ namespace InternetArchive
         public IList<Field>  ReturnFields { get { return result_fields; } }
         public IList<Sort>   Sorts { get { return sorts; } }
         public string Query { get; set; }
+        public int Page { get; set; }
 
         static Search () {
             UserAgent = "InternetArchiveSharp";
@@ -87,6 +88,7 @@ namespace InternetArchive
             }
 
             sb.AppendFormat ("&rows={0}", NumResults);
+            sb.AppendFormat ("&page={0}", Page);
             sb.AppendFormat ("&fmt={0}", "json");
             sb.Append ("&xmlsearch=Search");
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]