Messagelib

attachmentclipboardjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "attachmentclipboardjob.h"
8 #include <KLocalizedString>
9 #include <QApplication>
10 #include <QClipboard>
11 #include <QInputDialog>
12 
13 using namespace MessageComposer;
14 
15 AttachmentClipBoardJob::AttachmentClipBoardJob(QObject *parent)
16  : MessageCore::AttachmentLoadJob(parent)
17 {
18 }
19 
20 AttachmentClipBoardJob::~AttachmentClipBoardJob() = default;
21 
22 void AttachmentClipBoardJob::addAttachment(const QByteArray &data, const QString &attachmentName)
23 {
25  if (!data.isEmpty()) {
26  attachment->setName(attachmentName);
27  attachment->setFileName(attachmentName);
28  attachment->setData(data);
29  attachment->setMimeType("text/plain");
30  // TODO what about the other fields?
31  }
32  setAttachmentPart(attachment);
33  emitResult(); // Success.
34 }
35 
36 void AttachmentClipBoardJob::doStart()
37 {
39  const QString clipText = clip->text();
40  if (clipText.isEmpty()) {
41  setError(KJob::UserDefinedError);
42  setErrorText(i18n("No text found in Clipboard"));
43  emitResult();
44  } else {
45  bool ok = false;
46  QString attachmentName = QInputDialog::getText(nullptr, i18n("Define Attachment Name"), i18n("Attachment Name:"), {}, {}, &ok);
47  if (ok) {
48  if (attachmentName.isEmpty()) {
49  attachmentName = i18n("Clipboard Text");
50  }
51  addAttachment(clipText.toUtf8(), attachmentName);
52  }
53  }
54 }
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
A class that encapsulates an attachment.
QClipboard * clipboard()
QString i18n(const char *text, const TYPE &arg...)
QSharedPointer< AttachmentPart > Ptr
Defines a pointer to an attachment object.
bool isEmpty() const const
QByteArray toUtf8() const const
QString text(QClipboard::Mode mode) const const
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri May 20 2022 04:13:28 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.