Qt: allow special playlists (excluding all) to add/edit/delete

This commit is contained in:
Brad Parker 2018-09-21 16:32:38 -04:00
parent e64b371955
commit 329d472ee7
3 changed files with 55 additions and 31 deletions

View File

@ -81,7 +81,6 @@ void FileDropWidget::dropEvent(QDropEvent *event)
void MainWindow::onFileDropWidgetContextMenuRequested(const QPoint &pos)
{
settings_t *settings = config_get_ptr();
QScopedPointer<QMenu> menu;
QScopedPointer<QAction> downloadThumbnailAction;
QScopedPointer<QAction> addEntryAction;
@ -92,47 +91,23 @@ void MainWindow::onFileDropWidgetContextMenuRequested(const QPoint &pos)
QPointer<QAction> selectedAction;
QPoint cursorPos = QCursor::pos();
QHash<QString, QString> contentHash = getCurrentContentHash();
QDir playlistDir(settings->paths.directory_playlist);
QString playlistDirAbsPath = playlistDir.absolutePath();
QFileInfo currentPlaylistFileInfo;
QString currentPlaylistPath;
QString currentPlaylistFileName;
QString currentPlaylistDirPath;
QListWidgetItem *currentPlaylistItem = NULL;
bool specialPlaylist = false;
bool specialPlaylist = currentPlaylistIsSpecial();
bool allPlaylist = currentPlaylistIsAll();
bool actionsAdded = false;
if (m_browserAndPlaylistTabWidget->tabText(m_browserAndPlaylistTabWidget->currentIndex()) != msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_TAB_PLAYLISTS))
return;
currentPlaylistItem = m_listWidget->currentItem();
if (!currentPlaylistItem)
return;
if (currentPlaylistItem)
{
currentPlaylistPath = currentPlaylistItem->data(Qt::UserRole).toString();
currentPlaylistFileInfo = QFileInfo(currentPlaylistPath);
currentPlaylistFileName = currentPlaylistFileInfo.fileName();
currentPlaylistDirPath = currentPlaylistFileInfo.absoluteDir().absolutePath();
}
menu.reset(new QMenu(this));
/* Don't just compare strings in case there are case differences on Windows that should be ignored. */
if (QDir(currentPlaylistDirPath) != QDir(playlistDirAbsPath))
{
/* special playlists like history etc. can't have an association */
specialPlaylist = true;
}
if (!specialPlaylist)
{
downloadThumbnailAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_THUMBNAIL)), this));
menu->addAction(downloadThumbnailAction.data());
}
if (!allPlaylist)
{
addEntryAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_ENTRY)), this));
menu->addAction(addEntryAction.data());
@ -183,7 +158,11 @@ void MainWindow::onFileDropWidgetContextMenuRequested(const QPoint &pos)
}
}
}
else if (selectedAction == addFilesAction.data())
}
if (!allPlaylist)
{
if (selectedAction == addFilesAction.data())
{
QStringList filePaths = QFileDialog::getOpenFileNames(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_FILES));

View File

@ -985,6 +985,45 @@ QString MainWindow::getCurrentPlaylistPath()
return playlistPath;
}
bool MainWindow::currentPlaylistIsSpecial()
{
settings_t *settings = config_get_ptr();
QDir playlistDir(settings->paths.directory_playlist);
QString playlistDirAbsPath = playlistDir.absolutePath();
QFileInfo currentPlaylistFileInfo;
QString currentPlaylistPath;
QString currentPlaylistDirPath;
QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem();
bool specialPlaylist = false;
if (!currentPlaylistItem)
return false;
currentPlaylistPath = currentPlaylistItem->data(Qt::UserRole).toString();
currentPlaylistFileInfo = QFileInfo(currentPlaylistPath);
currentPlaylistDirPath = currentPlaylistFileInfo.absoluteDir().absolutePath();
/* Don't just compare strings in case there are case differences on Windows that should be ignored. */
if (QDir(currentPlaylistDirPath) != QDir(playlistDirAbsPath))
specialPlaylist = true;
return specialPlaylist;
}
bool MainWindow::currentPlaylistIsAll()
{
QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem();
bool all = false;
if (!currentPlaylistItem)
return false;
if (currentPlaylistItem->data(Qt::UserRole).toString() == ALL_PLAYLISTS_TOKEN)
all = true;
return all;
}
void MainWindow::deleteCurrentPlaylistItem()
{
QString playlistPath = getCurrentPlaylistPath();
@ -994,6 +1033,10 @@ void MainWindow::deleteCurrentPlaylistItem()
const char *playlistData = NULL;
unsigned index = 0;
bool ok = false;
bool isAllPlaylist = currentPlaylistIsAll();
if (isAllPlaylist)
return;
if (playlistPath.isEmpty())
return;

View File

@ -452,6 +452,8 @@ private:
void removeUpdateTempFiles();
bool addDirectoryFilesToList(QProgressDialog *dialog, QStringList &list, QDir &dir, QStringList &extensions);
void renamePlaylistItem(QListWidgetItem *item, QString newName);
bool currentPlaylistIsSpecial();
bool currentPlaylistIsAll();
QVector<QHash<QString, QString> > getPlaylistItems(QString pathString);
LoadCoreWindow *m_loadCoreWindow;