[libcalamares] Export network status as Q_PROPERTY and to QML
This commit is contained in:
parent
51e743a67f
commit
36fb1124be
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
@ -168,7 +168,11 @@ Manager::checkHasInternet()
|
||||
{
|
||||
hasInternet = synchronousPing( d->m_hasInternetUrl );
|
||||
}
|
||||
d->m_hasInternet = hasInternet;
|
||||
if ( hasInternet != d->m_hasInternet )
|
||||
{
|
||||
d->m_hasInternet = hasInternet;
|
||||
emit hasInternetChanged( hasInternet );
|
||||
}
|
||||
return hasInternet;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
@ -98,9 +98,10 @@ struct RequestStatus
|
||||
|
||||
QDebug& operator<<( QDebug& s, const RequestStatus& e );
|
||||
|
||||
class DLLEXPORT Manager : QObject
|
||||
class DLLEXPORT Manager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( bool hasInternet READ hasInternet NOTIFY hasInternetChanged FINAL )
|
||||
|
||||
Manager();
|
||||
|
||||
@ -133,6 +134,16 @@ public:
|
||||
|
||||
/// @brief Set the URL which is used for the general "is there internet" check.
|
||||
void setCheckHasInternetUrl( const QUrl& url );
|
||||
|
||||
/** @brief Do a network request asynchronously.
|
||||
*
|
||||
* Returns a pointer to the reply-from-the-request.
|
||||
* This may be a nullptr if an error occurs immediately.
|
||||
* The caller is responsible for cleaning up the reply (eventually).
|
||||
*/
|
||||
QNetworkReply* asynchronousGet( const QUrl& url, const RequestOptions& options = RequestOptions() );
|
||||
|
||||
public Q_SLOTS:
|
||||
/** @brief Do an explicit check for internet connectivity.
|
||||
*
|
||||
* This **may** do a ping to the configured check URL, but can also
|
||||
@ -148,13 +159,13 @@ public:
|
||||
*/
|
||||
bool hasInternet();
|
||||
|
||||
/** @brief Do a network request asynchronously.
|
||||
signals:
|
||||
/** @brief Indicates that internet connectivity status has changed
|
||||
*
|
||||
* Returns a pointer to the reply-from-the-request.
|
||||
* This may be a nullptr if an error occurs immediately.
|
||||
* The caller is responsible for cleaning up the reply (eventually).
|
||||
* The value is that returned from hasInternet() -- @c true when there
|
||||
* is connectivity, @c false otherwise.
|
||||
*/
|
||||
QNetworkReply* asynchronousGet( const QUrl& url, const RequestOptions& options = RequestOptions() );
|
||||
void hasInternetChanged( bool );
|
||||
|
||||
private:
|
||||
class Private;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "JobQueue.h"
|
||||
#include "Settings.h"
|
||||
#include "ViewManager.h"
|
||||
#include "network/Manager.h"
|
||||
#include "utils/Dirs.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
@ -242,6 +243,10 @@ registerQmlModels()
|
||||
"io.calamares.core", 1, 0, "Global", []( QQmlEngine*, QJSEngine* ) -> QObject* {
|
||||
return Calamares::JobQueue::instance()->globalStorage();
|
||||
} );
|
||||
qmlRegisterSingletonType< CalamaresUtils::Network::Manager >(
|
||||
"io.calamares.core", 1, 0, "Network", []( QQmlEngine*, QJSEngine* ) -> QObject* {
|
||||
return &CalamaresUtils::Network::Manager::instance();
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user