diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2005-10-09 03:32:46 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2005-10-09 03:32:46 +0000 |
| commit | 32e4324b9b5e615a84885b9132505e4706ededfe (patch) | |
| tree | 59a0679a05553423489f3dc7fb9d0f3bae7225b0 /lib/service | |
| parent | 699d41f217b6d8e91dce499964f8c1a69f5602ed (diff) | |
| download | enigma2-32e4324b9b5e615a84885b9132505e4706ededfe.tar.gz enigma2-32e4324b9b5e615a84885b9132505e4706ededfe.zip | |
service: add sort of servicelist including all required layers
Diffstat (limited to 'lib/service')
| -rw-r--r-- | lib/service/iservice.h | 19 | ||||
| -rw-r--r-- | lib/service/listboxservice.cpp | 13 | ||||
| -rw-r--r-- | lib/service/listboxservice.h | 2 | ||||
| -rw-r--r-- | lib/service/servicedvb.cpp | 54 | ||||
| -rw-r--r-- | lib/service/servicedvb.h | 11 | ||||
| -rw-r--r-- | lib/service/servicefs.cpp | 12 | ||||
| -rw-r--r-- | lib/service/servicefs.h | 1 |
7 files changed, 97 insertions, 15 deletions
diff --git a/lib/service/iservice.h b/lib/service/iservice.h index 54d7b11f..d0dc1e2b 100644 --- a/lib/service/iservice.h +++ b/lib/service/iservice.h @@ -250,10 +250,29 @@ public: /* new, shiny interface: streaming. */ virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0; + + /* use this for sorting. output is not sorted because of either + - performance reasons: the whole list must be buffered or + - the interface would be restricted to a list. streaming + (as well as a future "active" extension) won't be possible. + */ + virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0; }; TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr); + /* a helper class which can be used as argument to stl's sort(). */ +class iListableServiceCompare +{ + ePtr<iListableService> m_list; +public: + iListableServiceCompare(iListableService *list): m_list(list) { } + bool operator()(const eServiceReference &a, const eServiceReference &b) + { + return m_list->compareLessEqual(a, b); + } +}; + class iServiceOfflineOperations: public iObject { public: diff --git a/lib/service/listboxservice.cpp b/lib/service/listboxservice.cpp index 07838722..d4cbff20 100644 --- a/lib/service/listboxservice.cpp +++ b/lib/service/listboxservice.cpp @@ -108,6 +108,19 @@ void eListboxServiceContent::setElementFont(int element, gFont *font) m_element_font[element] = font; } +void eListboxServiceContent::sort() +{ + ePtr<iListableService> lst; + if (!m_service_center->list(m_root, lst)) + { + m_list.sort(iListableServiceCompare(lst)); + /* FIXME: is this really required or can we somehow keep the current entry? */ + cursorHome(); + if (m_listbox) + m_listbox->entryReset(); + } +} + DEFINE_REF(eListboxServiceContent); eListboxServiceContent::eListboxServiceContent() diff --git a/lib/service/listboxservice.h b/lib/service/listboxservice.h index f560b627..4e5a8dd5 100644 --- a/lib/service/listboxservice.h +++ b/lib/service/listboxservice.h @@ -45,6 +45,8 @@ public: void setElementPosition(int element, eRect where); void setElementFont(int element, gFont *font); + void sort(); + protected: void cursorHome(); void cursorEnd(); diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index ca08d481..a29b77ce 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -36,6 +36,7 @@ RESULT eStaticServiceDVBPVRInformation::getName(const eServiceReference &ref, st { ASSERT(ref == m_ref); name = m_parser.m_name.size() ? m_parser.m_name : ref.path; + return 0; } int eStaticServiceDVBPVRInformation::getLength(const eServiceReference &ref) @@ -133,7 +134,7 @@ eDVBServiceList::~eDVBServiceList() { } -RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list) +RESULT eDVBServiceList::startQuery() { ePtr<iDVBChannelList> db; ePtr<eDVBResourceManager> res; @@ -150,30 +151,50 @@ RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list) return err; } - ePtr<iDVBChannelListQuery> query; - ePtr<eDVBChannelQuery> q; if (m_parent.path.size()) + { eDVBChannelQuery::compile(q, m_parent.path); + if (!q) + { + eDebug("compile query failed"); + return err; + } + } - if ((err = db->startQuery(query, q)) != 0) + if ((err = db->startQuery(m_query, q)) != 0) { eDebug("startQuery failed"); return err; } - + + return 0; +} + +RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list) +{ eServiceReferenceDVB ref; - while (!query->getNextResult(ref)) + if (!m_query) + return -1; + + while (!m_query->getNextResult(ref)) list.push_back(ref); return 0; } -RESULT eDVBServiceList::getNext(eServiceReference &) +RESULT eDVBServiceList::getNext(eServiceReference &ref) { - /* implement me */ - return -1; + if (!m_query) + return -1; + + return m_query->getNextResult((eServiceReferenceDVB&)ref); +} + +int eDVBServiceList::compareLessEqual(const eServiceReference &a, const eServiceReference &b) +{ + return m_query->compareLessEqual((const eServiceReferenceDVB&)a, (const eServiceReferenceDVB&)b); } RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr) @@ -195,7 +216,14 @@ RESULT eServiceFactoryDVB::record(const eServiceReference &ref, ePtr<iRecordable RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr) { - ptr = new eDVBServiceList(ref); + ePtr<eDVBServiceList> list = new eDVBServiceList(ref); + if (list->startQuery()) + { + ptr = 0; + return -1; + } + + ptr = list; return 0; } @@ -389,6 +417,7 @@ RESULT eDVBServicePlay::start() eDebug("starting DVB service"); r = m_service_handler.tune((eServiceReferenceDVB&)m_reference); m_event(this, evStart); + return 0; } RESULT eDVBServicePlay::stop() @@ -459,8 +488,11 @@ RESULT eDVBServicePlay::info(ePtr<iServiceInformation> &ptr) RESULT eDVBServicePlay::getName(std::string &name) { if (m_dvb_service) + { m_dvb_service->getName(m_reference, name); - else + if (name.empty()) + name = "(...)"; + } else name = "DVB service"; return 0; } diff --git a/lib/service/servicedvb.h b/lib/service/servicedvb.h index accdd20d..57dca9a0 100644 --- a/lib/service/servicedvb.h +++ b/lib/service/servicedvb.h @@ -28,14 +28,17 @@ private: class eDVBServiceList: public iListableService { DECLARE_REF(eDVBServiceList); -private: - eServiceReference m_parent; - friend class eServiceFactoryDVB; - eDVBServiceList(const eServiceReference &parent); public: virtual ~eDVBServiceList(); RESULT getContent(std::list<eServiceReference> &list); RESULT getNext(eServiceReference &ptr); + int compareLessEqual(const eServiceReference &a, const eServiceReference &b); +private: + RESULT startQuery(); + eServiceReference m_parent; + friend class eServiceFactoryDVB; + eDVBServiceList(const eServiceReference &parent); + ePtr<iDVBChannelListQuery> m_query; }; class eDVBServicePlay: public iPlayableService, iSeekableService, public Object, public iServiceInformation diff --git a/lib/service/servicefs.cpp b/lib/service/servicefs.cpp index 057498d7..c5846abd 100644 --- a/lib/service/servicefs.cpp +++ b/lib/service/servicefs.cpp @@ -163,4 +163,16 @@ RESULT eServiceFS::getNext(eServiceReference &ptr) return 0; } +int eServiceFS::compareLessEqual(const eServiceReference &a, const eServiceReference &b) +{ + /* directories first */ + if ((a.flags & ~b.flags) & eServiceReference::isDirectory) + return 1; + else if ((~a.flags & b.flags) & eServiceReference::isDirectory) + return 0; + /* sort by filename */ + else + return a.path < b.path; +} + eAutoInitPtr<eServiceFactoryFS> init_eServiceFactoryFS(eAutoInitNumbers::service+1, "eServiceFactoryFS"); diff --git a/lib/service/servicefs.h b/lib/service/servicefs.h index 73bfd985..3400fb85 100644 --- a/lib/service/servicefs.h +++ b/lib/service/servicefs.h @@ -36,6 +36,7 @@ public: RESULT getContent(std::list<eServiceReference> &list); RESULT getNext(eServiceReference &ptr); + int compareLessEqual(const eServiceReference &, const eServiceReference &); }; #endif |
