+ move branding stuff from main() to FreeCADApp
This commit is contained in:
parent
1470a32533
commit
cc281d482e
|
@ -100,6 +100,7 @@
|
|||
// or the Python script "SubWCRev.py" on Linux based systems which builds
|
||||
// src/Build/Version.h. Or create your own from src/Build/Version.h.in!
|
||||
#include <Build/Version.h>
|
||||
#include "Branding.h"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/token_functions.hpp>
|
||||
|
@ -107,6 +108,7 @@
|
|||
#include <boost/bind.hpp>
|
||||
#include <boost/version.hpp>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
using namespace App;
|
||||
using namespace std;
|
||||
|
@ -1132,6 +1134,17 @@ void Application::initConfig(int argc, char ** argv)
|
|||
_argc = argc;
|
||||
_argv = argv;
|
||||
|
||||
// Now it's time to read-in the file branding.xml if it exists
|
||||
Branding brand;
|
||||
QString binDir = QString::fromUtf8((mConfig["AppHomePath"] + "bin").c_str());
|
||||
QFileInfo fi(binDir, QString::fromAscii("branding.xml"));
|
||||
if (brand.readFile(fi.absoluteFilePath())) {
|
||||
Branding::XmlConfig cfg = brand.getUserDefines();
|
||||
for (Branding::XmlConfig::iterator it = cfg.begin(); it != cfg.end(); ++it) {
|
||||
App::Application::Config()[it.key()] = it.value();
|
||||
}
|
||||
}
|
||||
|
||||
// extract home paths
|
||||
ExtractUserPath();
|
||||
|
||||
|
|
116
src/App/Branding.cpp
Normal file
116
src/App/Branding.cpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include <QXmlSimpleReader>
|
||||
#include <QXmlInputSource>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "Branding.h"
|
||||
|
||||
using namespace App;
|
||||
|
||||
Branding::Branding()
|
||||
{
|
||||
filter.push_back("Application");
|
||||
filter.push_back("WindowTitle");
|
||||
filter.push_back("CopyrightInfo");
|
||||
filter.push_back("MaintainerUrl");
|
||||
filter.push_back("WindowIcon");
|
||||
filter.push_back("ProgramLogo");
|
||||
filter.push_back("ProgramIcons");
|
||||
|
||||
filter.push_back("BuildVersionMajor");
|
||||
filter.push_back("BuildVersionMinor");
|
||||
filter.push_back("BuildRevision");
|
||||
filter.push_back("BuildRevisionDate");
|
||||
|
||||
filter.push_back("SplashScreen");
|
||||
filter.push_back("SplashAlignment");
|
||||
filter.push_back("SplashTextColor");
|
||||
filter.push_back("SplashInfoColor");
|
||||
|
||||
filter.push_back("StartWorkbench");
|
||||
|
||||
filter.push_back("ExeName");
|
||||
filter.push_back("ExeVendor");
|
||||
filter.push_back("NavigationStyle");
|
||||
}
|
||||
|
||||
bool Branding::readFile(const QString& fn)
|
||||
{
|
||||
QFile file(fn);
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
return false;
|
||||
if (!evaluateXML(&file, domDocument))
|
||||
return false;
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
Branding::XmlConfig Branding::getUserDefines() const
|
||||
{
|
||||
XmlConfig cfg;
|
||||
QDomElement root = domDocument.documentElement();
|
||||
QDomElement child;
|
||||
if (!root.isNull()) {
|
||||
child = root.firstChildElement();
|
||||
while (!child.isNull()) {
|
||||
std::string name = (const char*)child.localName().toAscii();
|
||||
std::string value = (const char*)child.text().toUtf8();
|
||||
if (std::find(filter.begin(), filter.end(), name) != filter.end())
|
||||
cfg[name] = value;
|
||||
child = child.nextSiblingElement();
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
bool Branding::evaluateXML(QIODevice *device, QDomDocument& xmlDocument)
|
||||
{
|
||||
QString errorStr;
|
||||
int errorLine;
|
||||
int errorColumn;
|
||||
|
||||
if (!xmlDocument.setContent(device, true, &errorStr, &errorLine,
|
||||
&errorColumn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement root = xmlDocument.documentElement();
|
||||
if (root.tagName() != QLatin1String("Branding")) {
|
||||
return false;
|
||||
}
|
||||
else if (root.hasAttribute(QLatin1String("version"))) {
|
||||
QString attr = root.attribute(QLatin1String("version"));
|
||||
if (attr != QLatin1String("1.0"))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
54
src/App/Branding.h
Normal file
54
src/App/Branding.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef APP_BRANDING_H
|
||||
#define APP_BRANDING_H
|
||||
|
||||
#include <string>
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
#include <QDomDocument>
|
||||
|
||||
class QIODevice;
|
||||
|
||||
namespace App {
|
||||
|
||||
class Branding
|
||||
{
|
||||
public:
|
||||
typedef QMap<std::string, std::string> XmlConfig;
|
||||
Branding();
|
||||
|
||||
bool readFile(const QString& fn);
|
||||
XmlConfig getUserDefines() const;
|
||||
|
||||
private:
|
||||
QVector<std::string> filter;
|
||||
bool evaluateXML(QIODevice *device, QDomDocument& xmlDocument);
|
||||
QDomDocument domDocument;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // APP_BRANDING_H
|
|
@ -28,11 +28,14 @@ if(WIN32)
|
|||
FreeCADBase
|
||||
${Boost_DEBUG_LIBRARIES}
|
||||
${Boost_LIBRARIES}
|
||||
${QT_DEBUG_LIBRARIES}
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
else(WIN32)
|
||||
set(FreeCADApp_LIBS
|
||||
FreeCADBase
|
||||
${Boost_LIBRARIES}
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
endif(WIN32)
|
||||
|
||||
|
@ -144,6 +147,7 @@ SET(FreeCADApp_CPP_SRCS
|
|||
${Properties_CPP_SRCS}
|
||||
Application.cpp
|
||||
ApplicationPy.cpp
|
||||
Branding.cpp
|
||||
ColorModel.cpp
|
||||
ComplexGeoData.cpp
|
||||
ComplexGeoDataPyImp.cpp
|
||||
|
@ -156,6 +160,7 @@ SET(FreeCADApp_HPP_SRCS
|
|||
${Document_HPP_SRCS}
|
||||
${Properties_HPP_SRCS}
|
||||
Application.h
|
||||
Branding.h
|
||||
ColorModel.h
|
||||
ComplexGeoData.h
|
||||
Enumeration.h
|
||||
|
|
|
@ -46,13 +46,6 @@
|
|||
#include <QLocale>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QXmlSimpleReader>
|
||||
#include <QXmlInputSource>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
// FreeCAD header
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Interpreter.h>
|
||||
|
@ -74,92 +67,6 @@ const char sBanner[] = "\xc2\xa9 Juergen Riegel, Werner Mayer, Yorik van Havre 2
|
|||
" # # # # # # # # # ## ## ##\n" \
|
||||
" # # #### #### ### # # #### ## ## ##\n\n" ;
|
||||
|
||||
class Branding
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, std::string> XmlConfig;
|
||||
Branding()
|
||||
{
|
||||
filter.push_back("Application");
|
||||
filter.push_back("WindowTitle");
|
||||
filter.push_back("CopyrightInfo");
|
||||
filter.push_back("MaintainerUrl");
|
||||
filter.push_back("WindowIcon");
|
||||
filter.push_back("ProgramLogo");
|
||||
filter.push_back("ProgramIcons");
|
||||
|
||||
filter.push_back("BuildVersionMajor");
|
||||
filter.push_back("BuildVersionMinor");
|
||||
filter.push_back("BuildRevision");
|
||||
filter.push_back("BuildRevisionDate");
|
||||
|
||||
filter.push_back("SplashScreen");
|
||||
filter.push_back("SplashAlignment");
|
||||
filter.push_back("SplashTextColor");
|
||||
filter.push_back("SplashInfoColor");
|
||||
|
||||
filter.push_back("StartWorkbench");
|
||||
|
||||
filter.push_back("ExeName");
|
||||
filter.push_back("ExeVendor");
|
||||
}
|
||||
|
||||
bool readFile(const QString& fn)
|
||||
{
|
||||
QFile file(fn);
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
return false;
|
||||
if (!evaluateXML(&file, domDocument))
|
||||
return false;
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
XmlConfig getUserDefines() const
|
||||
{
|
||||
XmlConfig cfg;
|
||||
QDomElement root = domDocument.documentElement();
|
||||
QDomElement child;
|
||||
if (!root.isNull()) {
|
||||
child = root.firstChildElement();
|
||||
while (!child.isNull()) {
|
||||
std::string name = (const char*)child.localName().toAscii();
|
||||
std::string value = (const char*)child.text().toUtf8();
|
||||
if (std::find(filter.begin(), filter.end(), name) != filter.end())
|
||||
cfg[name] = value;
|
||||
child = child.nextSiblingElement();
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> filter;
|
||||
bool evaluateXML(QIODevice *device, QDomDocument& xmlDocument)
|
||||
{
|
||||
QString errorStr;
|
||||
int errorLine;
|
||||
int errorColumn;
|
||||
|
||||
if (!xmlDocument.setContent(device, true, &errorStr, &errorLine,
|
||||
&errorColumn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement root = xmlDocument.documentElement();
|
||||
if (root.tagName() != QLatin1String("Branding")) {
|
||||
return false;
|
||||
}
|
||||
else if (root.hasAttribute(QLatin1String("version"))) {
|
||||
QString attr = root.attribute(QLatin1String("version"));
|
||||
if (attr != QLatin1String("1.0"))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
QDomDocument domDocument;
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
void InitMiniDumpWriter(const std::string&);
|
||||
#endif
|
||||
|
@ -252,6 +159,14 @@ int main( int argc, char ** argv )
|
|||
dmpfile += "crash.dmp";
|
||||
InitMiniDumpWriter(dmpfile);
|
||||
#endif
|
||||
std::map<std::string, std::string>::iterator it = App::Application::Config().find("NavigationStyle");
|
||||
if (it != App::Application::Config().end()) {
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
|
||||
// if not already defined do it now (for the very first start)
|
||||
std::string style = hGrp->GetASCII("NavigationStyle", it->second.c_str());
|
||||
hGrp->SetASCII("NavigationStyle", style.c_str());
|
||||
}
|
||||
|
||||
Gui::Application::initApplication();
|
||||
Base::Interpreter().replaceStdOutput();
|
||||
}
|
||||
|
@ -304,17 +219,6 @@ int main( int argc, char ** argv )
|
|||
exit(101);
|
||||
}
|
||||
|
||||
// Now it's time to read-in the file branding.xml if it exists
|
||||
Branding brand;
|
||||
QString path = QString::fromUtf8(App::GetApplication().getHomePath());
|
||||
QFileInfo fi(path, QString::fromAscii("branding.xml"));
|
||||
if (brand.readFile(fi.absoluteFilePath())) {
|
||||
Branding::XmlConfig cfg = brand.getUserDefines();
|
||||
for (Branding::XmlConfig::iterator it = cfg.begin(); it != cfg.end(); ++it) {
|
||||
App::Application::Config()[it->first] = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
// Run phase ===========================================================
|
||||
Base::RedirectStdOutput stdcout;
|
||||
Base::RedirectStdLog stdclog;
|
||||
|
|
Loading…
Reference in New Issue
Block a user