~ubuntu-branches/ubuntu/natty/clementine/natty

« back to all changes in this revision

Viewing changes to src/playlist/playlistitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2010-12-12 11:32:03 UTC
  • Revision ID: james.westby@ubuntu.com-20101212113203-oi0lbt5d9alzfjq7
Tags: upstream-0.6
ImportĀ upstreamĀ versionĀ 0.6

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 "playlistitem.h"
 
19
#include "songplaylistitem.h"
 
20
#include "library/library.h"
 
21
#include "library/libraryplaylistitem.h"
 
22
#include "radio/jamendoplaylistitem.h"
 
23
#include "radio/jamendoservice.h"
 
24
#include "radio/magnatuneplaylistitem.h"
 
25
#include "radio/magnatuneservice.h"
 
26
#include "radio/radioplaylistitem.h"
 
27
 
 
28
#include <QtConcurrentRun>
 
29
#include <QtDebug>
 
30
 
 
31
PlaylistItem::SpecialLoadResult::SpecialLoadResult(
 
32
    Type type, const QUrl& original_url, const QUrl& media_url)
 
33
      : type_(type), original_url_(original_url), media_url_(media_url)
 
34
{
 
35
}
 
36
 
 
37
PlaylistItem* PlaylistItem::NewFromType(const QString& type) {
 
38
  if (type == "Library")
 
39
    return new LibraryPlaylistItem(type);
 
40
  if (type == "Magnatune")
 
41
    return new MagnatunePlaylistItem(type);
 
42
  if (type == "Jamendo")
 
43
    return new JamendoPlaylistItem(type);
 
44
  if (type == "Stream" || type == "File")
 
45
    return new SongPlaylistItem(type);
 
46
  if (type == "Radio")
 
47
    return new RadioPlaylistItem(type);
 
48
 
 
49
  qWarning() << "Invalid PlaylistItem type:" << type;
 
50
  return NULL;
 
51
}
 
52
 
 
53
PlaylistItem* PlaylistItem::NewFromSongsTable(const QString& table, const Song& song) {
 
54
  if (table == Library::kSongsTable)
 
55
    return new LibraryPlaylistItem(song);
 
56
  if (table == MagnatuneService::kSongsTable)
 
57
    return new MagnatunePlaylistItem(song);
 
58
  if (table == JamendoService::kSongsTable)
 
59
    return new JamendoPlaylistItem(song);
 
60
 
 
61
  qWarning() << "Invalid PlaylistItem songs table:" << table;
 
62
  return NULL;
 
63
}
 
64
 
 
65
void PlaylistItem::BindToQuery(QSqlQuery* query) const {
 
66
  query->bindValue(1, type());
 
67
  query->bindValue(2, DatabaseValue(Column_LibraryId));
 
68
  query->bindValue(3, DatabaseValue(Column_Url));
 
69
  query->bindValue(4, DatabaseValue(Column_Title));
 
70
  query->bindValue(5, DatabaseValue(Column_Artist));
 
71
  query->bindValue(6, DatabaseValue(Column_Album));
 
72
  query->bindValue(7, DatabaseValue(Column_Length));
 
73
  query->bindValue(8, DatabaseValue(Column_RadioService));
 
74
}
 
75
 
 
76
void PlaylistItem::SetTemporaryMetadata(const Song& metadata) {
 
77
  temp_metadata_ = metadata;
 
78
  temp_metadata_.set_filetype(Song::Type_Stream);
 
79
}
 
80
 
 
81
void PlaylistItem::ClearTemporaryMetadata() {
 
82
  temp_metadata_ = Song();
 
83
}
 
84
 
 
85
static void ReloadPlaylistItem(PlaylistItemPtr item) {
 
86
  item->Reload();
 
87
}
 
88
 
 
89
QFuture<void> PlaylistItem::BackgroundReload() {
 
90
  return QtConcurrent::run(ReloadPlaylistItem, shared_from_this());
 
91
}