From 96380053322feba3cd3ec9fecc95f7ee87975033 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Sun, 26 Aug 2018 17:17:39 -0400 Subject: [PATCH] Qt: add UI option to set startup playlist, fixes #7103 --- intl/msg_hash_ja.h | 2 ++ intl/msg_hash_us.h | 2 ++ msg_hash.h | 1 + ui/drivers/qt/ui_qt_window.cpp | 29 ++++++++++++++++++++++++++++- ui/drivers/qt/viewoptionsdialog.cpp | 21 +++++++++++++++++++++ ui/drivers/qt/viewoptionsdialog.h | 1 + ui/drivers/ui_qt.h | 1 + 7 files changed, 56 insertions(+), 1 deletion(-) diff --git a/intl/msg_hash_ja.h b/intl/msg_hash_ja.h index de56179467..ca2fca063d 100644 --- a/intl/msg_hash_ja.h +++ b/intl/msg_hash_ja.h @@ -3792,3 +3792,5 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_THUMBNAIL, "サムネイルをダウンロード") MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALREADY_IN_PROGRESS, "他のダウンロードが実行中です。") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_STARTUP_PLAYLIST, + "起動時に表示するプレイリスト:") diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 675a4809eb..b88c1049c4 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -7390,3 +7390,5 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_THUMBNAIL, "Download thumbnail") MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALREADY_IN_PROGRESS, "A download is already in progress.") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_STARTUP_PLAYLIST, + "Start on playlist:") diff --git a/msg_hash.h b/msg_hash.h index e87319e4de..7e69b4e23c 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1913,6 +1913,7 @@ enum msg_hash_enums MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SHOW_HIDDEN_FILES, MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_ALL_PLAYLISTS_LIST_MAX_COUNT, MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_ALL_PLAYLISTS_GRID_MAX_COUNT, + MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_STARTUP_PLAYLIST, MENU_ENUM_LABEL_VALUE_QT_MENU_TOOLS, MENU_ENUM_LABEL_VALUE_QT_MENU_HELP, MENU_ENUM_LABEL_VALUE_QT_MENU_DOCK_CONTENT_BROWSER, diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index bcacb88944..a2251d1625 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -605,6 +605,33 @@ MainWindow::~MainWindow() removeGridItems(); } +QVector > MainWindow::getPlaylists() +{ + QVector > playlists; + int i; + + for (i = 0; i < m_listWidget->count(); i++) + { + QListWidgetItem *item = m_listWidget->item(i); + QPair pair; + QString label; + QString path; + + if (!item) + continue; + + label = item->text(); + path = item->data(Qt::UserRole).toString(); + + pair.first = label; + pair.second = path; + + playlists.append(pair); + } + + return playlists; +} + void MainWindow::onItemChanged() { ViewType viewType = getCurrentViewType(); @@ -633,7 +660,7 @@ QString MainWindow::getSpecialPlaylistPath(SpecialPlaylist playlist) switch (playlist) { case SPECIAL_PLAYLIST_HISTORY: - return m_historyPlaylistsItem->data(Qt::UserRole).toString(); + return (m_historyPlaylistsItem ? m_historyPlaylistsItem->data(Qt::UserRole).toString() : QString()); default: return QString(); } diff --git a/ui/drivers/qt/viewoptionsdialog.cpp b/ui/drivers/qt/viewoptionsdialog.cpp index a293b01a00..5d9bce0466 100644 --- a/ui/drivers/qt/viewoptionsdialog.cpp +++ b/ui/drivers/qt/viewoptionsdialog.cpp @@ -27,6 +27,7 @@ ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) : ,m_saveLastTabCheckBox(new QCheckBox(this)) ,m_showHiddenFilesCheckBox(new QCheckBox(this)) ,m_themeComboBox(new QComboBox(this)) + ,m_startupPlaylistComboBox(new QComboBox(this)) ,m_highlightColorPushButton(new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CHOOSE), this)) ,m_highlightColor() ,m_highlightColorLabel(new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_HIGHLIGHT_COLOR), this)) @@ -65,6 +66,7 @@ ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) : form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SUGGEST_LOADED_CORE_FIRST), m_suggestLoadedCoreFirstCheckBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_ALL_PLAYLISTS_LIST_MAX_COUNT), m_allPlaylistsListMaxCountSpinBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_ALL_PLAYLISTS_GRID_MAX_COUNT), m_allPlaylistsGridMaxCountSpinBox); + form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_STARTUP_PLAYLIST), m_startupPlaylistComboBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THEME), m_themeComboBox); form->addRow(m_highlightColorLabel, m_highlightColorPushButton); @@ -133,7 +135,11 @@ void ViewOptionsDialog::loadViewOptions() { QColor highlightColor = m_settings->value("highlight_color", QApplication::palette().highlight().color()).value(); QPixmap highlightPixmap(m_highlightColorPushButton->iconSize()); + QVector > playlists = m_mainwindow->getPlaylists(); + QString initialPlaylist = m_settings->value("initial_playlist", m_mainwindow->getSpecialPlaylistPath(SPECIAL_PLAYLIST_HISTORY)).toString(); int themeIndex = 0; + int playlistIndex = 0; + int i; m_saveGeometryCheckBox->setChecked(m_settings->value("save_geometry", false).toBool()); m_saveDockPositionsCheckBox->setChecked(m_settings->value("save_dock_positions", false).toBool()); @@ -156,6 +162,20 @@ void ViewOptionsDialog::loadViewOptions() } showOrHideHighlightColor(); + + m_startupPlaylistComboBox->clear(); + + for (i = 0; i < playlists.count(); i++) + { + const QPair &pair = playlists.at(i); + + m_startupPlaylistComboBox->addItem(pair.first, pair.second); + } + + playlistIndex = m_startupPlaylistComboBox->findData(initialPlaylist, Qt::UserRole, Qt::MatchFixedString); + + if (playlistIndex >= 0) + m_startupPlaylistComboBox->setCurrentIndex(playlistIndex); } void ViewOptionsDialog::showOrHideHighlightColor() @@ -183,6 +203,7 @@ void ViewOptionsDialog::saveViewOptions() m_settings->setValue("suggest_loaded_core_first", m_suggestLoadedCoreFirstCheckBox->isChecked()); m_settings->setValue("all_playlists_list_max_count", m_allPlaylistsListMaxCountSpinBox->value()); m_settings->setValue("all_playlists_grid_max_count", m_allPlaylistsGridMaxCountSpinBox->value()); + m_settings->setValue("initial_playlist", m_startupPlaylistComboBox->currentData(Qt::UserRole).toString()); if (!m_mainwindow->customThemeString().isEmpty()) m_settings->setValue("custom_theme", m_customThemePath); diff --git a/ui/drivers/qt/viewoptionsdialog.h b/ui/drivers/qt/viewoptionsdialog.h index 7b5c7c71fe..faf0f143df 100644 --- a/ui/drivers/qt/viewoptionsdialog.h +++ b/ui/drivers/qt/viewoptionsdialog.h @@ -37,6 +37,7 @@ private: QCheckBox *m_saveLastTabCheckBox; QCheckBox *m_showHiddenFilesCheckBox; QComboBox *m_themeComboBox; + QComboBox *m_startupPlaylistComboBox; QPushButton *m_highlightColorPushButton; QColor m_highlightColor; QLabel *m_highlightColorLabel; diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 69d8b899eb..d55f076f6e 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -285,6 +285,7 @@ public: QHash getCurrentContentHash(); static double lerp(double x, double y, double a, double b, double d); QString getSpecialPlaylistPath(SpecialPlaylist playlist); + QVector > getPlaylists(); signals: void thumbnailChanged(const QPixmap &pixmap);