1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

The disk usage is no longer automatically added to the title of the main and "Recordings" menus

This commit is contained in:
Klaus Schmidinger 2012-04-23 09:07:55 +02:00
parent 09e58657a1
commit 3d32b07862
9 changed files with 147 additions and 79 deletions

View File

@ -7052,7 +7052,7 @@ Video Disk Recorder Revision History
- Fixed handling IDLEPRIORITY in cDvbDevice::ProvidesChannel() (thanks to Frank
Schmirler).
2012-04-15: Version 1.7.28
2012-04-23: Version 1.7.28
- Fixed cPixmapMemory::DrawEllipse() for quadrants -1 and -4.
- Fixed getting the maximum short channel name length in case there are no short names
@ -7072,3 +7072,10 @@ Video Disk Recorder Revision History
variations of the DVB standard (thanks to Rolf Ahrenberg). Currently there is "DVB"
(for the original DVB standard) and "ANSI/SCTE", which is used to properly handle
certain private stream types.
- The disk usage is no longer automatically added to the title of the main and
"Recordings" menus. This has always been a mekeshift solution and it is now up
to the individual skin if, where and how it wants to display this information.
A skin can use the new cVideoDiskUsage class to implement such a display. For
compatibility, the default skins "Classic VDR", "ST:TNG Panels" and "Text mode"
(i.e. curses) have been changed to behave like before. Other skins may want to
display the disk usage in totally different ways.

View File

@ -96,3 +96,8 @@ VDR Plugin 'skincurses' Revision History
2012-03-11: Version 0.1.11
- Adapted menu column widths of 'skincurses' to the wider HD OSD sizes.
2012-04-23: Version 0.1.12
- Now displaying disk usage in the title of the main and "Recordings" menu,
which is no longer done by the VDR core.

View File

