Request to merge a fix for a crash during searching under Internet Tab (#5682)

* Changing ClearSearchResults order.

If search_ is null, there is no point in clearing it.

* Update to fix 12 (Crash when searching under Internet tab with Spotify)

* Formatting Fixes
This commit is contained in:
MelissaManley97 2017-03-28 12:38:55 -04:00 committed by John Maguire
parent 0b34586e52
commit a5d12d0d10
2 changed files with 55 additions and 49 deletions

View File

@ -395,16 +395,8 @@ void SpotifyService::AddSongsToStarred(const QList<QUrl>& songs_urls) {
server_->AddSongsToStarred(songs_urls); server_->AddSongsToStarred(songs_urls);
} }
void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) { void SpotifyService::InitSearch() {
if (login_task_id_) { search_ = new QStandardItem(IconLoader::Load("edit-find", IconLoader::Base),
app_->task_manager()->SetTaskFinished(login_task_id_);
login_task_id_ = 0;
}
// Create starred and inbox playlists if they're not here already
if (!search_) {
search_ =
new QStandardItem(IconLoader::Load("edit-find", IconLoader::Base),
tr("Search results")); tr("Search results"));
search_->setToolTip( search_->setToolTip(
tr("Start typing something on the search box above to " tr("Start typing something on the search box above to "
@ -421,8 +413,8 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
InternetModel::Role_PlayBehaviour); InternetModel::Role_PlayBehaviour);
starred_->setData(true, InternetModel::Role_CanBeModified); starred_->setData(true, InternetModel::Role_CanBeModified);
inbox_ = new QStandardItem(IconLoader::Load("mail-message", inbox_ = new QStandardItem(IconLoader::Load("mail-message", IconLoader::Base),
IconLoader::Base), tr("Inbox")); tr("Inbox"));
inbox_->setData(Type_InboxPlaylist, InternetModel::Role_Type); inbox_->setData(Type_InboxPlaylist, InternetModel::Role_Type);
inbox_->setData(true, InternetModel::Role_CanLazyLoad); inbox_->setData(true, InternetModel::Role_CanLazyLoad);
inbox_->setData(InternetModel::PlayBehaviour_MultipleItems, inbox_->setData(InternetModel::PlayBehaviour_MultipleItems,
@ -438,6 +430,17 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
root_->appendRow(toplist_); root_->appendRow(toplist_);
root_->appendRow(starred_); root_->appendRow(starred_);
root_->appendRow(inbox_); root_->appendRow(inbox_);
}
void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
if (login_task_id_) {
app_->task_manager()->SetTaskFinished(login_task_id_);
login_task_id_ = 0;
}
// Create starred and inbox playlists if they're not here already
if (!search_) {
InitSearch();
} else { } else {
// Always reset starred playlist // Always reset starred playlist
// TODO: might be improved by including starred playlist in the response, // TODO: might be improved by including starred playlist in the response,
@ -618,8 +621,8 @@ QList<QAction*> SpotifyService::playlistitem_actions(const Song& song) {
playlistitem_actions_.append(add_to_starred); playlistitem_actions_.append(add_to_starred);
// Create a menu with 'add to playlist' actions for each Spotify playlist // Create a menu with 'add to playlist' actions for each Spotify playlist
QAction* add_to_playlists = new QAction(IconLoader::Load("list-add", QAction* add_to_playlists =
IconLoader::Base), new QAction(IconLoader::Load("list-add", IconLoader::Base),
tr("Add to Spotify playlists"), this); tr("Add to Spotify playlists"), this);
QMenu* playlists_menu = new QMenu(); QMenu* playlists_menu = new QMenu();
for (const QStandardItem* playlist_item : playlists_) { for (const QStandardItem* playlist_item : playlists_) {
@ -678,8 +681,7 @@ void SpotifyService::EnsureMenuCreated() {
song_context_menu_->addSeparator(); song_context_menu_->addSeparator();
remove_from_playlist_ = song_context_menu_->addAction( remove_from_playlist_ = song_context_menu_->addAction(
IconLoader::Load("list-remove", IconLoader::Base), IconLoader::Load("list-remove", IconLoader::Base),
tr("Remove from playlist"), this, tr("Remove from playlist"), this, SLOT(RemoveCurrentFromPlaylist()));
SLOT(RemoveCurrentFromPlaylist()));
song_context_menu_->addAction(tr("Get a URL to share this Spotify song"), song_context_menu_->addAction(tr("Get a URL to share this Spotify song"),
this, SLOT(GetCurrentSongUrlToShare())); this, SLOT(GetCurrentSongUrlToShare()));
song_context_menu_->addSeparator(); song_context_menu_->addSeparator();
@ -765,6 +767,10 @@ void SpotifyService::SearchResults(
ClearSearchResults(); ClearSearchResults();
// Must initialize search pointer if it is nullptr
if (!search_) {
InitSearch();
}
// Fill results list // Fill results list
for (const Song& song : songs) { for (const Song& song : songs) {
QStandardItem* child = CreateSongItem(song); QStandardItem* child = CreateSongItem(song);
@ -848,10 +854,10 @@ void SpotifyService::ItemDoubleClicked(QStandardItem* item) {}
void SpotifyService::DropMimeData(const QMimeData* data, void SpotifyService::DropMimeData(const QMimeData* data,
const QModelIndex& index) { const QModelIndex& index) {
QModelIndex playlist_root_index = index; QModelIndex playlist_root_index = index;
QVariant q_playlist_type = playlist_root_index.data(InternetModel::Role_Type); QVariant q_playlist_type = playlist_root_index.data(InternetModel::Role_Type);
if (!q_playlist_type.isValid() || q_playlist_type.toInt() == InternetModel::Type_Track) { if (!q_playlist_type.isValid() ||
q_playlist_type.toInt() == InternetModel::Type_Track) {
// In case song was dropped on a playlist item, not on the playlist // In case song was dropped on a playlist item, not on the playlist
// title/root element // title/root element
playlist_root_index = index.parent(); playlist_root_index = index.parent();
@ -864,7 +870,8 @@ void SpotifyService::DropMimeData(const QMimeData* data,
if (playlist_type == Type_StarredPlaylist) { if (playlist_type == Type_StarredPlaylist) {
AddSongsToStarred(data->urls()); AddSongsToStarred(data->urls());
} else if (playlist_type == InternetModel::Type_UserPlaylist) { } else if (playlist_type == InternetModel::Type_UserPlaylist) {
QVariant q_playlist_index = playlist_root_index.data(Role_UserPlaylistIndex); QVariant q_playlist_index =
playlist_root_index.data(Role_UserPlaylistIndex);
if (!q_playlist_index.isValid()) return; if (!q_playlist_index.isValid()) return;
AddSongsToUserPlaylist(q_playlist_index.toInt(), data->urls()); AddSongsToUserPlaylist(q_playlist_index.toInt(), data->urls());
} }
@ -916,8 +923,7 @@ void SpotifyService::SyncPlaylistProgress(
} }
QAction* SpotifyService::GetNewShowConfigAction() { QAction* SpotifyService::GetNewShowConfigAction() {
QAction* action = new QAction(IconLoader::Load("configure", QAction* action = new QAction(IconLoader::Load("configure", IconLoader::Base),
IconLoader::Base),
tr("Configure Spotify..."), this); tr("Configure Spotify..."), this);
connect(action, SIGNAL(triggered()), this, SLOT(ShowConfig())); connect(action, SIGNAL(triggered()), this, SLOT(ShowConfig()));
return action; return action;

View File

@ -120,8 +120,8 @@ class SpotifyService : public InternetService {
// the pointer (or adding it to menu or anything else that will take ownership // the pointer (or adding it to menu or anything else that will take ownership
// of it) // of it)
QAction* GetNewShowConfigAction(); QAction* GetNewShowConfigAction();
void InitSearch();
void ClearSearchResults(); void ClearSearchResults();
QStandardItem* PlaylistBySpotifyIndex(int index) const; QStandardItem* PlaylistBySpotifyIndex(int index) const;
bool DoPlaylistsDiffer(const pb::spotify::Playlists& response) const; bool DoPlaylistsDiffer(const pb::spotify::Playlists& response) const;