9#include "attachmentpropertiesdialog.h"
11#include "attachmentfrommimecontentjob.h"
12#include "ui_attachmentpropertiesdialog.h"
13#include "ui_attachmentpropertiesdialog_readonly.h"
15#include "messagecore_debug.h"
18#include <KMime/Content>
19#include <KMime/Headers>
22#include <KLocalizedString>
23#include <QDesktopServices>
24#include <QDialogButtonBox>
25#include <QMimeDatabase>
31using namespace MessageCore;
33class Q_DECL_HIDDEN MessageCore::AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate
36 AttachmentPropertiesDialogPrivate(AttachmentPropertiesDialog *qq)
41 ~AttachmentPropertiesDialogPrivate()
49 void mimeTypeChanged(
const QString &type);
50 void populateEncodings();
51 void populateMimeTypes();
52 void populateWhatsThis();
56 AttachmentPropertiesDialog *
const q;
59 Ui::AttachmentPropertiesDialog *ui =
nullptr;
60 Ui::AttachmentPropertiesDialogReadOnly *uiReadOnly =
nullptr;
61 QVBoxLayout *mainLayout =
nullptr;
62 bool mReadOnly =
false;
65void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::init(
const AttachmentPart::Ptr &part,
bool readOnly)
71 mainLayout =
new QVBoxLayout;
72 q->setLayout(mainLayout);
74 mainLayout->addWidget(widget);
76 uiReadOnly =
new Ui::AttachmentPropertiesDialogReadOnly;
77 uiReadOnly->setupUi(widget);
79 ui =
new Ui::AttachmentPropertiesDialog;
88void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::polishUi()
91 QDialogButtonBox *buttonBox =
nullptr;
111 mainLayout->addWidget(buttonBox);
115void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::mimeTypeChanged(
const QString &type)
123 uiReadOnly->mimeIcon->setPixmap(pix);
125 ui->mimeIcon->setPixmap(pix);
129void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::populateWhatsThis()
133 const QString msgMimeType =
i18n(
134 "<p>The <em>MIME type</em> of the file:</p>"
135 "<p>Normally, you do not need to touch this setting, since the "
136 "type of the file is automatically checked; but, sometimes, %1 "
137 "may not detect the type correctly -- here is where you can fix "
141 const QString msgSize =
i18n(
142 "<p>The estimated size of the attachment:</p>"
143 "<p>Note that, in an email message, a binary file encoded with "
144 "base64 will take up four thirds the actual size of the file.</p>");
146 const QString msgName =
i18n(
147 "<p>The file name of the part:</p>"
148 "<p>Although this defaults to the name of the attached file, "
149 "it does not specify the file to be attached; rather, it "
150 "suggests a file name to be used by the recipient's mail agent "
151 "when saving the part to disk.</p>");
153 const QString msgDescription =
i18n(
154 "<p>A description of the part:</p>"
155 "<p>This is just an informational description of the part, "
156 "much like the Subject is for the whole message; most "
157 "mail agents will show this information in their message "
158 "previews alongside the attachment's icon.</p>");
160 const QString msgEncoding =
i18n(
161 "<p>The transport encoding of this part:</p>"
162 "<p>Normally, you do not need to change this, since %1 will use "
163 "a decent default encoding, depending on the MIME type; yet, "
164 "sometimes, you can significantly reduce the size of the "
165 "resulting message, e.g. if a PostScript file does not contain "
166 "binary data, but consists of pure text -- in this case, choosing "
167 "\"quoted-printable\" over the default \"base64\" will save up "
168 "to 25% in resulting message size.</p>",
171 const QString msgAutoDisplay =
i18n(
172 "<p>Check this option if you want to suggest to the "
173 "recipient the automatic (inline) display of this part in the "
174 "message preview, instead of the default icon view;</p>"
175 "<p>Technically, this is carried out by setting this part's "
176 "<em>Content-Disposition</em> header field to \"inline\" "
177 "instead of the default \"attachment\".</p>");
179 const QString msgSign =
i18n(
180 "<p>Check this option if you want this message part to be "
182 "<p>The signature will be made with the key that you associated "
183 "with the currently-selected identity.</p>");
185 const QString msgEncrypt =
i18n(
186 "<p>Check this option if you want this message part to be "
188 "<p>The part will be encrypted for the recipients of this "
192 uiReadOnly->size->setWhatsThis(msgSize);
193 uiReadOnly->name->setWhatsThis(msgName);
194 uiReadOnly->encoding->setWhatsThis(msgEncoding);
196 ui->mimeType->setWhatsThis(msgMimeType);
197 ui->size->setWhatsThis(msgSize);
198 ui->name->setWhatsThis(msgName);
199 ui->encrypt->setWhatsThis(msgEncrypt);
200 ui->sign->setWhatsThis(msgSign);
201 ui->autoDisplay->setWhatsThis(msgAutoDisplay);
202 ui->encoding->setWhatsThis(msgEncoding);
203 ui->description->setWhatsThis(msgDescription);
207void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::populateEncodings()
209 using namespace KMime;
210 using namespace KMime::Headers;
212 ui->encoding->clear();
213 ui->encoding->addItem(nameForEncoding(CE7Bit),
int(CE7Bit));
214 ui->encoding->addItem(nameForEncoding(CE8Bit),
int(CE8Bit));
215 ui->encoding->addItem(nameForEncoding(CEquPr),
int(CEquPr));
216 ui->encoding->addItem(nameForEncoding(CEbase64),
int(CEbase64));
225void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::populateMimeTypes()
227 const QStringList
list = QStringList() << QStringLiteral(
"text/html") << QStringLiteral(
"text/plain") << QStringLiteral(
"image/gif")
228 << QStringLiteral(
"image/jpeg") << QStringLiteral(
"image/png") << QStringLiteral(
"application/octet-stream")
229 << QStringLiteral(
"application/x-gunzip") << QStringLiteral(
"application/zip");
231 ui->mimeType->addItems(list);
234void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::loadFromPart()
242 uiReadOnly->name->setText(mPart->name().isEmpty() ? mPart->fileName() : mPart->name());
243 if (mPart->description().isEmpty()) {
244 uiReadOnly->description->hide();
245 uiReadOnly->descriptionLabel->hide();
247 uiReadOnly->description->setText(mPart->description());
249 uiReadOnly->encoding->setText(KMime::nameForEncoding(mPart->encoding()));
252 const int index = ui->mimeType->findText(mimeType);
254 ui->mimeType->insertItem(0, mimeType);
255 ui->mimeType->setCurrentIndex(0);
257 ui->mimeType->setCurrentIndex(index);
260 ui->name->setText(mPart->name().isEmpty() ? mPart->fileName() : mPart->name());
261 ui->description->setText(mPart->description());
262 ui->encoding->setCurrentIndex(
int(mPart->encoding()));
263 ui->autoDisplay->setChecked(mPart->isInline());
264 ui->encrypt->setChecked(mPart->isEncrypted());
265 ui->sign->setChecked(mPart->isSigned());
269static QString removeNewlines(
const QString &input)
272 ret.replace(QLatin1Char(
'\n'), QLatin1Char(
' '));
276void AttachmentPropertiesDialog::AttachmentPropertiesDialogPrivate::saveToPart()
279 Q_ASSERT(!mReadOnly);
284 mPart->setMimeType(ui->mimeType->currentText().toLatin1());
285 const QString
name = removeNewlines(ui->name->text());
286 mPart->setName(name);
287 mPart->setFileName(name);
288 mPart->setDescription(removeNewlines(ui->description->text()));
289 mPart->setInline(ui->autoDisplay->isChecked());
290 mPart->setSigned(ui->sign->isChecked());
291 mPart->setEncrypted(ui->encrypt->isChecked());
292 mPart->setInline(ui->autoDisplay->isChecked());
294 if (ui->mimeType->currentText().startsWith(QLatin1StringView(
"message")) && ui->encoding->itemData(ui->encoding->currentIndex()) != KMime::Headers::CE7Bit
295 && ui->encoding->itemData(ui->encoding->currentIndex()) != KMime::Headers::CE8Bit) {
296 qCWarning(MESSAGECORE_LOG) << R
"(Encoding on message/rfc822 must be "7bit" or "8bit".)";
299 mPart->setEncoding(KMime::Headers::contentEncoding(ui->encoding->itemData(ui->encoding->currentIndex()).toInt()));
304 , d(new AttachmentPropertiesDialogPrivate(this))
306 d->init(part, readOnly);
312 , d(new AttachmentPropertiesDialogPrivate(this))
317 qCCritical(MESSAGECORE_LOG) <<
"AttachmentFromMimeContentJob failed." << job->errorString();
335 return d->ui->encrypt->isEnabled();
343 d->ui->encrypt->setEnabled(
enabled);
350 return d->ui->sign->isEnabled();
358 d->ui->sign->setEnabled(
enabled);
362void AttachmentPropertiesDialog::accept()
373void invokeHelp(
const QString &docfile,
const QString &anchor)
377 url = QUrl(QStringLiteral(
"help:/")).
resolved(QUrl(docfile));
379 QUrlQuery
query(url);
380 query.addQueryItem(QStringLiteral(
"anchor"), anchor);
388void AttachmentPropertiesDialog::slotHelp()
390 invokeHelp(QStringLiteral(
"kmail2/the-composer-window.html"), QStringLiteral(
"attachments"));
393#include "moc_attachmentpropertiesdialog.cpp"
QSharedPointer< AttachmentPart > Ptr
Defines a pointer to an attachment object.
static KAboutData applicationData()
A job to load an attachment from a mime content.
QSharedPointer< AttachmentPart > Ptr
Defines a pointer to an attachment object.
AttachmentPart::Ptr attachmentPart() const
Returns the modified attachment.
bool isEncryptEnabled() const
Returns whether the encryption status of the attachment can be changed.
AttachmentPropertiesDialog(const AttachmentPart::Ptr &part, bool readOnly=false, QWidget *parent=nullptr)
Creates a new attachment properties dialog.
void setSignEnabled(bool enabled)
Sets whether the signature status of the attachment can be changed.
~AttachmentPropertiesDialog() override
Destroys the attachment properties dialog.
void setEncryptEnabled(bool enabled)
Sets whether the encryption status of the attachment can be changed.
bool isSignEnabled() const
Returns whether the signature status of the attachment can be changed.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
KCALUTILS_EXPORT QString mimeType()
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
void invokeHelp(const QString &anchor=QString(), const QString &appname=QString())
KIOCORE_EXPORT QString convertSize(KIO::filesize_t size)
QString name(const QVariant &location)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void currentTextChanged(const QString &text)
bool openUrl(const QUrl &url)
QDialog(QWidget *parent, Qt::WindowFlags f)
QPixmap pixmap(QWindow *window, const QSize &size, Mode mode, State state) const const
QIcon fromTheme(const QString &name)
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
QUrl resolved(const QUrl &relative) const const
void setQuery(const QString &query, ParsingMode mode)