aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Mardelle <[email protected]>2016-06-08 00:59:16 +0200
committerJean-Baptiste Mardelle <[email protected]>2016-06-08 01:00:33 +0200
commit9ef1675b47440d3699b00291c83fdc497123bec2 (patch)
treede54241aee01eb29586fde157da7e3d3fce90f55
parentfb3e5ef044636cdd61a92d92c0c9c24a82ca9560 (diff)
Add global cache data management (WIP), available in the second tab of project cache
from timeline preview menu
-rw-r--r--src/definitions.h11
-rw-r--r--src/doc/kdenlivedoc.cpp3
-rw-r--r--src/mainwindow.cpp3
-rw-r--r--src/project/dialogs/temporarydata.cpp166
-rw-r--r--src/project/dialogs/temporarydata.h42
-rw-r--r--src/project/projectmanager.cpp8
6 files changed, 217 insertions, 16 deletions
diff --git a/src/definitions.h b/src/definitions.h
index 96d099d..9682b8a 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -161,11 +161,12 @@ enum ClipJobStatus {
};
enum CacheType {
- CacheBase = 0,
- CachePreview = 1,
- CacheProxy = 2,
- CacheAudio = 3,
- CacheThumbs = 4
+ CacheRoot = 0,
+ CacheBase = 1,
+ CachePreview = 2,
+ CacheProxy = 3,
+ CacheAudio = 4,
+ CacheThumbs = 5
};
class TrackInfo {
diff --git a/src/doc/kdenlivedoc.cpp b/src/doc/kdenlivedoc.cpp
index 75a3c5c..ee119f4 100644
--- a/src/doc/kdenlivedoc.cpp
+++ b/src/doc/kdenlivedoc.cpp
@@ -1757,6 +1757,9 @@ QDir KdenliveDoc::getCacheDir(CacheType type, bool *ok) const
}
QString basePath = kdenliveCacheDir + "/" + documentId;
switch (type) {
+ case CacheRoot:
+ basePath = kdenliveCacheDir;
+ break;
case CachePreview:
basePath.append(QStringLiteral("/preview"));
break;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 70adf51..83b25cb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -3593,8 +3593,9 @@ void MainWindow::showTimelineToolbarMenu(const QPoint &pos)
void MainWindow::slotManageCache()
{
QDialog d(this);
+ d.setWindowTitle(i18n("Manage Cache Data"));
QVBoxLayout *lay = new QVBoxLayout;
- TemporaryData tmp(pCore->projectManager()->current(), true, this);
+ TemporaryData tmp(pCore->projectManager()->current(), false, this);
connect(&tmp, SIGNAL(disableProxies()), this, SLOT(slotDisableProxies()));
connect(&tmp, SIGNAL(disablePreview()), pCore->projectManager()->currentTimeline(), SLOT(invalidateRange()));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
diff --git a/src/project/dialogs/temporarydata.cpp b/src/project/dialogs/temporarydata.cpp
index 7ed60cc..b36fb9d 100644
--- a/src/project/dialogs/temporarydata.cpp
+++ b/src/project/dialogs/temporarydata.cpp
@@ -39,9 +39,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QStandardPaths>
#include <QToolButton>
#include <QDesktopServices>
+#include <QTreeWidget>
+#include <QPushButton>
static QList <QColor> chartColors;
+
ChartWidget::ChartWidget(QWidget * parent) :
QWidget(parent)
{
@@ -185,16 +188,16 @@ TemporaryData::TemporaryData(KdenliveDoc *doc, bool currentProjectOnly, QWidget
if (currentProjectOnly) {
lay->addWidget(m_currentPage);
+ QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
+ lay->addSpacerItem(spacer);
} else {
QTabWidget *tab = new QTabWidget(this);
tab->addTab(m_currentPage, i18n("Current Project"));
- QWidget *allProjects = new QWidget(this);
- tab->addTab(allProjects, i18n("All Projects"));
+ m_globalPage = new QWidget(this);
+ buildGlobalCacheDialog(minHeight);
+ tab->addTab(m_globalPage, i18n("All Projects"));
lay->addWidget(tab);
}
-
- QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
- lay->addSpacerItem(spacer);
setLayout(lay);
updateDataInfo();
}
@@ -234,7 +237,7 @@ void TemporaryData::updateDataInfo()
void TemporaryData::gotPreviewSize(KJob *job)
{
- KIO::DirectorySizeJob *sourceJob = (KIO::DirectorySizeJob *) job;
+ KIO::DirectorySizeJob *sourceJob = static_cast<KIO::DirectorySizeJob *> (job);
qulonglong total = sourceJob->totalSize();
if (sourceJob->totalFiles() == 0) {
total = 0;
@@ -251,7 +254,7 @@ void TemporaryData::gotPreviewSize(KJob *job)
void TemporaryData::gotProxySize(KJob *job)
{
- KIO::DirectorySizeJob *sourceJob = (KIO::DirectorySizeJob *) job;
+ KIO::DirectorySizeJob *sourceJob = static_cast<KIO::DirectorySizeJob *> (job);
qulonglong total = sourceJob->totalSize();
if (sourceJob->totalFiles() == 0) {
total = 0;
@@ -268,7 +271,7 @@ void TemporaryData::gotProxySize(KJob *job)
void TemporaryData::gotAudioSize(KJob *job)
{
- KIO::DirectorySizeJob *sourceJob = (KIO::DirectorySizeJob *) job;
+ KIO::DirectorySizeJob *sourceJob = static_cast<KIO::DirectorySizeJob *> (job);
qulonglong total = sourceJob->totalSize();
if (sourceJob->totalFiles() == 0) {
total = 0;
@@ -285,7 +288,7 @@ void TemporaryData::gotAudioSize(KJob *job)
void TemporaryData::gotThumbSize(KJob *job)
{
- KIO::DirectorySizeJob *sourceJob = (KIO::DirectorySizeJob *) job;
+ KIO::DirectorySizeJob *sourceJob = static_cast<KIO::DirectorySizeJob *> (job);
qulonglong total = sourceJob->totalSize();
if (sourceJob->totalFiles() == 0) {
total = 0;
@@ -416,3 +419,148 @@ void TemporaryData::openCacheFolder()
}
QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
}
+
+void TemporaryData::buildGlobalCacheDialog(int minHeight)
+{
+ QGridLayout *lay = new QGridLayout;
+ m_globalPie = new ChartWidget(this);
+ lay->addWidget(m_globalPie, 0, 0, 1, 1);
+ m_listWidget = new QTreeWidget(this);
+ m_listWidget->setColumnCount(3);
+ m_listWidget->setHeaderLabels(QStringList() << i18n("Folder") << i18n("Size") << i18n("Date"));
+ m_listWidget->setRootIsDecorated(false);
+ m_listWidget->setAlternatingRowColors(true);
+ m_listWidget->setSortingEnabled(true);
+ m_listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ lay->addWidget(m_listWidget, 0, 1, 1, 4);
+ m_globalPage->setLayout(lay);
+
+ // Total Cache data
+ QPalette pal = palette();
+ QLabel *color = new QLabel(this);
+ color->setFixedSize(minHeight, minHeight);
+ pal.setColor(QPalette::Window, chartColors.at(0));
+ color->setPalette(pal);
+ color->setAutoFillBackground(true);
+ lay->addWidget(color, 1, 1, Qt::AlignCenter);
+ QLabel *lab = new QLabel(i18n("Total Cached Data"), this);
+ lay->addWidget(lab, 1, 2, 1, 1);
+ m_globalSize = new QLabel(this);
+ lay->addWidget(m_globalSize, 1, 3, 1, 1);
+
+ // Selection
+ color = new QLabel(this);
+ color->setFixedSize(minHeight, minHeight);
+ pal.setColor(QPalette::Window, chartColors.at(1));
+ color->setPalette(pal);
+ color->setAutoFillBackground(true);
+ lay->addWidget(color, 2, 1, Qt::AlignCenter);
+ lab = new QLabel(i18n("Selected Cached Data"), this);
+ lay->addWidget(lab, 2, 2, 1, 1);
+ m_selectedSize = new QLabel(this);
+ lay->addWidget(m_selectedSize, 2, 3, 1, 1);
+ QPushButton *del = new QPushButton(i18n("Delete selected cache"), this);
+ connect(del, &QPushButton::clicked, this, &TemporaryData::deleteSelected);
+ lay->addWidget(del, 2, 4, 1, 1);
+
+ lay->setColumnStretch(4, 10);
+ lay->setRowStretch(0, 10);
+ connect(m_listWidget, &QTreeWidget::itemSelectionChanged, this, &TemporaryData::refreshGlobalPie);
+ updateGlobalInfo();
+}
+
+void TemporaryData::updateGlobalInfo()
+{
+ m_totalGlobal = 0;
+ m_listWidget->clear();
+ bool ok = false;
+ QDir preview = m_doc->getCacheDir(CacheRoot, &ok);
+ if (!ok) {
+ m_globalPage->setEnabled(false);
+ return;
+ }
+ m_globalDir = preview;
+ m_globalDirectories.clear();
+ m_processingDirectory.clear();
+ m_globalDirectories = m_globalDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ processglobalDirectories();
+}
+
+void TemporaryData::processglobalDirectories()
+{
+ if (m_globalDirectories.isEmpty())
+ return;
+ m_processingDirectory = m_globalDirectories.takeFirst();
+ KIO::DirectorySizeJob *job = KIO::directorySize(QUrl::fromLocalFile(m_globalDir.absoluteFilePath(m_processingDirectory)));
+ connect(job, &KIO::DirectorySizeJob::result, this, &TemporaryData::gotFolderSize);
+}
+
+void TemporaryData::gotFolderSize(KJob *job)
+{
+ KIO::DirectorySizeJob *sourceJob = static_cast<KIO::DirectorySizeJob *> (job);
+ qulonglong total = sourceJob->totalSize();
+ if (sourceJob->totalFiles() == 0) {
+ total = 0;
+ }
+ m_totalGlobal += total;
+ TreeWidgetItem *item = new TreeWidgetItem(m_listWidget);
+ // Check last save path for this cache folder
+ QDir dir(m_globalDir.absoluteFilePath(m_processingDirectory));
+ QStringList filters;
+ filters << QStringLiteral("*.kdenlive");
+ QStringList str = dir.entryList(filters, QDir::Files | QDir::Hidden, QDir::Time);
+ if (!str.isEmpty()) {
+ QString path = QUrl::fromPercentEncoding(str.at(0).toUtf8());
+ // Remove leading dot
+ path.remove(0, 1);
+ item->setText(0, m_processingDirectory + QString(" (%1)").arg(QUrl::fromLocalFile(path).fileName()));
+ if (QFile::exists(path)) {
+ item->setIcon(0, KoIconUtils::themedIcon("kdenlive"));
+ } else {
+ item->setIcon(0, KoIconUtils::themedIcon("dialog-close"));
+ }
+ } else {
+ item->setText(0, m_processingDirectory);
+ }
+ item->setData(0, Qt::UserRole, m_processingDirectory);
+ item->setText(1, KIO::convertSize(total));
+ QDateTime date = QFileInfo(dir.absolutePath()).lastModified();
+ item->setText(2, date.toString(Qt::SystemLocaleShortDate));
+ item->setData(1, Qt::UserRole, total);
+ item->setData(2, Qt::UserRole, date);
+ m_listWidget->addTopLevelItem(item);
+ m_listWidget->resizeColumnToContents(0);
+ m_listWidget->resizeColumnToContents(1);
+ if (m_globalDirectories.isEmpty()) {
+ m_globalSize->setText(KIO::convertSize(m_totalGlobal));
+ m_listWidget->setCurrentItem(m_listWidget->topLevelItem(0));
+ } else {
+ processglobalDirectories();
+ }
+}
+
+void TemporaryData::refreshGlobalPie()
+{
+ QList<QTreeWidgetItem *> list = m_listWidget->selectedItems();
+ qulonglong currentSize = 0;
+ foreach(QTreeWidgetItem *current, list) {
+ if (current) {
+ currentSize += current->data(1, Qt::UserRole).toULongLong();
+ }
+ }
+ m_selectedSize->setText(KIO::convertSize(currentSize));
+ int percent = (int) (currentSize * 360 / m_totalGlobal);
+ m_globalPie->setSegments(QList <int>() << 360 << percent);
+}
+
+void TemporaryData::deleteSelected()
+{
+ QList<QTreeWidgetItem *> list = m_listWidget->selectedItems();
+ QStringList folders;
+ foreach(QTreeWidgetItem *current, list) {
+ if (current) {
+ folders << current->data(0, Qt::UserRole).toString();
+ }
+ }
+ KMessageBox::warningContinueCancelList(this, i18n("Delete the following cache folders from\n%1", m_globalDir.absolutePath()), folders);
+}
diff --git a/src/project/dialogs/temporarydata.h b/src/project/dialogs/temporarydata.h
index 1015859..cd70b54 100644
--- a/src/project/dialogs/temporarydata.h
+++ b/src/project/dialogs/temporarydata.h
@@ -25,12 +25,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "definitions.h"
#include <QWidget>
+#include <QDir>
class KdenliveDoc;
class KJob;
class QPaintEvent;
class QLabel;
class QGridLayout;
+class QTreeWidget;
/**
* @class ChartWidget
@@ -50,6 +52,30 @@ private:
QList <int> m_segments;
};
+
+/**
+ * @class TreeWidgetItem
+ * @brief Manage custom sort order for size.
+ *
+ */
+
+class TreeWidgetItem : public QTreeWidgetItem {
+ public:
+ TreeWidgetItem(QTreeWidget* parent):QTreeWidgetItem(parent){}
+ private:
+ bool operator<(const QTreeWidgetItem &other)const {
+ int column = treeWidget()->sortColumn();
+ switch (column) {
+ case 0:
+ return text(column).toLower() < other.text(column).toLower();
+ break;
+ default:
+ return data(column, Qt::UserRole) < other.data(column, Qt::UserRole);
+ break;
+ }
+ }
+};
+
/**
* @class TemporaryData
* @brief Dialog allowing management of project's temporary data.
@@ -66,29 +92,45 @@ public:
private:
KdenliveDoc *m_doc;
ChartWidget *m_currentPie;
+ ChartWidget *m_globalPie;
QLabel *m_previewSize;
QLabel *m_proxySize;
QLabel *m_audioSize;
QLabel *m_thumbSize;
QLabel *m_currentSize;
+ QLabel *m_globalSize;
+ QLabel *m_selectedSize;
QWidget *m_currentPage;
+ QWidget *m_globalPage;
+ QTreeWidget *m_listWidget;
QGridLayout *m_grid;
qulonglong m_totalCurrent;
+ qulonglong m_totalGlobal;
QList <qulonglong> mCurrentSizes;
+ QList <qulonglong> mGlobalSizes;
+ QStringList m_globalDirectories;
+ QString m_processingDirectory;
+ QDir m_globalDir;
void updateDataInfo();
+ void updateGlobalInfo();
void updateTotal();
+ void buildGlobalCacheDialog(int minHeight);
+ void processglobalDirectories();
private slots:
void gotPreviewSize(KJob *job);
void gotProxySize(KJob *job);
void gotAudioSize(KJob *job);
void gotThumbSize(KJob *job);
+ void gotFolderSize(KJob *job);
+ void refreshGlobalPie();
void deletePreview();
void deleteProxy();
void deleteAudio();
void deleteThumbs();
void deleteAll();
void openCacheFolder();
+ void deleteSelected();
signals:
void disableProxies();
diff --git a/src/project/projectmanager.cpp b/src/project/projectmanager.cpp
index 14f2339..71bc062 100644
--- a/src/project/projectmanager.cpp
+++ b/src/project/projectmanager.cpp
@@ -325,7 +325,13 @@ bool ProjectManager::saveFileAs()
return saveFileAs();
}
}
-
+ bool ok = false;
+ QDir cacheDir = m_project->getCacheDir(CacheBase, &ok);
+ if (ok) {
+ QFile file(cacheDir.absoluteFilePath(QUrl::toPercentEncoding("." + outputFile)));
+ file.open(QIODevice::ReadWrite | QIODevice::Text);
+ file.close();
+ }
return saveFileAs(outputFile);
}