diff options
-rw-r--r-- | addons/resource.language.en_gb/resources/strings.po | 12 | ||||
-rwxr-xr-x | system/settings/settings.xml | 12 | ||||
-rw-r--r-- | xbmc/pvr/PVRManager.cpp | 76 | ||||
-rw-r--r-- | xbmc/pvr/PVRManager.h | 10 | ||||
-rw-r--r-- | xbmc/settings/Settings.cpp | 1 | ||||
-rw-r--r-- | xbmc/settings/Settings.h | 1 |
6 files changed, 100 insertions, 12 deletions
diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index dbbfb013a2..51a400f154 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -10277,7 +10277,11 @@ msgctxt "#19194" msgid "Continue?" msgstr "" -#empty string with id 19195 +#. pvr settings "delay mark last watched" setting label +#: system/settings/settings.xml +msgctxt "#19195" +msgid "Delay mark last watched" +msgstr "" #. value for "pvr client specific actions" dialog headers #: xbmc/pvr/PVRGUIActions.cpp @@ -18634,7 +18638,11 @@ msgctxt "#36235" msgid "Normal timeshift OSD always shows the complete timeshift buffer along with with the currently playing show, whereas the simple timeshift OSD only shows the currently playing show with no visual feedback how far in the timeshift buffer you can jump from the currently playing position." msgstr "" -#empty string with id 36236 +#: system/settings/settings.xml +msgctxt "#36236" +msgid "If set to a value greater than zero last watched time of channels will be stored the given amount of time after start of channel playback. Otherwise the last watched time will be stored immediately at start of channel playback." +msgstr "" + #: system/settings/settings.xml msgctxt "#36237" diff --git a/system/settings/settings.xml b/system/settings/settings.xml index 3996711db7..d83bc8d393 100755 --- a/system/settings/settings.xml +++ b/system/settings/settings.xml @@ -1420,6 +1420,18 @@ <formatlabel>14046</formatlabel> </control> </setting> + <setting id="pvrplayback.delaymarklastwatched" type="integer" label="19195" help="36236"> + <level>3</level> + <default>0</default> + <constraints> + <minimum>0</minimum> + <step>30</step> + <maximum>600</maximum> + </constraints> + <control type="spinner" format="string"> + <formatlabel>14045</formatlabel> + </control> + </setting> <setting id="pvrplayback.fps" type="integer" label="19108" help="36261"> <level>0</level> <default>0</default> diff --git a/xbmc/pvr/PVRManager.cpp b/xbmc/pvr/PVRManager.cpp index 161b73ad8b..b482fb7738 100644 --- a/xbmc/pvr/PVRManager.cpp +++ b/xbmc/pvr/PVRManager.cpp @@ -17,6 +17,7 @@ #include "messaging/ApplicationMessenger.h" #include "settings/Settings.h" #include "threads/SystemClock.h" +#include "threads/Timer.h" #include "utils/JobManager.h" #include "utils/Stopwatch.h" #include "utils/StringUtils.h" @@ -127,6 +128,7 @@ CPVRManager::CPVRManager(void) : m_database(new CPVRDatabase), m_parentalTimer(new CStopWatch), m_settings({ + CSettings::SETTING_PVRPLAYBACK_DELAYMARKLASTWATCHED, CSettings::SETTING_PVRPOWERMANAGEMENT_ENABLED, CSettings::SETTING_PVRPOWERMANAGEMENT_SETWAKEUPCMD, CSettings::SETTING_PVRPARENTAL_ENABLED, @@ -730,6 +732,33 @@ CPVRChannelGroupPtr CPVRManager::GetPlayingGroup(bool bRadio /* = false */) cons return CPVRChannelGroupPtr(); } +class CPVRManager::CLastWatchedUpdateTimer : public CTimer, private ITimerCallback +{ +public: + explicit CLastWatchedUpdateTimer(CPVRManager& pvrMgr, + const std::shared_ptr<CPVRChannel>& channel, + const CDateTime& time) + : CTimer(this), + m_pvrMgr(pvrMgr), + m_channel(channel), + m_time(time) + { + } + + // ITimerCallback implementation + void OnTimeout() override + { + m_pvrMgr.UpdateLastWatched(m_channel, m_time); + } + +private: + CLastWatchedUpdateTimer() = delete; + + CPVRManager& m_pvrMgr; + const std::shared_ptr<CPVRChannel> m_channel; + const CDateTime m_time; +}; + void CPVRManager::OnPlaybackStarted(const CFileItemPtr item) { m_playingChannel.reset(); @@ -746,7 +775,22 @@ void CPVRManager::OnPlaybackStarted(const CFileItemPtr item) m_playingClientId = m_playingChannel->ClientID(); SetPlayingGroup(channel); - UpdateLastWatched(channel); + + int iLastWatchedDelay = m_settings.GetIntValue(CSettings::SETTING_PVRPLAYBACK_DELAYMARKLASTWATCHED) * 1000; + if (iLastWatchedDelay > 0) + { + // Insert new / replace existing last watched update timer + if (m_lastWatchedUpdateTimer) + m_lastWatchedUpdateTimer->Stop(true); + + m_lastWatchedUpdateTimer.reset(new CLastWatchedUpdateTimer(*this, channel, CDateTime::GetUTCDateTime())); + m_lastWatchedUpdateTimer->Start(iLastWatchedDelay); + } + else + { + // Store last watched timestamp immediately + UpdateLastWatched(channel, CDateTime::GetUTCDateTime()); + } } else if (item->HasPVRRecordingInfoTag()) { @@ -776,7 +820,25 @@ void CPVRManager::OnPlaybackStopped(const CFileItemPtr item) if (item->HasPVRChannelInfoTag() && item->GetPVRChannelInfoTag() == m_playingChannel) { - UpdateLastWatched(item->GetPVRChannelInfoTag()); + bool bUpdateLastWatched = true; + + if (m_lastWatchedUpdateTimer) + { + if (m_lastWatchedUpdateTimer->IsRunning()) + { + // If last watched timer is still running, cancel it. Channel was not watched long enough to store the value. + m_lastWatchedUpdateTimer->Stop(true); + bUpdateLastWatched = false; + } + m_lastWatchedUpdateTimer.reset(); + } + + if (bUpdateLastWatched) + { + // If last watched timer is not running (any more), channel was watched long enough to store the value. + UpdateLastWatched(m_playingChannel, CDateTime::GetUTCDateTime()); + } + SetChanged(); NotifyObservers(ObservableMessageChannelPlaybackStopped); @@ -918,16 +980,16 @@ bool CPVRManager::CreateChannelEpgs(void) return m_bEpgsCreated; } -void CPVRManager::UpdateLastWatched(const CPVRChannelPtr &channel) +void CPVRManager::UpdateLastWatched(const CPVRChannelPtr &channel, const CDateTime& time) { - time_t tNow; - CDateTime::GetCurrentDateTime().GetAsTime(tNow); + time_t iTime; + time.GetAsTime(iTime); - channel->SetLastWatched(tNow); + channel->SetLastWatched(iTime); // update last watched timestamp for group CPVRChannelGroupPtr group(GetPlayingGroup(channel->IsRadio())); - group->SetLastWatched(tNow); + group->SetLastWatched(iTime); /* update last played group */ m_channelGroups->SetLastPlayedGroup(group); diff --git a/xbmc/pvr/PVRManager.h b/xbmc/pvr/PVRManager.h index dac66cb150..bbb9673b1f 100644 --- a/xbmc/pvr/PVRManager.h +++ b/xbmc/pvr/PVRManager.h @@ -445,8 +445,9 @@ namespace PVR /*! * @brief Updates the last watched timestamps of the channel and group which are currently playing. * @param channel The channel which is updated + * @param time The last watched time to set */ - void UpdateLastWatched(const CPVRChannelPtr &channel); + void UpdateLastWatched(const CPVRChannelPtr &channel, const CDateTime& time); /*! * @brief Set the playing group to the first group the channel is in if the given channel is not part of the current playing group @@ -523,8 +524,8 @@ namespace PVR CPVRDatabasePtr m_database; /*!< the database for all PVR related data */ mutable CCriticalSection m_critSection; /*!< critical section for all changes to this class, except for changes to triggers */ - bool m_bFirstStart = true; /*!< true when the PVR manager was started first, false otherwise */ - bool m_bEpgsCreated = false; /*!< true if epg data for channels has been created */ + bool m_bFirstStart = true; /*!< true when the PVR manager was started first, false otherwise */ + bool m_bEpgsCreated = false; /*!< true if epg data for channels has been created */ mutable CCriticalSection m_managerStateMutex; ManagerState m_managerState = ManagerStateStopped; @@ -542,5 +543,8 @@ namespace PVR CPVREpgInfoTagPtr m_playingEpgTag; std::string m_strPlayingClientName; int m_playingClientId = -1; + + class CLastWatchedUpdateTimer; + std::unique_ptr<CLastWatchedUpdateTimer> m_lastWatchedUpdateTimer; }; } diff --git a/xbmc/settings/Settings.cpp b/xbmc/settings/Settings.cpp index b3f021b03f..0f50e170c4 100644 --- a/xbmc/settings/Settings.cpp +++ b/xbmc/settings/Settings.cpp @@ -216,6 +216,7 @@ const std::string CSettings::SETTING_PVRPLAYBACK_SWITCHTOFULLSCREEN = "pvrplayba const std::string CSettings::SETTING_PVRPLAYBACK_SIGNALQUALITY = "pvrplayback.signalquality"; const std::string CSettings::SETTING_PVRPLAYBACK_CONFIRMCHANNELSWITCH = "pvrplayback.confirmchannelswitch"; const std::string CSettings::SETTING_PVRPLAYBACK_CHANNELENTRYTIMEOUT = "pvrplayback.channelentrytimeout"; +const std::string CSettings::SETTING_PVRPLAYBACK_DELAYMARKLASTWATCHED = "pvrplayback.delaymarklastwatched"; const std::string CSettings::SETTING_PVRPLAYBACK_FPS = "pvrplayback.fps"; const std::string CSettings::SETTING_PVRRECORD_INSTANTRECORDACTION = "pvrrecord.instantrecordaction"; const std::string CSettings::SETTING_PVRRECORD_INSTANTRECORDTIME = "pvrrecord.instantrecordtime"; diff --git a/xbmc/settings/Settings.h b/xbmc/settings/Settings.h index 59a39679b6..29536d40af 100644 --- a/xbmc/settings/Settings.h +++ b/xbmc/settings/Settings.h @@ -176,6 +176,7 @@ public: static const std::string SETTING_PVRPLAYBACK_SIGNALQUALITY; static const std::string SETTING_PVRPLAYBACK_CONFIRMCHANNELSWITCH; static const std::string SETTING_PVRPLAYBACK_CHANNELENTRYTIMEOUT; + static const std::string SETTING_PVRPLAYBACK_DELAYMARKLASTWATCHED; static const std::string SETTING_PVRPLAYBACK_FPS; static const std::string SETTING_PVRRECORD_INSTANTRECORDACTION; static const std::string SETTING_PVRRECORD_INSTANTRECORDTIME; |