diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp new file mode 100644 index 000000000..246cb54a6 --- /dev/null +++ b/src/libcalamaresui/Branding.cpp @@ -0,0 +1,106 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "Branding.h" + +#include "utils/CalamaresUtils.h" +#include "utils/Logger.h" +#include "utils/YamlUtils.h" + +#include +#include + +#include + + +namespace Calamares +{ + +Branding* Branding::s_instance = nullptr; + +Branding* +Branding::instance() +{ + return s_instance; +} + + +Branding::Branding( const QString& brandingFilePath, + QObject* parent ) + : QObject( parent ) + , m_descriptorPath( brandingFilePath ) +{ + cDebug() << "Using Calamares branding file at" << brandingFilePath; + QFile file( brandingFilePath ); + if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) ) + { + QByteArray ba = file.readAll(); + + try + { + YAML::Node doc = YAML::Load( ba.constData() ); + Q_ASSERT( doc.IsMap() ); + + m_componentName = QString::fromStdString( doc[ "component-name" ] + .as< std::string >() ); + if ( m_componentName != QFileInfo( m_descriptorPath ).absoluteDir().dirName() ) + { + cLog() << "FATAL ERROR in" + << m_descriptorPath + << "\nThe branding component name should match the name of the " + "component directory."; + ::exit( EXIT_FAILURE ); + } + } + catch ( YAML::Exception& e ) + { + cDebug() << "WARNING: YAML parser error " << e.what(); + } + } + else + { + cDebug() << "WARNING: Cannot read " << file.fileName(); + } + + s_instance = this; + cDebug() << "Loaded branding component" << m_componentName; +} + + +QString +Branding::descriptorPath() const +{ + return m_descriptorPath; +} + + +QString +Branding::componentName() const +{ + return m_componentName; +} + + +QString +Branding::componentDirectory() const +{ + QFileInfo fi ( m_descriptorPath ); + return fi.absoluteDir().absolutePath(); +} + +} diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h new file mode 100644 index 000000000..faad18511 --- /dev/null +++ b/src/libcalamaresui/Branding.h @@ -0,0 +1,54 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef BRANDING_H +#define BRANDING_H + +#include "UiDllMacro.h" +#include "Typedefs.h" + +#include + + +namespace Calamares +{ + +class UIDLLEXPORT Branding : public QObject +{ + Q_OBJECT +public: + static Branding* instance(); + + explicit Branding( const QString& brandingFilePath, + QObject *parent = nullptr ); + + QString descriptorPath() const; + QString componentName() const; + QString componentDirectory() const; + + +private: + static Branding* s_instance; + + QString m_descriptorPath; + QString m_componentName; +}; + +} + +#endif // BRANDING_H diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index ed143bc49..a78d52bd8 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -18,6 +18,7 @@ list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES widgets/WaitingWidget.cpp InstallationViewStep.cpp + Branding.cpp Settings.cpp ViewManager.cpp )