Commit 8903fbc2 authored by Marinus Schraal's avatar Marinus Schraal

albumwidget: Add selection-mode property

Obsoletes connecting to HeaderBar buttons directly.
parent e5ad6cc5
......@@ -28,7 +28,6 @@ from gi.repository import GdkPixbuf, GLib, GObject, Gtk
from gnomemusic import log
from gnomemusic.albumartcache import Art, ArtImage
from gnomemusic.grilo import grilo
from gnomemusic.gstplayer import Playback
from gnomemusic.widgets.disclistboxwidget import DiscBox
from gnomemusic.widgets.disclistboxwidget import DiscListBox # noqa: F401
from gnomemusic.widgets.songwidget import SongWidget
......@@ -54,6 +53,8 @@ class AlbumWidget(Gtk.EventBox):
_running_info_label = Gtk.Template.Child()
_title_label = Gtk.Template.Child()
selection_mode = GObject.Property(type=bool, default=False)
_duration = 0
def __repr__(self):
......@@ -74,8 +75,6 @@ class AlbumWidget(Gtk.EventBox):
self._player = player
self._iter_to_clean = None
self._selection_mode = False
self._create_model()
self._album = None
self._header_bar = None
......@@ -84,12 +83,11 @@ class AlbumWidget(Gtk.EventBox):
# _get_selected_songs
self.view = self._disc_listbox
self.show_all()
self.bind_property(
'selection-mode', self._disc_listbox, 'selection-mode',
GObject.BindingFlags.BIDIRECTIONAL)
@log
def _on_selection_mode_request(self, *args):
"""Selection mode toggled."""
self._header_bar._select_button.clicked()
self.show_all()
@log
def _create_model(self):
......@@ -130,8 +128,6 @@ class AlbumWidget(Gtk.EventBox):
art.image = self._cover
GLib.idle_add(grilo.populate_album_songs, item, self.add_item)
header_bar._select_button.connect(
'toggled', self._on_header_select_button_toggled)
self._album = utils.get_album_title(item)
self._artist_label.props.label = utils.get_artist_name(item)
......@@ -144,6 +140,11 @@ class AlbumWidget(Gtk.EventBox):
self._set_composer_label(item)
self.bind_property(
'selection-mode', self._header_bar, 'selection-mode',
GObject.BindingFlags.BIDIRECTIONAL |
GObject.BindingFlags.SYNC_CREATE)
self._player.connect('song-changed', self._update_model)
@log
......@@ -171,21 +172,6 @@ class AlbumWidget(Gtk.EventBox):
self.selection_toolbar.props.items_selected = n_items
self._header_bar.items_selected = n_items
@log
def _on_header_select_button_toggled(self, button):
"""Selection mode button clicked callback."""
if button.get_active():
self._selection_mode = True
self._disc_listbox.props.selection_mode = True
self._header_bar.props.selection_mode = True
self._parent_view.set_player_visible(False)
else:
self._selection_mode = False
self._disc_listbox.props.selection_mode = False
self._header_bar.props.selection_mode = False
if self._player.get_playback_status() != Playback.STOPPED:
self._parent_view.set_player_visible(True)
@log
def _create_disc_box(self, disc_nr, disc_songs):
disc_box = DiscBox(self._model)
......@@ -202,12 +188,11 @@ class AlbumWidget(Gtk.EventBox):
@log
def _selection_mode_toggled(self, widget):
self._selection_mode = not self._selection_mode
self._on_selection_mode_request()
self.props.selection_mode = not self.props.selection_mode
@log
def _song_activated(self, widget, song_widget):
if self._selection_mode:
if self.props.selection_mode:
song_widget.props.selected = not song_widget.props.selected
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment