[welcomeq] initial work for welcomeview in qml

This commit is contained in:
Camilo Higuita 2020-03-10 17:56:09 -05:00 committed by Adriaan de Groot
parent d7f7c16958
commit d26fa63ccd
7 changed files with 201 additions and 245 deletions

View File

@ -187,7 +187,7 @@ Config::setCountryCode( const QString& countryCode )
} }
void void
Config::setLanguageIcon( const QString languageIcon ) Config::setLanguageIcon(const QString &languageIcon )
{ {
m_languageIcon = languageIcon; m_languageIcon = languageIcon;
} }

View File

@ -101,13 +101,15 @@ class Config : public QObject
Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL ) Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL )
Q_PROPERTY( QString warningMessage MEMBER m_warningMessage CONSTANT FINAL ) Q_PROPERTY( QString warningMessage MEMBER m_warningMessage CONSTANT FINAL )
Q_PROPERTY( bool isNextEnabled MEMBER m_isNextEnabled NOTIFY isNextEnabledChanged FINAL ) Q_PROPERTY(QString supportUrl MEMBER m_supportUrl CONSTANT FINAL)
Q_PROPERTY(QString knownIssuesUrl MEMBER m_knownIssuesUrl CONSTANT FINAL)
Q_PROPERTY(QString releaseNotesUrl MEMBER m_releaseNotesUrl CONSTANT FINAL)
Q_PROPERTY(QString donateUrl MEMBER m_donateUrl CONSTANT FINAL)
public: public:
Config( QObject* parent = nullptr ); Config( QObject* parent = nullptr );
void setCountryCode( const QString &countryCode ); void setCountryCode( const QString &countryCode );
void setLanguageIcon( const QString languageIcon ); void setLanguageIcon( const QString &languageIcon );
RequirementsModel& requirementsModel () const; RequirementsModel& requirementsModel () const;
void setIsNextEnabled( const bool& isNextEnabled ); void setIsNextEnabled( const bool& isNextEnabled );
@ -151,7 +153,6 @@ private:
QString m_releaseNotesUrl; QString m_releaseNotesUrl;
QString m_donateUrl; QString m_donateUrl;
signals: signals:
void countryCodeChanged( QString countryCode ); void countryCodeChanged( QString countryCode );
void localeIndexChanged( int localeIndex ); void localeIndexChanged( int localeIndex );

View File

@ -1,44 +1,51 @@
# This is a re-write of the welcome module using QML view steps # This is a re-write of the welcome module using QML view steps
# instead of widgets. # instead of widgets.
#set( _welcome ${CMAKE_CURRENT_SOURCE_DIR}/../welcome ) set( _welcome ${CMAKE_CURRENT_SOURCE_DIR}/../welcome )
#include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${_welcome} ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${CMAKE_CURRENT_SOURCE_DIR}/../../libcalamares ${_welcome} )
## DUPLICATED WITH WELCOME MODULE # DUPLICATED WITH WELCOME MODULE
#find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus Network ) find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus Network )
#find_package( LIBPARTED ) find_package( LIBPARTED )
#if ( LIBPARTED_FOUND ) if ( LIBPARTED_FOUND )
# set( PARTMAN_SRC ${_welcome}/checker/partman_devices.c ) set( PARTMAN_SRC ${_welcome}/checker/partman_devices.c )
# set( CHECKER_LINK_LIBRARIES ${LIBPARTED_LIBRARY} ) set( CHECKER_LINK_LIBRARIES ${LIBPARTED_LIBRARY} )
#else() else()
# set( PARTMAN_SRC ) set( PARTMAN_SRC )
# set( CHECKER_LINK_LIBRARIES ) set( CHECKER_LINK_LIBRARIES )
# add_definitions( -DWITHOUT_LIBPARTED ) add_definitions( -DWITHOUT_LIBPARTED )
#endif() endif()
#set( CHECKER_SOURCES set( CHECKER_SOURCES
# ${_welcome}/checker/CheckerContainer.cpp ${_welcome}/checker/GeneralRequirements.cpp
# ${_welcome}/checker/GeneralRequirements.cpp ${PARTMAN_SRC}
# ${_welcome}/checker/ResultWidget.cpp )
# ${_welcome}/checker/ResultsListWidget.cpp
# ${PARTMAN_SRC}
#)
#calamares_add_plugin( welcomeq calamares_add_plugin( welcomeq
# TYPE viewmodule TYPE viewmodule
# EXPORT_MACRO PLUGINDLLEXPORT_PRO EXPORT_MACRO PLUGINDLLEXPORT_PRO
# SOURCES SOURCES
# ${CHECKER_SOURCES} ${CHECKER_SOURCES}
# WelcomeQmlViewStep.cpp WelcomeQmlViewStep.cpp
# Config.cpp ${_welcome}/Config.cpp
# RESOURCES RESOURCES
# welcomeq.qrc welcomeq.qrc
# LINK_PRIVATE_LIBRARIES LINK_PRIVATE_LIBRARIES
# calamaresui calamaresui
# ${CHECKER_LINK_LIBRARIES} ${CHECKER_LINK_LIBRARIES}
# Qt5::DBus Qt5::DBus
# Qt5::Network Qt5::Network
# SHARED_LIB SHARED_LIB
#) )
# add_executable( welcomeqmltest qmlmain.cpp Config.cpp WelcomeQmlViewStep.cpp ${CHECKER_SOURCES} )
# target_link_libraries( welcomeqmltest PRIVATE calamaresui Qt5::Core Qt5::Network Qt5::DBus ${CHECKER_LINK_LIBRARIES})
# set_target_properties( welcomeqmltest
# PROPERTIES
# ENABLE_EXPORTS TRUE
# RUNTIME_OUTPUT_NAME welcomeqmltest
# )
# calamares_automoc( welcomeqmltest )
# calamares_autouic( welcomeqmltest )

