The 'Main' menu now displays the used disk space in the title

This commit is contained in:
Klaus Schmidinger 2002-01-27 13:11:23 +01:00
parent 53c5499a0b
commit 28e54bc648
8 changed files with 68 additions and 21 deletions

View File

@ -879,7 +879,7 @@ Video Disk Recorder Revision History
- Fixed DVD audio sync problems (thanks to Andreas Schultz).
- Fixed external AC3 replay for DVDs (thanks to Andreas Schultz).
2002-01-26: Version 0.99pre2
2002-01-27: Version 0.99pre2
- Fixed setting the OSD size in the 'Confirm' interface call (thanks to
Deti Fliegl).
@ -916,3 +916,6 @@ Video Disk Recorder Revision History
- A message is now prompted if free disk space becomes low during recording.
- The editing process now calls AssertFreeDiskSpace() to remove deleted
recordings if the disk becomes full.
- The "Main" menu now displays in its title the used disk space (in percent)
and the estimated free disk space (in hh:mm), assuming a data rate of 30 MB
per minute.

View File

@ -7,7 +7,7 @@
* DVD support initially written by Andreas Schultz <aschultz@warp10.net>
* based on dvdplayer-0.5 by Matjaz Thaler <matjaz.thaler@guest.arnes.si>
*
* $Id: dvbapi.c 1.145 2002/01/26 15:28:41 kls Exp $
* $Id: dvbapi.c 1.146 2002/01/26 15:39:48 kls Exp $
*/
//#define DVDDEBUG 1
@ -507,7 +507,7 @@ cRecordBuffer::~cRecordBuffer()
bool cRecordBuffer::RunningLowOnDiskSpace(void)
{
if (time(NULL) > lastDiskSpaceCheck + DISKCHECKINTERVAL) {
uint Free = FreeDiskSpaceMB(fileName.Name());
int Free = FreeDiskSpaceMB(fileName.Name());
lastDiskSpaceCheck = time(NULL);
if (Free < MINFREEDISKSPACE) {
dsyslog(LOG_INFO, "low disk space (%d MB, limit is %d MB)", Free, MINFREEDISKSPACE);

10
i18n.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: i18n.c 1.48 2002/01/26 15:21:40 kls Exp $
* $Id: i18n.c 1.49 2002/01/27 13:11:23 kls Exp $
*
* Slovenian translations provided by Miha Setina <mihasetina@softhome.net>
* Italian translations provided by Alberto Carraro <bertocar@tin.it>
@ -1329,6 +1329,14 @@ const tPhrase Phrases[] = {
"bas",
"", // TODO
},
{ "free",
"frei",
"", // TODO
"", // TODO
"", // TODO
"", // TODO
"", // TODO
},
{ "Jump: ", // note the trailing blank
"Springen: ",
"", // TODO

15
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: menu.c 1.144 2002/01/26 11:09:25 kls Exp $
* $Id: menu.c 1.145 2002/01/27 13:09:49 kls Exp $
*/
#include "menu.h"
@ -15,6 +15,7 @@
#include "config.h"
#include "eit.h"
#include "i18n.h"
#include "videodir.h"
#define MENUTIMEOUT 120 // seconds
#define MAXWAIT4EPGINFO 10 // seconds
@ -1936,6 +1937,18 @@ cMenuMain::cMenuMain(bool Replaying, eOSState State)
{
digit = 0;
// Title with disk usage:
#define MB_PER_MINUTE 30 // this is just an estimate!
char buffer[40];
int FreeMB;
int Percent = VideoDiskSpace(&FreeMB);
int Hours = int(double(FreeMB) / MB_PER_MINUTE / 60);
int Minutes = (FreeMB / MB_PER_MINUTE) % 60;
snprintf(buffer, sizeof(buffer), "%s - Disk %d%% - %2d:%02d %s", tr("Main"), Percent, Hours, Minutes, tr("free"));
SetTitle(buffer);
// Basic menu items:
Add(new cOsdItem(hk(tr("Schedule")), osSchedule));

14
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.c 1.52 2002/01/26 12:04:32 kls Exp $
* $Id: tools.c 1.53 2002/01/27 12:36:23 kls Exp $
*/
#include "tools.h"
@ -223,10 +223,12 @@ const char *AddDirectory(const char *DirName, const char *FileName)
#define DFCMD "df -m -P '%s'"
uint FreeDiskSpaceMB(const char *Directory)
int FreeDiskSpaceMB(const char *Directory, int *UsedMB)
{
//TODO Find a simpler way to determine the amount of free disk space!
uint Free = 0;
if (UsedMB)
*UsedMB = 0;
int Free = 0;
char *cmd = NULL;
asprintf(&cmd, DFCMD, Directory);
FILE *p = popen(cmd, "r");
@ -234,8 +236,10 @@ uint FreeDiskSpaceMB(const char *Directory)
char *s;
while ((s = readline(p)) != NULL) {
if (strchr(s, '/')) {
uint available;
sscanf(s, "%*s %*d %*d %u", &available);
int used, available;
sscanf(s, "%*s %*d %d %d", &used, &available);
if (UsedMB)
*UsedMB = used;
Free = available;
break;
}

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.h 1.38 2002/01/26 11:55:06 kls Exp $
* $Id: tools.h 1.39 2002/01/26 15:38:10 kls Exp $
*/
#ifndef __TOOLS_H
@ -58,7 +58,7 @@ int time_ms(void);
void delay_ms(int ms);
bool isnumber(const char *s);
const char *AddDirectory(const char *DirName, const char *FileName); // returns a statically allocated string!
uint FreeDiskSpaceMB(const char *Directory);
int FreeDiskSpaceMB(const char *Directory, int *UsedMB = NULL);
bool DirectoryOk(const char *DirName, bool LogErrors = false);
bool MakeDirs(const char *FileName, bool IsDirectory = false);
bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks = false);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: videodir.c 1.6 2001/09/02 14:55:15 kls Exp $
* $Id: videodir.c 1.7 2002/01/27 12:37:26 kls Exp $
*/
#include "videodir.h"
@ -27,7 +27,7 @@ private:
public:
cVideoDirectory(void);
~cVideoDirectory();
uint FreeMB(void);
int FreeMB(int *UsedMB = NULL);
const char *Name(void) { return name ? name : VideoDirectory; }
const char *Stored(void) { return stored; }
int Length(void) { return length; }
@ -53,9 +53,9 @@ cVideoDirectory::~cVideoDirectory()
delete adjusted;
}
uint cVideoDirectory::FreeMB(void)
int cVideoDirectory::FreeMB(int *UsedMB)
{
return FreeDiskSpaceMB(name ? name : VideoDirectory);
return FreeDiskSpaceMB(name ? name : VideoDirectory, UsedMB);
}
bool cVideoDirectory::Next(void)
@ -117,9 +117,9 @@ int OpenVideoFile(const char *FileName, int Flags)
cVideoDirectory Dir;
if (Dir.IsDistributed()) {
// Find the directory with the most free space:
uint MaxFree = Dir.FreeMB();
int MaxFree = Dir.FreeMB();
while (Dir.Next()) {
uint Free = FreeDiskSpaceMB(Dir.Name());
int Free = FreeDiskSpaceMB(Dir.Name());
if (Free > MaxFree) {
Dir.Store();
MaxFree = Free;
@ -166,7 +166,7 @@ bool RemoveVideoFile(const char *FileName)
return RemoveFileOrDir(FileName, true);
}
bool VideoFileSpaceAvailable(unsigned int SizeMB)
bool VideoFileSpaceAvailable(int SizeMB)
{
cVideoDirectory Dir;
if (Dir.IsDistributed()) {
@ -181,6 +181,22 @@ bool VideoFileSpaceAvailable(unsigned int SizeMB)
return Dir.FreeMB() >= SizeMB;
}
int VideoDiskSpace(int *FreeMB, int *UsedMB)
{
int free = 0, used = 0;
cVideoDirectory Dir;
do {
int u;
free += Dir.FreeMB(&u);
used += u;
} while (Dir.Next());
if (FreeMB)
*FreeMB = free;
if (UsedMB)
*UsedMB = used;
return (free + used) ? used * 100 / (free + used) : 0;
}
const char *PrefixVideoFileName(const char *FileName, char Prefix)
{
static char *PrefixedName = NULL;

View File

@ -4,19 +4,22 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: videodir.h 1.3 2001/02/11 13:12:50 kls Exp $
* $Id: videodir.h 1.4 2002/01/27 12:37:20 kls Exp $
*/
#ifndef __VIDEODIR_H
#define __VIDEODIR_H
#include <stdlib.h>
extern const char *VideoDirectory;
int OpenVideoFile(const char *FileName, int Flags);
int CloseVideoFile(int FileHandle);
bool RenameVideoFile(const char *OldName, const char *NewName);
bool RemoveVideoFile(const char *FileName);
bool VideoFileSpaceAvailable(unsigned int SizeMB);
bool VideoFileSpaceAvailable(int SizeMB);
int VideoDiskSpace(int *FreeMB = NULL, int *UsedMB = NULL); // returns the used disk space in percent
const char *PrefixVideoFileName(const char *FileName, char Prefix);
void RemoveEmptyVideoDirectories(void);