Skip to content

Commit

Permalink
Don't load tracks unnecessarily
Browse files Browse the repository at this point in the history
- Rating widget: only activate when needs-computing is not True
- Files: store whether selected items are directories, set needs-computing appropriately
- Playlists: set needs-computing when the playlist is a SmartPlaylist
  • Loading branch information
virtuald committed Apr 28, 2017
1 parent b284232 commit aa890c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
26 changes: 19 additions & 7 deletions xlgui/panel/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _setup_tree(self):
"""
Sets up tree widget for the files panel
"""
self.model = Gtk.ListStore(Gio.File, GdkPixbuf.Pixbuf, str, str)
self.model = Gtk.ListStore(Gio.File, GdkPixbuf.Pixbuf, str, str, bool)
self.tree = tree = FilesDragTreeView(self, True, True)
tree.set_model(self.model)
tree.connect('row-activated', self.row_activated)
Expand Down Expand Up @@ -258,10 +258,8 @@ def row_activated(self, *i):
model, paths = selection.get_selected_rows()

for path in paths:
f = model[path][0]
ftype = f.query_info('standard::type', Gio.FileQueryInfoFlags.NONE, None).get_file_type()
if ftype == Gio.FileType.DIRECTORY:
self.load_directory(f)
if model[path][4]:
self.load_directory(model[path][0])
else:
self.emit('append-items', self.tree.get_selected_tracks(), True)

Expand Down Expand Up @@ -421,7 +419,7 @@ def idle():
model.clear()
row = 0
for sortname, name, f in subdirs:
model.append((f, self.directory, name, ''))
model.append((f, self.directory, name, '', True))
uri = f.get_uri()
if cursor_file and cursor_row == -1 and \
(cursor_uri == uri or cursor_uri.startswith(uri + '/')):
Expand All @@ -436,7 +434,7 @@ def idle():
size = locale.format_string('%d', size, True)
size = _('%s kB') % unicode(size, locale.getpreferredencoding())

model.append((f, self.track, name, size))
model.append((f, self.track, name, size, False))
if cursor_file and cursor_row == -1 and cursor_uri == f.get_uri():
cursor_row = row
row += 1
Expand Down Expand Up @@ -490,6 +488,20 @@ def get_selection_empty(self):
'''Returns True if there are no selected items'''
return self.get_selection().count_selected_rows() == 0

def get_selection_is_computed(self):
"""
Returns True if anything in the selection is a directory
"""
selection = self.get_selection()
model, paths = selection.get_selected_rows()

for path in paths:
if model[path][4]:
return True

return False


def get_selected_tracks(self):
"""
Returns the currently selected tracks
Expand Down
4 changes: 3 additions & 1 deletion xlgui/panel/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ def __init__(self, panel):
menu.MultiProviderMenu.__init__(self,
['track-panel-menu', 'files-panel-context-menu']
, panel)

def get_context(self):
context = common.LazyDict(self._parent)
context['needs-computing'] = lambda name, parent: parent.tree.get_selection_is_computed()
context['selected-tracks'] = lambda name, parent: parent.tree.get_selected_tracks()
context['selection-empty'] = lambda name, parent: parent.tree.get_selection_empty()

Expand Down Expand Up @@ -237,6 +238,7 @@ def __init__(self, parent):

def get_context(self):
context = common.LazyDict(self._parent)
context['needs-computing'] = lambda name, parent: parent.tree.get_selection_is_computed()
context['selected-playlist'] = lambda name, parent: parent.tree.get_selected_page(raw=True)
context['selected-tracks'] = lambda name, parent: parent.tree.get_selected_tracks()
context['selection-empty'] = lambda name, parent: parent.tree.get_selection_empty()
Expand Down
7 changes: 7 additions & 0 deletions xlgui/panel/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,13 @@ def get_selection_empty(self):
'''Returns True if there are no selected items'''
return self.get_selection().count_selected_rows() == 0

def get_selection_is_computed(self):
"""
Returns True if selection is a Smart Playlist
"""
item = self.get_selected_item(raw=True)
return isinstance(item, playlist.SmartPlaylist)

def get_selected_tracks(self):
"""
Used by the menu, just basically gets the selected
Expand Down
3 changes: 3 additions & 0 deletions xlgui/widgets/menuitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __init__(self, name, after, get_tracks_func=generic_get_tracks_func):
# TODO: For accessibility it would be nice to add mnemonics or some
# other key shortcut thing to the RatingMenu, e.g. "+" and "-"
def factory(self, menu, parent, context):
# don't show rating widget for computed track selections (see #340)
if context.get('needs-computing'):
return
item = rating.RatingMenuItem()
item.connect('show', self.on_show, menu, parent, context)
self._rating_changed_id = item.connect('rating-changed',
Expand Down

0 comments on commit aa890c6

Please sign in to comment.