diff --git a/src/internet/groovesharkservice.cpp b/src/internet/groovesharkservice.cpp index a86ee199d..b3177d9e0 100644 --- a/src/internet/groovesharkservice.cpp +++ b/src/internet/groovesharkservice.cpp @@ -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); } } diff --git a/src/internet/groovesharkservice.h b/src/internet/groovesharkservice.h index f5697e7e8..e3f687bd4 100644 --- a/src/internet/groovesharkservice.h +++ b/src/internet/groovesharkservice.h @@ -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 diff --git a/src/internet/internetmodel.h b/src/internet/internetmodel.h index 99efcd15e..66cf36691 100644 --- a/src/internet/internetmodel.h +++ b/src/internet/internetmodel.h @@ -85,6 +85,7 @@ public: enum Type { Type_Service = 1, + Type_Track, Type_UserPlaylist, Type_SmartPlaylist, diff --git a/src/internet/internetservice.cpp b/src/internet/internetservice.cpp index 8adfe6a45..b809f3ffb 100644 --- a/src/internet/internetservice.cpp +++ b/src/internet/internetservice.cpp @@ -23,6 +23,7 @@ #include "ui/iconloader.h" #include +#include 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; +} + diff --git a/src/internet/internetservice.h b/src/internet/internetservice.h index bdd1690f6..482e472b3 100644 --- a/src/internet/internetservice.h +++ b/src/internet/internetservice.h @@ -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_; diff --git a/src/internet/spotifyservice.cpp b/src/internet/spotifyservice.cpp index beb39c587..ec4a38f7e 100644 --- a/src/internet/spotifyservice.cpp +++ b/src/internet/spotifyservice.cpp @@ -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); }