DQt2: Implement Paths config dialog

This commit is contained in:
spxtr 2015-12-30 19:03:13 -08:00
parent 787bf156f0
commit 5b2a76458d
15 changed files with 377 additions and 48 deletions

View File

@ -12,6 +12,7 @@ set(SRCS
Resources.cpp
Settings.cpp
ToolBar.cpp
Config/PathDialog.cpp
GameList/GameFile.cpp
GameList/GameList.cpp
GameList/GameListModel.cpp

View File

@ -0,0 +1,185 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <QAction>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileDialog>
#include <QFont>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QSize>
#include <QVBoxLayout>
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/Config/PathDialog.h"
PathDialog::PathDialog(QWidget* parent)
: QDialog(parent)
{
setWindowTitle(tr("Paths"));
setAttribute(Qt::WA_DeleteOnClose);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(MakeGameFolderBox());
layout->addLayout(MakePathsLayout());
QDialogButtonBox* ok_box = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(ok_box, &QDialogButtonBox::accepted, this, &PathDialog::accept);
layout->addWidget(ok_box);
setLayout(layout);
}
void PathDialog::Browse()
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select a Directory"),
QDir::currentPath());
if (!dir.isEmpty())
{
Settings settings;
QStringList game_folders = settings.GetPaths();
if (!game_folders.contains(dir))
{
game_folders << dir;
settings.SetPaths(game_folders);
m_path_list->addItem(dir);
emit PathAdded(dir);
}
}
}
void PathDialog::BrowseDefaultGame()
{
QString file = QFileDialog::getOpenFileName(this,
tr("Select a Game"),
QDir::currentPath(),
tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.wbfs *.ciso *.gcz *.wad);;"
"All Files (*)"));
if (!file.isEmpty())
{
m_game_edit->setText(file);
Settings().SetDefaultGame(file);
}
}
void PathDialog::BrowseDVDRoot()
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select DVD Root"),
QDir::currentPath());
if (!dir.isEmpty())
{
m_dvd_edit->setText(dir);
Settings().SetDVDRoot(dir);
}
}
void PathDialog::BrowseApploader()
{
QString file = QFileDialog::getOpenFileName(this,
tr("Select an Apploader"),
QDir::currentPath(),
tr("Apploaders (*.img)"));
if (!file.isEmpty())
{
m_app_edit->setText(file);
Settings().SetApploader(file);
}
}
void PathDialog::BrowseWiiNAND()
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select Wii NAND Root"),
QDir::currentPath());
if (!dir.isEmpty())
{
m_nand_edit->setText(dir);
Settings().SetWiiNAND(dir);
}
}
QGroupBox* PathDialog::MakeGameFolderBox()
{
QGroupBox* game_box = new QGroupBox(tr("Game Folders"));
game_box->setMinimumSize(QSize(400, 250));
QVBoxLayout* vlayout = new QVBoxLayout;
m_path_list = new QListWidget;
m_path_list->insertItems(0, Settings().GetPaths());
m_path_list->setSpacing(1);
vlayout->addWidget(m_path_list);
QHBoxLayout* hlayout = new QHBoxLayout;
hlayout->addStretch();
QPushButton* add = new QPushButton(tr("Add"));
QPushButton* remove = new QPushButton(tr("Remove"));
hlayout->addWidget(add);
hlayout->addWidget(remove);
vlayout->addLayout(hlayout);
connect(add, &QPushButton::clicked, this, &PathDialog::Browse);
connect(remove, &QPushButton::clicked, this, &PathDialog::RemovePath);
game_box->setLayout(vlayout);
return game_box;
}
QGridLayout* PathDialog::MakePathsLayout()
{
QGridLayout* layout = new QGridLayout;
layout->setColumnStretch(1, 1);
m_game_edit = new QLineEdit(Settings().GetDefaultGame());
connect(m_game_edit, &QLineEdit::editingFinished,
[=]{ Settings().SetDefaultGame(m_game_edit->text()); });
QPushButton* game_open = new QPushButton;
connect(game_open, &QPushButton::clicked, this, &PathDialog::BrowseDefaultGame);
layout->addWidget(new QLabel(tr("Default Game")), 0, 0);
layout->addWidget(m_game_edit, 0, 1);
layout->addWidget(game_open, 0, 2);
m_dvd_edit = new QLineEdit(Settings().GetDVDRoot());
connect(m_dvd_edit, &QLineEdit::editingFinished,
[=]{ Settings().SetDVDRoot(m_dvd_edit->text()); });
QPushButton* dvd_open = new QPushButton;
connect(dvd_open, &QPushButton::clicked, this, &PathDialog::BrowseDVDRoot);
layout->addWidget(new QLabel(tr("DVD Root")), 1, 0);
layout->addWidget(m_dvd_edit, 1, 1);
layout->addWidget(dvd_open, 1, 2);
m_app_edit = new QLineEdit(Settings().GetApploader());
connect(m_app_edit, &QLineEdit::editingFinished,
[=]{ Settings().SetApploader(m_app_edit->text()); });
QPushButton* app_open = new QPushButton;
connect(app_open, &QPushButton::clicked, this, &PathDialog::BrowseApploader);
layout->addWidget(new QLabel(tr("Apploader")), 2, 0);
layout->addWidget(m_app_edit, 2, 1);
layout->addWidget(app_open, 2, 2);
m_nand_edit = new QLineEdit(Settings().GetWiiNAND());
connect(m_nand_edit, &QLineEdit::editingFinished,
[=]{ Settings().SetWiiNAND(m_nand_edit->text()); });
QPushButton* nand_open = new QPushButton;
connect(nand_open, &QPushButton::clicked, this, &PathDialog::BrowseWiiNAND);
layout->addWidget(new QLabel(tr("Wii NAND Root")), 3, 0);
layout->addWidget(m_nand_edit, 3, 1);
layout->addWidget(nand_open, 3, 2);
return layout;
}
void PathDialog::RemovePath()
{
int row = m_path_list->currentRow();
if (row < 0)
return;
emit PathRemoved(m_path_list->takeItem(row)->text());
Settings().RemovePath(row);
}

