Messagelib

attachmentclipboardjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2020 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()
21 {
22 }
23 
24 void AttachmentClipBoardJob::addAttachment(const QByteArray &data, const QString &attachmentName)
25 {
27  if (!data.isEmpty()) {
28  attachment->setName(attachmentName);
29  attachment->setFileName(attachmentName);
30  attachment->setData(data);
31  attachment->setMimeType("text/plain");
32  // TODO what about the other fields?
33  }
34  setAttachmentPart(attachment);
35  emitResult(); // Success.
36 }
37 
38 void AttachmentClipBoardJob::doStart()
39 {
41  const QString clipText = clip->text();
42  if (clipText.isEmpty()) {
43  setError(KJob::UserDefinedError);
44  setErrorText(i18n("No text found in Clipboard"));
45  emitResult();
46  } else {
47  bool ok = false;
48  QString attachmentName = QInputDialog::getText(nullptr, i18n("Define Attachment Name"), i18n("Attachment Name:"), {}, {}, &ok);
49  if (ok) {
50  if (attachmentName.isEmpty()) {
51  attachmentName = i18n("Clipboard Text");
52  }
53  addAttachment(clipText.toUtf8(), attachmentName);
54  }
55  }
56 }
bool isEmpty() const const
bool isEmpty() const const
A class that encapsulates an attachment.
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
QString i18n(const char *text, const TYPE &arg...)
QString text(QClipboard::Mode mode) const const
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QSharedPointer< AttachmentPart > Ptr
Defines a pointer to an attachment object.
QClipboard * clipboard()
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Sep 21 2020 23:14:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.