Esempio n. 1
0
class PlaylistsView(View):
    """
        Show playlist tracks
    """
    def __init__(self, playlist_ids, editable=True):
        """
            Init PlaylistView
            @parma playlist ids as [int]
            @param editable as bool
        """
        View.__init__(self)
        self.__tracks = []
        self.__playlist_ids = playlist_ids
        self.__signal_id1 = Lp().playlists.connect('playlist-add',
                                                   self.__on_playlist_add)
        self.__signal_id2 = Lp().playlists.connect('playlist-del',
                                                   self.__on_playlist_del)

        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/PlaylistView.ui')

        builder.get_object('title').set_label(", ".join(
            Lp().playlists.get_names(playlist_ids)))

        self.__edit_button = builder.get_object('edit-button')
        self.__jump_button = builder.get_object('jump-button')
        split_button = builder.get_object('split-button')
        if editable:
            split_button.set_active(not Lp().settings.get_value('split-view'))
        else:
            split_button.hide()

        if len(playlist_ids) > 1 or (
           playlist_ids[0] < 0 and playlist_ids[0] != Type.LOVED) or\
                not editable:
            self.__edit_button.hide()

        self.__playlists_widget = PlaylistsWidget(playlist_ids)
        self.__playlists_widget.show()
        self.add(builder.get_object('widget'))
        self._viewport.add(self.__playlists_widget)
        self._scrolled.set_property('expand', True)
        self.add(self._scrolled)
        # Connect signals after ui init
        # 'split-button' will emit a signal otherwise
        builder.connect_signals(self)

    def populate(self, tracks):
        """
            Populate view with tracks from playlist
            Thread safe
        """
        # We are looking for middle
        # Ponderate with this:
        # Tracks with cover == 2
        # Tracks without cover == 1
        prev_album_id = None
        heights = {}
        total = 0
        idx = 0
        for track_id in tracks:
            track = Track(track_id)
            if track.album_id != prev_album_id:
                heights[idx] = 2
                total += 2
            else:
                heights[idx] = 1
                total += 1
            prev_album_id = track.album_id
            idx += 1
        half = int(total / 2 + 0.5)
        mid_tracks = 1
        count = 0
        for height in heights.values():
            count += height
            if count >= half:
                break
            mid_tracks += 1
        self.__tracks = tracks
        self.__update_jump_button()
        self.__playlists_widget.populate_list_left(tracks[:mid_tracks], 1)
        self.__playlists_widget.populate_list_right(tracks[mid_tracks:],
                                                    mid_tracks + 1)

    def get_ids(self):
        """
            Return playlist ids
            @return id as [int]
        """
        return self.__playlist_ids

    def stop(self):
        """
            Stop populating
        """
        self.__playlists_widget.stop()

#######################
# PROTECTED           #
#######################

    def _get_children(self):
        """
            Return view children
        """
        return [self.__playlists_widget]

    def _on_destroy(self, widget):
        """
            Disconnect signals
            @param widget as Gtk.Widget
        """
        View._on_destroy(self, widget)
        if self.__signal_id1:
            Lp().playlists.disconnect(self.__signal_id1)
            self.__signal_id1 = None
        if self.__signal_id2:
            Lp().playlists.disconnect(self.__signal_id2)
            self.__signal_id2 = None

    def _on_split_button_toggled(self, button):
        """
            Split/Unsplit view
        """
        Lp().settings.set_value('split-view',
                                GLib.Variant('b', not button.get_active()))
        self.__playlists_widget.update_allocation()

    def _on_jump_button_clicked(self, button):
        """
            Scroll to current track
            @param button as Gtk.Button
        """
        y = self.__playlists_widget.get_current_ordinate()
        if y is not None:
            self._scrolled.get_vadjustment().set_value(y)

    def _on_edit_button_clicked(self, button):
        """
            Edit playlist
            @param button as Gtk.Button
        """
        Lp().window.show_playlist_editor(self.__playlist_ids[0])

    def _on_current_changed(self, player):
        """
            Current song changed, update playing button
            @param player as Player
        """
        View._on_current_changed(self, player)
        self.__update_jump_button()


