diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index 5d7f259dd7..5c10100f78 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -4,6 +4,7 @@ #include +#include "DolphinQt2/Settings.h" #include "DolphinQt2/GameList/GameList.h" #include "DolphinQt2/GameList/ListProxyModel.h" #include "DolphinQt2/GameList/TableProxyModel.h" @@ -18,15 +19,20 @@ GameList::GameList(QWidget* parent): QStackedWidget(parent) MakeTableView(); MakeListView(); + MakeEmptyView(); connect(m_table, &QTableView::doubleClicked, this, &GameList::GameSelected); connect(m_list, &QListView::doubleClicked, this, &GameList::GameSelected); connect(this, &GameList::DirectoryAdded, m_model, &GameListModel::DirectoryAdded); connect(this, &GameList::DirectoryRemoved, m_model, &GameListModel::DirectoryRemoved); + connect(m_model, &QAbstractItemModel::rowsInserted, this, &GameList::ConsiderViewChange); + connect(m_model, &QAbstractItemModel::rowsRemoved, this, &GameList::ConsiderViewChange); addWidget(m_table); addWidget(m_list); - setCurrentWidget(m_table); + addWidget(m_empty); + m_prefer_table = Settings().GetPreferredView(); + ConsiderViewChange(); } void GameList::MakeTableView() @@ -63,6 +69,14 @@ void GameList::MakeTableView() header->setSectionResizeMode(GameListModel::COL_RATING, QHeaderView::Fixed); } +void GameList::MakeEmptyView() +{ + m_empty = new QLabel(this); + m_empty->setText(tr("Dolphin did not find any game files.\n" + "Open the Paths dialog to add game folders.")); + m_empty->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); +} + void GameList::MakeListView() { m_list = new QListView(this); @@ -94,3 +108,25 @@ QString GameList::GetSelectedGame() const } return QStringLiteral(); } + +void GameList::SetPreferredView(bool table) +{ + m_prefer_table = table; + Settings().SetPreferredView(table); + ConsiderViewChange(); +} + +void GameList::ConsiderViewChange() +{ + if (m_model->rowCount(QModelIndex()) > 0) + { + if (m_prefer_table) + setCurrentWidget(m_table); + else + setCurrentWidget(m_list); + } + else + { + setCurrentWidget(m_empty); + } +} diff --git a/Source/Core/DolphinQt2/GameList/GameList.h b/Source/Core/DolphinQt2/GameList/GameList.h index c926f0cada..8b6e7628aa 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.h +++ b/Source/Core/DolphinQt2/GameList/GameList.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -22,18 +23,22 @@ public: QString GetSelectedGame() const; public slots: - void SetTableView() { setCurrentWidget(m_table); } - void SetListView() { setCurrentWidget(m_list); } + void SetTableView() { SetPreferredView(true); } + void SetListView() { SetPreferredView(false); } void SetViewColumn(int col, bool view) { m_table->setColumnHidden(col, !view); } signals: void GameSelected(); - void DirectoryAdded(QString dir); - void DirectoryRemoved(QString dir); + void DirectoryAdded(const QString& dir); + void DirectoryRemoved(const QString& dir); private: void MakeTableView(); void MakeListView(); + void MakeEmptyView(); + // We only have two views, just use a bool to distinguish. + void SetPreferredView(bool table); + void ConsiderViewChange(); GameListModel* m_model; QSortFilterProxyModel* m_table_proxy; @@ -41,4 +46,6 @@ private: QListView* m_list; QTableView* m_table; + QLabel* m_empty; + bool m_prefer_table; }; diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index 3a2a205b53..e9f015218a 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -81,7 +81,7 @@ void GameListModel::UpdateGame(QSharedPointer game) endInsertRows(); } -void GameListModel::RemoveGame(QString path) +void GameListModel::RemoveGame(const QString& path) { int entry = FindGame(path); if (entry < 0) diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.h b/Source/Core/DolphinQt2/GameList/GameListModel.h index a387e6cfe0..0193d0312f 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.h +++ b/Source/Core/DolphinQt2/GameList/GameListModel.h @@ -42,11 +42,11 @@ public: public slots: void UpdateGame(QSharedPointer game); - void RemoveGame(QString path); + void RemoveGame(const QString& path); signals: - void DirectoryAdded(QString dir); - void DirectoryRemoved(QString dir); + void DirectoryAdded(const QString& dir); + void DirectoryRemoved(const QString& dir); private: // Index in m_games, or -1 if it isn't found diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index b26bd9972f..ef42f01cc6 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -45,7 +45,7 @@ GameTracker::~GameTracker() m_loader_thread.wait(); } -void GameTracker::AddDirectory(QString dir) +void GameTracker::AddDirectory(const QString& dir) { if (!QFileInfo(dir).exists()) return; @@ -53,7 +53,7 @@ void GameTracker::AddDirectory(QString dir) UpdateDirectory(dir); } -void GameTracker::RemoveDirectory(QString dir) +void GameTracker::RemoveDirectory(const QString& dir) { removePath(dir); QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.h b/Source/Core/DolphinQt2/GameList/GameTracker.h index c5a6f41dd9..b3493cc522 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.h +++ b/Source/Core/DolphinQt2/GameList/GameTracker.h @@ -30,14 +30,14 @@ public: ~GameTracker(); public slots: - void AddDirectory(QString dir); - void RemoveDirectory(QString dir); + void AddDirectory(const QString& dir); + void RemoveDirectory(const QString& dir); signals: void GameLoaded(QSharedPointer game); - void GameRemoved(QString path); + void GameRemoved(const QString& path); - void PathChanged(QString path); + void PathChanged(const QString& path); private: void UpdateDirectory(const QString& dir); @@ -54,7 +54,7 @@ class GameLoader final : public QObject Q_OBJECT public slots: - void LoadGame(QString path) + void LoadGame(const QString& path) { GameFile* game = new GameFile(path); if (game->IsValid()) diff --git a/Source/Core/DolphinQt2/Host.h b/Source/Core/DolphinQt2/Host.h index fb10403535..64630a8874 100644 --- a/Source/Core/DolphinQt2/Host.h +++ b/Source/Core/DolphinQt2/Host.h @@ -30,7 +30,7 @@ public slots: void SetRenderFullscreen(bool fullscreen); signals: - void RequestTitle(QString title); + void RequestTitle(const QString& title); void RequestStop(); void RequestRenderSize(int w, int h); diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index b2d23424b6..c6605d4259 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -6,6 +6,7 @@ #include #include "DolphinQt2/MenuBar.h" +#include "DolphinQt2/Settings.h" MenuBar::MenuBar(QWidget* parent) : QMenuBar(parent) @@ -46,8 +47,9 @@ void MenuBar::AddGameListTypeSection(QMenu* view_menu) list_group->addAction(table_view); list_group->addAction(list_view); - // TODO load this from settings - table_view->setChecked(true); + bool prefer_table = Settings().GetPreferredView(); + table_view->setChecked(prefer_table); + list_view->setChecked(!prefer_table); connect(table_view, &QAction::triggered, this, &MenuBar::ShowTable); connect(list_view, &QAction::triggered, this, &MenuBar::ShowList); diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index a61cdb3dc0..c42b6c4c9e 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -105,6 +105,16 @@ DiscIO::IVolume::ELanguage Settings::GetGCSystemLanguage() const return SConfig::GetInstance().GetCurrentLanguage(false); } +bool Settings::GetPreferredView() const +{ + return value(QStringLiteral("PreferredView"), true).toBool(); +} + +void Settings::SetPreferredView(bool table) +{ + setValue(QStringLiteral("PreferredView"), table); +} + bool Settings::GetConfirmStop() const { return value(QStringLiteral("Emulation/ConfirmStop"), true).toBool(); diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index b1f5a51d30..63a3bd2f3c 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -35,6 +35,8 @@ public: void SetWiiNAND(const QString& path); DiscIO::IVolume::ELanguage GetWiiSystemLanguage() const; DiscIO::IVolume::ELanguage GetGCSystemLanguage() const; + bool GetPreferredView() const; + void SetPreferredView(bool table); // Emulation bool GetConfirmStop() const;