2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2009-2011, David Sansome <davidsansome@gmail.com>
|
|
|
|
Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2011, Tyler Rhodes <tyler.s.rhodes@gmail.com>
|
|
|
|
Copyright 2011, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetplaylistitem.h"
|
2014-12-19 00:40:30 +01:00
|
|
|
|
|
|
|
#include <QApplication>
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <QSettings>
|
2014-12-19 00:40:30 +01:00
|
|
|
#include <QtDebug>
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/settingsprovider.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "internet/core/internetmodel.h"
|
|
|
|
#include "internet/core/internetservice.h"
|
2010-08-03 20:57:17 +02:00
|
|
|
#include "library/sqlrow.h"
|
2011-04-27 00:06:58 +02:00
|
|
|
#include "playlist/playlistbackend.h"
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2020-06-21 06:21:12 +02:00
|
|
|
// Note that the "Radio" type is legacy and only supported for database
|
|
|
|
// backwards compatibility, so this uses "Internet" for all types.
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetPlaylistItem::InternetPlaylistItem(const QString& type)
|
2020-06-21 06:21:12 +02:00
|
|
|
: PlaylistItem("Internet"), set_service_icon_(false) {}
|
2014-02-07 16:34:20 +01:00
|
|
|
|
|
|
|
InternetPlaylistItem::InternetPlaylistItem(InternetService* service,
|
|
|
|
const Song& metadata)
|
|
|
|
: PlaylistItem("Internet"),
|
|
|
|
service_name_(service->name()),
|
|
|
|
set_service_icon_(false),
|
|
|
|
metadata_(metadata) {
|
2009-12-29 20:22:02 +01:00
|
|
|
InitMetadata();
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2020-06-21 06:21:12 +02:00
|
|
|
bool InternetPlaylistItem::IsTypeSupported(const QString& type) {
|
|
|
|
if (type == "Radio") return true;
|
|
|
|
if (type == "Internet") return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
bool InternetPlaylistItem::InitFromQuery(const SqlRow& query) {
|
2010-05-10 16:19:43 +02:00
|
|
|
// The song tables gets joined first, plus one each for the song ROWIDs
|
2014-02-07 16:34:20 +01:00
|
|
|
const int row =
|
|
|
|
(Song::kColumns.count() + 1) * PlaylistBackend::kSongTableJoins;
|
2010-04-14 23:03:00 +02:00
|
|
|
|
2011-04-27 00:06:58 +02:00
|
|
|
service_name_ = query.value(row + 1).toString();
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2011-06-17 22:00:10 +02:00
|
|
|
metadata_.InitFromQuery(query, false, (Song::kColumns.count() + 1) * 3);
|
2009-12-29 20:22:02 +01:00
|
|
|
InitMetadata();
|
2011-04-27 00:06:58 +02:00
|
|
|
|
2010-04-27 19:37:26 +02:00
|
|
|
return true;
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetService* InternetPlaylistItem::service() const {
|
|
|
|
InternetService* ret = InternetModel::ServiceByName(service_name_);
|
2011-01-15 01:53:39 +01:00
|
|
|
|
|
|
|
if (ret && !set_service_icon_) {
|
2011-07-15 15:27:50 +02:00
|
|
|
const_cast<InternetPlaylistItem*>(this)->set_service_icon_ = true;
|
2011-01-15 01:53:39 +01:00
|
|
|
|
|
|
|
QString icon = ret->Icon();
|
|
|
|
if (!icon.isEmpty()) {
|
2011-07-15 15:27:50 +02:00
|
|
|
const_cast<InternetPlaylistItem*>(this)->metadata_.set_art_manual(icon);
|
2011-01-12 20:59:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-15 01:53:39 +01:00
|
|
|
return ret;
|
2011-01-12 20:59:17 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
QVariant InternetPlaylistItem::DatabaseValue(DatabaseColumn column) const {
|
2010-04-14 23:03:00 +02:00
|
|
|
switch (column) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case Column_InternetService:
|
|
|
|
return service_name_;
|
|
|
|
default:
|
|
|
|
return PlaylistItem::DatabaseValue(column);
|
2010-04-14 23:03:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetPlaylistItem::InitMetadata() {
|
2011-04-27 00:06:58 +02:00
|
|
|
if (metadata_.title().isEmpty())
|
2011-04-28 14:27:53 +02:00
|
|
|
metadata_.set_title(metadata_.url().toString());
|
2010-03-07 23:46:41 +01:00
|
|
|
metadata_.set_filetype(Song::Type_Stream);
|
2011-04-27 00:06:58 +02:00
|
|
|
metadata_.set_valid(true);
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
Song InternetPlaylistItem::Metadata() const {
|
2011-02-03 21:59:53 +01:00
|
|
|
if (!set_service_icon_) {
|
|
|
|
// Get the icon if we don't have it already
|
|
|
|
service();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (HasTemporaryMetadata()) return temp_metadata_;
|
2009-12-29 20:22:02 +01:00
|
|
|
return metadata_;
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QUrl InternetPlaylistItem::Url() const { return metadata_.url(); }
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
PlaylistItem::Options InternetPlaylistItem::options() const {
|
|
|
|
InternetService* s = service();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!s) return Default;
|
2011-01-15 01:53:39 +01:00
|
|
|
return s->playlistitem_options();
|
2009-12-29 17:12:08 +01:00
|
|
|
}
|
2011-11-06 16:12:44 +01:00
|
|
|
|
|
|
|
QList<QAction*> InternetPlaylistItem::actions() {
|
|
|
|
InternetService* s = service();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!s) return QList<QAction*>();
|
2011-11-06 16:12:44 +01:00
|
|
|
return s->playlistitem_actions(metadata_);
|
|
|
|
}
|