#######################
# PRIVATE             #
#######################

    def __update_jump_button(self):
        """
            Update jump button status
        """
        if Lp().player.current_track.id in self.__tracks:
            self.__jump_button.set_sensitive(True)
            artists = ", ".join(Lp().player.current_track.artists)
            self.__jump_button.set_tooltip_markup(
                "<b>%s</b>\n%s" %
                (GLib.markup_escape_text(artists),
                 GLib.markup_escape_text(Lp().player.current_track.name)))
        else:
            self.__jump_button.set_sensitive(False)
            self.__jump_button.set_tooltip_text('')

    def __on_playlist_add(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self.__playlist_ids:
            self.__playlists_widget.append(track_id)

    def __on_playlist_del(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self.__playlist_ids:
            self.__playlists_widget.remove(track_id)
Esempio n. 2
0
class PlaylistsView(View):
    """
        Show playlist tracks
    """
    def __init__(self, playlist_ids, editable=True):
        """
            Init PlaylistView
            @parma playlist ids as [int]
            @param editable as bool
        """
        View.__init__(self, True)
        self.__tracks = []
        self.__playlist_ids = playlist_ids
        self.__signal_id1 = Lp().playlists.connect("playlist-add",
                                                   self.__on_playlist_add)
        self.__signal_id2 = Lp().playlists.connect("playlist-del",
                                                   self.__on_playlist_del)

        builder = Gtk.Builder()
        builder.add_from_resource("/org/gnome/Lollypop/PlaylistView.ui")
        self.__duration_label = builder.get_object("duration")
        builder.get_object("title").set_label(", ".join(
            Lp().playlists.get_names(playlist_ids)))

        self.__edit_button = builder.get_object("edit-button")
        self.__jump_button = builder.get_object("jump-button")
        split_button = builder.get_object("split-button")
        if editable:
            split_button.set_active(not Lp().settings.get_value("split-view"))
        else:
            split_button.hide()

        if len(playlist_ids) > 1 or (
           playlist_ids[0] < 0 and playlist_ids[0] not in [Type.LOVED,
                                                           Type.NOPARTY]) or\
                not editable:
            self.__edit_button.hide()

        self.__playlists_widget = PlaylistsWidget(playlist_ids)
        self.__playlists_widget.set_filter_func(self._filter_func)
        self.__playlists_widget.show()
        self.add(builder.get_object("widget"))
        self._viewport.add(self.__playlists_widget)
        self._scrolled.set_property("expand", True)
        self.add(self._scrolled)
        # Connect signals after ui init
        # "split-button" will emit a signal otherwise
        builder.connect_signals(self)
        # No duration for non user playlists
        # FIXME
        if playlist_ids[0] > 0:
            self.__set_duration()

    def populate(self, tracks):
        """
            Populate view with tracks from playlist
            Thread safe
        """
        # We are looking for middle
        # Ponderate with this:
        # Tracks with cover == 2
        # Tracks without cover == 1
        prev_album_id = None
        heights = {}
        total = 0
        idx = 0
        for track_id in tracks:
            track = Track(track_id)
            if track.album_id != prev_album_id:
                heights[idx] = 2
                total += 2
            else:
                heights[idx] = 1
                total += 1
            prev_album_id = track.album_id
            idx += 1
        half = int(total / 2 + 0.5)
        mid_tracks = 1
        count = 0
        for height in heights.values():
            count += height
            if count >= half:
                break
            mid_tracks += 1
        self.__tracks = tracks
        self.__update_jump_button()
        self.__playlists_widget.populate_list_left(tracks[:mid_tracks], 1)
        self.__playlists_widget.populate_list_right(tracks[mid_tracks:],
                                                    mid_tracks + 1)

    def get_ids(self):
        """
            Return playlist ids
            @return id as [int]
        """
        return self.__playlist_ids

    def stop(self):
        """
            Stop populating
        """
        self.__playlists_widget.stop()

#######################
# PROTECTED           #
#######################

    def _get_children(self):
        """
            Return view children
        """
        return [self.__playlists_widget]

    def _on_search_changed(self, entry):
        """
            Update filter
            @param entry as Gtk.Entry
        """
        self._filter = entry.get_text()
        for box in self.__playlists_widget.boxes:
            box.invalidate_filter()

    def _on_destroy(self, widget):
        """
            Disconnect signals
            @param widget as Gtk.Widget
        """
        View._on_destroy(self, widget)
        if self.__signal_id1:
            Lp().playlists.disconnect(self.__signal_id1)
            self.__signal_id1 = None
        if self.__signal_id2:
            Lp().playlists.disconnect(self.__signal_id2)
            self.__signal_id2 = None

    def _on_split_button_toggled(self, button):
        """
            Split/Unsplit view
        """
        Lp().settings.set_value("split-view",
                                GLib.Variant("b", not button.get_active()))
        self.__playlists_widget.update_allocation()

    def _on_jump_button_clicked(self, button):
        """
            Scroll to current track
            @param button as Gtk.Button
        """
        y = self.__playlists_widget.get_current_ordinate()
        if y is not None:
            self._scrolled.get_vadjustment().set_value(y)

    def _on_edit_button_clicked(self, button):
        """
            Edit playlist
            @param button as Gtk.Button
        """
        Lp().window.show_playlist_editor(self.__playlist_ids[0])

    def _on_current_changed(self, player):
        """
            Current song changed, update playing button
            @param player as Player
        """
        View._on_current_changed(self, player)
        self.__update_jump_button()


#######################
# PRIVATE             #
#######################

    def __set_duration(self):
        """
            Set playlist duration
        """
        duration = 0
        for playlist_id in self.__playlist_ids:
            duration += Lp().playlists.get_duration(playlist_id)

        hours = int(duration / 3600)
        mins = int(duration / 60)
        if hours > 0:
            mins -= hours * 60
            if mins > 0:
                self.__duration_label.set_text(_("%s h  %s m") % (hours, mins))
            else:
                self.__duration_label.set_text(_("%s h") % hours)
        else:
            self.__duration_label.set_text(_("%s m") % mins)

    def __update_jump_button(self):
        """
            Update jump button status
        """
        if Lp().player.current_track.id in self.__tracks:
            self.__jump_button.set_sensitive(True)
            artists = ", ".join(Lp().player.current_track.artists)
            self.__jump_button.set_tooltip_markup(
                "<b>%s</b>\n%s" %
                (GLib.markup_escape_text(artists),
                 GLib.markup_escape_text(Lp().player.current_track.name)))
        else:
            self.__jump_button.set_sensitive(False)
            self.__jump_button.set_tooltip_text("")

    def __on_playlist_add(self, manager, playlist_id, track_id, pos):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self.__playlist_ids:
            self.__playlists_widget.insert(track_id, pos)

    def __on_playlist_del(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self.__playlist_ids:
            self.__playlists_widget.remove(track_id)
Esempio n. 3
0
class PlaylistsView(View):
    """
        Show playlist tracks
    """

    def __init__(self, playlist_ids, editable=True):
        """
            Init PlaylistView
            @parma playlist ids as [int]
            @param editable as bool
        """
        View.__init__(self)
        self._tracks = []
        self._playlist_ids = playlist_ids
        self._signal_id1 = Lp().playlists.connect('playlist-add',
                                                  self._on_playlist_add)
        self._signal_id2 = Lp().playlists.connect('playlist-del',
                                                  self._on_playlist_del)

        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/PlaylistView.ui')
        builder.connect_signals(self)

        name = ""
        for playlist_id in playlist_ids:
            if playlist_id == Type.POPULARS:
                name += _("Popular tracks")+", "
            elif playlist_id == Type.RECENTS:
                name += _("Recently played")+", "
            elif playlist_id == Type.NEVER:
                name += _("Never played")+", "
            elif playlist_id == Type.RANDOMS:
                name += _("Random tracks")+", "
            elif playlist_id == Type.SEARCH:
                name += _("Search")+", "
            else:
                name += Lp().playlists.get_name(playlist_id)+", "
        builder.get_object('title').set_label(name[:-2])

        self._edit_button = builder.get_object('edit-button')
        self._jump_button = builder.get_object('jump-button')

        if len(playlist_ids) > 1 or (
           playlist_ids[0] < 0 and playlist_ids[0] != Type.LOVED) or\
                not editable:
            self._edit_button.hide()
        self._title = builder.get_object('title')

        self._playlists_widget = PlaylistsWidget(playlist_ids)
        self._playlists_widget.connect('populated', self._on_populated)
        self._playlists_widget.show()
        self.add(builder.get_object('widget'))
        self._viewport.add(self._playlists_widget)
        self._scrolled.set_property('expand', True)
        self.add(self._scrolled)

    def populate(self, tracks):
        """
            Populate view with tracks from playlist
            Thread safe
        """
        self._tracks = tracks
        mid_tracks = int(0.5+len(tracks)/2)
        self._playlists_widget.populate_list_left(tracks[:mid_tracks],
                                                  1)
        self._playlists_widget.populate_list_right(tracks[mid_tracks:],
                                                   mid_tracks + 1)

    def get_ids(self):
        """
            Return playlist ids
            @return id as [int]
        """
        return self._playlist_ids

    def stop(self):
        """
            Stop populating
        """
        self._playlists_widget.stop()

#######################
# PRIVATE             #
#######################
    def _get_children(self):
        """
            Return view children
        """
        return [self._playlists_widget]

    def _update_jump_button(self):
        """
            Update jump button status
        """
        if Lp().player.current_track.id in self._tracks:
            self._jump_button.set_sensitive(True)
            self._jump_button.set_tooltip_markup(
             "<b>%s</b>\n%s" % (escape(Lp().player.current_track.artist_names),
                                escape(Lp().player.current_track.name)))
        else:
            self._jump_button.set_sensitive(False)
            self._jump_button.set_tooltip_text('')

    def _on_playlist_add(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self._playlist_ids:
            self._playlists_widget.append(track_id)

    def _on_playlist_del(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self._playlist_ids:
            self._playlists_widget.remove(track_id)

    def _on_populated(self, widget):
        """
            Show current track
            @param widget as Gtk.Widget
        """
        self._update_jump_button()

    def _on_destroy(self, widget):
        """
            Disconnect signals
            @param widget as Gtk.Widget
        """
        View._on_destroy(self, widget)
        if self._signal_id1:
            Lp().playlists.disconnect(self._signal_id1)
            self._signal_id1 = None
        if self._signal_id2:
            Lp().playlists.disconnect(self._signal_id2)
            self._signal_id2 = None

    def _on_jump_button_clicked(self, button):
        """
            Scroll to current track
            @param button as Gtk.Button
        """
        y = self._playlists_widget.get_current_ordinate()
        if y is not None:
            self._scrolled.get_vadjustment().set_value(y)

    def _on_edit_button_clicked(self, button):
        """
            Edit playlist
            @param button as Gtk.Button
        """
        Lp().window.show_playlist_editor(self._playlist_ids[0])

    def _on_current_changed(self, player):
        """
            Current song changed, update playing button
            @param player as Player
        """
        View._on_current_changed(self, player)
        self._update_jump_button()
Esempio n. 4
0
class PlaylistsView(View):
    """
        Show playlist tracks
    """

    def __init__(self, playlist_ids, editable=True):
        """
            Init PlaylistView
            @parma playlist ids as [int]
            @param editable as bool
        """
        View.__init__(self)
        self._tracks = []
        self._playlist_ids = playlist_ids
        self._signal_id1 = Lp().playlists.connect('playlist-add',
                                                  self._on_playlist_add)
        self._signal_id2 = Lp().playlists.connect('playlist-del',
                                                  self._on_playlist_del)

        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/PlaylistView.ui')
        builder.connect_signals(self)

        builder.get_object('title').set_label(
                             ", ".join(Lp().playlists.get_names(playlist_ids)))

        self._edit_button = builder.get_object('edit-button')
        self._jump_button = builder.get_object('jump-button')

        if len(playlist_ids) > 1 or (
           playlist_ids[0] < 0 and playlist_ids[0] != Type.LOVED) or\
                not editable:
            self._edit_button.hide()

        self._playlists_widget = PlaylistsWidget(playlist_ids)
        self._playlists_widget.show()
        self.add(builder.get_object('widget'))
        self._viewport.add(self._playlists_widget)
        self._scrolled.set_property('expand', True)
        self.add(self._scrolled)

    def populate(self, tracks):
        """
            Populate view with tracks from playlist
            Thread safe
        """
        self._tracks = tracks
        self._update_jump_button()
        mid_tracks = int(0.5+len(tracks)/2)
        self._playlists_widget.populate_list_left(tracks[:mid_tracks],
                                                  1)
        self._playlists_widget.populate_list_right(tracks[mid_tracks:],
                                                   mid_tracks + 1)

    def get_ids(self):
        """
            Return playlist ids
            @return id as [int]
        """
        return self._playlist_ids

    def stop(self):
        """
            Stop populating
        """
        self._playlists_widget.stop()

#######################
# PRIVATE             #
#######################
    def _get_children(self):
        """
            Return view children
        """
        return [self._playlists_widget]

    def _update_jump_button(self):
        """
            Update jump button status
        """
        if Lp().player.current_track.id in self._tracks:
            self._jump_button.set_sensitive(True)
            self._jump_button.set_tooltip_markup(
             "<b>%s</b>\n%s" % (escape(Lp().player.current_track.artists),
                                escape(Lp().player.current_track.name)))
        else:
            self._jump_button.set_sensitive(False)
            self._jump_button.set_tooltip_text('')

    def _on_playlist_add(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self._playlist_ids:
            self._playlists_widget.append(track_id)

    def _on_playlist_del(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self._playlist_ids:
            self._playlists_widget.remove(track_id)

    def _on_populated(self, widget):
        """
            Show current track
            @param widget as LazyLoadingView
        """
        self._update_jump_button()

    def _on_destroy(self, widget):
        """
            Disconnect signals
            @param widget as Gtk.Widget
        """
        View._on_destroy(self, widget)
        if self._signal_id1:
            Lp().playlists.disconnect(self._signal_id1)
            self._signal_id1 = None
        if self._signal_id2:
            Lp().playlists.disconnect(self._signal_id2)
            self._signal_id2 = None

    def _on_jump_button_clicked(self, button):
        """
            Scroll to current track
            @param button as Gtk.Button
        """
        y = self._playlists_widget.get_current_ordinate()
        if y is not None:
            self._scrolled.get_vadjustment().set_value(y)

    def _on_edit_button_clicked(self, button):
        """
            Edit playlist
            @param button as Gtk.Button
        """
        Lp().window.show_playlist_editor(self._playlist_ids[0])

    def _on_current_changed(self, player):
        """
            Current song changed, update playing button
            @param player as Player
        """
        View._on_current_changed(self, player)
        self._update_jump_button()
Esempio n. 5
0
class PlaylistsView(View):
    """
        Show playlist tracks
    """

    def __init__(self, playlist_ids, editable=True):
        """
            Init PlaylistView
            @parma playlist ids as [int]
            @param editable as bool
        """
        View.__init__(self)
        self._tracks = []
        self._playlist_ids = playlist_ids
        self._signal_id1 = Lp().playlists.connect("playlist-add", self._on_playlist_add)
        self._signal_id2 = Lp().playlists.connect("playlist-del", self._on_playlist_del)

        builder = Gtk.Builder()
        builder.add_from_resource("/org/gnome/Lollypop/PlaylistView.ui")
        builder.connect_signals(self)

        builder.get_object("title").set_label(", ".join(Lp().playlists.get_names(playlist_ids)))

        self._edit_button = builder.get_object("edit-button")
        self._jump_button = builder.get_object("jump-button")

        if len(playlist_ids) > 1 or (playlist_ids[0] < 0 and playlist_ids[0] != Type.LOVED) or not editable:
            self._edit_button.hide()

        self._playlists_widget = PlaylistsWidget(playlist_ids)
        self._playlists_widget.show()
        self.add(builder.get_object("widget"))
        self._viewport.add(self._playlists_widget)
        self._scrolled.set_property("expand", True)
        self.add(self._scrolled)

    def populate(self, tracks):
        """
            Populate view with tracks from playlist
            Thread safe
        """
        # We are looking for middle
        # Ponderate with this:
        # Tracks with cover == 2
        # Tracks without cover == 1
        prev_album_id = None
        heights = {}
        total = 0
        idx = 0
        for track_id in tracks:
            track = Track(track_id)
            if track.album_id != prev_album_id:
                heights[idx] = 2
                total += 2
            else:
                heights[idx] = 1
                total += 1
            prev_album_id = track.album_id
            idx += 1
        half = int(total / 2 + 0.5)
        mid_tracks = 1
        count = 0
        for height in heights.values():
            count += height
            if count >= half:
                break
            mid_tracks += 1
        self._tracks = tracks
        self._update_jump_button()
        self._playlists_widget.populate_list_left(tracks[:mid_tracks], 1)
        self._playlists_widget.populate_list_right(tracks[mid_tracks:], mid_tracks + 1)

    def get_ids(self):
        """
            Return playlist ids
            @return id as [int]
        """
        return self._playlist_ids

    def stop(self):
        """
            Stop populating
        """
        self._playlists_widget.stop()

    #######################
    # PRIVATE             #
    #######################
    def _get_children(self):
        """
            Return view children
        """
        return [self._playlists_widget]

    def _update_jump_button(self):
        """
            Update jump button status
        """
        if Lp().player.current_track.id in self._tracks:
            self._jump_button.set_sensitive(True)
            artists = ", ".join(Lp().player.current_track.artists)
            self._jump_button.set_tooltip_markup(
                "<b>%s</b>\n%s" % (escape(artists), escape(Lp().player.current_track.name))
            )
        else:
            self._jump_button.set_sensitive(False)
            self._jump_button.set_tooltip_text("")

    def _on_playlist_add(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self._playlist_ids:
            self._playlists_widget.append(track_id)

    def _on_playlist_del(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self._playlist_ids:
            self._playlists_widget.remove(track_id)

    def _on_destroy(self, widget):
        """
            Disconnect signals
            @param widget as Gtk.Widget
        """
        View._on_destroy(self, widget)
        if self._signal_id1:
            Lp().playlists.disconnect(self._signal_id1)
            self._signal_id1 = None
        if self._signal_id2:
            Lp().playlists.disconnect(self._signal_id2)
            self._signal_id2 = None

    def _on_jump_button_clicked(self, button):
        """
            Scroll to current track
            @param button as Gtk.Button
        """
        y = self._playlists_widget.get_current_ordinate()
        if y is not None:
            self._scrolled.get_vadjustment().set_value(y)

    def _on_edit_button_clicked(self, button):
        """
            Edit playlist
            @param button as Gtk.Button
        """
        Lp().window.show_playlist_editor(self._playlist_ids[0])

    def _on_current_changed(self, player):
        """
            Current song changed, update playing button
            @param player as Player
        """
        View._on_current_changed(self, player)
        self._update_jump_button()
Esempio n. 6
0
class PlaylistsView(View):
    """
        Show playlist tracks
    """

    def __init__(self, playlist_ids, editable=True):
        """
            Init PlaylistView
            @parma playlist ids as [int]
            @param editable as bool
        """
        View.__init__(self, True)
        self.__tracks = []
        self.__playlist_ids = playlist_ids
        self.__signal_id1 = Lp().playlists.connect('playlist-add',
                                                   self.__on_playlist_add)
        self.__signal_id2 = Lp().playlists.connect('playlist-del',
                                                   self.__on_playlist_del)

        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/PlaylistView.ui')

        builder.get_object('title').set_label(
                             ", ".join(Lp().playlists.get_names(playlist_ids)))

        self.__edit_button = builder.get_object('edit-button')
        self.__jump_button = builder.get_object('jump-button')
        split_button = builder.get_object('split-button')
        if editable:
            split_button.set_active(not Lp().settings.get_value('split-view'))
        else:
            split_button.hide()

        if len(playlist_ids) > 1 or (
           playlist_ids[0] < 0 and playlist_ids[0] != Type.LOVED) or\
                not editable:
            self.__edit_button.hide()

        self.__playlists_widget = PlaylistsWidget(playlist_ids)
        self.__playlists_widget.set_filter_func(self._filter_func)
        self.__playlists_widget.show()
        self.add(builder.get_object('widget'))
        self._viewport.add(self.__playlists_widget)
        self._scrolled.set_property('expand', True)
        self.add(self._scrolled)
        # Connect signals after ui init
        # 'split-button' will emit a signal otherwise
        builder.connect_signals(self)

    def populate(self, tracks):
        """
            Populate view with tracks from playlist
            Thread safe
        """
        # We are looking for middle
        # Ponderate with this:
        # Tracks with cover == 2
        # Tracks without cover == 1
        prev_album_id = None
        heights = {}
        total = 0
        idx = 0
        for track_id in tracks:
            track = Track(track_id)
            if track.album_id != prev_album_id:
                heights[idx] = 2
                total += 2
            else:
                heights[idx] = 1
                total += 1
            prev_album_id = track.album_id
            idx += 1
        half = int(total / 2 + 0.5)
        mid_tracks = 1
        count = 0
        for height in heights.values():
            count += height
            if count >= half:
                break
            mid_tracks += 1
        self.__tracks = tracks
        self.__update_jump_button()
        self.__playlists_widget.populate_list_left(tracks[:mid_tracks],
                                                   1)
        self.__playlists_widget.populate_list_right(tracks[mid_tracks:],
                                                    mid_tracks + 1)

    def get_ids(self):
        """
            Return playlist ids
            @return id as [int]
        """
        return self.__playlist_ids

    def stop(self):
        """
            Stop populating
        """
        self.__playlists_widget.stop()

#######################
# PROTECTED           #
#######################
    def _get_children(self):
        """
            Return view children
        """
        return [self.__playlists_widget]

    def _on_search_changed(self, entry):
        """
            Update filter
            @param entry as Gtk.Entry
        """
        self._filter = entry.get_text()
        for box in self.__playlists_widget.boxes:
            box.invalidate_filter()

    def _on_destroy(self, widget):
        """
            Disconnect signals
            @param widget as Gtk.Widget
        """
        View._on_destroy(self, widget)
        if self.__signal_id1:
            Lp().playlists.disconnect(self.__signal_id1)
            self.__signal_id1 = None
        if self.__signal_id2:
            Lp().playlists.disconnect(self.__signal_id2)
            self.__signal_id2 = None

    def _on_split_button_toggled(self, button):
        """
            Split/Unsplit view
        """
        Lp().settings.set_value('split-view',
                                GLib.Variant('b', not button.get_active()))
        self.__playlists_widget.update_allocation()

    def _on_jump_button_clicked(self, button):
        """
            Scroll to current track
            @param button as Gtk.Button
        """
        y = self.__playlists_widget.get_current_ordinate()
        if y is not None:
            self._scrolled.get_vadjustment().set_value(y)

    def _on_edit_button_clicked(self, button):
        """
            Edit playlist
            @param button as Gtk.Button
        """
        Lp().window.show_playlist_editor(self.__playlist_ids[0])

    def _on_current_changed(self, player):
        """
            Current song changed, update playing button
            @param player as Player
        """
        View._on_current_changed(self, player)
        self.__update_jump_button()

#######################
# PRIVATE             #
#######################
    def __update_jump_button(self):
        """
            Update jump button status
        """
        if Lp().player.current_track.id in self.__tracks:
            self.__jump_button.set_sensitive(True)
            artists = ", ".join(Lp().player.current_track.artists)
            self.__jump_button.set_tooltip_markup(
             "<b>%s</b>\n%s" % (GLib.markup_escape_text(artists),
                                GLib.markup_escape_text(
                                              Lp().player.current_track.name)))
        else:
            self.__jump_button.set_sensitive(False)
            self.__jump_button.set_tooltip_text('')

    def __on_playlist_add(self, manager, playlist_id, track_id, pos):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self.__playlist_ids:
            self.__playlists_widget.insert(track_id, pos)

    def __on_playlist_del(self, manager, playlist_id, track_id):
        """
            Update tracks widgets
            @param manager as PlaylistsManager
            @param playlist id as int
            @param track id as int
        """
        if playlist_id in self.__playlist_ids:
            self.__playlists_widget.remove(track_id)