Merge branch 'skip_track' of https://github.com/asiviero/Clementine into asiviero-skip_track

Conflicts:
	src/playlist/playlist.cpp
	src/playlist/playlistitem.h
	src/ui/mainwindow.cpp
This commit is contained in:
Dave Sansome 2014-02-08 12:47:35 +11:00 committed by David Sansome
commit 89369029ab
6 changed files with 77 additions and 6 deletions

View File

@ -361,6 +361,14 @@ QVariant Playlist::data(const QModelIndex& index, int role) const {
}
return QVariant();
case Qt::FontRole:
if (items_[index.row()]->GetShouldSkip()) {
QFont track_font;
track_font.setStrikeOut(true);
return track_font;
}
return QVariant();
default:
return QVariant();
}
@ -462,14 +470,21 @@ int Playlist::NextVirtualIndex(int i, bool ignore_repeat_track) const {
if (!album_only) {
++i;
// Advance i until we find any track that is in the filter
while (i < virtual_items_.count() && !FilterContainsVirtualIndex(i)) ++i;
// Advance i until we find any track that is in the filter, skipping
// the selected to be skipped
while (i < virtual_items_.count() &&
(!FilterContainsVirtualIndex(i) || item_at(virtual_items_[i])->GetShouldSkip())) {
++i;
}
return i;
}
// We need to advance i until we get something else on the same album
Song last_song = current_item_metadata();
for (int j = i + 1; j < virtual_items_.count(); ++j) {
for (int j=i+1 ; j<virtual_items_.count(); ++j) {
if (item_at(virtual_items_[j])->GetShouldSkip()) {
continue;
}
Song this_song = item_at(virtual_items_[j])->Metadata();
if (((last_song.is_compilation() && this_song.is_compilation()) ||
last_song.artist() == this_song.artist()) &&
@ -502,13 +517,17 @@ int Playlist::PreviousVirtualIndex(int i, bool ignore_repeat_track) const {
--i;
// Decrement i until we find any track that is in the filter
while (i >= 0 && !FilterContainsVirtualIndex(i)) --i;
while (i>=0 && (!FilterContainsVirtualIndex(i) || item_at(virtual_items_[i])->GetShouldSkip()))
--i;
return i;
}
// We need to decrement i until we get something else on the same album
Song last_song = current_item_metadata();
for (int j = i - 1; j >= 0; --j) {
for (int j=i-1 ; j>=0; --j) {
if (item_at(virtual_items_[j])->GetShouldSkip()) {
continue;
}
Song this_song = item_at(virtual_items_[j])->Metadata();
if (((last_song.is_compilation() && this_song.is_compilation()) ||
last_song.artist() == this_song.artist()) &&
@ -2097,3 +2116,10 @@ bool Playlist::ApplyValidityOnCurrentSong(const QUrl& url, bool valid) {
void Playlist::SetColumnAlignment(const ColumnAlignmentMap& alignment) {
column_alignments_ = alignment;
}
void Playlist::SkipTracks(const QModelIndexList &source_indexes) {
foreach (const QModelIndex& source_index, source_indexes) {
PlaylistItemPtr track_to_skip = item_at(source_index.row());
track_to_skip->SetShouldSkip(!((track_to_skip)->GetShouldSkip()));
}
}

View File

@ -81,6 +81,8 @@ class Playlist : public QAbstractListModel {
QObject* parent = 0);
~Playlist();
void SkipTracks(const QModelIndexList &source_indexes);
// Always add new columns to the end of this enum - the values are persisted
enum Column {
Column_Title = 0,

View File

@ -113,3 +113,9 @@ QColor PlaylistItem::GetCurrentForegroundColor() const {
bool PlaylistItem::HasCurrentForegroundColor() const {
return !foreground_colors_.isEmpty();
}
void PlaylistItem::SetShouldSkip(bool val) {
should_skip_ = val;
}
bool PlaylistItem::GetShouldSkip() const {
return should_skip_;
}

View File

@ -32,7 +32,7 @@ class SqlRow;
class PlaylistItem : public std::enable_shared_from_this<PlaylistItem> {
public:
PlaylistItem(const QString& type) : type_(type) {}
PlaylistItem(const QString& type) : should_skip_(false), type_(type) {}
virtual ~PlaylistItem();
static PlaylistItem* NewFromType(const QString& type);
@ -91,8 +91,12 @@ class PlaylistItem : public std::enable_shared_from_this<PlaylistItem> {
// invalid so you might want to check that its id is not equal to -1
// before actually using it.
virtual bool IsLocalLibraryItem() const { return false; }
void SetShouldSkip(bool val);
bool GetShouldSkip() const;
protected:
bool should_skip_;
enum DatabaseColumn { Column_LibraryId, Column_InternetService, };
virtual QVariant DatabaseValue(DatabaseColumn) const {

View File

@ -568,6 +568,9 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
playlist_queue_ = playlist_menu_->addAction("", this, SLOT(PlaylistQueue()));
playlist_queue_->setShortcut(QKeySequence("Ctrl+D"));
ui_->playlist->addAction(playlist_queue_);
playlist_skip_ = playlist_menu_->addAction("", this, SLOT(PlaylistSkip()));
ui_->playlist->addAction(playlist_skip_);
playlist_menu_->addSeparator();
playlist_menu_->addAction(ui_->action_remove_from_playlist);
playlist_undoredo_ = playlist_menu_->addSeparator();
@ -1490,6 +1493,8 @@ void MainWindow::PlaylistRightClick(const QPoint& global_pos,
int streams = 0;
int in_queue = 0;
int not_in_queue = 0;
int in_skipped = 0;
int not_in_skipped = 0;
foreach(const QModelIndex & index, selection) {
if (index.column() != 0) continue;
@ -1509,6 +1514,12 @@ void MainWindow::PlaylistRightClick(const QPoint& global_pos,
not_in_queue++;
else
in_queue++;
if (item->GetShouldSkip()) {
in_skipped++;
} else {
not_in_skipped++;
}
}
int all = not_in_queue + in_queue;
@ -1550,6 +1561,15 @@ void MainWindow::PlaylistRightClick(const QPoint& global_pos,
else
playlist_queue_->setText(tr("Toggle queue status"));
if (in_skipped == 1 && not_in_skipped == 0)
playlist_skip_->setText(tr("Unskip track"));
else if (in_skipped > 1 && not_in_skipped == 0)
playlist_skip_->setText(tr("Unskip selected tracks"));
else if (in_skipped == 0 && not_in_skipped == 1)
playlist_skip_->setText(tr("Skip track"));
else if (in_skipped == 0 && not_in_skipped > 1)
playlist_skip_->setText(tr("Skip selected tracks"));
if (not_in_queue == 0)
playlist_queue_->setIcon(IconLoader::Load("go-previous"));
else
@ -2204,6 +2224,17 @@ void MainWindow::PlaylistQueue() {
app_->playlist_manager()->current()->queue()->ToggleTracks(indexes);
}
void MainWindow::PlaylistSkip() {
QModelIndexList indexes;
foreach(const QModelIndex & proxy_index,
ui_->playlist->view()->selectionModel()->selectedRows()) {
indexes << app_->playlist_manager()->current()->proxy()->mapToSource(
proxy_index);
}
app_->playlist_manager()->current()->SkipTracks(indexes);
}
void MainWindow::PlaylistCopyToDevice() {
QModelIndexList proxy_indexes =
ui_->playlist->view()->selectionModel()->selectedRows();

View File

@ -152,6 +152,7 @@ signals:
void PlaylistPlay();
void PlaylistStopAfter();
void PlaylistQueue();
void PlaylistSkip();
void PlaylistRemoveCurrent();
void PlaylistEditFinished(const QModelIndex& index);
void EditTracks();
@ -341,6 +342,7 @@ signals:
QAction* playlist_delete_;
QAction* playlist_open_in_browser_;
QAction* playlist_queue_;
QAction* playlist_skip_;
QAction* playlist_add_to_another_;
QList<QAction*> playlistitem_actions_;
QAction* playlistitem_actions_separator_;