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 "radioservice.h"
19
#include "radiomodel.h"
20
#include "core/mergedproxymodel.h"
21
#include "core/mimedata.h"
22
#include "ui/iconloader.h"
26
RadioService::RadioService(const QString& name, RadioModel* model)
30
append_to_playlist_(NULL),
31
replace_playlist_(NULL),
32
open_in_new_playlist_(NULL),
37
QList<QAction*> RadioService::GetPlaylistActions() {
39
separator_ = new QAction(this);
40
separator_->setSeparator(true);
43
return QList<QAction*>() << GetAppendToPlaylistAction()
44
<< GetReplacePlaylistAction()
45
<< GetOpenInNewPlaylistAction()
49
QAction* RadioService::GetAppendToPlaylistAction() {
50
if(!append_to_playlist_) {
51
append_to_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
52
tr("Append to current playlist"), this);
53
connect(append_to_playlist_, SIGNAL(triggered()), this, SLOT(AppendToPlaylist()));
56
return append_to_playlist_;
59
QAction* RadioService::GetReplacePlaylistAction() {
60
if(!replace_playlist_) {
61
replace_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
62
tr("Replace current playlist"), this);
63
connect(replace_playlist_, SIGNAL(triggered()), this, SLOT(ReplacePlaylist()));
66
return replace_playlist_;
69
QAction* RadioService::GetOpenInNewPlaylistAction() {
70
if(!open_in_new_playlist_) {
71
open_in_new_playlist_ = new QAction(IconLoader::Load("document-new"),
72
tr("Open in new playlist"), this);
73
connect(open_in_new_playlist_, SIGNAL(triggered()), this, SLOT(OpenInNewPlaylist()));
76
return open_in_new_playlist_;
79
PlaylistItem::SpecialLoadResult RadioService::StartLoading(const QUrl &url) {
80
return PlaylistItem::SpecialLoadResult(
81
PlaylistItem::SpecialLoadResult::TrackAvailable, url, url);
84
PlaylistItem::SpecialLoadResult RadioService::LoadNext(const QUrl&) {
85
return PlaylistItem::SpecialLoadResult();
88
void RadioService::AddItemToPlaylist(const QModelIndex& index, AddMode add_mode) {
89
AddItemsToPlaylist(QModelIndexList() << index, add_mode);
92
void RadioService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode) {
93
QMimeData* data = model()->merged_model()->mimeData(
94
model()->merged_model()->mapFromSource(indexes));
95
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
96
mime_data->clear_first_ = add_mode == AddMode_Replace;
97
mime_data->open_in_new_playlist_ = add_mode == AddMode_OpenInNew;
99
emit AddToPlaylistSignal(data);
102
void RadioService::AppendToPlaylist() {
103
AddItemToPlaylist(GetCurrentIndex(), AddMode_Append);
106
void RadioService::ReplacePlaylist() {
107
AddItemToPlaylist(GetCurrentIndex(), AddMode_Replace);
110
void RadioService::OpenInNewPlaylist() {
111
AddItemToPlaylist(GetCurrentIndex(), AddMode_OpenInNew);