Example #1
0
 def _add_tracks(self, widget, tracks, position=0):
     """
         Add tracks to widget
         @param widget as Gtk.ListBox
         @param tracks as [Track]
     """
     for track in tracks:
         # If user does not want to show real tracknumber and we are
         # in album view, calculate a fake tracknumber
         if not self.__show_tag_tracknumber and\
                 self.view_type & (ViewType.ALBUM | ViewType.ARTIST):
             track.set_number(position + 1)
         row = TrackRow(track, self.__album.artist_ids, self.view_type)
         row.show()
         row.connect("removed", self.__on_track_row_removed)
         widget.add(row)
         position += 1
    def __add_tracks(self, widgets, disc_number, previous_row=None):
        """
            Add tracks for to tracks widget
            @param widgets as OrderedDict
            @param disc number as int
            @param previous_row as TrackRow
        """
        if self.__cancellable.is_cancelled():
            return

        widget = next(iter(widgets))
        widgets.move_to_end(widget)
        tracks = widgets[widget]

        if not tracks:
            if len(self.__discs_to_load) == 0:
                self.__populated = True
            self._on_tracks_populated(disc_number)
            self._tracks_widget_left[disc_number].show()
            self._tracks_widget_right[disc_number].show()
            if self._list_type & RowListType.DND:
                self.__linking()
            return

        (track, position) = tracks.pop(0)
        if not App().settings.get_value("show-tag-tracknumber"):
            track.set_number(position + 1)
        track.set_featuring_ids(self._album.artist_ids)
        row = TrackRow(track, self._list_type)
        if self._list_type & RowListType.DND:
            row.set_previous_row(previous_row)
            if previous_row is not None:
                previous_row.set_next_row(row)
            row.connect("destroy", self.__on_row_destroy)
            row.connect("insert-track", self.__on_insert_track)
            row.connect("insert-album", self.__on_insert_album)
            row.connect("remove-track", self.__on_remove_track)
            row.connect("do-selection", self.__on_do_selection)
        row.show()
        widget.insert(row, position)
        GLib.idle_add(self.__add_tracks, widgets, disc_number, row)
Example #3
0
 def __on_insert_track(self, row, new_track_id, down):
     """
         Insert a new row at position
         @param row as PlaylistRow
         @param new_track_id as int
         @param down as bool
     """
     track = Track(new_track_id)
     # If same album, add track to album
     if track.album.id == row.track.album.id:
         position = self.children.index(row)
         new_row = TrackRow(track, track.album.artist_ids, self._view_type)
         new_row.connect("destroy", self.__on_row_destroy)
         new_row.connect("insert-track", self.__on_insert_track)
         new_row.connect("insert-album", self.__on_insert_album)
         new_row.connect("remove-track", self.__on_remove_track)
         new_row.connect("do-selection", self.__on_do_selection)
         new_row.show()
         if down:
             position += 1
             new_row.set_previous_row(row)
             new_row.set_next_row(row.next_row)
             if row.next_row is not None:
                 row.next_row.set_previous_row(new_row)
             row.set_next_row(new_row)
         else:
             new_row.set_previous_row(row.previous_row)
             new_row.set_next_row(row)
             if row.previous_row is not None:
                 row.previous_row.set_next_row(new_row)
             row.set_previous_row(new_row)
         new_row.update_number(position + 1)
         row.get_parent().insert(new_row, position)
         row.track.album.insert_track(track, position)
         if new_row.previous_row is not None and\
                 new_row.previous_row.track.id ==\
                 App().player.current_track.id:
             App().player.set_next()
             App().player.set_prev()
     # Else, we need to insert a new album with the track
     else:
         # Backup album as __destroy_split() will unset it
         album = row.track.album
         split_album = Album(album.id)
         split_tracks = self.__get_split_tracks(row, down)
         # Create new album
         track.album.set_tracks([track])
         # We use DNDRow because we know that if tracks are DND
         # we are DND. Little hack
         if len(self.children) == len(split_tracks):
             if self.previous_row is not None:
                 album = self.previous_row.album
             else:
                 album = Album()
         elif not split_tracks:
             if self.next_row is not None:
                 album = self.next_row.album
             else:
                 album = Album()
         if album.id == track.album.id:
             track.set_album(album)
             if down:
                 self.next_row.prepend_rows([track])
             else:
                 self.previous_row.append_rows([track])
         else:
             self.emit("insert-album-after",
                       album,
                       track.album)
         # Create split album
         if split_tracks:
             split_album.set_tracks(split_tracks)
             if album.id == track.album.id:
                 self.emit("insert-album-after", album, split_album)
             else:
                 self.emit("insert-album-after", track.album, split_album)
             self.__destroy_split(row, down)