Permalink
Browse files

Load search tag types dynamically from mpd.

  • Loading branch information...
1 parent d2b26de commit 7baed9541a1c5ced26f5a9e7cc89642bb0453dd4 @tsufeki committed Jul 10, 2013
Showing with 163 additions and 101 deletions.
  1. +4 −1 qygmy/browser.py
  2. +65 −13 qygmy/lists.py
  3. +92 −55 qygmy/translations/qygmy_pl.ts
  4. +2 −32 qygmy/ui/browser.ui
View
@@ -24,6 +24,8 @@ def setup_ui(self):
self.ui.plpath.clicked.connect(self.srv.playlists.cd)
self.ui.search_results.setup(self.srv.search)
self.ui.search_button.setDefaultAction(self.ui.search)
+ self.ui.what.setModel(self.srv.search.search_tags)
+ self.ui.what.model().modelReset.connect(lambda: self.ui.what.setCurrentIndex(0))
self.srv.state.changed.connect(self.on_state_changed)
try:
@@ -87,7 +89,8 @@ def on_close_triggered(self):
@Slot()
def on_search_triggered(self):
- self.srv.search.cd((self.ui.what.currentIndex(), self.ui.query.text()))
+ self.srv.search.cd((self.ui.what.itemData(self.ui.what.currentIndex()),
+ self.ui.query.text()))
@Slot()
def on_add_triggered(self, play=False, replace=False):
View
@@ -459,24 +459,76 @@ def setData(self, index, value, role=Qt.EditRole):
return False
-class Search(BrowserList):
+class SearchTags(RelayingConnection, QAbstractListModel):
+
+ def __init__(self, parent):
+ super().__init__(parent)
+ self.tags = []
+ self.retranslate()
+ self.state.changed2.connect(self._update)
+
+ def retranslate(self):
+ self.standard_tags = [
+ ('title', self.tr('Title')),
+ ('artist', self.tr('Artist')),
+ ('album', self.tr('Album')),
+ ('genre', self.tr('Genre')),
+ ('comment', self.tr('Comment')),
+ ('composer', self.tr('Composer')),
+ ('performer', self.tr('Performer')),
+ ('date', self.tr('Date')),
+ ('track', self.tr('Track')),
+ ('disc', self.tr('Disc')),
+ ('name', self.tr('Name')),
+ ]
+ self.special_tags = [
+ ('any', self.tr('Any')),
+ ('file', self.tr('File name')),
+ ]
- search_tags = [
- 'any',
- 'title',
- 'artist',
- 'album',
- 'comment',
- 'file',
- ]
+ @mpd_cmd(fallback=[])
+ def _tag_types(self):
+ return (t.lower() for t in self.conn.tagtypes())
+
+ def _update(self, newstate, oldstate):
+ if newstate != 'disconnect' and oldstate == 'disconnect':
+ self.beginResetModel()
+ self.tags = []
+ tags = set(self._tag_types())
+ for t in self.special_tags:
+ tags.discard(t[0])
+ self.tags.append(self.special_tags[0])
+ for t in self.standard_tags:
+ if t[0] in tags:
+ self.tags.append(t)
+ tags.discard(t[0])
+ self.tags.append(self.special_tags[1])
+ for t in sorted(tags):
+ if not t.startswith('musicbrainz_'):
+ self.tags.append((t, t))
+ self.endResetModel()
+
+ def rowCount(self, parent=None):
+ return len(self.tags)
+
+ def data(self, index, role=Qt.DisplayRole):
+ i = index.row()
+ if 0 <= i < self.rowCount():
+ if role == Qt.DisplayRole:
+ return self.tags[i][1]
+ elif role == Qt.UserRole:
+ return self.tags[i][0]
+
+
+class Search(BrowserList):
def __init__(self, parent):
- super().__init__(parent, (0, ''))
+ super().__init__(parent, ('', ''))
+ self.search_tags = SearchTags(self)
@mpd_cmd(fallback=[])
def ls(self, query):
- if query[1] == '':
+ if query[0] in ('', None) or query[1] in ('', None):
return []
- return sorted(self.conn.search(self.search_tags[query[0]], query[1]),
- key=self.sort_key)
+ return sorted(self.conn.search(query[0], query[1]), key=self.sort_key)
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.0" language="pl">
+<!DOCTYPE TS><TS version="1.1" language="pl">
<context>
<name>Browser</name>
<message>
- <location filename="../browser.py" line="117"/>
+ <location filename="../browser.py" line="122"/>
<source>Details</source>
<translation>Szczegóły</translation>
</message>
@@ -220,7 +219,7 @@
<context>
<name>Playlists</name>
<message>
- <location filename="../lists.py" line="369"/>
+ <location filename="../lists.py" line="370"/>
<source>New playlist</source>
<translation>Nowa lista</translation>
</message>
@@ -259,6 +258,74 @@
</message>
</context>
<context>
+ <name>SearchTags</name>
+ <message>
+ <location filename="../lists.py" line="471"/>
+ <source>Title</source>
+ <translation>Tytuł</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="472"/>
+ <source>Artist</source>
+ <translation>Artysta</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="473"/>
+ <source>Album</source>
+ <translation>Album</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="474"/>
+ <source>Genre</source>
+ <translation>Gatunek</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="475"/>
+ <source>Comment</source>
+ <translation>Komentarz</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="476"/>
+ <source>Composer</source>
+ <translation>Kompozytor</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="477"/>
+ <source>Performer</source>
+ <translation>Wykonawca</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="478"/>
+ <source>Date</source>
+ <translation>Data</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="479"/>
+ <source>Track</source>
+ <translation>Ścieżka</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="480"/>
+ <source>Disc</source>
+ <translation>Dysk</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="484"/>
+ <source>Any</source>
+ <translation>Wszystko</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="485"/>
+ <source>File name</source>
+ <translation>Nazwa pliku</translation>
+ </message>
+ <message>
+ <location filename="../lists.py" line="481"/>
+ <source>Name</source>
+ <translation>Nazwa</translation>
+ </message>
+</context>
+<context>
<name>Settings</name>
<message>
<location filename="../dialogs.py" line="70"/>
@@ -292,137 +359,107 @@
<context>
<name>browser</name>
<message>
- <location filename="../ui/browser.py" line="238"/>
+ <location filename="../ui/browser.py" line="232"/>
<source>Music database</source>
<translation>Baza muzyki</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="239"/>
+ <location filename="../ui/browser.py" line="233"/>
<source>&amp;Database</source>
<translation>&amp;Baza</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="240"/>
+ <location filename="../ui/browser.py" line="234"/>
<source>&amp;Playlists</source>
<translation>&amp;Listy</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="241"/>
+ <location filename="../ui/browser.py" line="235"/>
<source>Tag to search</source>
<translation>Szukany tag</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="242"/>
- <source>Any</source>
- <translation>Wszystko</translation>
- </message>
- <message>
- <location filename="../ui/browser.py" line="243"/>
- <source>Title</source>
- <translation>Tytuł</translation>
- </message>
- <message>
- <location filename="../ui/browser.py" line="244"/>
- <source>Artist</source>
- <translation>Artysta</translation>
- </message>
- <message>
- <location filename="../ui/browser.py" line="245"/>
- <source>Album</source>
- <translation>Album</translation>
- </message>
- <message>
- <location filename="../ui/browser.py" line="246"/>
- <source>Comment</source>
- <translation>Komentarz</translation>
- </message>
- <message>
- <location filename="../ui/browser.py" line="247"/>
- <source>File name</source>
- <translation>Nazwa pliku</translation>
- </message>
- <message>
- <location filename="../ui/browser.py" line="248"/>
+ <location filename="../ui/browser.py" line="236"/>
<source>&amp;Search</source>
<translation>&amp;Szukaj</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="249"/>
+ <location filename="../ui/browser.py" line="237"/>
<source>&amp;Add selected</source>
<translation>&amp;Dodaj zaznaczone</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="250"/>
+ <location filename="../ui/browser.py" line="238"/>
<source>Add selected songs to the current playlist</source>
<translation>Dodaj zaznaczone utwory do głównej listy</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="251"/>
+ <location filename="../ui/browser.py" line="239"/>
<source>&amp;Close</source>
<translation>&amp;Zamknij</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="252"/>
+ <location filename="../ui/browser.py" line="240"/>
<source>Close this window</source>
<translation>Zamknij to okno</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="253"/>
+ <location filename="../ui/browser.py" line="241"/>
<source>Ctrl+W</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../ui/browser.py" line="254"/>
+ <location filename="../ui/browser.py" line="242"/>
<source>Search</source>
<translation>Szukaj</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="255"/>
+ <location filename="../ui/browser.py" line="243"/>
<source>&amp;Remove selected</source>
<translation>&amp;Usuń zaznaczone</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="256"/>
+ <location filename="../ui/browser.py" line="244"/>
<source>Del</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../ui/browser.py" line="257"/>
+ <location filename="../ui/browser.py" line="245"/>
<source>Add selected and &amp;play</source>
<translation>Dodaj zaznaczone i &amp;odtwarzaj</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="258"/>
+ <location filename="../ui/browser.py" line="246"/>
<source>Shift+Return</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../ui/browser.py" line="259"/>
+ <location filename="../ui/browser.py" line="247"/>
<source>Song &amp;details...</source>
<translation>&amp;Szczegóły...</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="260"/>
+ <location filename="../ui/browser.py" line="248"/>
<source>Ctrl+I</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../ui/browser.py" line="261"/>
+ <location filename="../ui/browser.py" line="249"/>
<source>Re&amp;name</source>
<translation>Zmień &amp;nazwę</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="262"/>
+ <location filename="../ui/browser.py" line="250"/>
<source>F2</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../ui/browser.py" line="263"/>
+ <location filename="../ui/browser.py" line="251"/>
<source>R&amp;eplace the current playlist</source>
<translation>Za&amp;stąp główną listę</translation>
</message>
<message>
- <location filename="../ui/browser.py" line="264"/>
+ <location filename="../ui/browser.py" line="252"/>
<source>Rep&amp;lace and play</source>
<translation>Zas&amp;tąp i odtwarzaj</translation>
</message>
Oops, something went wrong.

0 comments on commit 7baed95

Please sign in to comment.