summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-12-25 00:23:02 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-12-25 00:23:02 +0800
commite20fe659302ac3414282ef0f717ffbb7be5e5417 (patch)
treebd847508315ab87cb28f0b3034603fdf8852bcc5
parentf9a4ec5574d2079898a9566e47a658280f8661fb (diff)
totem: only download a page at a time
-rw-r--r--totem/plugin/ppstream.py114
-rw-r--r--totem/plugin/ppstream.ui6
2 files changed, 64 insertions, 56 deletions
diff --git a/totem/plugin/ppstream.py b/totem/plugin/ppstream.py
index e53b010..554c865 100644
--- a/totem/plugin/ppstream.py
+++ b/totem/plugin/ppstream.py
@@ -426,6 +426,7 @@ class PPStream (totem.Plugin):
self.setup_categories ()
self.setup_films ()
self.setup_files ()
+ self.setup_page_ui ()
self.setup_config_dialog ()
self.vbox = self.builder.get_object ("pps_vbox")
@@ -542,7 +543,7 @@ class PPStream (totem.Plugin):
### fetch next subclass
self.fetch_next_subclass (True)
- def threaded_parse_films (self, res, clsid, subclsid, count):
+ def threaded_parse_films (self, res, clsid, subclsid, page, count):
cls, subcls = self.get_class_pair (clsid, subclsid)
if not subcls:
subcls = cls
@@ -551,7 +552,7 @@ class PPStream (totem.Plugin):
subcls.parsing_films = False
return None
try:
- result = self.ppslist.parseMovieList(subcls, res, subcls.page)
+ result = self.ppslist.parseMovieList(subcls, res, page)
except Exception, e:
print "Couldn't parse film list", clsid, subclsid, e
result = None
@@ -559,7 +560,7 @@ class PPStream (totem.Plugin):
subcls.parsing_films = False
return result
- def on_films_fetched (self, res, clsid, subclsid, count, new = True):
+ def on_films_fetched (self, res, clsid, subclsid, page, count, new = True):
if self.films_count != count:
return
@@ -568,40 +569,28 @@ class PPStream (totem.Plugin):
if not subcls:
subcls = cls
- if not hasattr(subcls, 'last_films'):
- subcls.last_films = False
+ if not hasattr(subcls, 'parsing_films'):
subcls.parsing_films = False
- if res == subcls.last_films:
- subcls.fetching_films = False
- subcls.films_fetched = True
- return
-
if res is None:
subcls.fetching_films = False
return
- subcls.last_films = res
-
- if new:
- #self.store_films_to_disk (clsid, subclsid, res)
- pass
-
- ### If the xml is larger then 4k, parse it in another thread.
+ ### If the size of content is larger then 4k, parse it in another thread.
### Blocking the main thread is bad.
if res and len(res) > 1024 * 2:
subcls.parsing_films = True
process = ProcessThread (res, self.threaded_parse_films,
self.add_parsed_films,
- clsid, subclsid, count)
+ clsid, subclsid, page, count)
process.start ()
self.update_progress_bar ()
return
- result = self.threaded_parse_films (res, clsid, subclsid, count)
- self.add_parsed_films (result, clsid, subclsid,count)
+ result = self.threaded_parse_films (res, clsid, subclsid, page, count)
+ self.add_parsed_films (result, clsid, subclsid, page, count)
- def add_parsed_films (self, result, clsid, subclsid, count):
+ def add_parsed_films (self, result, clsid, subclsid, page, count):
if self.films_count != count:
return
cls, subcls = self.get_class_pair (clsid, subclsid)
@@ -609,23 +598,15 @@ class PPStream (totem.Plugin):
subcls = cls
if result:
- subcls.addMovies(result, subcls.page)
+ subcls.addMovies(result, page)
- if len (subcls.getPages()) >= subcls.max_page:
- finished = True
- subcls.fetching_films = False
- subcls.films_fetched = True
- else:
- finished = False
+ subcls.fetching_films = False
+ subcls.films_fetched = True
if result:
## for film in result:
## print film
self.fill_films (result, clsid, subclsid)
- if not finished:
- self.fetch_films (clsid, subclsid)
- else:
- subcls.fetching_films = False
def parse_class (self, res):
self.ppslist.updateClasses(self.ppslist.parseClasses(res))
@@ -800,39 +781,27 @@ class PPStream (totem.Plugin):
except OSError, e:
print 'Failed to remove ', f, e
- def download_films (self, callback, clsid, subclsid, count):
- ## if self.load_films_from_disk (url, callback, clsid, subclsid,
- ## count):
- ## return
+ def download_films (self, callback, clsid, subclsid, page, count):
cls, subcls = self.get_class_pair (clsid, subclsid)
subcls = cls
thread = ProcessThread (None, self.__fetch_films,
callback, clsid, subclsid,
- count)
+ page, count)
thread.start()
- def __fetch_films(self, dummy, clsid, subclsid, *args):
+ def __fetch_films(self, dummy, clsid, subclsid, page, *args):
cls, subcls = self.get_class_pair (clsid, subclsid)
subcls = cls
- if not len (subcls.getPages()):
- subcls.page = 0
- return self.ppslist.fetchMovieList(cls, subcls.page)
+ return self.ppslist.fetchMovieList(cls, page)
def fetch_films (self, clsid, subclsid):
cls, subcls = self.get_class_pair (clsid, subclsid)
subcls = cls
- if len (subcls.getPages()) == subcls.max_page:
- return
- if not len (subcls.getPages()):
- subcls.page = 0
- elif subcls.fetching_films:
- subcls.page += 1
subcls.fetching_films = True
-
#print subcls, subcls.page
self.download_films (self.on_films_fetched, clsid, subclsid,
- self.films_count)
+ self.films_page, self.films_count)
def on_cat_treeview_row_activated(self, treeview, path, view_column, data=None):
model, rows = treeview.get_selection ().get_selected_rows ()
@@ -1305,6 +1274,7 @@ class PPStream (totem.Plugin):
cls, subcls = self.get_class_pair (*self.films_ids)
subcls = cls
subcls.fetching_films = False
+ self.films_page = 0
self.films_ids = (clsid, subclsid)
@@ -1325,11 +1295,8 @@ class PPStream (totem.Plugin):
### fill all loaded films
self.fill_all_films (clsid, subclsid)
- if not hasattr(subcls, 'films_fetched'):
- subcls.films_fetched = False
+ if not len(subcls.getPage(self.films_page)):
subcls.fetching_films = False
- if subcls.films_fetched:
- return
### load remaining films
if not subcls.fetching_films:
@@ -1355,6 +1322,7 @@ class PPStream (totem.Plugin):
self.entry[treeview_name] = None
self.films_ids = ()
self.films_count = 0
+ self.films_page = 0
"""This is done here rather than in the UI file,
because UI files parsed in C and GObjects created in
@@ -1609,6 +1577,45 @@ class PPStream (totem.Plugin):
model.set(iter, 6, url)
self.add_to_favorites_button.set_sensitive(all_files_fetched)
+ def on_first_page_clicked(self, *args):
+ pass
+
+ def on_prev_page_clicked(self, *args):
+ pass
+
+ def on_next_page_clicked(self, *args):
+ pass
+
+ def on_last_page_clicked(self, *args):
+ pass
+
+ def on_goto_page_clicked(self, *args):
+ pass
+
+ def set_page_max(self, max_page):
+ adjustment = self.which_page_button.get_adjustment()
+ adjustment.set_upper(max_page)
+
+ def set_current_page(self, current):
+ adjustment = self.which_page_button.get_adjustment()
+ adjustment.set_value(current)
+
+ def setup_page_ui (self):
+ self.page_hbox = self.builder.get_object('pps_page_hbox')
+ self.first_page_button = self.builder.get_object('pps_first_page_button')
+ self.prev_page_button = self.builder.get_object('pps_prev_page_button')
+ self.next_page_button = self.builder.get_object('pps_next_page_button')
+ self.last_page_button = self.builder.get_object('pps_last_page_button')
+ self.goto_page_button = self.builder.get_object('pps_goto_page_button')
+ self.which_page_button = self.builder.get_object('pps_which_page_button')
+
+ self.page_hbox.set_sensitive(False)
+
+ adjustment = self.which_page_button.get_adjustment()
+ adjustment.set_lower(1)
+ adjustment.set_upper(1)
+ adjustment.set_value(1)
+
def on_notebook_page_changed (self, notebook, notebook_page, page_num):
self.current_treeview_name = self.notebook_pages[page_num]
self.add_to_favorites_button.set_sensitive (False)
@@ -1624,6 +1631,7 @@ class PPStream (totem.Plugin):
else:
self.refresh_button.set_sensitive (True)
self.add_to_favorites_button.set_sensitive (True)
+ self.page_hbox.set_sensitive (True)
self.update_progress_bar ()
else:
self.refresh_button.set_sensitive (True)
diff --git a/totem/plugin/ppstream.ui b/totem/plugin/ppstream.ui
index cbfbfee..9f3bf71 100644
--- a/totem/plugin/ppstream.ui
+++ b/totem/plugin/ppstream.ui
@@ -199,7 +199,7 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox2">
+ <object class="GtkHBox" id="pps_page_hbox">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="pps_first_page_button">
@@ -270,7 +270,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="pps_go_to_page_button">
+ <object class="GtkButton" id="pps_goto_page_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -287,7 +287,7 @@
</packing>
</child>
<child>
- <object class="GtkSpinButton" id="pps_page_spinbutton">
+ <object class="GtkSpinButton" id="pps_which_page_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>