Implement Fase 5 lectura de correos y Fase 6 notificaciones: ReaderPage muestra correos reales vía EmailManager, añadido NotificationManager con QSystemTrayIcon y suscripción al Event Bus; actualizados EmailManager y DbChangeProcessor; creado estructura de notificaciones básica
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#include "notificationmanager.h"
|
||||
#include <QGuiApplication>
|
||||
#include <QDebug>
|
||||
|
||||
NotificationManager::NotificationManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
setupTrayIcon();
|
||||
setupConnections();
|
||||
}
|
||||
|
||||
void NotificationManager::setupTrayIcon()
|
||||
{
|
||||
m_trayIcon = new QSystemTrayIcon(this);
|
||||
// Set an icon (you may want to load from resources)
|
||||
m_trayIcon->setIcon(QIcon::fromTheme("mail-unread"));
|
||||
m_trayIcon->setToolTip("Wino Mail");
|
||||
|
||||
m_trayMenu = new QMenu(this);
|
||||
m_showHideAction = new QAction("Show/Hide", this);
|
||||
m_quitAction = new QAction("Quit", this);
|
||||
m_trayMenu->addAction(m_showHideAction);
|
||||
m_trayMenu->addSeparator();
|
||||
m_trayMenu->addAction(m_quitAction);
|
||||
m_trayIcon->setContextMenu(m_trayMenu);
|
||||
|
||||
m_newMailSound = new QSoundEffect(this);
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user