Skip to content

Commit

Permalink
Merge pull request #16593 from phunkyfish/group-member-backend-channel
Browse files Browse the repository at this point in the history
[pvr] support group specific channel numbering and option to start group number locally from 1
  • Loading branch information
phunkyfish committed Sep 26, 2019
2 parents b6727d4 + d098a4f commit b8b5fc7
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 74 deletions.
17 changes: 13 additions & 4 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -10971,7 +10971,13 @@ msgctxt "#19315"
msgid "Backend order"
msgstr ""

#empty strings from id 19316 to 19498
#. pvr settings "Start all group channel numbers from 1" setting label
#: system/settings/settings.xml
msgctxt "#19316"
msgid "Start group channel numbers from 1"
msgstr ""

#empty strings from id 19317 to 19498

#. label for epg genre value
#: xbmc/pvr/epg/Epg.cpp
Expand Down Expand Up @@ -18550,12 +18556,12 @@ msgstr ""

#: system/settings/settings.xml
msgctxt "#36205"
msgid "Sort the channels by channel number from the backend, but use own numbering for channels."
msgid "Sort the channels by channel number from the backend, but use local numbering for channels."
msgstr ""

#: system/settings/settings.xml
msgctxt "#36206"
msgid "Use the channel numbering from the backend, instead of configuring them manually in the channel manager. Only works with one enabled PVR add-on!"
msgid "Use the channel numbering from the backend. Only works with one enabled PVR add-on!"
msgstr ""

#: system/settings/settings.xml
Expand Down Expand Up @@ -19092,7 +19098,10 @@ msgctxt "#36305"
msgid "This category contains the settings for how picture file lists are handled."
msgstr ""

#empty string with id 36306
#: system/settings/settings.xml
msgctxt "#36306"
msgid "If not using backend channel numbers then start all groups channel numbers from 1."
msgstr ""

#. Description of setting with label #13360 "Automatically generate thumbnails"
#: system/settings/settings.xml
Expand Down
9 changes: 9 additions & 0 deletions system/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,15 @@
<default>false</default>
<control type="toggle" />
</setting>
<setting id="pvrmanager.startgroupchannelnumbersfromone" type="boolean" parent="pvrmanager.usebackendchannelnumbers" label="19316" help="36306">
<level>2</level>
<dependencies>
<dependency type="visible" on="property" name="pvrsettingvisible" setting="pvrmanager.usebackendchannelnumbers" operator="is">true</dependency>
<dependency type="enable" setting="pvrmanager.usebackendchannelnumbers" operator="is">false</dependency>
</dependencies>
<default>false</default>
<control type="toggle" />
</setting>
<setting id="pvrmanager.clientpriorities" type="action" label="19240" help="36210">
<level>2</level>
<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions xbmc/addons/PVRClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ void CPVRClient::cb_transfer_channel_group_member(void *kodiInstance, const ADDO
else if (group->IsRadio() == channel->IsRadio())
{
/* transfer this entry to the group */
group->AddToGroup(channel, CPVRChannelNumber(member->iChannelNumber, member->iSubChannelNumber), member->iOrder, true);
group->AddToGroup(channel, CPVRChannelNumber(), member->iOrder, true, CPVRChannelNumber(member->iChannelNumber, member->iSubChannelNumber));
}
}

Expand Down Expand Up @@ -1536,7 +1536,7 @@ void CPVRClient::cb_transfer_channel_entry(void *kodiInstance, const ADDON_HANDL

/* transfer this entry to the internal channels group */
CPVRChannelPtr transferChannel(new CPVRChannel(*channel, client->GetID()));
kodiChannels->UpdateFromClient(transferChannel, CPVRChannelNumber(), channel->iOrder);
kodiChannels->UpdateFromClient(transferChannel, CPVRChannelNumber(), channel->iOrder, transferChannel->ClientChannelNumber());
}

void CPVRClient::cb_transfer_recording_entry(void *kodiInstance, const ADDON_HANDLE handle, const PVR_RECORDING *recording)
Expand Down
37 changes: 27 additions & 10 deletions xbmc/pvr/PVRDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ void CPVRDatabase::CreateTables()
"idGroup integer, "
"iChannelNumber integer, "
"iSubChannelNumber integer, "
"iOrder integer"
"iOrder integer, "
"iClientChannelNumber integer, "
"iClientSubChannelNumber integer"
")"
);

Expand Down Expand Up @@ -208,6 +210,14 @@ void CPVRDatabase::UpdateTables(int iVersion)
m_pDS->exec("ALTER TABLE map_channelgroups_channels ADD iOrder integer");
m_pDS->exec("UPDATE map_channelgroups_channels SET iOrder = 0");
}

