mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 19:05:46 -05:00
[finished] Start Config-ification
- Introduce a Config class with suitable properties for use in QML, read configuration; this is unused right now.
This commit is contained in:
parent
b8a9c4c3b7
commit
4ae3a7af61
3 changed files with 138 additions and 0 deletions
|
@ -11,6 +11,7 @@ calamares_add_plugin( finished
|
|||
TYPE viewmodule
|
||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
SOURCES
|
||||
Config.cpp
|
||||
FinishedViewStep.cpp
|
||||
FinishedPage.cpp
|
||||
UI
|
||||
|
|
84
src/modules/finished/Config.cpp
Normal file
84
src/modules/finished/Config.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
const NamedEnumTable< Config::RestartMode >&
|
||||
restartModes()
|
||||
{
|
||||
using M = Config::RestartMode;
|
||||
static const NamedEnumTable< M > table { { "never", M::Never },
|
||||
{ "user-unchecked", M::UserDefaultUnchecked },
|
||||
{ "unchecked", M::UserDefaultUnchecked },
|
||||
{ "user-checked", M::UserDefaultChecked },
|
||||
{ "checked", M::UserDefaultChecked },
|
||||
{ "always", M::Always }
|
||||
|
||||
};
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
Config::Config( QObject* parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
RestartMode mode = RestartMode::Never;
|
||||
|
||||
QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" );
|
||||
if ( restartMode.isEmpty() )
|
||||
{
|
||||
if ( configurationMap.contains( "restartNowEnabled" ) )
|
||||
{
|
||||
cWarning() << "Configuring the finished module with deprecated restartNowEnabled settings";
|
||||
}
|
||||
|
||||
bool restartNowEnabled = CalamaresUtils::getBool( configurationMap, "restartNowEnabled", false );
|
||||
bool restartNowChecked = CalamaresUtils::getBool( configurationMap, "restartNowChecked", false );
|
||||
|
||||
if ( !restartNowEnabled )
|
||||
{
|
||||
mode = RestartMode::Never;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = restartNowChecked ? RestartMode::UserDefaultChecked : RestartMode::UserDefaultUnchecked;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool ok = false;
|
||||
mode = restartModes().find( restartMode, ok );
|
||||
if ( !ok )
|
||||
{
|
||||
cWarning() << "Configuring the finished module with bad restartNowMode" << restartMode;
|
||||
}
|
||||
}
|
||||
|
||||
m_restartNowMode = mode;
|
||||
|
||||
if ( mode != RestartMode::Never )
|
||||
{
|
||||
QString restartNowCommand = CalamaresUtils::getString( configurationMap, "restartNowCommand" );
|
||||
if ( restartNowCommand.isEmpty() )
|
||||
{
|
||||
restartNowCommand = QStringLiteral( "shutdown -r now" );
|
||||
}
|
||||
m_restartNowCommand = restartNowCommand;
|
||||
}
|
||||
|
||||
m_notifyOnFinished = CalamaresUtils::getBool( configurationMap, "notifyOnFinished", false );
|
||||
}
|
53
src/modules/finished/Config.h
Normal file
53
src/modules/finished/Config.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FINISHED_CONFIG_H
|
||||
#define FINISHED_CONFIG_H
|
||||
|
||||
#include "utils/NamedEnum.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Config : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QString restartNowCommand READ restartNowCommand CONSTANT FINAL )
|
||||
Q_PROPERTY( RestartMode restartNowMode READ restartNowMode CONSTANT FINAL )
|
||||
Q_PROPERTY( bool notifyOnFinished READ notifyOnFinished CONSTANT FINAL )
|
||||
|
||||
public:
|
||||
Config( QObject* parent = nullptr );
|
||||
|
||||
enum class RestartMode
|
||||
{
|
||||
Never,
|
||||
UserDefaultUnchecked,
|
||||
UserDefaultChecked,
|
||||
Always
|
||||
};
|
||||
Q_ENUM( RestartMode )
|
||||
|
||||
QString restartNowCommand() const { return m_restartNowCommand; }
|
||||
RestartMode restartNowMode() const { return m_restartNowMode; }
|
||||
bool notifyOnFinished() const { return m_notifyOnFinished; }
|
||||
|
||||
void setConfigurationMap( const QVariantMap& configurationMap );
|
||||
|
||||
private:
|
||||
QString m_restartNowCommand;
|
||||
RestartMode m_restartNowMode = RestartMode::Never;
|
||||
bool m_notifyOnFinished = false;
|
||||
};
|
||||
|
||||
const NamedEnumTable< Config::RestartMode >& restartModes();
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue