File indexing completed on 2024-12-22 04:56:52
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include "newmailnotificationhistorybrowsertext.h" 0007 #include "newmailnotifier_debug.h" 0008 #include "newmailnotifieropenfolderjob.h" 0009 #include "newmailnotifiershowmessagejob.h" 0010 0011 #include <KStandardAction> 0012 #include <QMenu> 0013 0014 NewMailNotificationHistoryBrowserText::NewMailNotificationHistoryBrowserText(QWidget *parent) 0015 : TextCustomEditor::RichTextBrowser(parent) 0016 { 0017 connect(this, &NewMailNotificationHistoryBrowserText::openMail, this, &NewMailNotificationHistoryBrowserText::slotOpenMail); 0018 connect(this, &NewMailNotificationHistoryBrowserText::openFolder, this, &NewMailNotificationHistoryBrowserText::slotSelectFolder); 0019 } 0020 0021 NewMailNotificationHistoryBrowserText::~NewMailNotificationHistoryBrowserText() = default; 0022 0023 void NewMailNotificationHistoryBrowserText::doSetSource(const QUrl &url, QTextDocument::ResourceType type) 0024 { 0025 Q_UNUSED(type); 0026 QString uri = url.toString(); 0027 qCDebug(NEWMAILNOTIFIER_LOG) << " uri " << uri; 0028 if (uri.startsWith(QLatin1StringView("openmail:"))) { 0029 uri.remove(QStringLiteral("openmail:")); 0030 qCDebug(NEWMAILNOTIFIER_LOG) << "openMail uri " << uri; 0031 Q_EMIT openMail(uri); 0032 } else if (uri.startsWith(QLatin1StringView("openfolder:"))) { 0033 uri.remove(QStringLiteral("openfolder:")); 0034 qCDebug(NEWMAILNOTIFIER_LOG) << "openFolder uri " << uri; 0035 Q_EMIT openFolder(uri); 0036 } else { 0037 qCWarning(NEWMAILNOTIFIER_LOG) << "No implement support for " << uri; 0038 } 0039 } 0040 0041 void NewMailNotificationHistoryBrowserText::addExtraMenuEntry(QMenu *menu, QPoint pos) 0042 { 0043 Q_UNUSED(pos) 0044 if (!toPlainText().isEmpty()) { 0045 QAction *clearAllAction = KStandardAction::clear(this, &NewMailNotificationHistoryBrowserText::clearHistory, menu); 0046 menu->addSeparator(); 0047 menu->addAction(clearAllAction); 0048 } 0049 } 0050 0051 void NewMailNotificationHistoryBrowserText::slotOpenMail(const QString &identifier) 0052 { 0053 auto job = new NewMailNotifierShowMessageJob(identifier.toLong()); 0054 job->start(); 0055 } 0056 0057 void NewMailNotificationHistoryBrowserText::slotSelectFolder(const QString &identifier) 0058 { 0059 auto job = new NewMailNotifierOpenFolderJob(identifier); 0060 job->start(); 0061 } 0062 0063 #include "moc_newmailnotificationhistorybrowsertext.cpp"