X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/40d02f130ec7ce66be08013e33b2006fa1453299..7542f853b1a682ad9bf21b592f26e31e3b64521c:/lib/service/servicefs.cpp diff --git a/lib/service/servicefs.cpp b/lib/service/servicefs.cpp index 708825f6..a225ae07 100644 --- a/lib/service/servicefs.cpp +++ b/lib/service/servicefs.cpp @@ -36,7 +36,10 @@ eServiceFactoryFS::eServiceFactoryFS() eServiceCenter::getPrivInstance(sc); if (sc) - sc->addServiceFactory(eServiceFactoryFS::id, this); + { + std::list extensions; + sc->addServiceFactory(eServiceFactoryFS::id, this, extensions); + } m_service_information = new eStaticServiceFSInformation(); } @@ -67,7 +70,7 @@ RESULT eServiceFactoryFS::record(const eServiceReference &ref, ePtr &ptr) { - ptr = new eServiceFS(ref.path.c_str()); + ptr = new eServiceFS(ref.path.c_str(), ref.getName().length() ? ref.getName().c_str() : 0); return 0; } @@ -87,15 +90,75 @@ RESULT eServiceFactoryFS::offlineOperations(const eServiceReference &, ePtr(c)); +} + RESULT eServiceFS::getContent(std::list &list, bool sorted) { DIR *d=opendir(path.c_str()); @@ -130,29 +193,27 @@ RESULT eServiceFS::getContent(std::list &list, bool sorted) } else { size_t e = filename.rfind('.'); - std::string extension = (e != std::string::npos) ? filename.substr(e) : ""; - int type = -1; - - if (extension == ".ts") - type = eServiceFactoryDVB::id; - else if (extension == ".mp3") - type = 4097; - else if (extension == ".ogg") - type = 4097; - else if (extension == ".mpg") - type = 4097; - else if (extension == ".vob") - type = 4097; - else if (extension == ".wav" || extension == ".wave") - type = 4097; - - if (type != -1) + if (e != std::string::npos && e+1 < filename.length()) { - eServiceReference service(type, - 0, - filename); - service.data[0] = 0; - list.push_back(service); + std::string extension = filename.substr(e+1); + std::transform(extension.begin(), extension.end(), extension.begin(), lower); + int type = getServiceTypeForExtension(extension); + + if (type == -1) + { + ePtr sc; + eServiceCenter::getPrivInstance(sc); + type = sc->getServiceTypeForExtension(extension); + } + + if (type != -1) + { + eServiceReference service(type, + 0, + filename); + service.data[0] = 0; + list.push_back(service); + } } } } @@ -169,6 +230,7 @@ RESULT eServiceFS::getContent(std::list &list, bool sorted) // useable format options are // R = Service Reference (as swig object .. this is very slow) // S = Service Reference (as python string object .. same as ref.toString()) +// C = Service Reference (as python string object .. same as ref.toCompareString()) // N = Service Name (as python string object) // when exactly one return value per service is selected in the format string, // then each value is directly a list entry @@ -177,7 +239,7 @@ RESULT eServiceFS::getContent(std::list &list, bool sorted) // unknown format string chars are returned as python None values ! PyObject *eServiceFS::getContent(const char* format, bool sorted) { - PyObject *ret=0; + ePyObject ret; std::list tmplist; int retcount=1; @@ -199,14 +261,17 @@ PyObject *eServiceFS::getContent(const char* format, bool sorted) for (int cnt=0; cnt < services; ++cnt) { eServiceReference &ref=*it++; - PyObject *tuple = retcount > 1 ? PyTuple_New(retcount) : 0; + ePyObject tuple = retcount > 1 ? PyTuple_New(retcount) : ePyObject(); for (int i=0; i < retcount; ++i) { - PyObject *tmp=0; + ePyObject tmp; switch(format[i]) { case 'R': // service reference (swig)object - tmp = New_eServiceReference(ref); + tmp = NEW_eServiceReference(ref); + break; + case 'C': // service reference compare string + tmp = PyString_FromString(ref.toCompareString().c_str()); break; case 'S': // service reference string tmp = PyString_FromString(ref.toString().c_str()); @@ -246,7 +311,7 @@ PyObject *eServiceFS::getContent(const char* format, bool sorted) PyList_SET_ITEM(ret, cnt, tuple); } } - return ret ? ret : PyList_New(0); + return ret ? (PyObject*)ret : (PyObject*)PyList_New(0); } RESULT eServiceFS::getNext(eServiceReference &ptr) @@ -288,4 +353,22 @@ RESULT eServiceFS::startEdit(ePtr &res) return -1; } +int eServiceFS::getServiceTypeForExtension(const char *str) +{ + for (std::map >::iterator sit(m_additional_extensions.begin()); sit != m_additional_extensions.end(); ++sit) + { + for (std::list::iterator eit(sit->second.begin()); eit != sit->second.end(); ++eit) + { + if (*eit == str) + return sit->first; + } + } + return -1; +} + +int eServiceFS::getServiceTypeForExtension(const std::string &str) +{ + return getServiceTypeForExtension(str.c_str()); +} + eAutoInitPtr init_eServiceFactoryFS(eAutoInitNumbers::service+1, "eServiceFactoryFS");