File indexing completed on 2024-12-08 03:40:50

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 CopyJob;
0021 class PasteJobPrivate;
0022 /**
0023  * @class KIO::PasteJob pastejob.h <KIO/PasteJob>
0024  *
0025  * A KIO job that handles pasting the clipboard contents.
0026  *
0027  * If the clipboard contains URLs, they are copied to the destination URL.
0028  * If the clipboard contains data, it is saved into a file after asking
0029  * the user to choose a filename and the preferred data format.
0030  *
0031  * @see KIO::pasteClipboard
0032  * @since 5.4
0033  */
0034 class KIOWIDGETS_EXPORT PasteJob : public Job
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     ~PasteJob() override;
0040 
0041 Q_SIGNALS:
0042     /**
0043      * Signals that a file or directory was created.
0044      */
0045     void itemCreated(const QUrl &url);
0046 
0047     /**
0048      * Emitted when a copy job was started as subjob as part of pasting. Note that a
0049      * CopyJob isn't always started by PasteJob. For instance pasting image content will create a file.
0050      *
0051      * You can use @p job to monitor the progress of the copy/move/link operation.
0052      *
0053      * @param job the job started for moving, copying or symlinking files
0054      * @since 6.0
0055      */
0056     void copyJobStarted(KIO::CopyJob *job);
0057 
0058 protected Q_SLOTS:
0059     void slotResult(KJob *job) override;
0060 
0061 protected:
0062     KIOWIDGETS_NO_EXPORT explicit PasteJob(PasteJobPrivate &dd);
0063 
0064 private:
0065     Q_DECLARE_PRIVATE(PasteJob)
0066 };
0067 
0068 /**
0069  * Pastes the clipboard contents.
0070  *
0071  * If the clipboard contains URLs, they are copied (or moved) to the destination URL,
0072  * using a KIO::CopyJob subjob.
0073  * Otherwise, the data from the clipboard is saved into a file using KIO::storedPut,
0074  * after asking the user to choose a filename and the preferred data format.
0075  *
0076  * This takes care of recording the subjob in the FileUndoManager, and emits
0077  * itemCreated for every file or directory being created, so that the view can select
0078  * these items.
0079  *
0080  * @param mimeData the MIME data to paste, usually QApplication::clipboard()->mimeData()
0081  * @param destDir The URL of the target directory
0082  * @param flags passed to the sub job
0083  *
0084  * @return A pointer to the job handling the operation.
0085  * @since 5.4
0086  */
0087 KIOWIDGETS_EXPORT PasteJob *paste(const QMimeData *mimeData, const QUrl &destDir, JobFlags flags = DefaultFlags);
0088 
0089 }
0090 
0091 #endif