private void EnqueueId (int trackId, bool prepend, bool generated)
{
if (trackId <= 0) {
return;
}
long view_order;
if (prepend && current_track != null) {
// We are going to prepend the track to the play queue, which means
// adding it after the current_track.
view_order = CurrentTrackViewOrder;
if (ServiceManager.PlayerEngine.IsPlaying (current_track)) {
view_order++;
}
} else {
if (generated) {
// view_order will point after the last track in the queue.
view_order = MaxViewOrder;
}
else {
// view_order will point after the last non-generated track in the queue.
view_order = ServiceManager.DbConnection.Query<long> (@"
SELECT MAX(ViewOrder) + 1
FROM CorePlaylistEntries
WHERE PlaylistID = ? AND Generated = 0",
DbId
);
}
}
// Increment the order of all tracks after view_order
ServiceManager.DbConnection.Execute (@"
UPDATE CorePlaylistEntries
SET ViewOrder = ViewOrder + 1
WHERE PlaylistID = ? AND ViewOrder >= ?",
DbId, view_order
);
// Add the track to the queue using the view order calculated above.
ServiceManager.DbConnection.Execute (@"
INSERT INTO CorePlaylistEntries
(PlaylistID, TrackID, ViewOrder, Generated)
VALUES (?, ?, ?, ?)",
DbId, trackId, view_order, generated ? 1 : 0
);
if (!generated) {
shuffler.RecordShuffleModification (trackId, ShuffleModificationType.Insertion);
}
OnTracksAdded ();
NotifyUser ();
}