File indexing completed on 2024-12-01 04:28:53

0001 /*
0002 SPDX-FileCopyrightText: 2016 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003 This file is part of Kdenlive. See www.kdenlive.org.
0004 
0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #pragma once
0009 
0010 #include "ui_managecache_ui.h"
0011 #include "definitions.h"
0012 #include <KIO/DirectorySizeJob>
0013 #include <QDir>
0014 #include <QTreeWidgetItem>
0015 #include <QDialog>
0016 
0017 class KdenliveDoc;
0018 class QPaintEvent;
0019 class QLabel;
0020 class QGridLayout;
0021 class QTreeWidget;
0022 class QPushButton;
0023 class QToolButton;
0024 
0025 /**
0026  * @class ChartWidget
0027  * @brief Chart drawing widget.
0028  *
0029  */
0030 class ChartWidget : public QWidget
0031 {
0032 public:
0033     explicit ChartWidget(QWidget *parent = nullptr);
0034     void setSegments(const QList<int> &segments);
0035     QColor colorAt(int pos) { return m_chartColors.at(pos); };
0036 
0037 protected:
0038     void paintEvent(QPaintEvent *event) override;
0039 
0040 private:
0041     QList<int> m_segments;
0042     QList<QColor> m_chartColors = {QColor(Qt::darkRed), QColor(Qt::darkBlue), QColor(Qt::darkGreen), QColor(Qt::darkMagenta), QColor(Qt::darkYellow)};
0043 };
0044 
0045 /** @class TreeWidgetItem
0046     @brief Manage custom sort order for size.
0047   */
0048 class TreeWidgetItem : public QTreeWidgetItem
0049 {
0050 public:
0051     TreeWidgetItem(QTreeWidget *parent)
0052         : QTreeWidgetItem(parent)
0053     {
0054     }
0055 
0056 private:
0057     bool operator<(const QTreeWidgetItem &other) const override
0058     {
0059         int column = treeWidget()->sortColumn();
0060         switch (column) {
0061             case 1:
0062                 return data(column, Qt::UserRole).toULongLong() < other.data(column, Qt::UserRole).toULongLong();
0063                 break;
0064             case 2:
0065                 return data(column, Qt::UserRole).toDateTime() < other.data(column, Qt::UserRole).toDateTime();
0066                 break;
0067             default:
0068                 return text(column).toLower() < other.text(column).toLower();
0069                 break;
0070         }
0071     }
0072 };
0073 
0074 /** @class TemporaryData
0075     @brief Dialog allowing management of cache data.
0076  */
0077 class TemporaryData : public QDialog, public Ui::ManageCache_UI
0078 {
0079     Q_OBJECT
0080 
0081 public:
0082     explicit TemporaryData(KdenliveDoc *doc, bool currentProjectOnly, QWidget *parent = nullptr);
0083 
0084 private:
0085     KdenliveDoc *m_doc;
0086     ChartWidget *m_currentPie;
0087     ChartWidget *m_globalPie;
0088     bool m_currentProjectOnly;
0089     KIO::filesize_t m_totalCurrent;
0090     KIO::filesize_t m_totalGlobal;
0091     KIO::filesize_t m_totalBackup;
0092     KIO::filesize_t m_totalProxy;
0093     QList<KIO::filesize_t> m_currentSizes;
0094     QStringList m_globalDirectories;
0095     QString m_processingDirectory;
0096     QDir m_globalDir;
0097     QStringList m_proxies;
0098     void updateDataInfo();
0099     void updateGlobalInfo();
0100     void updateTotal();
0101     void processglobalDirectories();
0102     void processBackupDirectories();
0103     void processProxyDirectory();
0104     void deleteCache(QStringList &folders);
0105     /** @brief
0106      * Check if size of cache + backup data exceeds a limit and warn user
0107      **/
0108     void refreshWarningMessage();
0109 
0110 private Q_SLOTS:
0111     void gotPreviewSize(KJob *job);
0112     void gotProxySize(KIO::filesize_t total);
0113     void gotAudioSize(KJob *job);
0114     void gotSequenceSize(KJob *job);
0115     void gotThumbSize(KJob *job);
0116     void gotFolderSize(KJob *job);
0117     void gotBackupSize(KJob *job);
0118     void gotProjectProxySize(KJob *job);
0119     void refreshGlobalPie();
0120     void deletePreview();
0121     void deleteProjectProxy();
0122     void deleteProxy();
0123     void deleteAudio();
0124     void deleteThumbs();
0125     void deleteCurrentCacheData(bool warn = true);
0126     void deleteBackup();
0127     void cleanBackup();
0128     void openCacheFolder();
0129     void deleteSelected();
0130     void cleanCache();
0131     void cleanProxy();
0132     /** @brief
0133      * Cleanup cached data and backup
0134      **/
0135     void slotCleanUp();
0136 
0137 Q_SIGNALS:
0138     void disableProxies();
0139     void disablePreview();
0140 };