mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
Port signal strength indicator to ModemManager
This commit is contained in:
parent
7f79b373ea
commit
89dbff8995
12 changed files with 185 additions and 73 deletions
|
|
@ -39,6 +39,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
|
|||
Service
|
||||
Notifications
|
||||
Wayland
|
||||
ModemManagerQt
|
||||
)
|
||||
find_package(KWinDBusInterface)
|
||||
set_package_properties(KWinDBusInterface PROPERTIES DESCRIPTION "KWin DBus interface"
|
||||
|
|
@ -59,6 +60,7 @@ add_subdirectory(bin)
|
|||
add_subdirectory(applets)
|
||||
add_subdirectory(containments)
|
||||
add_subdirectory(components)
|
||||
add_subdirectory(mmplugin)
|
||||
|
||||
find_program(PlasmaOpenSettings plasma-open-settings)
|
||||
set_package_properties(PlasmaOpenSettings PROPERTIES
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
|
|||
import "providers"
|
||||
|
||||
Item {
|
||||
// we can't use SignalStrengthProvider as the var type as it would import ofono (which may cause it to break if ofono is not installed)
|
||||
required property QtObject provider
|
||||
|
||||
width: strengthIcon.height + strengthLabel.width
|
||||
|
|
|
|||
|
|
@ -8,30 +8,12 @@
|
|||
import QtQuick 2.1
|
||||
import QtQuick.Layouts 1.1
|
||||
|
||||
import MeeGo.QOfono 0.2
|
||||
|
||||
import org.kde.plasma.plasmoid 2.0
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
import org.kde.plasma.mm 1.0
|
||||
|
||||
QtObject {
|
||||
property string icon: netreg.strength == 100 ? "network-mobile-100"
|
||||
: netreg.strength >= 80 ? "network-mobile-80"
|
||||
: netreg.strength >= 60 ? "network-mobile-60"
|
||||
: netreg.strength >= 40 ? "network-mobile-40"
|
||||
: netreg.strength >= 20 ? "network-mobile-20"
|
||||
: "network-mobile-0"
|
||||
|
||||
property string icon: "network-mobile-" + Math.floor(SignalIndicator.strength / 20) * 20
|
||||
|
||||
property string label: simManager.pinRequired !== OfonoSimManager.NoPin ? i18n("Sim locked") : netreg.name
|
||||
|
||||
property OfonoManager ofonoManager: OfonoManager {}
|
||||
|
||||
property OfonoNetworkRegistration netreg: OfonoNetworkRegistration {
|
||||
modemPath: ofonoManager.modems.length ? ofonoManager.modems[0] : ""
|
||||
}
|
||||
|
||||
property OfonoSimManager simManager: OfonoSimManager {
|
||||
modemPath: ofonoManager.modems.length ? ofonoManager.modems[0] : ""
|
||||
}
|
||||
property string label: SignalIndicator.simLocked ? i18n("Sim Locked") : SignalIndicator.name
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,15 @@ PlasmaCore.ColorScope {
|
|||
id: strengthLoader
|
||||
height: parent.height
|
||||
width: item ? item.width : 0
|
||||
source: Qt.resolvedUrl("indicators/SignalStrength.qml")
|
||||
active: signalStrengthProviderLoader.item
|
||||
sourceComponent: Indicators.SignalStrength {
|
||||
provider: signalStrengthProviderLoader.item
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: signalStrengthProviderLoader
|
||||
source: Qt.resolvedUrl("indicators/providers/SignalStrengthProvider.qml")
|
||||
}
|
||||
|
||||
PlasmaComponents.Label {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
|
||||
* SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
|
@ -7,71 +8,34 @@
|
|||
import QtQuick 2.1
|
||||
import QtQuick.Layouts 1.1
|
||||
|
||||
import MeeGo.QOfono 0.2
|
||||
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
|
||||
import "providers"
|
||||
|
||||
Item {
|
||||
required property QtObject provider
|
||||
|
||||
width: strengthIcon.height + strengthLabel.width
|
||||
Layout.minimumWidth: strengthIcon.height + strengthLabel.width
|
||||
OfonoManager {
|
||||
id: ofonoManager
|
||||
}
|
||||
|
||||
OfonoNetworkRegistration {
|
||||
id: netreg
|
||||
Component.onCompleted: {
|
||||
updateStrengthIcon()
|
||||
}
|
||||
|
||||
onNetworkOperatorsChanged : {
|
||||
console.log("operators :"+netreg.currentOperator["Name"].toString())
|
||||
}
|
||||
modemPath: ofonoManager.modems.length ? ofonoManager.modems[0] : ""
|
||||
function updateStrengthIcon() {
|
||||
if (netreg.strength >= 100) {
|
||||
strengthIcon.source = "network-mobile-100";
|
||||
} else if (netreg.strength >= 80) {
|
||||
strengthIcon.source = "network-mobile-80";
|
||||
} else if (netreg.strength >= 60) {
|
||||
strengthIcon.source = "network-mobile-60";
|
||||
} else if (netreg.strength >= 40) {
|
||||
strengthIcon.source = "network-mobile-40";
|
||||
} else if (netreg.strength >= 20) {
|
||||
strengthIcon.source = "network-mobile-20";
|
||||
} else {
|
||||
strengthIcon.source = "network-mobile-0";
|
||||
}
|
||||
}
|
||||
|
||||
onStrengthChanged: {
|
||||
console.log("Strength changed to " + netreg.strength)
|
||||
updateStrengthIcon()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
PlasmaCore.IconItem {
|
||||
id: strengthIcon
|
||||
colorGroup: PlasmaCore.ColorScope.colorGroup
|
||||
anchors {
|
||||
left: parent.left
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: height
|
||||
height: parent.height
|
||||
|
||||
source: provider.icon
|
||||
}
|
||||
|
||||
PlasmaComponents.Label {
|
||||
id: strengthLabel
|
||||
anchors {
|
||||
left: strengthIcon.right
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
text: netreg.name
|
||||
id: label
|
||||
anchors.left: strengthIcon.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
text: provider.label
|
||||
color: PlasmaCore.ColorScope.textColor
|
||||
font.pixelSize: parent.height / 2
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
|
||||
* SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
|
||||
* SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
import QtQuick 2.1
|
||||
|
||||
import org.kde.plasma.mm 1.0
|
||||
|
||||
QtObject {
|
||||
|
||||
property string icon: "network-mobile-" + Math.floor(SignalIndicator.strength / 20) * 20
|
||||
|
||||
property string label: SignalIndicator.simLocked ? i18n("Sim Locked") : SignalIndicator.name
|
||||
}
|
||||
|
||||
16
mmplugin/CMakeLists.txt
Normal file
16
mmplugin/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
add_library(ppc-mmqmlplugin)
|
||||
target_sources(ppc-mmqmlplugin PRIVATE
|
||||
mmqmlplugin.cpp
|
||||
signalindicator.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(ppc-mmqmlplugin
|
||||
Qt5::Qml
|
||||
KF5::ModemManagerQt
|
||||
)
|
||||
|
||||
set_property(TARGET ppc-mmqmlplugin PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/mm)
|
||||
file(COPY qmldir DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/mm)
|
||||
|
||||
install(TARGETS ppc-mmqmlplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/mm)
|
||||
install(FILES qmldir ${qml_SRC} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/mm)
|
||||
16
mmplugin/mmqmlplugin.cpp
Normal file
16
mmplugin/mmqmlplugin.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "mmqmlplugin.h"
|
||||
|
||||
#include <QQmlContext>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "signalindicator.h"
|
||||
|
||||
void MmQmlPlugin::registerTypes(const char *)
|
||||
{
|
||||
qmlRegisterSingletonType<SignalIndicator>("org.kde.plasma.mm", 1, 0, "SignalIndicator", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
||||
return new SignalIndicator();
|
||||
});
|
||||
}
|
||||
14
mmplugin/mmqmlplugin.h
Normal file
14
mmplugin/mmqmlplugin.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class MmQmlPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
void registerTypes(const char *uri) override;
|
||||
};
|
||||
3
mmplugin/qmldir
Normal file
3
mmplugin/qmldir
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module org.kde.plasma.mm
|
||||
plugin ppc-mmqmlplugin
|
||||
classname MmQmlPlugin
|
||||
52
mmplugin/signalindicator.cpp
Normal file
52
mmplugin/signalindicator.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "signalindicator.h"
|
||||
|
||||
SignalIndicator::SignalIndicator()
|
||||
{
|
||||
connect(ModemManager::notifier(), &ModemManager::Notifier::modemAdded, this, &SignalIndicator::updateModem);
|
||||
connect(ModemManager::notifier(), &ModemManager::Notifier::modemRemoved, this, &SignalIndicator::updateModem);
|
||||
updateModem();
|
||||
}
|
||||
|
||||
int SignalIndicator::strength() const
|
||||
{
|
||||
if (!m_modem) {
|
||||
return 0;
|
||||
}
|
||||
return m_modem->signalQuality().signal;
|
||||
}
|
||||
|
||||
QString SignalIndicator::name() const
|
||||
{
|
||||
return m_3gppModem ? m_3gppModem->operatorName() : QString();
|
||||
}
|
||||
|
||||
bool SignalIndicator::simLocked() const
|
||||
{
|
||||
if (!m_modem) {
|
||||
return true;
|
||||
}
|
||||
return !(m_modem->unlockRequired() == MM_MODEM_LOCK_NONE || m_modem->unlockRequired() == MM_MODEM_LOCK_SIM_PIN2);
|
||||
}
|
||||
|
||||
bool SignalIndicator::available() const
|
||||
{
|
||||
return !ModemManager::modemDevices().isEmpty();
|
||||
}
|
||||
|
||||
void SignalIndicator::updateModem()
|
||||
{
|
||||
if (!available()) {
|
||||
qWarning() << "No modems available";
|
||||
return;
|
||||
}
|
||||
m_modem = ModemManager::modemDevices()[0]->modemInterface();
|
||||
m_3gppModem = ModemManager::modemDevices()[0]->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();
|
||||
Q_EMIT nameChanged();
|
||||
connect(m_modem.get(), &ModemManager::Modem::signalQualityChanged, this, &SignalIndicator::strengthChanged);
|
||||
connect(m_3gppModem.get(), &ModemManager::Modem3gpp::operatorNameChanged, this, &SignalIndicator::nameChanged);
|
||||
connect(m_modem.get(), &ModemManager::Modem::unlockRequiredChanged, this, &SignalIndicator::simLockedChanged);
|
||||
Q_EMIT availableChanged();
|
||||
}
|
||||
37
mmplugin/signalindicator.h
Normal file
37
mmplugin/signalindicator.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ModemManagerQt/Manager>
|
||||
#include <ModemManagerQt/modem3gpp.h>
|
||||
#include <QObject>
|
||||
|
||||
class SignalIndicator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int strength READ strength NOTIFY strengthChanged)
|
||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||
Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
|
||||
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
|
||||
|
||||
public:
|
||||
SignalIndicator();
|
||||
|
||||
int strength() const;
|
||||
QString name() const;
|
||||
bool simLocked() const;
|
||||
bool available() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void strengthChanged();
|
||||
void nameChanged();
|
||||
void simLockedChanged();
|
||||
void availableChanged();
|
||||
|
||||
private:
|
||||
ModemManager::Modem::Ptr m_modem;
|
||||
ModemManager::Modem3gpp::Ptr m_3gppModem;
|
||||
void updateModem();
|
||||
};
|
||||
Loading…
Reference in a new issue