some changes for new default skin
[enigma2.git] / lib / components / scan.cpp
1 #include <lib/dvb/dvb.h>
2 #include <lib/dvb/db.h>
3 #include <lib/components/scan.h>
4 #include <lib/base/eerror.h>
5 #include <lib/dvb/scan.h>
6
7 DEFINE_REF(eComponentScan);
8
9 void eComponentScan::scanEvent(int evt)
10 {
11 //      eDebug("scan event %d!", evt);
12         
13         if (evt == eDVBScan::evtFinish)
14         {
15                 m_done = 1;
16                 ePtr<iDVBChannelList> db;
17                 ePtr<eDVBResourceManager> res;
18                 
19                 int err;
20                 if ((err = eDVBResourceManager::getInstance(res)) != 0)
21                 {
22                         eDebug("no resource manager");
23                         m_failed = 2;
24                 } else if ((err = res->getChannelList(db)) != 0)
25                 {
26                         m_failed = 3;
27                         eDebug("no channel list");
28                 } else
29                 {
30                         m_scan->insertInto(db);
31                         db->flush();
32                         eDebug("scan done!");
33                 }
34         }
35         
36         if (evt == eDVBScan::evtNewService)
37         {
38                 newService();
39                 return;
40         }
41         
42         if (evt == eDVBScan::evtFail)
43         {
44                 eDebug("scan failed.");
45                 m_failed = 1;
46                 m_done = 1;
47         }
48         
49         statusChanged();
50 }
51
52 eComponentScan::eComponentScan(): m_done(-1), m_failed(0)
53 {
54 }
55
56 eComponentScan::~eComponentScan()
57 {
58 }
59
60 void eComponentScan::clear()
61 {
62         m_initial.clear();
63 }
64
65 void eComponentScan::addInitial(const eDVBFrontendParametersSatellite &p)
66 {
67         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
68         parm->setDVBS(p);
69         m_initial.push_back(parm);
70 }
71
72 void eComponentScan::addInitial(const eDVBFrontendParametersCable &p)
73 {
74         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
75         parm->setDVBC(p);
76         m_initial.push_back(parm);
77 }
78
79 void eComponentScan::addInitial(const eDVBFrontendParametersTerrestrial &p)
80 {
81         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
82         parm->setDVBT(p);
83         m_initial.push_back(parm);
84 }
85
86
87 int eComponentScan::start(int feid, int flags)
88 {
89         if (m_initial.empty())
90                 return -2;
91
92         if (m_done != -1)
93                 return -1;
94         
95         m_done = 0;
96         ePtr<eDVBResourceManager> mgr;
97         
98         eDVBResourceManager::getInstance(mgr);
99
100         eUsePtr<iDVBChannel> channel;
101
102         if (mgr->allocateRawChannel(channel, feid))
103         {
104                 eDebug("scan: allocating raw channel (on frontend %d) failed!", feid);
105                 return -1;
106         }
107
108         std::list<ePtr<iDVBFrontendParameters> > list;
109
110         m_scan = new eDVBScan(channel);
111         m_scan->connectEvent(slot(*this, &eComponentScan::scanEvent), m_scan_event_connection);
112         m_scan->start(m_initial, flags);
113         
114         return 0;
115 }
116
117 RESULT eComponentScan::getFrontend(ePtr<iDVBFrontend> &fe)
118 {
119         if (m_scan)
120                 return m_scan->getFrontend(fe);
121         fe = 0;
122         return -1;
123 }
124
125 int eComponentScan::getProgress()
126 {
127         if (!m_scan)
128                 return 0;
129         int done, total, services;
130         m_scan->getStats(done, total, services);
131         if (!total)
132                 return 0;
133         return done * 100 / total;
134 }
135
136 int eComponentScan::getNumServices()
137 {
138         if (!m_scan)
139                 return 0;
140         int done, total, services;
141         m_scan->getStats(done, total, services);
142         return services;
143 }
144
145 int eComponentScan::isDone()
146 {
147         return m_done;
148 }
149
150 int eComponentScan::getError()
151 {
152         return m_failed;
153 }
154
155 void eComponentScan::getLastServiceName(std::string &string)
156 {
157         if (!m_scan)
158                 return;
159         m_scan->getLastServiceName(string);
160 }