Make double-clicking on radio items work properly again. It's hacks all the way down...

This commit is contained in:
David Sansome 2010-06-18 15:31:49 +00:00
parent 43ae900852
commit d3be5a4215
3 changed files with 16 additions and 10 deletions

View File

@ -47,6 +47,7 @@
using boost::shared_ptr;
const char* Playlist::kRowsMimetype = "application/x-clementine-playlist-rows";
const char* Playlist::kPlayNowMimetype = "application/x-clementine-play-now";
Playlist::Playlist(PlaylistBackend* backend, int id, QObject *parent)
: QAbstractListModel(parent),
@ -462,7 +463,7 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro
InsertSongs(song_data->songs, row);
} else if (const RadioMimeData* radio_data = qobject_cast<const RadioMimeData*>(data)) {
// Dragged from the Radio pane
InsertRadioStations(radio_data->items, row);
InsertRadioStations(radio_data->items, row, data->hasFormat(kPlayNowMimetype));
} else if (data->hasFormat(kRowsMimetype)) {
// Dragged from the playlist
// Rearranging it is tricky...
@ -649,7 +650,7 @@ QModelIndex Playlist::InsertSongs(const SongList& songs, int pos) {
return InsertItems(items, pos);
}
QModelIndex Playlist::InsertRadioStations(const QList<RadioItem*>& items, int pos) {
QModelIndex Playlist::InsertRadioStations(const QList<RadioItem*>& items, int pos, bool play_now) {
PlaylistItemList playlist_items;
QList<QUrl> song_urls;
foreach (RadioItem* item, items) {
@ -665,7 +666,7 @@ QModelIndex Playlist::InsertRadioStations(const QList<RadioItem*>& items, int po
}
if (!song_urls.isEmpty()) {
InsertUrls(song_urls, false, pos);
InsertUrls(song_urls, play_now, pos);
}
return InsertItems(playlist_items, pos);

View File

@ -83,6 +83,7 @@ class Playlist : public QAbstractListModel {
};
static const char* kRowsMimetype;
static const char* kPlayNowMimetype;
static bool CompareItems(int column, Qt::SortOrder order,
boost::shared_ptr<PlaylistItem> a,
@ -132,7 +133,7 @@ class Playlist : public QAbstractListModel {
QModelIndex InsertLibraryItems(const SongList& items, int pos = -1);
QModelIndex InsertMagnatuneItems(const SongList& items, int pos = -1);
QModelIndex InsertSongs(const SongList& items, int pos = -1);
QModelIndex InsertRadioStations(const QList<RadioItem*>& items, int pos = -1);
QModelIndex InsertRadioStations(const QList<RadioItem*>& items, int pos = -1, bool play_now = false);
void InsertUrls(const QList<QUrl>& urls, bool play_now, int pos = -1);
void StopAfter(int row);
void ReloadItems(const QList<int>& rows);

View File

@ -842,15 +842,19 @@ void MainWindow::RadioDoubleClick(const QModelIndex& index) {
if (!data)
return;
if (player_->GetState() != Engine::Playing)
data->setData(Playlist::kPlayNowMimetype, "true");
int rows = playlists_->current()->rowCount();
playlists_->current()->dropMimeData(data.get(), Qt::CopyAction, -1, 0, QModelIndex());
QModelIndex first_song = playlists_->current()->index(0, 0);
if (!playlists_->current()->proxy()->mapFromSource(first_song).isValid()) {
// The first song doesn't match the filter, so don't play it
return;
}
if (player_->GetState() != Engine::Playing && playlists_->current()->rowCount() > rows) {
QModelIndex first_song = playlists_->current()->index(rows, 0);
if (!playlists_->current()->proxy()->mapFromSource(first_song).isValid()) {
// The first song doesn't match the filter, so don't play it
return;
}
if (first_song.isValid() && player_->GetState() != Engine::Playing) {
playlists_->SetActiveToCurrent();
player_->PlayAt(first_song.row(), Engine::First, true);
}