Add an action to get GS songs' URLs to share

This commit is contained in:
Arnaud Bienner 2011-11-10 00:56:27 +01:00
parent bfea7b8945
commit 5479239d81
3 changed files with 71 additions and 15 deletions

View File

@ -19,12 +19,15 @@
#include <boost/scoped_ptr.hpp>
#include <QApplication>
#include <QClipboard>
#include <QInputDialog>
#include <QMenu>
#include <QMessageBox>
#include <QMimeData>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QPushButton>
#include <QTimer>
#include <qjson/parser.h>
@ -751,12 +754,50 @@ QList<QAction*> GroovesharkService::playlistitem_actions(const Song& song) {
add_to_playlists->setMenu(playlists_menu);
playlistitem_actions_.append(add_to_playlists);
QAction* share_song = new QAction(tr("Get an URL to share this Grooveshark song"), this);
connect(share_song, SIGNAL(triggered()), SLOT(GetCurrentSongUrlToShare()));
playlistitem_actions_.append(share_song);
// Keep in mind the current song id
current_song_id_ = ExtractSongId(song.url());
return playlistitem_actions_;
}
void GroovesharkService::GetCurrentSongUrlToShare() {
GetSongUrlToShare(current_song_id_);
}
void GroovesharkService::GetSongUrlToShare(int song_id) {
QList<Param> parameters;
parameters << Param("songID", song_id);
QNetworkReply* reply = CreateRequest("getSongURLFromSongID", parameters, true);
NewClosure(reply, SIGNAL(finished()), this,
SLOT(SongUrlToShareReceived(QNetworkReply*)), reply);
}
void GroovesharkService::SongUrlToShareReceived(QNetworkReply* reply) {
reply->deleteLater();
QVariantMap result = ExtractResult(reply);
if (!result["url"].isValid())
return;
QString url = result["url"].toString();
QMessageBox url_box;
url_box.setWindowTitle(tr("Grooveshark song's URL"));
url_box.setText(url);
url_box.setStandardButtons(QMessageBox::Ok);
QPushButton* copy_to_clipboard_button = url_box.addButton(tr("Copy to clipboard"), QMessageBox::ActionRole);
url_box.exec();
if (url_box.clickedButton() == copy_to_clipboard_button) {
QApplication::clipboard()->setText(url);
}
}
void GroovesharkService::AddCurrentSongToPlaylist(QAction* action) {
int playlist_id = action->data().toInt();
if (!playlists_.contains(playlist_id)) {

View File

@ -85,6 +85,7 @@ class GroovesharkService : public InternetService {
void DeletePlaylist(int playlist_id);
void AddUserFavoriteSong(int song_id);
void RemoveFromFavorites(int song_id);
void GetSongUrlToShare(int song_id);
void MarkStreamKeyOver30Secs(const QString& stream_key, const QString& server_id);
void MarkSongComplete(const QString& song_id, const QString& stream_key, const QString& server_id);
@ -145,6 +146,8 @@ class GroovesharkService : public InternetService {
void AddCurrentSongToUserFavorites() { AddUserFavoriteSong(current_song_id_); }
void AddCurrentSongToPlaylist(QAction* action);
void UserFavoriteSongAdded(QNetworkReply* reply);
void GetCurrentSongUrlToShare();
void SongUrlToShareReceived(QNetworkReply* reply);
void RemoveCurrentFromPlaylist();
void RemoveCurrentFromFavorites();
void SongRemovedFromFavorites(QNetworkReply* reply);

View File

@ -419,11 +419,11 @@ msgstr ""
msgid "Add stream..."
msgstr ""
#: internet/groovesharkservice.cpp:738
#: internet/groovesharkservice.cpp:740
msgid "Add to Grooveshark favorites"
msgstr ""
#: internet/groovesharkservice.cpp:744
#: internet/groovesharkservice.cpp:746
msgid "Add to Grooveshark playlists"
msgstr ""
@ -618,7 +618,7 @@ msgstr ""
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
#: internet/groovesharkservice.cpp:865
#: internet/groovesharkservice.cpp:905
msgid "Are you sure you want to delete this playlist?"
msgstr ""
@ -972,7 +972,7 @@ msgstr ""
msgid "Composer"
msgstr ""
#: internet/groovesharkservice.cpp:475
#: internet/groovesharkservice.cpp:477
msgid "Configure Grooveshark..."
msgstr ""
@ -1025,6 +1025,10 @@ msgstr ""
msgid "Convert any music that the device can't play"
msgstr ""
#: internet/groovesharkservice.cpp:792
msgid "Copy to clipboard"
msgstr ""
#: library/libraryview.cpp:265 ui/mainwindow.cpp:524
#: widgets/fileviewlist.cpp:43
msgid "Copy to device..."
@ -1100,7 +1104,7 @@ msgstr ""
msgid "Covers from %1"
msgstr ""
#: internet/groovesharkservice.cpp:460 internet/groovesharkservice.cpp:817
#: internet/groovesharkservice.cpp:462 internet/groovesharkservice.cpp:857
msgid "Create a new Grooveshark playlist"
msgstr ""
@ -1240,7 +1244,7 @@ msgstr ""
msgid "Delay between visualizations"
msgstr ""
#: internet/groovesharkservice.cpp:463 internet/groovesharkservice.cpp:864
#: internet/groovesharkservice.cpp:465 internet/groovesharkservice.cpp:904
msgid "Delete Grooveshark playlist"
msgstr ""
@ -1663,7 +1667,7 @@ msgstr ""
msgid "Fast"
msgstr ""
#: internet/groovesharkservice.cpp:601
#: internet/groovesharkservice.cpp:603
msgid "Favorites"
msgstr ""
@ -1838,6 +1842,10 @@ msgstr ""
msgid "Genre"
msgstr ""
#: internet/groovesharkservice.cpp:757
msgid "Get an URL to share this Grooveshark song"
msgstr ""
#: internet/somafmservice.cpp:94
msgid "Getting channels"
msgstr ""
@ -1880,10 +1888,14 @@ msgstr ""
msgid "Grooveshark"
msgstr ""
#: internet/groovesharkservice.cpp:389
#: internet/groovesharkservice.cpp:391
msgid "Grooveshark login error"
msgstr ""
#: internet/groovesharkservice.cpp:789
msgid "Grooveshark song's URL"
msgstr ""
#: ui_groupbydialog.h:124
msgid "Group Library by..."
msgstr ""
@ -2075,7 +2087,7 @@ msgstr ""
msgid "Invalid session key"
msgstr ""
#: internet/groovesharkservice.cpp:382
#: internet/groovesharkservice.cpp:384
msgid "Invalid username and/or password"
msgstr ""
@ -2543,7 +2555,7 @@ msgstr ""
msgid "My Recommendations"
msgstr ""
#: internet/groovesharkservice.cpp:818 ui/equalizer.cpp:172
#: internet/groovesharkservice.cpp:858 ui/equalizer.cpp:172
#: ui_deviceproperties.h:369 ui_magnatunedownloaddialog.h:135
#: ui_wizardfinishpage.h:84 ui_globalshortcutssettingspage.h:174
msgid "Name"
@ -3141,11 +3153,11 @@ msgstr ""
msgid "Remove folder"
msgstr ""
#: internet/groovesharkservice.cpp:470
#: internet/groovesharkservice.cpp:472
msgid "Remove from favorites"
msgstr ""
#: internet/groovesharkservice.cpp:467 ui_mainwindow.h:674
#: internet/groovesharkservice.cpp:469 ui_mainwindow.h:674
msgid "Remove from playlist"
msgstr ""
@ -3300,11 +3312,11 @@ msgid "Search"
msgstr ""
#: internet/groovesharksearchplaylisttype.cpp:32
#: internet/groovesharkservice.cpp:673
#: internet/groovesharkservice.cpp:675
msgid "Search Grooveshark"
msgstr ""
#: internet/groovesharkservice.cpp:473 internet/groovesharkservice.cpp:482
#: internet/groovesharkservice.cpp:475 internet/groovesharkservice.cpp:484
msgid "Search Grooveshark (opens a new tab)"
msgstr ""
@ -4120,7 +4132,7 @@ msgstr ""
msgid "Used"
msgstr ""
#: internet/groovesharkservice.cpp:385
#: internet/groovesharkservice.cpp:387
#, qt-format
msgid "User %1 doesn't have a Grooveshark Anywhere account"
msgstr ""