예제 #1
0
    def __init__(self, track, menu):
        """
            Init widget
            @param track as Track
            @param menu as Gio.Menu
        """
        Popover.__init__(self)
        if menu is not None:
            self.bind_model(menu, None)

        if track.year is not None:
            year_label = Gtk.Label()
            year_label.set_text(str(track.year))
            dt = GLib.DateTime.new_from_unix_local(track.timestamp)
            year_label.set_tooltip_text(dt.format(_("%Y-%m-%d")))
            year_label.set_margin_end(5)
            year_label.get_style_context().add_class("dim-label")
            year_label.set_property("halign", Gtk.Align.END)
            year_label.set_property("hexpand", True)
            year_label.show()

        # Hack to add two widgets in popover
        grid = Gtk.Grid()
        grid.set_orientation(Gtk.Orientation.VERTICAL)

        stack = Gtk.Stack()
        stack.add_named(grid, "main")
        stack.show_all()

        menu_widget = self.get_child()
        if menu_widget is not None:
            self.remove(menu_widget)
            grid.add(menu_widget)

        hgrid = Gtk.Grid()
        hgrid.get_style_context().add_class("popover-rating-loved-grid")
        rating = RatingWidget(track)
        rating.set_property("halign", Gtk.Align.START)
        rating.set_margin_end(10)
        rating.show()

        loved = LovedWidget(track)
        loved.set_property("halign", Gtk.Align.START)
        loved.set_property("hexpand", True)
        loved.show()

        hgrid.add(rating)
        hgrid.add(loved)

        if track.year is not None:
            hgrid.add(year_label)
        hgrid.show()

        grid.add(hgrid)
        self.add(stack)
예제 #2
0
    def __init__(self, object, button):
        """
            Init widget
            @param object as Track/Album
            @param button as Gtk.Button
        """
        Gtk.Grid.__init__(self)
        self.__object = object
        self.__button = button

        # Check portal for tag editor
        dbus_helper = DBusHelper()
        dbus_helper.call("CanLaunchTagEditor", None,
                         self.__on_can_launch_tag_editor, None)
        self.__edit = HoverWidget("document-properties-symbolic",
                                  self.__edit_tags)
        self.__edit.set_tooltip_text(_("Modify information"))
        self.__edit.set_margin_end(10)
        self.add(self.__edit)

        playlist = HoverWidget("view-list-symbolic",
                               self.__show_playlist_manager)
        playlist.set_tooltip_text(_("Add to playlist"))
        playlist.show()
        self.add(playlist)

        if isinstance(self.__object, Album):
            if Lp().player.album_in_queue(self.__object):
                queue = HoverWidget("list-remove-symbolic",
                                    self.__add_to_queue)
                queue.set_tooltip_text(_("Remove from queue"))
            else:
                queue = HoverWidget("list-add-symbolic", self.__add_to_queue)
                queue.set_tooltip_text(_("Add to queue"))
            queue.set_margin_start(10)
            queue.show()
            self.add(queue)
        else:
            rating = RatingWidget(object)
            rating.set_margin_top(5)
            rating.set_margin_end(10)
            rating.set_margin_bottom(5)
            rating.set_property("halign", Gtk.Align.END)
            rating.set_property("hexpand", True)
            rating.show()

            loved = LovedWidget(object)
            loved.set_margin_end(5)
            loved.set_margin_top(5)
            loved.set_margin_bottom(5)
            loved.show()

            self.add(rating)
            self.add(loved)
