Debian Codegraph @

src/App/Branding.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 51 Franklin Street, *
19 * Fifth Floor, Boston, MA 02110-1301, USA *
20 * *
21 ***************************************************************************/
22
23
24
25 #include <QFile>
26
27 #include "Branding.h"
28
29
30 using namespace App;
31
32 Branding::Branding()
33 {
34 filter.push_back("Application");
35 filter.push_back("WindowTitle");
36 filter.push_back("CopyrightInfo");
37 filter.push_back("MaintainerUrl");
38 filter.push_back("WindowIcon");
39 filter.push_back("ProgramLogo");
40 filter.push_back("ProgramIcons");
41 filter.push_back("DesktopFileName");
42 filter.push_back("StyleSheet");
43
44 filter.push_back("BuildVersionMajor");
45 filter.push_back("BuildVersionMinor");
46 filter.push_back("BuildVersionPoint");
47 filter.push_back("BuildRevision");
48 filter.push_back("BuildRevisionDate");
49 filter.push_back("BuildVersionSuffix");
50 filter.push_back("BuildRepositoryURL");
51
52 filter.push_back("AboutImage");
53 filter.push_back("SplashScreen");
54 filter.push_back("SplashAlignment");
55 filter.push_back("SplashTextColor");
56 filter.push_back("SplashInfoColor");
57 filter.push_back("SplashInfoFont");
58 filter.push_back("SplashInfoPosition");
59 filter.push_back("SplashWarningColor");
60
61 filter.push_back("StartWorkbench");
62
63 filter.push_back("ExeName");
64 filter.push_back("ExeVendor");
65 filter.push_back("ExeVersion");
66 filter.push_back("AppDataSkipVendor");
67 filter.push_back("NavigationStyle");
68 filter.push_back("UserParameterTemplate");
69 }
70
71 bool Branding::readFile(const QString& fn)
72 {
73 QFile file(fn);
74 if (!file.open(QFile::ReadOnly)) {
75 return false;
76 }
77 if (!evaluateXML(&file, domDocument)) {
78 return false;
79 }
80 file.close();
81 return true;
82 }
83
84 Branding::XmlConfig Branding::getUserDefines() const
85 {
86 XmlConfig cfg;
87 QDomElement root = domDocument.documentElement();
88 QDomElement child;
89 if (!root.isNull()) {
90 child = root.firstChildElement();
91 while (!child.isNull()) {
92 std::string name = child.localName().toLatin1().constData();
93 std::string value = child.text().toUtf8().constData();
94 if (filter.contains(name)) {
95 cfg[name] = std::move(value);
96 }
97 child = child.nextSiblingElement();
98 }
99 }
100 return cfg;
101 }
102
103 bool Branding::evaluateXML(QIODevice* device, QDomDocument& xmlDocument)
104 {
105 #if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
106 if (!xmlDocument.setContent(device, QDomDocument::ParseOption::UseNamespaceProcessing)) {
107 return false;
108 }
109 #else
110 QString errorStr;
111 int errorLine;
112 int errorColumn;
113 if (!xmlDocument.setContent(device, true, &errorStr, &errorLine, &errorColumn)) {
114 return false;
115 }
116 #endif
117
118 QDomElement root = xmlDocument.documentElement();
119 if (root.tagName() != QLatin1String("Branding")) {
120 return false;
121 }
122 if (root.hasAttribute(QLatin1String("version"))) {
123 QString attr = root.attribute(QLatin1String("version"));
124 if (attr != QLatin1String("1.0")) {
125 return false;
126 }
127 }
128
129 return true;
130 }