FreeCAD

Форк
0
/
Branding.cpp 
113 строк · 3.9 Кб
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
#include "PreCompiled.h"
25

26
#include <QFile>
27

28
#include "Branding.h"
29

30

31
using namespace App;
32

33
Branding::Branding()
34
{
35
    filter.push_back("Application");
36
    filter.push_back("WindowTitle");
37
    filter.push_back("CopyrightInfo");
38
    filter.push_back("MaintainerUrl");
39
    filter.push_back("WindowIcon");
40
    filter.push_back("ProgramLogo");
41
    filter.push_back("ProgramIcons");
42
    filter.push_back("StyleSheet");
43

44
    filter.push_back("BuildVersionMajor");
45
    filter.push_back("BuildVersionMinor");
46
    filter.push_back("BuildRevision");
47
    filter.push_back("BuildRevisionDate");
48

49
    filter.push_back("SplashScreen");
50
    filter.push_back("SplashAlignment");
51
    filter.push_back("SplashTextColor");
52
    filter.push_back("SplashInfoColor");
53

54
    filter.push_back("StartWorkbench");
55

56
    filter.push_back("ExeName");
57
    filter.push_back("ExeVendor");
58
    filter.push_back("NavigationStyle");
59
    filter.push_back("UserParameterTemplate");
60
}
61

62
bool Branding::readFile(const QString& fn)
63
{
64
    QFile file(fn);
65
    if (!file.open(QFile::ReadOnly))
66
        return false;
67
    if (!evaluateXML(&file, domDocument))
68
        return false;
69
    file.close();
70
    return true;
71
}
72

73
Branding::XmlConfig Branding::getUserDefines() const
74
{
75
    XmlConfig cfg;
76
    QDomElement root = domDocument.documentElement();
77
    QDomElement child;
78
    if (!root.isNull()) {
79
        child = root.firstChildElement();
80
        while (!child.isNull()) {
81
            std::string name = child.localName().toLatin1().constData();
82
            std::string value = child.text().toUtf8().constData();
83
            if (std::find(filter.begin(), filter.end(), name) != filter.end())
84
                cfg[name] = value;
85
            child = child.nextSiblingElement();
86
        }
87
    }
88
    return cfg;
89
}
90

91
bool Branding::evaluateXML(QIODevice *device, QDomDocument& xmlDocument)
92
{
93
    QString errorStr;
94
    int errorLine;
95
    int errorColumn;
96

97
    if (!xmlDocument.setContent(device, true, &errorStr, &errorLine,
98
                                &errorColumn)) {
99
        return false;
100
    }
101

102
    QDomElement root = xmlDocument.documentElement();
103
    if (root.tagName() != QLatin1String("Branding")) {
104
        return false;
105
    }
106
    else if (root.hasAttribute(QLatin1String("version"))) {
107
        QString attr = root.attribute(QLatin1String("version"));
108
        if (attr != QLatin1String("1.0"))
109
            return false;
110
    }
111

112
    return true;
113
}
114

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.