mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-02 20:36:44 +01:00
Factorize some code for creating song item in Grooveshark and Spotify
This commit is contained in:
parent
3c5e91ce84
commit
c7aca6335d
@ -296,11 +296,7 @@ void GroovesharkService::SearchSongsFinished() {
|
||||
|
||||
// Fill results list
|
||||
foreach (const Song& song, songs) {
|
||||
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
||||
child->setData(Type_Track, InternetModel::Role_Type);
|
||||
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
||||
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||
child->setData(song.url(), InternetModel::Role_Url);
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
search_->appendRow(child);
|
||||
}
|
||||
|
||||
@ -496,7 +492,7 @@ void GroovesharkService::ShowContextMenu(const QPoint& global_pos) {
|
||||
|
||||
// Check if we can display actions to get URL for sharing songs/playlists:
|
||||
// - share song
|
||||
if (index.data(InternetModel::Role_Type).toInt() == Type_Track) {
|
||||
if (index.data(InternetModel::Role_Type).toInt() == InternetModel::Type_Track) {
|
||||
display_share_song_url = true;
|
||||
current_song_id_ = ExtractSongId(index.data(InternetModel::Role_Url).toUrl());
|
||||
}
|
||||
@ -574,7 +570,6 @@ void GroovesharkService::EnsureItemsCreated() {
|
||||
tr("Search results"));
|
||||
search_->setToolTip(tr("Start typing something on the search box above to "
|
||||
"fill this search results list"));
|
||||
search_->setData(Type_SearchResults, InternetModel::Role_Type);
|
||||
search_->setData(InternetModel::PlayBehaviour_DoubleClickAction,
|
||||
InternetModel::Role_PlayBehaviour);
|
||||
root_->appendRow(search_);
|
||||
@ -710,11 +705,7 @@ void GroovesharkService::PlaylistSongsRetrieved() {
|
||||
Song::SortSongsListAlphabetically(&songs);
|
||||
|
||||
foreach (const Song& song, songs) {
|
||||
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
||||
child->setData(Type_Track, InternetModel::Role_Type);
|
||||
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
||||
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||
child->setData(song.url(), InternetModel::Role_Url);
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
child->setData(playlist_info.id_, Role_UserPlaylistId);
|
||||
child->setData(true, InternetModel::Role_CanBeModified);
|
||||
|
||||
@ -753,11 +744,7 @@ void GroovesharkService::UserFavoritesRetrieved(QNetworkReply* reply, int task_i
|
||||
Song::SortSongsListAlphabetically(&songs);
|
||||
|
||||
foreach (const Song& song, songs) {
|
||||
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
||||
child->setData(Type_Track, InternetModel::Role_Type);
|
||||
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
||||
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||
child->setData(song.url(), InternetModel::Role_Url);
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
child->setData(true, InternetModel::Role_CanBeModified);
|
||||
|
||||
favorites_->appendRow(child);
|
||||
@ -794,12 +781,7 @@ void GroovesharkService::PopularSongsMonthRetrieved(QNetworkReply* reply) {
|
||||
return;
|
||||
|
||||
foreach (const Song& song, songs) {
|
||||
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
||||
child->setData(Type_Track, InternetModel::Role_Type);
|
||||
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
||||
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||
child->setData(song.url(), InternetModel::Role_Url);
|
||||
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
popular_month_->appendRow(child);
|
||||
}
|
||||
}
|
||||
@ -826,12 +808,7 @@ void GroovesharkService::PopularSongsTodayRetrieved(QNetworkReply* reply) {
|
||||
return;
|
||||
|
||||
foreach (const Song& song, songs) {
|
||||
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
||||
child->setData(Type_Track, InternetModel::Role_Type);
|
||||
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
||||
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||
child->setData(song.url(), InternetModel::Role_Url);
|
||||
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
popular_today_->appendRow(child);
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,6 @@ class GroovesharkService : public InternetService {
|
||||
GroovesharkService(Application* app, InternetModel *parent);
|
||||
~GroovesharkService();
|
||||
|
||||
enum Type {
|
||||
Type_SearchResults = InternetModel::TypeCount,
|
||||
Type_Track
|
||||
};
|
||||
|
||||
enum Role {
|
||||
Role_UserPlaylistId = InternetModel::RoleCount,
|
||||
Role_PlaylistType
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
|
||||
enum Type {
|
||||
Type_Service = 1,
|
||||
Type_Track,
|
||||
Type_UserPlaylist,
|
||||
Type_SmartPlaylist,
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QStandardItem>
|
||||
|
||||
InternetService::InternetService(const QString& name, Application* app,
|
||||
InternetModel* model, QObject* parent)
|
||||
@ -104,3 +105,14 @@ void InternetService::ReplacePlaylist() {
|
||||
void InternetService::OpenInNewPlaylist() {
|
||||
AddItemsToPlaylist(model()->selected_indexes(), AddMode_OpenInNew);
|
||||
}
|
||||
|
||||
QStandardItem* InternetService::CreateSongItem(const Song& song) {
|
||||
QStandardItem* item = new QStandardItem(song.PrettyTitleWithArtist());
|
||||
item->setData(InternetModel::Type_Track, InternetModel::Role_Type);
|
||||
item->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
||||
item->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||
item->setData(song.url(), InternetModel::Role_Url);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
class Application;
|
||||
class InternetModel;
|
||||
class LibraryFilterWidget;
|
||||
class QStandardItem;
|
||||
|
||||
class InternetService : public QObject {
|
||||
Q_OBJECT
|
||||
@ -106,6 +107,10 @@ protected:
|
||||
// Adds the 'indexes' elements to playlist using the 'add_mode' mode.
|
||||
void AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode);
|
||||
|
||||
// Convenient function for creating a item representing a song.
|
||||
// Set some common properties (type=track, url, etc.)
|
||||
QStandardItem* CreateSongItem(const Song& song);
|
||||
|
||||
protected:
|
||||
Application* app_;
|
||||
|
||||
|
@ -452,11 +452,7 @@ void SpotifyService::FillPlaylist(
|
||||
Song song;
|
||||
SongFromProtobuf(tracks.Get(i), &song);
|
||||
|
||||
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
||||
child->setData(Type_Track, InternetModel::Role_Type);
|
||||
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
|
||||
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||
child->setData(song.url(), InternetModel::Role_Url);
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
|
||||
item->appendRow(child);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user