|
6 | 6 | #include <qt/guiutil.h> |
7 | 7 |
|
8 | 8 | #include <qt/bitcoinaddressvalidator.h> |
| 9 | +#include <qt/bitcoingui.h> |
9 | 10 | #include <qt/bitcoinunits.h> |
10 | 11 | #include <qt/qvalidatedlineedit.h> |
11 | 12 | #include <qt/walletmodel.h> |
@@ -1064,7 +1065,36 @@ void loadStyleSheet(QWidget* widget, bool fDebugWidget) |
1064 | 1065 | if (!qFile.open(QFile::ReadOnly)) { |
1065 | 1066 | throw std::runtime_error(strprintf("%s: Failed to open file: %s", __func__, file.toStdString())); |
1066 | 1067 | } |
1067 | | - stylesheet->append(QLatin1String(qFile.readAll())); |
| 1068 | + |
| 1069 | + QString strStyle = QLatin1String(qFile.readAll()); |
| 1070 | + // Process all <os=...></os> groups in the stylesheet first |
| 1071 | + QRegularExpressionMatch osStyleMatch; |
| 1072 | + QRegularExpression osStyleExp("^(<os=(?:'|\").+(?:'|\")>)((?:.|\n)+?)(</os>?)$"); |
| 1073 | + osStyleExp.setPatternOptions(QRegularExpression::MultilineOption); |
| 1074 | + QRegularExpressionMatchIterator it = osStyleExp.globalMatch(strStyle); |
| 1075 | + |
| 1076 | + // For all <os=...></os> sections |
| 1077 | + while (it.hasNext() && (osStyleMatch = it.next()).isValid()) { |
| 1078 | + QStringList listMatches = osStyleMatch.capturedTexts(); |
| 1079 | + |
| 1080 | + // Full match + 3 group matches |
| 1081 | + if (listMatches.size() % 4) { |
| 1082 | + throw std::runtime_error(strprintf("%s: Invalid <os=...></os> section in file %s", __func__, file.toStdString())); |
| 1083 | + } |
| 1084 | + |
| 1085 | + for (int i = 0; i < listMatches.size(); i += 4) { |
| 1086 | + if (!listMatches[i + 1].contains(QString::fromStdString(BitcoinGUI::DEFAULT_UIPLATFORM))) { |
| 1087 | + // If os is not supported for this styles |
| 1088 | + // just remove the full match |
| 1089 | + strStyle.replace(listMatches[i], ""); |
| 1090 | + } else { |
| 1091 | + // If its supported remove the <os=...></os> tags |
| 1092 | + strStyle.replace(listMatches[i + 1], ""); |
| 1093 | + strStyle.replace(listMatches[i + 3], ""); |
| 1094 | + } |
| 1095 | + } |
| 1096 | + } |
| 1097 | + stylesheet->append(strStyle); |
1068 | 1098 | } |
1069 | 1099 | return true; |
1070 | 1100 | }; |
|
0 commit comments