2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
#include "internetservice.h"
|
|
|
|
#include "internetmodel.h"
|
2011-05-30 16:54:48 +02:00
|
|
|
#include "core/logging.h"
|
2011-01-10 23:26:13 +01:00
|
|
|
#include "core/mergedproxymodel.h"
|
|
|
|
#include "core/mimedata.h"
|
2011-02-10 23:24:17 +01:00
|
|
|
#include "ui/iconloader.h"
|
|
|
|
|
|
|
|
#include <QMenu>
|
2012-06-27 21:19:30 +02:00
|
|
|
#include <QStandardItem>
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
InternetService::InternetService(const QString& name, Application* app,
|
|
|
|
InternetModel* model, QObject* parent)
|
2011-05-30 16:54:48 +02:00
|
|
|
: QObject(parent),
|
2012-02-12 14:41:50 +01:00
|
|
|
app_(app),
|
2010-05-09 17:51:04 +02:00
|
|
|
model_(model),
|
2011-02-10 23:24:17 +01:00
|
|
|
name_(name),
|
|
|
|
append_to_playlist_(NULL),
|
|
|
|
replace_playlist_(NULL),
|
|
|
|
open_in_new_playlist_(NULL),
|
|
|
|
separator_(NULL)
|
2009-12-26 16:13:38 +01:00
|
|
|
{
|
|
|
|
}
|
2010-01-18 03:23:55 +01:00
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
QList<QAction*> InternetService::GetPlaylistActions() {
|
2011-02-10 23:24:17 +01:00
|
|
|
if(!separator_) {
|
|
|
|
separator_ = new QAction(this);
|
|
|
|
separator_->setSeparator(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QList<QAction*>() << GetAppendToPlaylistAction()
|
|
|
|
<< GetReplacePlaylistAction()
|
|
|
|
<< GetOpenInNewPlaylistAction()
|
|
|
|
<< separator_;
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
QAction* InternetService::GetAppendToPlaylistAction() {
|
2011-02-10 23:24:17 +01:00
|
|
|
if(!append_to_playlist_) {
|
|
|
|
append_to_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
|
|
|
|
tr("Append to current playlist"), this);
|
|
|
|
connect(append_to_playlist_, SIGNAL(triggered()), this, SLOT(AppendToPlaylist()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return append_to_playlist_;
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
QAction* InternetService::GetReplacePlaylistAction() {
|
2011-02-10 23:24:17 +01:00
|
|
|
if(!replace_playlist_) {
|
|
|
|
replace_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
|
|
|
|
tr("Replace current playlist"), this);
|
|
|
|
connect(replace_playlist_, SIGNAL(triggered()), this, SLOT(ReplacePlaylist()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return replace_playlist_;
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
QAction* InternetService::GetOpenInNewPlaylistAction() {
|
2011-02-10 23:24:17 +01:00
|
|
|
if(!open_in_new_playlist_) {
|
|
|
|
open_in_new_playlist_ = new QAction(IconLoader::Load("document-new"),
|
|
|
|
tr("Open in new playlist"), this);
|
|
|
|
connect(open_in_new_playlist_, SIGNAL(triggered()), this, SLOT(OpenInNewPlaylist()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return open_in_new_playlist_;
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetService::AddItemToPlaylist(const QModelIndex& index, AddMode add_mode) {
|
2011-02-09 19:23:14 +01:00
|
|
|
AddItemsToPlaylist(QModelIndexList() << index, add_mode);
|
2011-01-10 23:26:13 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode) {
|
2011-01-10 23:26:13 +01:00
|
|
|
QMimeData* data = model()->merged_model()->mimeData(
|
|
|
|
model()->merged_model()->mapFromSource(indexes));
|
|
|
|
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
2011-02-09 19:23:14 +01:00
|
|
|
mime_data->clear_first_ = add_mode == AddMode_Replace;
|
2011-02-16 19:29:35 +01:00
|
|
|
mime_data->open_in_new_playlist_ = add_mode == AddMode_OpenInNew;
|
2011-01-10 23:26:13 +01:00
|
|
|
}
|
|
|
|
emit AddToPlaylistSignal(data);
|
|
|
|
}
|
2011-02-10 23:24:17 +01:00
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetService::AppendToPlaylist() {
|
2012-03-11 15:44:43 +01:00
|
|
|
AddItemsToPlaylist(model()->selected_indexes(), AddMode_Append);
|
2011-02-10 23:24:17 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetService::ReplacePlaylist() {
|
2012-03-11 15:44:43 +01:00
|
|
|
AddItemsToPlaylist(model()->selected_indexes(), AddMode_Replace);
|
2011-02-10 23:24:17 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetService::OpenInNewPlaylist() {
|
2012-03-11 15:44:43 +01:00
|
|
|
AddItemsToPlaylist(model()->selected_indexes(), AddMode_OpenInNew);
|
2011-02-10 23:24:17 +01:00
|
|
|
}
|
2012-06-27 21:19:30 +02:00
|
|
|
|
|
|
|
QStandardItem* InternetService::CreateSongItem(const Song& song) {
|
|
|
|
QStandardItem* item = new QStandardItem(song.PrettyTitleWithArtist());
|
|
|
|
item->setData(InternetModel::Type_Track, InternetModel::Role_Type);
|
|
|
|
item->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
|
|
|
item->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
|
|
|
item->setData(song.url(), InternetModel::Role_Url);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|