/usr/share/pyshared/quodlibet/browsers/search.py is in exfalso 3.0.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | # -*- coding: utf-8 -*-
# Copyright 2004-2013 Joe Wreschnig, Michael Urman, IƱigo Serna,
# Christoph Reiter, Steven Robertson, Nick Boultbee
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation
import os
from gi.repository import Gtk, GLib
from quodlibet import config
from quodlibet import const
from quodlibet import qltk
from quodlibet.browsers._base import Browser
from quodlibet.parse import Query
from quodlibet.qltk.ccb import ConfigCheckMenuItem
from quodlibet.qltk.completion import LibraryTagCompletion
from quodlibet.qltk.menubutton import MenuButton
from quodlibet.qltk.songlist import SongList
from quodlibet.qltk.searchbar import SearchBarBox, LimitSearchBarBox
from quodlibet.qltk.x import Alignment, SymbolicIconImage
QUERIES = os.path.join(const.USERDIR, "lists", "queries")
class EmptyBar(Gtk.VBox, Browser):
"""A browser that the user only interacts with indirectly, via the
Filter menu. The VBox remains empty."""
__gsignals__ = Browser.__gsignals__
name = _("Disable Browser")
accelerated_name = _("_Disable Browser")
priority = 0
in_menu = False
def pack(self, songpane):
container = Gtk.VBox(spacing=6)
container.pack_start(self, False, True, 0)
container.pack_start(songpane, True, True, 0)
return container
def unpack(self, container, songpane):
container.remove(songpane)
container.remove(self)
def __init__(self, library, main):
super(EmptyBar, self).__init__()
self._text = ""
self._filter = None
self._library = library
self.commands = {"query": self.__query}
self.connect('destroy', self.__destroy)
def __destroy(self, *args):
del self.commands
def active_filter(self, song):
if self._filter is not None:
return self._filter(song)
else:
return True
def filter_text(self, text):
self._text = text
self.activate()
def __query(self, text, library, window, player):
self.filter_text(text)
def save(self):
config.set("browsers", "query_text", self._text.encode('utf-8'))
def restore(self, activate=True):
try:
text = config.get("browsers", "query_text")
except Exception:
return
if activate:
self.filter_text(text)
else:
self._text = text
def finalize(self, restore):
config.set("browsers", "query_text", "")
def _get_songs(self):
try:
self._filter = Query(self._text, star=SongList.star).search
except Query.error:
pass
else:
if Query.match_all(self._text):
songs = self._library.values()
self._filter = None
else:
songs = filter(self._filter, self._library)
return songs
def activate(self):
songs = self._get_songs()
if songs is not None:
GLib.idle_add(self.emit, 'songs-selected', songs, None)
def can_filter_text(self):
return True
def unfilter(self):
self.filter_text("")
class SearchBar(EmptyBar):
"""Like EmptyBar, but the user can also enter a query manually.
This is QL's default browser. EmptyBar handles all the GObject stuff."""
name = _("Search Library")
accelerated_name = _("_Search Library")
priority = 1
in_menu = True
class PreferencesButton(Gtk.HBox):
def __init__(self, search_bar_box):
super(SearchBar.PreferencesButton, self).__init__()
menu = Gtk.Menu()
limit_item = ConfigCheckMenuItem(
_("_Limit Results"), "browsers", "search_limit", True)
limit_item.connect("toggled", search_bar_box.toggle_limit_widgets)
menu.append(limit_item)
menu.show_all()
button = MenuButton(
SymbolicIconImage("emblem-system", Gtk.IconSize.MENU),
arrow=True)
button.set_menu(menu)
self.pack_start(button, True, True, 0)
def __init__(self, library, main, limit=True):
super(SearchBar, self).__init__(library, main)
self.set_spacing(6)
completion = LibraryTagCompletion(library.librarian)
self.accelerators = Gtk.AccelGroup()
if limit:
show_limit = config.getboolean("browsers", "search_limit")
sbb = LimitSearchBarBox(completion=completion,
accel_group=self.accelerators,
show_limit=show_limit)
else:
sbb = SearchBarBox(completion=completion,
accel_group=self.accelerators)
sbb.connect('query-changed', self.__text_parse)
sbb.connect('focus-out', self.__focus)
self._sb_box = sbb
if limit:
prefs = SearchBar.PreferencesButton(sbb)
sbb.pack_start(prefs, False, True, 0)
align = (Alignment(sbb, left=3, right=3, top=3) if main
else Alignment(sbb))
self.pack_start(align, False, True, 0)
self.connect('destroy', self.__destroy)
self.show_all()
def __destroy(self, *args):
self._sb_box = None
def __focus(self, widget, *args):
qltk.get_top_parent(widget).songlist.grab_focus()
def activate(self):
songs = self._get_songs()
if songs is not None and self._sb_box:
songs = self._sb_box.limit(songs)
GLib.idle_add(self.emit, 'songs-selected', songs, None)
def __text_parse(self, bar, text):
self._text = text
self.activate()
def filter_text(self, text):
self._text = text
self._sb_box.set_text(text)
self.activate()
browsers = [EmptyBar, SearchBar]
|