1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2014 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef PASTEJOB_H
9#define PASTEJOB_H
10
11#include <QUrl>
12
13#include "kiowidgets_export.h"
14#include <kio/job_base.h>
15
16class QMimeData;
17
18namespace KIO
19{
20class CopyJob;
21class PasteJobPrivate;
22/*!
23 * \class KIO::PasteJob
24 * \inheaderfile KIO/PasteJob
25 * \inmodule KIOWidgets
26 *
27 * \brief A KIO job that handles pasting the clipboard contents.
28 *
29 * If the clipboard contains URLs, they are copied to the destination URL.
30 * If the clipboard contains data, it is saved into a file after asking
31 * the user to choose a filename and the preferred data format.
32 *
33 * \sa KIO::paste
34 * \since 5.4
35 */
36class KIOWIDGETS_EXPORT PasteJob : public Job
37{
38 Q_OBJECT
39
40public:
41 ~PasteJob() override;
42
43Q_SIGNALS:
44 /*!
45 * Signals that a file or directory was created.
46 */
47 void itemCreated(const QUrl &url);
48
49 /*!
50 * Emitted when a copy job was started as subjob as part of pasting. Note that a
51 * CopyJob isn't always started by PasteJob. For instance pasting image content will create a file.
52 *
53 * You can use \a job to monitor the progress of the copy/move/link operation.
54 *
55 * \a job the job started for moving, copying or symlinking files
56 * \since 6.0
57 */
58 void copyJobStarted(KIO::CopyJob *job);
59
60protected Q_SLOTS:
61 void slotResult(KJob *job) override;
62
63protected:
64 KIOWIDGETS_NO_EXPORT explicit PasteJob(PasteJobPrivate &dd);
65
66private:
67 Q_DECLARE_PRIVATE(PasteJob)
68};
69
70/*!
71 * \relates KIO::PasteJob
72 *
73 * Pastes the clipboard contents.
74 *
75 * If the clipboard contains URLs, they are copied (or moved) to the destination URL,
76 * using a KIO::CopyJob subjob.
77 * Otherwise, the data from the clipboard is saved into a file using KIO::storedPut,
78 * after asking the user to choose a filename and the preferred data format.
79 *
80 * This takes care of recording the subjob in the FileUndoManager, and emits
81 * itemCreated for every file or directory being created, so that the view can select
82 * these items.
83 *
84 * \a mimeData the MIME data to paste, usually QApplication::clipboard()->mimeData()
85 *
86 * \a destDir The URL of the target directory
87 *
88 * \a flags passed to the sub job
89 *
90 * Returns a pointer to the job handling the operation.
91 * \since 5.4
92 */
93KIOWIDGETS_EXPORT PasteJob *paste(const QMimeData *mimeData, const QUrl &destDir, JobFlags flags = DefaultFlags);
94
95}
96
97#endif
98

source code of kio/src/widgets/pastejob.h