Git commit 6fdf31cd3562ed445a27fabe6e1590445de161d9 by Jan Kundrát. Committed on 02/05/2019 at 11:44. Pushed by gerrit into branch 'master'.
GUI: detect some calendaring events So, I started getting many text/calendar items from $corporate_environment. Let's try if Trojita's experience when dealing with this can be improved a little bit. The first step is determining the kind of the calendar object from MIME. This is standardized [1] and provided by IMAP's usual BODYSTRUCTURE. I was thinking that the UX could be made better by directly showing whether this is: - an invitation which typically requests some action or targets "me", - some ad-hoc event notification, - a reply to an invitation, etc. This can be done even without parsing ical files at all, which is nice. What I would like to see in future is some basic UI rendering of the calendar object, integration with an external calendar system (hi vdirsyncer+khal, etc), and a way of sending replies (confirmation/rejection) when I'm invited to a meeting. That's for future work, though. [1] https://tools.ietf.org/html/rfc5546#section-3.2 Change-Id: Icfd90ad3dad3d5d6ae5a2c7dce1cad8f44b89ee2 M +21 -1 src/Gui/PartWidget.cpp https://commits.kde.org/trojita/6fdf31cd3562ed445a27fabe6e1590445de161d9 diff --git a/src/Gui/PartWidget.cpp b/src/Gui/PartWidget.cpp index f73bd665..bb27604d 100644 --- a/src/Gui/PartWidget.cpp +++ b/src/Gui/PartWidget.cpp @@ -38,6 +38,7 @@ #include "Gui/Util.h" #include "Imap/Model/ItemRoles.h" #include "Imap/Model/MailboxTree.h" +#include "Imap/Parser/Message.h" #include "UiUtils/IconLoader.h" namespace { @@ -134,6 +135,7 @@ MultipartAlternativeWidget::MultipartAlternativeWidget(QWidget *parent, const bool isPlainText = mimeType == QLatin1String("text/plain"); const bool isHtml = mimeType == QLatin1String("text/html"); + const bool isCalendar = mimeType == QLatin1String("text/calendar"); if (isPlainText) { //: Translators: use something very short, perhaps even "text". Don't describe this as "Clear text". @@ -143,13 +145,31 @@ MultipartAlternativeWidget::MultipartAlternativeWidget(QWidget *parent, } else if (isHtml) { //: Translators: caption of the tab which shows a HTML version of the mail. Use some short, compact text here. mimeType = tr("HTML"); + } else if (isCalendar) { + using bodyFldParam_t = Imap::Message::AbstractMessage::bodyFldParam_t; + const auto bodyFldParam = anotherPart.data(Imap::Mailbox::RolePartBodyFldParam).value<bodyFldParam_t>(); + auto method = bodyFldParam[QByteArray("METHOD")].toUpper(); + if (method == "CANCEL") { + mimeType = tr("Cancelled Event"); + } else if (method == "REQUEST") { + mimeType = tr("Meeting Request"); + } else if (method == "PUBLISH") { + mimeType = tr("Calendar Event"); + } else if (method == "REPLY") { + mimeType = tr("Calendar Reply"); + } else if (method == "ADD") { + mimeType = tr("New Meeting"); + } + // We do not handle REFRESH, COUNTER or DECLINECOUNTER because they are "too specific" for now } addTab(item, mimeType); // Bug 332950: some items nested within a multipart/alternative message are not exactly an alternative. // One such example is a text/calendar right next to a text/html and a text/plain. - if (!isPlainText && !isHtml) { + if (isCalendar) { + setTabIcon(i, UiUtils::loadIcon(QStringLiteral("text-calendar"))); + } else if (!isPlainText && !isHtml) { // Unfortunately we cannot change the tab background with current Qt (Q1 2014), // see https://bugreports.qt-project.org/browse/QTBUG-840 for details setTabIcon(i, UiUtils::loadIcon(QStringLiteral("emblem-important")));
