X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/198b91600d552127762c7d24502398dab3fc4594..9925392e576717cc0df070ace822a6f392808bb7:/lib/dvb/db.cpp diff --git a/lib/dvb/db.cpp b/lib/dvb/db.cpp index 153f5804..2665877a 100644 --- a/lib/dvb/db.cpp +++ b/lib/dvb/db.cpp @@ -10,7 +10,6 @@ DEFINE_REF(eDVBService); -// the following three methodes are declared in idvb.h RESULT eBouquet::addService(const eServiceReference &ref) { list::iterator it = @@ -52,6 +51,49 @@ RESULT eBouquet::moveService(const eServiceReference &ref, unsigned int pos) return 0; } +RESULT eBouquet::flushChanges() +{ + FILE *f=fopen(m_path.c_str(), "wt"); + if (!f) + return -1; + if ( fprintf(f, "#NAME %s\r\n", m_bouquet_name.c_str()) < 0 ) + goto err; + for (list::iterator i(m_services.begin()); i != m_services.end(); ++i) + { + eServiceReference tmp = *i; + std::string str = tmp.path; + if ( (i->flags&eServiceReference::flagDirectory) == eServiceReference::flagDirectory ) + { + unsigned int p1 = str.find("FROM BOUQUET \""); + if (p1 == std::string::npos) + { + eDebug("doof... kaputt"); + continue; + } + str.erase(0, p1+14); + p1 = str.find("\""); + if (p1 == std::string::npos) + { + eDebug("doof2... kaputt"); + continue; + } + str.erase(p1); + tmp.path=str; + } + if ( fprintf(f, "#SERVICE %s\r\n", tmp.toString().c_str()) < 0 ) + goto err; + if ( i->name.length() ) + if ( fprintf(f, "#DESCRIPTION %s\r\n", i->name.c_str()) < 0 ) + goto err; + } + fclose(f); + return 0; +err: + fclose(f); + eDebug("couldn't write file %s", m_path.c_str()); + return -1; +} + eDVBService::eDVBService() { } @@ -71,6 +113,18 @@ eDVBService &eDVBService::operator=(const eDVBService &s) return *this; } +void eDVBService::genSortName() +{ + m_service_name_sort = removeDVBChars(m_service_name); + makeUpper(m_service_name_sort); + while ((!m_service_name_sort.empty()) && m_service_name_sort[0] == ' ') + m_service_name_sort.erase(0, 1); + + /* put unnamed services at the end, not at the beginning. */ + if (m_service_name_sort.empty()) + m_service_name_sort = "\xFF"; +} + RESULT eDVBService::getName(const eServiceReference &ref, std::string &name) { if (!ref.name.empty()) @@ -261,15 +315,8 @@ void eDVBDB::load() line[strlen(line)-1]=0; s->m_service_name = line; - s->m_service_name_sort = removeDVBChars(line); - makeUpper(s->m_service_name_sort); - while ((!s->m_service_name_sort.empty()) && s->m_service_name_sort[0] == ' ') - s->m_service_name_sort.erase(0, 1); - - /* put unnamed services at the end, not at the beginning. */ - if (s->m_service_name_sort.empty()) - s->m_service_name_sort = "\xFF"; - + s->genSortName(); + fgets(line, 256, f); if (strlen(line)) line[strlen(line)-1]=0; @@ -416,6 +463,18 @@ void eDVBDB::loadBouquet(const char *path) if (!fp) { eDebug("failed to open."); + if ( strstr(path, "bouquets.tv") ) + { + eDebug("recreate bouquets.tv"); + bouquet.m_bouquet_name="Bouquets (TV)"; + bouquet.flushChanges(); + } + else if ( strstr(path, "bouquets.radio") ) + { + eDebug("recreate bouquets.radio"); + bouquet.m_bouquet_name="Bouquets (Radio)"; + bouquet.flushChanges(); + } return; } char line[256]; @@ -485,6 +544,39 @@ void eDVBDB::loadBouquets() { loadBouquet("bouquets.tv"); loadBouquet("bouquets.radio"); +// create default bouquets when missing + if ( m_bouquets.find("userbouquet.favourites.tv") == m_bouquets.end() ) + { + eBouquet &b = m_bouquets["userbouquet.favourites.tv"]; + b.m_path = "userbouquet.favourites.tv"; + b.m_bouquet_name = "Favourites (TV)"; + b.flushChanges(); + eServiceReference ref; + memset(ref.data, 0, sizeof(ref.data)); + ref.type=1; + ref.flags=7; + ref.data[0]=1; + ref.path="(type == 1) FROM BOUQUET \"userbouquet.favourites.tv\" ORDER BY bouquet"; + eBouquet &parent = m_bouquets["bouquets.tv"]; + parent.m_services.push_back(ref); + parent.flushChanges(); + } + if ( m_bouquets.find("userbouquet.favourites.radio") == m_bouquets.end() ) + { + eBouquet &b = m_bouquets["userbouquet.favourites.radio"]; + b.m_path = "userbouquet.favourites.radio"; + b.m_bouquet_name = "Favourites (Radio)"; + b.flushChanges(); + eServiceReference ref; + memset(ref.data, 0, sizeof(ref.data)); + ref.type=1; + ref.flags=7; + ref.data[0]=1; + ref.path="(type == 2) FROM BOUQUET \"userbouquet.favourites.radio\" ORDER BY bouquet"; + eBouquet &parent = m_bouquets["bouquets.radio"]; + parent.m_services.push_back(ref); + parent.flushChanges(); + } } void eDVBDB::saveBouquets() @@ -549,6 +641,12 @@ RESULT eDVBDB::getService(const eServiceReferenceDVB &reference, ePtr