Commit 5f13e6f3 authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Create events from email when dragging them in the kontact sidebar

parent 9eeed156
Pipeline #76011 passed with stage
in 12 minutes and 53 seconds
......@@ -1368,6 +1368,8 @@ void ActionManager::openEventEditor(const QString &summary,
int action = IncidenceEditorNG::IncidenceEditorSettings::self()->defaultEmailAttachMethod();
if (attachmentMimetype != QLatin1String("message/rfc822")) {
action = IncidenceEditorNG::IncidenceEditorSettings::Link;
} else if (file.isEmpty()) {
action = KOPrefs::TodoAttachLink;
} else if (IncidenceEditorNG::IncidenceEditorSettings::self()->defaultEmailAttachMethod() == IncidenceEditorNG::IncidenceEditorSettings::Ask) {
auto menu = new QMenu(nullptr);
QAction *attachLink = menu->addAction(i18n("Attach as &link"));
......@@ -1472,6 +1474,8 @@ void ActionManager::openTodoEditor(const QString &summary,
int action = KOPrefs::instance()->defaultTodoAttachMethod();
if (attachmentMimetype != QLatin1String("message/rfc822")) {
action = KOPrefs::TodoAttachLink;
} else if (file.isEmpty()) {
action = KOPrefs::TodoAttachLink;
} else if (KOPrefs::instance()->defaultTodoAttachMethod() == KOPrefs::TodoAttachAsk) {
auto menu = new QMenu(nullptr);
QAction *attachLink = menu->addAction(i18n("Attach as &link"));
......
......@@ -963,28 +963,18 @@ void CalendarView::newEvent(const QString &summary,
const QStringList &attachmentMimetypes,
bool inlineAttachment)
{
// Adjust the start/end date times (i.e. replace invalid values by defaults,
// and let the view adjust the type.
QDateTime startDt;
QDateTime endDt;
bool allDay = false;
dateTimesForNewEvent(startDt, endDt, allDay);
IncidenceEditorNG::IncidenceDefaults defaults = IncidenceEditorNG::IncidenceDefaults::minimalIncidenceDefaults();
defaults.setStartDateTime(startDt);
defaults.setEndDateTime(endDt);
// if attach or attendee list is empty, these methods don't do anything, so
// it's safe to call them in every case
defaults.setAttachments(attachments, attachmentMimetypes, QStringList(), inlineAttachment);
defaults.setAttendees(attendees);
KCalendarCore::Event::Ptr event(new KCalendarCore::Event);
defaults.setDefaults(event);
event->setSummary(summary);
event->setDescription(description);
event->setAllDay(allDay);
newEventEditor(event);
Akonadi::Collection defaultCol = defaultCollection(KCalendarCore::Event::eventMimeType());
IncidenceEditorNG::IncidenceDialogFactory::createEventEditor(summary,
description,
attachments,
attendees,
attachmentMimetypes,
QStringList() /* attachment labels */,
inlineAttachment,
defaultCol,
true /* cleanupAttachmentTempFiles */,
this /* parent */);
}
void CalendarView::newTodo(const QString &summary,
......
......@@ -16,7 +16,10 @@
#include <KCalendarCore/Incidence>
#include <KCalendarCore/MemoryCalendar>
#include <ItemFetchJob>
#include <ItemFetchScope>
#include <KCalUtils/ICalDrag>
#include <KMime/Message>
#include <KontactInterface/Core>
......@@ -25,6 +28,7 @@
#include <KLocalizedString>
#include <QAction>
#include <QIcon>
#include <QTemporaryFile>
#include <QDropEvent>
#include <QStandardPaths>
......@@ -159,6 +163,44 @@ void KOrganizerPlugin::processDropEvent(QDropEvent *event)
}
}
if (md->hasUrls()) {
for (const auto &url : md->urls()) {
if (url.scheme() == QStringLiteral("akonadi") && url.hasQuery()) {
const QUrlQuery query(url.query());
if (!query.queryItemValue(QStringLiteral("item")).isEmpty()
&& query.queryItemValue(QStringLiteral("type")) == QStringLiteral("message/rfc822")) {
Akonadi::ItemFetchJob *job =
new Akonadi::ItemFetchJob(Akonadi::Item(static_cast<qint64>(query.queryItemValue(QStringLiteral("item")).toLongLong())));
job->fetchScope().fetchAllAttributes();
job->fetchScope().fetchFullPayload(true);
connect(job, &KJob::result, this, [this, url](KJob *job) {
if (job->error()) {
return;
}
Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
const Akonadi::Item::List items = fetchJob->items();
for (const Akonadi::Item &item : items) {
if (item.mimeType() == QStringLiteral("message/rfc822")) {
auto mail = item.payload<KMime::Message::Ptr>();
interface()->openEventEditor(i18nc("Event from email summary", "Mail: %1", mail->subject()->asUnicodeString()),
i18nc("Event from email content",
"<b>From:</b> %1<br /><b>To:</b> %2<br /><b>Subject:</b> %3",
mail->from()->displayString(),
mail->to()->displayString(),
mail->subject()->asUnicodeString()),
url.toDisplayString(),
QString(),
QStringList(),
QStringLiteral("message/rfc822"));
}
}
});
}
return;
}
}
}
if (md->hasText()) {
const QString text = md->text();
qCDebug(KORGANIZERPLUGIN_LOG) << "DROP:" << text;
......
......@@ -15,7 +15,10 @@
#include <KCalendarCore/MemoryCalendar>
#include <ItemFetchJob>
#include <ItemFetchScope>
#include <KCalUtils/ICalDrag>
#include <KMime/Message>
#include <KontactInterface/Core>
......@@ -167,6 +170,44 @@ void TodoPlugin::processDropEvent(QDropEvent *event)
}
}
if (md->hasUrls()) {
for (const auto &url : md->urls()) {
if (url.scheme() == QStringLiteral("akonadi") && url.hasQuery()) {
const QUrlQuery query(url.query());
if (!query.queryItemValue(QStringLiteral("item")).isEmpty()
&& query.queryItemValue(QStringLiteral("type")) == QStringLiteral("message/rfc822")) {
Akonadi::ItemFetchJob *job =
new Akonadi::ItemFetchJob(Akonadi::Item(static_cast<qint64>(query.queryItemValue(QStringLiteral("item")).toLongLong())));
job->fetchScope().fetchAllAttributes();
job->fetchScope().fetchFullPayload(true);
connect(job, &KJob::result, this, [this, url](KJob *job) {
if (job->error()) {
return;
}
Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
const Akonadi::Item::List items = fetchJob->items();
for (const Akonadi::Item &item : items) {
if (item.mimeType() == QStringLiteral("message/rfc822")) {
auto mail = item.payload<KMime::Message::Ptr>();
interface()->openTodoEditor(i18nc("Event from email summary", "Mail: %1", mail->subject()->asUnicodeString()),
i18nc("Event from email content",
"<b>From:</b> %1<br /><b>To:</b> %2<br /><b>Subject:</b> %3",
mail->from()->displayString(),
mail->to()->displayString(),
mail->subject()->asUnicodeString()),
url.toDisplayString(),
QString(),
QStringList(),
QStringLiteral("message/rfc822"));
}
}
});
}
return;
}
}
}
if (md->hasText()) {
const QString text = md->text();
interface()->openTodoEditor(text);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment