PathPane.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // Copyright 2015 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "DolphinQt/Settings/PathPane.h"
  4. #include <QCheckBox>
  5. #include <QDir>
  6. #include <QGroupBox>
  7. #include <QLabel>
  8. #include <QLineEdit>
  9. #include <QListWidget>
  10. #include <QPushButton>
  11. #include <QVBoxLayout>
  12. #include "Common/Config/Config.h"
  13. #include "Common/FileUtil.h"
  14. #include "Core/Config/MainSettings.h"
  15. #include "Core/Config/UISettings.h"
  16. #include "DolphinQt/QtUtils/DolphinFileDialog.h"
  17. #include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
  18. #include "DolphinQt/Settings.h"
  19. PathPane::PathPane(QWidget* parent) : QWidget(parent)
  20. {
  21. setWindowTitle(tr("Paths"));
  22. QVBoxLayout* layout = new QVBoxLayout;
  23. layout->addWidget(MakeGameFolderBox());
  24. layout->addLayout(MakePathsLayout());
  25. setLayout(layout);
  26. }
  27. void PathPane::Browse()
  28. {
  29. QString dir = QDir::toNativeSeparators(
  30. DolphinFileDialog::getExistingDirectory(this, tr("Select a Directory"), QDir::currentPath()));
  31. if (!dir.isEmpty())
  32. Settings::Instance().AddPath(dir);
  33. }
  34. void PathPane::BrowseDefaultGame()
  35. {
  36. QString file = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
  37. this, tr("Select a Game"), Settings::Instance().GetDefaultGame(),
  38. QStringLiteral("%1 (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wia *.rvz "
  39. "hif_000000.nfs *.wad *.m3u *.json);;%2 (*)")
  40. .arg(tr("All GC/Wii files"))
  41. .arg(tr("All Files"))));
  42. if (!file.isEmpty())
  43. Settings::Instance().SetDefaultGame(file);
  44. }
  45. void PathPane::BrowseWiiNAND()
  46. {
  47. QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
  48. this, tr("Select Wii NAND Root"), QString::fromStdString(Config::Get(Config::MAIN_FS_PATH))));
  49. if (!dir.isEmpty())
  50. {
  51. m_nand_edit->setText(dir);
  52. OnNANDPathChanged();
  53. }
  54. }
  55. void PathPane::BrowseDump()
  56. {
  57. QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
  58. this, tr("Select Dump Path"), QString::fromStdString(Config::Get(Config::MAIN_DUMP_PATH))));
  59. if (!dir.isEmpty())
  60. {
  61. m_dump_edit->setText(dir);
  62. Config::SetBase(Config::MAIN_DUMP_PATH, dir.toStdString());
  63. }
  64. }
  65. void PathPane::BrowseLoad()
  66. {
  67. QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
  68. this, tr("Select Load Path"), QString::fromStdString(Config::Get(Config::MAIN_LOAD_PATH))));
  69. if (!dir.isEmpty())
  70. {
  71. m_load_edit->setText(dir);
  72. Config::SetBase(Config::MAIN_LOAD_PATH, dir.toStdString());
  73. }
  74. }
  75. void PathPane::BrowseResourcePack()
  76. {
  77. QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
  78. this, tr("Select Resource Pack Path"),
  79. QString::fromStdString(Config::Get(Config::MAIN_RESOURCEPACK_PATH))));
  80. if (!dir.isEmpty())
  81. {
  82. m_resource_pack_edit->setText(dir);
  83. Config::SetBase(Config::MAIN_RESOURCEPACK_PATH, dir.toStdString());
  84. }
  85. }
  86. void PathPane::BrowseWFS()
  87. {
  88. const QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
  89. this, tr("Select WFS Path"), QString::fromStdString(Config::Get(Config::MAIN_WFS_PATH))));
  90. if (!dir.isEmpty())
  91. {
  92. m_wfs_edit->setText(dir);
  93. Config::SetBase(Config::MAIN_WFS_PATH, dir.toStdString());
  94. }
  95. }
  96. void PathPane::OnNANDPathChanged()
  97. {
  98. Config::SetBase(Config::MAIN_FS_PATH, m_nand_edit->text().toStdString());
  99. }
  100. QGroupBox* PathPane::MakeGameFolderBox()
  101. {
  102. QGroupBox* game_box = new QGroupBox(tr("Game Folders"));
  103. QVBoxLayout* vlayout = new QVBoxLayout;
  104. m_path_list = new QListWidget;
  105. m_path_list->insertItems(0, Settings::Instance().GetPaths());
  106. m_path_list->setSpacing(1);
  107. connect(&Settings::Instance(), &Settings::PathAdded, this,
  108. [this](const QString& dir) { m_path_list->addItem(dir); });
  109. connect(&Settings::Instance(), &Settings::PathRemoved, this, [this](const QString& dir) {
  110. auto items = m_path_list->findItems(dir, Qt::MatchExactly);
  111. for (auto& item : items)
  112. delete item;
  113. });
  114. connect(m_path_list, &QListWidget::itemSelectionChanged, this,
  115. [this] { m_remove_path->setEnabled(m_path_list->selectedItems().count()); });
  116. vlayout->addWidget(m_path_list);
  117. QHBoxLayout* hlayout = new QHBoxLayout;
  118. hlayout->addStretch();
  119. QPushButton* add = new NonDefaultQPushButton(tr("Add..."));
  120. m_remove_path = new NonDefaultQPushButton(tr("Remove"));
  121. m_remove_path->setEnabled(false);
  122. auto* recursive_checkbox = new QCheckBox(tr("Search Subfolders"));
  123. recursive_checkbox->setChecked(Config::Get(Config::MAIN_RECURSIVE_ISO_PATHS));
  124. auto* auto_checkbox = new QCheckBox(tr("Check for Game List Changes in the Background"));
  125. auto_checkbox->setChecked(Settings::Instance().IsAutoRefreshEnabled());
  126. hlayout->addWidget(add);
  127. hlayout->addWidget(m_remove_path);
  128. vlayout->addLayout(hlayout);
  129. vlayout->addWidget(recursive_checkbox);
  130. vlayout->addWidget(auto_checkbox);
  131. connect(recursive_checkbox, &QCheckBox::toggled, [](bool checked) {
  132. Config::SetBase(Config::MAIN_RECURSIVE_ISO_PATHS, checked);
  133. Settings::Instance().RefreshGameList();
  134. });
  135. connect(auto_checkbox, &QCheckBox::toggled, &Settings::Instance(),
  136. &Settings::SetAutoRefreshEnabled);
  137. connect(add, &QPushButton::clicked, this, &PathPane::Browse);
  138. connect(m_remove_path, &QPushButton::clicked, this, &PathPane::RemovePath);
  139. game_box->setLayout(vlayout);
  140. return game_box;
  141. }
  142. QGridLayout* PathPane::MakePathsLayout()
  143. {
  144. QGridLayout* layout = new QGridLayout;
  145. layout->setColumnStretch(1, 1);
  146. m_game_edit = new QLineEdit(Settings::Instance().GetDefaultGame());
  147. connect(m_game_edit, &QLineEdit::editingFinished,
  148. [this] { Settings::Instance().SetDefaultGame(m_game_edit->text()); });
  149. connect(&Settings::Instance(), &Settings::DefaultGameChanged, this,
  150. [this](const QString& path) { m_game_edit->setText(path); });
  151. QPushButton* game_open = new NonDefaultQPushButton(QStringLiteral("..."));
  152. connect(game_open, &QPushButton::clicked, this, &PathPane::BrowseDefaultGame);
  153. layout->addWidget(new QLabel(tr("Default ISO:")), 0, 0);
  154. layout->addWidget(m_game_edit, 0, 1);
  155. layout->addWidget(game_open, 0, 2);
  156. m_nand_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(D_WIIROOT_IDX)));
  157. connect(m_nand_edit, &QLineEdit::editingFinished, this, &PathPane::OnNANDPathChanged);
  158. QPushButton* nand_open = new NonDefaultQPushButton(QStringLiteral("..."));
  159. connect(nand_open, &QPushButton::clicked, this, &PathPane::BrowseWiiNAND);
  160. layout->addWidget(new QLabel(tr("Wii NAND Root:")), 1, 0);
  161. layout->addWidget(m_nand_edit, 1, 1);
  162. layout->addWidget(nand_open, 1, 2);
  163. m_dump_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(D_DUMP_IDX)));
  164. connect(m_dump_edit, &QLineEdit::editingFinished,
  165. [this] { Config::SetBase(Config::MAIN_DUMP_PATH, m_dump_edit->text().toStdString()); });
  166. QPushButton* dump_open = new NonDefaultQPushButton(QStringLiteral("..."));
  167. connect(dump_open, &QPushButton::clicked, this, &PathPane::BrowseDump);
  168. layout->addWidget(new QLabel(tr("Dump Path:")), 2, 0);
  169. layout->addWidget(m_dump_edit, 2, 1);
  170. layout->addWidget(dump_open, 2, 2);
  171. m_load_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(D_LOAD_IDX)));
  172. connect(m_load_edit, &QLineEdit::editingFinished,
  173. [this] { Config::SetBase(Config::MAIN_LOAD_PATH, m_load_edit->text().toStdString()); });
  174. QPushButton* load_open = new NonDefaultQPushButton(QStringLiteral("..."));
  175. connect(load_open, &QPushButton::clicked, this, &PathPane::BrowseLoad);
  176. layout->addWidget(new QLabel(tr("Load Path:")), 3, 0);
  177. layout->addWidget(m_load_edit, 3, 1);
  178. layout->addWidget(load_open, 3, 2);
  179. m_resource_pack_edit =
  180. new QLineEdit(QString::fromStdString(File::GetUserPath(D_RESOURCEPACK_IDX)));
  181. connect(m_resource_pack_edit, &QLineEdit::editingFinished, [this] {
  182. Config::SetBase(Config::MAIN_RESOURCEPACK_PATH, m_resource_pack_edit->text().toStdString());
  183. });
  184. QPushButton* resource_pack_open = new NonDefaultQPushButton(QStringLiteral("..."));
  185. connect(resource_pack_open, &QPushButton::clicked, this, &PathPane::BrowseResourcePack);
  186. layout->addWidget(new QLabel(tr("Resource Pack Path:")), 4, 0);
  187. layout->addWidget(m_resource_pack_edit, 4, 1);
  188. layout->addWidget(resource_pack_open, 4, 2);
  189. m_wfs_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(D_WFSROOT_IDX)));
  190. connect(m_load_edit, &QLineEdit::editingFinished,
  191. [this] { Config::SetBase(Config::MAIN_WFS_PATH, m_wfs_edit->text().toStdString()); });
  192. QPushButton* wfs_open = new NonDefaultQPushButton(QStringLiteral("..."));
  193. connect(wfs_open, &QPushButton::clicked, this, &PathPane::BrowseWFS);
  194. layout->addWidget(new QLabel(tr("WFS Path:")), 5, 0);
  195. layout->addWidget(m_wfs_edit, 5, 1);
  196. layout->addWidget(wfs_open, 5, 2);
  197. return layout;
  198. }
  199. void PathPane::RemovePath()
  200. {
  201. auto item = m_path_list->currentItem();
  202. if (!item)
  203. return;
  204. Settings::Instance().RemovePath(item->text());
  205. }