~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/radio/radioservice.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Clementine.
2
 
   Copyright 2010, David Sansome <me@davidsansome.com>
3
 
 
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.
8
 
 
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.
13
 
 
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/>.
16
 
*/
17
 
 
18
 
#include "radioservice.h"
19
 
#include "radiomodel.h"
20
 
#include "core/mergedproxymodel.h"
21
 
#include "core/mimedata.h"
22
 
#include "ui/iconloader.h"
23
 
 
24
 
#include <QMenu>
25
 
 
26
 
RadioService::RadioService(const QString& name, RadioModel* model)
27
 
  : QObject(model),
28
 
    model_(model),
29
 
    name_(name),
30
 
    append_to_playlist_(NULL),
31
 
    replace_playlist_(NULL),
32
 
    open_in_new_playlist_(NULL),
33
 
    separator_(NULL)
34
 
{
35
 
}
36
 
 
37
 
QList<QAction*> RadioService::GetPlaylistActions() {
38
 
  if(!separator_) {
39
 
    separator_ = new QAction(this);
40
 
    separator_->setSeparator(true);
41
 
  }
42
 
 
43
 
  return QList<QAction*>() << GetAppendToPlaylistAction()
44
 
                           << GetReplacePlaylistAction()
45
 
                           << GetOpenInNewPlaylistAction()
46
 
                           << separator_;
47
 
}
48
 
 
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()));
54
 
  }
55
 
 
56
 
  return append_to_playlist_;
57
 
}
58
 
 
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()));
64
 
  }
65
 
 
66
 
  return replace_playlist_;
67
 
}
68
 
 
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()));
74
 
  }
75
 
 
76
 
  return open_in_new_playlist_;
77
 
}
78
 
 
79
 
PlaylistItem::SpecialLoadResult RadioService::StartLoading(const QUrl &url) {
80
 
  return PlaylistItem::SpecialLoadResult(
81
 
      PlaylistItem::SpecialLoadResult::TrackAvailable, url, url);
82
 
}
83
 
 
84
 
PlaylistItem::SpecialLoadResult RadioService::LoadNext(const QUrl&) {
85
 
  return PlaylistItem::SpecialLoadResult();
86
 
}
87
 
 
88
 
void RadioService::AddItemToPlaylist(const QModelIndex& index, AddMode add_mode) {
89
 
  AddItemsToPlaylist(QModelIndexList() << index, add_mode);
90
 
}
91
 
 
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;
98
 
  }
99
 
  emit AddToPlaylistSignal(data);
100
 
}
101
 
 
102
 
void RadioService::AppendToPlaylist() {
103
 
  AddItemToPlaylist(GetCurrentIndex(), AddMode_Append);
104
 
}
105
 
 
106
 
void RadioService::ReplacePlaylist() {
107
 
  AddItemToPlaylist(GetCurrentIndex(), AddMode_Replace);
108
 
}
109
 
 
110
 
void RadioService::OpenInNewPlaylist() {
111
 
  AddItemToPlaylist(GetCurrentIndex(), AddMode_OpenInNew);
112
 
}