indicator: move systray action class to own folder

This commit is contained in:
Piyush Aggarwal 2021-05-23 11:20:54 +05:30
parent bf4ac716bf
commit 94d4a9c1c2
5 changed files with 92 additions and 43 deletions

View file

@ -13,6 +13,7 @@ set(indicator_SRCS
main.cpp
deviceindicator.cpp
${kdeconnect_custom_icons_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/systray_actions/battery_action.cpp
)
include(ECMAddAppIcon)
@ -39,7 +40,10 @@ endif()
add_executable(kdeconnect-indicator ${indicator_SRCS} ${debug_file_SRCS})
target_include_directories(kdeconnect-indicator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/systray_actions)
target_link_libraries(kdeconnect-indicator Qt5::Widgets KF5::CoreAddons KF5::I18n KF5::Notifications KF5::DBusAddons KF5::KCMUtils kdeconnectinterfaces kdeconnectcore kdeconnectversion)
if (WIN32)
add_compile_definitions(QSYSTRAY)
endif()

View file

@ -1,5 +1,6 @@
/*
* 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
*/
@ -11,47 +12,7 @@
#include "interfaces/dbusinterfaces.h"
#include <dbushelper.h>
class BatteryAction : public QAction
{
Q_OBJECT
public:
BatteryAction(DeviceDbusInterface* device)
: QAction(nullptr)
, m_batteryIface(device->id())
{
setCharge(m_batteryIface.charge());
setCharging(m_batteryIface.isCharging());
connect(&m_batteryIface, &BatteryDbusInterface::refreshedProxy, this, [this]{
setCharge(m_batteryIface.charge());
setCharging(m_batteryIface.isCharging());
});
setIcon(QIcon::fromTheme(QStringLiteral("battery")));
update();
}
void update() {
if (m_charge < 0)
setText(i18n("No Battery"));
else if (m_charging)
setText(i18n("Battery: %1% (Charging)", m_charge));
else
setText(i18n("Battery: %1%", m_charge));
}
private Q_SLOTS:
void setCharge(int charge) { m_charge = charge; update(); }
void setCharging(bool charging) { m_charging = charging; update(); }
private:
BatteryDbusInterface m_batteryIface;
int m_charge = -1;
bool m_charging = false;
};
#include <systray_actions.h>
DeviceIndicator::DeviceIndicator(DeviceDbusInterface* device)
: QMenu(device->name(), nullptr)
@ -136,5 +97,3 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface* device)
}
}, this);
}
#include "deviceindicator.moc"

View file

@ -0,0 +1,47 @@
/*
* 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 "battery_action.h"
BatteryAction::BatteryAction(DeviceDbusInterface* device)
: QAction(nullptr)
, m_batteryIface(device->id())
{
setCharge(m_batteryIface.charge());
setCharging(m_batteryIface.isCharging());
connect(&m_batteryIface, &BatteryDbusInterface::refreshedProxy, this, [this]{
setCharge(m_batteryIface.charge());
setCharging(m_batteryIface.isCharging());
});
setIcon(QIcon::fromTheme(QStringLiteral("battery")));
BatteryAction::update();
}
void BatteryAction::update()
{
if (m_charge < 0)
setText(i18n("No Battery"));
else if (m_charging)
setText(i18n("Battery: %1% (Charging)", m_charge));
else
setText(i18n("Battery: %1%", m_charge));
}
void BatteryAction::setCharge(int charge)
{
m_charge = charge;
update();
}
void BatteryAction::setCharging(bool charging)
{
m_charging = charging;
update();
}

View 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 BATTERYACTION_H
#define BATTERYACTION_H
#include <QMenu>
#include <QFileDialog>
#include <KLocalizedString>
#include "interfaces/dbusinterfaces.h"
#include <dbushelper.h>
class BatteryAction : public QAction
{
Q_OBJECT
public:
BatteryAction(DeviceDbusInterface* device);
void update();
private Q_SLOTS:
void setCharge(int charge);
void setCharging(bool charging);
private:
BatteryDbusInterface m_batteryIface;
int m_charge = -1;
bool m_charging = false;
};
#endif // BATTERYACTION_H

View file

@ -0,0 +1,4 @@
#ifndef SYSTRAY_ACTIONS_H
#define SYSTRAY_ACTIONS_H
#include <battery_action.h>
#endif // SYSTRAY_ACTIONS_H