[PATCH 11/17] grilo-test-ui.py: Implemented browse



---
 tools/python/grilo-test-ui.py |  104 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 96 insertions(+), 8 deletions(-)

diff --git a/tools/python/grilo-test-ui.py b/tools/python/grilo-test-ui.py
index 0c1918a..36b7987 100644
--- a/tools/python/grilo-test-ui.py
+++ b/tools/python/grilo-test-ui.py
@@ -164,8 +164,28 @@ class MainWindow(Gtk.Window):
     def _source_removed_cb(self, plugin_registry, media_source):
         print media_source.get_name()
 
-    def _browser_activated_cb(self, *args):
-        pass
+    def _browser_activated_cb(self, tree_view, path, column, data=None):
+        model = tree_view.get_model()
+        success, iter = model.get_iter(path)
+        if success:
+            source = model.get_value(iter, BrowserListStore.SOURCE_COLUMN)
+            content = model.get_value(iter, BrowserListStore.CONTENT_COLUMN)
+            type = model.get_value(iter, BrowserListStore.TYPE_COLUMN)
+        else:
+            return
+
+        if type == BrowserListStore.OBJECT_TYPE_MEDIA:
+            return
+        elif type == BrowserListStore.OBJECT_TYPE_SOURCE:
+            container = None
+        elif content:
+            container = content
+        else:
+            container = None
+
+        self._browse_history_push(self._ui_state.cur_source,
+                                  self._ui_state.cur_container)
+        self.browse(source, container)
 
     def _browser_row_selected_cb(self, *args):
         pass
@@ -230,23 +250,91 @@ class MainWindow(Gtk.Window):
                 self._operation_finished()
                 print ('**** search finished %(id)s ****' % {'id':operation_id})
 
+    def _browse_cb(self, source, operation_id, media, remaining, data, error):
+        state = data
+        state.count += 1
+
+        if media:
+            icon = None #get_icon_for_media(media)
+            name = media.get_title()
+            if isinstance(media, Grl.MediaBox):
+                childcount = media.get_childcount()
+                type = BrowserListStore.OBJECT_TYPE_CONTAINER
+                if childcount == Grl.METADATA_KEY_CHILDCOUNT_UNKNOWN:
+                    childcount = '?'
+                name = ('%(name)s (%(count)s)' % {'name':name,
+                                                  'count':childcount})
+            else:
+                type = BrowserListStore.OBJECT_TYPE_MEDIA
+
+            model = self._browser_window.get_browser().get_model()
+            model.append((source, media, type, name, icon))
+        if remaining == 0:
+            if self._ui_state.cur_op_id == operation_id and \
+               media:
+                state.offset += state.count
+                if state.count >= self.BROWSE_CHUNK_SIZE and \
+                   state.offset < self.BROWSE_MAX_COUNT:
+                    state.count = 0
+                    next_browse_id = source.browse(self._ui_state.cur_container,
+                                                   self.BROWSE_KEYS,
+                                                   state.offset,
+                                                   self.BROWSE_CHUNK_SIZE,
+                                                   self.BROWSE_FLAGS,
+                                                   self._browse_cb,
+                                                   state)
+                    self._operation_started(source, next_browse_id, False)
+            else:
+                self._operation_finished()
+                print ('**** browse finished (%(id)s) ****' % {'id':operation_id})
+
+    def _browse_history_push (self, source, media):
+        self._ui_state.source_stack.append(source)
+        self._ui_state.container_stack.append(media)
+
     def _cancel_current_operation(self):
         if self._ui_state.op_ongoing:
             if not self._ui_state.multiple:
-                self._ui_state.op_source.cancel(self._ui_state.cur_op_id)
+                self._ui_state.cur_op_source.cancel(self._ui_state.cur_op_id)
             else:
                 Grl.multiple_cancel(self._ui_state.cur_op_id)
             self._ui_state.op_ongoing = False
 
     def _operation_started(self, source, search_id, multiple):
-        self._ui_state = UIState(op_ongoing=True,
-                                 cur_op_source=source,
-                                 cur_op_id=search_id,
-                                 multiple=multiple)
+        self._ui_state.op_ongoing = True
+        self._ui_state.cur_op_source = source
+        self._ui_state.cur_op_id = search_id
+        self._ui_state.multiple = multiple
 
     def _operation_finished(self):
         self._ui_state.op_ongoing = False
 
+    def _set_cur_browse(self, source, media):
+        self._ui_state.cur_source = source
+        self._ui_state.cur_container = media
+
+    def _set_cur_metadata(self, source, media):
+        self._ui_state.cur_md_source = source
+        self._ui_state.cur_md_media = media
+
+    def browse(self, source, container):
+        if source:
+            self._cancel_current_operation()
+            self._clear_panes()
+            state = OperationState()
+            browse_id = source.browse(container,
+                                      self.BROWSE_KEYS,
+                                      0,
+                                      self.BROWSE_CHUNK_SIZE,
+                                      self.BROWSE_FLAGS,
+                                      self._browse_cb,
+                                      state)
+            self._operation_started(source, browse_id, False)
+        else:
+            self._show_plugins()
+        self._set_cur_browse(source, container)
+        self._set_cur_metadata(None, None)
+
     def search(self, source, text):
         self._cancel_current_operation()
         state = OperationState(text)
@@ -294,7 +382,7 @@ class UIState(object):
         self.last_url = last_url
 
 class OperationState(object):
-    def __init__(self, text, offset=0, count=0):
+    def __init__(self, text=None, offset=0, count=0):
         self.text = text
         self.offset = offset
         self.count = count
-- 
1.7.0.4



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