-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(UI): Fix TheTvDbImages language configuration
Follow up to 68ea08d
- Loading branch information
Showing
10 changed files
with
192 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "scrapers/image/TheTvDbImagesConfiguration.h" | ||
|
||
#include "scrapers/image/TheTvDbImages.h" | ||
|
||
namespace { | ||
|
||
static constexpr char moduleName[] = "scrapers"; | ||
static const Settings::Key KEY_SCRAPERS_LANGUAGE(moduleName, "Scrapers/images.thetvdb/Language"); | ||
|
||
} // namespace | ||
|
||
|
||
namespace mediaelch { | ||
namespace scraper { | ||
|
||
TheTvDbImagesConfiguration::TheTvDbImagesConfiguration(Settings& settings) : | ||
ScraperConfiguration(QString(TheTvDbImages::ID), settings) | ||
{ | ||
settings.onSettingChanged(KEY_SCRAPERS_LANGUAGE, this, [this]() { emit languageChanged(language()); }); | ||
} | ||
|
||
void TheTvDbImagesConfiguration::init() | ||
{ | ||
settings().setDefaultValue(KEY_SCRAPERS_LANGUAGE, defaultLocale().toString()); | ||
} | ||
|
||
mediaelch::Locale TheTvDbImagesConfiguration::defaultLocale() | ||
{ | ||
return {"en"}; | ||
} | ||
|
||
QVector<Locale> TheTvDbImagesConfiguration::supportedLanguages() | ||
{ | ||
// Multiple languages, but no way to query for it and also no official list of languages. | ||
return QVector<Locale>({ | ||
"bg", | ||
"zh", | ||
"hr", | ||
"cs", | ||
"da", | ||
"nl", | ||
"en", | ||
"fi", | ||
"fr", | ||
"de", | ||
"el", | ||
"he", | ||
"hu", | ||
"it", | ||
"ja", | ||
"ko", | ||
"no", | ||
"pl", | ||
"pt", | ||
"ru", | ||
"sl", | ||
"es", | ||
"sv", | ||
"tr", | ||
}); | ||
} | ||
|
||
Locale TheTvDbImagesConfiguration::language() | ||
{ | ||
return settings().value(KEY_SCRAPERS_LANGUAGE).toString(); | ||
} | ||
|
||
void TheTvDbImagesConfiguration::setLanguage(const Locale& value) | ||
{ | ||
settings().setValue(KEY_SCRAPERS_LANGUAGE, value.toString()); | ||
} | ||
|
||
|
||
} // namespace scraper | ||
} // namespace mediaelch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "data/Locale.h" | ||
#include "scrapers/ScraperConfiguration.h" | ||
#include "settings/Settings.h" | ||
#include "utils/Meta.h" | ||
|
||
#include <QVector> | ||
|
||
namespace mediaelch { | ||
namespace scraper { | ||
|
||
class TheTvDbImagesConfiguration : public QObject, public ScraperConfiguration | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit TheTvDbImagesConfiguration(Settings& settings); | ||
~TheTvDbImagesConfiguration() override = default; | ||
|
||
void init() override; | ||
|
||
ELCH_NODISCARD static mediaelch::Locale defaultLocale(); | ||
ELCH_NODISCARD static QVector<Locale> supportedLanguages(); | ||
|
||
signals: | ||
void languageChanged(Locale language); | ||
|
||
public: | ||
ELCH_NODISCARD Locale language() override; | ||
void setLanguage(const Locale& value) override; | ||
}; | ||
|
||
} // namespace scraper | ||
} // namespace mediaelch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "ui/scrapers/image/TheTvDbImagesConfigurationView.h" | ||
|
||
#include <QGridLayout> | ||
#include <QLabel> | ||
|
||
namespace mediaelch { | ||
namespace scraper { | ||
|
||
|
||
TheTvDbImagesConfigurationView::TheTvDbImagesConfigurationView(TheTvDbImagesConfiguration& settings) : | ||
m_settings(settings) | ||
{ | ||
m_languageBox = new LanguageCombo(this); | ||
m_languageBox->setupLanguages(m_settings.supportedLanguages(), m_settings.language()); | ||
|
||
auto* layout = new QGridLayout(this); | ||
layout->addWidget(new QLabel(tr("Language")), 0, 0); | ||
layout->addWidget(m_languageBox, 0, 1); | ||
layout->setColumnStretch(2, 1); | ||
layout->setContentsMargins(12, 0, 12, 12); | ||
|
||
|
||
connect(m_languageBox, &LanguageCombo::languageChanged, this, [this]() { | ||
m_settings.setLanguage(m_languageBox->currentLocale()); | ||
}); | ||
connect(&m_settings, &TheTvDbImagesConfiguration::languageChanged, this, [this](Locale language) { | ||
const bool blocked = m_languageBox->blockSignals(true); // avoid triggering save-logic or infinite loop | ||
m_languageBox->setLanguage(language); | ||
m_languageBox->blockSignals(blocked); | ||
}); | ||
} | ||
|
||
|
||
} // namespace scraper | ||
} // namespace mediaelch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "scrapers/image/TheTvDbImagesConfiguration.h" | ||
#include "ui/small_widgets/LanguageCombo.h" | ||
|
||
#include <QWidget> | ||
|
||
namespace mediaelch { | ||
namespace scraper { | ||
|
||
class TheTvDbImagesConfigurationView : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit TheTvDbImagesConfigurationView(TheTvDbImagesConfiguration& settings); | ||
~TheTvDbImagesConfigurationView() override = default; | ||
|
||
private: | ||
TheTvDbImagesConfiguration& m_settings; | ||
LanguageCombo* m_languageBox{nullptr}; | ||
}; | ||
|
||
} // namespace scraper | ||
} // namespace mediaelch |