diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2005-02-07 09:14:02 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2005-02-07 09:14:02 +0000 |
| commit | d9ee52e4f0fbe9a1ae00d0e66f9e6f0a07fa319f (patch) | |
| tree | f1084b85919b5590615e281331cfe535c3a160c8 /lib/service | |
| parent | 4bc08995411e21f3564f09e136809be68ddf96a8 (diff) | |
| download | enigma2-d9ee52e4f0fbe9a1ae00d0e66f9e6f0a07fa319f.tar.gz enigma2-d9ee52e4f0fbe9a1ae00d0e66f9e6f0a07fa319f.zip | |
- added iStaticServiceInformation
- added service list interface for dvb
- started work on queries (currently only "instr" on servicename)
- started work on infobar
- added listbox with service
- fixed dvbdb
- remove some debug output
Diffstat (limited to 'lib/service')
| -rw-r--r-- | lib/service/iservice.h | 25 | ||||
| -rw-r--r-- | lib/service/listboxservice.cpp | 134 | ||||
| -rw-r--r-- | lib/service/listboxservice.h | 48 | ||||
| -rw-r--r-- | lib/service/service.cpp | 4 | ||||
| -rw-r--r-- | lib/service/service.h | 2 | ||||
| -rw-r--r-- | lib/service/servicedvb.cpp | 94 | ||||
| -rw-r--r-- | lib/service/servicedvb.h | 17 | ||||
| -rw-r--r-- | lib/service/servicefs.cpp | 10 | ||||
| -rw-r--r-- | lib/service/servicefs.h | 4 | ||||
| -rw-r--r-- | lib/service/servicemp3.cpp | 20 | ||||
| -rw-r--r-- | lib/service/servicemp3.h | 14 |
11 files changed, 330 insertions, 42 deletions
diff --git a/lib/service/iservice.h b/lib/service/iservice.h index 01c61fcc..5a8a0627 100644 --- a/lib/service/iservice.h +++ b/lib/service/iservice.h @@ -147,13 +147,21 @@ public: large list, provided that no state information is nessesary to deliver the required information. Anyway - ref *must* be the same as the argument to the info() or getIServiceInformation call! */ -class iServiceInformation: public iObject +class iStaticServiceInformation: public iObject { public: virtual RESULT getName(const eServiceReference &ref, std::string &name)=0; }; -typedef ePtr<iServiceInformation> iServiceInformationPtr; +TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr); + +class iServiceInformation: public iStaticServiceInformation +{ +public: + +}; + +TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr); class iPauseableService: public iObject { @@ -162,7 +170,7 @@ public: virtual RESULT unpause()=0; }; -typedef ePtr<iPauseableService> iPauseableServicePtr; +TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr); class iPlayableService: public iObject { @@ -176,8 +184,8 @@ public: virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0; virtual RESULT start()=0; virtual RESULT stop()=0; - virtual RESULT getIPausableService(ePtr<iPauseableService> &ptr)=0; - virtual RESULT getIServiceInformation(ePtr<iServiceInformation> &ptr)=0; + virtual RESULT pause(ePtr<iPauseableService> &ptr)=0; + virtual RESULT info(ePtr<iServiceInformation> &ptr)=0; }; TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr); @@ -189,10 +197,9 @@ public: virtual RESULT stop()=0; }; -typedef ePtr<iRecordableService> iRecordableServicePtr; +TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr); // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList); -typedef std::list<eServiceReference> eServiceReferenceList; class iListableService: public iObject { @@ -208,9 +215,9 @@ public: virtual RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr)=0; virtual RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr)=0; virtual RESULT list(const eServiceReference &, ePtr<iListableService> &ptr)=0; - virtual RESULT info(const eServiceReference &, ePtr<iServiceInformation> &ptr); + virtual RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr); }; -typedef ePtr<iServiceHandler> iServiceHandlerPtr; +TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr); #endif diff --git a/lib/service/listboxservice.cpp b/lib/service/listboxservice.cpp new file mode 100644 index 00000000..011c96ca --- /dev/null +++ b/lib/service/listboxservice.cpp @@ -0,0 +1,134 @@ +#include <lib/service/listboxservice.h> +#include <lib/service/service.h> + +void eListboxServiceContent::setRoot(const eServiceReference &root) +{ + m_root = root; + + assert(m_service_center); + + ePtr<iListableService> lst; + if (m_service_center->list(m_root, lst)) + eDebug("no list available!"); + else + if (lst->getContent(m_list)) + eDebug("getContent failed"); + + m_size = m_list.size(); + cursorHome(); +} + +DEFINE_REF(eListboxServiceContent); + +eListboxServiceContent::eListboxServiceContent() +{ + m_size = 0; + cursorHome(); + eServiceCenter::getInstance(m_service_center); +} + +void eListboxServiceContent::cursorHome() +{ + m_cursor = m_list.begin(); + m_cursor_number = 0; +} + +void eListboxServiceContent::cursorEnd() +{ + m_cursor = m_list.end(); + m_cursor_number = m_size; +} + +int eListboxServiceContent::cursorMove(int count) +{ + if (count > 0) + { + while (count && (m_cursor != m_list.end())) + { + ++m_cursor; + ++m_cursor_number; + --count; + } + } else if (count < 0) + { + while (count && (m_cursor != m_list.begin())) + { + --m_cursor; + --m_cursor_number; + ++count; + } + } + + return 0; +} + +int eListboxServiceContent::cursorValid() +{ + return m_cursor != m_list.end(); +} + +int eListboxServiceContent::cursorSet(int n) +{ + cursorHome(); + cursorMove(n); + + return 0; +} + +int eListboxServiceContent::cursorGet() +{ + return m_cursor_number; +} + +void eListboxServiceContent::cursorSave() +{ + m_saved_cursor = m_cursor; + m_saved_cursor_number = m_cursor_number; +} + +void eListboxServiceContent::cursorRestore() +{ + m_cursor = m_saved_cursor; + m_cursor_number = m_saved_cursor_number; +} + +int eListboxServiceContent::size() +{ + return m_size; +} + +void eListboxServiceContent::setSize(const eSize &size) +{ + m_itemsize = size; +} + +void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected) +{ + ePtr<gFont> fnt = new gFont("Arial", 14); + painter.clip(eRect(offset, m_itemsize)); + style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal); + painter.clear(); + + if (cursorValid()) + { + painter.setFont(fnt); + + ePoint text_offset = offset + (selected ? ePoint(2, 2) : ePoint(1, 1)); + + /* get name of service */ + ePtr<iStaticServiceInformation> service_info; + m_service_center->info(*m_cursor, service_info); + std::string name = "<n/a>"; + + if (service_info) + service_info->getName(*m_cursor, name); + + painter.renderText(eRect(text_offset, m_itemsize), name); + + if (selected) + style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry); + } + + painter.clippop(); +} + diff --git a/lib/service/listboxservice.h b/lib/service/listboxservice.h new file mode 100644 index 00000000..45e5ba71 --- /dev/null +++ b/lib/service/listboxservice.h @@ -0,0 +1,48 @@ +#ifndef __lib_service_listboxservice_h +#define __lib_service_listboxservice_h + +#include <lib/gui/elistbox.h> +#include <lib/service/iservice.h> + +class eServiceCenter; + +class eListboxServiceContent: public virtual iListboxContent +{ + DECLARE_REF; +public: + eListboxServiceContent(); + void setRoot(const eServiceReference &ref); + +protected: + void cursorHome(); + void cursorEnd(); + int cursorMove(int count=1); + int cursorValid(); + int cursorSet(int n); + int cursorGet(); + + void cursorSave(); + void cursorRestore(); + int size(); + + // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though + void setSize(const eSize &size); + + /* the following functions always refer to the selected item */ + void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected); +private: + typedef std::list<eServiceReference> list; + + list m_list; + list::iterator m_cursor, m_saved_cursor; + + int m_cursor_number, m_saved_cursor_number; + int m_size; + + eSize m_itemsize; + ePtr<eServiceCenter> m_service_center; + + eServiceReference m_root; +}; + +#endif diff --git a/lib/service/service.cpp b/lib/service/service.cpp index 40cbf8df..75d4987b 100644 --- a/lib/service/service.cpp +++ b/lib/service/service.cpp @@ -90,7 +90,7 @@ RESULT eServiceCenter::list(const eServiceReference &ref, ePtr<iListableService> return i->second->list(ref, ptr); } -RESULT eServiceCenter::info(const eServiceReference &ref, ePtr<iServiceInformation> &ptr) +RESULT eServiceCenter::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr) { std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type); if (i == handler.end()) @@ -114,7 +114,7 @@ RESULT eServiceCenter::removeServiceFactory(int id) } /* default handlers */ -RESULT iServiceHandler::info(const eServiceReference &, ePtr<iServiceInformation> &ptr) +RESULT iServiceHandler::info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr) { ptr = 0; return -1; diff --git a/lib/service/service.h b/lib/service/service.h index c3f0c482..9f4b4560 100644 --- a/lib/service/service.h +++ b/lib/service/service.h @@ -23,7 +23,7 @@ public: RESULT play(const eServiceReference &, iPlayableServicePtr &ptr); RESULT record(const eServiceReference &, iRecordableServicePtr &ptr); RESULT list(const eServiceReference &, iListableServicePtr &ptr); - RESULT info(const eServiceReference &, ePtr<iServiceInformation> &ptr); + RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr); // eServiceCenter static RESULT getInstance(eServiceCenterPtr &ptr) { ptr = instance; return 0; } diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index 0c6d72bd..d1ebeb30 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -6,6 +6,9 @@ #include <lib/base/init_num.h> #include <lib/base/init.h> +#include <lib/dvb/dvb.h> +#include <lib/dvb/db.h> + DEFINE_REF(eServiceFactoryDVB) eServiceFactoryDVB::eServiceFactoryDVB() @@ -26,6 +29,53 @@ eServiceFactoryDVB::~eServiceFactoryDVB() sc->removeServiceFactory(eServiceFactoryDVB::id); } +DEFINE_REF(eDVBServiceList); + +eDVBServiceList::eDVBServiceList(const eServiceReference &parent): m_parent(parent) +{ +} + +eDVBServiceList::~eDVBServiceList() +{ +} + +RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list) +{ + ePtr<iDVBChannelList> db; + ePtr<eDVBResourceManager> res; + + int err; + if ((err = eDVBResourceManager::getInstance(res)) != 0) + { + eDebug("no resource manager"); + return err; + } + if ((err = res->getChannelList(db)) != 0) + { + eDebug("no channel list"); + return err; + } + + ePtr<iDVBChannelListQuery> query; + + ePtr<eDVBChannelQuery> q; + + if (m_parent.path.size()) + eDVBChannelQuery::compile(q, m_parent.path); + + if ((err = db->startQuery(query, q)) != 0) + { + eDebug("startQuery failed"); + return err; + } + + eServiceReferenceDVB ref; + + while (!query->getNextResult(ref)) + list.push_back(ref); + return 0; +} + RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr) { // check resources... @@ -39,10 +89,46 @@ RESULT eServiceFactoryDVB::record(const eServiceReference &, ePtr<iRecordableSer return -1; } -RESULT eServiceFactoryDVB::list(const eServiceReference &, ePtr<iListableService> &ptr) +RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr) +{ + ptr = new eDVBServiceList(ref); + return 0; +} + +RESULT eServiceFactoryDVB::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr) { ptr = 0; - return -1; + // TODO: handle the listing itself + // if (ref.... == -1) .. return "... bouquets ..."; + // could be also done in another serviceFactory (with seperate ID) to seperate actual services and lists + // TODO: cache + ePtr<iDVBChannelList> db; + ePtr<eDVBResourceManager> res; + + int err; + if ((err = eDVBResourceManager::getInstance(res)) != 0) + { + eDebug("no resource manager"); + return err; + } + if ((err = res->getChannelList(db)) != 0) + { + eDebug("no channel list"); + return err; + } + + ePtr<eDVBService> service; + + /* we are sure to have a ..DVB reference as the info() call was forwarded here according to it's ID. */ + if ((err = db->getService((eServiceReferenceDVB&)ref, service)) != 0) + { + eDebug("getService failed!"); + return err; + } + + /* eDVBService has the iStaticServiceInformation interface, so we pass it here. */ + ptr = service; + return 0; } eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref): @@ -145,14 +231,14 @@ RESULT eDVBServicePlay::connectEvent(const Slot2<void,iPlayableService*,int> &ev return -1; } -RESULT eDVBServicePlay::getIPausableService(ePtr<iPauseableService> &ptr) +RESULT eDVBServicePlay::pause(ePtr<iPauseableService> &ptr) { // not yet possible, maybe later... ptr = 0; return -1; } -RESULT eDVBServicePlay::getIServiceInformation(ePtr<iServiceInformation> &ptr) +RESULT eDVBServicePlay::info(ePtr<iServiceInformation> &ptr) { ptr = this; return 0; diff --git a/lib/service/servicedvb.h b/lib/service/servicedvb.h index c54eb5c0..94659ed1 100644 --- a/lib/service/servicedvb.h +++ b/lib/service/servicedvb.h @@ -18,6 +18,19 @@ public: RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr); RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr); RESULT list(const eServiceReference &, ePtr<iListableService> &ptr); + RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr); +}; + +class eDVBServiceList: public iListableService +{ +DECLARE_REF; +private: + eServiceReference m_parent; + friend class eServiceFactoryDVB; + eDVBServiceList(const eServiceReference &parent); +public: + virtual ~eDVBServiceList(); + RESULT getContent(std::list<eServiceReference> &list); }; class eDVBServicePlay: public iPlayableService, public Object, public iServiceInformation @@ -41,8 +54,8 @@ public: RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection); RESULT start(); RESULT stop(); - RESULT getIPausableService(ePtr<iPauseableService> &ptr); - RESULT getIServiceInformation(ePtr<iServiceInformation> &ptr); + RESULT pause(ePtr<iPauseableService> &ptr); + RESULT info(ePtr<iServiceInformation> &ptr); // iServiceInformation RESULT getName(const eServiceReference &ref, std::string &name); diff --git a/lib/service/servicefs.cpp b/lib/service/servicefs.cpp index de75cc67..5a945679 100644 --- a/lib/service/servicefs.cpp +++ b/lib/service/servicefs.cpp @@ -12,16 +12,16 @@ #include <unistd.h> -class eServiceFSInformation: public iServiceInformation +class eStaticServiceFSInformation: public iStaticServiceInformation { DECLARE_REF; public: RESULT getName(const eServiceReference &ref, std::string &name); }; -DEFINE_REF(eServiceFSInformation); +DEFINE_REF(eStaticServiceFSInformation); -RESULT eServiceFSInformation::getName(const eServiceReference &ref, std::string &name) +RESULT eStaticServiceFSInformation::getName(const eServiceReference &ref, std::string &name) { name = ref.path; } @@ -36,7 +36,7 @@ eServiceFactoryFS::eServiceFactoryFS() if (sc) sc->addServiceFactory(eServiceFactoryFS::id, this); - m_service_information = new eServiceFSInformation(); + m_service_information = new eStaticServiceFSInformation(); } eServiceFactoryFS::~eServiceFactoryFS() @@ -69,7 +69,7 @@ RESULT eServiceFactoryFS::list(const eServiceReference &ref, ePtr<iListableServi return 0; } -RESULT eServiceFactoryFS::info(const eServiceReference &ref, ePtr<iServiceInformation> &ptr) +RESULT eServiceFactoryFS::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr) { ptr = m_service_information; return 0; diff --git a/lib/service/servicefs.h b/lib/service/servicefs.h index d8e77609..337ff620 100644 --- a/lib/service/servicefs.h +++ b/lib/service/servicefs.h @@ -15,9 +15,9 @@ public: RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr); RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr); RESULT list(const eServiceReference &, ePtr<iListableService> &ptr); - RESULT info(const eServiceReference &, ePtr<iServiceInformation> &ptr); + RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr); private: - ePtr<iServiceInformation> m_service_information; + ePtr<iStaticServiceInformation> m_service_information; }; class eServiceFS: public iListableService diff --git a/lib/service/servicemp3.cpp b/lib/service/servicemp3.cpp index 1f883f94..a5f1b773 100644 --- a/lib/service/servicemp3.cpp +++ b/lib/service/servicemp3.cpp @@ -17,7 +17,7 @@ eServiceFactoryMP3::eServiceFactoryMP3() if (sc) sc->addServiceFactory(eServiceFactoryMP3::id, this); - m_service_info = new eServiceMP3Info(); + m_service_info = new eStaticServiceMP3Info(); } eServiceFactoryMP3::~eServiceFactoryMP3() @@ -51,29 +51,29 @@ RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService return -1; } -RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iServiceInformation> &ptr) +RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr) { ptr = m_service_info; return 0; } -// eServiceMP3Info +// eStaticServiceMP3Info -// eServiceMP3Info is seperated from eServiceMP3 to give information +// eStaticServiceMP3Info is seperated from eServiceMP3 to give information // about unopened files. -// probably eServiceMP3 should use this class as well, and eServiceMP3Info +// probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info // should have a database backend where ID3-files etc. are cached. // this would allow listing the mp3 database based on certain filters. -DEFINE_REF(eServiceMP3Info) +DEFINE_REF(eStaticServiceMP3Info) -eServiceMP3Info::eServiceMP3Info() +eStaticServiceMP3Info::eStaticServiceMP3Info() { } -RESULT eServiceMP3Info::getName(const eServiceReference &ref, std::string &name) +RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name) { name = "MP3 file: " + ref.path; return 0; @@ -134,13 +134,13 @@ RESULT eServiceMP3::stop() return 0; } -RESULT eServiceMP3::getIPausableService(ePtr<iPauseableService> &ptr) { ptr=this; return 0; } +RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr) { ptr=this; return 0; } // iPausableService RESULT eServiceMP3::pause() { printf("mp3 pauses!\n"); return 0; } RESULT eServiceMP3::unpause() { printf("mp3 unpauses!\n"); return 0; } -RESULT eServiceMP3::getIServiceInformation(ePtr<iServiceInformation>&i) { i = this; return 0; } +RESULT eServiceMP3::info(ePtr<iServiceInformation>&i) { i = this; return 0; } RESULT eServiceMP3::getName(const eServiceReference &ref, std::string &name) { diff --git a/lib/service/servicemp3.h b/lib/service/servicemp3.h index 7ef84025..40287ae5 100644 --- a/lib/service/servicemp3.h +++ b/lib/service/servicemp3.h @@ -3,7 +3,7 @@ #include <lib/service/iservice.h> -class eServiceMP3Info ; +class eStaticServiceMP3Info; class eServiceFactoryMP3: public iServiceHandler { @@ -17,16 +17,16 @@ public: RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr); RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr); RESULT list(const eServiceReference &, ePtr<iListableService> &ptr); - RESULT info(const eServiceReference &, ePtr<iServiceInformation> &ptr); + RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr); private: - ePtr<eServiceMP3Info> m_service_info; + ePtr<eStaticServiceMP3Info> m_service_info; }; -class eServiceMP3Info: public iServiceInformation +class eStaticServiceMP3Info: public iServiceInformation { DECLARE_REF; friend class eServiceFactoryMP3; - eServiceMP3Info(); + eStaticServiceMP3Info(); public: RESULT getName(const eServiceReference &ref, std::string &name); }; @@ -53,13 +53,13 @@ public: RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection); RESULT start(); RESULT stop(); - RESULT getIPausableService(ePtr<iPauseableService> &ptr); + RESULT pause(ePtr<iPauseableService> &ptr); // iPausableService RESULT pause(); RESULT unpause(); - RESULT getIServiceInformation(ePtr<iServiceInformation>&); + RESULT info(ePtr<iServiceInformation>&); // iServiceInformation RESULT getName(const eServiceReference &ref, std::string &name); |
