fix timerediting
[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::evtFail)
37         {
38                 eDebug("scan failed.");
39                 m_failed = 1;
40                 m_done = 1;
41         }
42         
43         statusChanged();
44 }
45
46 eComponentScan::eComponentScan(): m_done(-1), m_failed(0)
47 {
48 }
49
50 eComponentScan::~eComponentScan()
51 {
52 }
53
54 void eComponentScan::clear()
55 {
56         m_initial.clear();
57 }
58
59 void eComponentScan::addInitial(const eDVBFrontendParametersSatellite &p)
60 {
61         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
62         parm->setDVBS(p);
63         m_initial.push_back(parm);
64 }
65
66 void eComponentScan::addInitial(const eDVBFrontendParametersCable &p)
67 {
68         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
69         parm->setDVBC(p);
70         m_initial.push_back(parm);
71 }
72
73 void eComponentScan::addInitial(const eDVBFrontendParametersTerrestrial &p)
74 {
75         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
76         parm->setDVBT(p);
77         m_initial.push_back(parm);
78 }
79
80
81 int eComponentScan::start(int feid, int flags)
82 {
83         if (m_initial.empty())
84                 return -2;
85
86         if (m_done != -1)
87                 return -1;
88         
89         m_done = 0;
90         ePtr<eDVBResourceManager> mgr;
91         
92         eDVBResourceManager::getInstance(mgr);
93
94         eUsePtr<iDVBChannel> channel;
95
96         if (mgr->allocateRawChannel(channel, feid))
97         {
98                 eDebug("scan: allocating raw channel (on frontend %d) failed!", feid);
99                 return -1;
100         }
101
102         std::list<ePtr<iDVBFrontendParameters> > list;
103                 
104         m_scan = new eDVBScan(channel);
105         m_scan->connectEvent(slot(*this, &eComponentScan::scanEvent), m_scan_event_connection);
106         m_scan->start(m_initial, flags);
107         
108         return 0;
109 }
110
111 int eComponentScan::getProgress()
112 {
113         if (!m_scan)
114                 return 0;
115         int done, total, services;
116         m_scan->getStats(done, total, services);
117         if (!total)
118                 return 0;
119         return done * 100 / total;
120 }
121
122 int eComponentScan::getNumServices()
123 {
124         if (!m_scan)
125                 return 0;
126         int done, total, services;
127         m_scan->getStats(done, total, services);
128         return services;
129 }
130
131 int eComponentScan::isDone()
132 {
133         return m_done;
134 }
135
136 int eComponentScan::getError()
137 {
138         return m_failed;
139 }