Fixes to playlist context menu

- Add all playlist actions to initialization list
- Make rescan songs work for non-collection songs by using playlist item reload
- Only show add to another playlist and remove from playlist when songs are selected
- Add some missing icons

Fixes #503
This commit is contained in:
Jonas Kvinge 2020-08-07 22:13:02 +02:00
parent 1db16232de
commit c2a94b61bf
2 changed files with 70 additions and 43 deletions

View File

@ -254,9 +254,28 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
#ifdef HAVE_TIDAL
tidal_view_(new InternetTabsView(app_, app->internet_services()->ServiceBySource(Song::Source_Tidal), TidalSettingsPage::kSettingsGroup, SettingsDialog::Page_Tidal, this)),
#endif
collection_show_all_(nullptr),
collection_show_duplicates_(nullptr),
collection_show_untagged_(nullptr),
playlist_menu_(new QMenu(this)),
playlist_play_pause_(nullptr),
playlist_stop_after_(nullptr),
playlist_undoredo_(nullptr),
playlist_organize_(nullptr),
playlist_show_in_collection_(nullptr),
playlist_copy_to_collection_(nullptr),
playlist_move_to_collection_(nullptr),
#ifndef Q_OS_WIN
playlist_copy_to_device_(nullptr),
#endif
playlist_open_in_browser_(nullptr),
playlist_copy_url_(nullptr),
playlist_queue_(nullptr),
playlist_queue_play_next_(nullptr),
playlist_skip_(nullptr),
playlist_add_to_another_(nullptr),
playlistitem_actions_separator_(nullptr),
playlist_rescan_songs_(nullptr),
collection_sort_model_(new QSortFilterProxyModel(this)),
track_position_timer_(new QTimer(this)),
track_slider_timer_(new QTimer(this)),
@ -382,8 +401,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
ui_->action_shuffle->setIcon(IconLoader::Load("media-playlist-shuffle"));
ui_->action_remove_duplicates->setIcon(IconLoader::Load("list-remove"));
ui_->action_remove_unavailable->setIcon(IconLoader::Load("list-remove"));
//ui_->action_remove_from_playlist->setIcon(IconLoader::Load("list-remove"));
ui_->action_remove_from_playlist->setIcon(IconLoader::Load("list-remove"));
// Configure
@ -456,6 +474,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
connect(ui_->action_abort_collection_scan, SIGNAL(triggered()), app_->collection(), SLOT(AbortScan()));
#if defined(HAVE_GSTREAMER)
connect(ui_->action_add_files_to_transcoder, SIGNAL(triggered()), SLOT(AddFilesToTranscoder()));
ui_->action_add_files_to_transcoder->setIcon(IconLoader::Load("tools-wizard"));
#else
ui_->action_add_files_to_transcoder->setDisabled(true);
#endif
@ -632,7 +651,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
playlist_menu_->addAction(ui_->action_renumber_tracks);
playlist_menu_->addAction(ui_->action_selection_set_value);
playlist_menu_->addAction(ui_->action_auto_complete_tags);
playlist_rescan_songs_ = playlist_menu_->addAction(IconLoader::Load(""), tr("Rescan song(s)..."), this, SLOT(RescanSongs()));
playlist_rescan_songs_ = playlist_menu_->addAction(IconLoader::Load("view-refresh"), tr("Rescan song(s)..."), this, SLOT(RescanSongs()));
playlist_menu_->addAction(playlist_rescan_songs_);
#ifdef HAVE_GSTREAMER
playlist_menu_->addAction(ui_->action_add_files_to_transcoder);
@ -1629,14 +1648,14 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
}
// Are we allowed to pause?
if (index.isValid()) {
if (source_index.isValid()) {
playlist_play_pause_->setEnabled(app_->playlist_manager()->current()->current_row() != source_index.row() || !(app_->playlist_manager()->current()->item_at(source_index.row())->options() & PlaylistItem::PauseDisabled));
}
else {
playlist_play_pause_->setEnabled(false);
}
playlist_stop_after_->setEnabled(index.isValid());
playlist_stop_after_->setEnabled(source_index.isValid());
// Are any of the selected songs editable or queued?
QModelIndexList selection = ui_->playlist->view()->selectionModel()->selectedRows();
@ -1677,18 +1696,18 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
}
// this is available when we have one or many files and at least one of those is not CUE related
ui_->action_edit_track->setEnabled(editable);
ui_->action_edit_track->setVisible(editable);
ui_->action_edit_track->setEnabled(editable > 0);
ui_->action_edit_track->setVisible(editable > 0);
#if defined(HAVE_GSTREAMER) && defined(HAVE_CHROMAPRINT)
ui_->action_auto_complete_tags->setEnabled(editable);
ui_->action_auto_complete_tags->setVisible(editable);
ui_->action_auto_complete_tags->setEnabled(editable > 0);
ui_->action_auto_complete_tags->setVisible(editable > 0);
#else
ui_->action_auto_complete_tags->setEnabled(false);
ui_->action_auto_complete_tags->setVisible(false);
#endif
playlist_rescan_songs_->setEnabled(collection_songs > 0 && editable > 0);
playlist_rescan_songs_->setVisible(collection_songs > 0 && editable > 0);
playlist_rescan_songs_->setEnabled(editable > 0);
playlist_rescan_songs_->setVisible(editable > 0);
#ifdef HAVE_GSTREAMER
ui_->action_add_files_to_transcoder->setEnabled(editable);
@ -1703,8 +1722,9 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
bool track_column = (index.column() == Playlist::Column_Track);
ui_->action_renumber_tracks->setVisible(editable >= 2 && track_column);
ui_->action_selection_set_value->setVisible(editable >= 2 && !track_column);
ui_->action_edit_value->setVisible(editable);
ui_->action_remove_from_playlist->setEnabled(!selection.isEmpty());
ui_->action_edit_value->setVisible(editable > 0);
ui_->action_remove_from_playlist->setEnabled(selected > 0);
ui_->action_remove_from_playlist->setVisible(selected > 0);
playlist_show_in_collection_->setVisible(false);
playlist_copy_to_collection_->setVisible(false);
@ -1757,7 +1777,7 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
else {
Playlist::Column column = static_cast<Playlist::Column>(index.column());
bool column_is_editable = Playlist::column_is_editable(column) && editable;
bool column_is_editable = Playlist::column_is_editable(column) && editable > 0;
ui_->action_selection_set_value->setVisible(ui_->action_selection_set_value->isVisible() && column_is_editable);
ui_->action_edit_value->setVisible(ui_->action_edit_value->isVisible() && column_is_editable);
@ -1772,17 +1792,17 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
// Is it a collection item?
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
if (item && item->IsLocalCollectionItem() && item->Metadata().id() != -1) {
playlist_organize_->setVisible(editable);
playlist_show_in_collection_->setVisible(editable);
playlist_organize_->setVisible(editable > 0);
playlist_show_in_collection_->setVisible(editable > 0);
playlist_open_in_browser_->setVisible(true);
}
else {
playlist_copy_to_collection_->setVisible(editable);
playlist_move_to_collection_->setVisible(editable);
playlist_copy_to_collection_->setVisible(editable > 0);
playlist_move_to_collection_->setVisible(editable > 0);
}
#if defined(HAVE_GSTREAMER) && !defined(Q_OS_WIN)
playlist_copy_to_device_->setVisible(editable);
playlist_copy_to_device_->setVisible(editable > 0);
#endif
// Remove old item actions, if any.
@ -1800,32 +1820,36 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
if (playlist_add_to_another_ != nullptr) {
playlist_menu_->removeAction(playlist_add_to_another_);
delete playlist_add_to_another_;
playlist_add_to_another_ = nullptr;
}
// create the playlist submenu
QMenu *add_to_another_menu = new QMenu(tr("Add to another playlist"), this);
add_to_another_menu->setIcon(IconLoader::Load("list-add"));
// Create the playlist submenu if songs are selected.
if (selected > 0) {
QMenu *add_to_another_menu = new QMenu(tr("Add to another playlist"), this);
add_to_another_menu->setIcon(IconLoader::Load("list-add"));
for (const PlaylistBackend::Playlist &playlist : app_->playlist_backend()->GetAllOpenPlaylists()) {
// don't add the current playlist
if (playlist.id != app_->playlist_manager()->current()->id()) {
QAction *existing_playlist = new QAction(this);
existing_playlist->setText(playlist.name);
existing_playlist->setData(playlist.id);
add_to_another_menu->addAction(existing_playlist);
for (const PlaylistBackend::Playlist &playlist : app_->playlist_backend()->GetAllOpenPlaylists()) {
// don't add the current playlist
if (playlist.id != app_->playlist_manager()->current()->id()) {
QAction *existing_playlist = new QAction(this);
existing_playlist->setText(playlist.name);
existing_playlist->setData(playlist.id);
add_to_another_menu->addAction(existing_playlist);
}
}
add_to_another_menu->addSeparator();
// add to a new playlist
QAction *new_playlist = new QAction(this);
new_playlist->setText(tr("New playlist"));
new_playlist->setData(-1); // fake id
add_to_another_menu->addAction(new_playlist);
playlist_add_to_another_ = playlist_menu_->insertMenu(ui_->action_remove_from_playlist, add_to_another_menu);
connect(add_to_another_menu, SIGNAL(triggered(QAction*)), SLOT(AddToPlaylist(QAction*)));
}
add_to_another_menu->addSeparator();
// add to a new playlist
QAction *new_playlist = new QAction(this);
new_playlist->setText(tr("New playlist"));
new_playlist->setData(-1); // fake id
add_to_another_menu->addAction(new_playlist);
playlist_add_to_another_ = playlist_menu_->insertMenu(ui_->action_remove_from_playlist, add_to_another_menu);
connect(add_to_another_menu, SIGNAL(triggered(QAction*)), SLOT(AddToPlaylist(QAction*)));
playlist_menu_->popup(global_pos);
}
@ -1853,8 +1877,13 @@ void MainWindow::RescanSongs() {
const QModelIndex source_index = app_->playlist_manager()->current()->proxy()->mapToSource(proxy_index);
if (!source_index.isValid()) continue;
PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row()));
if (!item || !item->IsLocalCollectionItem()) continue;
songs << item->Metadata();
if (!item) continue;
if (item->IsLocalCollectionItem()) {
songs << item->Metadata();
}
else if (item->Metadata().source() == Song::Source_LocalFile) {
item->Reload();
}
}
if (songs.isEmpty()) return;

View File

@ -346,8 +346,6 @@ class MainWindow : public QMainWindow, public PlatformInterface {
QAction *playlist_add_to_another_;
QList<QAction*> playlistitem_actions_;
QAction *playlistitem_actions_separator_;
QAction *search_for_artist_;
QAction *search_for_album_;
QAction *playlist_rescan_songs_;
QModelIndex playlist_menu_index_;