예제 #3
0
    def __init__(self, object, button):
        """
            Init widget
            @param object as Track/Album
            @param button as Gtk.Button
        """
        Gtk.Grid.__init__(self)
        self.__object = object
        self.__button = button

        if self.__object.is_web:
            if Type.CHARTS in self.__object.genre_ids:
                if isinstance(self.__object, Album):
                    save = HoverWidget("document-save-symbolic",
                                       self.__save_object)
                    save.set_tooltip_text(_("Save into collection"))
                    save.set_margin_end(10)
                    save.show()
                    self.add(save)
            else:
                trash = HoverWidget("user-trash-symbolic",
                                    self.__remove_object)
                if isinstance(self.__object, Album):
                    trash.set_tooltip_text(_("Remove album"))
                else:
                    trash.set_tooltip_text(_("Remove track"))
                trash.set_margin_end(10)
                trash.show()
                self.add(trash)
        else:
            # Check portal for tag editor
            try:
                Gio.bus_get(Gio.BusType.SESSION, None, self.__on_get_bus,
                            "CanLaunchTagEditor", None,
                            self.__on_can_launch_tag_editor)
            except Exception as e:
                print("ContextWidget::__init__():", e)

            self.__edit = HoverWidget("document-properties-symbolic",
                                      self.__edit_tags)
            self.__edit.set_tooltip_text(_("Modify information"))
            self.__edit.set_margin_end(10)
            self.add(self.__edit)

        if Type.CHARTS not in self.__object.genre_ids:
            playlist = HoverWidget("view-list-symbolic",
                                   self.__show_playlist_manager)
            playlist.set_tooltip_text(_("Add to playlist"))
            playlist.show()
            self.add(playlist)

        if isinstance(self.__object, Album):
            if Lp().player.album_in_queue(self.__object):
                queue = HoverWidget("list-remove-symbolic",
                                    self.__add_to_queue)
                queue.set_tooltip_text(_("Remove from queue"))
            else:
                queue = HoverWidget("list-add-symbolic", self.__add_to_queue)
                queue.set_tooltip_text(_("Add to queue"))
            queue.set_margin_start(10)
            queue.show()
            self.add(queue)
        else:
            if self.__object.is_web:
                web = Gtk.LinkButton(self.__object.uri)
                icon = Gtk.Image.new_from_icon_name("web-browser-symbolic",
                                                    Gtk.IconSize.MENU)
                web.set_image(icon)
                web.get_style_context().add_class("no-padding")
                web.set_margin_start(5)
                web.set_tooltip_text(self.__object.uri)
                web.show_all()
                uri = "https://www.youtube.com/results?search_query=%s" %\
                    (self.__object.artists[0] + " " + self.__object.name,)
                search = Gtk.LinkButton(uri)
                icon = Gtk.Image.new_from_icon_name("edit-find-symbolic",
                                                    Gtk.IconSize.MENU)
                search.set_image(icon)
                search.get_style_context().add_class("no-padding")
                search.set_tooltip_text(uri)
                search.show_all()

                self.add(web)
                self.add(search)

            if Type.CHARTS not in self.__object.genre_ids:
                rating = RatingWidget(object)
                rating.set_margin_top(5)
                rating.set_margin_end(10)
                rating.set_margin_bottom(5)
                rating.set_property("halign", Gtk.Align.END)
                rating.set_property("hexpand", True)
                rating.show()

                loved = LovedWidget(object)
                loved.set_margin_end(5)
                loved.set_margin_top(5)
                loved.set_margin_bottom(5)
                loved.show()

                self.add(rating)
                self.add(loved)
