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

Check every 2 weeks the size of cached data and warn user if it exceeds the defined limit

parent b7d9ce97
Pipeline #238326 passed with stage
in 3 minutes and 59 seconds
......@@ -574,6 +574,11 @@
<default>1024</default>
</entry>
<entry name="lastCacheCheck" type="DateTime">
<label>Kdenlive will check every 2 weeks on startup if the cached data exceeds the defined maxcachesize. This is the last checked date</label>
Please register or sign in to reply
<default></default>
</entry>
<entry name="defaultprojectfolder" type="Path">
<label>Default folder for project files.</label>
<default></default>
......
......@@ -479,6 +479,10 @@ void MainWindow::init(const QString &mltPath)
tabifyDockWidget(m_compositionListDock, m_effectListDock);
tabifyDockWidget(m_effectStackDock, pCore->bin()->clipPropertiesDock());
bool firstRun = readOptions();
if (KdenliveSettings::lastCacheCheck().isNull()) {
// Define a date for first check
KdenliveSettings::setLastCacheCheck(QDateTime::currentDateTime());
}
// Build effects menu
m_effectsMenu = new QMenu(i18n("Add Effect"), this);
......@@ -4518,6 +4522,61 @@ void MainWindow::processRestoreState(const QByteArray &state)
restoreState(state);
}
void MainWindow::checkMaxCacheSize()
{
// Check cached data size
if (KdenliveSettings::maxcachesize() <= 0) {
return;
}
if (KdenliveSettings::lastCacheCheck().daysTo(QDateTime::currentDateTime()) < 14) {
return;
}
KdenliveSettings::setLastCacheCheck(QDateTime::currentDateTime());
bool ok;
KIO::filesize_t total = 0;
QDir cacheDir = pCore->currentDoc()->getCacheDir(SystemCacheRoot, &ok);
if (!ok) {
return;
}
QDir backupFolder(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/.backup"));
QList<QDir> toAdd;
QList<QDir> toRemove;
if (cacheDir.exists()) {
toAdd << cacheDir;
}
if (backupFolder.exists()) {
toAdd << cacheDir;
}
if (cacheDir.cd(QStringLiteral("knewstuff"))) {
toRemove << cacheDir;
cacheDir.cdUp();
}
if (cacheDir.cd(QStringLiteral("attica"))) {
toRemove << cacheDir;
cacheDir.cdUp();
}
if (cacheDir.cd(QStringLiteral("proxy"))) {
toRemove << cacheDir;
cacheDir.cdUp();
}
pCore->displayMessage(i18n("Checking cached data size"), InformationMessage);
while (!toAdd.isEmpty()) {
QDir dir = toAdd.takeFirst();
KIO::DirectorySizeJob *job = KIO::directorySize(QUrl::fromLocalFile(dir.absolutePath()));
job->exec();
total += job->totalSize();
}
while (!toRemove.isEmpty()) {
QDir dir = toRemove.takeFirst();
KIO::DirectorySizeJob *job = KIO::directorySize(QUrl::fromLocalFile(dir.absolutePath()));
job->exec();
total -= job->totalSize();
}
if (total > KIO::filesize_t(1048576) * KdenliveSettings::maxcachesize()) {
slotManageCache();
}
}
#ifdef DEBUG_MAINW
#undef DEBUG_MAINW
#endif
......@@ -169,6 +169,9 @@ public:
* @return number of installed items */
int getNewStuff(const QString &configFile);
/** @brief Check if the maximum cached data size is not exceeded. */
void checkMaxCacheSize();
protected:
/** @brief Closes the window.
* @return false if the user presses "Cancel" on a confirmation dialog or
......
......@@ -135,6 +135,7 @@ void ProjectManager::slotLoadOnOpen()
}
}
});
pCore->window()->checkMaxCacheSize();
}
void ProjectManager::init(const QUrl &projectUrl, const QString &clipList)
......
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