Support dragging a smart playlist into a playlist

This commit is contained in:
David Sansome 2010-10-24 16:40:19 +00:00
parent a2595025b8
commit f8fd0e578c
8 changed files with 71 additions and 12 deletions

View File

@ -284,6 +284,7 @@ set(HEADERS
radio/savedradio.h
radio/somafmservice.h
smartplaylists/generatormimedata.h
smartplaylists/playlistgenerator.h
smartplaylists/playlistgeneratorinserter.h
smartplaylists/smartplaylistcontainer.h

View File

@ -32,7 +32,9 @@
#include "radio/radiomodel.h"
#include "radio/radioplaylistitem.h"
#include "radio/savedradio.h"
#include "smartplaylists/generatormimedata.h"
#include "smartplaylists/playlistgeneratorinserter.h"
#include "smartplaylists/smartplaylistmodel.h"
#include <QtDebug>
#include <QMimeData>
@ -493,7 +495,6 @@ void Playlist::set_current_index(int i) {
}
Qt::ItemFlags Playlist::flags(const QModelIndex &index) const {
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if(column_is_editable((Column)index.column()))
@ -506,7 +507,9 @@ Qt::ItemFlags Playlist::flags(const QModelIndex &index) const {
}
QStringList Playlist::mimeTypes() const {
return QStringList() << "text/uri-list" << kRowsMimetype;
qDebug() << __PRETTY_FUNCTION__;
return QStringList() << "text/uri-list" << kRowsMimetype
<< SmartPlaylistModel::kMimeType;
}
Qt::DropActions Playlist::supportedDropActions() const {
@ -530,6 +533,8 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro
} else if (const RadioMimeData* radio_data = qobject_cast<const RadioMimeData*>(data)) {
// Dragged from the Radio pane
InsertRadioStations(radio_data->items, row, data->hasFormat(kPlayNowMimetype));
} else if (const GeneratorMimeData* generator_data = qobject_cast<const GeneratorMimeData*>(data)) {
InsertSmartPlaylist(generator_data->generator_, row, data->hasFormat(kPlayNowMimetype));
} else if (data->hasFormat(kRowsMimetype)) {
// Dragged from the playlist
// Rearranging it is tricky...

View File

@ -169,7 +169,6 @@ class Playlist : public QAbstractListModel {
void sort(int column, Qt::SortOrder order);
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
public slots:
void set_current_index(int index);
void Paused();

View File

@ -0,0 +1,33 @@
/* This file is part of Clementine.
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/>.
*/
#ifndef GENERATORMIMEDATA_H
#define GENERATORMIMEDATA_H
#include <QMimeData>
#include "playlistgenerator_fwd.h"
class GeneratorMimeData : public QMimeData {
Q_OBJECT
public:
GeneratorMimeData(PlaylistGeneratorPtr generator) : generator_(generator) {}
PlaylistGeneratorPtr generator_;
};
#endif // GENERATORMIMEDATA_H

View File

@ -24,7 +24,6 @@ SmartPlaylistContainer::SmartPlaylistContainer(QWidget *parent)
: QWidget(parent),
ui_(new Ui_SmartPlaylistContainer),
first_show_(true),
library_(NULL),
model_(new SmartPlaylistModel(this)),
playlist_manager_(NULL)
{
@ -39,6 +38,10 @@ SmartPlaylistContainer::~SmartPlaylistContainer() {
delete ui_;
}
void SmartPlaylistContainer::set_library(LibraryBackend* library) {
model_->set_library(library);
}
void SmartPlaylistContainer::showEvent(QShowEvent*) {
if (!first_show_)
return;
@ -50,7 +53,7 @@ void SmartPlaylistContainer::showEvent(QShowEvent*) {
}
void SmartPlaylistContainer::Play(const QModelIndex& index, bool as_new, bool clear) {
PlaylistGeneratorPtr generator = model_->CreateGenerator(index, library_);
PlaylistGeneratorPtr generator = model_->CreateGenerator(index);
if (!generator)
return;

View File

@ -35,7 +35,7 @@ public:
SmartPlaylistContainer(QWidget* parent);
~SmartPlaylistContainer();
void set_library(LibraryBackend* library) { library_ = library; }
void set_library(LibraryBackend* library);
void set_playlists(PlaylistManager* playlist_manager) { playlist_manager_ = playlist_manager; }
protected:
@ -48,7 +48,6 @@ private:
Ui_SmartPlaylistContainer* ui_;
bool first_show_;
LibraryBackend* library_;
SmartPlaylistModel* model_;
PlaylistManager* playlist_manager_;
};

View File

@ -14,6 +14,7 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "generatormimedata.h"
#include "playlistgenerator.h"
#include "smartplaylistmodel.h"
#include "ui/iconloader.h"
@ -21,9 +22,11 @@
#include <QSettings>
const char* SmartPlaylistModel::kSettingsGroup = "SmartPlaylists";
const char* SmartPlaylistModel::kMimeType = "application/x-clementine-smart-playlist-generator";
SmartPlaylistModel::SmartPlaylistModel(QObject* parent)
: QStandardItemModel(parent),
library_(NULL),
container_icon_(IconLoader::Load("folder")),
playlist_icon_(IconLoader::Load("view-media-playlist")),
smart_item_(CreateContainer(tr("Smart playlists"), "smart")),
@ -94,8 +97,7 @@ void SmartPlaylistModel::SaveDefaultQuery(QSettings* s, int i,
if (!order.isEmpty()) s->setValue("order", order);
}
PlaylistGeneratorPtr SmartPlaylistModel::CreateGenerator(
const QModelIndex& index, LibraryBackend* library) const {
PlaylistGeneratorPtr SmartPlaylistModel::CreateGenerator(const QModelIndex& index) const {
PlaylistGeneratorPtr ret;
// Get the item
@ -124,7 +126,17 @@ PlaylistGeneratorPtr SmartPlaylistModel::CreateGenerator(
return ret;
// Initialise the generator
ret->set_library(library);
ret->set_library(library_);
ret->Load(s);
return ret;
}
QMimeData* SmartPlaylistModel::mimeData(const QModelIndexList& indexes) const {
PlaylistGeneratorPtr generator = CreateGenerator(indexes.first());
if (!generator)
return NULL;
GeneratorMimeData* data = new GeneratorMimeData(generator);
data->setData(kMimeType, QByteArray());
return data;
}

View File

@ -47,9 +47,14 @@ public:
};
static const char* kSettingsGroup;
static const char* kMimeType;
PlaylistGeneratorPtr CreateGenerator(const QModelIndex& index,
LibraryBackend* library) const;
void set_library(LibraryBackend* library) { library_ = library; }
PlaylistGeneratorPtr CreateGenerator(const QModelIndex& index) const;
// QAbstractItemModel
QMimeData* mimeData(const QModelIndexList& indexes) const;
private:
void Load(const char* name, QStandardItem* parent);
@ -61,6 +66,8 @@ private:
QStandardItem* CreateContainer(const QString& name, const QString& group);
private:
LibraryBackend* library_;
QIcon container_icon_;
QIcon playlist_icon_;