예제 #4
0
    def __init__(self, object, button):
        """
            Init widget
            @param object as Track/Album
            @param button as Gtk.Button
        """
        Gtk.EventBox.__init__(self)
        self.__object = object
        self.__button = button

        self.connect("button-release-event", self.__on_button_release_event)

        grid = Gtk.Grid()
        grid.show()

        if isinstance(object, Disc):
            play_button = Gtk.Button.new_from_icon_name(
                "media-playback-start-symbolic", Gtk.IconSize.BUTTON)
            play_button.connect("clicked", self.__on_play_button_clicked)
            play_button.get_style_context().add_class("dim-button")
            play_button.set_tooltip_text(_("Play"))
            play_button.set_margin_end(2)
            play_button.show()
            grid.add(play_button)
        else:
            edit_button = Gtk.Button.new_from_icon_name(
                "document-properties-symbolic", Gtk.IconSize.BUTTON)
            edit_button.connect("clicked", self.__on_edit_button_clicked)
            edit_button.get_style_context().add_class("dim-button")
            edit_button.set_tooltip_text(_("Modify information"))
            edit_button.set_margin_end(2)
            grid.add(edit_button)
            # Check portal for tag editor
            if App().art.tag_editor:
                edit_button.show()

        if isinstance(object, Track):
            add_to_queue = True
            string = _("Add to queue")
            icon = "zoom-in-symbolic"
            if App().player.track_in_queue(self.__object):
                add_to_queue = False
                string = _("Remove from queue")
                icon = "zoom-out-symbolic"
            queue_button = Gtk.Button.new_from_icon_name(
                icon, Gtk.IconSize.BUTTON)
            queue_button.connect("clicked", self.__on_queue_button_clicked,
                                 add_to_queue)
            queue_button.get_style_context().add_class("dim-button")
            queue_button.set_tooltip_text(string)
            queue_button.set_margin_end(2)
            queue_button.show()
            grid.add(queue_button)
        else:
            add = True
            string = _("Add to current playlist")
            icon = "list-add-symbolic"
            # Search album in player
            if isinstance(object, Disc):
                album = object.album
            else:
                album = object
            player_album_track_ids = []
            for _album in App().player.albums:
                if album.id == _album.id:
                    player_album_track_ids += _album.track_ids
            if len(set(player_album_track_ids) & set(object.track_ids)) == len(
                    object.track_ids):
                add = False
                string = _("Remove from current playlist")
                icon = "list-remove-symbolic"
            current_playlist_button = Gtk.Button.new_from_icon_name(
                icon, Gtk.IconSize.BUTTON)
            current_playlist_button.connect(
                "clicked", self.__on_current_playlist_button_clicked, add)
            current_playlist_button.get_style_context().add_class("dim-button")
            current_playlist_button.set_tooltip_text(string)
            current_playlist_button.set_margin_end(2)
            current_playlist_button.show()
            grid.add(current_playlist_button)

        playlist_button = Gtk.Button.new_from_icon_name(
            "view-list-symbolic", Gtk.IconSize.BUTTON)
        playlist_button.connect("clicked", self.__on_playlist_button_clicked)
        playlist_button.get_style_context().add_class("dim-button")
        playlist_button.set_tooltip_text(_("Add to playlist"))
        playlist_button.show()
        grid.add(playlist_button)

        if isinstance(self.__object, Track):
            rating = RatingWidget(object)
            rating.set_margin_end(2)
            rating.set_property("halign", Gtk.Align.END)
            rating.set_property("hexpand", True)
            rating.show()
            loved = LovedWidget(object)
            loved.set_margin_end(2)
            loved.show()
            grid.add(rating)
            grid.add(loved)
        self.add(grid)
