Commit b7d9ce97 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add a max cache size config setting so that we can check if the total cached...

Add a max cache size config setting so that we can check if the total cached data exceeds this limit and warn user
parent afcb0a6a
......@@ -569,6 +569,11 @@
<default>/tmp/</default>
</entry>
<entry name="maxcachesize" type="Int">
<label>Kdenlive will periodically check if the cached data exceeds this limit. Data is in Mb</label>
<default>1024</default>
</entry>
<entry name="defaultprojectfolder" type="Path">
<label>Default folder for project files.</label>
<default></default>
......
......@@ -177,6 +177,10 @@ TemporaryData::TemporaryData(KdenliveDoc *doc, bool currentProjectOnly, QWidget
// Cache info message
cache_info->hide();
QAction *a = new QAction(QIcon::fromTheme(QStringLiteral("edit-clear-history")), i18n("Cleanup"), this);
cache_info->setText(i18n("Your cache and backup data exceeds %1, cleanup is recommended.", KIO::convertSize(1048576 * KdenliveSettings::maxcachesize())));
cache_info->addAction(a);
connect(a, &QAction::triggered, this, &TemporaryData::slotCleanUp);
processBackupDirectories();
......@@ -352,18 +356,21 @@ void TemporaryData::cleanBackup()
QFileInfoList files = backupFolder.entryInfoList(QDir::Files, QDir::Time);
QStringList oldFiles;
QDateTime current = QDateTime::currentDateTime();
KIO::filesize_t totalSize = 0;
for (const QFileInfo &f : qAsConst(files)) {
if (f.lastModified().addMonths(KdenliveSettings::cleanCacheMonths()) < current) {
oldFiles << f.fileName();
totalSize += f.size();
}
}
if (oldFiles.isEmpty()) {
KMessageBox::information(this, i18n("No backup data older than %1 months was found.", KdenliveSettings::cleanCacheMonths()));
return;
}
if (KMessageBox::warningContinueCancelList(this,
i18n("This will delete backup data for projects older than %1 months.", KdenliveSettings::cleanCacheMonths()),
oldFiles) != KMessageBox::Continue) {
if (KMessageBox::warningContinueCancelList(
this,
i18n("This will delete backup data (%1) for projects older than %2 months.", KIO::convertSize(totalSize), KdenliveSettings::cleanCacheMonths()),
oldFiles) != KMessageBox::Continue) {
return;
}
if (backupFolder.dirName() == QLatin1String(".backup")) {
......@@ -543,6 +550,8 @@ void TemporaryData::gotBackupSize(KJob *job)
if (sourceJob->totalFiles() == 0) {
total = 0;
}
m_totalBackup = total;
refreshWarningMessage();
gBackupSize->setText(KIO::convertSize(total));
}
......@@ -626,13 +635,7 @@ void TemporaryData::gotFolderSize(KJob *job)
listWidget->resizeColumnToContents(1);
if (m_globalDirectories.isEmpty()) {
// Processing done, check total size
if (m_totalGlobal > 1048576000) {
// Cache larger than 1 GB, warn
cache_info->setText(i18n("Your cached data exceeds 1Gb, cleanup is recommended."));
cache_info->animatedShow();
} else {
cache_info->animatedHide();
}
refreshWarningMessage();
gTotalSize->setText(KIO::convertSize(m_totalGlobal));
listWidget->setCurrentItem(listWidget->topLevelItem(0));
} else {
......@@ -640,6 +643,16 @@ void TemporaryData::gotFolderSize(KJob *job)
}
}
void TemporaryData::refreshWarningMessage()
{
if (KdenliveSettings::maxcachesize() > 0 && (m_totalGlobal + m_totalBackup > KIO::filesize_t(1048576) * KdenliveSettings::maxcachesize())) {
// Cache larger than x MB, warn
cache_info->animatedShow();
} else {
cache_info->animatedHide();
}
}
void TemporaryData::refreshGlobalPie()
{
QList<QTreeWidgetItem *> list = listWidget->selectedItems();
......@@ -740,3 +753,9 @@ void TemporaryData::cleanProxy()
}
processProxyDirectory();
}
void TemporaryData::slotCleanUp()
{
cleanCache();
cleanBackup();
}
......@@ -88,6 +88,7 @@ private:
bool m_currentProjectOnly;
KIO::filesize_t m_totalCurrent;
KIO::filesize_t m_totalGlobal;
KIO::filesize_t m_totalBackup;
QList<KIO::filesize_t> m_currentSizes;
QStringList m_globalDirectories;
QString m_processingDirectory;
......@@ -100,6 +101,10 @@ private:
void processBackupDirectories();
void processProxyDirectory();
void deleteCache(QStringList &folders);
/** @brief
* Check if size of cache + backup data exceeds a limit and warn user
**/
void refreshWarningMessage();
private slots:
void gotPreviewSize(KJob *job);
......@@ -122,6 +127,10 @@ private slots:
void deleteSelected();
void cleanCache();
void cleanProxy();
/** @brief
* Cleanup cached data and backup
**/
void slotCleanUp();
signals:
void disableProxies();
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>506</width>
<height>446</height>
<width>395</width>
<height>514</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -16,14 +16,14 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item row="0" column="0">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Proxy and Transcode Jobs</string>
......@@ -59,7 +59,49 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Cached Data</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Warn if cached data exceeds</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="kcfg_maxcachesize">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string>MiB</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>10000000</number>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Set to zero to disable checking</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>625</width>
<height>529</height>
<height>579</height>
</rect>
</property>
<property name="windowTitle">
......@@ -287,7 +287,8 @@
<string>...</string>
</property>
<property name="icon">
<iconset theme="help-about"/>
<iconset theme="help-about">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
......@@ -661,6 +662,9 @@
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="closeButtonVisible">
<bool>false</bool>
</property>
<property name="messageType">
<enum>KMessageWidget::Warning</enum>
</property>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment