Merge pull request #12591 from jdgleaver/qt-default-core-fix

(Qt) Fix default core detection when playlist file name does not match 'db_name'
This commit is contained in:
Autechre 2021-06-30 05:07:57 +02:00 committed by GitHub
commit a40c3767bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 10 deletions

View File

@ -1401,12 +1401,12 @@ void MainWindow::deleteCurrentPlaylistItem()
reloadPlaylists(); reloadPlaylists();
} }
QString MainWindow::getPlaylistDefaultCore(QString dbName) QString MainWindow::getPlaylistDefaultCore(QString plName)
{ {
playlist_config_t playlist_config; playlist_config_t playlist_config;
char playlistPath[PATH_MAX_LENGTH]; char playlistPath[PATH_MAX_LENGTH];
QByteArray dbNameByteArray = dbName.toUtf8(); QByteArray plNameByteArray = plName.toUtf8();
const char *dbNameCString = dbNameByteArray.data(); const char *plNameCString = plNameByteArray.data();
playlist_t *cachedPlaylist = playlist_get_cached(); playlist_t *cachedPlaylist = playlist_get_cached();
playlist_t *playlist = NULL; playlist_t *playlist = NULL;
bool loadPlaylist = true; bool loadPlaylist = true;
@ -1421,13 +1421,13 @@ QString MainWindow::getPlaylistDefaultCore(QString dbName)
playlistPath[0] = '\0'; playlistPath[0] = '\0';
if (!settings || string_is_empty(dbNameCString)) if (!settings || string_is_empty(plNameCString))
return corePath; return corePath;
/* Get playlist path */ /* Get playlist path */
fill_pathname_join( fill_pathname_join(
playlistPath, playlistPath,
settings->paths.directory_playlist, dbNameCString, settings->paths.directory_playlist, plNameCString,
sizeof(playlistPath)); sizeof(playlistPath));
strlcat(playlistPath, ".lpl", sizeof(playlistPath)); strlcat(playlistPath, ".lpl", sizeof(playlistPath));
@ -1479,6 +1479,7 @@ void PlaylistModel::getPlaylistItems(QString path)
QByteArray pathArray; QByteArray pathArray;
playlist_config_t playlist_config; playlist_config_t playlist_config;
const char *pathData = NULL; const char *pathData = NULL;
const char *playlistName = NULL;
playlist_t *playlist = NULL; playlist_t *playlist = NULL;
unsigned playlistSize = 0; unsigned playlistSize = 0;
unsigned i = 0; unsigned i = 0;
@ -1492,6 +1493,8 @@ void PlaylistModel::getPlaylistItems(QString path)
pathArray.append(path); pathArray.append(path);
pathData = pathArray.constData(); pathData = pathArray.constData();
if (!string_is_empty(pathData))
playlistName = path_basename(pathData);
playlist_config_set_path(&playlist_config, pathData); playlist_config_set_path(&playlist_config, pathData);
playlist = playlist_init(&playlist_config); playlist = playlist_init(&playlist_config);
@ -1536,6 +1539,12 @@ void PlaylistModel::getPlaylistItems(QString path)
hash["db_name"].remove(".lpl"); hash["db_name"].remove(".lpl");
} }
if (!string_is_empty(playlistName))
{
hash["pl_name"] = playlistName;
hash["pl_name"].remove(".lpl");
}
m_contents.append(hash); m_contents.append(hash);
} }

View File

@ -2731,12 +2731,19 @@ QHash<QString, QString> MainWindow::getSelectedCore()
break; break;
case CORE_SELECTION_PLAYLIST_DEFAULT: case CORE_SELECTION_PLAYLIST_DEFAULT:
{ {
QString plName;
QString defaultCorePath; QString defaultCorePath;
if (contentHash.isEmpty() || contentHash["db_name"].isEmpty()) if (contentHash.isEmpty())
break; break;
defaultCorePath = getPlaylistDefaultCore(contentHash["db_name"]); plName = contentHash["pl_name"].isEmpty() ?
contentHash["db_name"] : contentHash["pl_name"];
if (plName.isEmpty())
break;
defaultCorePath = getPlaylistDefaultCore(plName);
if (!defaultCorePath.isEmpty()) if (!defaultCorePath.isEmpty())
coreHash["core_path"] = defaultCorePath; coreHash["core_path"] = defaultCorePath;
@ -2845,7 +2852,10 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
break; break;
case CORE_SELECTION_PLAYLIST_DEFAULT: case CORE_SELECTION_PLAYLIST_DEFAULT:
{ {
QString defaultCorePath = getPlaylistDefaultCore(contentHash["db_name"]); QString plName = contentHash["pl_name"].isEmpty() ?
contentHash["db_name"] : contentHash["pl_name"];
QString defaultCorePath = getPlaylistDefaultCore(plName);
if (!defaultCorePath.isEmpty()) if (!defaultCorePath.isEmpty())
{ {
@ -3034,7 +3044,8 @@ void MainWindow::setCoreActions()
switch(m_currentBrowser) switch(m_currentBrowser)
{ {
case BROWSER_TYPE_PLAYLISTS: case BROWSER_TYPE_PLAYLISTS:
currentPlaylistFileName = hash["db_name"]; currentPlaylistFileName = hash["pl_name"].isEmpty() ?
hash["db_name"] : hash["pl_name"];
break; break;
case BROWSER_TYPE_FILES: case BROWSER_TYPE_FILES:
currentPlaylistFileName = m_fileModel->rootDirectory().dirName(); currentPlaylistFileName = m_fileModel->rootDirectory().dirName();

View File

@ -368,7 +368,7 @@ public:
QToolButton* runPushButton(); QToolButton* runPushButton();
QToolButton* stopPushButton(); QToolButton* stopPushButton();
QTabWidget* browserAndPlaylistTabWidget(); QTabWidget* browserAndPlaylistTabWidget();
QString getPlaylistDefaultCore(QString dbName); QString getPlaylistDefaultCore(QString plName);
ViewOptionsDialog* viewOptionsDialog(); ViewOptionsDialog* viewOptionsDialog();
QSettings* settings(); QSettings* settings();
QVector<QHash<QString, QString> > getCoreInfo(); QVector<QHash<QString, QString> > getCoreInfo();