Changeset View
Changeset View
Standalone View
Standalone View
plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp
Show First 20 Lines • Show All 356 Lines • ▼ Show 20 Line(s) | 356 | if ((*it).role() != role) { | |||
---|---|---|---|---|---|
357 | role = Attendee::OptParticipant; // they differ, default | 357 | role = Attendee::OptParticipant; // they differ, default | ||
358 | break; | 358 | break; | ||
359 | } | 359 | } | ||
360 | } | 360 | } | ||
361 | } | 361 | } | ||
362 | return role; | 362 | return role; | ||
363 | } | 363 | } | ||
364 | 364 | | |||
365 | static Attachment::Ptr findAttachment(const QString &name, const QString &iCal) | 365 | static Attachment findAttachment(const QString &name, const QString &iCal) | ||
366 | { | 366 | { | ||
367 | Incidence::Ptr incidence = stringToIncidence(iCal); | 367 | Incidence::Ptr incidence = stringToIncidence(iCal); | ||
368 | 368 | | |||
369 | // get the attachment by name from the incidence | 369 | // get the attachment by name from the incidence | ||
370 | Attachment::List attachments = incidence->attachments(); | 370 | Attachment::List attachments = incidence->attachments(); | ||
371 | Attachment::Ptr attachment; | 371 | Attachment attachment; | ||
372 | if (!attachments.isEmpty()) { | | |||
373 | const Attachment::List::ConstIterator end = attachments.constEnd(); | 372 | const Attachment::List::ConstIterator end = attachments.constEnd(); | ||
374 | for (Attachment::List::ConstIterator it = attachments.constBegin(); it != end; ++it) { | 373 | for (Attachment::List::ConstIterator it = attachments.constBegin(); it != end; ++it) { | ||
375 | if ((*it)->label() == name) { | 374 | if ((*it).label() == name) { | ||
376 | attachment = *it; | 375 | attachment = *it; | ||
377 | break; | 376 | break; | ||
378 | } | 377 | } | ||
379 | } | 378 | } | ||
380 | } | | |||
381 | 379 | | |||
382 | if (!attachment) { | 380 | if (attachment.isEmpty()) { | ||
383 | KMessageBox::error( | 381 | KMessageBox::error( | ||
384 | nullptr, | 382 | nullptr, | ||
385 | i18n("No attachment named \"%1\" found in the invitation.", name)); | 383 | i18n("No attachment named \"%1\" found in the invitation.", name)); | ||
386 | return Attachment::Ptr(); | 384 | return Attachment(); | ||
387 | } | 385 | } | ||
388 | 386 | | |||
389 | if (attachment->isUri()) { | 387 | if (attachment.isUri()) { | ||
390 | bool fileExists = false; | 388 | bool fileExists = false; | ||
391 | QUrl attachmentUrl(attachment->uri()); | 389 | QUrl attachmentUrl(attachment.uri()); | ||
392 | if (attachmentUrl.isLocalFile()) { | 390 | if (attachmentUrl.isLocalFile()) { | ||
393 | fileExists = QFile::exists(attachmentUrl.toLocalFile()); | 391 | fileExists = QFile::exists(attachmentUrl.toLocalFile()); | ||
394 | } else { | 392 | } else { | ||
395 | auto job = KIO::stat(attachmentUrl, KIO::StatJob::SourceSide, 0); | 393 | auto job = KIO::stat(attachmentUrl, KIO::StatJob::SourceSide, 0); | ||
396 | fileExists = job->exec(); | 394 | fileExists = job->exec(); | ||
397 | } | 395 | } | ||
398 | if (!fileExists) { | 396 | if (!fileExists) { | ||
399 | KMessageBox::information( | 397 | KMessageBox::information( | ||
400 | nullptr, | 398 | nullptr, | ||
401 | i18n("The invitation attachment \"%1\" is a web link that " | 399 | i18n("The invitation attachment \"%1\" is a web link that " | ||
402 | "is inaccessible from this computer. Please ask the event " | 400 | "is inaccessible from this computer. Please ask the event " | ||
403 | "organizer to resend the invitation with this attachment " | 401 | "organizer to resend the invitation with this attachment " | ||
404 | "stored inline instead of a link.", | 402 | "stored inline instead of a link.", | ||
405 | attachmentUrl.toDisplayString())); | 403 | attachmentUrl.toDisplayString())); | ||
406 | return Attachment::Ptr(); | 404 | return Attachment(); | ||
407 | } | 405 | } | ||
408 | } | 406 | } | ||
409 | return attachment; | 407 | return attachment; | ||
410 | } | 408 | } | ||
411 | 409 | | |||
412 | static QString findReceiver(KMime::Content *node) | 410 | static QString findReceiver(KMime::Content *node) | ||
413 | { | 411 | { | ||
414 | if (!node || !node->topLevel()) { | 412 | if (!node || !node->topLevel()) { | ||
▲ Show 20 Lines • Show All 605 Lines • ▼ Show 20 Line(s) | 997 | if (status == Attendee::Delegated) { | |||
1020 | 1018 | | |||
1021 | ok = mail(viewerInstance, incidence, dir, iTIPRequest, receiver, delegateString, Delegation); | 1019 | ok = mail(viewerInstance, incidence, dir, iTIPRequest, receiver, delegateString, Delegation); | ||
1022 | } | 1020 | } | ||
1023 | return ok; | 1021 | return ok; | ||
1024 | } | 1022 | } | ||
1025 | 1023 | | |||
1026 | bool openAttachment(const QString &name, const QString &iCal) const | 1024 | bool openAttachment(const QString &name, const QString &iCal) const | ||
1027 | { | 1025 | { | ||
1028 | Attachment::Ptr attachment(findAttachment(name, iCal)); | 1026 | Attachment attachment(findAttachment(name, iCal)); | ||
1029 | if (!attachment) { | 1027 | if (attachment.isEmpty()) { | ||
1030 | return false; | 1028 | return false; | ||
1031 | } | 1029 | } | ||
1032 | 1030 | | |||
1033 | if (attachment->isUri()) { | 1031 | if (attachment.isUri()) { | ||
1034 | QDesktopServices::openUrl(QUrl(attachment->uri())); | 1032 | QDesktopServices::openUrl(QUrl(attachment.uri())); | ||
1035 | } else { | 1033 | } else { | ||
1036 | // put the attachment in a temporary file and launch it | 1034 | // put the attachment in a temporary file and launch it | ||
1037 | QTemporaryFile *file = nullptr; | 1035 | QTemporaryFile *file = nullptr; | ||
1038 | QMimeDatabase db; | 1036 | QMimeDatabase db; | ||
1039 | QStringList patterns = db.mimeTypeForName(attachment->mimeType()).globPatterns(); | 1037 | QStringList patterns = db.mimeTypeForName(attachment.mimeType()).globPatterns(); | ||
1040 | if (!patterns.empty()) { | 1038 | if (!patterns.empty()) { | ||
1041 | QString pattern = patterns.at(0); | 1039 | QString pattern = patterns.at(0); | ||
1042 | file = new QTemporaryFile(QDir::tempPath() + QStringLiteral("/messageviewer_XXXXXX") + pattern.remove(QLatin1Char('*'))); | 1040 | file = new QTemporaryFile(QDir::tempPath() + QStringLiteral("/messageviewer_XXXXXX") + pattern.remove(QLatin1Char('*'))); | ||
1043 | } else { | 1041 | } else { | ||
1044 | file = new QTemporaryFile(); | 1042 | file = new QTemporaryFile(); | ||
1045 | } | 1043 | } | ||
1046 | file->setAutoRemove(false); | 1044 | file->setAutoRemove(false); | ||
1047 | file->open(); | 1045 | file->open(); | ||
1048 | file->setPermissions(QFile::ReadUser); | 1046 | file->setPermissions(QFile::ReadUser); | ||
1049 | file->write(QByteArray::fromBase64(attachment->data())); | 1047 | file->write(QByteArray::fromBase64(attachment.data())); | ||
1050 | file->close(); | 1048 | file->close(); | ||
1051 | 1049 | | |||
1052 | KRun::RunFlags flags; | 1050 | KRun::RunFlags flags; | ||
1053 | flags |= KRun::DeleteTemporaryFiles; | 1051 | flags |= KRun::DeleteTemporaryFiles; | ||
1054 | bool stat = KRun::runUrl(QUrl::fromLocalFile(file->fileName()), attachment->mimeType(), nullptr, flags); | 1052 | bool stat = KRun::runUrl(QUrl::fromLocalFile(file->fileName()), attachment.mimeType(), nullptr, flags); | ||
1055 | delete file; | 1053 | delete file; | ||
1056 | return stat; | 1054 | return stat; | ||
1057 | } | 1055 | } | ||
1058 | return true; | 1056 | return true; | ||
1059 | } | 1057 | } | ||
1060 | 1058 | | |||
1061 | bool saveAsAttachment(const QString &name, const QString &iCal) const | 1059 | bool saveAsAttachment(const QString &name, const QString &iCal) const | ||
1062 | { | 1060 | { | ||
1063 | Attachment::Ptr a(findAttachment(name, iCal)); | 1061 | Attachment a(findAttachment(name, iCal)); | ||
1064 | if (!a) { | 1062 | if (a.isEmpty()) { | ||
1065 | return false; | 1063 | return false; | ||
1066 | } | 1064 | } | ||
1067 | 1065 | | |||
1068 | // get the saveas file name | 1066 | // get the saveas file name | ||
1069 | const QString saveAsFile = QFileDialog::getSaveFileName(nullptr, i18n("Save Invitation Attachment"), name, QString()); | 1067 | const QString saveAsFile = QFileDialog::getSaveFileName(nullptr, i18n("Save Invitation Attachment"), name, QString()); | ||
1070 | 1068 | | |||
1071 | if (saveAsFile.isEmpty()) { | 1069 | if (saveAsFile.isEmpty()) { | ||
1072 | return false; | 1070 | return false; | ||
1073 | } | 1071 | } | ||
1074 | 1072 | | |||
1075 | bool stat = false; | 1073 | bool stat = false; | ||
1076 | if (a->isUri()) { | 1074 | if (a.isUri()) { | ||
1077 | // save the attachment url | 1075 | // save the attachment url | ||
1078 | auto job = KIO::file_copy(QUrl(a->uri()), QUrl::fromLocalFile(saveAsFile)); | 1076 | auto job = KIO::file_copy(QUrl(a.uri()), QUrl::fromLocalFile(saveAsFile)); | ||
1079 | stat = job->exec(); | 1077 | stat = job->exec(); | ||
1080 | } else { | 1078 | } else { | ||
1081 | // put the attachment in a temporary file and save it | 1079 | // put the attachment in a temporary file and save it | ||
1082 | QTemporaryFile *file{ | 1080 | QTemporaryFile *file{ | ||
1083 | nullptr | 1081 | nullptr | ||
1084 | }; | 1082 | }; | ||
1085 | QMimeDatabase db; | 1083 | QMimeDatabase db; | ||
1086 | QStringList patterns = db.mimeTypeForName(a->mimeType()).globPatterns(); | 1084 | QStringList patterns = db.mimeTypeForName(a.mimeType()).globPatterns(); | ||
1087 | if (!patterns.empty()) { | 1085 | if (!patterns.empty()) { | ||
1088 | QString pattern = patterns.at(0); | 1086 | QString pattern = patterns.at(0); | ||
1089 | file = new QTemporaryFile(QDir::tempPath() + QStringLiteral("/messageviewer_XXXXXX") + pattern.remove(QLatin1Char('*'))); | 1087 | file = new QTemporaryFile(QDir::tempPath() + QStringLiteral("/messageviewer_XXXXXX") + pattern.remove(QLatin1Char('*'))); | ||
1090 | } else { | 1088 | } else { | ||
1091 | file = new QTemporaryFile(); | 1089 | file = new QTemporaryFile(); | ||
1092 | } | 1090 | } | ||
1093 | file->setAutoRemove(false); | 1091 | file->setAutoRemove(false); | ||
1094 | file->open(); | 1092 | file->open(); | ||
1095 | file->setPermissions(QFile::ReadUser); | 1093 | file->setPermissions(QFile::ReadUser); | ||
1096 | file->write(QByteArray::fromBase64(a->data())); | 1094 | file->write(QByteArray::fromBase64(a.data())); | ||
1097 | file->close(); | 1095 | file->close(); | ||
1098 | const QString filename = file->fileName(); | 1096 | const QString filename = file->fileName(); | ||
1099 | delete file; | 1097 | delete file; | ||
1100 | 1098 | | |||
1101 | auto job = KIO::file_copy(QUrl::fromLocalFile(filename), QUrl::fromLocalFile(saveAsFile)); | 1099 | auto job = KIO::file_copy(QUrl::fromLocalFile(filename), QUrl::fromLocalFile(saveAsFile)); | ||
1102 | stat = job->exec(); | 1100 | stat = job->exec(); | ||
1103 | } | 1101 | } | ||
1104 | return stat; | 1102 | return stat; | ||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |