From 47e8cb97b46b0dd24fc691a16e2894c38158d1b9 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 31 May 2017 00:42:15 -0700 Subject: [PATCH] DolphinQt2: move path signals from PathDialog to Settings --- Source/Core/DolphinQt2/Config/PathDialog.cpp | 25 +++++++++----------- Source/Core/DolphinQt2/Config/PathDialog.h | 4 ---- Source/Core/DolphinQt2/GameList/GameList.cpp | 4 ++-- Source/Core/DolphinQt2/GameList/GameList.h | 2 -- Source/Core/DolphinQt2/MainWindow.cpp | 7 ------ Source/Core/DolphinQt2/MainWindow.h | 1 - Source/Core/DolphinQt2/Settings.cpp | 18 +++++++++++++- Source/Core/DolphinQt2/Settings.h | 7 +++++- 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/PathDialog.cpp b/Source/Core/DolphinQt2/Config/PathDialog.cpp index 62f1b25a2d..0ca2e05004 100644 --- a/Source/Core/DolphinQt2/Config/PathDialog.cpp +++ b/Source/Core/DolphinQt2/Config/PathDialog.cpp @@ -37,16 +37,7 @@ void PathDialog::Browse() QString dir = QFileDialog::getExistingDirectory(this, tr("Select a Directory"), QDir::currentPath()); if (!dir.isEmpty()) - { - QStringList game_folders = Settings::Instance().GetPaths(); - if (!game_folders.contains(dir)) - { - game_folders << dir; - Settings::Instance().SetPaths(game_folders); - m_path_list->addItem(dir); - emit PathAdded(dir); - } - } + Settings::Instance().AddPath(dir); } void PathDialog::BrowseDefaultGame() @@ -103,6 +94,13 @@ QGroupBox* PathDialog::MakeGameFolderBox() m_path_list = new QListWidget; m_path_list->insertItems(0, Settings::Instance().GetPaths()); m_path_list->setSpacing(1); + connect(&Settings::Instance(), &Settings::PathAdded, + [this](const QString& dir) { m_path_list->addItem(dir); }); + connect(&Settings::Instance(), &Settings::PathRemoved, [this](const QString& dir) { + auto items = m_path_list->findItems(dir, Qt::MatchExactly); + for (auto& item : items) + delete item; + }); vlayout->addWidget(m_path_list); QHBoxLayout* hlayout = new QHBoxLayout; @@ -168,9 +166,8 @@ QGridLayout* PathDialog::MakePathsLayout() void PathDialog::RemovePath() { - int row = m_path_list->currentRow(); - if (row < 0) + auto item = m_path_list->currentItem(); + if (!item) return; - emit PathRemoved(m_path_list->takeItem(row)->text()); - Settings::Instance().RemovePath(row); + Settings::Instance().RemovePath(item->text()); } diff --git a/Source/Core/DolphinQt2/Config/PathDialog.h b/Source/Core/DolphinQt2/Config/PathDialog.h index a486889680..9c8f7fbc5f 100644 --- a/Source/Core/DolphinQt2/Config/PathDialog.h +++ b/Source/Core/DolphinQt2/Config/PathDialog.h @@ -23,10 +23,6 @@ public slots: void BrowseApploader(); void BrowseWiiNAND(); -signals: - void PathAdded(QString path); - void PathRemoved(QString path); - private: QGroupBox* MakeGameFolderBox(); QGridLayout* MakePathsLayout(); diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index 54ab89cb95..d4112ba962 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -42,8 +42,8 @@ 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); + connect(&Settings::Instance(), &Settings::PathAdded, m_model, &GameListModel::DirectoryAdded); + connect(&Settings::Instance(), &Settings::PathRemoved, m_model, &GameListModel::DirectoryRemoved); connect(m_model, &QAbstractItemModel::rowsInserted, this, &GameList::ConsiderViewChange); connect(m_model, &QAbstractItemModel::rowsRemoved, this, &GameList::ConsiderViewChange); diff --git a/Source/Core/DolphinQt2/GameList/GameList.h b/Source/Core/DolphinQt2/GameList/GameList.h index 750ed92c7a..ae4e6edf74 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.h +++ b/Source/Core/DolphinQt2/GameList/GameList.h @@ -42,8 +42,6 @@ private slots: signals: void GameSelected(); - void DirectoryAdded(const QString& dir); - void DirectoryRemoved(const QString& dir); private: void MakeTableView(); diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index e6677712ec..92fb9b826d 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -40,7 +40,6 @@ MainWindow::MainWindow() : QMainWindow(nullptr) CreateComponents(); ConnectGameList(); - ConnectPathsDialog(); ConnectToolBar(); ConnectRenderWidget(); ConnectStack(); @@ -169,12 +168,6 @@ void MainWindow::ConnectStack() setCentralWidget(m_stack); } -void MainWindow::ConnectPathsDialog() -{ - connect(m_paths_dialog, &PathDialog::PathAdded, m_game_list, &GameList::DirectoryAdded); - connect(m_paths_dialog, &PathDialog::PathRemoved, m_game_list, &GameList::DirectoryRemoved); -} - void MainWindow::Open() { QString file = QFileDialog::getOpenFileName( diff --git a/Source/Core/DolphinQt2/MainWindow.h b/Source/Core/DolphinQt2/MainWindow.h index cc617c3ac0..0d7964cccb 100644 --- a/Source/Core/DolphinQt2/MainWindow.h +++ b/Source/Core/DolphinQt2/MainWindow.h @@ -63,7 +63,6 @@ private: void ConnectRenderWidget(); void ConnectStack(); void ConnectToolBar(); - void ConnectPathsDialog(); void InitControllers(); void ShutdownControllers(); diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index 88bb0e1c28..a1ec7d7b94 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -61,16 +61,32 @@ QStringList Settings::GetPaths() const return value(QStringLiteral("GameList/Paths")).toStringList(); } +void Settings::AddPath(const QString& path) +{ + QStringList game_folders = Settings::Instance().GetPaths(); + if (!game_folders.contains(path)) + { + game_folders << path; + Settings::Instance().SetPaths(game_folders); + emit PathAdded(path); + } +} + void Settings::SetPaths(const QStringList& paths) { setValue(QStringLiteral("GameList/Paths"), paths); } -void Settings::RemovePath(int i) +void Settings::RemovePath(const QString& path) { QStringList paths = GetPaths(); + int i = paths.indexOf(path); + if (i < 0) + return; + paths.removeAt(i); SetPaths(paths); + emit PathRemoved(path); } QString Settings::GetDefaultGame() const diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index 817139056c..d7f3dae319 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -35,8 +35,9 @@ public: // GameList QStringList GetPaths() const; + void AddPath(const QString& path); void SetPaths(const QStringList& paths); - void RemovePath(int i); + void RemovePath(const QString& path); QString GetDefaultGame() const; void SetDefaultGame(const QString& path); QString GetDVDRoot() const; @@ -107,6 +108,10 @@ public: void Save(); +signals: + void PathAdded(const QString&); + void PathRemoved(const QString&); + private: Settings(); };