File indexing completed on 2024-04-21 04:51:54

0001 /*
0002     SPDX-FileCopyrightText: 2011 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003     SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartalb.uber.space>
0004 
0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #pragma once
0009 
0010 #include "ui_archivewidget_ui.h"
0011 #include "timeline2/model/timelinemodel.hpp"
0012 
0013 #include <KIO/CopyJob>
0014 #include <QTemporaryFile>
0015 #include <kio/global.h>
0016 
0017 #include <QDialog>
0018 #include <QDomDocument>
0019 #include <QFuture>
0020 #include <memory>
0021 
0022 class KJob;
0023 class KArchive;
0024 
0025 class KMessageWidget;
0026 
0027 /** @class ArchiveWidget
0028     @brief A widget allowing to archive a project (copy all project files to a new location)
0029     @author Jean-Baptiste Mardelle
0030  */
0031 class ArchiveWidget : public QDialog, public Ui::ArchiveWidget_UI
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     ArchiveWidget(const QString &projectName, const QString &xmlData, const QStringList &luma_list, const QStringList &other_list, QWidget *parent = nullptr);
0037     // Constructor for extracting widget
0038     explicit ArchiveWidget(QUrl url, QWidget *parent = nullptr);
0039     ~ArchiveWidget() override;
0040 
0041     QString extractedProjectFile() const;
0042 
0043 private Q_SLOTS:
0044     void slotCheckSpace();
0045     bool slotStartArchiving(bool firstPass = true);
0046     void slotArchivingFinished(KJob *job = nullptr, bool finished = false);
0047     void slotArchivingProgress(KJob *, qulonglong);
0048     void done(int r) Q_DECL_OVERRIDE;
0049     bool closeAccepted();
0050     void createArchive();
0051     void slotArchivingIntProgress(int);
0052     void slotArchivingBoolFinished(bool result, const QString &errorString);
0053     void slotStartExtracting();
0054     void doExtracting();
0055     void slotExtractingFinished();
0056     void slotExtractProgress();
0057     void slotGotProgress(KJob *);
0058     void openArchiveForExtraction();
0059     void slotDisplayMessage(const QString &icon, const QString &text);
0060     void slotJobResult(bool success, const QString &text);
0061     void slotProxyOnly(int onlyProxy);
0062     void onlyTimelineItems(int onlyTimeline);
0063 
0064 protected:
0065     void closeEvent(QCloseEvent *e) override;
0066 
0067 private:
0068     enum {
0069         ClipIdRole = Qt::UserRole + 1,
0070         SlideshowImagesRole,
0071         SlideshowSizeRole,
0072         IsInTimelineRole,
0073     };
0074     KIO::filesize_t m_requestedSize, m_timelineSize;
0075     KIO::CopyJob *m_copyJob;
0076     QMap<QUrl, QUrl> m_duplicateFiles;
0077     QMap<QUrl, QUrl> m_replacementList;
0078     QString m_name;
0079     QString m_archiveName;
0080     QDomDocument m_doc;
0081     QTemporaryFile *m_temp;
0082     bool m_abortArchive;
0083     QFuture<void> m_archiveThread;
0084     QStringList m_foldersList;
0085     QMap<QString, QString> m_filesList;
0086     QStringList m_processedFiles;
0087     bool m_extractMode;
0088     QUrl m_extractUrl;
0089     QString m_projectName;
0090     QTimer *m_progressTimer;
0091     KArchive *m_archive;
0092     int m_missingClips;
0093     KMessageWidget *m_infoMessage;
0094 
0095     /** @brief Generate tree widget subitems from a string list of urls. */
0096     void generateItems(QTreeWidgetItem *parentItem, const QStringList &items);
0097     /** @brief Generate tree widget subitems from a map of clip ids / urls. */
0098     void generateItems(QTreeWidgetItem *parentItem, const QMap<QString, QString> &items);
0099     /** @brief Make urls in the given playlist file (*.mlt) relative.
0100     * @param filename the url of the *.mlt file
0101     * @returns the files content with replaced urls
0102     */
0103     QString processPlaylistFile(const QString &filename);
0104     /** @brief Make urls in project file relative */
0105     bool processProjectFile();
0106     /** @brief Replace urls in mlt doc.
0107     * @param doc the xml document
0108     * @param destPrefix (optional) prefix to put before each new file path
0109     * @returns the doc's content with replaced urls
0110     */
0111     QString processMltFile(const QDomDocument &doc, const QString &destPrefix = QString());
0112     void processElement(QDomElement e, const QString root);
0113     /** @brief If the given element contains the property its content (url) will be converted to a relative file path
0114      *  @param e the dom element  that might contains the property
0115      *  @param propertyName name of the property that should be checked
0116      *  @param root rootpath of the parent mlt document
0117     */
0118     void propertyProcessUrl(const QDomElement &e, const QString &propertyName, const QString &root);
0119 
0120 Q_SIGNALS:
0121     void archivingFinished(bool, const QString &);
0122     void archiveProgress(int);
0123     void extractingFinished();
0124     void showMessage(const QString &, const QString &);
0125 };