+#include <lib/dvb/decoder.h>
+
+#include <lib/service/servicedvbrecord.h>
+#include <lib/dvb/metaparser.h>
+#include <lib/dvb/tstools.h>
+
+class eStaticServiceDVBInformation: public iStaticServiceInformation
+{
+ DECLARE_REF(eStaticServiceDVBInformation);
+public:
+ RESULT getName(const eServiceReference &ref, std::string &name);
+ int getLength(const eServiceReference &ref);
+};
+
+DEFINE_REF(eStaticServiceDVBInformation);
+
+RESULT eStaticServiceDVBInformation::getName(const eServiceReference &ref, std::string &name)
+{
+ eServiceReferenceDVB &service = (eServiceReferenceDVB&)ref;
+ if ( !ref.name.empty() )
+ {
+ if (service.getParentTransportStreamID().get()) // linkage subservice
+ {
+ ePtr<iServiceHandler> service_center;
+ if (!eServiceCenter::getInstance(service_center))
+ {
+ eServiceReferenceDVB parent = service;
+ parent.setTransportStreamID( service.getParentTransportStreamID() );
+ parent.setServiceID( service.getParentServiceID() );
+ parent.setParentTransportStreamID(eTransportStreamID(0));
+ parent.setParentServiceID(eServiceID(0));
+ parent.name="";
+ ePtr<iStaticServiceInformation> service_info;
+ if (!service_center->info(parent, service_info))
+ {
+ if (!service_info->getName(parent, name))
+ {
+ // just show short name
+ unsigned int pos = name.find("\xc2\x86");
+ if ( pos != std::string::npos )
+ name.erase(0, pos+2);
+ pos = name.find("\xc2\x87");
+ if ( pos != std::string::npos )
+ name.erase(pos);
+ name+=" - ";
+ }
+ }
+ }
+ }
+ else
+ name="";
+ name += ref.name;
+ return 0;
+ }
+ else
+ return -1;
+}
+
+int eStaticServiceDVBInformation::getLength(const eServiceReference &ref)
+{
+ return -1;
+}
+
+class eStaticServiceDVBBouquetInformation: public iStaticServiceInformation
+{
+ DECLARE_REF(eStaticServiceDVBBouquetInformation);
+public:
+ RESULT getName(const eServiceReference &ref, std::string &name);
+ int getLength(const eServiceReference &ref);
+};
+
+DEFINE_REF(eStaticServiceDVBBouquetInformation);
+
+RESULT eStaticServiceDVBBouquetInformation::getName(const eServiceReference &ref, std::string &name)
+{
+ ePtr<iDVBChannelList> db;
+ ePtr<eDVBResourceManager> res;
+
+ int err;
+ if ((err = eDVBResourceManager::getInstance(res)) != 0)
+ {
+ eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no resource manager!");
+ return err;
+ }
+ if ((err = res->getChannelList(db)) != 0)
+ {
+ eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no channel list!");
+ return err;
+ }
+
+ eBouquet *bouquet=0;
+ if ((err = db->getBouquet(ref, bouquet)) != 0)
+ {
+ eDebug("eStaticServiceDVBBouquetInformation::getName failed.. getBouquet failed!");
+ return -1;
+ }
+
+ if ( bouquet && bouquet->m_bouquet_name.length() )
+ {
+ name = bouquet->m_bouquet_name;
+ return 0;
+ }
+ else
+ return -1;
+}
+
+int eStaticServiceDVBBouquetInformation::getLength(const eServiceReference &ref)
+{
+ return -1;
+}
+
+class eStaticServiceDVBPVRInformation: public iStaticServiceInformation
+{
+ DECLARE_REF(eStaticServiceDVBPVRInformation);
+ eServiceReference m_ref;
+ eDVBMetaParser m_parser;
+public:
+ eStaticServiceDVBPVRInformation(const eServiceReference &ref);
+ RESULT getName(const eServiceReference &ref, std::string &name);
+ int getLength(const eServiceReference &ref);
+
+ int getInfo(const eServiceReference &ref, int w);
+ std::string getInfoString(const eServiceReference &ref,int w);
+};
+
+DEFINE_REF(eStaticServiceDVBPVRInformation);
+
+eStaticServiceDVBPVRInformation::eStaticServiceDVBPVRInformation(const eServiceReference &ref)
+{
+ m_ref = ref;
+ m_parser.parseFile(ref.path);
+}
+
+RESULT eStaticServiceDVBPVRInformation::getName(const eServiceReference &ref, std::string &name)
+{
+ ASSERT(ref == m_ref);
+ name = m_parser.m_name.size() ? m_parser.m_name : ref.path;
+ return 0;
+}
+
+int eStaticServiceDVBPVRInformation::getLength(const eServiceReference &ref)
+{
+ ASSERT(ref == m_ref);
+
+ eDVBTSTools tstools;
+
+ if (tstools.openFile(ref.path.c_str()))
+ return 0;
+
+ pts_t len;
+ if (tstools.calcLen(len))
+ return 0;
+
+ return len / 90000;
+}
+
+int eStaticServiceDVBPVRInformation::getInfo(const eServiceReference &ref, int w)
+{
+ switch (w)
+ {
+ case iServiceInformation::sDescription:
+ return iServiceInformation::resIsString;
+ case iServiceInformation::sTimeCreate:
+ if (m_parser.m_time_create)
+ return m_parser.m_time_create;
+ else
+ return iServiceInformation::resNA;
+ default:
+ return iServiceInformation::resNA;
+ }
+}
+
+std::string eStaticServiceDVBPVRInformation::getInfoString(const eServiceReference &ref,int w)
+{
+ switch (w)
+ {
+ case iServiceInformation::sDescription:
+ return m_parser.m_description;
+ default:
+ return "";
+ }
+}
+
+class eDVBPVRServiceOfflineOperations: public iServiceOfflineOperations
+{
+ DECLARE_REF(eDVBPVRServiceOfflineOperations);
+ eServiceReferenceDVB m_ref;
+public:
+ eDVBPVRServiceOfflineOperations(const eServiceReference &ref);
+
+ RESULT deleteFromDisk(int simulate);
+ RESULT getListOfFilenames(std::list<std::string> &);
+};
+
+DEFINE_REF(eDVBPVRServiceOfflineOperations);
+
+eDVBPVRServiceOfflineOperations::eDVBPVRServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReferenceDVB&)ref)
+{
+}
+
+RESULT eDVBPVRServiceOfflineOperations::deleteFromDisk(int simulate)
+{
+ if (simulate)
+ return 0;
+ else
+ {
+ std::list<std::string> res;
+ if (getListOfFilenames(res))
+ return -1;
+
+ /* TODO: deferred removing.. */
+ for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
+ {
+ eDebug("Removing %s...", i->c_str());
+ ::unlink(i->c_str());
+ }
+
+ return 0;
+ }
+}
+
+RESULT eDVBPVRServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
+{
+ res.clear();
+ res.push_back(m_ref.path);
+ res.push_back(m_ref.path + ".meta");
+ return 0;
+}