File indexing completed on 2024-10-06 12:54:08

0001 // SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
0002 // SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0003 // SPDX-License-Identifier: GPL-3.0-only
0004 
0005 #include "trayicon.h"
0006 
0007 #include <QCoreApplication>
0008 #include <QMenu>
0009 
0010 #include <KLocalizedString>
0011 
0012 TrayIcon::TrayIcon(QObject *parent)
0013     : QSystemTrayIcon(parent)
0014 {
0015     setIcon(QIcon(":/icons/org.kde.neochat.tray.svg"));
0016     QMenu *menu = new QMenu();
0017     auto viewAction_ = new QAction(i18n("Show"), parent);
0018 
0019     connect(viewAction_, &QAction::triggered, this, &TrayIcon::showWindow);
0020     connect(this, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
0021         if (reason == QSystemTrayIcon::Trigger) {
0022             Q_EMIT showWindow();
0023         }
0024     });
0025 
0026     menu->addAction(viewAction_);
0027 
0028     menu->addSeparator();
0029 
0030     auto quitAction = new QAction(i18n("Quit"), parent);
0031     quitAction->setIcon(QIcon::fromTheme("application-exit"));
0032     connect(quitAction, &QAction::triggered, QCoreApplication::instance(), QCoreApplication::quit);
0033 
0034     menu->addAction(quitAction);
0035 
0036     setContextMenu(menu);
0037 }
0038 
0039 #include "moc_trayicon.cpp"