DQt2: Add a message if the game list is empty.

This commit is contained in:
spxtr 2016-01-01 02:29:39 -08:00
parent 552ea58bf5
commit 48d1adb96f
10 changed files with 76 additions and 19 deletions

View file

@ -4,6 +4,7 @@
#include <QHeaderView> #include <QHeaderView>
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/GameList/GameList.h" #include "DolphinQt2/GameList/GameList.h"
#include "DolphinQt2/GameList/ListProxyModel.h" #include "DolphinQt2/GameList/ListProxyModel.h"
#include "DolphinQt2/GameList/TableProxyModel.h" #include "DolphinQt2/GameList/TableProxyModel.h"
@ -18,15 +19,20 @@ GameList::GameList(QWidget* parent): QStackedWidget(parent)
MakeTableView(); MakeTableView();
MakeListView(); MakeListView();
MakeEmptyView();
connect(m_table, &QTableView::doubleClicked, this, &GameList::GameSelected); connect(m_table, &QTableView::doubleClicked, this, &GameList::GameSelected);
connect(m_list, &QListView::doubleClicked, this, &GameList::GameSelected); connect(m_list, &QListView::doubleClicked, this, &GameList::GameSelected);
connect(this, &GameList::DirectoryAdded, m_model, &GameListModel::DirectoryAdded); connect(this, &GameList::DirectoryAdded, m_model, &GameListModel::DirectoryAdded);
connect(this, &GameList::DirectoryRemoved, m_model, &GameListModel::DirectoryRemoved); 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_table);
addWidget(m_list); addWidget(m_list);
setCurrentWidget(m_table); addWidget(m_empty);
m_prefer_table = Settings().GetPreferredView();
ConsiderViewChange();
} }
void GameList::MakeTableView() void GameList::MakeTableView()
@ -69,6 +75,14 @@ void GameList::MakeTableView()
header->setSectionResizeMode(GameListModel::COL_RATING, QHeaderView::Fixed); 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() void GameList::MakeListView()
{ {
m_list = new QListView(this); m_list = new QListView(this);
@ -100,3 +114,25 @@ QString GameList::GetSelectedGame() const
} }
return QStringLiteral(); 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);
}
}

View file

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <QLabel>
#include <QListView> #include <QListView>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStackedWidget> #include <QStackedWidget>
@ -22,18 +23,22 @@ public:
QString GetSelectedGame() const; QString GetSelectedGame() const;
public slots: public slots:
void SetTableView() { setCurrentWidget(m_table); } void SetTableView() { SetPreferredView(true); }
void SetListView() { setCurrentWidget(m_list); } void SetListView() { SetPreferredView(false); }
void SetViewColumn(int col, bool view) { m_table->setColumnHidden(col, !view); } void SetViewColumn(int col, bool view) { m_table->setColumnHidden(col, !view); }
signals: signals:
void GameSelected(); void GameSelected();
void DirectoryAdded(QString dir); void DirectoryAdded(const QString& dir);
void DirectoryRemoved(QString dir); void DirectoryRemoved(const QString& dir);
private: private:
void MakeTableView(); void MakeTableView();
void MakeListView(); void MakeListView();
void MakeEmptyView();
// We only have two views, just use a bool to distinguish.
void SetPreferredView(bool table);
void ConsiderViewChange();
GameListModel* m_model; GameListModel* m_model;
QSortFilterProxyModel* m_table_proxy; QSortFilterProxyModel* m_table_proxy;
@ -41,4 +46,6 @@ private:
QListView* m_list; QListView* m_list;
QTableView* m_table; QTableView* m_table;
QLabel* m_empty;
bool m_prefer_table;
}; };

View file

