Skip to content

Commit

Permalink
[Setup]
Browse files Browse the repository at this point in the history
* introduce new config.usage.numberMode setting as an replacement for config.usage.alternative_number_mode

[eDVBDB]
* extend m_numbering_mode to use LCN channel numbers from lcndb
  • Loading branch information
jbleyel committed Jul 27, 2024
1 parent 05eec29 commit 20d11eb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
2 changes: 1 addition & 1 deletion data/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</setup>
<setup key="ChannelSelection" title="Channel Selection Settings" showOpenWebif="1">
<item level="0" text="Include CI assignment" description="Set CI assignment for detection of available services.">config.misc.use_ci_assignment</item>
<item level="1" text="Alternative numbering mode" description="When enabled, channel numbering will start at '1' for each bouquet.">config.usage.alternative_number_mode</item>
<item level="1" text="Numbering mode" description="Select 'Unique numbering' to assign unique numbers for every service in every bouquet. Use 'Bouquets start at 1' to start numbering each bouquet from 1. Use 'LCN numbering' to use consistent service LCNs where ever that service is used.">config.usage.numberMode</item>
<item level="1" text="Always show bouquets" description="Select 'Yes' to always show the bouquet screen first when opening the channel list. Select 'No' to open the channel list using the current bouquet.">config.usage.show_bouquetalways</item>
<item level="1" text="Change bouquets in quickzap" description="When enabled, continue to the next bouquet when the last channel of the current bouquet is reached while changing channels.">config.usage.quickzap_bouquet_change</item>
<item level="1" text="Channel list preview" description="Select 'Yes' to enable preview of channels while in the EPG list. Press 'OK' to preview the currently selected channel. Press 'OK' again to exit the EPG and zap to the selected channel. Press 'EXIT' to exit the EPG and return to the previously selected channel.">config.usage.servicelistpreview_mode</item>
Expand Down
76 changes: 63 additions & 13 deletions lib/dvb/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <lib/base/eerror.h>
#include <lib/base/estring.h>
#include <lib/base/esettings.h>
#include <lib/base/esimpleconfig.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <dvbsi++/service_description_section.h>
Expand Down Expand Up @@ -723,7 +724,33 @@ void eDVBDB::loadServicelist(const char *file)
return;
}

eDebug("[eDVBDB] lcndb");
char line[256];
m_lcnmap.clear();
std::string lfname = eEnv::resolve("${sysconfdir}/enigma2/lcndb");
CFile lf(lfname, "rt");
if(lf)
{
while (!feof(lf))
{
if (!fgets(line, sizeof(line), lf))
break;

int ns;
int onid;
int tsid;
int sid;
int lcn;
int signal = -1;
sscanf(line, "%x:%x:%x:%x:%d:%d",&ns, &onid, &tsid, &sid, &lcn, &signal);
if(signal > 0) {
eServiceReferenceDVB s = eServiceReferenceDVB(eDVBNamespace(ns), eTransportStreamID(tsid), eOriginalNetworkID(onid), eServiceID(sid), 0);
//eDebug("[eDVBDB] add lcndb %s / %d", s.toString().c_str(), lcn);
m_lcnmap.insert(std::pair<eServiceReferenceDVB, int>(s, lcn));
}
}
}

int version;
if ((!fgets(line, sizeof(line), f)) || sscanf(line, "eDVB services /%d/", &version) != 1)
{
Expand Down Expand Up @@ -1081,7 +1108,7 @@ void eDVBDB::loadBouquet(const char *path)
DIR *dir = opendir(p.c_str());
if (!dir)
{
eDebug("[eDVBDB] Cannot open directory where the userbouquets should be expected..");
eDebug("[eDVBDB] Error: Cannot open directory '%s' where the userbouquets should be expected.", p.c_str());
return;
}
dirent *entry;
Expand All @@ -1097,15 +1124,15 @@ void eDVBDB::loadBouquet(const char *path)
std::string bouquet_name = path;
if (!bouquet_name.length())
{
eDebug("[eDVBDB] Bouquet load failed.. no path given..");
eDebug("[eDVBDB] Error: Bouquet load failed. 'No path given.'");
return;
}
size_t pos = bouquet_name.rfind('/');
if ( pos != std::string::npos )
bouquet_name.erase(0, pos+1);
if (bouquet_name.empty())
{
eDebug("[eDVBDB] Bouquet load failed.. no filename given..");
eDebug("[eDVBDB] Error: Bouquet load failed. 'No filename given'");
return;
}
eBouquet &bouquet = m_bouquets[bouquet_name];
Expand All @@ -1122,7 +1149,10 @@ void eDVBDB::loadBouquet(const char *path)

for(int index = 0; searchpath[index]; index++)
{
file_path = enigma_conf + searchpath[index] + "/" + path;
if(index < 2)
file_path = enigma_conf + searchpath[index] + "/" + path;
else
file_path = enigma_conf + path;

if (!access(file_path.c_str(), R_OK))
{
Expand Down Expand Up @@ -1154,13 +1184,13 @@ void eDVBDB::loadBouquet(const char *path)
}
else
{
eDebug("[eDVBDB] can't load bouquet %s",path);
eDebug("[eDVBDB] can't load bouquet %s", path);
return;
}
}
}

eDebug("[eDVBDB] loading bouquet... %s", file_path.c_str());
eDebug("[eDVBDB] loading bouquet %s", file_path.c_str());
CFile fp(file_path, "rt");

