Messagelib

attachmentclipboardjob.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
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
13using namespace MessageComposer;
14
15AttachmentClipBoardJob::AttachmentClipBoardJob(QObject *parent)
16 : MessageCore::AttachmentLoadJob(parent)
17{
18}
19
20AttachmentClipBoardJob::~AttachmentClipBoardJob() = default;
21
22void 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
36void 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, i18nc("@title:window", "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}
55
56#include "moc_attachmentclipboardjob.cpp"
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
void setAttachmentPart(const AttachmentPart::Ptr &part)
Subclasses use this method to set the loaded part.
A class that encapsulates an attachment.
QSharedPointer< AttachmentPart > Ptr
Defines a pointer to an attachment object.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
bool isEmpty() const const
QString text(Mode mode) const const
QClipboard * clipboard()
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
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.