View File

@ -0,0 +1,40 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QDialog>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QListWidget>
class PathDialog final : public QDialog
{
Q_OBJECT
public:
explicit PathDialog(QWidget* parent = nullptr);
public slots:
void Browse();
void BrowseDefaultGame();
void BrowseDVDRoot();
void BrowseApploader();
void BrowseWiiNAND();
signals:
void PathAdded(QString path);
void PathRemoved(QString path);
private:
QGroupBox* MakeGameFolderBox();
QGridLayout* MakePathsLayout();
void RemovePath();
QListWidget* m_path_list;
QLineEdit* m_game_edit;
QLineEdit* m_dvd_edit;
QLineEdit* m_app_edit;
QLineEdit* m_nand_edit;
};

View File

@ -22,6 +22,7 @@ GameList::GameList(QWidget* parent): QStackedWidget(parent)
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);
addWidget(m_table);
addWidget(m_list);

View File

@ -29,6 +29,7 @@ public slots:
signals:
void GameSelected();
void DirectoryAdded(QString dir);
void DirectoryRemoved(QString dir);
private:
void MakeTableView();

View File

@ -11,6 +11,7 @@ GameListModel::GameListModel(QObject* parent)
connect(&m_tracker, &GameTracker::GameLoaded, this, &GameListModel::UpdateGame);
connect(&m_tracker, &GameTracker::GameRemoved, this, &GameListModel::RemoveGame);
connect(this, &GameListModel::DirectoryAdded, &m_tracker, &GameTracker::AddDirectory);
connect(this, &GameListModel::DirectoryRemoved, &m_tracker, &GameTracker::RemoveDirectory);
}
QVariant GameListModel::data(const QModelIndex& index, int role) const
@ -67,24 +68,36 @@ int GameListModel::columnCount(const QModelIndex& parent) const
return NUM_COLS;
}
void GameListModel::UpdateGame(QSharedPointer<GameFile> game)
{
QString path = game->GetPath();
if (m_entries.contains(path))
RemoveGame(path);
beginInsertRows(QModelIndex(), m_games.size(), m_games.size());
m_entries[path] = m_games.size();
m_games.append(game);
int entry = FindGame(path);
if (entry < 0)
entry = m_games.size();
beginInsertRows(QModelIndex(), entry, entry);
m_games.insert(entry, game);
endInsertRows();
}
void GameListModel::RemoveGame(QString path)
{
int entry = m_entries[path];
int entry = FindGame(path);
if (entry < 0)
return;
beginRemoveRows(QModelIndex(), entry, entry);
m_entries.remove(path);
m_games.removeAt(entry);
endRemoveRows();
}
int GameListModel::FindGame(const QString& path) const
{
for (int i = 0; i < m_games.size(); i++)
{
if (m_games[i]->GetPath() == path)
return i;
}
return -1;
}

View File

@ -46,10 +46,12 @@ public slots:
signals:
void DirectoryAdded(QString dir);
void DirectoryRemoved(QString dir);
private:
// Index in m_games, or -1 if it isn't found
int FindGame(const QString& path) const;
GameTracker m_tracker;
QList<QSharedPointer<GameFile>> m_games;
// Path -> index in m_games
QMap<QString, int> m_entries;
};

