summaryrefslogtreecommitdiff
path: root/zaplist.c
diff options
context:
space:
mode:
authorMartin Schirrmacher <vdr.zaphistory@schirrmacher.eu>2013-08-15 21:24:18 +0200
committerMartin Schirrmacher <vdr.zaphistory@schirrmacher.eu>2013-08-15 21:24:18 +0200
commit111b0cc69414d8025a66b3325a65d7286be87df7 (patch)
tree13e4ec5b46e6607456e7015b0aa1365994f35a8e /zaplist.c
downloadvdr-plugin-zaphistory-111b0cc69414d8025a66b3325a65d7286be87df7.tar.gz
vdr-plugin-zaphistory-111b0cc69414d8025a66b3325a65d7286be87df7.tar.bz2
initial commit
Diffstat (limited to 'zaplist.c')
-rw-r--r--zaplist.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/zaplist.c b/zaplist.c
new file mode 100644
index 0000000..0d3ebec
--- /dev/null
+++ b/zaplist.c
@@ -0,0 +1,124 @@
+/*
+ * zaplist.c: A plugin for the Video Disk Recorder
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ * $Id$
+ */
+
+#include <vdr/channels.h>
+
+#include "zaplist.h"
+#include "setup-zaphistory.h"
+
+cZapHistory ZapHistory;
+
+cZapHistoryChannel* cZapHistory::FindChannel(cChannel *channel) {
+ if (channel == NULL)
+ return NULL;
+
+ cZapHistoryChannel *returnVal = NULL;
+
+ // Look for channel
+ for ( cZapHistoryChannel *zapChan = First(); zapChan; zapChan = Next( zapChan ) ) {
+ if ( zapChan->GetChannelID() == channel->GetChannelID() ) {
+ returnVal = zapChan;
+ break;
+ }
+ }
+
+ return returnVal;
+}
+
+void cZapHistory::Reset( cZapHistoryChannel *zapChan, bool statisticOnly ) {
+ if (zapChan != NULL) { // Operate on ONE channel
+ if (statisticOnly) { // reset statistics
+ zapChan->Reset();
+ } else { // delete entry
+ if (zapChan == currentChannel)
+ currentChannel = NULL;
+ Del(zapChan);
+ }
+ } else { // operate in complete history
+ if (statisticOnly) { // reset statistics
+ for ( cZapHistoryChannel *zapChan = First(); zapChan; zapChan = Next( zapChan ) ) {
+ zapChan->Reset();
+ }
+ } else { // clear history
+ currentChannel = NULL;
+
+ while (First() != NULL) {
+ Del( First() );
+ }
+ }
+ }
+
+ Save();
+}
+
+void cZapHistory::UpdateHistory(cZapHistoryChannel *zapChan) {
+ for ( cZapHistoryChannel *chan = First(); chan; chan = Next( chan ) ) {
+ chan->SetHistoryPos( chan->GetHistoryPos() + 1);
+ }
+
+ zapChan->IncreaseZapCount();
+ zapChan->SetHistoryPos(1);
+ UpdateWatchTime();
+}
+
+cZapHistory::cZapHistory() {
+ currentChannel = NULL;
+ lastSwitch = time(NULL);
+ sortMode = historySort;
+}
+
+void cZapHistory::ViewInterrupted() {
+ // Add view time to current channel before playback of st. is started
+ UpdateWatchTime();
+
+ lastSwitch = -1;
+}
+
+cZapHistorySortMode cZapHistory::GetSortMode() {
+ return sortMode;
+}
+
+void cZapHistory::SetSortMode( cZapHistorySortMode mode ) {
+ sortMode = mode;
+}
+
+void cZapHistory::UpdateWatchTime() {
+ if (currentChannel == NULL || lastSwitch == -1)
+ return;
+
+ // Add wiew time since last switch
+ currentChannel->AddWatchTime( time(NULL) - lastSwitch );
+
+ lastSwitch = time(NULL);
+}
+
+void cZapHistory::ViewContinue() {
+ lastSwitch = time(NULL);
+}
+
+void cZapHistory::ChannelSwitch( cChannel *channel ) {
+ cZapHistoryChannel *zapChan = FindChannel( channel );
+
+ // Channel not in history management
+ if ( zapChan == NULL ) {
+ // Create new history channel
+ zapChan = new cZapHistoryChannel();
+ zapChan->SetChannelID( channel->GetChannelID() );
+ // Add channel to history
+ Ins( zapChan );
+ UpdateHistory(zapChan);
+ } else if (currentChannel != zapChan) { // Channel already in history management and
+ // a real switch (another channel)
+ UpdateHistory(zapChan);
+ }
+
+ currentChannel = zapChan;
+
+ // Write history to file
+ ZapHistory.Save();
+}