Skip to content

Commit

Permalink
Fix the first click of "..." item in the language combo box
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Feb 3, 2022
1 parent d7ea192 commit 3a3ccb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 11 additions & 14 deletions Source/Gui/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,16 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QDialog{parent}
}
_ui.cbLanguages->addItem("...");

Update(Core::Settings::GetCurrent(), false);

connect(
_ui.buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this,
&SettingsWindow::RestoreDefaults);

connect(
_ui.cbLanguages, qOverload<int>(&QComboBox::currentIndexChanged), this, [this](int index) {
static auto lastIndex = _ui.cbLanguages->currentIndex();
bool isMore = _ui.cbLanguages->count() == index + 1;
if (!isMore) {
lastIndex = _ui.cbLanguages->currentIndex();
}
if (_trigger) {
On_cbLanguages_currentIndexChanged(index, isMore);
}
if (isMore) {
_ui.cbLanguages->setCurrentIndex(lastIndex);
On_cbLanguages_currentIndexChanged(index);
}
});

Expand Down Expand Up @@ -175,8 +169,6 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QDialog{parent}
On_pbOpenLogsDirectory_clicked();
}
});

Update(Core::Settings::GetCurrent(), false);
}

int SettingsWindow::GetTabCount() const
Expand Down Expand Up @@ -258,7 +250,9 @@ void SettingsWindow::Update(const Core::Settings::Fields &fields, bool trigger)

_trigger = trigger;

_ui.cbLanguages->setCurrentIndex(ApdApp->GetCurrentLoadedLocaleIndex());
auto currentLangIndex = ApdApp->GetCurrentLoadedLocaleIndex();
_lastLanguageIndex = currentLangIndex;
_ui.cbLanguages->setCurrentIndex(currentLangIndex);

_ui.cbAutoRun->setChecked(fields.auto_run);

Expand Down Expand Up @@ -287,15 +281,18 @@ void SettingsWindow::showEvent(QShowEvent *event)
Update(Core::Settings::GetCurrent(), false);
}

void SettingsWindow::On_cbLanguages_currentIndexChanged(int index, bool isMore)
void SettingsWindow::On_cbLanguages_currentIndexChanged(int index)
{
if (!isMore) {
if (_ui.cbLanguages->count() != index + 1) {
_lastLanguageIndex = index;

const auto &availableLocales = ApdApp->AvailableLocales();
const auto &locale = availableLocales.at(index);

Core::Settings::ModifiableAccess()->language_locale = locale.name();
}
else {
_ui.cbLanguages->setCurrentIndex(_lastLanguageIndex);
// clang-format off
QDesktopServices::openUrl(QUrl{
"https://github.com/SpriteOvO/AirPodsDesktop/blob/main/CONTRIBUTING.md#-translation-guide"
Expand Down
4 changes: 2 additions & 2 deletions Source/Gui/SettingsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class SettingsWindow : public QDialog

private:
Ui::SettingsWindow _ui;

bool _trigger{true};
int _lastLanguageIndex{0};

void InitCreditsText();
void RestoreDefaults();
Expand All @@ -53,7 +53,7 @@ class SettingsWindow : public QDialog
void showEvent(QShowEvent *event) override;

// General
void On_cbLanguages_currentIndexChanged(int index, bool isMore);
void On_cbLanguages_currentIndexChanged(int index);
void On_cbAutoRun_toggled(bool checked);
void On_pbUnbind_clicked();

Expand Down

0 comments on commit 3a3ccb8

Please sign in to comment.