@ -81,7 +81,7 @@ void GameListModel::UpdateGame(QSharedPointer<GameFile> game)
endInsertRows(); endInsertRows();
} }
void GameListModel::RemoveGame(QString path) void GameListModel::RemoveGame(const QString& path)
{ {
int entry = FindGame(path); int entry = FindGame(path);
if (entry < 0) if (entry < 0)

View file

@ -42,11 +42,11 @@ public:
public slots: public slots:
void UpdateGame(QSharedPointer<GameFile> game); void UpdateGame(QSharedPointer<GameFile> game);
void RemoveGame(QString path); void RemoveGame(const QString& path);
signals: signals:
void DirectoryAdded(QString dir); void DirectoryAdded(const QString& dir);
void DirectoryRemoved(QString dir); void DirectoryRemoved(const QString& dir);
private: private:
// Index in m_games, or -1 if it isn't found // Index in m_games, or -1 if it isn't found

View file

@ -45,7 +45,7 @@ GameTracker::~GameTracker()
m_loader_thread.wait(); m_loader_thread.wait();
} }
void GameTracker::AddDirectory(QString dir) void GameTracker::AddDirectory(const QString& dir)
{ {
if (!QFileInfo(dir).exists()) if (!QFileInfo(dir).exists())
return; return;
@ -53,7 +53,7 @@ void GameTracker::AddDirectory(QString dir)
UpdateDirectory(dir); UpdateDirectory(dir);
} }
void GameTracker::RemoveDirectory(QString dir) void GameTracker::RemoveDirectory(const QString& dir)
{ {
removePath(dir); removePath(dir);
QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories);

View file

@ -30,14 +30,14 @@ public:
~GameTracker(); ~GameTracker();
public slots: public slots:
void AddDirectory(QString dir); void AddDirectory(const QString& dir);
void RemoveDirectory(QString dir); void RemoveDirectory(const QString& dir);
signals: signals:
void GameLoaded(QSharedPointer<GameFile> game); void GameLoaded(QSharedPointer<GameFile> game);
void GameRemoved(QString path); void GameRemoved(const QString& path);
void PathChanged(QString path); void PathChanged(const QString& path);
private: private:
void UpdateDirectory(const QString& dir); void UpdateDirectory(const QString& dir);
@ -54,7 +54,7 @@ class GameLoader final : public QObject
Q_OBJECT Q_OBJECT
public slots: public slots:
void LoadGame(QString path) void LoadGame(const QString& path)
{ {
GameFile* game = new GameFile(path); GameFile* game = new GameFile(path);
if (game->IsValid()) if (game->IsValid())

View file

@ -30,7 +30,7 @@ public slots:
void SetRenderFullscreen(bool fullscreen); void SetRenderFullscreen(bool fullscreen);
signals: signals:
void RequestTitle(QString title); void RequestTitle(const QString& title);
void RequestStop(); void RequestStop();
void RequestRenderSize(int w, int h); void RequestRenderSize(int w, int h);

View file

@ -6,6 +6,7 @@
#include <QActionGroup> #include <QActionGroup>
#include "DolphinQt2/MenuBar.h" #include "DolphinQt2/MenuBar.h"
#include "DolphinQt2/Settings.h"
MenuBar::MenuBar(QWidget* parent) MenuBar::MenuBar(QWidget* parent)
: QMenuBar(parent) : QMenuBar(parent)
@ -46,8 +47,9 @@ void MenuBar::AddGameListTypeSection(QMenu* view_menu)
list_group->addAction(table_view); list_group->addAction(table_view);
list_group->addAction(list_view); list_group->addAction(list_view);
// TODO load this from settings bool prefer_table = Settings().GetPreferredView();
table_view->setChecked(true); table_view->setChecked(prefer_table);
list_view->setChecked(!prefer_table);
connect(table_view, &QAction::triggered, this, &MenuBar::ShowTable); connect(table_view, &QAction::triggered, this, &MenuBar::ShowTable);
connect(list_view, &QAction::triggered, this, &MenuBar::ShowList); connect(list_view, &QAction::triggered, this, &MenuBar::ShowList);

View file

@ -105,6 +105,16 @@ DiscIO::IVolume::ELanguage Settings::GetGCSystemLanguage() const
return SConfig::GetInstance().GetCurrentLanguage(false); 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 bool Settings::GetConfirmStop() const
{ {
return value(QStringLiteral("Emulation/ConfirmStop"), true).toBool(); return value(QStringLiteral("Emulation/ConfirmStop"), true).toBool();

View file

@ -35,6 +35,8 @@ public:
void SetWiiNAND(const QString& path); void SetWiiNAND(const QString& path);
DiscIO::IVolume::ELanguage GetWiiSystemLanguage() const; DiscIO::IVolume::ELanguage GetWiiSystemLanguage() const;
DiscIO::IVolume::ELanguage GetGCSystemLanguage() const; DiscIO::IVolume::ELanguage GetGCSystemLanguage() const;
bool GetPreferredView() const;
void SetPreferredView(bool table);
// Emulation // Emulation
bool GetConfirmStop() const; bool GetConfirmStop() const;