Commit cc4d4c92 authored by ManiacTwister's avatar ManiacTwister

Added disk space reservation to prevent the disk from running full

Signed-off-by: ManiacTwister's avatarManiacTwister <git@s7t.de>
parent c8461656
......@@ -93,6 +93,14 @@ DvbConfigDialog::DvbConfigDialog(DvbManager *manager_, QWidget *parent) : KDialo
gridLayout->addWidget(endMarginBox, 3, 1);
boxLayout->addLayout(gridLayout);
gridLayout->addWidget(new QLabel(i18n("Reserved disk space (MB):")), 4, 0);
minFreeDiskspaceBox = new QSpinBox(widget);
minFreeDiskspaceBox->setRange(0, 1024000); // 1000 GB
minFreeDiskspaceBox->setValue(manager->getMinFreeDiskspace());
gridLayout->addWidget(minFreeDiskspaceBox, 4, 1);
boxLayout->addLayout(gridLayout);
gridLayout = new QGridLayout();
gridLayout->addWidget(new QLabel(i18n("Use ISO 8859-1 charset instead of ISO 6937:")),
1, 0);
......@@ -350,6 +358,7 @@ void DvbConfigDialog::accept()
manager->setTimeShiftFolder(timeShiftFolderEdit->text());
manager->setBeginMargin(beginMarginBox->value() * 60);
manager->setEndMargin(endMarginBox->value() * 60);
manager->setMinFreeDiskspace(minFreeDiskspaceBox->value());
manager->setOverride6937Charset(override6937CharsetBox->isChecked());
bool latitudeOk;
......
......@@ -77,6 +77,7 @@ private:
KLineEdit *timeShiftFolderEdit;
QSpinBox *beginMarginBox;
QSpinBox *endMarginBox;
QSpinBox *minFreeDiskspaceBox;
QCheckBox *override6937CharsetBox;
KLineEdit *latitudeEdit;
KLineEdit *longitudeEdit;
......
......@@ -26,6 +26,7 @@
#include <KConfigGroup>
#include <KLocale>
#include <KStandardDirs>
#include <kdiskfreespaceinfo.h>
#include <config-kaffeine.h>
#include "../log.h"
#include "dvbconfig.h"
......@@ -352,6 +353,11 @@ bool DvbManager::override6937Charset() const
return KGlobal::config()->group("DVB").readEntry("Override6937", false);
}
int DvbManager::getMinFreeDiskspace() const
{
return KGlobal::config()->group("DVB").readEntry("MinFreeDiskspace", 1); // 1 MB
}
void DvbManager::setRecordingFolder(const QString &path)
{
KGlobal::config()->group("DVB").writeEntry("RecordingFolder", path);
......@@ -378,6 +384,11 @@ void DvbManager::setOverride6937Charset(bool override)
DvbSiText::setOverride6937(override);
}
void DvbManager::setMinFreeDiskspace(int mbyte)
{
KGlobal::config()->group("DVB").writeEntry("MinFreeDiskspace", mbyte);
}
double DvbManager::getLatitude()
{
return KGlobal::config()->group("DVB").readEntry("Latitude", 0.0);
......@@ -790,6 +801,20 @@ bool DvbManager::readScanSources(DvbScanData &data, const char *tag, Transmissio
return true;
}
bool DvbManager::checkFreeDiskspace(QString fileName)
{
KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(fileName);
if(info.isValid()) {
// Checks if there is more space than the user reserved and if there are at least more than 10mb free
if(info.available() <= ((qulonglong) (getMinFreeDiskspace()) * 1024 * 1024) || info.available() < 10485760) {
Log("DvbManager::checkFreeDiskspace: disk space to low on") << info.mountPoint();
return false;
}
}
// this returns also true if we cannot check if enough space is available
return true;
}
DvbDeviceConfig::DvbDeviceConfig(const QString &deviceId_, const QString &frontendName_,
DvbDevice *device_) : deviceId(deviceId_), frontendName(frontendName_), device(device_),
useCount(0), prioritizedUseCount(0)
......
......@@ -125,11 +125,13 @@ public:
int getBeginMargin() const; // seconds
int getEndMargin() const; // seconds
bool override6937Charset() const;
int getMinFreeDiskspace() const; // megabytes
void setRecordingFolder(const QString &path);
void setTimeShiftFolder(const QString &path);
void setBeginMargin(int beginMargin); // seconds
void setEndMargin(int endMargin); // seconds
void setOverride6937Charset(bool override);
void setMinFreeDiskspace(int mbyte); // megabytes
static double getLatitude();
static double getLongitude();
......@@ -138,6 +140,8 @@ public:
void enableDvbDump();
bool checkFreeDiskspace(QString fileName);
private slots:
void requestBuiltinDeviceManager(QObject *&builtinDeviceManager);
void deviceAdded(DvbBackendDevice *backendDevice);
......
......@@ -401,6 +401,10 @@ bool DvbRecordingFile::start(const DvbRecording &recording)
}
}
if(!manager->checkFreeDiskspace(file.fileName())) {
return false;
}
if (device == NULL) {
channel = recording.channel;
device = manager->requestDevice(channel->source, channel->transponder,
......@@ -530,6 +534,10 @@ void DvbRecordingFile::pmtSectionChanged(const QByteArray &pmtSectionData_)
if (!pmtValid) {
pmtValid = true;
if(!manager->checkFreeDiskspace(file.fileName())) {
stop();
return;
}
file.write(patGenerator.generatePackets());
file.write(pmtGenerator.generatePackets());
......@@ -555,6 +563,11 @@ void DvbRecordingFile::insertPatPmt()
return;
}
if(!manager->checkFreeDiskspace(file.fileName())) {
stop();
return;
}
file.write(patGenerator.generatePackets());
file.write(pmtGenerator.generatePackets());
}
......@@ -581,5 +594,10 @@ void DvbRecordingFile::processData(const char data[188])
return;
}
if(!manager->checkFreeDiskspace(file.fileName())) {
stop();
return;
}
file.write(data, 188);
}
Markdown is supported
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