1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "internetservice.h"
19
#include "internetmodel.h"
20
#include "core/logging.h"
21
#include "core/mergedproxymodel.h"
22
#include "core/mimedata.h"
23
#include "ui/iconloader.h"
27
InternetService::InternetService(const QString& name, InternetModel* model, QObject* parent)
31
append_to_playlist_(NULL),
32
replace_playlist_(NULL),
33
open_in_new_playlist_(NULL),
38
QList<QAction*> InternetService::GetPlaylistActions() {
40
separator_ = new QAction(this);
41
separator_->setSeparator(true);
44
return QList<QAction*>() << GetAppendToPlaylistAction()
45
<< GetReplacePlaylistAction()
46
<< GetOpenInNewPlaylistAction()
50
QAction* InternetService::GetAppendToPlaylistAction() {
51
if(!append_to_playlist_) {
52
append_to_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
53
tr("Append to current playlist"), this);
54
connect(append_to_playlist_, SIGNAL(triggered()), this, SLOT(AppendToPlaylist()));
57
return append_to_playlist_;
60
QAction* InternetService::GetReplacePlaylistAction() {
61
if(!replace_playlist_) {
62
replace_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
63
tr("Replace current playlist"), this);
64
connect(replace_playlist_, SIGNAL(triggered()), this, SLOT(ReplacePlaylist()));
67
return replace_playlist_;
70
QAction* InternetService::GetOpenInNewPlaylistAction() {
71
if(!open_in_new_playlist_) {
72
open_in_new_playlist_ = new QAction(IconLoader::Load("document-new"),
73
tr("Open in new playlist"), this);
74
connect(open_in_new_playlist_, SIGNAL(triggered()), this, SLOT(OpenInNewPlaylist()));
77
return open_in_new_playlist_;
80
void InternetService::AddItemToPlaylist(const QModelIndex& index, AddMode add_mode) {
81
AddItemsToPlaylist(QModelIndexList() << index, add_mode);
84
void InternetService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode) {
85
QMimeData* data = model()->merged_model()->mimeData(
86
model()->merged_model()->mapFromSource(indexes));
87
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
88
mime_data->clear_first_ = add_mode == AddMode_Replace;
89
mime_data->open_in_new_playlist_ = add_mode == AddMode_OpenInNew;
91
emit AddToPlaylistSignal(data);
94
void InternetService::AppendToPlaylist() {
95
AddItemToPlaylist(GetCurrentIndex(), AddMode_Append);
98
void InternetService::ReplacePlaylist() {
99
AddItemToPlaylist(GetCurrentIndex(), AddMode_Replace);
102
void InternetService::OpenInNewPlaylist() {
103
AddItemToPlaylist(GetCurrentIndex(), AddMode_OpenInNew);