Commit fe3d79cc authored by Piyush Aggarwal's avatar Piyush Aggarwal 🎮
Browse files

indicator: add connectivity action

parent 94d4a9c1
......@@ -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](){
......
/*
* 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();
}
/*
* 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
\ No newline at end of file
#ifndef SYSTRAY_ACTIONS_H
#define SYSTRAY_ACTIONS_H
#include <battery_action.h>
#include <connectivity_action.h>
#endif // SYSTRAY_ACTIONS_H
Markdown is supported
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