3 # This file is part of Jamaendo.
4 # Copyright (c) 2010 Kristoffer Gronlund
6 # Jamaendo is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # Jamaendo is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Jamaendo. If not, see <http://www.gnu.org/licenses/>.
19 # Player code heavily based on http://thpinfo.com/2008/panucci/:
20 # A resuming media player for Podcasts and Audiobooks
21 # Copyright (c) 2008-05-26 Thomas Perl <thpinfo.com>
22 # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
28 import helldon as hildon
30 from playerwindow import open_playerwindow
31 from showartist import ShowArtist
32 from showalbum import ShowAlbum
33 from albumlist import MusicList
34 from fetcher import Fetcher
36 class SearchWindow(hildon.StackableWindow):
38 hildon.StackableWindow.__init__(self)
39 self.set_title("Search")
42 vbox = gtk.VBox(False, 0)
45 self.connect('destroy', self.on_destroy)
48 self.panarea = hildon.PannableArea()
49 self.musiclist = MusicList()
50 self.musiclist.loading_message = "Nothing found yet"
51 self.musiclist.empty_message = "No matching results"
52 self.musiclist.connect('row-activated', self.row_activated)
53 self.panarea.add(self.musiclist)
54 vbox.pack_start(self.panarea, True, True, 0)
57 # Create selector for search mode
58 self.mode_selector = hildon.TouchSelector(text=True)
60 self.mode_selector.append_text("Artists")
61 self.mode_selector.append_text("Albums")
62 self.mode_selector.append_text("Tracks")
63 self.mode = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT,
64 hildon.BUTTON_ARRANGEMENT_VERTICAL)
65 self.mode.set_title("Search for")
66 self.mode.set_selector(self.mode_selector)
67 self.mode_selector.connect("changed", self.mode_changed)
68 #vbox.pack_start(self.mode, False)
69 self.mode.set_active(1)
73 hbox = gtk.HBox(False, 0)
74 self.entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
75 self.entry.set_placeholder("Search")
76 self.entry.connect('activate', self.on_search)
77 btn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
79 btn.connect('clicked', self.on_search)
80 hbox.pack_start(self.mode, False)
81 hbox.pack_start(self.entry, True, True, 0)
82 hbox.pack_start(btn, False)
83 vbox.pack_start(hbox, False)
88 def create_menu(self):
90 from playerwindow import open_playerwindow
92 self.menu = hildon.AppMenu()
93 player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
94 player.set_label("Open player")
95 player.connect("clicked", on_player)
96 self.menu.append(player)
98 self.set_app_menu(self.menu)
100 def on_destroy(self, wnd):
105 def mode_changed(self, selector, user_data):
107 #current_selection = selector.get_current_text()
109 def on_search(self, w):
110 mode = self.mode.get_active()
111 txt = self.entry.get_text()
112 self.musiclist.set_loading(False)
113 self.musiclist.get_model().clear()
121 itemgen = lambda: jamaendo.search_artists(query=txt)
123 itemgen = lambda: jamaendo.search_albums(query=txt)
125 itemgen = lambda: jamaendo.search_tracks(query=txt)
129 self.fetcher = Fetcher(itemgen, self,
130 on_item = self.on_add_result,
131 on_ok = self.on_add_ok,
132 on_fail = self.on_add_fail)
137 items = jamaendo.search_artists(query=txt)
139 items = jamaendo.search_albums(query=txt)
141 items = jamaendo.search_tracks(query=txt)
144 self.idmap[item.ID] = item
146 self.musiclist.add_items(items)
147 except jamaendo.JamaendoAPIException:
148 # nothing found, force redraw
149 self.musiclist.queue_draw()
152 def on_add_result(self, wnd, item):
154 self.musiclist.add_items([item])
155 self.idmap[item.ID] = item
157 def on_add_ok(self, wnd):
162 def on_add_fail(self, wnd, error):
164 self.musiclist.queue_draw()
168 def row_activated(self, treeview, path, view_column):
169 _id = self.musiclist.get_item_id(path)
170 item = self.idmap[_id]
173 def open_item(self, item):
174 if isinstance(item, jamaendo.Album):
175 wnd = ShowAlbum(item)
177 elif isinstance(item, jamaendo.Artist):
178 wnd = ShowArtist(item)
180 elif isinstance(item, jamaendo.Track):
181 wnd = open_playerwindow()
182 wnd.play_tracks([item])