strawberry-audio-player-win.../src/internet/internetplaylistitem.cpp

107 lines
2.9 KiB
C++
Raw Normal View History

2018-08-09 18:10:03 +02:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QApplication>
#include <QSettings>
#include <QVariant>
#include <QString>
#include <QtDebug>
#include "internetplaylistitem.h"
#include "internetservice.h"
#include "internetmodel.h"
#include "core/settingsprovider.h"
#include "collection/sqlrow.h"
#include "playlist/playlistbackend.h"
InternetPlaylistItem::InternetPlaylistItem(const QString &type)
: PlaylistItem(type), set_service_icon_(false) {}
InternetPlaylistItem::InternetPlaylistItem(InternetService *service, const Song &metadata)
: PlaylistItem("Internet"),
service_name_(service->name()),
set_service_icon_(false),
metadata_(metadata) {
InitMetadata();
}
bool InternetPlaylistItem::InitFromQuery(const SqlRow &query) {
// The song tables gets joined first, plus one each for the song ROWIDs
const int row = (Song::kColumns.count() + 1) * PlaylistBackend::kSongTableJoins;
service_name_ = query.value(row + 1).toString();
metadata_.InitFromQuery(query, false, (Song::kColumns.count() + 1) * 1);
InitMetadata();
return true;
}
InternetService *InternetPlaylistItem::service() const {
InternetService *ret = InternetModel::ServiceByName(service_name_);
if (ret && !set_service_icon_) {
const_cast<InternetPlaylistItem*>(this)->set_service_icon_ = true;
QString icon = ret->Icon();
if (!icon.isEmpty()) {
const_cast<InternetPlaylistItem*>(this)->metadata_.set_art_manual(icon);
}
}
return ret;
}
QVariant InternetPlaylistItem::DatabaseValue(DatabaseColumn column) const {
switch (column) {
case Column_InternetService:
return service_name_;
default:
return PlaylistItem::DatabaseValue(column);
}
}
void InternetPlaylistItem::InitMetadata() {
if (metadata_.title().isEmpty())
metadata_.set_title(metadata_.url().toString());
2018-09-06 22:34:18 +02:00
if (metadata_.filetype() == Song::Type_Unknown) metadata_.set_filetype(Song::Type_Stream);
2018-08-09 18:10:03 +02:00
metadata_.set_valid(true);
}
Song InternetPlaylistItem::Metadata() const {
if (!set_service_icon_) {
// Get the icon if we don't have it already
service();
}
if (HasTemporaryMetadata()) return temp_metadata_;
return metadata_;
}
QUrl InternetPlaylistItem::Url() const { return metadata_.url(); }