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

« back to all changes in this revision

Viewing changes to src/internet/internetservice.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 "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"
 
24
 
 
25
#include <QMenu>
 
26
 
 
27
InternetService::InternetService(const QString& name, InternetModel* model, QObject* parent)
 
28
  : QObject(parent),
 
29
    model_(model),
 
30
    name_(name),
 
31
    append_to_playlist_(NULL),
 
32
    replace_playlist_(NULL),
 
33
    open_in_new_playlist_(NULL),
 
34
    separator_(NULL)
 
35
{
 
36
}
 
37
 
 
38
QList<QAction*> InternetService::GetPlaylistActions() {
 
39
  if(!separator_) {
 
40
    separator_ = new QAction(this);
 
41
    separator_->setSeparator(true);
 
42
  }
 
43
 
 
44
  return QList<QAction*>() << GetAppendToPlaylistAction()
 
45
                           << GetReplacePlaylistAction()
 
46
                           << GetOpenInNewPlaylistAction()
 
47
                           << separator_;
 
48
}
 
49
 
 
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()));
 
55
  }
 
56
 
 
57
  return append_to_playlist_;
 
58
}
 
59
 
 
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()));
 
65
  }
 
66
 
 
67
  return replace_playlist_;
 
68
}
 
69
 
 
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()));
 
75
  }
 
76
 
 
77
  return open_in_new_playlist_;
 
78
}
 
79
 
 
80
void InternetService::AddItemToPlaylist(const QModelIndex& index, AddMode add_mode) {
 
81
  AddItemsToPlaylist(QModelIndexList() << index, add_mode);
 
82
}
 
83
 
 
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;
 
90
  }
 
91
  emit AddToPlaylistSignal(data);
 
92
}
 
93
 
 
94
void InternetService::AppendToPlaylist() {
 
95
  AddItemToPlaylist(GetCurrentIndex(), AddMode_Append);
 
96
}
 
97
 
 
98
void InternetService::ReplacePlaylist() {
 
99
  AddItemToPlaylist(GetCurrentIndex(), AddMode_Replace);
 
100
}
 
101
 
 
102
void InternetService::OpenInNewPlaylist() {
 
103
  AddItemToPlaylist(GetCurrentIndex(), AddMode_OpenInNew);
 
104
}