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 pastejob.h <KIO/PasteJob>
24 *
25 * A KIO job that handles pasting the clipboard contents.
26 *
27 * If the clipboard contains URLs, they are copied to the destination URL.
28 * If the clipboard contains data, it is saved into a file after asking
29 * the user to choose a filename and the preferred data format.
30 *
31 * @see KIO::pasteClipboard
32 * @since 5.4
33 */
34class KIOWIDGETS_EXPORT PasteJob : public Job
35{
36 Q_OBJECT
37
38public:
39 ~PasteJob() override;
40
41Q_SIGNALS:
42 /**
43 * Signals that a file or directory was created.
44 */
45 void itemCreated(const QUrl &url);
46
47 /**
48 * Emitted when a copy job was started as subjob as part of pasting. Note that a
49 * CopyJob isn't always started by PasteJob. For instance pasting image content will create a file.
50 *
51 * You can use @p job to monitor the progress of the copy/move/link operation.
52 *
53 * @param job the job started for moving, copying or symlinking files
54 * @since 6.0
55 */
56 void copyJobStarted(KIO::CopyJob *job);
57
58protected Q_SLOTS:
59 void slotResult(KJob *job) override;
60
61protected:
62 KIOWIDGETS_NO_EXPORT explicit PasteJob(PasteJobPrivate &dd);
63
64private:
65 Q_DECLARE_PRIVATE(PasteJob)
66};
67
68/**
69 * Pastes the clipboard contents.
70 *
71 * If the clipboard contains URLs, they are copied (or moved) to the destination URL,
72 * using a KIO::CopyJob subjob.
73 * Otherwise, the data from the clipboard is saved into a file using KIO::storedPut,
74 * after asking the user to choose a filename and the preferred data format.
75 *
76 * This takes care of recording the subjob in the FileUndoManager, and emits
77 * itemCreated for every file or directory being created, so that the view can select
78 * these items.
79 *
80 * @param mimeData the MIME data to paste, usually QApplication::clipboard()->mimeData()
81 * @param destDir The URL of the target directory
82 * @param flags passed to the sub job
83 *
84 * @return A pointer to the job handling the operation.
85 * @since 5.4
86 */
87KIOWIDGETS_EXPORT PasteJob *paste(const QMimeData *mimeData, const QUrl &destDir, JobFlags flags = DefaultFlags);
88
89}
90
91#endif
92

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