Qt: start on history playlist by default, UI option to change it will come later

This commit is contained in:
Brad Parker 2018-08-21 13:39:16 -04:00
parent 94ec9233f6
commit 06daa1f9ef
4 changed files with 74 additions and 11 deletions

View File

@ -750,7 +750,10 @@ void MainWindow::reloadPlaylists()
if (firstItem)
{
bool found = false;
bool foundCurrent = false;
bool foundInitial = false;
QString initialPlaylist = m_settings->value("initial_playlist", m_historyPlaylistsItem->data(Qt::UserRole).toString()).toString();
QListWidgetItem *initialItem = NULL;
for (i = 0; i < m_listWidget->count(); i++)
{
@ -761,21 +764,35 @@ void MainWindow::reloadPlaylists()
{
path = item->data(Qt::UserRole).toString();
if (!currentPlaylistPath.isEmpty() && !path.isEmpty())
if (!path.isEmpty())
{
if (path == currentPlaylistPath)
/* don't break early here since we want to make sure we've found both initial and current items if they exist */
if (!foundInitial && path == initialPlaylist)
{
found = true;
foundInitial = true;
initialItem = item;
}
if (!foundCurrent && !currentPlaylistPath.isEmpty() && path == currentPlaylistPath)
{
foundCurrent = true;
m_listWidget->setCurrentItem(item);
break;
}
}
}
}
/* the previous playlist must be gone now, just select the first one */
if (!found)
m_listWidget->setCurrentItem(firstItem);
if (!foundCurrent)
{
if (foundInitial && initialItem)
{
m_listWidget->setCurrentItem(initialItem);
}
else
{
/* the previous playlist must be gone now, just select the first one */
m_listWidget->setCurrentItem(firstItem);
}
}
}
}
}

View File

@ -581,6 +581,17 @@ MainWindow::~MainWindow()
removeGridItems();
}
QString MainWindow::getSpecialPlaylistPath(SpecialPlaylist playlist)
{
switch (playlist)
{
case SPECIAL_PLAYLIST_HISTORY:
return m_historyPlaylistsItem->data(Qt::UserRole).toString();
default:
return QString();
}
}
double MainWindow::lerp(double x, double y, double a, double b, double d) {
return a + (b - a) * ((double)(d - x) / (double)(y - x));
}

View File

@ -260,6 +260,9 @@ static void* ui_companion_qt_init(void)
QComboBox *launchWithComboBox = NULL;
QSettings *qsettings = NULL;
QListWidget *listWidget = NULL;
QString initialPlaylist;
bool foundPlaylist = false;
int i = 0;
if (!handle)
@ -275,6 +278,8 @@ static void* ui_companion_qt_init(void)
qsettings = mainwindow->settings();
initialPlaylist = qsettings->value("initial_playlist", mainwindow->getSpecialPlaylistPath(SPECIAL_PLAYLIST_HISTORY)).toString();
mainwindow->resize(qMin(desktopRect.width(), INITIAL_WIDTH), qMin(desktopRect.height(), INITIAL_HEIGHT));
mainwindow->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, mainwindow->size(), desktopRect));
@ -571,16 +576,40 @@ static void* ui_companion_qt_init(void)
mainwindow->onTabWidgetIndexChanged(0);
}
for (i = 0; i < listWidget->count() && listWidget->count() > 0; i++)
/* the initial playlist that is selected is based on the user's setting (initialPlaylist) */
for (i = 0; listWidget->count() && i < listWidget->count(); i++)
{
/* select the first non-hidden row */
if (!listWidget->isRowHidden(i))
QListWidgetItem *item = listWidget->item(i);
QString path;
if (!item)
continue;
path = item->data(Qt::UserRole).toString();
if (path == initialPlaylist)
{
foundPlaylist = true;
listWidget->setRowHidden(i, false);
listWidget->setCurrentRow(i);
break;
}
}
/* couldn't find the user's initial playlist, just find anything */
if (!foundPlaylist)
{
for (i = 0; listWidget->count() && i < listWidget->count(); i++)
{
/* select the first non-hidden row */
if (!listWidget->isRowHidden(i))
{
listWidget->setCurrentRow(i);
break;
}
}
}
return handle;
}

View File

@ -87,6 +87,11 @@ class CoreInfoDialog;
class PlaylistEntryDialog;
class ViewOptionsDialog;
enum SpecialPlaylist
{
SPECIAL_PLAYLIST_HISTORY
};
class GridItem : public QObject
{
Q_OBJECT
@ -277,6 +282,7 @@ public:
QString getCurrentPlaylistPath();
QHash<QString, QString> getCurrentContentHash();
static double lerp(double x, double y, double a, double b, double d);
QString getSpecialPlaylistPath(SpecialPlaylist playlist);
signals:
void thumbnailChanged(const QPixmap &pixmap);