Do spotify image requests with string IDs instead of spotify://image/ urls. For some reason this seems to fix occasional crashes when image results arrive. Fixes issue 2411.

This commit is contained in:
David Sansome 2011-11-29 10:20:23 +00:00
parent 32d709664b
commit 8d5ef62256
5 changed files with 102 additions and 107 deletions

View File

@ -154,17 +154,20 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(
SpotifyService* spotify = InternetModel::Service<SpotifyService>();
if (!connected_spotify_) {
connect(spotify, SIGNAL(ImageLoaded(QUrl,QImage)),
SLOT(SpotifyImageLoaded(QUrl,QImage)));
connect(spotify, SIGNAL(ImageLoaded(QString,QImage)),
SLOT(SpotifyImageLoaded(QString,QImage)));
connected_spotify_ = true;
}
QUrl url = QUrl(filename);
remote_spotify_tasks_.insert(url, task);
QString id = QUrl(filename).path();
if (id.startsWith('/')) {
id.remove(0, 1);
}
remote_spotify_tasks_.insert(id, task);
// Need to schedule this in the spotify service's thread
QMetaObject::invokeMethod(spotify, "LoadImage", Qt::QueuedConnection,
Q_ARG(QUrl, url));
Q_ARG(QString, id));
return TryLoadResult(true, false, QImage());
#else
return TryLoadResult(false, false, QImage());
@ -175,16 +178,14 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(
return TryLoadResult(false, !image.isNull(), image.isNull() ? default_ : image);
}
void AlbumCoverLoader::SpotifyImageLoaded(const QUrl& url, const QImage& image) {
if (!remote_spotify_tasks_.contains(url))
void AlbumCoverLoader::SpotifyImageLoaded(const QString& id, const QImage& image) {
if (!remote_spotify_tasks_.contains(id))
return;
Task task = remote_spotify_tasks_.take(url);
Task task = remote_spotify_tasks_.take(id);
QImage scaled = ScaleAndPad(image);
emit ImageLoaded(task.id, scaled);
emit ImageLoaded(task.id, scaled, image);
qLog(Debug) << "Spotify image was for task" << task.id;
}
void AlbumCoverLoader::RemoteFetchFinished() {

View File

@ -65,7 +65,7 @@ class AlbumCoverLoader : public QObject {
protected slots:
void ProcessTasks();
void RemoteFetchFinished();
void SpotifyImageLoaded(const QUrl& url, const QImage& image);
void SpotifyImageLoaded(const QString& url, const QImage& image);
protected:
enum State {
@ -108,7 +108,7 @@ class AlbumCoverLoader : public QObject {
QMutex mutex_;
QQueue<Task> tasks_;
QMap<QNetworkReply*, Task> remote_tasks_;
QMap<QUrl, Task> remote_spotify_tasks_;
QMap<QString, Task> remote_spotify_tasks_;
quint64 next_id_;
NetworkAccessManager* network_;

View File

@ -237,7 +237,7 @@ void SpotifyService::EnsureServerCreated(const QString& username,
connect(server_, SIGNAL(SearchResults(spotify_pb::SearchResponse)),
SLOT(SearchResults(spotify_pb::SearchResponse)));
connect(server_, SIGNAL(ImageLoaded(QString,QImage)),
SLOT(ImageLoaded(QString,QImage)));
SIGNAL(ImageLoaded(QString,QImage)));
connect(server_, SIGNAL(SyncPlaylistProgress(spotify_pb::SyncPlaylistProgress)),
SLOT(SyncPlaylistProgress(spotify_pb::SyncPlaylistProgress)));
@ -611,23 +611,9 @@ void SpotifyService::ItemDoubleClicked(QStandardItem* item) {
}
}
void SpotifyService::LoadImage(const QUrl& url) {
if (url.scheme() != "spotify" || url.host() != "image") {
return;
}
QString image_id = url.path();
if (image_id.startsWith('/')) {
image_id.remove(0, 1);
}
void SpotifyService::LoadImage(const QString& id) {
EnsureServerCreated();
server_->LoadImage(image_id);
}
void SpotifyService::ImageLoaded(const QString& id, const QImage& image) {
qLog(Debug) << "Image loaded:" << id;
emit ImageLoaded(QUrl("spotify://image/" + id), image);
server_->LoadImage(id);
}
void SpotifyService::SyncPlaylistProgress(

View File

@ -59,7 +59,7 @@ public:
void Logout();
void Login(const QString& username, const QString& password);
void Search(const QString& text, Playlist* playlist, bool now = false);
Q_INVOKABLE void LoadImage(const QUrl& url);
Q_INVOKABLE void LoadImage(const QString& id);
SpotifyServer* server() const;
@ -75,7 +75,7 @@ public:
signals:
void BlobStateChanged();
void LoginFinished(bool success);
void ImageLoaded(const QUrl& url, const QImage& image);
void ImageLoaded(const QString& id, const QImage& image);
public slots:
void ShowConfig();
@ -102,7 +102,6 @@ private slots:
void StarredLoaded(const spotify_pb::LoadPlaylistResponse& response);
void UserPlaylistLoaded(const spotify_pb::LoadPlaylistResponse& response);
void SearchResults(const spotify_pb::SearchResponse& response);
void ImageLoaded(const QString& id, const QImage& image);
void SyncPlaylistProgress(const spotify_pb::SyncPlaylistProgress& progress);
void OpenSearchTab();

View File

@ -424,11 +424,11 @@ msgstr ""
msgid "Add stream..."
msgstr ""
#: internet/groovesharkservice.cpp:909
#: internet/groovesharkservice.cpp:917
msgid "Add to Grooveshark favorites"
msgstr ""
#: internet/groovesharkservice.cpp:915
#: internet/groovesharkservice.cpp:923
msgid "Add to Grooveshark playlists"
msgstr ""
@ -474,7 +474,7 @@ msgstr ""
msgid "Added within three months"
msgstr ""
#: internet/groovesharkservice.cpp:1108
#: internet/groovesharkservice.cpp:1164
msgid "Adding song to favorites"
msgstr ""
@ -611,7 +611,7 @@ msgstr ""
msgid "Appearance"
msgstr ""
#: core/commandlineoptions.cpp:163
#: core/commandlineoptions.cpp:160
msgid "Append files/URLs to the playlist"
msgstr ""
@ -633,7 +633,7 @@ msgstr ""
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
#: internet/groovesharkservice.cpp:1080
#: internet/groovesharkservice.cpp:1088
msgid "Are you sure you want to delete this playlist?"
msgstr ""
@ -830,7 +830,7 @@ msgstr ""
msgid "Change shuffle mode"
msgstr ""
#: core/commandlineoptions.cpp:170
#: core/commandlineoptions.cpp:167
msgid "Change the language"
msgstr ""
@ -969,7 +969,7 @@ msgstr ""
msgid "Combine identical results from different sources"
msgstr ""
#: core/commandlineoptions.cpp:173
#: core/commandlineoptions.cpp:170
msgid "Comma separated list of class:level, level is 0-3"
msgstr ""
@ -992,7 +992,7 @@ msgstr ""
msgid "Composer"
msgstr ""
#: internet/groovesharkservice.cpp:504
#: internet/groovesharkservice.cpp:512
msgid "Configure Grooveshark..."
msgstr ""
@ -1045,7 +1045,7 @@ msgstr ""
msgid "Convert any music that the device can't play"
msgstr ""
#: internet/groovesharkservice.cpp:962
#: internet/groovesharkservice.cpp:970
msgid "Copy to clipboard"
msgstr ""
@ -1125,7 +1125,7 @@ msgstr ""
msgid "Covers from %1"
msgstr ""
#: internet/groovesharkservice.cpp:488 internet/groovesharkservice.cpp:1031
#: internet/groovesharkservice.cpp:493 internet/groovesharkservice.cpp:1039
msgid "Create a new Grooveshark playlist"
msgstr ""
@ -1249,7 +1249,7 @@ msgstr ""
msgid "De&fault"
msgstr ""
#: core/commandlineoptions.cpp:159
#: core/commandlineoptions.cpp:156
msgid "Decrease the volume by 4%"
msgstr ""
@ -1265,7 +1265,7 @@ msgstr ""
msgid "Delay between visualizations"
msgstr ""
#: internet/groovesharkservice.cpp:491 internet/groovesharkservice.cpp:1079
#: internet/groovesharkservice.cpp:496 internet/groovesharkservice.cpp:1087
msgid "Delete Grooveshark playlist"
msgstr ""
@ -1386,11 +1386,11 @@ msgstr ""
msgid "Display options"
msgstr ""
#: core/commandlineoptions.cpp:169
#: core/commandlineoptions.cpp:166
msgid "Display the global search popup"
msgstr ""
#: core/commandlineoptions.cpp:167
#: core/commandlineoptions.cpp:164
msgid "Display the on-screen-display"
msgstr ""
@ -1584,11 +1584,11 @@ msgstr ""
msgid "Equalizer"
msgstr ""
#: core/commandlineoptions.cpp:171
#: core/commandlineoptions.cpp:168
msgid "Equivalent to --log-levels *:1"
msgstr ""
#: core/commandlineoptions.cpp:172
#: core/commandlineoptions.cpp:169
msgid "Equivalent to --log-levels *:3"
msgstr ""
@ -1697,7 +1697,7 @@ msgstr ""
msgid "Fast"
msgstr ""
#: internet/groovesharkservice.cpp:543
#: internet/groovesharkservice.cpp:551
msgid "Favorites"
msgstr ""
@ -1880,11 +1880,11 @@ msgstr ""
msgid "Genre"
msgstr ""
#: internet/groovesharkservice.cpp:926
#: internet/groovesharkservice.cpp:934
msgid "Get an URL to share this Grooveshark song"
msgstr ""
#: internet/groovesharkservice.cpp:705
#: internet/groovesharkservice.cpp:713
msgid "Getting Grooveshark popular songs"
msgstr ""
@ -1930,11 +1930,11 @@ msgstr ""
msgid "Grooveshark"
msgstr ""
#: internet/groovesharkservice.cpp:413
#: internet/groovesharkservice.cpp:416
msgid "Grooveshark login error"
msgstr ""
#: internet/groovesharkservice.cpp:958
#: internet/groovesharkservice.cpp:966
msgid "Grooveshark song's URL"
msgstr ""
@ -2073,7 +2073,7 @@ msgstr ""
msgid "Include keyboard shortcut help in the tooltip"
msgstr ""
#: core/commandlineoptions.cpp:158
#: core/commandlineoptions.cpp:155
msgid "Increase the volume by 4%"
msgstr ""
@ -2081,7 +2081,7 @@ msgstr ""
msgid "Increase volume"
msgstr ""
#: wiimotedev/wiimotesettingspage.cpp:124 ../bin/src/ui_deviceproperties.h:373
#: ../bin/src/ui_deviceproperties.h:373 wiimotedev/wiimotesettingspage.cpp:124
msgid "Information"
msgstr ""
@ -2129,7 +2129,7 @@ msgstr ""
msgid "Invalid session key"
msgstr ""
#: internet/groovesharkservice.cpp:406
#: internet/groovesharkservice.cpp:409
msgid "Invalid username and/or password"
msgstr ""
@ -2166,9 +2166,9 @@ msgstr ""
msgid "Keep buttons for %1 second..."
msgstr ""
#: ../bin/src/ui_wiimoteshortcutgrabber.h:127
#: wiimotedev/wiimoteshortcutgrabber.cpp:73
#: wiimotedev/wiimoteshortcutgrabber.cpp:117
#: ../bin/src/ui_wiimoteshortcutgrabber.h:127
#, qt-format
msgid "Keep buttons for %1 seconds..."
msgstr ""
@ -2383,7 +2383,7 @@ msgstr ""
msgid "Loading..."
msgstr ""
#: core/commandlineoptions.cpp:164
#: core/commandlineoptions.cpp:161
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
@ -2565,8 +2565,8 @@ msgstr ""
msgid "Music Library"
msgstr ""
#: core/globalshortcuts.cpp:54 wiimotedev/wiimotesettingspage.cpp:105
#: ../bin/src/ui_mainwindow.h:692
#: core/globalshortcuts.cpp:54 ../bin/src/ui_mainwindow.h:692
#: wiimotedev/wiimotesettingspage.cpp:105
msgid "Mute"
msgstr ""
@ -2602,8 +2602,8 @@ msgstr ""
msgid "My Recommendations"
msgstr ""
#: internet/groovesharkservice.cpp:1032 ui/equalizer.cpp:172
#: ../bin/src/ui_deviceproperties.h:369
#: internet/groovesharkservice.cpp:1040 internet/groovesharkservice.cpp:1132
#: ui/equalizer.cpp:172 ../bin/src/ui_deviceproperties.h:369
#: ../bin/src/ui_magnatunedownloaddialog.h:135
#: ../bin/src/ui_wizardfinishpage.h:84
#: ../bin/src/ui_globalshortcutssettingspage.h:174
@ -2667,8 +2667,8 @@ msgstr ""
msgid "Next"
msgstr ""
#: core/globalshortcuts.cpp:50 wiimotedev/wiimotesettingspage.cpp:99
#: ../bin/src/ui_mainwindow.h:635
#: core/globalshortcuts.cpp:50 ../bin/src/ui_mainwindow.h:635
#: wiimotedev/wiimotesettingspage.cpp:99
msgid "Next track"
msgstr ""
@ -2772,7 +2772,7 @@ msgid "Only show the first"
msgstr ""
#: internet/digitallyimportedservicebase.cpp:178
#: internet/groovesharkservice.cpp:503 internet/icecastservice.cpp:299
#: internet/groovesharkservice.cpp:511 internet/icecastservice.cpp:299
#: internet/jamendoservice.cpp:415 internet/magnatuneservice.cpp:273
#: internet/somafmservice.cpp:84
#, qt-format
@ -2834,7 +2834,7 @@ msgstr ""
msgid "Original tags"
msgstr ""
#: core/commandlineoptions.cpp:166
#: core/commandlineoptions.cpp:163
msgid "Other options"
msgstr ""
@ -2878,7 +2878,7 @@ msgstr ""
msgid "Pause"
msgstr ""
#: core/commandlineoptions.cpp:153
#: core/commandlineoptions.cpp:150
msgid "Pause playback"
msgstr ""
@ -2892,8 +2892,8 @@ msgstr ""
#: core/globalshortcuts.cpp:45 ui/mainwindow.cpp:506 ui/mainwindow.cpp:841
#: ui/mainwindow.cpp:860 ui/mainwindow.cpp:1262 ui/qtsystemtrayicon.cpp:166
#: ui/qtsystemtrayicon.cpp:192 wiimotedev/wiimotesettingspage.cpp:101
#: ../bin/src/ui_mainwindow.h:631
#: ui/qtsystemtrayicon.cpp:192 ../bin/src/ui_mainwindow.h:631
#: wiimotedev/wiimotesettingspage.cpp:101
msgid "Play"
msgstr ""
@ -2913,7 +2913,7 @@ msgstr ""
msgid "Play custom radio..."
msgstr ""
#: core/commandlineoptions.cpp:152
#: core/commandlineoptions.cpp:149
msgid "Play if stopped, pause if playing"
msgstr ""
@ -2926,7 +2926,7 @@ msgstr ""
msgid "Play tag radio..."
msgstr ""
#: core/commandlineoptions.cpp:165
#: core/commandlineoptions.cpp:162
msgid "Play the <n>th track in the playlist"
msgstr ""
@ -2942,7 +2942,7 @@ msgstr ""
msgid "Player name"
msgstr ""
#: core/commandlineoptions.cpp:150
#: core/commandlineoptions.cpp:147
msgid "Player options"
msgstr ""
@ -2955,7 +2955,7 @@ msgstr ""
msgid "Playlist finished"
msgstr ""
#: core/commandlineoptions.cpp:162
#: core/commandlineoptions.cpp:159
msgid "Playlist options"
msgstr ""
@ -2967,7 +2967,7 @@ msgstr ""
msgid "Playlist type"
msgstr ""
#: internet/groovesharkservice.cpp:539
#: internet/groovesharkservice.cpp:547
msgid "Playlists"
msgstr ""
@ -2979,15 +2979,15 @@ msgstr ""
msgid "Pop"
msgstr ""
#: internet/groovesharkservice.cpp:521
#: internet/groovesharkservice.cpp:529
msgid "Popular songs"
msgstr ""
#: internet/groovesharkservice.cpp:525
#: internet/groovesharkservice.cpp:533
msgid "Popular songs of the Month"
msgstr ""
#: internet/groovesharkservice.cpp:532
#: internet/groovesharkservice.cpp:540
msgid "Popular songs today"
msgstr ""
@ -3065,12 +3065,12 @@ msgstr ""
msgid "Previous"
msgstr ""
#: core/globalshortcuts.cpp:51 wiimotedev/wiimotesettingspage.cpp:100
#: ../bin/src/ui_mainwindow.h:629
#: core/globalshortcuts.cpp:51 ../bin/src/ui_mainwindow.h:629
#: wiimotedev/wiimotesettingspage.cpp:100
msgid "Previous track"
msgstr ""
#: core/commandlineoptions.cpp:174
#: core/commandlineoptions.cpp:171
msgid "Print out version information"
msgstr ""
@ -3083,8 +3083,8 @@ msgstr ""
msgid "Progress"
msgstr ""
#: wiimotedev/wiimotesettingspage.cpp:227
#: ../bin/src/ui_wiimoteshortcutgrabber.h:125
#: wiimotedev/wiimotesettingspage.cpp:227
msgid "Push Wiiremote button"
msgstr ""
@ -3211,11 +3211,11 @@ msgstr ""
msgid "Remove folder"
msgstr ""
#: internet/groovesharkservice.cpp:498
#: internet/groovesharkservice.cpp:506
msgid "Remove from favorites"
msgstr ""
#: internet/groovesharkservice.cpp:495 ../bin/src/ui_mainwindow.h:674
#: internet/groovesharkservice.cpp:503 ../bin/src/ui_mainwindow.h:674
msgid "Remove from playlist"
msgstr ""
@ -3223,10 +3223,19 @@ msgstr ""
msgid "Remove playlist"
msgstr ""
#: internet/groovesharkservice.cpp:1166
#: internet/groovesharkservice.cpp:1222
msgid "Removing song from favorites"
msgstr ""
#: internet/groovesharkservice.cpp:1131
#, qt-format
msgid "Rename \"%1\" playlist"
msgstr ""
#: internet/groovesharkservice.cpp:499
msgid "Rename Grooveshark playlist"
msgstr ""
#: playlist/playlisttabbar.cpp:131
msgid "Rename playlist"
msgstr ""
@ -3301,11 +3310,11 @@ msgstr ""
msgid "Results"
msgstr ""
#: internet/groovesharkservice.cpp:676
#: internet/groovesharkservice.cpp:684
msgid "Retrieving Grooveshark favorites songs"
msgstr ""
#: internet/groovesharkservice.cpp:585
#: internet/groovesharkservice.cpp:593
msgid "Retrieving Grooveshark playlists"
msgstr ""
@ -3383,11 +3392,11 @@ msgid "Search"
msgstr ""
#: internet/groovesharksearchplaylisttype.cpp:32
#: internet/groovesharkservice.cpp:844
#: internet/groovesharkservice.cpp:852
msgid "Search Grooveshark"
msgstr ""
#: internet/groovesharkservice.cpp:501 internet/groovesharkservice.cpp:515
#: internet/groovesharkservice.cpp:509 internet/groovesharkservice.cpp:523
msgid "Search Grooveshark (opens a new tab)"
msgstr ""
@ -3439,7 +3448,7 @@ msgstr ""
msgid "Search terms"
msgstr ""
#: internet/groovesharkservice.cpp:273
#: internet/groovesharkservice.cpp:276
msgid "Searching on Grooveshark"
msgstr ""
@ -3455,11 +3464,11 @@ msgstr ""
msgid "Seek forward"
msgstr ""
#: core/commandlineoptions.cpp:161
#: core/commandlineoptions.cpp:158
msgid "Seek the currently playing track by a relative amount"
msgstr ""
#: core/commandlineoptions.cpp:160
#: core/commandlineoptions.cpp:157
msgid "Seek the currently playing track to an absolute position"
msgstr ""
@ -3496,7 +3505,7 @@ msgstr ""
msgid "Set %1 to \"%2\"..."
msgstr ""
#: core/commandlineoptions.cpp:157
#: core/commandlineoptions.cpp:154
msgid "Set the volume to <value> percent"
msgstr ""
@ -3659,7 +3668,7 @@ msgstr ""
msgid "Ska"
msgstr ""
#: core/commandlineoptions.cpp:155
#: core/commandlineoptions.cpp:152
msgid "Skip backwards in playlist"
msgstr ""
@ -3667,7 +3676,7 @@ msgstr ""
msgid "Skip count"
msgstr ""
#: core/commandlineoptions.cpp:156
#: core/commandlineoptions.cpp:153
msgid "Skip forwards in playlist"
msgstr ""
@ -3763,7 +3772,7 @@ msgstr ""
msgid "Starred"
msgstr ""
#: core/commandlineoptions.cpp:151
#: core/commandlineoptions.cpp:148
msgid "Start the playlist currently playing"
msgstr ""
@ -3786,8 +3795,8 @@ msgstr ""
msgid "Starting..."
msgstr ""
#: core/globalshortcuts.cpp:48 wiimotedev/wiimotesettingspage.cpp:102
#: ../bin/src/ui_mainwindow.h:633
#: core/globalshortcuts.cpp:48 ../bin/src/ui_mainwindow.h:633
#: wiimotedev/wiimotesettingspage.cpp:102
msgid "Stop"
msgstr ""
@ -3799,7 +3808,7 @@ msgstr ""
msgid "Stop after this track"
msgstr ""
#: core/commandlineoptions.cpp:154
#: core/commandlineoptions.cpp:151
msgid "Stop playback"
msgstr ""
@ -3819,7 +3828,7 @@ msgstr ""
msgid "Streaming membership"
msgstr ""
#: internet/groovesharkservice.cpp:552
#: internet/groovesharkservice.cpp:560
msgid "Subscribed playlists"
msgstr ""
@ -4060,7 +4069,7 @@ msgstr ""
msgid "Toggle scrobbling"
msgstr ""
#: core/commandlineoptions.cpp:168
#: core/commandlineoptions.cpp:165
msgid "Toggle visibility for the pretty on-screen-display"
msgstr ""
@ -4114,7 +4123,7 @@ msgstr ""
msgid "URI"
msgstr ""
#: core/commandlineoptions.cpp:150
#: core/commandlineoptions.cpp:147
msgid "URL(s)"
msgstr ""
@ -4143,7 +4152,7 @@ msgstr ""
msgid "Unset cover"
msgstr ""
#: internet/groovesharkservice.cpp:986
#: internet/groovesharkservice.cpp:994
msgid "Update Grooveshark playlist"
msgstr ""
@ -4155,7 +4164,7 @@ msgstr ""
msgid "Update the library when Clementine starts"
msgstr ""
#: library/librarywatcher.cpp:81
#: library/librarywatcher.cpp:86
#, qt-format
msgid "Updating %1"
msgstr ""
@ -4165,11 +4174,11 @@ msgstr ""
msgid "Updating %1%..."
msgstr ""
#: library/librarywatcher.cpp:79
#: library/librarywatcher.cpp:84
msgid "Updating library"
msgstr ""
#: core/commandlineoptions.cpp:150
#: core/commandlineoptions.cpp:147
msgid "Usage"
msgstr ""
@ -4225,7 +4234,7 @@ msgstr ""
msgid "Used"
msgstr ""
#: internet/groovesharkservice.cpp:409
#: internet/groovesharkservice.cpp:412
#, qt-format
msgid "User %1 doesn't have a Grooveshark Anywhere account"
msgstr ""
@ -4663,7 +4672,7 @@ msgstr ""
msgid "on"
msgstr ""
#: core/commandlineoptions.cpp:150
#: core/commandlineoptions.cpp:147
msgid "options"
msgstr ""