From 28e54bc648502820202ea44f6a990c9502f901f7 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 27 Jan 2002 13:11:23 +0100 Subject: The 'Main' menu now displays the used disk space in the title --- HISTORY | 5 ++++- dvbapi.c | 4 ++-- i18n.c | 10 +++++++++- menu.c | 15 ++++++++++++++- tools.c | 14 +++++++++----- tools.h | 4 ++-- videodir.c | 30 +++++++++++++++++++++++------- videodir.h | 7 +++++-- 8 files changed, 68 insertions(+), 21 deletions(-) diff --git a/HISTORY b/HISTORY index db2e1bbc..196e5fd1 100644 --- a/HISTORY +++ b/HISTORY @@ -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. diff --git a/dvbapi.c b/dvbapi.c index d04f97e3..048639c6 100644 --- a/dvbapi.c +++ b/dvbapi.c @@ -7,7 +7,7 @@ * DVD support initially written by Andreas Schultz * based on dvdplayer-0.5 by Matjaz Thaler * - * $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); diff --git a/i18n.c b/i18n.c index b0236ec7..d074bbf4 100644 --- a/i18n.c +++ b/i18n.c @@ -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 * Italian translations provided by Alberto Carraro @@ -1329,6 +1329,14 @@ const tPhrase Phrases[] = { "bas", "", // TODO }, + { "free", + "frei", + "", // TODO + "", // TODO + "", // TODO + "", // TODO + "", // TODO + }, { "Jump: ", // note the trailing blank "Springen: ", "", // TODO diff --git a/menu.c b/menu.c index ea55f272..74a4a9d7 100644 --- a/menu.c +++ b/menu.c @@ -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)); diff --git a/tools.c b/tools.c index b18c0ef5..dc579e55 100644 --- a/tools.c +++ b/tools.c @@ -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; } diff --git a/tools.h b/tools.h index 8bb09699..f9390185 100644 --- a/tools.h +++ b/tools.h @@ -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); diff --git a/videodir.c b/videodir.c index d9d3f852..dbb1bd19 100644 --- a/videodir.c +++ b/videodir.c @@ -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; diff --git a/videodir.h b/videodir.h index 0197de30..a719c5e0 100644 --- a/videodir.h +++ b/videodir.h @@ -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 + 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); -- cgit v1.2.3