Use QSystemTrayIcon instead of KStatusNotifierItem
KSNI doesn't support Windows and macOS and we don't need any of the features it provides over QSystemTrayIcon Also remove some dead code
This commit is contained in:
@@ -62,9 +62,8 @@ Controller::Controller(QObject *parent)
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
TrayIcon *trayIcon = new TrayIcon(this);
|
||||
trayIcon->show();
|
||||
connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
||||
trayIcon->setIconSource("org.kde.neochat");
|
||||
trayIcon->setIsOnline(true);
|
||||
#endif
|
||||
|
||||
QTimer::singleShot(0, this, [=] {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
|
||||
* SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
@@ -11,34 +12,28 @@
|
||||
#include <KLocalizedString>
|
||||
|
||||
TrayIcon::TrayIcon(QObject *parent)
|
||||
: KStatusNotifierItem(parent)
|
||||
: QSystemTrayIcon(parent)
|
||||
{
|
||||
setIcon(QIcon::fromTheme("org.kde.neochat"));
|
||||
QMenu *menu = new QMenu();
|
||||
auto viewAction_ = new QAction(i18n("Show"), parent);
|
||||
|
||||
connect(viewAction_, &QAction::triggered, this, &TrayIcon::showWindow);
|
||||
connect(this, &KStatusNotifierItem::activateRequested, this, [this](bool active) {
|
||||
if (active) {
|
||||
connect(this, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Trigger) {
|
||||
Q_EMIT showWindow();
|
||||
}
|
||||
});
|
||||
|
||||
menu->addAction(viewAction_);
|
||||
|
||||
setCategory(Communications);
|
||||
menu->addSeparator();
|
||||
|
||||
auto quitAction = new QAction(i18n("Quit"), parent);
|
||||
quitAction->setIcon(QIcon::fromTheme("application-exit"));
|
||||
connect(quitAction, &QAction::triggered, QCoreApplication::instance(), QCoreApplication::quit);
|
||||
|
||||
menu->addAction(quitAction);
|
||||
|
||||
setContextMenu(menu);
|
||||
}
|
||||
|
||||
void TrayIcon::setIsOnline(bool online)
|
||||
{
|
||||
m_isOnline = online;
|
||||
setStatus(Active);
|
||||
Q_EMIT isOnlineChanged();
|
||||
}
|
||||
|
||||
void TrayIcon::setIconSource(const QString &source)
|
||||
{
|
||||
m_iconSource = source;
|
||||
setIconByName(source);
|
||||
Q_EMIT iconSourceChanged();
|
||||
}
|
||||
|
||||
@@ -8,43 +8,21 @@
|
||||
|
||||
// Modified from mujx/nheko's TrayIcon.
|
||||
|
||||
#include <KStatusNotifierItem>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QAction>
|
||||
#include <QIcon>
|
||||
#include <QIconEngine>
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
|
||||
class TrayIcon : public KStatusNotifierItem
|
||||
class TrayIcon : public QSystemTrayIcon
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged)
|
||||
Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged)
|
||||
public:
|
||||
TrayIcon(QObject *parent = nullptr);
|
||||
|
||||
QString iconSource()
|
||||
{
|
||||
return m_iconSource;
|
||||
}
|
||||
void setIconSource(const QString &source);
|
||||
|
||||
bool isOnline() const
|
||||
{
|
||||
return m_isOnline;
|
||||
}
|
||||
void setIsOnline(bool online);
|
||||
|
||||
Q_SIGNALS:
|
||||
void notificationCountChanged();
|
||||
void iconSourceChanged();
|
||||
void isOnlineChanged();
|
||||
|
||||
void showWindow();
|
||||
|
||||
private:
|
||||
QString m_iconSource;
|
||||
bool m_isOnline = true;
|
||||
};
|
||||
|
||||
#endif // TRAYICON_H
|
||||
|
||||
Reference in New Issue
Block a user