Skip to content

Commit

Permalink
settings import - cosmetic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolcha committed Sep 29, 2024
1 parent 787c4b3 commit 401b28c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions app/core/skin_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct SkinManager::Impl {
QSet<QString> user_skins;

void reload();

const LegacySkinLoader* find(const QString& id) const;
};

void SkinManager::Impl::reload()
Expand Down Expand Up @@ -56,6 +58,17 @@ void SkinManager::Impl::reload()
loaders.remove(id);
}

const LegacySkinLoader* SkinManager::Impl::find(const QString& id) const
{
if (auto iter = loaders.find(id); iter != loaders.end())
return &iter.value();
// search skin by name as fallback
for (auto iter = loaders.begin(); iter != loaders.end(); ++iter)
if (iter->title() == id)
return &iter.value();
return nullptr;
}

SkinManager::SkinManager()
: _impl(std::make_unique<Impl>())
{
Expand All @@ -71,12 +84,8 @@ std::unique_ptr<Skin> SkinManager::loadSkin(const QFont& font) const

std::unique_ptr<Skin> SkinManager::loadSkin(const QString& id) const
{
if (auto iter = _impl->loaders.find(id); iter != _impl->loaders.end())
if (auto iter = _impl->find(id))
return iter->skin();
// search skin by name as fallback
for (auto iter = _impl->loaders.begin(); iter != _impl->loaders.end(); ++iter)
if (iter->title() == id)
return iter->skin();
return std::make_unique<ErrorSkin>();
}

Expand All @@ -87,7 +96,7 @@ QStringList SkinManager::availableSkins() const

SkinManager::Metadata SkinManager::metadata(const QString& id) const
{
if (auto iter = _impl->loaders.find(id); iter != _impl->loaders.end())
if (auto iter = _impl->find(id))
return iter->metadata();
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion app/gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void SettingsDialog::on_import_btn_clicked()
void SettingsDialog::on_export_btn_clicked()
{
auto filename = QFileDialog::getSaveFileName(this, tr("Export settings"),
QDir::home().filePath("digital_clock_5.dc5"),
QDir::home().filePath("clock_settings.dc5"),
tr("Digital Clock 5 Settings (*.dc5)"));
if (filename.isEmpty()) return;
QVariantHash settings;
Expand Down

0 comments on commit 401b28c

Please sign in to comment.