From 69b5f25644ea6391f44e00bacaffd7c556d0f6d7 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 7 Apr 2018 19:36:54 +0200 Subject: [PATCH] Qt: Fix vfs dialog reset and add some translations Reset would crash the app, because a cleared item received a signal on currentItemChanged. Also, Reset did not reset the list as one might think, but clean it and then result in wrong behaviour. Furthermore the settings were saved, regardless of accepting the dialog or not. --- rpcs3/rpcs3qt/vfs_dialog_tab.cpp | 31 +++++++++++++++---------------- rpcs3/rpcs3qt/vfs_dialog_tab.h | 3 +++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/rpcs3/rpcs3qt/vfs_dialog_tab.cpp b/rpcs3/rpcs3qt/vfs_dialog_tab.cpp index f3be998b7c..89a3d27387 100644 --- a/rpcs3/rpcs3qt/vfs_dialog_tab.cpp +++ b/rpcs3/rpcs3qt/vfs_dialog_tab.cpp @@ -31,10 +31,8 @@ vfs_dialog_tab::vfs_dialog_tab(const vfs_settings_info& settingsInfo, std::share m_dirList->setMinimumWidth(m_dirList->sizeHintForColumn(0)); QHBoxLayout* selectedConfigLayout = new QHBoxLayout; - QLabel* selectedMessage = new QLabel(m_info.name + " directory:"); - m_selectedConfigLabel = new QLabel(); - m_selectedConfigLabel->setText(current_dir.isEmpty() ? EmptyPath : current_dir); - selectedConfigLayout->addWidget(selectedMessage); + m_selectedConfigLabel = new QLabel(current_dir.isEmpty() ? EmptyPath : current_dir); + selectedConfigLayout->addWidget(new QLabel(m_info.name + tr(" directory:"))); selectedConfigLayout->addWidget(m_selectedConfigLabel); selectedConfigLayout->addStretch(); @@ -46,6 +44,9 @@ vfs_dialog_tab::vfs_dialog_tab(const vfs_settings_info& settingsInfo, std::share connect(m_dirList, &QListWidget::currentItemChanged, [this](QListWidgetItem* current, QListWidgetItem*) { + if (!current) + return; + m_selectedConfigLabel->setText(current->text().isEmpty() ? EmptyPath : current->text()); }); } @@ -66,21 +67,19 @@ void vfs_dialog_tab::SetSettings() void vfs_dialog_tab::Reset() { - const QString current_dir = qstr(m_info.cfg_node->to_string()); m_dirList->clear(); - m_info.cfg_node->from_default(); - m_selectedConfigLabel->setText(current_dir.isEmpty() ? EmptyPath : current_dir); - m_dirList->addItem(new QListWidgetItem(current_dir)); - m_gui_settings->SetValue(m_info.listLocation, QStringList(current_dir)); + m_dirList->setCurrentItem(new QListWidgetItem(qstr(m_info.cfg_node->def), m_dirList)); } void vfs_dialog_tab::AddNewDirectory() { - QString dir = QFileDialog::getExistingDirectory(nullptr, "Choose a directory", QCoreApplication::applicationDirPath()); - if (dir != "") - { - if (dir.endsWith("/") == false) dir += '/'; - new QListWidgetItem(dir, m_dirList); - m_selectedConfigLabel->setText(dir); - } + QString dir = QFileDialog::getExistingDirectory(nullptr, tr("Choose a directory"), QCoreApplication::applicationDirPath()); + + if (dir.isEmpty()) + return; + + if (!dir.endsWith("/")) + dir += '/'; + + m_dirList->setCurrentItem(new QListWidgetItem(dir, m_dirList)); } diff --git a/rpcs3/rpcs3qt/vfs_dialog_tab.h b/rpcs3/rpcs3qt/vfs_dialog_tab.h index fba53ec892..2afbac73a8 100644 --- a/rpcs3/rpcs3qt/vfs_dialog_tab.h +++ b/rpcs3/rpcs3qt/vfs_dialog_tab.h @@ -27,7 +27,10 @@ public: void SetSettings(); void AddNewDirectory(); + + // Reset this tab without saving the settings yet void Reset(); + private: const QString EmptyPath = tr("Empty Path");