1
0
Fork 0
forked from suyu/suyu

Address trivial review comments

This commit is contained in:
fearlessTobi 2019-05-03 19:21:57 +02:00 committed by FearlessTobi
parent 2d8eba5baf
commit 7a8f484020
7 changed files with 59 additions and 53 deletions

View file

@ -521,7 +521,7 @@ void Config::ReadPathValues() {
ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString(); ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString();
UISettings::values.game_dir_deprecated_deepscan = UISettings::values.game_dir_deprecated_deepscan =
ReadSetting(QStringLiteral("gameListDeepScan"), false).toBool(); ReadSetting(QStringLiteral("gameListDeepScan"), false).toBool();
int gamedirs_size = qt_config->beginReadArray(QStringLiteral("gamedirs")); const int gamedirs_size = qt_config->beginReadArray(QStringLiteral("gamedirs"));
for (int i = 0; i < gamedirs_size; ++i) { for (int i = 0; i < gamedirs_size; ++i) {
qt_config->setArrayIndex(i); qt_config->setArrayIndex(i);
UISettings::GameDir game_dir; UISettings::GameDir game_dir;
@ -927,7 +927,7 @@ void Config::SavePathValues() {
qt_config->beginWriteArray(QStringLiteral("gamedirs")); qt_config->beginWriteArray(QStringLiteral("gamedirs"));
for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) { for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) {
qt_config->setArrayIndex(i); qt_config->setArrayIndex(i);
const auto& game_dir = UISettings::values.game_dirs.at(i); const auto& game_dir = UISettings::values.game_dirs[i];
WriteSetting(QStringLiteral("path"), game_dir.path); WriteSetting(QStringLiteral("path"), game_dir.path);
WriteSetting(QStringLiteral("deep_scan"), game_dir.deep_scan, false); WriteSetting(QStringLiteral("deep_scan"), game_dir.deep_scan, false);
WriteSetting(QStringLiteral("expanded"), game_dir.expanded, true); WriteSetting(QStringLiteral("expanded"), game_dir.expanded, true);

View file

@ -87,12 +87,12 @@ QString GameList::getLastFilterResultItem() {
QStandardItem* folder; QStandardItem* folder;
QStandardItem* child; QStandardItem* child;
QString file_path; QString file_path;
int folder_count = item_model->rowCount(); const int folder_count = item_model->rowCount();
for (int i = 0; i < folder_count; ++i) { for (int i = 0; i < folder_count; ++i) {
folder = item_model->item(i, 0); folder = item_model->item(i, 0);
QModelIndex folder_index = folder->index(); const QModelIndex folder_index = folder->index();
int childrenCount = folder->rowCount(); const int children_count = folder->rowCount();
for (int j = 0; j < childrenCount; ++j) { for (int j = 0; j < children_count; ++j) {
if (!tree_view->isRowHidden(j, folder_index)) { if (!tree_view->isRowHidden(j, folder_index)) {
child = folder->child(j, 0); child = folder->child(j, 0);
file_path = child->data(GameListItemPath::FullPathRole).toString(); file_path = child->data(GameListItemPath::FullPathRole).toString();
@ -160,7 +160,7 @@ static bool ContainsAllWords(const QString& haystack, const QString& userinput)
// Syncs the expanded state of Game Directories with settings to persist across sessions // Syncs the expanded state of Game Directories with settings to persist across sessions
void GameList::onItemExpanded(const QModelIndex& item) { void GameList::onItemExpanded(const QModelIndex& item) {
GameListItemType type = item.data(GameListItem::TypeRole).value<GameListItemType>(); const auto type = item.data(GameListItem::TypeRole).value<GameListItemType>();
if (type == GameListItemType::CustomDir || type == GameListItemType::InstalledDir || if (type == GameListItemType::CustomDir || type == GameListItemType::InstalledDir ||
type == GameListItemType::SystemDir) type == GameListItemType::SystemDir)
item.data(GameListDir::GameDirRole).value<UISettings::GameDir*>()->expanded = item.data(GameListDir::GameDirRole).value<UISettings::GameDir*>()->expanded =
@ -169,11 +169,11 @@ void GameList::onItemExpanded(const QModelIndex& item) {
// Event in order to filter the gamelist after editing the searchfield // Event in order to filter the gamelist after editing the searchfield
void GameList::onTextChanged(const QString& new_text) { void GameList::onTextChanged(const QString& new_text) {
int folder_count = tree_view->model()->rowCount(); const int folder_count = tree_view->model()->rowCount();
QString edit_filter_text = new_text.toLower(); QString edit_filter_text = new_text.toLower();
QStandardItem* folder; QStandardItem* folder;
QStandardItem* child; QStandardItem* child;
int childrenTotal = 0; int children_total = 0;
QModelIndex root_index = item_model->invisibleRootItem()->index(); QModelIndex root_index = item_model->invisibleRootItem()->index();
// If the searchfield is empty every item is visible // If the searchfield is empty every item is visible
@ -181,22 +181,22 @@ void GameList::onTextChanged(const QString& new_text) {
if (edit_filter_text.isEmpty()) { if (edit_filter_text.isEmpty()) {
for (int i = 0; i < folder_count; ++i) { for (int i = 0; i < folder_count; ++i) {
folder = item_model->item(i, 0); folder = item_model->item(i, 0);
QModelIndex folder_index = folder->index(); const QModelIndex folder_index = folder->index();
int childrenCount = folder->rowCount(); const int children_count = folder->rowCount();
for (int j = 0; j < childrenCount; ++j) { for (int j = 0; j < children_count; ++j) {
++childrenTotal; ++children_total;
tree_view->setRowHidden(j, folder_index, false); tree_view->setRowHidden(j, folder_index, false);
} }
} }
search_field->setFilterResult(childrenTotal, childrenTotal); search_field->setFilterResult(children_total, children_total);
} else { } else {
int result_count = 0; int result_count = 0;
for (int i = 0; i < folder_count; ++i) { for (int i = 0; i < folder_count; ++i) {
folder = item_model->item(i, 0); folder = item_model->item(i, 0);
QModelIndex folder_index = folder->index(); const QModelIndex folder_index = folder->index();
int childrenCount = folder->rowCount(); const int children_count = folder->rowCount();
for (int j = 0; j < childrenCount; ++j) { for (int j = 0; j < children_count; ++j) {
++childrenTotal; ++children_total;
const QStandardItem* child = folder->child(j, 0); const QStandardItem* child = folder->child(j, 0);
const QString file_path = const QString file_path =
child->data(GameListItemPath::FullPathRole).toString().toLower(); child->data(GameListItemPath::FullPathRole).toString().toLower();
@ -220,7 +220,7 @@ void GameList::onTextChanged(const QString& new_text) {
} else { } else {
tree_view->setRowHidden(j, folder_index, true); tree_view->setRowHidden(j, folder_index, true);
} }
search_field->setFilterResult(result_count, childrenTotal); search_field->setFilterResult(result_count, children_total);
} }
} }
} }
@ -230,7 +230,7 @@ void GameList::onUpdateThemedIcons() {
for (int i = 0; i < item_model->invisibleRootItem()->rowCount(); i++) { for (int i = 0; i < item_model->invisibleRootItem()->rowCount(); i++) {
QStandardItem* child = item_model->invisibleRootItem()->child(i); QStandardItem* child = item_model->invisibleRootItem()->child(i);
int icon_size = UISettings::values.icon_size; const int icon_size = UISettings::values.icon_size;
switch (child->data(GameListItem::TypeRole).value<GameListItemType>()) { switch (child->data(GameListItem::TypeRole).value<GameListItemType>()) {
case GameListItemType::InstalledDir: case GameListItemType::InstalledDir:
child->setData( child->setData(
@ -249,7 +249,8 @@ void GameList::onUpdateThemedIcons() {
case GameListItemType::CustomDir: { case GameListItemType::CustomDir: {
const UISettings::GameDir* game_dir = const UISettings::GameDir* game_dir =
child->data(GameListDir::GameDirRole).value<UISettings::GameDir*>(); child->data(GameListDir::GameDirRole).value<UISettings::GameDir*>();
QString icon_name = QFileInfo::exists(game_dir->path) ? QStringLiteral("folder") const QString icon_name = QFileInfo::exists(game_dir->path)
? QStringLiteral("folder")
: QStringLiteral("bad_folder"); : QStringLiteral("bad_folder");
child->setData( child->setData(
QIcon::fromTheme(icon_name).pixmap(icon_size).scaled( QIcon::fromTheme(icon_name).pixmap(icon_size).scaled(
@ -357,14 +358,14 @@ void GameList::AddEntry(const QList<QStandardItem*>& entry_items, GameListDir* p
} }
void GameList::ValidateEntry(const QModelIndex& item) { void GameList::ValidateEntry(const QModelIndex& item) {
auto selected = item.sibling(item.row(), 0); const auto selected = item.sibling(item.row(), 0);
switch (selected.data(GameListItem::TypeRole).value<GameListItemType>()) { switch (selected.data(GameListItem::TypeRole).value<GameListItemType>()) {
case GameListItemType::Game: { case GameListItemType::Game: {
QString file_path = selected.data(GameListItemPath::FullPathRole).toString(); const QString file_path = selected.data(GameListItemPath::FullPathRole).toString();
if (file_path.isEmpty()) if (file_path.isEmpty())
return; return;
QFileInfo file_info(file_path); const QFileInfo file_info(file_path);
if (!file_info.exists()) if (!file_info.exists())
return; return;
@ -391,7 +392,7 @@ void GameList::ValidateEntry(const QModelIndex& item) {
bool GameList::isEmpty() { bool GameList::isEmpty() {
for (int i = 0; i < item_model->rowCount(); i++) { for (int i = 0; i < item_model->rowCount(); i++) {
const QStandardItem* child = item_model->invisibleRootItem()->child(i); const QStandardItem* child = item_model->invisibleRootItem()->child(i);
GameListItemType type = static_cast<GameListItemType>(child->type()); const auto type = static_cast<GameListItemType>(child->type());
if (!child->hasChildren() && if (!child->hasChildren() &&
(type == GameListItemType::InstalledDir || type == GameListItemType::SystemDir)) { (type == GameListItemType::InstalledDir || type == GameListItemType::SystemDir)) {
item_model->invisibleRootItem()->removeRow(child->row()); item_model->invisibleRootItem()->removeRow(child->row());
@ -422,16 +423,16 @@ void GameList::DonePopulating(QStringList watch_list) {
QCoreApplication::processEvents(); QCoreApplication::processEvents();
} }
tree_view->setEnabled(true); tree_view->setEnabled(true);
int folder_count = tree_view->model()->rowCount(); const int folder_count = tree_view->model()->rowCount();
int childrenTotal = 0; int children_total = 0;
for (int i = 0; i < folder_count; ++i) { for (int i = 0; i < folder_count; ++i) {
int childrenCount = item_model->item(i, 0)->rowCount(); int children_count = item_model->item(i, 0)->rowCount();
for (int j = 0; j < childrenCount; ++j) { for (int j = 0; j < children_count; ++j) {
++childrenTotal; ++children_total;
} }
} }
search_field->setFilterResult(childrenTotal, childrenTotal); search_field->setFilterResult(children_total, children_total);
if (childrenTotal > 0) { if (children_total > 0) {
search_field->setFocus(); search_field->setFocus();
} }
} }
@ -441,7 +442,7 @@ void GameList::PopupContextMenu(const QPoint& menu_location) {
if (!item.isValid()) if (!item.isValid())
return; return;
auto selected = item.sibling(item.row(), 0); const auto selected = item.sibling(item.row(), 0);
QMenu context_menu; QMenu context_menu;
switch (selected.data(GameListItem::TypeRole).value<GameListItemType>()) { switch (selected.data(GameListItem::TypeRole).value<GameListItemType>()) {
case GameListItemType::Game: case GameListItemType::Game:
@ -523,7 +524,7 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) {
QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down ")); QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down "));
QAction* open_directory_location = context_menu.addAction(tr("Open Directory Location")); QAction* open_directory_location = context_menu.addAction(tr("Open Directory Location"));
int row = selected.row(); const int row = selected.row();
move_up->setEnabled(row > 0); move_up->setEnabled(row > 0);
move_down->setEnabled(row < item_model->rowCount() - 2); move_down->setEnabled(row < item_model->rowCount() - 2);
@ -532,7 +533,7 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) {
// find the indices of the items in settings and swap them // find the indices of the items in settings and swap them
UISettings::values.game_dirs.swap( UISettings::values.game_dirs.swap(
UISettings::values.game_dirs.indexOf(game_dir), UISettings::values.game_dirs.indexOf(game_dir),
UISettings::values.game_dirs.indexOf(*selected.sibling(selected.row() - 1, 0) UISettings::values.game_dirs.indexOf(*selected.sibling(row - 1, 0)
.data(GameListDir::GameDirRole) .data(GameListDir::GameDirRole)
.value<UISettings::GameDir*>())); .value<UISettings::GameDir*>()));
// move the treeview items // move the treeview items
@ -549,7 +550,7 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) {
.data(GameListDir::GameDirRole) .data(GameListDir::GameDirRole)
.value<UISettings::GameDir*>())); .value<UISettings::GameDir*>()));
// move the treeview items // move the treeview items
QList<QStandardItem*> item = item_model->takeRow(row); const QList<QStandardItem*> item = item_model->takeRow(row);
item_model->invisibleRootItem()->insertRow(row + 1, item); item_model->invisibleRootItem()->insertRow(row + 1, item);
tree_view->setExpanded(selected, game_dir.expanded); tree_view->setExpanded(selected, game_dir.expanded);
}); });

View file

@ -80,7 +80,7 @@ signals:
void NavigateToGamedbEntryRequested(u64 program_id, void NavigateToGamedbEntryRequested(u64 program_id,
const CompatibilityList& compatibility_list); const CompatibilityList& compatibility_list);
void OpenPerGameGeneralRequested(const std::string& file); void OpenPerGameGeneralRequested(const std::string& file);
void OpenDirectory(QString directory); void OpenDirectory(const QString& directory);
void AddDirectory(); void AddDirectory();
void ShowList(bool show); void ShowList(bool show);

View file

@ -220,11 +220,13 @@ public:
UISettings::GameDir* game_dir = &directory; UISettings::GameDir* game_dir = &directory;
setData(QVariant::fromValue(game_dir), GameDirRole); setData(QVariant::fromValue(game_dir), GameDirRole);
int icon_size = UISettings::values.icon_size; const int icon_size = UISettings::values.icon_size;
switch (dir_type) { switch (dir_type) {
case GameListItemType::InstalledDir: case GameListItemType::InstalledDir:
setData(QIcon::fromTheme("sd_card").pixmap(icon_size).scaled( setData(
icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), QIcon::fromTheme(QStringLiteral("sd_card"))
.pixmap(icon_size)
.scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
Qt::DecorationRole); Qt::DecorationRole);
setData("Installed Titles", Qt::DisplayRole); setData("Installed Titles", Qt::DisplayRole);
break; break;
@ -235,7 +237,9 @@ public:
setData("System Titles", Qt::DisplayRole); setData("System Titles", Qt::DisplayRole);
break; break;
case GameListItemType::CustomDir: case GameListItemType::CustomDir:
QString icon_name = QFileInfo::exists(game_dir->path) ? "folder" : "bad_folder"; const QString icon_name = QFileInfo::exists(game_dir->path)
? QStringLiteral("folder")
: QStringLiteral("bad_folder");
setData(QIcon::fromTheme(icon_name).pixmap(icon_size).scaled( setData(QIcon::fromTheme(icon_name).pixmap(icon_size).scaled(
icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
Qt::DecorationRole); Qt::DecorationRole);
@ -257,9 +261,10 @@ public:
explicit GameListAddDir() { explicit GameListAddDir() {
setData(type(), TypeRole); setData(type(), TypeRole);
int icon_size = UISettings::values.icon_size; const int icon_size = UISettings::values.icon_size;
setData(QIcon::fromTheme("plus").pixmap(icon_size).scaled( setData(QIcon::fromTheme(QStringLiteral("plus"))
icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), .pixmap(icon_size)
.scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
Qt::DecorationRole); Qt::DecorationRole);
setData("Add New Game Directory", Qt::DisplayRole); setData("Add New Game Directory", Qt::DisplayRole);
} }

View file

@ -354,16 +354,16 @@ void GameListWorker::run() {
for (UISettings::GameDir& game_dir : game_dirs) { for (UISettings::GameDir& game_dir : game_dirs) {
if (game_dir.path == "INSTALLED") { if (game_dir.path == "INSTALLED") {
GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir); auto* const game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir);
emit DirEntryReady({game_list_dir}); emit DirEntryReady({game_list_dir});
AddTitlesToGameList(game_list_dir); AddTitlesToGameList(game_list_dir);
} else if (game_dir.path == "SYSTEM") { } else if (game_dir.path == "SYSTEM") {
GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir); auto* const game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir);
emit DirEntryReady({game_list_dir}); emit DirEntryReady({game_list_dir});
AddTitlesToGameList(game_list_dir); AddTitlesToGameList(game_list_dir);
} else { } else {
watch_list.append(game_dir.path); watch_list.append(game_dir.path);
GameListDir* game_list_dir = new GameListDir(game_dir); auto* const game_list_dir = new GameListDir(game_dir);
emit DirEntryReady({game_list_dir}); emit DirEntryReady({game_list_dir});
provider->ClearAllEntries(); provider->ClearAllEntries();
ScanFileSystem(ScanTarget::FillManualContentProvider, game_dir.path.toStdString(), 2, ScanFileSystem(ScanTarget::FillManualContentProvider, game_dir.path.toStdString(), 2,

View file

@ -1309,11 +1309,11 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id,
QDesktopServices::openUrl(QUrl(QStringLiteral("https://yuzu-emu.org/game/") + directory)); QDesktopServices::openUrl(QUrl(QStringLiteral("https://yuzu-emu.org/game/") + directory));
} }
void GMainWindow::OnGameListOpenDirectory(QString directory) { void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
QString path; QString path;
if (directory == QStringLiteral("INSTALLED")) { if (directory == QStringLiteral("INSTALLED")) {
// TODO: Find a better solution when installing files to the SD card gets implemented // TODO: Find a better solution when installing files to the SD card gets implemented
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir).c_str() + path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
std::string("user/Contents/registered")); std::string("user/Contents/registered"));
} else if (directory == QStringLiteral("SYSTEM")) { } else if (directory == QStringLiteral("SYSTEM")) {
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir).c_str() + path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir).c_str() +
@ -1329,7 +1329,7 @@ void GMainWindow::OnGameListOpenDirectory(QString directory) {
} }
void GMainWindow::OnGameListAddDirectory() { void GMainWindow::OnGameListAddDirectory() {
QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory")); const QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
if (dir_path.isEmpty()) if (dir_path.isEmpty())
return; return;
UISettings::GameDir game_dir{dir_path, false, true}; UISettings::GameDir game_dir{dir_path, false, true};

View file

@ -187,7 +187,7 @@ private slots:
void OnGameListCopyTID(u64 program_id); void OnGameListCopyTID(u64 program_id);
void OnGameListNavigateToGamedbEntry(u64 program_id, void OnGameListNavigateToGamedbEntry(u64 program_id,
const CompatibilityList& compatibility_list); const CompatibilityList& compatibility_list);
void OnGameListOpenDirectory(QString path); void OnGameListOpenDirectory(const QString& directory);
void OnGameListAddDirectory(); void OnGameListAddDirectory();
void OnGameListShowList(bool show); void OnGameListShowList(bool show);
void OnGameListOpenPerGameProperties(const std::string& file); void OnGameListOpenPerGameProperties(const std::string& file);