mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-29 02:29:56 +01:00
Don't require each InternetService to keep track of its own current index - do it in the model instead
This commit is contained in:
parent
93938d3bcd
commit
75a897e92d
@ -56,7 +56,6 @@ DigitallyImportedServiceBase::DigitallyImportedServiceBase(
|
||||
basic_audio_type_(1),
|
||||
premium_audio_type_(2),
|
||||
root_(NULL),
|
||||
context_item_(NULL),
|
||||
saved_channels_(kSettingsGroup, api_service_name, kStreamsCacheDurationSecs),
|
||||
api_client_(new DigitallyImportedClient(api_service_name, this))
|
||||
{
|
||||
@ -171,8 +170,7 @@ void DigitallyImportedServiceBase::ReloadSettings() {
|
||||
saved_channels_.Load();
|
||||
}
|
||||
|
||||
void DigitallyImportedServiceBase::ShowContextMenu(
|
||||
const QModelIndex& index, const QPoint& global_pos) {
|
||||
void DigitallyImportedServiceBase::ShowContextMenu(const QPoint& global_pos) {
|
||||
if (!context_menu_) {
|
||||
context_menu_.reset(new QMenu);
|
||||
context_menu_->addActions(GetPlaylistActions());
|
||||
@ -188,7 +186,6 @@ void DigitallyImportedServiceBase::ShowContextMenu(
|
||||
this, SLOT(ShowSettingsDialog()));
|
||||
}
|
||||
|
||||
context_item_ = model()->itemFromIndex(index);
|
||||
context_menu_->popup(global_pos);
|
||||
}
|
||||
|
||||
@ -244,10 +241,6 @@ void DigitallyImportedServiceBase::LoadStation(const QString& key) {
|
||||
connect(reply, SIGNAL(finished()), SLOT(LoadPlaylistFinished()));
|
||||
}
|
||||
|
||||
QModelIndex DigitallyImportedServiceBase::GetCurrentIndex() {
|
||||
return context_item_->index();
|
||||
}
|
||||
|
||||
|
||||
DigitallyImportedService::DigitallyImportedService(
|
||||
Application* app, InternetModel* model, QObject* parent)
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* parent);
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
|
||||
void ReloadSettings();
|
||||
|
||||
@ -72,9 +72,6 @@ public slots:
|
||||
signals:
|
||||
void StreamsChanged();
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
void LoadPlaylistFinished();
|
||||
void Homepage();
|
||||
|
@ -428,7 +428,7 @@ void GroovesharkService::ResetSessionId() {
|
||||
s.setValue("sessionid", session_id_);
|
||||
}
|
||||
|
||||
void GroovesharkService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
|
||||
void GroovesharkService::ShowContextMenu(const QPoint& global_pos) {
|
||||
EnsureMenuCreated();
|
||||
|
||||
// Check if we should display actions
|
||||
@ -436,6 +436,8 @@ void GroovesharkService::ShowContextMenu(const QModelIndex& index, const QPoint&
|
||||
display_remove_from_playlist_action = false,
|
||||
display_remove_from_favorites_action = false;
|
||||
|
||||
QModelIndex index(model()->current_index());
|
||||
|
||||
if (index.data(InternetModel::Role_Type).toInt() == InternetModel::Type_UserPlaylist &&
|
||||
index.data(Role_PlaylistType).toInt() == UserPlaylist) {
|
||||
display_delete_playlist_action = true;
|
||||
@ -457,11 +459,6 @@ void GroovesharkService::ShowContextMenu(const QModelIndex& index, const QPoint&
|
||||
remove_from_favorites_->setVisible(display_remove_from_favorites_action);
|
||||
|
||||
context_menu_->popup(global_pos);
|
||||
context_item_ = index;
|
||||
}
|
||||
|
||||
QModelIndex GroovesharkService::GetCurrentIndex() {
|
||||
return context_item_;
|
||||
}
|
||||
|
||||
void GroovesharkService::UpdateTotalSongCount(int count) {
|
||||
@ -1153,12 +1150,12 @@ void GroovesharkService::NewPlaylistCreated(QNetworkReply* reply, const QString&
|
||||
}
|
||||
|
||||
void GroovesharkService::DeleteCurrentPlaylist() {
|
||||
if (context_item_.data(InternetModel::Role_Type).toInt() !=
|
||||
if (model()->current_index().data(InternetModel::Role_Type).toInt() !=
|
||||
InternetModel::Type_UserPlaylist) {
|
||||
return;
|
||||
}
|
||||
|
||||
int playlist_id = context_item_.data(Role_UserPlaylistId).toInt();
|
||||
int playlist_id = model()->current_index().data(Role_UserPlaylistId).toInt();
|
||||
DeletePlaylist(playlist_id);
|
||||
}
|
||||
|
||||
@ -1197,12 +1194,14 @@ void GroovesharkService::PlaylistDeleted(QNetworkReply* reply, int playlist_id)
|
||||
}
|
||||
|
||||
void GroovesharkService::RenameCurrentPlaylist() {
|
||||
if (context_item_.data(InternetModel::Role_Type).toInt() != InternetModel::Type_UserPlaylist
|
||||
|| context_item_.data(Role_PlaylistType).toInt() != UserPlaylist) {
|
||||
const QModelIndex& index(model()->current_index());
|
||||
|
||||
if (index.data(InternetModel::Role_Type).toInt() != InternetModel::Type_UserPlaylist
|
||||
|| index.data(Role_PlaylistType).toInt() != UserPlaylist) {
|
||||
return;
|
||||
}
|
||||
|
||||
int playlist_id = context_item_.data(Role_UserPlaylistId).toInt();
|
||||
const int playlist_id = index.data(Role_UserPlaylistId).toInt();
|
||||
RenamePlaylist(playlist_id);
|
||||
}
|
||||
|
||||
@ -1269,13 +1268,15 @@ void GroovesharkService::UserFavoriteSongAdded(QNetworkReply* reply, int task_id
|
||||
}
|
||||
|
||||
void GroovesharkService::RemoveCurrentFromPlaylist() {
|
||||
if (context_item_.parent().data(InternetModel::Role_Type).toInt() !=
|
||||
const QModelIndex& index(model()->current_index());
|
||||
|
||||
if (index.parent().data(InternetModel::Role_Type).toInt() !=
|
||||
InternetModel::Type_UserPlaylist) {
|
||||
return;
|
||||
}
|
||||
|
||||
int playlist_id = context_item_.data(Role_UserPlaylistId).toInt();
|
||||
int song_id = ExtractSongId(context_item_.data(InternetModel::Role_Url).toUrl());
|
||||
int playlist_id = index.data(Role_UserPlaylistId).toInt();
|
||||
int song_id = ExtractSongId(index.data(InternetModel::Role_Url).toUrl());
|
||||
if (song_id) {
|
||||
RemoveFromPlaylist(playlist_id, song_id);
|
||||
}
|
||||
@ -1293,11 +1294,13 @@ void GroovesharkService::RemoveFromPlaylist(int playlist_id, int song_id) {
|
||||
}
|
||||
|
||||
void GroovesharkService::RemoveCurrentFromFavorites() {
|
||||
if (context_item_.parent().data(Role_PlaylistType).toInt() != UserFavorites) {
|
||||
const QModelIndex& index(model()->current_index());
|
||||
|
||||
if (index.parent().data(Role_PlaylistType).toInt() != UserFavorites) {
|
||||
return;
|
||||
}
|
||||
|
||||
int song_id = ExtractSongId(context_item_.data(InternetModel::Role_Url).toUrl());
|
||||
int song_id = ExtractSongId(index.data(InternetModel::Role_Url).toUrl());
|
||||
if (song_id) {
|
||||
RemoveFromFavorites(song_id);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class GroovesharkService : public InternetService {
|
||||
smart_playlists::GeneratorPtr CreateGenerator(QStandardItem* item);
|
||||
void DropMimeData(const QMimeData* data, const QModelIndex& index);
|
||||
QList<QAction*> playlistitem_actions(const Song& song);
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
|
||||
void Search(const QString& text, Playlist* playlist, bool now = false);
|
||||
// User should be logged in to be able to generate streaming urls
|
||||
@ -128,8 +128,6 @@ class GroovesharkService : public InternetService {
|
||||
void ShowConfig();
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
struct PlaylistInfo {
|
||||
PlaylistInfo() {}
|
||||
PlaylistInfo(int id, QString name, QStandardItem* item)
|
||||
@ -245,7 +243,6 @@ class GroovesharkService : public InternetService {
|
||||
NetworkAccessManager* network_;
|
||||
|
||||
QMenu* context_menu_;
|
||||
QModelIndex context_item_;
|
||||
int current_song_id_;
|
||||
|
||||
QAction* create_playlist_;
|
||||
|
@ -273,17 +273,12 @@ QWidget* IcecastService::HeaderWidget() const {
|
||||
return filter_;
|
||||
}
|
||||
|
||||
void IcecastService::ShowContextMenu(const QModelIndex& index,
|
||||
const QPoint& global_pos) {
|
||||
void IcecastService::ShowContextMenu(const QPoint& global_pos) {
|
||||
EnsureMenuCreated();
|
||||
|
||||
if (index.model() == model_)
|
||||
context_item_ = index;
|
||||
else
|
||||
context_item_ = QModelIndex();
|
||||
|
||||
const bool can_play = context_item_.isValid() &&
|
||||
model_->GetSong(context_item_).is_valid();
|
||||
const bool can_play = model()->current_index().isValid() &&
|
||||
model()->current_index().model() == model_ &&
|
||||
model_->GetSong(model()->current_index()).is_valid();
|
||||
|
||||
GetAppendToPlaylistAction()->setEnabled(can_play);
|
||||
GetReplacePlaylistAction()->setEnabled(can_play);
|
||||
@ -308,7 +303,3 @@ void IcecastService::EnsureMenuCreated() {
|
||||
void IcecastService::Homepage() {
|
||||
QDesktopServices::openUrl(QUrl(kHomepage));
|
||||
}
|
||||
|
||||
QModelIndex IcecastService::GetCurrentIndex() {
|
||||
return context_item_;
|
||||
}
|
||||
|
@ -48,13 +48,10 @@ public:
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* item);
|
||||
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
|
||||
QWidget* HeaderWidget() const;
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
void LoadDirectory();
|
||||
void Homepage();
|
||||
@ -70,7 +67,6 @@ private:
|
||||
QStandardItem* root_;
|
||||
NetworkAccessManager* network_;
|
||||
QMenu* context_menu_;
|
||||
QModelIndex context_item_;
|
||||
|
||||
IcecastBackend* backend_;
|
||||
IcecastModel* model_;
|
||||
|
@ -255,11 +255,19 @@ bool InternetModel::dropMimeData(const QMimeData* data, Qt::DropAction action, i
|
||||
return true;
|
||||
}
|
||||
|
||||
void InternetModel::ShowContextMenu(const QModelIndex& merged_model_index,
|
||||
const QPoint& global_pos) {
|
||||
InternetService* service = ServiceForIndex(merged_model_index);
|
||||
void InternetModel::ShowContextMenu(const QModelIndexList& selected_merged_model_indexes,
|
||||
const QModelIndex& current_merged_model_index,
|
||||
const QPoint& global_pos) {
|
||||
current_index_ = merged_model_->mapToSource(current_merged_model_index);
|
||||
|
||||
selected_indexes_.clear();
|
||||
foreach (const QModelIndex& index, selected_merged_model_indexes) {
|
||||
selected_indexes_ << merged_model_->mapToSource(index);
|
||||
}
|
||||
|
||||
InternetService* service = ServiceForIndex(current_merged_model_index);
|
||||
if (service)
|
||||
service->ShowContextMenu(merged_model_->mapToSource(merged_model_index), global_pos);
|
||||
service->ShowContextMenu(global_pos);
|
||||
}
|
||||
|
||||
void InternetModel::ReloadSettings() {
|
||||
|
@ -141,13 +141,17 @@ public:
|
||||
bool hasChildren(const QModelIndex& parent) const;
|
||||
int rowCount(const QModelIndex& parent) const;
|
||||
|
||||
void ShowContextMenu(const QModelIndex& merged_model_index,
|
||||
void ShowContextMenu(const QModelIndexList& selected_merged_model_indexes,
|
||||
const QModelIndex& current_merged_model_index,
|
||||
const QPoint& global_pos);
|
||||
void ReloadSettings();
|
||||
|
||||
Application* app() const { return app_; }
|
||||
MergedProxyModel* merged_model() const { return merged_model_; }
|
||||
|
||||
const QModelIndex& current_index() const { return current_index_; }
|
||||
const QModelIndexList& selected_indexes() const { return selected_indexes_; }
|
||||
|
||||
signals:
|
||||
void StreamError(const QString& message);
|
||||
void StreamMetadataFound(const QUrl& original_url, const Song& song);
|
||||
@ -162,6 +166,11 @@ private:
|
||||
|
||||
Application* app_;
|
||||
MergedProxyModel* merged_model_;
|
||||
|
||||
// Set when a context menu is requested, can be accessed by context menu
|
||||
// actions to do things to the current item.
|
||||
QModelIndexList selected_indexes_;
|
||||
QModelIndex current_index_;
|
||||
};
|
||||
|
||||
#endif // INTERNETMODEL_H
|
||||
|
@ -94,13 +94,13 @@ void InternetService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode
|
||||
}
|
||||
|
||||
void InternetService::AppendToPlaylist() {
|
||||
AddItemToPlaylist(GetCurrentIndex(), AddMode_Append);
|
||||
AddItemsToPlaylist(model()->selected_indexes(), AddMode_Append);
|
||||
}
|
||||
|
||||
void InternetService::ReplacePlaylist() {
|
||||
AddItemToPlaylist(GetCurrentIndex(), AddMode_Replace);
|
||||
AddItemsToPlaylist(model()->selected_indexes(), AddMode_Replace);
|
||||
}
|
||||
|
||||
void InternetService::OpenInNewPlaylist() {
|
||||
AddItemToPlaylist(GetCurrentIndex(), AddMode_OpenInNew);
|
||||
AddItemsToPlaylist(model()->selected_indexes(), AddMode_OpenInNew);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
virtual QStandardItem* CreateRootItem() = 0;
|
||||
virtual void LazyPopulate(QStandardItem* parent) = 0;
|
||||
|
||||
virtual void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {}
|
||||
virtual void ShowContextMenu(const QPoint& global_pos) {}
|
||||
virtual void ItemDoubleClicked(QStandardItem* item) {}
|
||||
// Create a generator for smart playlists
|
||||
virtual smart_playlists::GeneratorPtr CreateGenerator(QStandardItem* item) { return smart_playlists::GeneratorPtr(); }
|
||||
@ -77,10 +77,6 @@ private slots:
|
||||
void OpenInNewPlaylist();
|
||||
|
||||
protected:
|
||||
// Subclass provides the currently selected QModelIndex on InternetService's
|
||||
// request.
|
||||
virtual QModelIndex GetCurrentIndex() = 0;
|
||||
|
||||
// Returns all the playlist insertion related QActions (see below).
|
||||
QList<QAction*> GetPlaylistActions();
|
||||
|
||||
|
@ -39,7 +39,8 @@ void InternetView::contextMenuEvent(QContextMenuEvent* e) {
|
||||
MergedProxyModel* merged_model = static_cast<MergedProxyModel*>(model());
|
||||
InternetModel* internet_model = static_cast<InternetModel*>(merged_model->sourceModel());
|
||||
|
||||
internet_model->ShowContextMenu(index, e->globalPos());
|
||||
internet_model->ShowContextMenu(selectionModel()->selectedRows(), index,
|
||||
e->globalPos());
|
||||
}
|
||||
|
||||
void InternetView::currentChanged(const QModelIndex ¤t, const QModelIndex&) {
|
||||
|
@ -427,16 +427,11 @@ void JamendoService::EnsureMenuCreated() {
|
||||
}
|
||||
}
|
||||
|
||||
void JamendoService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
|
||||
void JamendoService::ShowContextMenu(const QPoint& global_pos) {
|
||||
EnsureMenuCreated();
|
||||
|
||||
if (index.model() == library_sort_model_) {
|
||||
context_item_ = index;
|
||||
} else {
|
||||
context_item_ = QModelIndex();
|
||||
}
|
||||
|
||||
const bool enabled = accepted_download_ && context_item_.isValid();
|
||||
const bool enabled = accepted_download_ &&
|
||||
model()->current_index().model() == library_sort_model_;
|
||||
|
||||
//make menu items visible and enabled only when needed
|
||||
GetAppendToPlaylistAction()->setVisible(accepted_download_);
|
||||
@ -458,13 +453,9 @@ QWidget* JamendoService::HeaderWidget() const {
|
||||
return library_filter_;
|
||||
}
|
||||
|
||||
QModelIndex JamendoService::GetCurrentIndex() {
|
||||
return context_item_;
|
||||
}
|
||||
|
||||
void JamendoService::AlbumInfo() {
|
||||
SongList songs(library_model_->GetChildSongs(
|
||||
library_sort_model_->mapToSource(context_item_)));
|
||||
library_sort_model_->mapToSource(model()->current_index())));
|
||||
if (songs.isEmpty())
|
||||
return;
|
||||
|
||||
@ -478,7 +469,7 @@ void JamendoService::AlbumInfo() {
|
||||
|
||||
void JamendoService::DownloadAlbum() {
|
||||
SongList songs(library_model_->GetChildSongs(
|
||||
library_sort_model_->mapToSource(context_item_)));
|
||||
library_sort_model_->mapToSource(model()->current_index())));
|
||||
if (songs.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -41,7 +41,7 @@ class JamendoService : public InternetService {
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* item);
|
||||
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
|
||||
QWidget* HeaderWidget() const;
|
||||
|
||||
@ -66,9 +66,6 @@ class JamendoService : public InternetService {
|
||||
static const int kBatchSize;
|
||||
static const int kApproxDatabaseSize;
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private:
|
||||
void ParseDirectory(QIODevice* device) const;
|
||||
|
||||
@ -102,7 +99,6 @@ class JamendoService : public InternetService {
|
||||
NetworkAccessManager* network_;
|
||||
|
||||
QMenu* context_menu_;
|
||||
QModelIndex context_item_;
|
||||
|
||||
QAction* album_info_;
|
||||
QAction* download_album_;
|
||||
|
@ -581,10 +581,8 @@ void LastFMService::Ban() {
|
||||
app_->player()->Next();
|
||||
}
|
||||
|
||||
void LastFMService::ShowContextMenu(const QModelIndex& index, const QPoint &global_pos) {
|
||||
context_item_ = model()->itemFromIndex(index);
|
||||
|
||||
switch (index.parent().data(InternetModel::Role_Type).toInt()) {
|
||||
void LastFMService::ShowContextMenu(const QPoint& global_pos) {
|
||||
switch (model()->current_index().parent().data(InternetModel::Role_Type).toInt()) {
|
||||
case Type_Artists:
|
||||
case Type_Tags:
|
||||
case Type_Custom:
|
||||
@ -596,7 +594,7 @@ void LastFMService::ShowContextMenu(const QModelIndex& index, const QPoint &glob
|
||||
break;
|
||||
}
|
||||
|
||||
const bool playable = model()->IsPlayable(index);
|
||||
const bool playable = model()->IsPlayable(model()->current_index());
|
||||
GetAppendToPlaylistAction()->setEnabled(playable);
|
||||
GetReplacePlaylistAction()->setEnabled(playable);
|
||||
GetOpenInNewPlaylistAction()->setEnabled(playable);
|
||||
@ -753,10 +751,6 @@ void LastFMService::RefreshNeighboursFinished() {
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex LastFMService::GetCurrentIndex() {
|
||||
return context_item_->index();
|
||||
}
|
||||
|
||||
void LastFMService::AddArtistRadio() {
|
||||
AddArtistOrTag("artists", LastFMStationDialog::Artist,
|
||||
kUrlArtist, tr(kTitleArtist),
|
||||
@ -855,9 +849,10 @@ void LastFMService::RestoreList(const QString& name,
|
||||
}
|
||||
|
||||
void LastFMService::Remove() {
|
||||
int type = context_item_->parent()->data(InternetModel::Role_Type).toInt();
|
||||
QStandardItem* context_item = model()->itemFromIndex(model()->current_index());
|
||||
int type = context_item->parent()->data(InternetModel::Role_Type).toInt();
|
||||
|
||||
context_item_->parent()->removeRow(context_item_->row());
|
||||
context_item->parent()->removeRow(context_item->row());
|
||||
|
||||
if (type == Type_Artists)
|
||||
SaveList("artists", artist_list_);
|
||||
|
@ -87,7 +87,7 @@ class LastFMService : public InternetService {
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* parent);
|
||||
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint &global_pos);
|
||||
void ShowContextMenu(const QPoint &global_pos);
|
||||
|
||||
PlaylistItem::Options playlistitem_options() const;
|
||||
|
||||
@ -138,9 +138,6 @@ class LastFMService : public InternetService {
|
||||
|
||||
void SavedItemsChanged();
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
void AuthenticateReplyFinished();
|
||||
void UpdateSubscriberStatusFinished();
|
||||
@ -207,7 +204,6 @@ class LastFMService : public InternetService {
|
||||
QAction* add_tag_action_;
|
||||
QAction* add_custom_action_;
|
||||
QAction* refresh_friends_action_;
|
||||
QStandardItem* context_item_;
|
||||
|
||||
QUrl last_url_;
|
||||
bool initial_tune_;
|
||||
|
@ -288,25 +288,18 @@ void MagnatuneService::EnsureMenuCreated() {
|
||||
context_menu_->addMenu(library_filter_->menu());
|
||||
}
|
||||
|
||||
void MagnatuneService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
|
||||
void MagnatuneService::ShowContextMenu(const QPoint& global_pos) {
|
||||
EnsureMenuCreated();
|
||||
|
||||
if (index.model() == library_sort_model_)
|
||||
context_item_ = index;
|
||||
else
|
||||
context_item_ = QModelIndex();
|
||||
const bool is_valid = model()->current_index().model() == library_sort_model_;
|
||||
|
||||
GetAppendToPlaylistAction()->setEnabled(context_item_.isValid());
|
||||
GetReplacePlaylistAction()->setEnabled(context_item_.isValid());
|
||||
GetOpenInNewPlaylistAction()->setEnabled(context_item_.isValid());
|
||||
download_->setEnabled(context_item_.isValid() && membership_ == Membership_Download);
|
||||
GetAppendToPlaylistAction()->setEnabled(is_valid);
|
||||
GetReplacePlaylistAction()->setEnabled(is_valid);
|
||||
GetOpenInNewPlaylistAction()->setEnabled(is_valid);
|
||||
download_->setEnabled(is_valid && membership_ == Membership_Download);
|
||||
context_menu_->popup(global_pos);
|
||||
}
|
||||
|
||||
QModelIndex MagnatuneService::GetCurrentIndex() {
|
||||
return context_item_;
|
||||
}
|
||||
|
||||
void MagnatuneService::Homepage() {
|
||||
QDesktopServices::openUrl(QUrl(kHomepage));
|
||||
}
|
||||
@ -345,7 +338,7 @@ void MagnatuneService::ShowConfig() {
|
||||
}
|
||||
|
||||
void MagnatuneService::Download() {
|
||||
QModelIndex index = library_sort_model_->mapToSource(context_item_);
|
||||
QModelIndex index = library_sort_model_->mapToSource(model()->current_index());
|
||||
SongList songs = library_model_->GetChildSongs(index);
|
||||
|
||||
MagnatuneDownloadDialog* dialog = new MagnatuneDownloadDialog(this, 0);
|
||||
|
@ -71,7 +71,7 @@ class MagnatuneService : public InternetService {
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* item);
|
||||
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
|
||||
QWidget* HeaderWidget() const;
|
||||
|
||||
@ -89,9 +89,6 @@ class MagnatuneService : public InternetService {
|
||||
signals:
|
||||
void DownloadFinished(const QStringList& albums);
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
void UpdateTotalSongCount(int count);
|
||||
void ReloadDatabase();
|
||||
@ -110,7 +107,6 @@ class MagnatuneService : public InternetService {
|
||||
MagnatuneUrlHandler* url_handler_;
|
||||
|
||||
QMenu* context_menu_;
|
||||
QModelIndex context_item_;
|
||||
QStandardItem* root_;
|
||||
|
||||
QAction* download_;
|
||||
|
@ -93,8 +93,7 @@ void SavedRadio::SaveStreams() {
|
||||
emit StreamsChanged();
|
||||
}
|
||||
|
||||
void SavedRadio::ShowContextMenu(const QModelIndex& index,
|
||||
const QPoint& global_pos) {
|
||||
void SavedRadio::ShowContextMenu(const QPoint& global_pos) {
|
||||
if (!context_menu_) {
|
||||
context_menu_ = new QMenu;
|
||||
context_menu_->addActions(GetPlaylistActions());
|
||||
@ -104,8 +103,9 @@ void SavedRadio::ShowContextMenu(const QModelIndex& index,
|
||||
context_menu_->addAction(IconLoader::Load("document-open-remote"), tr("Add another stream..."), this, SIGNAL(ShowAddStreamDialog()));
|
||||
}
|
||||
|
||||
context_item_ = model()->itemFromIndex(index);
|
||||
const bool is_root = index.data(InternetModel::Role_Type).toInt() == InternetModel::Type_Service;
|
||||
const bool is_root =
|
||||
model()->current_index().data(InternetModel::Role_Type).toInt() ==
|
||||
InternetModel::Type_Service;
|
||||
|
||||
GetAppendToPlaylistAction()->setEnabled(!is_root);
|
||||
GetReplacePlaylistAction()->setEnabled(!is_root);
|
||||
@ -117,37 +117,37 @@ void SavedRadio::ShowContextMenu(const QModelIndex& index,
|
||||
}
|
||||
|
||||
void SavedRadio::Remove() {
|
||||
streams_.removeAll(Stream(QUrl(context_item_->data(InternetModel::Role_Url).toUrl())));
|
||||
context_item_->parent()->removeRow(context_item_->row());
|
||||
QStandardItem* context_item = model()->itemFromIndex(model()->current_index());
|
||||
|
||||
streams_.removeAll(Stream(QUrl(context_item->data(InternetModel::Role_Url).toUrl())));
|
||||
context_item->parent()->removeRow(context_item->row());
|
||||
SaveStreams();
|
||||
}
|
||||
|
||||
void SavedRadio::Edit() {
|
||||
QStandardItem* context_item = model()->itemFromIndex(model()->current_index());
|
||||
|
||||
if (!edit_dialog_) {
|
||||
edit_dialog_.reset(new AddStreamDialog);
|
||||
edit_dialog_->set_save_visible(false);
|
||||
}
|
||||
|
||||
edit_dialog_->set_name(context_item_->text());
|
||||
edit_dialog_->set_url(context_item_->data(InternetModel::Role_Url).toUrl());
|
||||
edit_dialog_->set_name(context_item->text());
|
||||
edit_dialog_->set_url(context_item->data(InternetModel::Role_Url).toUrl());
|
||||
if (edit_dialog_->exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
int i = streams_.indexOf(Stream(QUrl(context_item_->data(InternetModel::Role_Url).toUrl())));
|
||||
int i = streams_.indexOf(Stream(QUrl(context_item->data(InternetModel::Role_Url).toUrl())));
|
||||
Stream& stream = streams_[i];
|
||||
stream.name_ = edit_dialog_->name();
|
||||
stream.url_ = edit_dialog_->url();
|
||||
|
||||
context_item_->setText(stream.name_);
|
||||
context_item_->setData(stream.url_, InternetModel::Role_Url);
|
||||
context_item->setText(stream.name_);
|
||||
context_item->setData(stream.url_, InternetModel::Role_Url);
|
||||
|
||||
SaveStreams();
|
||||
}
|
||||
|
||||
QModelIndex SavedRadio::GetCurrentIndex() {
|
||||
return context_item_->index();
|
||||
}
|
||||
|
||||
void SavedRadio::AddStreamToList(const Stream& stream, QStandardItem* parent) {
|
||||
QStandardItem* s = new QStandardItem(QIcon(":last.fm/icon_radio.png"), stream.name_);
|
||||
s->setData(stream.url_, InternetModel::Role_Url);
|
||||
|
@ -55,7 +55,7 @@ class SavedRadio : public InternetService {
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* item);
|
||||
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
|
||||
void Add(const QUrl& url, const QString& name = QString());
|
||||
|
||||
@ -65,9 +65,6 @@ class SavedRadio : public InternetService {
|
||||
void ShowAddStreamDialog();
|
||||
void StreamsChanged();
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
void Remove();
|
||||
void Edit();
|
||||
@ -79,7 +76,6 @@ class SavedRadio : public InternetService {
|
||||
|
||||
private:
|
||||
QMenu* context_menu_;
|
||||
QStandardItem* context_item_;
|
||||
QStandardItem* root_;
|
||||
|
||||
QAction* remove_action_;
|
||||
|
@ -79,7 +79,7 @@ void SomaFMService::LazyPopulate(QStandardItem* item) {
|
||||
}
|
||||
}
|
||||
|
||||
void SomaFMService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
|
||||
void SomaFMService::ShowContextMenu(const QPoint& global_pos) {
|
||||
if (!context_menu_) {
|
||||
context_menu_ = new QMenu;
|
||||
context_menu_->addActions(GetPlaylistActions());
|
||||
@ -87,7 +87,6 @@ void SomaFMService::ShowContextMenu(const QModelIndex& index, const QPoint& glob
|
||||
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh channels"), this, SLOT(RefreshStreams()));
|
||||
}
|
||||
|
||||
context_item_ = model()->itemFromIndex(index);
|
||||
context_menu_->popup(global_pos);
|
||||
}
|
||||
|
||||
@ -176,10 +175,6 @@ void SomaFMService::Homepage() {
|
||||
QDesktopServices::openUrl(QUrl(kHomepage));
|
||||
}
|
||||
|
||||
QModelIndex SomaFMService::GetCurrentIndex() {
|
||||
return context_item_->index();
|
||||
}
|
||||
|
||||
PlaylistItem::Options SomaFMService::playlistitem_options() const {
|
||||
return PlaylistItem::PauseDisabled;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* item);
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
|
||||
PlaylistItem::Options playlistitem_options() const;
|
||||
QNetworkAccessManager* network() const { return network_; }
|
||||
@ -70,9 +70,6 @@ public:
|
||||
signals:
|
||||
void StreamsChanged();
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
void ForceRefreshStreams();
|
||||
void RefreshStreams();
|
||||
@ -89,7 +86,6 @@ private:
|
||||
|
||||
QStandardItem* root_;
|
||||
QMenu* context_menu_;
|
||||
QStandardItem* context_item_;
|
||||
|
||||
QNetworkAccessManager* network_;
|
||||
|
||||
|
@ -126,10 +126,6 @@ void SpotifyService::LazyPopulate(QStandardItem* item) {
|
||||
return;
|
||||
}
|
||||
|
||||
QModelIndex SpotifyService::GetCurrentIndex() {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void SpotifyService::Login(const QString& username, const QString& password) {
|
||||
Logout();
|
||||
EnsureServerCreated(username, password);
|
||||
@ -584,9 +580,9 @@ SpotifyServer* SpotifyService::server() const {
|
||||
return server_;
|
||||
}
|
||||
|
||||
void SpotifyService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
|
||||
void SpotifyService::ShowContextMenu(const QPoint& global_pos) {
|
||||
EnsureMenuCreated();
|
||||
QStandardItem* item = model()->itemFromIndex(index);
|
||||
QStandardItem* item = model()->itemFromIndex(model()->current_index());
|
||||
if (item) {
|
||||
int type = item->data(InternetModel::Role_Type).toInt();
|
||||
if (type == Type_InboxPlaylist ||
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* parent);
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
void ItemDoubleClicked(QStandardItem* item);
|
||||
void DropMimeData(const QMimeData* data, const QModelIndex& index);
|
||||
PlaylistItem::Options playlistitem_options() const;
|
||||
@ -81,9 +81,6 @@ signals:
|
||||
public slots:
|
||||
void ShowConfig();
|
||||
|
||||
protected:
|
||||
virtual QModelIndex GetCurrentIndex();
|
||||
|
||||
private:
|
||||
void StartBlobProcess();
|
||||
void FillPlaylist(QStandardItem* item, const pb::spotify::LoadPlaylistResponse& response);
|
||||
@ -132,7 +129,6 @@ private:
|
||||
QMenu* context_menu_;
|
||||
QMenu* playlist_context_menu_;
|
||||
QAction* playlist_sync_action_;
|
||||
QModelIndex context_item_;
|
||||
|
||||
QTimer* search_delay_;
|
||||
|
||||
|
@ -249,8 +249,7 @@ QStandardItem* PodcastService::CreatePodcastEpisodeItem(const PodcastEpisode& ep
|
||||
return item;
|
||||
}
|
||||
|
||||
void PodcastService::ShowContextMenu(const QModelIndex& index,
|
||||
const QPoint& global_pos) {
|
||||
void PodcastService::ShowContextMenu(const QPoint& global_pos) {
|
||||
if (!context_menu_) {
|
||||
context_menu_ = new QMenu;
|
||||
context_menu_->addAction(
|
||||
@ -277,16 +276,16 @@ void PodcastService::ShowContextMenu(const QModelIndex& index,
|
||||
this, SLOT(ShowConfig()));
|
||||
}
|
||||
|
||||
current_index_ = index;
|
||||
current_index_ = model()->current_index();
|
||||
bool is_episode = false;
|
||||
|
||||
switch (index.data(InternetModel::Role_Type).toInt()) {
|
||||
switch (current_index_.data(InternetModel::Role_Type).toInt()) {
|
||||
case Type_Podcast:
|
||||
current_podcast_index_ = index;
|
||||
current_podcast_index_ = current_index_;
|
||||
break;
|
||||
|
||||
case Type_Episode:
|
||||
current_podcast_index_ = index.parent();
|
||||
current_podcast_index_ = current_index_.parent();
|
||||
is_episode = true;
|
||||
break;
|
||||
|
||||
@ -324,10 +323,6 @@ void PodcastService::ReloadSettings() {
|
||||
// TODO: reload the podcast icons that are already loaded?
|
||||
}
|
||||
|
||||
QModelIndex PodcastService::GetCurrentIndex() {
|
||||
return current_index_;
|
||||
}
|
||||
|
||||
void PodcastService::AddPodcast() {
|
||||
if (!add_podcast_dialog_) {
|
||||
add_podcast_dialog_.reset(new AddPodcastDialog(app_));
|
||||
|
@ -56,12 +56,9 @@ public:
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* parent);
|
||||
|
||||
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
||||
void ShowContextMenu(const QPoint& global_pos);
|
||||
void ReloadSettings();
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
void AddPodcast();
|
||||
void UpdateSelectedPodcast();
|
||||
|
Loading…
x
Reference in New Issue
Block a user