File indexing completed on 2024-04-28 15:27:30

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2014 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef PASTEJOB_H
0009 #define PASTEJOB_H
0010 
0011 #include <QUrl>
0012 
0013 #include "kiowidgets_export.h"
0014 #include <kio/job_base.h>
0015 
0016 class QMimeData;
0017 
0018 namespace KIO
0019 {
0020 class PasteJobPrivate;
0021 /**
0022  * @class KIO::PasteJob pastejob.h <KIO/PasteJob>
0023  *
0024  * A KIO job that handles pasting the clipboard contents.
0025  *
0026  * If the clipboard contains URLs, they are copied to the destination URL.
0027  * If the clipboard contains data, it is saved into a file after asking
0028  * the user to choose a filename and the preferred data format.
0029  *
0030  * @see KIO::pasteClipboard
0031  * @since 5.4
0032  */
0033 class KIOWIDGETS_EXPORT PasteJob : public Job
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     ~PasteJob() override;
0039 
0040 Q_SIGNALS:
0041     /**
0042      * Signals that a file or directory was created.
0043      */
0044     void itemCreated(const QUrl &url);
0045 
0046 protected Q_SLOTS:
0047     void slotResult(KJob *job) override;
0048 
0049 protected:
0050     KIOWIDGETS_NO_EXPORT explicit PasteJob(PasteJobPrivate &dd);
0051 
0052 private:
0053     Q_DECLARE_PRIVATE(PasteJob)
0054 };
0055 
0056 /**
0057  * Pastes the clipboard contents.
0058  *
0059  * If the clipboard contains URLs, they are copied (or moved) to the destination URL,
0060  * using a KIO::CopyJob subjob.
0061  * Otherwise, the data from the clipboard is saved into a file using KIO::storedPut,
0062  * after asking the user to choose a filename and the preferred data format.
0063  *
0064  * This takes care of recording the subjob in the FileUndoManager, and emits
0065  * itemCreated for every file or directory being created, so that the view can select
0066  * these items.
0067  *
0068  * @param mimeData the MIME data to paste, usually QApplication::clipboard()->mimeData()
0069  * @param destDir The URL of the target directory
0070  * @param flags passed to the sub job
0071  *
0072  * @return A pointer to the job handling the operation.
0073  * @since 5.4
0074  */
0075 KIOWIDGETS_EXPORT PasteJob *paste(const QMimeData *mimeData, const QUrl &destDir, JobFlags flags = DefaultFlags);
0076 
0077 }
0078 
0079 #endif