예제 #5
0
    def __init__(self, object, button):
        """
            Init widget
            @param object as Track/Album
            @param button as Gtk.Button
        """
        Gtk.Grid.__init__(self)
        self.__object = object
        self.__button = button

        can_launch = False

        if self.__object.is_web:
            if self.__object.genre_ids == [Type.CHARTS]:
                if isinstance(self.__object, Album):
                    save = HoverWidget('document-save-symbolic',
                                       self.__save_object)
                    save.set_tooltip_text(_("Save into collection"))
                    save.set_margin_end(10)
                    save.show()
            else:
                trash = HoverWidget('user-trash-symbolic',
                                    self.__remove_object)
                if isinstance(self.__object, Album):
                    trash.set_tooltip_text(_("Remove album"))
                else:
                    trash.set_tooltip_text(_("Remove track"))
                trash.set_margin_end(10)
                trash.show()
        else:
            # Check portal for tag editor
            try:
                bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
                proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE,
                                               None,
                                               'org.gnome.Lollypop.Portal',
                                               '/org/gnome/LollypopPortal',
                                               'org.gnome.Lollypop.Portal',
                                               None)
                can_launch = proxy.call_sync('CanLaunchTagEditor', None,
                                             Gio.DBusCallFlags.NO_AUTO_START,
                                             500, None)[0]
            except:
                print("You are missing lollypop-portal: "
                      "https://github.com/gnumdk/lollypop-portal")
            if can_launch:
                edit = HoverWidget('document-properties-symbolic',
                                   self.__edit_tags)
                edit.set_tooltip_text(_("Modify information"))
                edit.set_margin_end(10)
                edit.show()

        playlist = HoverWidget('view-list-symbolic',
                               self.__show_playlist_manager)
        playlist.set_tooltip_text(_("Playlists"))
        playlist.show()

        if isinstance(self.__object, Album):
            if Lp().player.album_in_queue(self.__object):
                queue = HoverWidget('list-remove-symbolic',
                                    self.__add_to_queue)
                queue.set_tooltip_text(_("Remove from queue"))
            else:
                queue = HoverWidget('list-add-symbolic', self.__add_to_queue)
                queue.set_tooltip_text(_("Add to queue"))
            queue.set_margin_start(10)
            queue.show()
        else:
            rating = RatingWidget(object)
            rating.set_margin_top(5)
            rating.set_margin_end(10)
            rating.set_margin_bottom(5)
            rating.set_property('halign', Gtk.Align.END)
            rating.set_property('hexpand', True)
            rating.show()

            loved = LovedWidget(object)
            loved.set_margin_end(5)
            loved.set_margin_top(5)
            loved.set_margin_bottom(5)
            loved.show()

            if self.__object.is_web:
                web = Gtk.LinkButton(self.__object.uri)
                icon = Gtk.Image.new_from_icon_name('web-browser-symbolic',
                                                    Gtk.IconSize.MENU)
                web.set_image(icon)
                web.get_style_context().add_class('no-padding')
                web.set_margin_start(5)
                web.set_tooltip_text(self.__object.uri)
                web.show_all()
                uri = "https://www.youtube.com/results?search_query=%s" %\
                    (self.__object.artists[0] + " " + self.__object.name,)
                search = Gtk.LinkButton(uri)
                icon = Gtk.Image.new_from_icon_name('edit-find-symbolic',
                                                    Gtk.IconSize.MENU)
                search.set_image(icon)
                search.get_style_context().add_class('no-padding')
                search.set_tooltip_text(uri)
                search.show_all()

        if self.__object.is_web:
            if self.__object.genre_ids == [Type.CHARTS]:
                if isinstance(self.__object, Album):
                    self.add(save)
            else:
                self.add(trash)
        elif can_launch:
            self.add(edit)
        self.add(playlist)
        if isinstance(self.__object, Album):
            self.add(queue)
        else:
            if self.__object.album.is_web:
                self.add(web)
                self.add(search)
            self.add(rating)
            self.add(loved)