View File

@ -1,23 +0,0 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "Config.h"
Config::Config() {}
Config::~Config() {}

View File

@ -1,51 +0,0 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WELCOMEQ_CONFIG_H
#define WELCOMEQ_CONFIG_H
#include <QObject>
#include <QUrl>
class Config : public QObject
{
Q_OBJECT
Q_PROPERTY( QUrl helpUrl READ helpUrl CONSTANT FINAL )
Q_PROPERTY( QUrl issuesUrl READ issuesUrl CONSTANT FINAL )
Q_PROPERTY( QUrl notesUrl READ notesUrl CONSTANT FINAL )
Q_PROPERTY( QUrl donateUrl READ donateUrl CONSTANT FINAL )
public:
Config();
virtual ~Config();
void setHelpUrl( const QUrl& url ) { m_helpUrl = url; }
void setIssuesUrl( const QUrl& url ) { m_issuesUrl = url; }
void setNotesUrl( const QUrl& url ) { m_notesUrl = url; }
void setDonateUrl( const QUrl& url ) { m_donateUrl = url; }
public slots:
QUrl helpUrl() const { return m_helpUrl; }
QUrl issuesUrl() const { return m_issuesUrl; }
QUrl notesUrl() const { return m_notesUrl; }
QUrl donateUrl() const { return m_donateUrl; }
private:
QUrl m_helpUrl, m_issuesUrl, m_notesUrl, m_donateUrl;
};
#endif

View File

