fix: Companion improve themes exceptions handling (#1763)

This commit is contained in:
Neil Horne
2022-03-30 19:28:46 +10:00
committed by GitHub
parent b3108841ff
commit 777b0a48ae
+31 -29
View File
@@ -48,12 +48,10 @@ UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, Gene
int col = 0; int col = 0;
int row = 0; int row = 0;
// set default theme as back up std::string themeName = tr("Information unavailable").toStdString();
const std::string defaultTheme = "EdgeTX Default"; std::string themeAuthor = "";
std::string themeName = defaultTheme; std::string themeInfo = "";
std::string themeAuthor = "EdgeTX Team"; std::string themeFolder = "";
std::string themeInfo = "Default EdgeTX Color Scheme";
std::string themeFolder = "/THEMES/EdgeTX";
QString selTheme = QString(); QString selTheme = QString();
@@ -73,20 +71,26 @@ UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, Gene
} }
if (!selTheme.isEmpty()) { if (!selTheme.isEmpty()) {
QFile fst(sdPath % selTheme); QStringList strl = selTheme.split("/");
if (strl.size() >= 3) {
themeFolder = "/THEMES/" + strl.at(2).toStdString();
themeName = strl.at(2).toStdString();
}
if (fst.exists()) { QString selThemeDetails(sdPath % selTheme);
QStringList strl = selTheme.split("/");
if (strl.size() >= 3)
themeFolder = "/THEMES/" + strl.at(2).toStdString();
YAML::Node node = YAML::LoadFile(QString(sdPath % selTheme).toStdString()); if (QFile(selThemeDetails).exists()) {
YAML::Node node = YAML::LoadFile(selThemeDetails.toStdString());
if (node["summary"]) { if (node["summary"]) {
const auto &summary = node["summary"]; const auto &summary = node["summary"];
if (summary.IsMap()) { if (summary.IsMap()) {
themeName = summary["name"].as<std::string>(); if (summary["name"].IsScalar())
themeAuthor = summary["author"].as<std::string>(); themeName = summary["name"].as<std::string>();
themeInfo = summary["info"].as<std::string>(); if (summary["author"].IsScalar())
themeAuthor = summary["author"].as<std::string>();
if (summary["info"].IsScalar())
themeInfo = summary["info"].as<std::string>();
} }
} }
} }
@@ -106,21 +110,19 @@ UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, Gene
addGridLabel(grid, tr("Information"), row, col++); addGridLabel(grid, tr("Information"), row, col++);
addGridLabel(grid, themeInfo.c_str(), row++, col++); addGridLabel(grid, themeInfo.c_str(), row++, col++);
if (themeName != defaultTheme) { col = 0;
col = 0; addGridBlankRow(grid, row);
addGridBlankRow(grid, row); addGridLabel(grid, "", row, col++);
addGridLabel(grid, "", row, col++);
QLabel * img = new QLabel(this); QLabel * img = new QLabel(this);
QString path = sdPath + themeFolder.c_str() + "/logo.png"; QString path = sdPath + themeFolder.c_str() + "/logo.png";
QFile fimg(path); QFile fimg(path);
if (fimg.exists()) { if (fimg.exists()) {
QImage image(path); QImage image(path);
if (!image.isNull()) { if (!image.isNull()) {
img->setText(""); img->setText("");
img->setFixedSize(QSize(firmware->getCapability(LcdWidth) / 2, firmware->getCapability(LcdHeight) / 2)); img->setFixedSize(QSize(firmware->getCapability(LcdWidth) / 2, firmware->getCapability(LcdHeight) / 2));
img->setPixmap(QPixmap::fromImage(image.scaled(firmware->getCapability(LcdWidth) / 2, firmware->getCapability(LcdHeight) / 2))); img->setPixmap(QPixmap::fromImage(image.scaled(firmware->getCapability(LcdWidth) / 2, firmware->getCapability(LcdHeight) / 2)));
}
} }
grid->addWidget(img, row++, col++); grid->addWidget(img, row++, col++);