4 xmms-search : A usable and useful search system for XMMS2.
6 Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
8 This application is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This application is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this application; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301
25 import xmmsclient
.glib
as xg
26 import xmmsclient
.collections
as xc
36 from xmms_list
import *
38 __version__
= "0.0.1alpha"
39 __author__
= "Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>"
40 __copyright__
= "Copyright 2007, Sadrul Habib Chowdhury"
44 sys
.setdefaultencoding("utf-8")
46 class XSearchResult(XList
):
48 'add-to-playlist': ('add_to_playlist', gnt
.KEY_CTRL_A
),
50 def add_to_playlist(self
, null
):
51 songs
= self
.get_rows()
53 if not song
.tagged
: continue
55 self
.update_row_flags(song
)
56 id = song
.get_data('song-id')
57 self
.xmms
.playlist_add_id(id)
60 gobject
.type_register(XSearchResult
)
61 gnt
.register_bindings(XSearchResult
)
63 class XSearch(gnt
.Box
):
64 def __init__(self
, xmms
):
65 gnt
.Box
.__init
__(self
, False, True)
68 self
.entry
= gnt
.Entry('')
69 self
.list = XSearchResult(xmms
)
70 self
.list.hide_column(XList
.POSITION
)
71 self
.list.hide_column(XList
.ALBUM
)
72 self
.add_widget(self
.entry
)
73 self
.add_widget(self
.list)
74 self
.entry
.connect('activate', self
.search
)
76 def search(self
, entry
):
77 self
.list.remove_all()
78 string
= entry
.get_text()
83 searchstring
= "artist:*%s* OR title:*%s*" % (string
, string
)
84 coll
= xmmsclient
.xmmsapi
.coll_parse(searchstring
)
85 def got_coll_list(result
):
86 self
.list.remove_all()
87 songs
= result
.value()
90 self
.list.add_mlib_song(pos
, song
)
94 string
= [""] * self
.list.COLUMNS
95 string
[self
.list.TITLE
] = "Searching..."
96 self
.list.add_row_after(ph
, string
, None)
97 self
.xmms
.coll_query_ids(coll
, cb
= got_coll_list
)
99 def standalone(self
, title
= "XMMS2 Search"):
100 self
.set_toplevel(True)
101 self
.set_title(title
)
103 gobject
.type_register(XSearch
)
104 gnt
.register_bindings(XSearch
)
107 xmms
= xmmsclient
.XMMS("pygnt-search")
109 xmms
.connect(os
.getenv("XMMS_PATH"))
110 conn
= xg
.GLibConnector(xmms
)
114 except IOError, detail
:
115 common
.show_error("Connection failed: " + str(detail
))
117 if __name__
== '__main__':