View File

@ -47,20 +47,46 @@ GameTracker::~GameTracker()
void GameTracker::AddDirectory(QString dir)
{
if (!QFileInfo(dir).exists())
return;
addPath(dir);
UpdateDirectory(dir);
}
void GameTracker::UpdateDirectory(const QString& dir)
void GameTracker::RemoveDirectory(QString dir)
{
QDirIterator it(dir, game_filters);
removePath(dir);
QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories);
while (it.hasNext())
{
QString path = QFileInfo(it.next()).canonicalFilePath();
if (!m_tracked_files.contains(path))
if (m_tracked_files.contains(path))
{
m_tracked_files[path]--;
if (m_tracked_files[path] == 0)
{
removePath(path);
m_tracked_files.remove(path);
emit GameRemoved(path);
}
}
}
}
void GameTracker::UpdateDirectory(const QString& dir)
{
QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories);
while (it.hasNext())
{
QString path = QFileInfo(it.next()).canonicalFilePath();
if (m_tracked_files.contains(path))
{
m_tracked_files[path]++;
}
else
{
addPath(path);
m_tracked_files.insert(path);
m_tracked_files[path] = 1;
emit PathChanged(path);
}
}

View File

@ -5,7 +5,7 @@
#pragma once
#include <QFileSystemWatcher>
#include <QSet>
#include <QMap>
#include <QSharedPointer>
#include <QString>
#include <QStringList>
@ -31,6 +31,7 @@ public:
public slots:
void AddDirectory(QString dir);
void RemoveDirectory(QString dir);
signals:
void GameLoaded(QSharedPointer<GameFile> game);
@ -42,7 +43,8 @@ private:
void UpdateDirectory(const QString& dir);
void UpdateFile(const QString& path);
QSet<QString> m_tracked_files;
// game path -> number of directories that track it
QMap<QString, int> m_tracked_files;
QThread m_loader_thread;
GameLoader* m_loader;
};

View File