예제 #6
0
    def populate(self):
        """
            Populate widget content
        """
        if self._widget is None:
            OverlayAlbumHelper.__init__(self)
            self.__context = None
            grid = Gtk.Grid()
            grid.set_margin_start(5)
            grid.set_margin_end(5)
            grid.set_row_spacing(1)
            grid.set_vexpand(True)
            grid.show()
            self.__title_label = Gtk.Label()
            self.__title_label.set_margin_end(10)
            self.__title_label.set_ellipsize(Pango.EllipsizeMode.END)
            self.__title_label.get_style_context().add_class("dim-label")
            self.__title_label.set_property("has-tooltip", True)
            self.__title_label.connect("query-tooltip",
                                       self.__on_query_tooltip)
            self.__title_label.show()
            self.__artist_label = Gtk.Label()
            self.__artist_label.set_margin_end(10)
            self.__artist_label.set_ellipsize(Pango.EllipsizeMode.END)
            self.__artist_label.set_property("has-tooltip", True)
            self.__artist_label.connect("query-tooltip",
                                        self.__on_query_tooltip)
            self.__artist_label.show()
            self.__year_label = Gtk.Label()
            self.__year_label.set_margin_end(10)
            self.__year_label.get_style_context().add_class("dim-label")
            self.__year_label.show()
            self.__duration_label = Gtk.Label()
            self.__duration_label.get_style_context().add_class("dim-label")
            self.__duration_label.show()
            self.__context_button = Gtk.Button.new_from_icon_name(
                "go-next-symbolic", Gtk.IconSize.BUTTON)
            self.__context_button.set_relief(Gtk.ReliefStyle.NONE)
            self.__context_button.connect("clicked", self.__on_context_clicked)
            self.__context_button.get_style_context().add_class("menu-button")
            self.__context_button.get_style_context().add_class(
                                                          "album-menu-button")
            self.__context_button.show()
            self._widget = Gtk.Grid()
            self._widget.set_orientation(Gtk.Orientation.VERTICAL)
            self._widget.set_row_spacing(2)
            self._widget.show()
            self.__header = Gtk.Grid()
            self.__header.add(self.__artist_label)
            self.__header.add(self.__title_label)
            self.__header.add(self.__year_label)
            self.__header.add(self.__context_button)
            self.__header.show()
            self._widget.add(self.__header)
            separator = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
            separator.show()
            self._widget.add(separator)

            loved = LovedWidget(self._album)
            loved.set_property("valign", Gtk.Align.CENTER)
            loved.set_margin_end(10)
            loved.show()

            rating = RatingWidget(self._album)
            rating.set_property("valign", Gtk.Align.CENTER)
            rating.set_property("halign", Gtk.Align.END)
            rating.set_margin_end(10)
            rating.show()

            if self.__show_cover:
                self.__header.add(self.__duration_label)
                self.__duration_label.set_hexpand(True)
                self.__duration_label.set_property("halign", Gtk.Align.END)
                eventbox = Gtk.EventBox()
                eventbox.connect("enter-notify-event", self._on_enter_notify)
                eventbox.connect("leave-notify-event", self._on_leave_notify)
                eventbox.connect("button-press-event", self._on_button_press)
                eventbox.show()
                self.set_property("valign", Gtk.Align.CENTER)
                self._artwork = App().art_helper.get_image(ArtSize.BIG,
                                                           ArtSize.BIG,
                                                           "cover-frame")
                self._artwork.show()
                eventbox.add(self._artwork)
                self.__duration_label.set_hexpand(True)
                self._overlay = Gtk.Overlay.new()
                self._overlay.add(eventbox)
                self._overlay.show()
                self.__coverbox = Gtk.Grid()
                self.__coverbox.set_row_spacing(2)
                self.__coverbox.set_margin_end(10)
                self.__coverbox.set_orientation(Gtk.Orientation.VERTICAL)
                self.__coverbox.show()
                self.__coverbox.attach(self._overlay, 0, 0, 2, 1)
                loved.set_property("halign", Gtk.Align.START)
                self.__coverbox.attach(rating, 0, 1, 1, 1)
                self.__coverbox.attach_next_to(loved,
                                               rating,
                                               Gtk.PositionType.RIGHT,
                                               1,
                                               1)
                if App().window.container.stack.get_allocation().width <\
                        Sizing.MEDIUM:
                    self.__coverbox.hide()
                if len(self._artist_ids) > 1:
                    self.__artist_label.set_text(
                        ", ".join(self._album.artists))
                    self.__artist_label.show()
            else:
                self._artwork = None
                loved.set_property("halign", Gtk.Align.END)
                self.__header.add(rating)
                self.__header.add(loved)
                rating.set_hexpand(True)
                self.__header.add(self.__duration_label)
                self.__artist_label.set_text(", ".join(self._album.artists))
                self.__artist_label.show()
            self.__set_duration()
            album_name = GLib.markup_escape_text(self._album.name)
            artist_name = GLib.markup_escape_text(
                ", ".join(self._album.artists))
            self.__title_label.set_markup("<b>%s</b>" % album_name)
            self.__artist_label.set_markup("<b>%s</b>" % artist_name)
            if self._album.year is not None:
                self.__year_label.set_label(str(self._album.year))
                self.__year_label.show()
            self.set_selection()
            if self._artwork is None:
                TracksView.populate(self)
                self._widget.add(self._responsive_widget)
                self._responsive_widget.show()
            else:
                grid.add(self.__coverbox)
                self.set_artwork()
            grid.add(self._widget)
            self.add(grid)
        else:
            TracksView.populate(self)
