File indexing completed on 2024-09-15 04:28:35
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 #include "windowcontroller.h" 0013 0014 TrayIcon::TrayIcon(QObject *parent) 0015 : QSystemTrayIcon(parent) 0016 { 0017 setIcon(QIcon(QStringLiteral(":/icons/org.kde.neochat.tray.svg"))); 0018 QMenu *menu = new QMenu(); 0019 auto viewAction_ = new QAction(i18n("Show"), parent); 0020 0021 connect(viewAction_, &QAction::triggered, this, [] { 0022 WindowController::instance().toggleWindow(); 0023 }); 0024 connect(this, &QSystemTrayIcon::activated, this, [](QSystemTrayIcon::ActivationReason reason) { 0025 if (reason == QSystemTrayIcon::Trigger) { 0026 WindowController::instance().toggleWindow(); 0027 } 0028 }); 0029 0030 menu->addAction(viewAction_); 0031 0032 menu->addSeparator(); 0033 0034 auto quitAction = new QAction(i18n("Quit"), parent); 0035 quitAction->setIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); 0036 connect(quitAction, &QAction::triggered, QCoreApplication::instance(), QCoreApplication::quit); 0037 0038 menu->addAction(quitAction); 0039 0040 setContextMenu(menu); 0041 } 0042 0043 #include "moc_trayicon.cpp"