@ -14,6 +14,7 @@
#include "DolphinQt2/MainWindow.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/Config/PathDialog.h"
#include "DolphinQt2/GameList/GameListModel.h"
MainWindow::MainWindow() : QMainWindow(nullptr)
@ -49,13 +50,12 @@ void MainWindow::MakeToolBar()
addToolBar(m_tool_bar);
connect(m_tool_bar, &ToolBar::OpenPressed, this, &MainWindow::Open);
// TODO make this open the config paths dialog, not the current Browse menu.
connect(m_tool_bar, &ToolBar::PathsPressed, this, &MainWindow::Browse);
connect(m_tool_bar, &ToolBar::PlayPressed, this, &MainWindow::Play);
connect(m_tool_bar, &ToolBar::PausePressed, this, &MainWindow::Pause);
connect(m_tool_bar, &ToolBar::StopPressed, this, &MainWindow::Stop);
connect(m_tool_bar, &ToolBar::FullScreenPressed, this, &MainWindow::FullScreen);
connect(m_tool_bar, &ToolBar::ScreenShotPressed, this, &MainWindow::ScreenShot);
connect(m_tool_bar, &ToolBar::PathsPressed, this, &MainWindow::PathsConfig);
connect(this, &MainWindow::EmulationStarted, m_tool_bar, &ToolBar::EmulationStarted);
connect(this, &MainWindow::EmulationPaused, m_tool_bar, &ToolBar::EmulationPaused);
@ -96,28 +96,11 @@ void MainWindow::Open()
StartGame(file);
}
void MainWindow::Browse()
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select a Directory"),
QDir::currentPath());
if (!dir.isEmpty())
{
Settings settings;
QStringList iso_folders = settings.GetPaths();
if (!iso_folders.contains(dir))
{
iso_folders << dir;
settings.SetPaths(iso_folders);
emit m_game_list->DirectoryAdded(dir);
}
}
}
void MainWindow::Play()
{
// If we're in a paused game, start it up again.
// Otherwise, play the selected game, if there is one.
// Otherwise, play the default game.
// Otherwise, play the last played game, if there is one.
// Otherwise, prompt for a new game.
if (Core::GetState() == Core::CORE_PAUSE)
@ -134,11 +117,19 @@ void MainWindow::Play()
}
else
{
QString path = Settings().GetLastGame();
if (!path.isEmpty() && QFile::exists(path))
StartGame(path);
QString default_path = Settings().GetDefaultGame();
if (!default_path.isEmpty() && QFile::exists(default_path))
{
StartGame(default_path);
}
else
Open();
{
QString last_path = Settings().GetLastGame();
if (!last_path.isEmpty() && QFile::exists(last_path))
StartGame(last_path);
else
Open();
}
}
}
}
@ -191,6 +182,14 @@ void MainWindow::ScreenShot()
Core::SaveScreenShot();
}
void MainWindow::PathsConfig()
{
PathDialog* paths = new PathDialog(this);
connect(paths, &PathDialog::PathAdded, m_game_list, &GameList::DirectoryAdded);
connect(paths, &PathDialog::PathRemoved, m_game_list, &GameList::DirectoryRemoved);
paths->exec();
}
void MainWindow::StartGame(const QString& path)
{
// If we're running, only start a new game once we've stopped the last.

View File

@ -29,7 +29,6 @@ signals:
private slots:
void Open();
void Browse();
void Play();
void Pause();
@ -40,6 +39,8 @@ private slots:
void FullScreen();
void ScreenShot();
void PathsConfig();
private:
void MakeGameList();
void MakeMenuBar();

View File

@ -44,6 +44,57 @@ void Settings::SetPaths(const QStringList& paths)
setValue(QStringLiteral("GameList/Paths"), paths);
}
void Settings::RemovePath(int i)
{
QStringList paths = GetPaths();
paths.removeAt(i);
SetPaths(paths);
}
QString Settings::GetDefaultGame() const
{
return QString::fromStdString(SConfig::GetInstance().m_strDefaultISO);
}
void Settings::SetDefaultGame(const QString& path)
{
SConfig::GetInstance().m_strDefaultISO = path.toStdString();
SConfig::GetInstance().SaveSettings();
}
QString Settings::GetDVDRoot() const
{
return QString::fromStdString(SConfig::GetInstance().m_strDVDRoot);
}
void Settings::SetDVDRoot(const QString& path)
{
SConfig::GetInstance().m_strDVDRoot = path.toStdString();
SConfig::GetInstance().SaveSettings();
}
QString Settings::GetApploader() const
{
return QString::fromStdString(SConfig::GetInstance().m_strApploader);
}
void Settings::SetApploader(const QString& path)
{
SConfig::GetInstance().m_strApploader = path.toStdString();
SConfig::GetInstance().SaveSettings();
}
QString Settings::GetWiiNAND() const
{
return QString::fromStdString(SConfig::GetInstance().m_NANDPath);
}
void Settings::SetWiiNAND(const QString& path)
{
SConfig::GetInstance().m_NANDPath = path.toStdString();
SConfig::GetInstance().SaveSettings();
}
DiscIO::IVolume::ELanguage Settings::GetWiiSystemLanguage() const
{
return SConfig::GetInstance().GetCurrentLanguage(true);

View File

@ -24,6 +24,15 @@ public:
void SetLastGame(const QString& path);
QStringList GetPaths() const;
void SetPaths(const QStringList& paths);
void RemovePath(int i);
QString GetDefaultGame() const;
void SetDefaultGame(const QString& path);
QString GetDVDRoot() const;
void SetDVDRoot(const QString& path);
QString GetApploader() const;
void SetApploader(const QString& path);
QString GetWiiNAND() const;
void SetWiiNAND(const QString& path);
DiscIO::IVolume::ELanguage GetWiiSystemLanguage() const;
DiscIO::IVolume::ELanguage GetGCSystemLanguage() const;

View File

@ -49,10 +49,6 @@ void ToolBar::EmulationStopped()
void ToolBar::MakeActions()
{
m_open_action = addAction(tr("Open"), this, SIGNAL(OpenPressed()));
m_paths_action = addAction(tr("Paths"), this, SIGNAL(PathsPressed()));
addSeparator();
m_play_action = addAction(tr("Play"), this, SIGNAL(PlayPressed()));
m_pause_action = addAction(tr("Pause"), this, SIGNAL(PausePressed()));
@ -69,6 +65,8 @@ void ToolBar::MakeActions()
addSeparator();
m_paths_action = addAction(tr("Paths"), this, SIGNAL(PathsPressed()));
m_config_action = addAction(tr("Settings"));
m_config_action->setEnabled(false);

View File

@ -22,25 +22,25 @@ public slots:
signals:
void OpenPressed();
void PathsPressed();
void PlayPressed();
void PausePressed();
void StopPressed();
void FullScreenPressed();
void ScreenShotPressed();
void PathsPressed();
private:
void MakeActions();
void UpdateIcons();
QAction* m_open_action;
QAction* m_paths_action;
QAction* m_play_action;
QAction* m_pause_action;
QAction* m_stop_action;
QAction* m_fullscreen_action;
QAction* m_screenshot_action;
QAction* m_paths_action;
QAction* m_config_action;
QAction* m_graphics_action;
QAction* m_controllers_action;