Commit 94d4a9c1 authored by Piyush Aggarwal's avatar Piyush Aggarwal 🎮
Browse files

indicator: move systray action class to own folder

parent bf4ac716
......@@ -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()
......
/*
* 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"
/*
* 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();
}
/*
* 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
\ No newline at end of file
#ifndef SYSTRAY_ACTIONS_H
#define SYSTRAY_ACTIONS_H
#include <battery_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