Commit 4efbe8a9 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Move live image check from Handler to UiUtils

Makes it easier to reuse.
parent 6e88bd78
......@@ -31,6 +31,8 @@
#include <QString>
#include <optional>
using namespace NetworkManager;
UiUtils::SortedConnectionType UiUtils::connectionTypeToSortedType(NetworkManager::ConnectionSettings::ConnectionType type)
......@@ -675,3 +677,29 @@ QString UiUtils::formatLastUsedDateRelative(const QDateTime &lastUsed)
}
return lastUsedText;
}
bool UiUtils::isLiveImage()
{
static std::optional<bool> liveImage = std::nullopt;
if (liveImage.has_value()) {
return liveImage.value();
}
QFile cmdFile(QStringLiteral("/proc/cmdline"));
cmdFile.open(QIODevice::ReadOnly);
if (!cmdFile.isOpen()) {
return false;
}
const QString cmdFileOutput = cmdFile.readAll();
cmdFile.close();
if (cmdFileOutput.contains(QStringLiteral("rd.live.image"))) {
liveImage = true;
return true;
}
liveImage = false;
return false;
}
......@@ -116,6 +116,11 @@ public:
*/
static QString wirelessFrequencyToString(uint frequency);
/**
* Check whether we're running in a live image session.
*/
static bool isLiveImage();
#if WITH_MODEMMANAGER_SUPPORT
static QString convertAllowedModeToString(ModemManager::Modem::ModemModes mode);
static QString convertAccessTechnologyToString(ModemManager::Modem::AccessTechnologies tech);
......
......@@ -70,7 +70,7 @@ Handler::Handler(QObject *parent)
}
m_hotspotSupported = checkHotspotSupported();
m_runningLiveImage = checkRunningLiveImage();
m_runningLiveImage = UiUtils::isLiveImage();
if (NetworkManager::checkVersion(1, 16, 0)) {
connect(NetworkManager::notifier(), &NetworkManager::Notifier::primaryConnectionTypeChanged, this, &Handler::primaryConnectionTypeChanged);
......@@ -704,25 +704,6 @@ bool Handler::checkHotspotSupported()
return false;
}
bool Handler::checkRunningLiveImage()
{
QFile cmdFile(QStringLiteral("/proc/cmdline"));
cmdFile.open(QIODevice::ReadOnly);
if (!cmdFile.isOpen()) {
return false;
}
const QString cmdFileOutput = cmdFile.readAll();
cmdFile.close();
if (cmdFileOutput.contains(QStringLiteral("rd.live.image"))) {
return true;
}
return false;
}
void Handler::scheduleRequestScan(const QString &interface, int timeout)
{
QTimer *timer;
......
......@@ -148,7 +148,6 @@ private:
void scanRequestFailed(const QString &interface);
bool checkRequestScanRateLimit(const NetworkManager::WirelessDevice::Ptr &wifiDevice);
bool checkHotspotSupported();
bool checkRunningLiveImage();
void scheduleRequestScan(const QString &interface, int timeout);
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment