2026-05-24 00:02:19 +02:00
|
|
|
#include "notificationmanager.h"
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
NotificationManager::NotificationManager(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
2026-05-24 21:01:05 +02:00
|
|
|
, m_trayIcon(nullptr)
|
|
|
|
|
, m_trayMenu(nullptr)
|
|
|
|
|
, m_showHideAction(nullptr)
|
|
|
|
|
, m_quitAction(nullptr)
|
|
|
|
|
, m_newMailSound(nullptr)
|
2026-05-24 00:02:19 +02:00
|
|
|
{
|
2026-05-24 21:01:05 +02:00
|
|
|
// Defer initialization to after QApplication is fully ready
|
|
|
|
|
// We'll initialize in a separate method called from main after the event loop starts?
|
|
|
|
|
// For now, we do nothing and log.
|
|
|
|
|
qDebug() << "NotificationManager: constructor (deferred initialization)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NotificationManager::~NotificationManager()
|
|
|
|
|
{
|
|
|
|
|
// Cleanup if we ever initialize
|
|
|
|
|
if (m_trayMenu) {
|
|
|
|
|
delete m_trayMenu;
|
|
|
|
|
}
|
|
|
|
|
// Note: m_trayIcon, m_showHideAction, m_quitAction, m_newMailSound are children of this or m_trayMenu?
|
|
|
|
|
// Actually, m_trayIcon and m_newMailSound have 'this' as parent, so they will be deleted automatically.
|
|
|
|
|
// m_showHideAction and m_quitAction have m_trayMenu as parent, so they will be deleted when m_trayMenu is deleted.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::initialize()
|
|
|
|
|
{
|
|
|
|
|
// Initialize the tray icon and related objects
|
|
|
|
|
m_trayIcon = new QSystemTrayIcon(this);
|
|
|
|
|
m_trayMenu = new QMenu(this); // parent to NotificationManager so it gets deleted with us
|
|
|
|
|
m_showHideAction = new QAction("Show/Hide", m_trayMenu);
|
|
|
|
|
m_quitAction = new QAction("Quit", m_trayMenu);
|
|
|
|
|
m_newMailSound = new QSoundEffect(this);
|
|
|
|
|
|
2026-05-24 00:02:19 +02:00
|
|
|
setupTrayIcon();
|
|
|
|
|
setupConnections();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::setupTrayIcon()
|
|
|
|
|
{
|
|
|
|
|
// Set an icon (you may want to load from resources)
|
|
|
|
|
m_trayIcon->setIcon(QIcon::fromTheme("mail-unread"));
|
|
|
|
|
m_trayIcon->setToolTip("Wino Mail");
|
|
|
|
|
|
|
|
|
|
m_trayMenu->addAction(m_showHideAction);
|
|
|
|
|
m_trayMenu->addSeparator();
|
|
|
|
|
m_trayMenu->addAction(m_quitAction);
|
|
|
|
|
m_trayIcon->setContextMenu(m_trayMenu);
|
|
|
|
|
|
|
|
|
|
m_newMailSound->setSource(QUrl::fromLocalFile("/usr/share/sounds/freedesktop/stereo/message-new-instant.oga"));
|
|
|
|
|
m_newMailSound->setVolume(0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::setupConnections()
|
|
|
|
|
{
|
|
|
|
|
// Connect tray icon signals
|
|
|
|
|
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &NotificationManager::onTrayIconActivated);
|
|
|
|
|
connect(m_showHideAction, &QAction::triggered, this, &NotificationManager::onShowHideRequested);
|
|
|
|
|
connect(m_quitAction, &QAction::triggered, qApp, &QGuiApplication::quit);
|
|
|
|
|
|
|
|
|
|
// Subscribe to mail added events
|
|
|
|
|
SUBSCRIBE(WinoMail::Events::MailItemAddedEvent, [this](const WinoMail::Events::MailItemAddedEvent& event) {
|
|
|
|
|
onMailItemAdded(event);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Show tray icon
|
|
|
|
|
m_trayIcon->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::onMailItemAdded(const WinoMail::Events::MailItemAddedEvent& event)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "NotificationManager: New mail arrived -" << event.item.subject();
|
|
|
|
|
// Show a system tray notification
|
|
|
|
|
m_trayIcon->showMessage(
|
|
|
|
|
"Wino Mail - Nuevo correo",
|
|
|
|
|
event.item.subject(),
|
|
|
|
|
QSystemTrayIcon::MessageIcon::Information,
|
|
|
|
|
5000 // 5 seconds
|
|
|
|
|
);
|
|
|
|
|
// Play sound
|
|
|
|
|
playNewMailSound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
|
|
|
|
{
|
|
|
|
|
if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick) {
|
|
|
|
|
onShowHideRequested();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::onShowHideRequested()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement actual show/hide of main window
|
|
|
|
|
// For now, just log
|
|
|
|
|
qDebug() << "NotificationManager: Show/Hide requested";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::onQuitRequested()
|
|
|
|
|
{
|
|
|
|
|
// Already connected to quit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotificationManager::playNewMailSound()
|
|
|
|
|
{
|
|
|
|
|
if (m_newMailSound->isLoaded()) {
|
|
|
|
|
m_newMailSound->play();
|
|
|
|
|
}
|
|
|
|
|
}
|