2010-06-12 17:18:16 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-06-12 17:18:16 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "albumcovermanagerlist.h"
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
2010-06-12 17:18:16 +02:00
|
|
|
|
2010-06-12 19:32:27 +02:00
|
|
|
#include <QDropEvent>
|
2010-06-12 17:18:16 +02:00
|
|
|
#include <QUrl>
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include "albumcovermanager.h"
|
|
|
|
#include "library/librarybackend.h"
|
|
|
|
#include "playlist/songmimedata.h"
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
AlbumCoverManagerList::AlbumCoverManagerList(QWidget* parent)
|
|
|
|
: QListWidget(parent), manager_(nullptr) {}
|
2010-06-12 17:18:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QMimeData* AlbumCoverManagerList::mimeData(const QList<QListWidgetItem*> items)
|
|
|
|
const {
|
2010-06-12 17:18:16 +02:00
|
|
|
// Get songs
|
|
|
|
SongList songs;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (QListWidgetItem* item : items) {
|
2010-06-12 17:18:16 +02:00
|
|
|
songs << manager_->GetSongsInAlbum(indexFromItem(item));
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (songs.isEmpty()) return nullptr;
|
2010-06-12 17:18:16 +02:00
|
|
|
|
|
|
|
// Get URLs from the songs
|
|
|
|
QList<QUrl> urls;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& song : songs) {
|
|
|
|
urls << song.url();
|
|
|
|
}
|
2010-06-12 17:18:16 +02:00
|
|
|
|
|
|
|
// Get the QAbstractItemModel data so the picture works
|
2014-02-06 14:48:00 +01:00
|
|
|
std::unique_ptr<QMimeData> orig_data(QListWidget::mimeData(items));
|
2010-06-12 17:18:16 +02:00
|
|
|
|
|
|
|
SongMimeData* mime_data = new SongMimeData;
|
|
|
|
mime_data->backend = manager_->backend();
|
|
|
|
mime_data->songs = songs;
|
|
|
|
mime_data->setUrls(urls);
|
2014-02-07 16:34:20 +01:00
|
|
|
mime_data->setData(orig_data->formats()[0],
|
|
|
|
orig_data->data(orig_data->formats()[0]));
|
2010-06-12 17:18:16 +02:00
|
|
|
return mime_data;
|
|
|
|
}
|
2010-06-12 19:32:27 +02:00
|
|
|
|
|
|
|
void AlbumCoverManagerList::dropEvent(QDropEvent* e) {
|
|
|
|
// Set movement to Static just for this dropEvent so the user can't move the
|
|
|
|
// album covers. If it's set to Static all the time then the user can't even
|
|
|
|
// drag to the playlist
|
|
|
|
QListWidget::Movement old_movement = movement();
|
|
|
|
setMovement(QListWidget::Static);
|
|
|
|
QListWidget::dropEvent(e);
|
|
|
|
setMovement(old_movement);
|
|
|
|
}
|