예제 #7
0
    def __init__(self, object, button):
        """
            Init widget
            @param object as Track/Album
            @param button as Gtk.Button
        """
        Gtk.Grid.__init__(self)
        self.__object = object
        self.__button = button

        can_launch = False

        if self.__object.is_web:
            if Type.CHARTS in self.__object.genre_ids:
                if isinstance(self.__object, Album):
                    save = HoverWidget('document-save-symbolic',
                                       self.__save_object)
                    save.set_tooltip_text(_("Save into collection"))
                    save.set_margin_end(10)
                    save.show()
                    self.add(save)
            else:
                trash = HoverWidget('user-trash-symbolic',
                                    self.__remove_object)
                if isinstance(self.__object, Album):
                    trash.set_tooltip_text(_("Remove album"))
                else:
                    trash.set_tooltip_text(_("Remove track"))
                trash.set_margin_end(10)
                trash.show()
                self.add(trash)
        else:
            # Check portal for tag editor
            try:
                bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
                proxy = Gio.DBusProxy.new_sync(
                                            bus, Gio.DBusProxyFlags.NONE, None,
                                            'org.gnome.Lollypop.Portal',
                                            '/org/gnome/LollypopPortal',
                                            'org.gnome.Lollypop.Portal', None)
                can_launch = proxy.call_sync('CanLaunchTagEditor', None,
                                             Gio.DBusCallFlags.NO_AUTO_START,
                                             500, None)[0]
            except:
                print("You are missing lollypop-portal: "
                      "https://github.com/gnumdk/lollypop-portal")
            if can_launch:
                edit = HoverWidget('document-properties-symbolic',
                                   self.__edit_tags)
                edit.set_tooltip_text(_("Modify information"))
                edit.set_margin_end(10)
                edit.show()
                self.add(edit)

        if Type.CHARTS not in self.__object.genre_ids:
            playlist = HoverWidget('view-list-symbolic',
                                   self.__show_playlist_manager)
            playlist.set_tooltip_text(_("Playlists"))
            playlist.show()
            self.add(playlist)

        if isinstance(self.__object, Album):
            if Lp().player.album_in_queue(self.__object):
                queue = HoverWidget('list-remove-symbolic',
                                    self.__add_to_queue)
                queue.set_tooltip_text(_("Remove from queue"))
            else:
                queue = HoverWidget('list-add-symbolic', self.__add_to_queue)
                queue.set_tooltip_text(_("Add to queue"))
            queue.set_margin_start(10)
            queue.show()
            self.add(queue)
        else:
            if self.__object.is_web:
                web = Gtk.LinkButton(self.__object.uri)
                icon = Gtk.Image.new_from_icon_name('web-browser-symbolic',
                                                    Gtk.IconSize.MENU)
                web.set_image(icon)
                web.get_style_context().add_class('no-padding')
                web.set_margin_start(5)
                web.set_tooltip_text(self.__object.uri)
                web.show_all()
                uri = "https://www.youtube.com/results?search_query=%s" %\
                    (self.__object.artists[0] + " " + self.__object.name,)
                search = Gtk.LinkButton(uri)
                icon = Gtk.Image.new_from_icon_name('edit-find-symbolic',
                                                    Gtk.IconSize.MENU)
                search.set_image(icon)
                search.get_style_context().add_class('no-padding')
                search.set_tooltip_text(uri)
                search.show_all()

                self.add(web)
                self.add(search)

            if Type.CHARTS not in self.__object.genre_ids:
                rating = RatingWidget(object)
                rating.set_margin_top(5)
                rating.set_margin_end(10)
                rating.set_margin_bottom(5)
                rating.set_property('halign', Gtk.Align.END)
                rating.set_property('hexpand', True)
                rating.show()

                loved = LovedWidget(object)
                loved.set_margin_end(5)
                loved.set_margin_top(5)
                loved.set_margin_bottom(5)
                loved.show()

                self.add(rating)
                self.add(loved)