@ -3,15 +3,16 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: skincurses.c 2.8 2012/03/11 14:42:52 kls Exp $
* $Id: skincurses.c 2.9 2012/04/23 08:53:13 kls Exp $
*/
#include <ncurses.h>
#include <vdr/osd.h>
#include <vdr/plugin.h>
#include <vdr/skins.h>
#include <vdr/videodir.h>
static const char *VERSION = "0.1.11";
static const char *VERSION = "0.1.12";
static const char *DESCRIPTION = trNOOP("A text only skin");
static const char *MAINMENUENTRY = NULL;
@ -262,6 +263,9 @@ void cSkinCursesDisplayChannel::Flush(void)
class cSkinCursesDisplayMenu : public cSkinDisplayMenu {
private:
cOsd *osd;
cString title;
int lastDiskUsageState;
void DrawTitle(void);
void DrawScrollbar(int Total, int Offset, int Shown, int Top, int Height, bool CanScrollUp, bool CanScrollDown);
void SetTextScrollbar(void);
public:
@ -285,6 +289,7 @@ public:
cSkinCursesDisplayMenu::cSkinCursesDisplayMenu(void)
{
osd = new cCursesOsd(0, 0);
lastDiskUsageState = -1;
osd->DrawRectangle(0, 0, ScOsdWidth - 1, ScOsdHeight - 1, clrBackground);
}
@ -332,9 +337,16 @@ void cSkinCursesDisplayMenu::Clear(void)
textScroller.Reset();
}
void cSkinCursesDisplayMenu::DrawTitle(void)
{
bool WithDisk = MenuCategory() == mcMain || MenuCategory() == mcRecording;
osd->DrawText(0, 0, WithDisk ? cString::sprintf("%s - %s", *title, *cVideoDiskUsage::String()) : title, clrBlack, clrCyan, &Font, ScOsdWidth);
}
void cSkinCursesDisplayMenu::SetTitle(const char *Title)
{
osd->DrawText(0, 0, Title, clrBlack, clrCyan, &Font, ScOsdWidth);
title = Title;
DrawTitle();
}
void cSkinCursesDisplayMenu::SetButtons(const char *Red, const char *Green, const char *Yellow, const char *Blue)
@ -475,6 +487,8 @@ void cSkinCursesDisplayMenu::SetText(const char *Text, bool FixedFont)
void cSkinCursesDisplayMenu::Flush(void)
{
if (cVideoDiskUsage::HasChanged(lastDiskUsageState))
DrawTitle();
cString date = DayDateTime();
osd->DrawText(ScOsdWidth - Utf8StrLen(date) - 2, 0, date, clrBlack, clrCyan, &Font);
osd->Flush();

67
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 2.49 2012/04/22 10:44:20 kls Exp $
* $Id: menu.c 2.50 2012/04/22 15:13:14 kls Exp $
*/
#include "menu.h"
@ -34,7 +34,6 @@
#define MAXWAIT4EPGINFO 3 // seconds
#define MODETIMEOUT 3 // seconds
#define DISKSPACECHEK 5 // seconds between disk space checks
#define NEWTIMERLIMIT 120 // seconds until the start time of a new timer created from the Schedule menu,
// within which it will go directly into the "Edit timer" menu to allow
// further parameter settings
@ -52,47 +51,6 @@
#define CHNUMWIDTH (numdigits(Channels.MaxNumber()) + 1)
#define CHNAMWIDTH (min(MAXCHNAMWIDTH, Channels.MaxShortChannelNameLength() + 1))
// --- cFreeDiskSpace --------------------------------------------------------
#define MB_PER_MINUTE 25.75 // this is just an estimate!
class cFreeDiskSpace {
private:
static time_t lastDiskSpaceCheck;
static int lastFreeMB;
static cString freeDiskSpaceString;
public:
static bool HasChanged(bool ForceCheck = false);
static const char *FreeDiskSpaceString(void) { HasChanged(); return freeDiskSpaceString; }
};
time_t cFreeDiskSpace::lastDiskSpaceCheck = 0;
int cFreeDiskSpace::lastFreeMB = 0;
cString cFreeDiskSpace::freeDiskSpaceString;
cFreeDiskSpace FreeDiskSpace;
bool cFreeDiskSpace::HasChanged(bool ForceCheck)
{
if (ForceCheck || time(NULL) - lastDiskSpaceCheck > DISKSPACECHEK) {
int FreeMB;
int Percent = VideoDiskSpace(&FreeMB);
lastDiskSpaceCheck = time(NULL);
if (ForceCheck || FreeMB != lastFreeMB) {
int MBperMinute = Recordings.MBperMinute();
if (MBperMinute <= 0)
MBperMinute = MB_PER_MINUTE;
int Minutes = int(double(FreeMB) / MBperMinute);
int Hours = Minutes / 60;
Minutes %= 60;
freeDiskSpaceString = cString::sprintf("%s %d%% - %2d:%02d %s", tr("Disk"), Percent, Hours, Minutes, tr("free"));
lastFreeMB = FreeMB;
return true;
}
}
return false;
}
// --- cMenuEditCaItem -------------------------------------------------------
class cMenuEditCaItem : public cMenuEditIntItem {
@ -2234,7 +2192,6 @@ cMenuRecordings::cMenuRecordings(const char *Base, int Level, bool OpenSubMenus)
helpKeys = -1;
Display(); // this keeps the higher level menus from showing up briefly when pressing 'Back' during replay
Set();
SetFreeDiskDisplay(true);
if (Current() < 0)
SetCurrent(First());
else if (OpenSubMenus && cReplayControl::LastReplayed() && Open(true))
@ -2249,16 +2206,6 @@ cMenuRecordings::~cMenuRecordings()
free(base);
}
bool cMenuRecordings::SetFreeDiskDisplay(bool Force)
{
if (FreeDiskSpace.HasChanged(Force)) {
//XXX -> skin function!!!
SetTitle(cString::sprintf("%s - %s", base ? base : tr("Recordings"), FreeDiskSpace.FreeDiskSpaceString()));
return true;
}
return false;
}
void cMenuRecordings::SetHelpKeys(void)
{
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
@ -2321,7 +2268,6 @@ void cMenuRecordings::Set(bool Refresh)
}
}
free(LastItemText);
Refresh |= SetFreeDiskDisplay(Refresh);
if (Refresh)
Display();
}
@ -2427,7 +2373,7 @@ eOSState cMenuRecordings::Delete(void)
Recordings.DelByName(ri->FileName());
cOsdMenu::Del(Current());
SetHelpKeys();
SetFreeDiskDisplay(true);
cVideoDiskUsage::ForceCheck();
Display();
if (!Count())
return osBack;
@ -2500,8 +2446,6 @@ eOSState cMenuRecordings::ProcessKey(eKeys Key)
Display();
}
if (!HasSubMenu()) {
if (HadSubMenu)
SetFreeDiskDisplay();
if (Key != kNone)
SetHelpKeys();
}
@ -3416,13 +3360,6 @@ bool cMenuMain::Update(bool Force)
{
bool result = false;
// Title with disk usage:
if (FreeDiskSpace.HasChanged(Force)) {
//XXX -> skin function!!!
SetTitle(cString::sprintf("%s - %s", tr("VDR"), FreeDiskSpace.FreeDiskSpaceString()));
result = true;
}
bool NewReplaying = cControl::Control() != NULL;
if (Force || NewReplaying != replaying) {
replaying = NewReplaying;

3
menu.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: menu.h 2.6 2012/04/19 14:28:37 kls Exp $
* $Id: menu.h 2.7 2012/04/22 15:08:58 kls Exp $
*/
#ifndef __MENU_H
@ -196,7 +196,6 @@ private:
int level;
int recordingsState;
int helpKeys;
bool SetFreeDiskDisplay(bool Force = false);
void SetHelpKeys(void);
void Set(bool Refresh = false);
bool Open(bool OpenSubMenus = false);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: skinclassic.c 2.6 2011/08/21 11:02:06 kls Exp $
* $Id: skinclassic.c 2.7 2012/04/23 08:48:03 kls Exp $
*/
#include "skinclassic.h"
@ -12,6 +12,7 @@
#include "i18n.h"
#include "osd.h"
#include "themes.h"
#include "videodir.h"
#define ScrollWidth (Setup.FontOsdSize / 4)
#define TextFrame (Setup.FontOsdSize / 10)
@ -170,7 +171,10 @@ private:
int y0, y1, y2, y3, y4, y5;
int lineHeight;
int dateWidth;
cString title;
cString lastDate;
int lastDiskUsageState;
void DrawTitle(void);
void DrawScrollbar(int Total, int Offset, int Shown, int Top, int Height, bool CanScrollUp, bool CanScrollDown);
void SetTextScrollbar(void);
public:
@ -196,6 +200,7 @@ cSkinClassicDisplayMenu::cSkinClassicDisplayMenu(void)
{
const cFont *font = cFont::GetFont(fontOsd);
lineHeight = font->Height();
lastDiskUsageState = -1;
dateWidth = 0;
x0 = 0;
x1 = x0 + 2 * TextSpacing;
@ -270,10 +275,17 @@ void cSkinClassicDisplayMenu::Clear(void)
osd->DrawRectangle(x0, y1, x3 - 1, y4 - 1, Theme.Color(clrBackground));
}
void cSkinClassicDisplayMenu::SetTitle(const char *Title)
void cSkinClassicDisplayMenu::DrawTitle(void)
{
const cFont *font = cFont::GetFont(fontOsd);
osd->DrawText(x0, y0, Title, Theme.Color(clrMenuTitleFg), Theme.Color(clrMenuTitleBg), font, x3 - x0 - dateWidth);
bool WithDisk = MenuCategory() == mcMain || MenuCategory() == mcRecording;
osd->DrawText(x0, y0, WithDisk ? cString::sprintf("%s - %s", *title, *cVideoDiskUsage::String()) : title, Theme.Color(clrMenuTitleFg), Theme.Color(clrMenuTitleBg), font, x3 - x0 - dateWidth);
}
void cSkinClassicDisplayMenu::SetTitle(const char *Title)
{
title = Title;
DrawTitle();
}
void cSkinClassicDisplayMenu::SetButtons(const char *Red, const char *Green, const char *Yellow, const char *Blue)
@ -422,6 +434,8 @@ const cFont *cSkinClassicDisplayMenu::GetTextAreaFont(bool FixedFont) const
void cSkinClassicDisplayMenu::Flush(void)
{
if (cVideoDiskUsage::HasChanged(lastDiskUsageState))
DrawTitle();
cString date = DayDateTime();
if (!*lastDate || strcmp(date, lastDate)) {
const cFont *font = cFont::GetFont(fontOsd);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: skinsttng.c 2.14 2012/03/11 13:32:00 kls Exp $
* $Id: skinsttng.c 2.15 2012/04/23 08:39:11 kls Exp $
*/
// "Star Trek: The Next Generation"(R) is a registered trademark of Paramount Pictures
@ -16,6 +16,7 @@
#include "osd.h"
#include "menu.h"
#include "themes.h"
#include "videodir.h"
#include "symbols/arrowdown.xpm"
#include "symbols/arrowup.xpm"
@ -401,8 +402,11 @@ private:
int lineHeight;
tColor frameColor;
int currentIndex;
cString title;
bool message;
cString lastDate;
int lastDiskUsageState;
void DrawTitle(void);
void DrawScrollbar(int Total, int Offset, int Shown, int Top, int Height, bool CanScrollUp, bool CanScrollDown);
void SetTextScrollbar(void);
public:
@ -429,6 +433,7 @@ cSkinSTTNGDisplayMenu::cSkinSTTNGDisplayMenu(void)
const cFont *font = cFont::GetFont(fontOsd);
lineHeight = font->Height();
frameColor = Theme.Color(clrMenuFrame);
lastDiskUsageState = -1;
currentIndex = -1;
message = false;
x0 = 0;
@ -548,15 +553,22 @@ void cSkinSTTNGDisplayMenu::Clear(void)
osd->DrawRectangle(x1, y3, x7 - 1, y4 - 1, Theme.Color(clrBackground));
}
void cSkinSTTNGDisplayMenu::SetTitle(const char *Title)
void cSkinSTTNGDisplayMenu::DrawTitle(void)
{
const cFont *font = cFont::GetFont(fontOsd);
const char *VDR = " VDR";
bool WithDisk = MenuCategory() == mcMain || MenuCategory() == mcRecording;
int w = font->Width(VDR);
osd->DrawText(x3 + TextSpacing, y0, Title, Theme.Color(clrMenuTitle), frameColor, font, x4 - w - x3 - TextSpacing);
osd->DrawText(x3 + TextSpacing, y0, WithDisk ? cString::sprintf("%s - %s", *title, *cVideoDiskUsage::String()) : title, Theme.Color(clrMenuTitle), frameColor, font, x4 - w - x3 - TextSpacing);
osd->DrawText(x4 - w, y0, VDR, frameColor, clrBlack, font, w, lineHeight);
}
void cSkinSTTNGDisplayMenu::SetTitle(const char *Title)
{
title = Title;
DrawTitle();
}
void cSkinSTTNGDisplayMenu::SetButtons(const char *Red, const char *Green, const char *Yellow, const char *Blue)
{
cString date = DayDateTime();
@ -749,6 +761,8 @@ const cFont *cSkinSTTNGDisplayMenu::GetTextAreaFont(bool FixedFont) const
void cSkinSTTNGDisplayMenu::Flush(void)
{
if (cVideoDiskUsage::HasChanged(lastDiskUsageState))
DrawTitle();
if (!message) {
cString date = DayDateTime();
if (!*lastDate || strcmp(date, lastDate)) {

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.15 2008/02/16 13:00:03 kls Exp $
* $Id: videodir.c 2.1 2012/04/22 15:03:10 kls Exp $
*/
#include "videodir.h"
@ -241,3 +241,43 @@ bool IsOnVideoDirectoryFileSystem(const char *FileName)
} while (Dir.Next());
return false;
}
// --- cVideoDiskUsage -------------------------------------------------------
#define DISKSPACECHEK 5 // seconds between disk space checks
#define MB_PER_MINUTE 25.75 // this is just an estimate!
int cVideoDiskUsage::state = 0;
time_t cVideoDiskUsage::lastChecked = 0;
int cVideoDiskUsage::usedPercent = 0;
int cVideoDiskUsage::freeMB = 0;
int cVideoDiskUsage::freeMinutes = 0;
bool cVideoDiskUsage::HasChanged(int &State)
{
if (time(NULL) - lastChecked > DISKSPACECHEK) {
int FreeMB;
int UsedPercent = VideoDiskSpace(&FreeMB);
if (FreeMB != freeMB) {
usedPercent = UsedPercent;
freeMB = FreeMB;
int MBperMinute = Recordings.MBperMinute();
if (MBperMinute <= 0)
MBperMinute = MB_PER_MINUTE;
freeMinutes = int(double(FreeMB) / MBperMinute);
state++;
}
lastChecked = time(NULL);
}
if (State != state) {
State = state;
return true;
}
return false;
}
cString cVideoDiskUsage::String(void)
{
HasChanged(state);
return cString::sprintf("%s %d%% - %2d:%02d %s", tr("Disk"), usedPercent, freeMinutes / 60, freeMinutes % 60, tr("free"));
}

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: videodir.h 1.7 2008/02/16 12:53:11 kls Exp $
* $Id: videodir.h 2.1 2012/04/22 15:07:56 kls Exp $
*/
#ifndef __VIDEODIR_H
@ -25,4 +25,42 @@ cString PrefixVideoFileName(const char *FileName, char Prefix);
void RemoveEmptyVideoDirectories(void);
bool IsOnVideoDirectoryFileSystem(const char *FileName);
class cVideoDiskUsage {
private:
static int state;
static time_t lastChecked;
static int usedPercent;
static int freeMB;
static int freeMinutes;
public:
static bool HasChanged(int &State);
///< Returns true if the usage of the video disk space has changed since the last
///< call to this function with the given State variable. The caller should
///< initialize State to -1, and it will be set to the current internal state
///< value of the video disk usage checker upon return. Future calls with the same
///< State variable can then quickly check for changes.
static void ForceCheck(void) { lastChecked = 0; }
///< To avoid unnecessary load, the video disk usage is only actually checked
///< every DISKSPACECHEK seconds. Calling ForceCheck() makes sure that the next call
///< to HasChanged() will check the disk usage immediately. This is useful in case
///< some files have been deleted and the result shall be displayed instantly.
static cString String(void);
///< Returns a localized string of the form "Disk nn% - hh:mm free".
///< This function is mainly for use in skins that want to retain the display of the
///< free disk space in the menu title, as was the case until VDR version 1.7.27.
///< An implicit call to HasChanged() is done in this function, to make sure the
///< returned value is up to date.
static int UsedPercent(void) { return usedPercent; }
///< Returns the used space of the video disk in percent.
///< The caller should call HasChanged() first, to make sure the value is up to date.
static int FreeMB(void) { return freeMB; }
///< Returns the amount of free space on the video disk in MB.
///< The caller should call HasChanged() first, to make sure the value is up to date.
static int FreeMinutes(void) { return freeMinutes; }
///< Returns the number of minutes that can still be recorded on the video disk.
///< This is an estimate and depends on the data rate of the existing recordings.
///< There is no guarantee that this value will actually be met.
///< The caller should call HasChanged() first, to make sure the value is up to date.
};
#endif //__VIDEODIR_H