[gnome-music] A first ugly attempt to search in remote sources
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] A first ugly attempt to search in remote sources
- Date: Mon, 12 May 2014 08:45:52 +0000 (UTC)
commit cd9c795832e97fceea6d6714dac5aa392a1d2081
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Tue Oct 8 14:40:46 2013 +0200
A first ugly attempt to search in remote sources
gnomemusic/grilo.py | 21 +++++----
gnomemusic/searchbar.py | 122 ++++++++++++++++++++++++++---------------------
gnomemusic/view.py | 2 +
3 files changed, 82 insertions(+), 63 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 7402f7f..8a91517 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -133,11 +133,15 @@ class Grilo(GObject.GObject):
self.sources[id] = mediaSource
self.tracker = mediaSource
+ self.search_source = mediaSource
if self.tracker is not None:
self.emit('ready')
self.tracker.notify_change_start()
self.tracker.connect('content-changed', self._on_content_changed)
+ elif (mediaSource.supported_operations() & Grl.SupportedOps.SEARCH)\
+ and (mediaSource.get_supported_media() & Grl.MediaType.AUDIO):
+ self.sources[id] = mediaSource
except Exception as e:
logger.debug("Source %s: exception %s" % (id, e))
@@ -173,16 +177,15 @@ class Grilo(GObject.GObject):
self.tracker.query(query, self.METADATA_KEYS, options, _callback, None)
@log
- def _search_callback(self):
- pass
-
- @log
- def search(self, q):
+ def search(self, q, callback):
options = self.options.copy()
- for source in self.sources:
- logger.debug(source.get_name() + ' - ' + q)
- source.search(q, [Grl.METADATA_KEY_ID], 0, 10,
- options, self._search_callback, source)
+
+ @log
+ def _search_callback(src, param, item, id, offset, data):
+ if item is not None:
+ #print("%s: %s by %s" % (item.get_url(), item.get_title(), item.get_author()))
+ callback(src, param, item)
+ self.search_source.search(q, [Grl.METADATA_KEY_ID], options, _search_callback, None)
@log
def get_media_from_uri(self, uri, callback):
diff --git a/gnomemusic/searchbar.py b/gnomemusic/searchbar.py
index 8dfea52..6e580ca 100644
--- a/gnomemusic/searchbar.py
+++ b/gnomemusic/searchbar.py
@@ -1,16 +1,78 @@
from gi.repository import Gtk, Gd, GObject, Pango
+from gnomemusic.grilo import grilo
from gnomemusic import log
import logging
logger = logging.getLogger(__name__)
-
class BaseModelColumns():
ID = 0
NAME = 1
HEADING_TEXT = 2
+class BaseManager:
+
+ def __init__(self, id, label, entry):
+ self.id = id
+ self.label = label
+ self.entry = entry
+ self.tag = Gd.TaggedEntryTag()
+ self.tag.manager = self
+ self.values = []
+
+ def fill_in_values(self, model):
+ if self.id == "search":
+ self.values = [
+ ["search_all", "All fields", self.label],
+ ["search_artist", "Artist", ""],
+ ["search_album", "Album", ""],
+ ["search_track", "Track", ""],
+ ]
+ for value in self.values:
+ _iter = model.append()
+ model.set(_iter, [0, 1, 2], value)
+ self.selected_id = self.values[0][BaseModelColumns.ID]
+
+ def get_active(self):
+ return self.selected_id
+
+ def set_active(self, selected_id):
+ selected_value = [x for x in self.values if x[BaseModelColumns.ID] == selected_id]
+ if selected_value != []:
+ selected_value = selected_value[0]
+ self.selected_id = selected_value[BaseModelColumns.ID]
+
+ # If selected values has non-empty HEADING_TEXT then it is a default value
+ # No need to set the tag there
+ if selected_value[BaseModelColumns.HEADING_TEXT] == "":
+ self.entry.add_tag(self.tag)
+ self.tag.set_label(selected_value[BaseModelColumns.NAME])
+ else:
+ self.entry.remove_tag(self.tag)
+
+ def reset_to_default(self):
+ self.set_active(self.values[0][BaseModelColumns.ID])
+
+
+class SourceManager(BaseManager):
+ def fill_in_values(self, model):
+ if self.id == "source":
+ # First one should always be 'Filesystem'
+ src = grilo.sources['grl-filesystem']
+ self.values.append([src.get_id(), src.get_name(), self.label])
+ for key in grilo.sources:
+ source = grilo.sources[key]
+ if source.get_id() == 'grl-filesystem':
+ continue
+ self.values.append([source.get_id(), source.get_name(), ""])
+ super(SourceManager, self).fill_in_values(model)
+
+ def set_active(self, selected_id):
+ super(SourceManager, self).set_active(selected_id)
+ src = grilo.sources[selected_id]
+ grilo.search_source = src
+
class FilterView():
def __init__(self, manager, dropdown):
self.manager = manager
@@ -81,7 +143,7 @@ class DropDown(Gd.Revealer):
self.add(frame)
def initialize_filters(self, searchbar):
- sourcesManager = BaseManager('source', "Sources", searchbar._search_entry)
+ sourcesManager = SourceManager('source', "Sources", searchbar._search_entry)
sourcesFilter = FilterView(sourcesManager, self)
self._grid.add(sourcesFilter.view)
@@ -95,57 +157,6 @@ class DropDown(Gd.Revealer):
manager.set_active(id)
-class BaseManager:
-
- def __init__(self, id, label, entry):
- self.id = id
- self.label = label
- self.entry = entry
- self.tag = Gd.TaggedEntryTag()
- self.tag.manager = self
-
- def fill_in_values(self, model):
- self.values = []
- if self.id == "source":
- self.values = [
- ["sources_local", "Local", self.label],
- ["sources_upnp", "UPnP", ""],
- ["sources_grooveshark", "GrooveShark", ""],
- ["sources_soundcloud", "SoundCloud", ""],
- ]
- if self.id == "search":
- self.values = [
- ["search_all", "All fields", self.label],
- ["search_artist", "Artist", ""],
- ["search_album", "Album", ""],
- ["search_track", "Track", ""],
- ]
- for value in self.values:
- _iter = model.append()
- model.set(_iter, [0, 1, 2], value)
- self.selected_id = self.values[0][BaseModelColumns.ID]
-
- def get_active(self):
- return self.selected_id
-
- def set_active(self, selected_id):
- selected_value = [x for x in self.values if x[BaseModelColumns.ID] == selected_id]
- if selected_value != []:
- selected_value = selected_value[0]
- self.selected_id = selected_value[BaseModelColumns.ID]
-
- # If selected values has non-empty HEADING_TEXT then it is a default value
- # No need to set the tag there
- if selected_value[BaseModelColumns.HEADING_TEXT] == "":
- self.entry.add_tag(self.tag)
- self.tag.set_label(selected_value[BaseModelColumns.NAME])
- else:
- self.entry.remove_tag(self.tag)
-
- def reset_to_default(self):
- self.set_active(self.values[0][BaseModelColumns.ID])
-
-
class Searchbar(Gd.Revealer):
@log
@@ -229,7 +240,10 @@ class Searchbar(Gd.Revealer):
def search_entry_changed(self, widget):
self.search_term = self._search_entry.get_text()
if self.view:
- self.view.filter.refilter()
+ self.view._model.clear()
+ grilo.search(self.search_term, self.view._add_item)
+ #if self.view:
+ # self.view.filter.refilter()
@log
def show_bar(self, show):
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index a21aa67..0baf813 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -475,6 +475,8 @@ class Songs(ViewContainer):
artist = item.get_string(Grl.METADATA_KEY_ARTIST)\
or item.get_author()\
or _("Unknown Artist")
+ if item.get_url() is None:
+ return
_iter = self._model.insert_with_valuesv(
-1,
[2, 3, 5, 8, 9, 10],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]