view_albums_genre_box.py 2.54 KB
Newer Older
Cédric Bellegarde's avatar
Cédric Bellegarde committed
1
# Copyright (c) 2014-2019 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
Cédric Bellegarde's avatar
Cédric Bellegarde committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from gi.repository import GLib

from lollypop.view_flowbox import FlowBoxView
from lollypop.widgets_albums_genre import AlbumsGenreWidget
17
from lollypop.define import App, Type, ViewType
18
from lollypop.utils import get_icon_name
Cédric Bellegarde's avatar
Cédric Bellegarde committed
19 20 21 22 23 24 25


class AlbumsGenreBoxView(FlowBoxView):
    """
        Show decades in a FlowBox
    """

26
    def __init__(self, view_type):
Cédric Bellegarde's avatar
Cédric Bellegarde committed
27 28
        """
            Init decade view
29
            @param view_type as ViewType
Cédric Bellegarde's avatar
Cédric Bellegarde committed
30
        """
31
        FlowBoxView.__init__(self, view_type)
Cédric Bellegarde's avatar
Cédric Bellegarde committed
32
        self._widget_class = AlbumsGenreWidget
33
        self._empty_icon_name = get_icon_name(Type.GENRES)
Cédric Bellegarde's avatar
Cédric Bellegarde committed
34 35 36 37 38 39 40 41 42 43

#######################
# PROTECTED           #
#######################
    def _add_items(self, item_ids, *args):
        """
            Add albums to the view
            Start lazy loading
            @param item ids as [int]
        """
44
        widget = FlowBoxView._add_items(self, item_ids, self._view_type)
Cédric Bellegarde's avatar
Cédric Bellegarde committed
45 46 47 48 49 50 51
        if widget is not None:
            widget.connect("overlayed", self.on_overlayed)

    def _on_map(self, widget):
        """
            Set active ids
        """
52
        FlowBoxView._on_map(self, widget)
Cédric Bellegarde's avatar
Cédric Bellegarde committed
53 54 55 56
        App().settings.set_value("state-one-ids",
                                 GLib.Variant("ai", [Type.GENRES]))
        App().settings.set_value("state-two-ids",
                                 GLib.Variant("ai", []))
57 58 59 60 61 62 63 64 65 66 67 68

    def _on_item_activated(self, flowbox, widget):
        """
            Show Context view for activated album
            @param flowbox as Gtk.Flowbox
            @param widget as PlaylistRoundedWidget
        """
        if not self._view_type & ViewType.SMALL and\
                FlowBoxView._on_item_activated(self, flowbox, widget):
            return
        App().window.emit("show-can-go-back", True)
        App().window.emit("can-go-back-changed", True)
69
        App().window.container.show_view([Type.GENRES], widget.data)