diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 8645ae9c1..6a2a35ab0 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -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 +#include "Branding.h" #include #include @@ -107,6 +108,7 @@ #include #include #include +#include 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(); diff --git a/src/App/Branding.cpp b/src/App/Branding.cpp new file mode 100644 index 000000000..4bbe5dc1a --- /dev/null +++ b/src/App/Branding.cpp @@ -0,0 +1,116 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * 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 +#include +#include +#include +#include + +#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; +} diff --git a/src/App/Branding.h b/src/App/Branding.h new file mode 100644 index 000000000..3d4804fda --- /dev/null +++ b/src/App/Branding.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * 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 +#include +#include +#include +#include + +class QIODevice; + +namespace App { + +class Branding +{ +public: + typedef QMap XmlConfig; + Branding(); + + bool readFile(const QString& fn); + XmlConfig getUserDefines() const; + +private: + QVector filter; + bool evaluateXML(QIODevice *device, QDomDocument& xmlDocument); + QDomDocument domDocument; +}; + +} + +#endif // APP_BRANDING_H diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index 9232c187e..c62dd446a 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -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 diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp index 26d96d11c..3a581dc01 100644 --- a/src/Main/MainGui.cpp +++ b/src/Main/MainGui.cpp @@ -46,13 +46,6 @@ #include #include -#include -#include -#include -#include -#include -#include - // FreeCAD header #include #include @@ -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 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 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::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;