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
35 class SearchWindow(hildon.StackableWindow):
37 hildon.StackableWindow.__init__(self)
38 self.set_title("Search")
41 vbox = gtk.VBox(False, 0)
45 self.panarea = hildon.PannableArea()
46 self.musiclist = MusicList()
47 self.musiclist.loading_message = "Nothing found yet"
48 self.musiclist.empty_message = "No matching results"
49 self.musiclist.connect('row-activated', self.row_activated)
50 self.panarea.add(self.musiclist)
51 vbox.pack_start(self.panarea, True, True, 0)
54 # Create selector for search mode
55 self.mode_selector = hildon.TouchSelector(text=True)
57 self.mode_selector.append_text("Artists")
58 self.mode_selector.append_text("Albums")
59 self.mode_selector.append_text("Tracks")
60 self.mode = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT,
61 hildon.BUTTON_ARRANGEMENT_VERTICAL)
62 self.mode.set_title("Search for")
63 self.mode.set_selector(self.mode_selector)
64 self.mode_selector.connect("changed", self.mode_changed)
65 #vbox.pack_start(self.mode, False)
66 self.mode.set_active(1)
70 hbox = gtk.HBox(False, 0)
71 self.entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
72 self.entry.set_placeholder("Search")
73 self.entry.connect('activate', self.on_search)
74 btn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
76 btn.connect('clicked', self.on_search)
77 hbox.pack_start(self.mode, False)
78 hbox.pack_start(self.entry, True, True, 0)
79 hbox.pack_start(btn, False)
80 vbox.pack_start(hbox, False)
85 def create_menu(self):
87 from playerwindow import open_playerwindow
89 self.menu = hildon.AppMenu()
90 player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
91 player.set_label("Open player")
92 player.connect("clicked", on_player)
93 self.menu.append(player)
95 self.set_app_menu(self.menu)
97 def mode_changed(self, selector, user_data):
99 #current_selection = selector.get_current_text()
101 def on_search(self, w):
102 mode = self.mode.get_active()
103 txt = self.entry.get_text()
104 self.musiclist.set_loading(False)
105 self.musiclist.get_model().clear()
109 items = jamaendo.search_artists(query=txt)
111 items = jamaendo.search_albums(query=txt)
113 items = jamaendo.search_tracks(query=txt)
116 self.idmap[item.ID] = item
118 self.musiclist.add_items(items)
119 except jamaendo.JamaendoAPIException:
120 # nothing found, force redraw
121 self.musiclist.queue_draw()
123 def row_activated(self, treeview, path, view_column):
124 _id = self.musiclist.get_item_id(path)
125 item = self.idmap[_id]
128 def open_item(self, item):
129 if isinstance(item, jamaendo.Album):
130 wnd = ShowAlbum(item)
132 elif isinstance(item, jamaendo.Artist):
133 wnd = ShowArtist(item)
135 elif isinstance(item, jamaendo.Track):
136 wnd = open_playerwindow()
137 wnd.play_tracks([item])