mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 19:31:02 +01:00
Ability to rename GS playlists
This commit is contained in:
parent
efbd19fb36
commit
ff7cd0334e
@ -88,6 +88,9 @@ GroovesharkService::GroovesharkService(InternetModel *parent)
|
||||
subscribed_playlists_divider_(NULL),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
context_menu_(NULL),
|
||||
create_playlist_(NULL),
|
||||
delete_playlist_(NULL),
|
||||
rename_playlist_(NULL),
|
||||
remove_from_playlist_(NULL),
|
||||
remove_from_favorites_(NULL),
|
||||
search_delay_(new QTimer(this)),
|
||||
@ -466,6 +469,8 @@ void GroovesharkService::ShowContextMenu(const QModelIndex& index, const QPoint&
|
||||
display_remove_from_playlist_action = true;
|
||||
}
|
||||
delete_playlist_->setVisible(display_delete_playlist_action);
|
||||
// If we can delete this playlist, we can also rename it
|
||||
rename_playlist_->setVisible(display_delete_playlist_action);
|
||||
remove_from_playlist_->setVisible(display_remove_from_playlist_action);
|
||||
remove_from_favorites_->setVisible(display_remove_from_favorites_action);
|
||||
|
||||
@ -490,6 +495,9 @@ void GroovesharkService::EnsureMenuCreated() {
|
||||
delete_playlist_ = context_menu_->addAction(
|
||||
IconLoader::Load("edit-delete"), tr("Delete Grooveshark playlist"),
|
||||
this, SLOT(DeleteCurrentPlaylist()));
|
||||
rename_playlist_ = context_menu_->addAction(
|
||||
IconLoader::Load("edit-rename"), tr("Rename Grooveshark playlist"),
|
||||
this, SLOT(RenameCurrentPlaylist()));
|
||||
context_menu_->addSeparator();
|
||||
remove_from_playlist_ = context_menu_->addAction(
|
||||
IconLoader::Load("list-remove"), tr("Remove from playlist"),
|
||||
@ -1104,6 +1112,54 @@ void GroovesharkService::PlaylistDeleted(QNetworkReply* reply, int playlist_id)
|
||||
root_->removeRow(playlist_info.item_->row());
|
||||
}
|
||||
|
||||
void GroovesharkService::RenameCurrentPlaylist() {
|
||||
if (context_item_.data(InternetModel::Role_Type).toInt() != InternetModel::Type_UserPlaylist
|
||||
|| context_item_.data(Role_PlaylistType).toInt() != UserPlaylist) {
|
||||
return;
|
||||
}
|
||||
|
||||
int playlist_id = context_item_.data(Role_UserPlaylistId).toInt();
|
||||
RenamePlaylist(playlist_id);
|
||||
}
|
||||
|
||||
void GroovesharkService::RenamePlaylist(int playlist_id) {
|
||||
if (!playlists_.contains(playlist_id)) {
|
||||
return;
|
||||
}
|
||||
const QString& old_name = playlists_[playlist_id].name_;
|
||||
QString new_name = QInputDialog::getText(NULL,
|
||||
tr("Rename \"%1\" playlist").arg(old_name),
|
||||
tr("Name"),
|
||||
QLineEdit::Normal);
|
||||
if (new_name.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<Param> parameters;
|
||||
parameters << Param("playlistID", playlist_id)
|
||||
<< Param("name", new_name);
|
||||
QNetworkReply* reply = CreateRequest("renamePlaylist", parameters);
|
||||
NewClosure(reply, SIGNAL(finished()),
|
||||
this, SLOT(PlaylistRenamed(QNetworkReply*, int, const QString&)), reply, playlist_id, new_name);
|
||||
}
|
||||
|
||||
void GroovesharkService::PlaylistRenamed(QNetworkReply* reply,
|
||||
int playlist_id,
|
||||
const QString& new_name) {
|
||||
reply->deleteLater();
|
||||
QVariantMap result = ExtractResult(reply);
|
||||
if (!result["success"].toBool()) {
|
||||
qLog(Warning) << "Grooveshark renamePlaylist failed";
|
||||
return;
|
||||
}
|
||||
if (!playlists_.contains(playlist_id)) {
|
||||
return;
|
||||
}
|
||||
PlaylistInfo& playlist_info = playlists_[playlist_id];
|
||||
playlist_info.name_ = new_name;
|
||||
playlist_info.item_->setText(new_name);
|
||||
}
|
||||
|
||||
void GroovesharkService::AddUserFavoriteSong(int song_id) {
|
||||
int task_id = model()->task_manager()->StartTask(tr("Adding song to favorites"));
|
||||
QList<Param> parameters;
|
||||
|
@ -88,6 +88,7 @@ class GroovesharkService : public InternetService {
|
||||
// Refresh playlist_id playlist , or create it if it doesn't exist
|
||||
void RefreshPlaylist(int playlist_id, const QString& playlist_name);
|
||||
void DeletePlaylist(int playlist_id);
|
||||
void RenamePlaylist(int playlist_id);
|
||||
void AddUserFavoriteSong(int song_id);
|
||||
void RemoveFromFavorites(int song_id);
|
||||
void GetSongUrlToShare(int song_id);
|
||||
@ -150,7 +151,9 @@ class GroovesharkService : public InternetService {
|
||||
void CreateNewPlaylist();
|
||||
void NewPlaylistCreated(QNetworkReply* reply, const QString& name);
|
||||
void DeleteCurrentPlaylist();
|
||||
void RenameCurrentPlaylist();
|
||||
void PlaylistDeleted(QNetworkReply* reply, int playlist_id);
|
||||
void PlaylistRenamed(QNetworkReply* reply, int playlist_id, const QString& new_name);
|
||||
void AddCurrentSongToUserFavorites() { AddUserFavoriteSong(current_song_id_); }
|
||||
void AddCurrentSongToPlaylist(QAction* action);
|
||||
void UserFavoriteSongAdded(QNetworkReply* reply, int task_id);
|
||||
@ -221,6 +224,7 @@ class GroovesharkService : public InternetService {
|
||||
|
||||
QAction* create_playlist_;
|
||||
QAction* delete_playlist_;
|
||||
QAction* rename_playlist_;
|
||||
QAction* remove_from_playlist_;
|
||||
QAction* remove_from_favorites_;
|
||||
QList<QAction*> playlistitem_actions_;
|
||||
|
Loading…
Reference in New Issue
Block a user