indicator: add connectivity action
This commit is contained in:
parent
94d4a9c1c2
commit
fe3d79ccbc
5 changed files with 89 additions and 0 deletions
|
@ -14,6 +14,7 @@ set(indicator_SRCS
|
|||
deviceindicator.cpp
|
||||
${kdeconnect_custom_icons_SRCS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/systray_actions/battery_action.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/systray_actions/connectivity_action.cpp
|
||||
)
|
||||
|
||||
include(ECMAddAppIcon)
|
||||
|
|
|
@ -30,6 +30,12 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface* device)
|
|||
[battery](bool available) { battery->setVisible(available); }
|
||||
, this);
|
||||
|
||||
auto connectivity = new ConnectivityAction(device);
|
||||
addAction(connectivity);
|
||||
setWhenAvailable(device->hasPlugin(QStringLiteral("kdeconnect_connectivity_report")),
|
||||
[connectivity](bool available) { connectivity->setVisible(available); }
|
||||
, this);
|
||||
|
||||
// Browse device filesystem
|
||||
auto browse = addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Browse device"));
|
||||
connect(browse, &QAction::triggered, device, [device](){
|
||||
|
|
46
indicator/systray_actions/connectivity_action.cpp
Normal file
46
indicator/systray_actions/connectivity_action.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||
* SPDX-FileCopyrightText: 2020 Piyush Aggarwal <piyushaggarwal002@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#include "connectivity_action.h"
|
||||
|
||||
ConnectivityAction::ConnectivityAction(DeviceDbusInterface* device)
|
||||
: QAction(nullptr)
|
||||
, m_connectivityiface(device->id())
|
||||
{
|
||||
setCellularNetworkStrength(m_connectivityiface.cellularNetworkStrength());
|
||||
setCellularNetworkType(m_connectivityiface.cellularNetworkType());
|
||||
|
||||
connect(&m_connectivityiface, &ConnectivityReportDbusInterface::refreshedProxy, this, [this]{
|
||||
setCellularNetworkStrength(m_connectivityiface.cellularNetworkStrength());
|
||||
setCellularNetworkType(m_connectivityiface.cellularNetworkType());
|
||||
});
|
||||
|
||||
setIcon(QIcon::fromTheme(QStringLiteral("network-wireless")));
|
||||
|
||||
ConnectivityAction::update();
|
||||
}
|
||||
|
||||
void ConnectivityAction::update()
|
||||
{
|
||||
if (m_cellularNetworkStrength < 0) {
|
||||
setText(i18nc("The fallback text to display in case the remote device does not have a cellular connection", "No Cellular Connectivity"));
|
||||
} else {
|
||||
setText(i18nc("Display the cellular connection type and an approximate percentage of signal strength","%1 | ~%2%", m_cellularNetworkType, m_cellularNetworkStrength * 25));
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectivityAction::setCellularNetworkStrength(int cellularNetworkStrength)
|
||||
{
|
||||
m_cellularNetworkStrength = cellularNetworkStrength;
|
||||
update();
|
||||
}
|
||||
|
||||
void ConnectivityAction::setCellularNetworkType(QString cellularNetworkType)
|
||||
{
|
||||
m_cellularNetworkType = cellularNetworkType;
|
||||
update();
|
||||
}
|
35
indicator/systray_actions/connectivity_action.h
Normal file
35
indicator/systray_actions/connectivity_action.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||
* SPDX-FileCopyrightText: 2020 Piyush Aggarwal <piyushaggarwal002@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#ifndef CONNECTIVITYACTION_H
|
||||
#define CONNECTIVITYACTION_H
|
||||
|
||||
#include <QMenu>
|
||||
#include <QFileDialog>
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include "interfaces/dbusinterfaces.h"
|
||||
|
||||
#include <dbushelper.h>
|
||||
|
||||
class ConnectivityAction : public QAction
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ConnectivityAction(DeviceDbusInterface* device);
|
||||
void update();
|
||||
private Q_SLOTS:
|
||||
void setCellularNetworkStrength(int cellularNetworkStrength);
|
||||
void setCellularNetworkType(QString cellularNetworkType);
|
||||
|
||||
private:
|
||||
ConnectivityReportDbusInterface m_connectivityiface;
|
||||
QString m_cellularNetworkType;
|
||||
int m_cellularNetworkStrength = -1;
|
||||
};
|
||||
|
||||
#endif // CONNECTIVITYACTION_H
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef SYSTRAY_ACTIONS_H
|
||||
#define SYSTRAY_ACTIONS_H
|
||||
#include <battery_action.h>
|
||||
#include <connectivity_action.h>
|
||||
#endif // SYSTRAY_ACTIONS_H
|
||||
|
|
Loading…
Reference in a new issue