2026-06-17 22:44:27 +02:00
|
|
|
#include "ui/readerview.h"
|
|
|
|
|
#include <QFont>
|
2026-08-17 15:34:49 +02:00
|
|
|
#include <QDesktopServices>
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
#include "db/dao/mailitemdao.h"
|
2026-06-17 22:44:27 +02:00
|
|
|
|
|
|
|
|
ReaderView::ReaderView(QWidget *parent) : QWidget(parent) {
|
|
|
|
|
setupUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReaderView::setupUI() {
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
|
|
|
|
mainLayout->setContentsMargins(15, 15, 15, 15);
|
|
|
|
|
mainLayout->setSpacing(10);
|
|
|
|
|
|
|
|
|
|
// Header Section
|
|
|
|
|
QWidget *headerWidget = new QWidget();
|
|
|
|
|
QVBoxLayout *headerLayout = new QVBoxLayout(headerWidget);
|
|
|
|
|
headerLayout->setSpacing(5);
|
|
|
|
|
|
|
|
|
|
m_subjectLabel = new QLabel();
|
|
|
|
|
QFont subjectFont = m_subjectLabel->font();
|
|
|
|
|
subjectFont.setBold(true);
|
|
|
|
|
subjectFont.setPointSize(14);
|
|
|
|
|
m_subjectLabel->setFont(subjectFont);
|
|
|
|
|
m_subjectLabel->setText("No subject");
|
|
|
|
|
m_subjectLabel->setWordWrap(true);
|
|
|
|
|
|
|
|
|
|
m_fromLabel = new QLabel();
|
|
|
|
|
m_fromLabel->setText("From: ");
|
|
|
|
|
|
|
|
|
|
m_dateLabel = new QLabel();
|
|
|
|
|
m_dateLabel->setText("Date: ");
|
|
|
|
|
m_dateLabel->setStyleSheet("color: gray; font-style: italic;");
|
|
|
|
|
|
|
|
|
|
headerLayout->addWidget(m_subjectLabel);
|
|
|
|
|
headerLayout->addWidget(m_fromLabel);
|
|
|
|
|
headerLayout->addWidget(m_dateLabel);
|
|
|
|
|
|
|
|
|
|
// Action Buttons
|
|
|
|
|
QHBoxLayout *actionsLayout = new QHBoxLayout();
|
|
|
|
|
m_replyButton = new QPushButton("Reply");
|
|
|
|
|
m_forwardButton = new QPushButton("Forward");
|
|
|
|
|
m_deleteButton = new QPushButton("Delete");
|
|
|
|
|
m_deleteButton->setStyleSheet("color: red;");
|
2026-06-18 18:58:27 +02:00
|
|
|
|
2026-06-23 01:34:13 +02:00
|
|
|
QPushButton *m_detachButton = new QPushButton("↗ Abrir en ventana");
|
|
|
|
|
m_detachButton->setToolTip("Abrir este correo en una ventana independiente");
|
2026-06-18 18:58:27 +02:00
|
|
|
|
2026-06-17 22:44:27 +02:00
|
|
|
actionsLayout->addWidget(m_replyButton);
|
|
|
|
|
actionsLayout->addWidget(m_forwardButton);
|
2026-06-18 18:58:27 +02:00
|
|
|
actionsLayout->addWidget(m_detachButton);
|
2026-06-17 22:44:27 +02:00
|
|
|
actionsLayout->addStretch();
|
|
|
|
|
actionsLayout->addWidget(m_deleteButton);
|
|
|
|
|
|
|
|
|
|
// Body Viewer
|
|
|
|
|
m_bodyViewer = new QTextBrowser();
|
|
|
|
|
m_bodyViewer->setOpenExternalLinks(true);
|
|
|
|
|
m_bodyViewer->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
|
2026-08-17 15:34:49 +02:00
|
|
|
m_attachmentList = new QListWidget();
|
|
|
|
|
m_attachmentList->setVisible(false);
|
|
|
|
|
m_attachmentList->setMaximumHeight(110);
|
|
|
|
|
m_attachmentList->setToolTip(tr("Double-click an attachment to open it"));
|
|
|
|
|
connect(m_attachmentList, &QListWidget::itemDoubleClicked, this,
|
|
|
|
|
[](QListWidgetItem *listItem) {
|
|
|
|
|
const QString path = listItem->data(Qt::UserRole).toString();
|
|
|
|
|
if (!path.isEmpty()) QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-17 22:44:27 +02:00
|
|
|
mainLayout->addWidget(headerWidget);
|
|
|
|
|
mainLayout->addLayout(actionsLayout);
|
2026-08-17 15:34:49 +02:00
|
|
|
mainLayout->addWidget(m_attachmentList);
|
2026-06-17 22:44:27 +02:00
|
|
|
mainLayout->addWidget(m_bodyViewer);
|
|
|
|
|
|
|
|
|
|
// Connections
|
|
|
|
|
connect(m_replyButton, &QPushButton::clicked, [this]() {
|
|
|
|
|
if (m_bodyViewer->toPlainText().isEmpty()) return;
|
|
|
|
|
});
|
2026-06-18 18:58:27 +02:00
|
|
|
|
|
|
|
|
connect(m_detachButton, &QPushButton::clicked, this, &ReaderView::detachRequested);
|
2026-06-17 22:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReaderView::setMailItem(const MailItem* item) {
|
|
|
|
|
if (!item) {
|
|
|
|
|
m_subjectLabel->setText("No mail selected");
|
|
|
|
|
m_fromLabel->setText("From: ");
|
|
|
|
|
m_dateLabel->setText("Date: ");
|
2026-08-17 15:34:49 +02:00
|
|
|
m_attachmentList->clear();
|
|
|
|
|
m_attachmentList->setVisible(false);
|
2026-06-17 22:44:27 +02:00
|
|
|
m_bodyViewer->setHtml("<i>Please select a message to read</i>");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_subjectLabel->setText(item->subject());
|
|
|
|
|
m_fromLabel->setText(QString("From: %1").arg(item->sender()));
|
|
|
|
|
m_dateLabel->setText(QString("Date: %1").arg(item->date().toString("ddd, d MMM yyyy hh:mm")));
|
2026-08-17 15:34:49 +02:00
|
|
|
m_attachmentList->clear();
|
|
|
|
|
const QVector<StoredAttachmentRecord> attachments = MailItemDao::attachmentsForMail(item->id());
|
|
|
|
|
for (const StoredAttachmentRecord &attachment : attachments) {
|
|
|
|
|
auto *listItem = new QListWidgetItem(attachment.fileName, m_attachmentList);
|
|
|
|
|
listItem->setData(Qt::UserRole, attachment.storedPath);
|
|
|
|
|
listItem->setToolTip(attachment.storedPath);
|
|
|
|
|
}
|
|
|
|
|
m_attachmentList->setVisible(!attachments.isEmpty());
|
2026-06-17 22:44:27 +02:00
|
|
|
m_bodyViewer->setHtml(item->bodyHtml());
|
2026-08-17 15:34:49 +02:00
|
|
|
}
|