if (fp)
Expand Down Expand Up @@ -1319,7 +1349,7 @@ void eDVBDB::renumberBouquet()
renumberBouquet( m_bouquets["bouquets.radio"] );
}

void eDVBDB::setNumberingMode(bool numberingMode)
void eDVBDB::setNumberingMode(int numberingMode)
{
if (m_numbering_mode != numberingMode)
{
Expand All @@ -1328,9 +1358,13 @@ void eDVBDB::setNumberingMode(bool numberingMode)
}
}


int eDVBDB::renumberBouquet(eBouquet &bouquet, int startChannelNum)
{
eDebug("[eDVBDB] Renumber %s, starting at %d", bouquet.m_bouquet_name.c_str(), startChannelNum);
if(startChannelNum == -1) // LCN
eDebug("[eDVBDB] Renumber %s, via LCN", bouquet.m_bouquet_name.c_str());
else
eDebug("[eDVBDB] Renumber %s, starting at %d", bouquet.m_bouquet_name.c_str(), startChannelNum);
std::list<eServiceReference> &list = bouquet.m_services;
bool addBQFlag = (bouquet.m_bouquet_name != "Last Scanned");

Expand All @@ -1350,16 +1384,31 @@ int eDVBDB::renumberBouquet(eBouquet &bouquet, int startChannelNum)
char *end = strchr(beg, endchr);
filename.assign(beg, end - beg);
eBouquet &subBouquet = m_bouquets[filename];
if (m_numbering_mode || filename.find("alternatives.") == 0)
if ((m_numbering_mode == 1) || filename.find("alternatives.") == 0)
renumberBouquet(subBouquet);
else
startChannelNum = renumberBouquet(subBouquet, startChannelNum);
}
}

}

if (!(ref.flags & (eServiceReference::isMarker | eServiceReference::isDirectory)) || (ref.flags & eServiceReference::isNumberedMarker))
{
if (m_numbering_mode == 2)
{
if (m_lcnmap.size())
{
eServiceReferenceDVB channel = eServiceReferenceDVB(ref.toString());
channel.setServiceType(0);
std::map<eServiceReferenceDVB, int>::iterator it = m_lcnmap.find(channel);
if (it != m_lcnmap.end())
ref.number = it->second;
}
}
else
ref.number = startChannelNum++;
}
if( !(ref.flags & (eServiceReference::isMarker|eServiceReference::isDirectory)) ||
(ref.flags & eServiceReference::isNumberedMarker) )
ref.number = startChannelNum++;

// add is in bouquet flag to m_services
if(addBQFlag && ref.flags == 0)
Expand All @@ -1377,9 +1426,10 @@ int eDVBDB::renumberBouquet(eBouquet &bouquet, int startChannelNum)
eDVBDB *eDVBDB::instance;

eDVBDB::eDVBDB()
: m_numbering_mode(false), m_load_unlinked_userbouquets(true)
: m_load_unlinked_userbouquets(true)
{
instance = this;
m_numbering_mode = eSimpleConfig::getInt("config.usage.numberMode", 0);
reloadServicelist();
}

Expand Down
6 changes: 4 additions & 2 deletions lib/dvb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class eDVBDB: public iDVBChannelList

std::map<std::string, eBouquet> m_bouquets;

bool m_numbering_mode, m_load_unlinked_userbouquets;
bool m_load_unlinked_userbouquets;
int m_numbering_mode;
#ifdef SWIG
eDVBDB();
~eDVBDB();
#endif
private:
void loadServiceListV5(FILE * f);
std::map<eServiceReferenceDVB, int> m_lcnmap;
public:
// iDVBChannelList
RESULT removeFlags(unsigned int flagmask, int dvb_namespace=-1, int tsid=-1, int onid=-1, unsigned int orb_pos=0xFFFFFFFF);
Expand Down Expand Up @@ -80,7 +82,7 @@ class eDVBDB: public iDVBChannelList
int renumberBouquet(eBouquet &bouquet, int startChannelNum = 1);
#endif
eServiceReference searchReference(int tsid, int onid, int sid);
void setNumberingMode(bool numberingMode);
void setNumberingMode(int numberingMode);
void setLoadUnlinkedUserbouquets(bool value) { m_load_unlinked_userbouquets=value; }
void renumberBouquet();
void loadServicelist(const char *filename);
Expand Down
15 changes: 11 additions & 4 deletions lib/python/Components/UsageConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,20 @@ def correctInvalidEPGDataChange(configElement):
])
config.usage.correct_invalid_epgdata.addNotifier(correctInvalidEPGDataChange)

config.usage.alternative_number_mode = ConfigYesNo(default=False)

def alternativeNumberModeChange(configElement):
def setNumberModeChange(configElement):
eDVBDB.getInstance().setNumberingMode(configElement.value)
config.usage.alternative_number_mode.value = config.usage.numberMode != 0
refreshServiceList()

config.usage.alternative_number_mode.addNotifier(alternativeNumberModeChange)
config.usage.numberMode = ConfigSelection(default=0, choices=[
(0, _("Unique numbering")),
(1, _("Bouquets start at 1")),
(2, _("LCN numbering"))
])
config.usage.numberMode.addNotifier(setNumberModeChange, initial_call=False)

# Fallback old settigs will be removed later because this setting is probably used in plugins
config.usage.alternative_number_mode = ConfigYesNo(default=config.usage.numberMode != 0)

config.usage.hide_number_markers = ConfigYesNo(default=True)
config.usage.hide_number_markers.addNotifier(refreshServiceList)
Expand Down

0 comments on commit 20d11eb

Please sign in to comment.