diff options
author | Midas <vdrportal_midas@gmx.de> | 2011-04-21 09:06:40 +0200 |
---|---|---|
committer | Midas <vdrportal_midas@gmx.de> | 2011-04-21 09:06:40 +0200 |
commit | bacf88d79eac8dec11cbb53bd1efa5992b63fc01 (patch) | |
tree | 1708485583737a9f78024e18e93c13d62d36ad48 | |
download | vdr-plugin-sleeptimer-bacf88d79eac8dec11cbb53bd1efa5992b63fc01.tar.gz vdr-plugin-sleeptimer-bacf88d79eac8dec11cbb53bd1efa5992b63fc01.tar.bz2 |
Initialization with sleeptimer 0.7 (latest version by Thomas Koch)
-rw-r--r-- | COPYING | bin | 0 -> 61440 bytes | |||
-rw-r--r-- | HISTORY | 31 | ||||
-rw-r--r-- | Makefile | 86 | ||||
-rw-r--r-- | README | 13 | ||||
-rw-r--r-- | i18n.c | 174 | ||||
-rw-r--r-- | i18n.h | 16 | ||||
-rw-r--r-- | patches/vdr-1.2.6-sleeptimer.diff | 48 | ||||
-rw-r--r-- | patches/vdr-1.3.6-sleeptimer.diff | 48 | ||||
-rw-r--r-- | sleeptimer.c | 294 |
9 files changed, 710 insertions, 0 deletions
Binary files differ @@ -0,0 +1,31 @@ +VDR Plugin 'sleeptimer' Revision History +---------------------------------------- +2006-01-22: Version 0.7 + - Fixed language support in Sleep-Timer menu, earlier only German + was supported (Thanks to Mika Karjunen) + +2004-07-18: Version 0.6 + - Made sleeptimer compile and work with VDR 1.3.x (Thanks to + Klaus Schmidinger) + +2004-04-02: Version 0.5 + + - Enter absolut shutdown time (Thanks to Michael Maucher) + Note: if VDRs Version is below 1.3.7 you have to patch VDR for this. Look + at the "patches" directory. + +2004-03-08: Version 0.4 + + - Don't display shutdown warning while shutting down (Thanks to Tobias Grimm) + +2004-02-22: Version 0.3 + +- Bugfix in parameter parsing (Thanks to Andreas Brachold) + +2003-09-11: Version 0.2 + +- Some language fixes. + +2003-05-12: Version 0.1 + +- Initial revision. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8c2829c --- /dev/null +++ b/Makefile @@ -0,0 +1,86 @@ +# +# Makefile for a Video Disk Recorder plugin +# +# $Id$ + +# The official name of this plugin. +# This name will be used in the '-P...' option of VDR to load the plugin. +# By default the main source file also carries this name. +# +PLUGIN = sleeptimer + +### The version number of this plugin (taken from the main source file): + +VERSION = $(shell grep 'static const char \*VERSION *=' $(PLUGIN).c | awk '{ print $$6 }' | sed -e 's/[";]//g') + +### The version number of VDR's plugin API (taken from VDR's "config.h"): + +APIVERSION = $(shell sed -ne '/define APIVERSION/s/^.*"\(.*\)".*$$/\1/p' $(VDRDIR)/config.h) + +### The C++ compiler and options: + +CXX ?= g++ +CXXFLAGS ?= -O2 -Wall -Woverloaded-virtual + +### The directory environment: + +DVBDIR = ../../../../DVB +VDRDIR = ../../.. +LIBDIR = ../../lib +TMPDIR = /tmp + +### Allow user defined options to overwrite defaults: + +-include $(VDRDIR)/Make.config + +### The version number of VDR (taken from VDR's "config.h"): + +VDRVERSION = $(shell grep 'define VDRVERSION ' $(VDRDIR)/config.h | awk '{ print $$3 }' | sed -e 's/"//g') + +### The name of the distribution archive: + +ARCHIVE = $(PLUGIN)-$(VERSION) +PACKAGE = vdr-$(ARCHIVE) + +### Includes and Defines (add further entries here): + +INCLUDES += -I$(VDRDIR)/include -I$(DVBDIR)/include + +DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' + +### The object files (add further files here): + +OBJS = $(PLUGIN).o i18n.o + +### Implicit rules: + +%.o: %.c + $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + +# Dependencies: + +MAKEDEP = g++ -MM -MG +DEPFILE = .dependencies +$(DEPFILE): Makefile + @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ + +-include $(DEPFILE) + +### Targets: + +all: libvdr-$(PLUGIN).so + +libvdr-$(PLUGIN).so: $(OBJS) + $(CXX) $(CXXFLAGS) -shared $(OBJS) -o $@ + @cp $@ $(LIBDIR)/$@.$(APIVERSION) + +dist: clean + @-rm -rf $(TMPDIR)/$(ARCHIVE) + @mkdir $(TMPDIR)/$(ARCHIVE) + @cp -a * $(TMPDIR)/$(ARCHIVE) + @tar czf $(PACKAGE).tgz -C $(TMPDIR) $(ARCHIVE) + @-rm -rf $(TMPDIR)/$(ARCHIVE) + @echo Distribution package created as $(PACKAGE).tgz + +clean: + @-rm -f $(OBJS) $(DEPFILE) *.so *.tgz core* *~ @@ -0,0 +1,13 @@ +This is a "plugin" for the Video Disk Recorder (VDR). + +Written by: Thomas Koch <tom@linvdr.org> + +Project's homepage: http://www.linvdr.org/projects/sleeptimer/ + +Latest version available at: Project's homepage + +See the file COPYING for license information. + +Description: + +use -e parameter to redefine the command for shutdown. By default /sbin/poweroff is called @@ -0,0 +1,174 @@ +/* + * i18n.c: Internationalization + * + * See the README file for copyright information and how to reach the author. + * + * $Id: i18n.c 1.3 2002/06/23 13:05:59 kls Exp $ + */ + +#include "i18n.h" + +const tI18nPhrase Phrases[] = { + { "Not active",// English + "Nicht aktiv", //Deutch + "",// Slovenski + "",// Italiano + "",// Nederlands + "",// Português + "",// Francais + "",// Norsk + "Ei aktiivinen",// Suomi + "",// Polski + "",// Español + "",// Greek + "",// svenska + "",// Romaneste + "",// Magyar + }, + { "Disable Sleep-Timer in %d minutes", + "Sleep-Timer in %d Minuten abbrechen", + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "Peruuta %d minuutin ajastin?",// Suomi + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + }, + { "Abort Sleep-Timer?", + "Sleep-Timer abbrechen?", + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "Keskeytä ajastin",// Suomi + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + }, + { "Activate Sleep-Timer at %i:%0.2i?", + "Sleep-Timer um %i:%0.2i aktivieren?", + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "Aktivoi ajastin %i:%0.2i?",// Suomi + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + }, + { "Activate Sleep-Timer in %d minutes?", + "Sleep-Timer in %d Minuten aktivieren?", + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "Aktivoi %d minuutin ajastin?",// Suomi + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + }, + { "Sleep-Timer", + "Sleep-Timer", + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "Ajastin",// Suomi + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + }, + { "Action", + "Aktion", + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "Toiminto",// Suomi + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + }, + { "Going to sleep in about one minute", + "Sleep-Timer in einer Minute", + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "Ajastin aktivoituu noin minuutin kuluttua",// Suomi + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + "",// TODO + }, + { "Shutdown-Time", + "Shutdown-Zeit", + "", + "", + "", + "", + "", + "", + "Sammutusaika", // Suomi + "", + "", + "", + "", + "", + "", + }, + { "Shutdown-Minutes", + "Shutdown-Minuten", + "", + "", + "", + "", + "", + "", + "Sammutus minuutteina", + "", + "", + "", + "", + "", + "", + }, + { NULL } + }; + @@ -0,0 +1,16 @@ +/* + * i18n.h: Internationalization + * + * See the README file for copyright information and how to reach the author. + * + * $Id$ + */ + +#ifndef _I18N__H +#define _I18N__H + +#include <vdr/i18n.h> + +extern const tI18nPhrase Phrases[]; + +#endif //_I18N__H diff --git a/patches/vdr-1.2.6-sleeptimer.diff b/patches/vdr-1.2.6-sleeptimer.diff new file mode 100644 index 0000000..ad6903e --- /dev/null +++ b/patches/vdr-1.2.6-sleeptimer.diff @@ -0,0 +1,48 @@ +diff -Nur vdr-1.2.6.orig/menu.c vdr-1.2.6/menu.c +--- vdr-1.2.6.orig/menu.c 2003-10-03 16:36:20.000000000 +0200 ++++ vdr-1.2.6/menu.c 2004-03-18 06:04:00.000000000 +0100 +@@ -268,17 +268,6 @@ + + // --- cMenuEditTimeItem ----------------------------------------------------- + +-class cMenuEditTimeItem : public cMenuEditItem { +-protected: +- int *value; +- int hh, mm; +- int pos; +- virtual void Set(void); +-public: +- cMenuEditTimeItem(const char *Name, int *Value); +- virtual eOSState ProcessKey(eKeys Key); +- }; +- + cMenuEditTimeItem::cMenuEditTimeItem(const char *Name, int *Value) + :cMenuEditItem(Name) + { +diff -Nur vdr-1.2.6.orig/menu.h vdr-1.2.6/menu.h +--- vdr-1.2.6.orig/menu.h 2003-08-03 11:37:18.000000000 +0200 ++++ vdr-1.2.6/menu.h 2004-03-18 06:04:00.000000000 +0100 +@@ -16,6 +16,7 @@ + #include "dvbplayer.h" + #include "recorder.h" + #include "recording.h" ++#include "menuitems.h" + + class cMenuMain : public cOsdMenu { + private: +@@ -179,4 +180,15 @@ + static void ClearLastReplayed(const char *FileName); + }; + ++class cMenuEditTimeItem : public cMenuEditItem { ++protected: ++ int *value; ++ int hh, mm; ++ int pos; ++ virtual void Set(void); ++public: ++ cMenuEditTimeItem(const char *Name, int *Value); ++ virtual eOSState ProcessKey(eKeys Key); ++ }; ++ + #endif //__MENU_H diff --git a/patches/vdr-1.3.6-sleeptimer.diff b/patches/vdr-1.3.6-sleeptimer.diff new file mode 100644 index 0000000..f5d5309 --- /dev/null +++ b/patches/vdr-1.3.6-sleeptimer.diff @@ -0,0 +1,48 @@ +diff -Nur vdr-1.3.1.orig/menu.c vdr-1.3.1/menu.c +--- vdr-1.3.1.orig/menu.c 2004-01-11 16:40:32.000000000 +0100 ++++ vdr-1.3.1/menu.c 2004-03-18 06:06:19.000000000 +0100 +@@ -267,17 +267,6 @@ + + // --- cMenuEditTimeItem ----------------------------------------------------- + +-class cMenuEditTimeItem : public cMenuEditItem { +-protected: +- int *value; +- int hh, mm; +- int pos; +- virtual void Set(void); +-public: +- cMenuEditTimeItem(const char *Name, int *Value); +- virtual eOSState ProcessKey(eKeys Key); +- }; +- + cMenuEditTimeItem::cMenuEditTimeItem(const char *Name, int *Value) + :cMenuEditItem(Name) + { +diff -Nur vdr-1.3.1.orig/menu.h vdr-1.3.1/menu.h +--- vdr-1.3.1.orig/menu.h 2004-01-04 12:01:13.000000000 +0100 ++++ vdr-1.3.1/menu.h 2004-03-18 06:06:19.000000000 +0100 +@@ -17,6 +17,7 @@ + #include "dvbplayer.h" + #include "recorder.h" + #include "recording.h" ++#include "menuitems.h" + + class cMenuMain : public cOsdMenu { + private: +@@ -182,4 +183,15 @@ + static void ClearLastReplayed(const char *FileName); + }; + ++class cMenuEditTimeItem : public cMenuEditItem { ++protected: ++ int *value; ++ int hh, mm; ++ int pos; ++ virtual void Set(void); ++public: ++ cMenuEditTimeItem(const char *Name, int *Value); ++ virtual eOSState ProcessKey(eKeys Key); ++ }; ++ + #endif //__MENU_H diff --git a/sleeptimer.c b/sleeptimer.c new file mode 100644 index 0000000..f1c08e1 --- /dev/null +++ b/sleeptimer.c @@ -0,0 +1,294 @@ +/* + * sleeptimer.c: A plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + * $Id$ + */ + +#include <vdr/plugin.h> +#include <vdr/interface.h> +#include <vdr/device.h> +#include "i18n.h" + +static const char *VERSION = "0.7"; +static const char *DESCRIPTION = "Sleep-Timer for VDR"; +static const char *MAINMENUENTRY = "Sleep-Timer"; +int multi = 15; +int max_minute = 360; +int sleepat = 0; +int Method = 0; +int Shutdown_Time = 0; +int Shutdown_Minutes = 0; +char *Command = "/sbin/poweroff"; + +// Tools +int time_now() { + char buff[15]; + time_t tm; + time(&tm); + strftime(buff, sizeof(buff), "%s", localtime(&tm)); + return(atoi(buff)); +} + +int time_then(int minutes) { + int now; + now = time_now(); + return(now + (minutes * 60)); +} + +int i2s(int tnow) { + time_t tme = time(NULL); + struct tm *TM; + char buf[15]; + int dif; + int Std; + int Min; + + TM = localtime(&tme); + (*TM).tm_sec = 0; + (*TM).tm_min = 0; + (*TM).tm_hour = 0; + strftime(buf, sizeof(buf), "%s", TM); + dif = (tnow - atoi(buf)); + Std = dif / 3600; + Min = ((dif - Std * 3600) / 60); + return Std * 100 + Min; +} + +int s2i(int &Min, int &Std, int Value) { + time_t tme = time(NULL); + char buf[15]; + struct tm *TM; + TM = localtime(&tme); + Std = int(Value / 100); + Min = ((Value - Std * 100) % 60); + if (Std * 60 + Min < (*TM).tm_hour * 60 + (*TM).tm_min) + (*TM).tm_mday++; + (*TM).tm_sec = 0; + (*TM).tm_min = 0; + (*TM).tm_hour = 0; + strftime(buf, sizeof(buf), "%s", TM); + return atoi(buf) + Std * 3600 + Min * 60; +} + +// cMenuSetupSleeptimer +class cMenuSetupSleeptimer : public cMenuSetupPage { +private: + int newMethod; +public: + cMenuSetupSleeptimer(void); + virtual void Store(void); +}; + +cMenuSetupSleeptimer::cMenuSetupSleeptimer(void) { + newMethod = Method; + Add(new cMenuEditBoolItem(tr("Action"), &newMethod, tr("Shutdown"), tr("Mute"))); +} + +void cMenuSetupSleeptimer::Store(void) { + SetupStore("Method", Method = newMethod); +} + + +// cBackgroundSleepTimer +class cBackgroundSleepTimer : public cThread { +private: + virtual void Action(void); +public: + cBackgroundSleepTimer(void); + ~cBackgroundSleepTimer(); +}; + +class MainMenu : public cOsdMenu { +public: + MainMenu(void); + eOSState ProcessKey(eKeys k); + cBackgroundSleepTimer *dos; +}; + +cBackgroundSleepTimer::cBackgroundSleepTimer(void) { + Start(); +} + +cBackgroundSleepTimer::~cBackgroundSleepTimer() { + sleepat = 0; +} + +void cBackgroundSleepTimer::Action(void) { + isyslog("sleeptimer: thread started (pid=%d)", getpid()); + while(sleepat) { + if(sleepat <= time_now()) { + isyslog("sleeptimer: timeout"); + if(Method == 0) { + isyslog("sleeptimer: executing \"%s\"", Command); + if(SystemExec(Command) == -1) + isyslog("sleeptimer: errror while executing \"%s\"!", Command); + } + if(Method == 1) { + isyslog("sleeptimer: muting audio"); + if(!cDevice::PrimaryDevice()->IsMute()) + cDevice::PrimaryDevice()->ToggleMute(); + } + sleepat = 0; + } else { + if((sleepat - 60) <= time_now()) { + Interface->Confirm(tr("Going to sleep in about one minute"), 5, false); + isyslog("sleeptimer: going to sleep in about one minute"); + } + } + if(sleepat) + sleep(10); + } + isyslog("sleeptimer: thread end (pid=%d)", getpid()); +} + +// cPluginSleeptimer +class cPluginSleeptimer : public cPlugin { +public: + cPluginSleeptimer(void); + virtual ~cPluginSleeptimer(); + virtual const char *Version(void) { return VERSION; } + virtual const char *Description(void) { return DESCRIPTION; } + virtual const char *CommandLineHelp(void); + virtual bool ProcessArgs(int argc, char *argv[]); + virtual bool Start(void); + virtual void Housekeeping(void); + virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; } + virtual cOsdObject *MainMenuAction(void); + virtual cMenuSetupPage *SetupMenu(void); + virtual bool SetupParse(const char *Name, const char *Value); + // +}; + + +cPluginSleeptimer::cPluginSleeptimer(void) +{ + // Initialize any member variables here. + // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL + // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! +} + +cPluginSleeptimer::~cPluginSleeptimer() +{ + // Clean up after yourself! +} + +const char *cPluginSleeptimer::CommandLineHelp(void) +{ + // Return a string that describes all known command line options. + return " -e command shutdown command (default: /sbin/poweroff)\n"; +} + +bool cPluginSleeptimer::ProcessArgs(int argc, char *argv[]) +{ + // Implement command line argument processing here if applicable. + int c; + while((c = getopt(argc, argv, "e:")) != -1 ) { + switch(c) { + case 'e': + Command = optarg; + break; + default: return false; + } + } + return true; +} + +bool cPluginSleeptimer::Start(void) +{ + RegisterI18n(Phrases); + return true; +} + +void cPluginSleeptimer::Housekeeping(void) +{ +} + +cOsdObject *cPluginSleeptimer::MainMenuAction(void) +{ + return new MainMenu; +} + +cMenuSetupPage *cPluginSleeptimer::SetupMenu(void) +{ + return new cMenuSetupSleeptimer; +} + +bool cPluginSleeptimer::SetupParse(const char *Name, const char *Value) +{ + if(!strcasecmp(Name, "Method")) + Method = atoi(Value); + else return false; + return true; +} + +MainMenu::MainMenu(void) : cOsdMenu("Sleep Timer", 20) { + char buf[80]; + + if(!sleepat) + snprintf(buf, sizeof(buf), "%s", tr("Not active")); + else { + snprintf(buf, sizeof(buf), tr("Disable Sleep-Timer in %d minutes"), + (sleepat - time_now()) / 60); + } + + Add(new cOsdItem(hk(buf))); + if(sleepat) { + Shutdown_Time = i2s(sleepat); + Shutdown_Minutes = ((sleepat - time_now()) / 60); + } else { + Shutdown_Time = i2s(time_now()); + Shutdown_Minutes = 15; + } + /*Added language support in 0.61*/ + Add(new cMenuEditTimeItem(tr("Shutdown-Time"), &Shutdown_Time)); + Add(new cMenuEditIntItem(tr("Shutdown-Minutes"), &Shutdown_Minutes)); +} + +eOSState MainMenu::ProcessKey(eKeys k) { + int current; + eOSState state = cOsdMenu::ProcessKey(k); + switch(state) { + case osUnknown: + switch(k) { + case kOk: + current = Current(); + if(current == 0) { + if(Interface->Confirm(tr("Abort Sleep-Timer?"))) { + sleepat = 0; + return(osEnd); + } + } else if(current == 1) { + char buf[80]; + int tmp, Std, Min; + tmp = s2i(Min, Std, Shutdown_Time); + snprintf(buf, sizeof(buf), tr("Activate Sleep-Timer at %i:%0.2i?"), Std, Min); + + if(Interface->Confirm(buf)) { + sleepat = tmp; + dos = new cBackgroundSleepTimer; + return(osEnd); + } + } else if(current == 2) { + char buf[80]; + snprintf(buf, sizeof(buf), tr("Activate Sleep-Timer in %d minutes?"), Shutdown_Minutes); + if(Interface->Confirm(buf)) { + sleepat = time_then(Shutdown_Minutes); + dos = new cBackgroundSleepTimer; + return(osEnd); + } + } + return(osPlugin); + break; + default: break; + } + case osBack: + case osEnd: + break; + default: break; + } + return(state); +} + +VDRPLUGINCREATOR(cPluginSleeptimer); // Don't touch this! |