if (iVersion < 36)
{
m_pDS->exec("ALTER TABLE map_channelgroups_channels ADD iClientChannelNumber integer");
m_pDS->exec("UPDATE map_channelgroups_channels SET iClientChannelNumber = 0");
m_pDS->exec("ALTER TABLE map_channelgroups_channels ADD iClientSubChannelNumber integer");
m_pDS->exec("UPDATE map_channelgroups_channels SET iClientSubChannelNumber = 0");
}
}

/********** Client methods **********/
Expand Down Expand Up @@ -300,7 +310,8 @@ int CPVRDatabase::Get(CPVRChannelGroup &results, bool bCompressDB)

std::string strQuery = PrepareSQL("SELECT channels.idChannel, channels.iUniqueId, channels.bIsRadio, channels.bIsHidden, channels.bIsUserSetIcon, channels.bIsUserSetName, "
"channels.sIconPath, channels.sChannelName, channels.bIsVirtual, channels.bEPGEnabled, channels.sEPGScraper, channels.iLastWatched, channels.iClientId, channels.bIsLocked, "
"map_channelgroups_channels.iChannelNumber, map_channelgroups_channels.iSubChannelNumber, map_channelgroups_channels.iOrder, channels.idEpg, channels.bHasArchive "
"map_channelgroups_channels.iChannelNumber, map_channelgroups_channels.iSubChannelNumber, map_channelgroups_channels.iOrder, map_channelgroups_channels.iClientChannelNumber, "
"map_channelgroups_channels.iClientSubChannelNumber, channels.idEpg, channels.bHasArchive "
"FROM map_channelgroups_channels "
"LEFT JOIN channels ON channels.idChannel = map_channelgroups_channels.idChannel "
"WHERE map_channelgroups_channels.idGroup = %u", results.GroupID());
Expand Down Expand Up @@ -334,7 +345,9 @@ int CPVRDatabase::Get(CPVRChannelGroup &results, bool bCompressDB)
PVRChannelGroupMember newMember(channel,
CPVRChannelNumber(static_cast<unsigned int>(m_pDS->fv("iChannelNumber").get_asInt()),
static_cast<unsigned int>(m_pDS->fv("iSubChannelNumber").get_asInt())),
0, static_cast<int>(m_pDS->fv("iOrder").get_asInt()));
0, static_cast<int>(m_pDS->fv("iOrder").get_asInt()),
CPVRChannelNumber(static_cast<unsigned int>(m_pDS->fv("iClientChannelNumber").get_asInt()),
static_cast<unsigned int>(m_pDS->fv("iClientSubChannelNumber").get_asInt())));
results.m_sortedMembers.emplace_back(newMember);
results.m_members.insert(std::make_pair(channel->StorageId(), newMember));

Expand Down Expand Up @@ -617,7 +630,7 @@ int CPVRDatabase::Get(CPVRChannelGroup &group, const CPVRChannelGroup &allGroup)

CSingleLock lock(m_critSection);

