trunk 20080912
[gitenigma.git] / src / channelinfo.cpp
blobc94845c16002bd827e5ca8e83d1bcd2d76f5c058
1 #include <channelinfo.h>
2 #include <lib/base/i18n.h>
3 #include <lib/system/init.h>
4 #include <lib/system/init_num.h>
5 #include <lib/gui/eskin.h>
6 #include <lib/gdi/font.h>
7 #include <lib/dvb/epgcache.h>
8 #include <lib/dvb/dvbservice.h>
9 #include <lib/dvb/frontend.h>
10 #include <lib/system/info.h>
11 #include <sys/stat.h>
12 #include <time.h>
13 #include <epgwindow.h>
15 eChannelInfo::eChannelInfo( eWidget* parent, const char *deco)
16 :eDecoWidget(parent, 0, deco),
17 ctime(this), cname(this), copos(this), cdescr(this),
18 cdolby(this), cstereo(this),
19 cformat(this), cscrambled(this), eit(0)
21 foregroundColor=eSkin::getActive()->queryColor("eStatusBar.foreground");
22 backgroundColor=eSkin::getActive()->queryColor("eStatusBar.background");
23 gFont fn = eSkin::getActive()->queryFont("eChannelInfo");
25 cdescr.setFont( fn );
26 cdescr.setForegroundColor( foregroundColor );
27 cdescr.setBackgroundColor( backgroundColor );
28 cdescr.setFlags(RS_WRAP);
29 cdescr.hide();
31 copos.setFont( fn );
32 copos.setAlign( eTextPara::dirRight );
33 copos.setForegroundColor( foregroundColor );
34 copos.setBackgroundColor( backgroundColor );
35 copos.setFlags( RS_FADE );
37 cname.setFont( fn );
38 cname.setForegroundColor( foregroundColor );
39 cname.setBackgroundColor( backgroundColor );
40 cname.setFlags( RS_FADE );
42 ctime.setFont( fn );
43 ctime.setForegroundColor( foregroundColor );
44 ctime.setBackgroundColor( backgroundColor );
45 ctime.setFlags( RS_FADE );
47 gPixmap *pm=eSkin::getActive()->queryImage("sselect_dolby");
48 cdolby.setPixmap(pm);
49 cdolby.pixmap_position = ePoint(0,0);
50 cdolby.hide();
52 pm = eSkin::getActive()->queryImage("sselect_stereo");
53 cstereo.setPixmap(pm);
54 cstereo.pixmap_position = ePoint(0,0);
55 cstereo.hide();
57 pm = eSkin::getActive()->queryImage("sselect_format");
58 cformat.setPixmap(pm);
59 cformat.pixmap_position = ePoint(0,0);
60 cformat.hide();
62 pm = eSkin::getActive()->queryImage("sselect_crypt");
63 cscrambled.setPixmap(pm);
64 cscrambled.pixmap_position = ePoint(0,0);
65 cscrambled.hide();
68 const char *eChannelInfo::genresTableShort[256] =
70 /* 0x0 undefined */ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
71 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
73 /* 0x1 Movie */ _("Movie"),("Thriller"),_("Adventure"),_("SciFi"),_("Comedy"),
74 _("Soap"),_("Romance"),_("Serious"),_("Adult"),
75 NULL,NULL,NULL,NULL,NULL,NULL,NULL,
77 /* 0x2 News */ _("News"),_("Weather"),_("Magazine"),_("Documentary"),_("Discussion"),
78 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
79 NULL,NULL,NULL,
81 /* 0x3 Show */ _("Show"),_("Game Show"),_("Variety"),_("Talk"),
82 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
83 NULL,NULL,NULL,NULL,
85 /* 0x4 Sports */ _("Sports"),_("Special Event"),_("Sports Mag."),_("Football"),_("Tennis"),_("Team Sports"),
86 _("Athletics"),_("Motor Sports"),_("Water Sports"),_("Winter Sports"),_("Equestrian"),
87 _("Martial Sports"),
88 NULL,NULL,NULL,NULL,
90 /* 0x5 Children */ _("Children"),_("Pre-School"),_("Age 6-14"),_("Age 10-16"),_("School"),
91 _("Cartoons"),
92 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
93 NULL,NULL,
95 /* 0x6 Music */ _("Music"),_("Rock/Pop"),_("Classical"),_("Folk"),_("Jazz"),_("Musical"),_("Ballet"),
96 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
97 NULL,
99 /* 0x7 Culture */ _("Culture"),_("Perf. Arts"),_("Fine Arts"),_("Religion"),_("Pop. Arts"),_("Literature"),
100 _("Film"),_("Experimental"),_("Press"),_("New Media"),_("Art Mag."),_("Fashion"),
101 NULL,NULL,NULL,NULL,
103 /* 0x8 Social */ _("Social"),_("Soc. Mag."),_("Economics"),_("Remark. People"),
104 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
105 NULL,NULL,NULL,NULL,
107 /* 0x9 Education */ _("Education"),_("Nature"),_("Technology"),_("Medicine"),_("Expeditions"),_("Spiritual"),
108 _("Further Ed."),_("Languages"),
109 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
111 /* 0xa Leisure */ _("Hobbies"),_("Travel"),_("Handicraft"),_("Motoring"),_("Fitness"),_("Cooking"),
112 _("Shopping"),_("Gardening"),
113 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
115 /* 0xb Special */ _("Orig. Lang."),_("B&W"),_("Unpublished"),_("Live"),
116 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
117 NULL,NULL,NULL,NULL,
119 /* 0xc reserved */ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
120 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
122 /* 0xd reserved */ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
123 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
125 /* 0xe reserved */ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
126 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
128 /* 0xf user defined */ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
129 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
132 void eChannelInfo::ParseEITInfo(EITEvent *e)
134 name=descr=genre=starttime="";
135 cflags=0;
136 eString t;
138 if(e->start_time!=0)
140 tm *stime=localtime(&e->start_time);
141 starttime.sprintf("%02d:%02d", stime->tm_hour, stime->tm_min);
142 int show_current_remaining=1;
143 eConfig::getInstance()->getKey("/ezap/osd/showCurrentRemaining", show_current_remaining);
144 if (show_current_remaining)
146 time_t now = time(0) + eDVB::getInstance()->time_difference;
147 int duration = e->duration - (now - e->start_time);
148 if ( duration > e->duration )
149 duration = e->duration;
150 else if ( duration < 0 )
151 duration = 0;
152 t.sprintf(" (+%dmin)", (int)(duration/60));
154 else
155 t.sprintf(" (%dmin)", (int)(e->duration/60));
158 if (e->free_CA_mode )
159 cflags |= cflagScrambled;
161 LocalEventData led;
162 led.getLocalData(e, &name, &descr, 0);
164 for (ePtrList<Descriptor>::iterator d(e->descriptor); d != e->descriptor.end(); ++d)
166 Descriptor *descriptor=*d;
167 if (descriptor->Tag()==DESCR_COMPONENT)
169 ComponentDescriptor *cd=(ComponentDescriptor*)descriptor;
171 if( cd->stream_content == 2 && cd->component_type == 5)
172 cflags |= cflagDolby;
173 else if( cd->stream_content == 2 && cd->component_type == 3)
174 cflags |= cflagStereo;
175 else if( cd->stream_content == 1 && (cd->component_type == 2 || cd->component_type == 3) )
176 cflags |= cflagWide;
178 else if(descriptor->Tag()==DESCR_CONTENT)
180 ContentDescriptor *cod=(ContentDescriptor*)descriptor;
182 for(ePtrList<descr_content_entry_struct>::iterator ce(cod->contentList.begin()); ce != cod->contentList.end(); ++ce)
184 if(genresTableShort[ce->content_nibble_level_1*16+ce->content_nibble_level_2])
186 /* if ( !genre.length() )
187 genre+=_("GENRE: ");*/
188 genre += gettext( genresTableShort[ce->content_nibble_level_1*16+ce->content_nibble_level_2] );
189 genre += " ";
194 if(!t.isNull()) name += t;
196 cname.setText( name );
197 if ( genre.size() )
199 if ( name.size() )
200 descr+=" / ";
201 descr+=genre;
203 cdescr.setText( descr );
204 ctime.setText( starttime );
206 int n = 0;
207 n = LayoutIcon(&cdolby, (cflags & cflagDolby), n);
208 n = LayoutIcon(&cstereo, (cflags & cflagStereo), n);
209 n = LayoutIcon(&cformat, (cflags & cflagWide), n );
210 n = LayoutIcon(&cscrambled, (cflags & cflagScrambled), n );
213 void eChannelInfo::closeEIT()
215 if (eit)
216 eit->abort();
219 void eChannelInfo::getServiceInfo( const eServiceReferenceDVB& service )
221 closeEIT();
222 delete eit;
223 eit=0;
225 // eService *service=eServiceInterface::getInstance()->addRef(service);
227 if (!service.path.size())
229 cdescr.show();
230 cname.setFlags(RS_FADE);
231 cname.resize( eSize( clientrect.width()/8*7-4, clientrect.height()/3) );
232 int opos=service.getDVBNamespace().get()>>16;
233 if ( eSystemInfo::getInstance()->getFEType() == eSystemInfo::feSatellite )
234 copos.setText(eString().sprintf("%d.%d\xC2\xB0%c", abs(opos / 10), abs(opos % 10), opos>0?'E':'W') );
235 EITEvent *e = 0;
236 e = eEPGCache::getInstance()->lookupEvent(service);
237 if (e) // data is in cache...
239 ParseEITInfo(e);
240 delete e;
242 else // we parse the eit...
244 cname.setText(_("no data for this service avail"));
245 eDVBServiceController *sapi=eDVB::getInstance()->getServiceAPI();
246 if (!sapi)
247 return;
248 eServiceReferenceDVB &ref = sapi->service;
250 int type = ((service.getTransportStreamID()==ref.getTransportStreamID())
251 && (service.getOriginalNetworkID()==ref.getOriginalNetworkID())) ? EIT::tsActual:EIT::tsOther;
253 eit = new EIT( EIT::typeNowNext, service.getServiceID().get(), type );
254 CONNECT( eit->tableReady, eChannelInfo::EITready );
255 eit->start();
257 } else
259 copos.setText("");
260 cdescr.hide();
261 cname.setFlags(RS_WRAP);
262 cname.resize( eSize( clientrect.width()/8*7-4, clientrect.height() ));
263 // should be moved to eService
264 int filelength=service.getFileLength();
265 if (filelength <= 0)
267 eString filename=service.path;
268 int slice=0;
269 struct stat64 s;
270 while (!stat64((filename + (slice ? eString().sprintf(".%03d", slice) : eString(""))).c_str(), &s))
272 filelength+=s.st_size/1024;
273 slice++;
276 int i = service.path.rfind("/");
277 i++;
278 eString size;
279 size.sprintf(_("\nFilesize: %d MB"), filelength/1024);
280 cname.setText(eString(_("Filename: "))+service.path.mid( i, service.path.length()-i)+size );
284 void eChannelInfo::EITready( int err )
286 // eDebug("Channelinfo eit ready: %d", err);
287 if (eit->ready && !eit->error)
289 if ( eit->events.size() )
290 ParseEITInfo(eit->events.begin());
292 else if ( err == -ETIMEDOUT )
293 closeEIT();
296 void eChannelInfo::update( const eServiceReferenceDVB& service )
298 if (service)
300 current = service;
301 getServiceInfo(current);
305 void eChannelInfo::clear()
307 cname.setText("");
308 cdescr.setText("");
309 ctime.setText("");
310 copos.setText("");
311 cdolby.hide();
312 cstereo.hide();
313 cformat.hide();
314 cscrambled.hide();
317 int eChannelInfo::LayoutIcon(eLabel *icon, int doit, int num )
319 if( doit )
321 int x,y;
323 switch(num)
325 case 0:
326 x=2;
327 y=28;
328 break;
329 case 1:
330 x=44;
331 y=28;
332 break;
333 case 2:
334 x=2;
335 y=50;
336 break;
337 case 3:
338 x=44;
339 y=50;
340 break;
341 default:
342 x=0;
343 y=0;
344 break;
346 icon->move(ePoint(x,y));
347 icon->show();
348 num++;
351 return num;
355 void eChannelInfo::redrawWidget(gPainter *target, const eRect& where)
357 if ( deco )
358 deco.drawDecoration(target, ePoint(width(), height()));
360 target->line( ePoint(clientrect.left() + clientrect.width()/8 + 1, clientrect.top()),ePoint(clientrect.left() + clientrect.width()/8 + 1,clientrect.bottom()-1));
363 int eChannelInfo::eventHandler(const eWidgetEvent &event)
365 switch (event.type)
367 case eWidgetEvent::changedSize:
369 if (deco)
370 clientrect=crect;
372 int dx=clientrect.width()/8;
373 int dy=clientrect.height()/3;
374 ctime.move( ePoint(0,0) );
375 ctime.resize( eSize(dx, 36 ));
377 cname.move( ePoint( dx + 4, 0 ) );
379 cdescr.move( ePoint(dx + 4, dy) );
380 cdescr.resize( eSize( clientrect.width() - (dx*2 + 4), dy+dy) );
382 copos.move( ePoint( clientrect.width() - (dx+4), dy+dy) );
383 copos.resize( eSize(dx + 4, dy) );
385 cdolby.resize( eSize(25,15) );
386 cstereo.resize( eSize(25,15) );
387 cformat.resize( eSize(25,15) );
388 cscrambled.resize( eSize(25,15) );
390 invalidate();
391 break;
393 default:
394 break;
396 return eDecoWidget::eventHandler(event);
399 static eWidget *create_eChannelInfo(eWidget *parent)
401 return new eChannelInfo(parent);
404 class eChannelInfoSkinInit
406 public:
407 eChannelInfoSkinInit()
409 eSkin::addWidgetCreator("eChannelInfo", create_eChannelInfo);
411 ~eChannelInfoSkinInit()
413 eSkin::removeWidgetCreator("eChannelInfo", create_eChannelInfo);
417 eAutoInitP0<eChannelInfoSkinInit> init_eChannelInfoSkinInit(eAutoInitNumbers::guiobject, "eChannelInfo");