2019-04-29 11:36:04 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2020-06-17 15:02:01 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2013-2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2018 Adriaan de Groot <groot@kde.org>
|
2019-04-29 11:36:04 +02:00
|
|
|
*
|
|
|
|
* Originally from Tomahawk, portions:
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2010-2011 Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
|
|
|
* SPDX-FileCopyrightText: 2010-2011 Leo Franchi <lfranchi@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2010-2012 Jeff Mitchell <jeff@tomahawk-player.org>
|
2019-04-29 11:36:04 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
* License-Filename: LICENSE
|
|
|
|
*
|
2019-04-29 11:36:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Variant.h"
|
|
|
|
|
|
|
|
#include "Logger.h"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
getBool( const QVariantMap& map, const QString& key, bool d )
|
|
|
|
{
|
|
|
|
bool result = d;
|
|
|
|
if ( map.contains( key ) )
|
|
|
|
{
|
|
|
|
auto v = map.value( key );
|
|
|
|
if ( v.type() == QVariant::Bool )
|
2019-08-04 21:22:54 +02:00
|
|
|
{
|
2019-04-29 11:36:04 +02:00
|
|
|
result = v.toBool();
|
2019-08-04 21:22:54 +02:00
|
|
|
}
|
2019-04-29 11:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
2019-08-04 21:22:54 +02:00
|
|
|
getString( const QVariantMap& map, const QString& key )
|
2019-04-29 11:36:04 +02:00
|
|
|
{
|
|
|
|
if ( map.contains( key ) )
|
|
|
|
{
|
|
|
|
auto v = map.value( key );
|
|
|
|
if ( v.type() == QVariant::String )
|
2019-08-04 21:22:54 +02:00
|
|
|
{
|
2019-04-29 11:36:04 +02:00
|
|
|
return v.toString();
|
2019-08-04 21:22:54 +02:00
|
|
|
}
|
2019-04-29 11:36:04 +02:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2020-06-17 15:02:01 +02:00
|
|
|
QStringList
|
|
|
|
getStringList( const QVariantMap& map, const QString& key )
|
|
|
|
{
|
|
|
|
if ( map.contains( key ) )
|
|
|
|
{
|
|
|
|
auto v = map.value( key );
|
|
|
|
if ( v.type() == QVariant::StringList )
|
|
|
|
{
|
|
|
|
return v.toStringList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2019-07-22 15:56:20 +02:00
|
|
|
qint64
|
|
|
|
getInteger( const QVariantMap& map, const QString& key, qint64 d )
|
2019-04-29 11:36:04 +02:00
|
|
|
{
|
2019-07-22 15:56:20 +02:00
|
|
|
qint64 result = d;
|
2019-04-29 11:36:04 +02:00
|
|
|
if ( map.contains( key ) )
|
|
|
|
{
|
|
|
|
auto v = map.value( key );
|
2020-06-15 16:16:13 +02:00
|
|
|
result = v.toString().toLongLong(nullptr, 0);
|
2019-04-29 11:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-03-21 19:21:16 +01:00
|
|
|
quint64
|
|
|
|
getUnsignedInteger( const QVariantMap& map, const QString& key, quint64 u )
|
|
|
|
{
|
|
|
|
quint64 result = u;
|
|
|
|
if ( map.contains( key ) )
|
|
|
|
{
|
|
|
|
auto v = map.value( key );
|
|
|
|
result = v.toString().toULongLong(nullptr, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-04-29 11:36:04 +02:00
|
|
|
double
|
|
|
|
getDouble( const QVariantMap& map, const QString& key, double d )
|
|
|
|
{
|
|
|
|
double result = d;
|
|
|
|
if ( map.contains( key ) )
|
|
|
|
{
|
|
|
|
auto v = map.value( key );
|
|
|
|
if ( v.type() == QVariant::Int )
|
2019-08-04 21:22:54 +02:00
|
|
|
{
|
2019-04-29 11:36:04 +02:00
|
|
|
result = v.toInt();
|
2019-08-04 21:22:54 +02:00
|
|
|
}
|
2019-04-29 11:36:04 +02:00
|
|
|
else if ( v.type() == QVariant::Double )
|
2019-08-04 21:22:54 +02:00
|
|
|
{
|
2019-04-29 11:36:04 +02:00
|
|
|
result = v.toDouble();
|
2019-08-04 21:22:54 +02:00
|
|
|
}
|
2019-04-29 11:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap
|
|
|
|
getSubMap( const QVariantMap& map, const QString& key, bool& success )
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
if ( map.contains( key ) )
|
|
|
|
{
|
|
|
|
auto v = map.value( key );
|
|
|
|
if ( v.type() == QVariant::Map )
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
return v.toMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariantMap();
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
} // namespace CalamaresUtils
|