const std::string strQuery = PrepareSQL("SELECT idChannel, iChannelNumber, iSubChannelNumber, iOrder FROM map_channelgroups_channels "
const std::string strQuery = PrepareSQL("SELECT idChannel, iChannelNumber, iSubChannelNumber, iOrder, iClientChannelNumber, iClientSubChannelNumber FROM map_channelgroups_channels "
"WHERE idGroup = %u ORDER BY iChannelNumber", group.GroupID());
if (ResultQuery(strQuery))
{
Expand All @@ -642,7 +655,9 @@ int CPVRDatabase::Get(CPVRChannelGroup &group, const CPVRChannelGroup &allGroup)
PVRChannelGroupMember newMember(channel->second,
CPVRChannelNumber(static_cast<unsigned int>(m_pDS->fv("iChannelNumber").get_asInt()),
static_cast<unsigned int>(m_pDS->fv("iSubChannelNumber").get_asInt())),
0, static_cast<int>(m_pDS->fv("iOrder").get_asInt()));
0, static_cast<int>(m_pDS->fv("iOrder").get_asInt()),
CPVRChannelNumber(static_cast<unsigned int>(m_pDS->fv("iClientChannelNumber").get_asInt()),
static_cast<unsigned int>(m_pDS->fv("iClientSubChannelNumber").get_asInt())));
group.m_sortedMembers.emplace_back(newMember);
group.m_members.insert(std::make_pair(channel->second->StorageId(), newMember));
++iReturn;
Expand Down Expand Up @@ -724,16 +739,18 @@ bool CPVRDatabase::PersistGroupMembers(const CPVRChannelGroup &group)
{
for (const auto& groupMember : group.m_sortedMembers)
{
const std::string strWhereClause = PrepareSQL("idChannel = %u AND idGroup = %u AND iChannelNumber = %u AND iSubChannelNumber = %u AND iOrder = %u",
groupMember.channel->ChannelID(), group.GroupID(), groupMember.channelNumber.GetChannelNumber(), groupMember.channelNumber.GetSubChannelNumber());
const std::string strWhereClause = PrepareSQL("idChannel = %u AND idGroup = %u AND iChannelNumber = %u AND iSubChannelNumber = %u AND iOrder = %u AND iClientChannelNumber = %u AND iClientSubChannelNumber = %u",
groupMember.channel->ChannelID(), group.GroupID(), groupMember.channelNumber.GetChannelNumber(), groupMember.channelNumber.GetSubChannelNumber(), groupMember.iOrder,
groupMember.clientChannelNumber.GetChannelNumber(), groupMember.clientChannelNumber.GetSubChannelNumber());

const std::string strValue = GetSingleValue("map_channelgroups_channels", "idChannel", strWhereClause);
if (strValue.empty())
{
strQuery = PrepareSQL("REPLACE INTO map_channelgroups_channels ("
"idGroup, idChannel, iChannelNumber, iSubChannelNumber, iOrder) "
"VALUES (%i, %i, %i, %i, %i);",
group.GroupID(), groupMember.channel->ChannelID(), groupMember.channelNumber.GetChannelNumber(), groupMember.channelNumber.GetSubChannelNumber(), groupMember.iOrder);
"idGroup, idChannel, iChannelNumber, iSubChannelNumber, iOrder, iClientChannelNumber, iClientSubChannelNumber) "
"VALUES (%i, %i, %i, %i, %i, %i, %i);",
group.GroupID(), groupMember.channel->ChannelID(), groupMember.channelNumber.GetChannelNumber(), groupMember.channelNumber.GetSubChannelNumber(), groupMember.iOrder,
groupMember.clientChannelNumber.GetChannelNumber(), groupMember.clientChannelNumber.GetSubChannelNumber());
QueueInsertQuery(strQuery);
}
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/PVRDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace PVR
* @brief Get the minimal database version that is required to operate correctly.
* @return The minimal database version.
*/
int GetSchemaVersion() const override { return 35; }
int GetSchemaVersion() const override { return 36; }

/*!
* @brief Get the default sqlite database filename.
Expand Down
13 changes: 13 additions & 0 deletions xbmc/pvr/channels/PVRChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,19 @@ void CPVRChannel::SetChannelNumber(const CPVRChannelNumber& channelNumber)
}
}

void CPVRChannel::SetClientChannelNumber(const CPVRChannelNumber& clientChannelNumber)
{
CSingleLock lock(m_critSection);
if (m_clientChannelNumber != clientChannelNumber)
{
m_clientChannelNumber = clientChannelNumber;

const std::shared_ptr<CPVREpg> epg = GetEPG();
if (epg)
epg->GetChannelData()->SetSortableClientChannelNumber(m_clientChannelNumber.SortableChannelNumber());
}
}

void CPVRChannel::ToSortable(SortItem& sortable, Field field) const
{
CSingleLock lock(m_critSection);
Expand Down
10 changes: 8 additions & 2 deletions xbmc/pvr/channels/PVRChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ namespace PVR
*/
void SetChannelNumber(const CPVRChannelNumber& channelNumber);

/*!
* @brief Set the client channel number for this channel.
* @param clientChannelNumber The new client channel number
*/
void SetClientChannelNumber(const CPVRChannelNumber& clientChannelNumber);

/*!
* @brief Get the channel number for this channel.
* @return The channel number.
Expand Down Expand Up @@ -443,7 +449,7 @@ namespace PVR
std::string m_strChannelName; /*!< the name for this channel used by XBMC */
time_t m_iLastWatched = 0; /*!< last time channel has been watched */
bool m_bChanged = false; /*!< true if anything in this entry was changed that needs to be persisted */
CPVRChannelNumber m_channelNumber; /*!< the number this channel has in the currently selected channel group */
CPVRChannelNumber m_channelNumber; /*!< the active channel number this channel has in the currently selected channel group */
std::shared_ptr<CPVRRadioRDSInfoTag> m_rdsTag; /*! < the radio rds data, if available for the channel. */
bool m_bHasArchive = false; /*!< true if this channel supports archive */
//@}
Expand All @@ -462,7 +468,7 @@ namespace PVR
//@{
int m_iUniqueId = -1; /*!< the unique identifier for this channel */
int m_iClientId = -1; /*!< the identifier of the client that serves this channel */
CPVRChannelNumber m_clientChannelNumber; /*!< the channel number on the client */
CPVRChannelNumber m_clientChannelNumber; /*!< the channel number on the client for the currently selected channel group */
std::string m_strClientChannelName; /*!< the name of this channel on the client */
std::string m_strInputFormat; /*!< the stream input type based on ffmpeg/libavformat/allformats.c */
std::string m_strFileNameAndPath; /*!< the filename to be used by PVRManager to open and read the stream */
Expand Down

0 comments on commit b8b5fc7

Please sign in to comment.