[PATCH 13/17] grilo-test-ui.py: Added metadata resolution support



---
 tools/python/grilo-test-ui.py |   79 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/tools/python/grilo-test-ui.py b/tools/python/grilo-test-ui.py
index 36b7987..d76f00e 100644
--- a/tools/python/grilo-test-ui.py
+++ b/tools/python/grilo-test-ui.py
@@ -8,10 +8,13 @@ class MainWindow(Gtk.Window):
 
     BROWSE_FLAGS = (Grl.MetadataResolutionFlags) (Grl.MetadataResolutionFlags.FAST_ONLY |
                                                   Grl.MetadataResolutionFlags.IDLE_RELAY)
+    METADATA_FLAGS = (Grl.MetadataResolutionFlags) (Grl.MetadataResolutionFlags.FULL |
+                                                    Grl.MetadataResolutionFlags.IDLE_RELAY)
     BROWSE_CHUNK_SIZE = 100
     BROWSE_MAX_COUNT = 2 * BROWSE_CHUNK_SIZE
 
     BROWSE_KEYS = []
+    METADATA_KEYS = []
 
     def __init__(self):
         super(MainWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL)
@@ -19,21 +22,27 @@ class MainWindow(Gtk.Window):
         self.set_title('Grilo Test UI using introspection')
 
         Grl.init([])
+
         self._ui_state = UIState()
-        self.BROWSE_KEYS = self._lookup_keys()
+        self.BROWSE_KEYS = self._lookup_browse_keys()
+        self.METADATA_KEYS = self._lookup_metadata_keys()
 
         self._setup_ui()
         self._load_plugins()
 
         self.show_all()
 
-    def _lookup_keys(self):
+    def _lookup_browse_keys(self):
         registry = Grl.PluginRegistry.get_default()
         key_id = registry.lookup_metadata_key('id')
         key_title = registry.lookup_metadata_key('title')
         key_childcount = registry.lookup_metadata_key('childcount')
         return [key_id, key_title, key_childcount]
 
+    def _lookup_metadata_keys(self):
+        registry = Grl.PluginRegistry.get_default()
+        return registry.get_metadata_keys()
+
     def _load_plugins(self):
         registry = Grl.PluginRegistry.get_default()
         registry.connect('source-added',
@@ -187,8 +196,34 @@ class MainWindow(Gtk.Window):
                                   self._ui_state.cur_container)
         self.browse(source, container)
 
-    def _browser_row_selected_cb(self, *args):
-        pass
+    def _browser_row_selected_cb(self, tree_view, data=None):
+        path, column = tree_view.get_cursor()
+        model = self._browser_window.get_browser().get_model()
+        success, iter = model.get_iter(path)
+        if not success:
+            return
+        source = model.get_value(iter, BrowserListStore.SOURCE_COLUMN)
+        content = model.get_value(iter, BrowserListStore.CONTENT_COLUMN)
+
+        if source != self._ui_state.cur_md_source or \
+           content != self._ui_state.cur_md_media:
+            self._set_cur_metadata(source, content)
+            self.metadata(source, content)
+
+        if not content and \
+           source.supported_operations() & Grl.SupportedOps.STORE:
+            self._store_btn.set_sensitive(True)
+        elif content and isinstance(content, Grl.MediaBox) and \
+             source.supported_operations() & Grl.SupportedOps.STORE_PARENT:
+            self._store_btn.set_sensitive(True)
+        else:
+            self._store_btn.set_sensitive(False)
+
+        if content and \
+           source.supported_operations() & Grl.SupportedOps.REMOVE:
+            self._remove_btn.set_sensitive(True)
+        else:
+            self._remove_btn.set_sensitive(False)
 
     def _show_btn_clicked_cb(self, *args):
         pass
@@ -288,6 +323,31 @@ class MainWindow(Gtk.Window):
                 self._operation_finished()
                 print ('**** browse finished (%(id)s) ****' % {'id':operation_id})
 
+    def _metadata_cb(self, source, media, data, error):
+        if media != self._ui_state.cur_md_media:
+            return
+
+        metadata_model = MetadataListStore()
+        self._contents_window.get_metadata().set_model(metadata_model)
+
+        if media:
+            keys = media.get_keys()
+            for key in keys:
+                value = media.get(key)
+                desc = Grl.metadata_key_get_desc(key)
+                metadata_model.append((desc, value))
+                print ('%(keyname)s: %(keyvalue)s' % {'keyname':desc,
+                                                      'keyvalue':value})
+
+            if (isinstance(media, Grl.MediaAudio) or \
+                isinstance(media, Grl.MediaVideo) or \
+                isinstance(media, Grl.MediaImage)):
+                self._ui_state.last_url = media.get_url()
+                if self._ui_state.last_url:
+                    self._show_btn.set_sensitive(True)
+                else:
+                    self._show_btn.set_sensitive(False)
+
     def _browse_history_push (self, source, media):
         self._ui_state.source_stack.append(source)
         self._ui_state.container_stack.append(media)
@@ -317,6 +377,17 @@ class MainWindow(Gtk.Window):
         self._ui_state.cur_md_source = source
         self._ui_state.cur_md_media = media
 
+    def metadata(self, source, media):
+        if source:
+            if source.supported_operations() & Grl.SupportedOps.METADATA:
+                source.metadata(media,
+                                self.METADATA_KEYS,
+                                self.METADATA_FLAGS,
+                                self._metadata_cb,
+                                None)
+            else:
+                self._metadata_cb(source, media, None, None)
+
     def browse(self, source, container):
         if source:
             self._cancel_current_operation()
-- 
1.7.0.4



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