@ -26,9 +26,12 @@
#include "locale/Lookup.h" #include "locale/Lookup.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h" #include "utils/Variant.h"
#include "utils/Dirs.h"
#include "Branding.h" #include "Branding.h"
#include "modulesystem/ModuleManager.h" #include "modulesystem/ModuleManager.h"
#include <QQmlEngine>
#include "utils/Yaml.h"
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QPixmap> #include <QPixmap>
@ -37,54 +40,64 @@
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep >(); ) CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep >(); )
WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent ) WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent )
: Calamares::QmlViewStep( QStringLiteral( "welcomeq" ), parent ) : Calamares::QmlViewStep("welcome", parent )
, m_config( new Config( ) ) // the qml singleton takes ownership and deletes it
// , m_nextEnabled( false )
, m_requirementsChecker( new GeneralRequirements( this ) ) , m_requirementsChecker( new GeneralRequirements( this ) )
{ {
connect( Calamares::ModuleManager::instance(), // connect( m_config,
&Calamares::ModuleManager::requirementsComplete, // &Config::isNextEnabledChanged,
this, // this,
&WelcomeQmlViewStep::nextStatusChanged ); // &WelcomeQmlViewStep::nextStatusChanged );
// emit nextStatusChanged(true);
qmlRegisterSingletonType< Config >( "io.calamares.module", 1, 0, "Welcome", [&](QQmlEngine*, QJSEngine*) -> QObject* { return m_config; } );
qmlRegisterSingletonType< Calamares::Branding >( "io.calamares.ui", 1, 0, "Branding", [](QQmlEngine*, QJSEngine*) -> QObject* { return Calamares::Branding::instance(); } );
} }
WelcomeQmlViewStep::~WelcomeQmlViewStep() {}
QString QString
WelcomeQmlViewStep::prettyName() const WelcomeQmlViewStep::prettyName() const
{ {
return tr( "Welcome" ); return tr( "Welcome" );
} }
/** @brief Look up a URL for a button bool
* WelcomeQmlViewStep::isNextEnabled() const
* Looks up @p key in @p map; if it is a *boolean* value, then
* assume an old-style configuration, and fetch the string from
* the branding settings @p e. If it is a string, not a boolean,
* use it as-is. If not found, or a weird type, returns empty.
*
* This allows switching the showKnownIssuesUrl and similar settings
* in welcome.conf from a boolean (deferring to branding) to an
* actual string for immediate use. Empty strings, as well as
* "false" as a setting, will hide the buttons as before.
*/
static QString
jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key )
{ {
if ( !map.contains( key ) ) // TODO: should return true
{ // return m_config->property("isNextEnabled").toBool();
return QString(); return true;
} }
auto v = map.value( key );
if ( v.type() == QVariant::Bool )
{
return v.toBool() ? ( *e ) : QString();
}
if ( v.type() == QVariant::String )
{
return v.toString();
}
return QString(); bool
WelcomeQmlViewStep::isBackEnabled() const
{
// TODO: should return true (it's weird that you are not allowed to have welcome *after* anything
return false;
}
bool
WelcomeQmlViewStep::isAtBeginning() const
{
// TODO: adjust to "pages" in the QML
return true;
}
bool
WelcomeQmlViewStep::isAtEnd() const
{
// TODO: adjust to "pages" in the QML
return true;
}
Calamares::JobList
WelcomeQmlViewStep::jobs() const
{
return Calamares::JobList();
} }
void void
@ -92,17 +105,16 @@ WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{ {
using Calamares::Branding; using Calamares::Branding;
m_config.setHelpUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); // TODO: expand Config class and set the remaining fields // with the configurationMap all those properties can be accesed withouth having to declare a property, get and setter for each
m_config.setIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
m_config.setNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
m_config.setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) );
// TODO: figure out how the requirements (held by ModuleManager) should be accessible // TODO: figure out how the requirements (held by ModuleManager) should be accessible
// to QML as a odel. // to QML as a odel. //will be model as a qvariantmap containing a alert level and the message string
if ( configurationMap.contains( "requirements" ) if ( configurationMap.contains( "requirements" )
&& configurationMap.value( "requirements" ).type() == QVariant::Map ) && configurationMap.value( "requirements" ).type() == QVariant::Map )
{ {
m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() ); m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() );
m_config->requirementsModel().setRequirementsList( checkRequirements() );
} }
else else
cWarning() << "no valid requirements map found in welcome " cWarning() << "no valid requirements map found in welcome "
@ -142,11 +154,11 @@ WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) );
if ( !icon.isNull() ) if ( !icon.isNull() )
{ {
// TODO: figure out where to set this: Config? m_config->setLanguageIcon(language);
} }
} }
QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last
} }
Calamares::RequirementsList Calamares::RequirementsList
@ -155,6 +167,12 @@ WelcomeQmlViewStep::checkRequirements()
return m_requirementsChecker->checkRequirements(); return m_requirementsChecker->checkRequirements();
} }
Config*
WelcomeQmlViewStep::config() const
{
return m_config;
}
static inline void static inline void
logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler )
{ {
@ -192,12 +210,7 @@ WelcomeQmlViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoI
if ( ( r >= 0 ) ) if ( ( r >= 0 ) )
{ {
// TODO: update Config to point to selected language // TODO: update Config to point to selected language
m_config->setCountryCode( countryCode );
} }
} }
} }
QObject*
WelcomeQmlViewStep::getConfig()
{
return &m_config;
}

View File

@ -21,11 +21,12 @@
#include "Config.h" #include "Config.h"
#include "DllMacro.h"
#include "modulesystem/Requirement.h" #include "modulesystem/Requirement.h"
#include "utils/PluginFactory.h" #include "utils/PluginFactory.h"
#include "viewpages/QmlViewStep.h" #include "viewpages/QmlViewStep.h"
#include <DllMacro.h>
#include <QObject> #include <QObject>
#include <QVariantMap> #include <QVariantMap>
@ -39,16 +40,26 @@ class Handler;
class GeneralRequirements; class GeneralRequirements;
// TODO: Needs a generic Calamares::QmlViewStep as base class
// TODO: refactor and move what makes sense to base class
class PLUGINDLLEXPORT WelcomeQmlViewStep : public Calamares::QmlViewStep class PLUGINDLLEXPORT WelcomeQmlViewStep : public Calamares::QmlViewStep
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WelcomeQmlViewStep( QObject* parent = nullptr ); explicit WelcomeQmlViewStep( QObject* parent = nullptr );
virtual ~WelcomeQmlViewStep() override;
QString prettyName() const override; QString prettyName() const override;
bool isNextEnabled() const override;
bool isBackEnabled() const override;
bool isAtBeginning() const override;
bool isAtEnd() const override;
Calamares::JobList jobs() const override;
void setConfigurationMap( const QVariantMap& configurationMap ) override; void setConfigurationMap( const QVariantMap& configurationMap ) override;
/** @brief Sets the country that Calamares is running in. /** @brief Sets the country that Calamares is running in.
@ -60,13 +71,11 @@ public:
void setCountry( const QString&, CalamaresUtils::GeoIP::Handler* handler ); void setCountry( const QString&, CalamaresUtils::GeoIP::Handler* handler );
Calamares::RequirementsList checkRequirements() override; Calamares::RequirementsList checkRequirements() override;
Config* config() const;
protected:
QObject* getConfig() override;
private: private:
// TODO: a generic QML viewstep should return a config object from a method // TODO: a generic QML viewstep should return a config object from a method
Config m_config; Config *m_config;
GeneralRequirements* m_requirementsChecker; GeneralRequirements* m_requirementsChecker;
}; };