summaryrefslogtreecommitdiff
path: root/raveos-calamares-module/desktopselect/DesktopBackend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'raveos-calamares-module/desktopselect/DesktopBackend.cpp')
-rw-r--r--raveos-calamares-module/desktopselect/DesktopBackend.cpp56
1 files changed, 52 insertions, 4 deletions
diff --git a/raveos-calamares-module/desktopselect/DesktopBackend.cpp b/raveos-calamares-module/desktopselect/DesktopBackend.cpp
index 9fd1cc2..c5c2fec 100644
--- a/raveos-calamares-module/desktopselect/DesktopBackend.cpp
+++ b/raveos-calamares-module/desktopselect/DesktopBackend.cpp
@@ -1,23 +1,71 @@
#include "DesktopBackend.h"
+#include <QLocale>
+#include <QVariantMap>
+
DesktopBackend::DesktopBackend(QObject* parent)
: QObject(parent)
+ , m_locale(QLocale::system().name())
{}
void DesktopBackend::setDesktops(const QVariantList& desktops)
{
- m_desktops = desktops;
+ m_rawDesktops = desktops;
m_selectedIndex = -1;
+ rebuildDesktops();
emit desktopsChanged();
emit selectedIndexChanged();
}
-void DesktopBackend::selectDesktop(int index)
+void DesktopBackend::setLocale(const QString& locale)
{
- if (index == m_selectedIndex)
+ if (m_locale == locale)
return;
+ m_locale = locale;
+ rebuildDesktops();
+ emit localeChanged();
+ emit desktopsChanged();
+}
+
+void DesktopBackend::rebuildDesktops()
+{
+ const bool hungarian = m_locale.startsWith(QLatin1String("hu"));
+ const bool german = m_locale.startsWith(QLatin1String("de"));
+
+ m_desktops.clear();
+ for (const QVariant& v : m_rawDesktops)
+ {
+ const QVariantMap raw = v.toMap();
+
+ QVariantMap item;
+ item.insert(QStringLiteral("name"), raw.value(QStringLiteral("name")));
+ item.insert(
+ QStringLiteral("description"),
+ hungarian ? raw.value(QStringLiteral("description_hu"), raw.value(QStringLiteral("description")))
+ : german ? raw.value(QStringLiteral("description_de"), raw.value(QStringLiteral("description")))
+ : raw.value(QStringLiteral("description_en"), raw.value(QStringLiteral("description"))));
+ item.insert(
+ QStringLiteral("badge"),
+ hungarian ? raw.value(QStringLiteral("badge_hu"), raw.value(QStringLiteral("badge")))
+ : german ? raw.value(QStringLiteral("badge_de"), raw.value(QStringLiteral("badge")))
+ : raw.value(QStringLiteral("badge_en"), raw.value(QStringLiteral("badge"))));
+ item.insert(QStringLiteral("badge_color"), raw.value(QStringLiteral("badge_color")));
+ item.insert(QStringLiteral("available"), raw.value(QStringLiteral("available"), true));
+ item.insert(QStringLiteral("packages"), raw.value(QStringLiteral("packages")));
+
+ m_desktops.append(item);
+ }
+}
+
+void DesktopBackend::selectDesktop(int index)
+{
if (index < 0 || index >= m_desktops.size())
return;
+ if (!m_desktops[index].toMap().value(QStringLiteral("available"), true).toBool())
+ return;
+ if (index == m_selectedIndex)
+ return;
+
m_selectedIndex = index;
emit selectedIndexChanged();
emit selectionMade();
@@ -29,7 +77,7 @@ QStringList DesktopBackend::selectedPackages() const
return {};
const QVariantMap desktop = m_desktops[m_selectedIndex].toMap();
QStringList pkgs;
- for (const auto& v : desktop.value("packages").toList())
+ for (const auto& v : desktop.value(QStringLiteral("packages")).toList())
pkgs << v.toString();
return pkgs;
}