"CREATE TABLE map_channelgroups_channels ("
"idChannel integer, "
"idGroup integer, "
- "iChannelNumber integer"
+ "iChannelNumber integer, "
+ "iLastWatched integer"
")"
);
if (iVersion < 22)
m_pDS->exec("ALTER TABLE channels ADD bIsLocked bool");
+
+ if (iVersion < 23)
+ m_pDS->exec("ALTER TABLE channelgroups ADD iLastWatched integer");
}
int CPVRDatabase::GetLastChannelId(void)
{
CPVRChannelGroup data(m_pDS->fv("bIsRadio").get_asBool(), m_pDS->fv("idGroup").get_asInt(), m_pDS->fv("sName").get_asString());
data.SetGroupType(m_pDS->fv("iGroupType").get_asInt());
+ data.SetLastWatched((time_t) m_pDS->fv("iLastWatched").get_asInt());
results.Update(data);
CLog::Log(LOGDEBUG, "PVR - %s - group '%s' loaded from the database", __FUNCTION__, data.GroupName().c_str());
/* insert a new entry when this is a new group, or replace the existing one otherwise */
if (group.GroupID() <= 0)
- strQuery = PrepareSQL("INSERT INTO channelgroups (bIsRadio, iGroupType, sName) VALUES (%i, %i, '%s')",
- (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str());
+ strQuery = PrepareSQL("INSERT INTO channelgroups (bIsRadio, iGroupType, sName, iLastWatched) VALUES (%i, %i, '%s', %u)",
+ (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str(), group.LastWatched());
else
- strQuery = PrepareSQL("REPLACE INTO channelgroups (idGroup, bIsRadio, iGroupType, sName) VALUES (%i, %i, %i, '%s')",
- group.GroupID(), (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str());
+ strQuery = PrepareSQL("REPLACE INTO channelgroups (idGroup, bIsRadio, iGroupType, sName, iLastWatched) VALUES (%i, %i, %i, '%s', %u)",
+ group.GroupID(), (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str(), group.LastWatched());
bReturn = ExecuteQuery(strQuery);
* @brief Get the minimal database version that is required to operate correctly.
* @return The minimal database version.
*/
- virtual int GetSchemaVersion() const { return 22; };
+ virtual int GetSchemaVersion() const { return 23; };
/*!
* @brief Get the default sqlite database filename.
if (channel && channel->HasPVRChannelInfoTag())
{
CLog::Log(LOGNOTICE, "PVRManager - %s - continue playback on channel '%s'", __FUNCTION__, channel->GetPVRChannelInfoTag()->ChannelName().c_str());
- return StartPlayback(channel->GetPVRChannelInfoTag(), (CSettings::Get().GetInt("pvrplayback.startlast") == START_LAST_CHANNEL_MIN));
+ SetPlayingGroup(m_channelGroups->GetLastPlayedGroup());
+ StartPlayback(channel->GetPVRChannelInfoTag(), (CSettings::Get().GetInt("pvrplayback.startlast") == START_LAST_CHANNEL_MIN));
+ return true;
}
return false;
return bReturn;
CPVRChannelPtr playingChannel;
- bool bPersistChannel(false);
+ CPVRChannelGroupPtr group;
+ bool bPersistChanges(false);
if ((bReturn = m_addons->OpenStream(*channel.GetPVRChannelInfoTag(), false)) != false)
{
CSingleLock lock(m_critSection);
if (m_addons->GetPlayingChannel(playingChannel))
{
- /* store current time in iLastWatched */
time_t tNow;
CDateTime::GetCurrentDateTime().GetAsTime(tNow);
+
+ /* update last watched timestamp for channel */
playingChannel->SetLastWatched(tNow);
- bPersistChannel = true;
- m_channelGroups->SetLastPlayedGroup(GetPlayingGroup(playingChannel->IsRadio()));
+ /* update last watched timestamp for group */
+ group = g_PVRManager.GetPlayingGroup(playingChannel->IsRadio());
+ group->SetLastWatched(tNow);
+
+ /* update last played group */
+ m_channelGroups->SetLastPlayedGroup(group);
+
+ bPersistChanges = true;
}
}
- if (bPersistChannel)
+ if (bPersistChanges)
+ {
playingChannel->Persist();
+ group->Persist();
+ }
return bReturn;
}
void CPVRManager::CloseStream(void)
{
CPVRChannelPtr channel;
- bool bPersistChannel(false);
+ CPVRChannelGroupPtr group;
+ bool bPersistChanges(false);
{
CSingleLock lock(m_critSection);
if (m_addons->GetPlayingChannel(channel))
{
- /* store current time in iLastWatched */
time_t tNow;
CDateTime::GetCurrentDateTime().GetAsTime(tNow);
+
+ /* update last watched timestamp for channel */
channel->SetLastWatched(tNow);
- bPersistChannel = true;
- m_channelGroups->SetLastPlayedGroup(GetPlayingGroup(channel->IsRadio()));
+ /* update last watched timestamp for group */
+ group = g_PVRManager.GetPlayingGroup(channel->IsRadio());
+ group->SetLastWatched(tNow);
+
+ /* update last played group */
+ m_channelGroups->SetLastPlayedGroup(group);
+
+ bPersistChanges = true;
}
m_addons->CloseStream();
SAFE_DELETE(m_currentFile);
}
- if (bPersistChannel)
+ if (bPersistChanges)
+ {
channel->Persist();
+ group->Persist();
+ }
}
void CPVRManager::UpdateCurrentFile(void)
m_bChanged(false),
m_bUsingBackendChannelOrder(false),
m_bSelectedGroup(false),
- m_bPreventSortAndRenumber(false)
+ m_bPreventSortAndRenumber(false),
+ m_iLastWatched(0)
{
}
m_bChanged(false),
m_bUsingBackendChannelOrder(false),
m_bSelectedGroup(false),
- m_bPreventSortAndRenumber(false)
+ m_bPreventSortAndRenumber(false),
+ m_iLastWatched(0)
{
}
m_bChanged(false),
m_bUsingBackendChannelOrder(false),
m_bSelectedGroup(false),
- m_bPreventSortAndRenumber(false)
+ m_bPreventSortAndRenumber(false),
+ m_iLastWatched(0)
{
}
m_bChanged = group.m_bChanged;
m_bUsingBackendChannelOrder = group.m_bUsingBackendChannelOrder;
m_bUsingBackendChannelNumbers = group.m_bUsingBackendChannelNumbers;
+ m_iLastWatched = group.m_iLastWatched;
for (int iPtr = 0; iPtr < group.Size(); iPtr++)
m_members.push_back(group.m_members.at(iPtr));
return strReturn;
}
+time_t CPVRChannelGroup::LastWatched(void) const
+{
+ CSingleLock lock(m_critSection);
+ return m_iLastWatched;
+}
+
+bool CPVRChannelGroup::SetLastWatched(time_t iLastWatched)
+{
+ CSingleLock lock(m_critSection);
+
+ if (m_iLastWatched != iLastWatched)
+ {
+ /* update last watched */
+ m_iLastWatched = iLastWatched;
+ SetChanged();
+ m_bChanged = true;
+
+ return true;
+ }
+
+ return false;
+}
+
bool CPVRChannelGroup::PreventSortAndRenumber(void) const
{
CSingleLock lock(m_critSection);
int GroupType(void) const;
/*!
+ * @return Time group has been watched last.
+ */
+ time_t LastWatched() const;
+
+ /*!
+ * @brief Last time group has been watched
+ * @param iLastWatched The new value.
+ * @return True if something changed, false otherwise.
+ */
+ bool SetLastWatched(time_t iLastWatched);
+
+ /*!
* @brief Set if sorting and renumbering should happen after adding/updating channels to group.
* @param bPreventSortAndRenumber The new sorting and renumbering prevention value for this group.
*/
bool m_bUsingBackendChannelNumbers; /*!< true to use the channel numbers from 1 backend, false otherwise */
bool m_bSelectedGroup; /*!< true when this is the selected group, false otherwise */
bool m_bPreventSortAndRenumber; /*!< true when sorting and renumbering should not be done after adding/updating channels to the group */
+ time_t m_iLastWatched; /*!< last time group has been watched */
std::vector<PVRChannelGroupMember> m_members;
CCriticalSection m_critSection;
// create a new group if none was found
updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(m_bRadio, group.GroupID(), group.GroupName()));
updateGroup->SetGroupType(group.GroupType());
+ updateGroup->SetLastWatched(group.LastWatched());
m_groups.push_back(updateGroup);
}
else
return empty;
}
+CPVRChannelGroupPtr CPVRChannelGroups::GetLastPlayedGroup() const
+{
+ CSingleLock lock(m_critSection);
+
+ CPVRChannelGroupPtr group;
+ for (std::vector<CPVRChannelGroupPtr>::const_iterator it = m_groups.begin(); it != m_groups.end(); it++)
+ {
+ if ((*it)->LastWatched() > 0 && (!group || (*it)->LastWatched() > group->LastWatched()))
+ group = (*it);
+ }
+
+ return group;
+}
+
std::vector<CPVRChannelGroupPtr> CPVRChannelGroups::GetMembers() const
{
CSingleLock lock(m_critSection);
CPVRChannelGroupPtr GetLastGroup(void) const;
/*!
+ * @brief The group that was played last.
+ * @return The last watched group.
+ */
+ CPVRChannelGroupPtr GetLastPlayedGroup() const;
+
+ /*!
* @brief Get the list of groups.
* @param groups The list to store the results in.
* @return The amount of items that were added.
CFileItemPtr CPVRChannelGroupsContainer::GetLastPlayedChannel(void) const
{
- CFileItemPtr lastChannel = GetGroupAllTV()->GetLastPlayedChannel();
- bool bHasTVChannel(lastChannel && lastChannel->HasPVRChannelInfoTag());
+ CPVRChannelGroupPtr group = GetLastPlayedGroup();
+ if (group)
+ return group->GetLastPlayedChannel();
- CFileItemPtr lastRadioChannel = GetGroupAllRadio()->GetLastPlayedChannel();
- bool bHasRadioChannel(lastRadioChannel && lastRadioChannel->HasPVRChannelInfoTag());
+ return CFileItemPtr(new CFileItem);
+}
+
+CPVRChannelGroupPtr CPVRChannelGroupsContainer::GetLastPlayedGroup() const
+{
+ CPVRChannelGroupPtr groupTV = m_groupsTV->GetLastPlayedGroup();
+ CPVRChannelGroupPtr groupRadio = m_groupsRadio->GetLastPlayedGroup();
- if (!bHasTVChannel || (bHasRadioChannel && lastChannel->GetPVRChannelInfoTag()->LastWatched() < lastRadioChannel->GetPVRChannelInfoTag()->LastWatched()))
- return lastRadioChannel;
+ if (!groupTV || (groupRadio && groupTV->LastWatched() < groupRadio->LastWatched()))
+ return groupRadio;
- return lastChannel;
+ return groupTV;
}
bool CPVRChannelGroupsContainer::CreateChannel(const CPVRChannel &channel)
*/
CFileItemPtr GetLastPlayedChannel(void) const;
+ /*!
+ * @brief The group that was played last.
+ * @return The last watched group.
+ */
+ CPVRChannelGroupPtr GetLastPlayedGroup() const;
+
bool CreateChannel(const CPVRChannel &channel);
/*!