Debian Codegraph @

samples/qtvidcap/epgwindow.cpp

raw
1 /*
2 EPG (Electronic Program Guide) window for AviCap
3
4 written 2003 by Alexander Rawass ([email protected])
5 */
6
7
8 #include <unistd.h>
9 #ifndef WIN32
10 #include <pwd.h>
11 #endif
12
13 #include "vidconf.h"
14 #include "v4lwindow.h"
15 #include "capproc.h"
16 #include "codecdialog.h"
17
18 #include <avm_fourcc.h>
19 #include <avm_cpuinfo.h>
20 #include <avm_creators.h>
21 #include <avm_output.h>
22 #include <utils.h>
23 #define DECLARE_REGISTRY_SHORTCUT
24 #include <configfile.h>
25 #undef DECLARE_REGISTRY_SHORTCUT
26
27 #include <qcheckbox.h>
28 #include <qcombobox.h>
29 #include <qfiledialog.h>
30 #include <qlabel.h>
31 #include <qlineedit.h>
32 #include <qpushbutton.h>
33 #include <qspinbox.h>
34 #include <qtabwidget.h>
35 #include <qlistview.h>
36 #include <qcombobox.h>
37 #include <qsplitter.h>
38 #include <qgroupbox.h>
39 #include <qlayout.h>
40 #include <qpushbutton.h>
41 #include <qbuttongroup.h>
42 #include <qmessagebox.h>
43 #include <qpainter.h>
44 #include <qhgroupbox.h>
45 #include <qvgroupbox.h>
46 #include <qhbox.h>
47 #include <qvbox.h>
48 #include <qcolordialog.h>
49 #include <qstringlist.h>
50 #include <qregexp.h>
51 #include <qpopupmenu.h>
52 #include <qtextstream.h>
53
54 #include <qdom.h>
55
56 #include <stdio.h>
57 #include <stdlib.h> // atof
58 #include <qtabwidget.h>
59
60 #include <stdio.h>
61 #include <stdlib.h> // atof
62 #include <sys/vfs.h> //statfs
63 #include <time.h>
64
65 #if QT_VERSION>=300
66 #include <qtextedit.h>
67 #endif
68
69 #if 1
70
71 //#include <qdatetimeedit.h>
72 #include "epgwindow.h"
73 #include "timertable.h"
74
75 #include <qtable.h>
76
77 int calcTimeDiff(){
78
79 struct tm local;
80 time_t absolute;
81
82 time(&absolute);
83 localtime_r(&absolute,&local);
84
85 //printf("gmtoff=%ld \n",local.tm_gmtoff);
86 return local.tm_gmtoff;
87
88 }
89
90 EpgWindow::EpgWindow(V4LWindow *v4l,TimerTable *timer)
91 : QWidget(0), avm::AvmOutputLog("EPGWindow")
92 {
93 v4lwin=v4l;
94 timertable=timer;
95 channel_row=0;
96 today_item=-1;
97 regexp_dirty=true;
98 current_recording=NULL;
99 next_recording=NULL;
100 zoom_step=0;
101 strip_y_size=strip_y_default;
102
103 AVMOUT(AVML_DEBUG, "EPGWindow started");
104
105 local_timediff=calcTimeDiff();
106 //printf("timediff is %ld\n",local_timediff);
107
108 initWidgets();
109 makeConfigWidget(0);
110
111 load();
112 makeChannelStrips();
113 conf_channel_view->updateGeometry();
114 conf_channel_scroll->updateGeometry();
115 conf_channel_view->adjustSize();
116
117 current_date_item=-1;
118
119 day_selected(today_item);
120 // config_widget->show();
121
122 epg_timer=new QTimer(this);
123 connect(epg_timer,SIGNAL(timeout()),SLOT(timer()));
124 epg_timer->start(1000*60); //every minute
125 }
126
127 EpgWindow::~EpgWindow()
128 {
129 }
130
131 void EpgWindow::lock(bool lock)
132 {
133 conf_dir_edit->setReadOnly(lock);
134 regexp_edit->setReadOnly(lock);
135 if(lock){
136 conf_channel_view->hide();
137 }
138 else{
139 conf_channel_view->show();
140 }
141 }
142
143 void EpgWindow::addEntry(QDateTime start_date,QDateTime stop_date,QString channel_str,QString title,QString desc){
144 // printf("addEntry %s\n",title.latin1());
145 EpgTableItem *item=new EpgTableItem(ptable,this,start_date,stop_date,channel_str, title, desc);
146
147 QDate sdate=start_date.date();
148
149 EpgProgram *new_program=new EpgProgram();
150 new_program->start=start_date;
151 new_program->stop=stop_date;
152 new_program->title=title;
153 new_program->desc=desc;
154 new_program->blockmode=regexp_unset;
155
156 bool stored_program=false;
157 while(!stored_program){
158 bool found_day=false;
159
160 //iterate over dates
161 //EpgDayList::iterator id;
162 QValueListIterator<EpgDay *> id;
163 for(id=epglist.begin();!found_day && id!=epglist.end();id++){
164 EpgDay *day=*id;
165 if(sdate==day->date){
166 found_day=true;
167 //we iterate over channels
168
169 bool found_channel=false;
170 //EpgChannelList::iterator ic;
171 EpgChannelListIterator ic;
172 for(ic=day->channels.begin();!found_channel && ic!=day->channels.end();ic++){
173 EpgChannel *ch=*ic;
174 if(ch->chid==channel_str){
175 found_channel=true;
176
177 new_program->channelnr=ch->channelnr;
178 ch->programs.append(new_program);
179 stored_program=true;
180 //found=true;
181 }
182 }
183 if(!found_channel){
184 // add a new channel
185
186 //printf("creating new channel %s (%s) in day %s\n",channel_str.latin1(),findNameToId(channel_str).latin1(),day->date.toString().latin1());
187 EpgChannel *newch=new EpgChannel();
188 newch->chid=channel_str;
189 day->channels.append(newch);
190
191 //search for the EpgChannelId
192 EpgChIdListIterator icht;
193 bool found_chid=false;
194 for(icht=epgChannels.begin();!found_chid && icht!=epgChannels.end();icht++){
195 EpgIdChannel *epgidch=*icht;
196
197 if(epgidch->epgid==newch->chid){
198 found_chid=true;
199 newch->channelnr=epgidch->chnr;
200 newch->idchannel=epgidch;
201 }
202 }
203 }
204 }
205 }
206 if(!found_day){
207 // add a new day
208 //printf("creating a new day %s\n",sdate.toString().latin1());
209 EpgDay *newday=new EpgDay();
210 newday->date=sdate;
211 epglist.append(newday);
212
213 QString daydesc=sdate.toString(epg_dateformat);
214 if(QDate::currentDate()==sdate){
215 daydesc=daydesc+tr(" Today");
216 }
217 day_selector->insertItem(daydesc);
218 int itemnr=day_selector->count()-1;
219 //printf("day got nr %d\n",itemnr);
220 newday->itemnr=itemnr;
221 if(QDate::currentDate()==sdate){
222 today_item=itemnr;
223 }
224 // day_selector->changeItem(QString().sprintf("%d",itemnr)+daydesc,itemnr);
225 }
226 }//end while !stored_program
227
228 }
229
230
231 void EpgWindow::doChannel(QDomElement &elem){
232 // printElem(elem);
233
234 EpgIdChannel *new_channel=new EpgIdChannel();
235
236 new_channel->epgid=elem.attribute("id");
237 if(new_channel->epgid.isNull()){
238 printf("didnt get attribute in channel\n");
239 delete new_channel;
240 return;
241 }
242
243 QDomNode n=elem.firstChild();
244
245 while(!n.isNull()){
246 QDomElement e=n.toElement();
247 if(!e.isNull()){
248 if(e.tagName()=="display-name"){
249 new_channel->epgname=e.text();
250 }
251 else{
252 //ignore
253 }
254 }
255 n=n.nextSibling();
256 }
257
258
259 epgChannels.append(new_channel);
260
261 QCheckListItem *item=new QCheckListItem(ctable,"test",QCheckListItem::CheckBox);
262 item->setText(0,new_channel->epgname);
263 #if 0
264 EpgChannelStrip *newstrip=new EpgChannelStrip(gridview,this,new_channel);
265 gridlayout->addWidget(newstrip);
266 // newstrip->repaint();
267
268 #endif
269
270 new_channel->strip=NULL;
271 QHBox *hbox=new QHBox(conf_channel_view);
272 #if 0
273 new_channel->conf_channel_label=new QLabel(tr("Provider ")+provider+" EPGid "+new_channel->epgid+" "+new_channel->epgname+" is ",hbox);
274 #endif
275
276 new_channel->conf_channel_label=new QLabel("EPGid "+new_channel->epgid+" ("+new_channel->epgname+") is ",hbox);
277 // conf_channel_lay->addWidget(new_channel->conf_channel_label,channel_row,0);
278
279 new_channel->conf_channel_box=new QComboBox(hbox);
280 // conf_channel_lay->addWidget(new_channel->conf_channel_box,channel_row,1);
281
282 new_channel->conf_channel_box->insertItem(tr("not available"));
283 for(int i=0;i<ACnumChannels();i++){
284 new_channel->conf_channel_box->insertItem(QString().sprintf("%02d - %s",i+1,ACchannelName(i).latin1()));
285 }
286 #if 0
287 int chnr=RI(QString().sprintf("Epg-%s-%s",provider.latin1(),new_channel->epgid.latin1()),0);
288 #endif
289 int chnr=RI(QString().sprintf("Epg-%s-%s","Provider",new_channel->epgid.latin1()),0);
290
291 new_channel->conf_channel_box->setCurrentItem(chnr);
292
293 new_channel->chnr=chnr;
294
295 //connect(new_channel->conf_channel_box,SIGNAL(activated(int)),this,channelMappingChanged(int));
296
297 QPushButton *color_button=new QPushButton(tr("Color"),hbox);
298 // color_button->setToggleButton(false);
299
300 new_channel->color_button=color_button;
301
302 QString colstr=RS(QString().sprintf("Epg-%s-%s-Color","Provider",new_channel->epgid.latin1()),"#DDDDDD");
303 QColor color=QColor(colstr);
304 new_channel->color=color;
305 #if QT_VERSION>=300
306 color_button->setBackgroundMode(Qt::PaletteBackground);
307 //color_button->setBackgroundMode(Qt::FixedColor);
308 color_button->setPaletteBackgroundColor(color);
309 #else
310 #warning "no color_button->setBackgroundMode(Qt::PaletteBackground)"
311 #endif
312
313 connect(color_button,SIGNAL(pressed()),this,SLOT(colorSelector()));
314
315 channel_row++;
316 }
317
318 #if 0
319 void EpgWindow::channelMappingChanged(int nr){
320 }
321 #endif
322
323 QDateTime EpgWindow::parseDate(QString datestr){
324
325 QString yearstr=datestr.mid(0,4);
326 QString monstr=datestr.mid(4,2);
327 QString daystr=datestr.mid(6,2);
328
329 QString hourstr=datestr.mid(8,2);
330 QString minstr=datestr.mid(10,2);
331 QString secstr=datestr.mid(12,2);
332
333 QDateTime datetime;
334
335 datetime.setDate(QDate(yearstr.toInt(),monstr.toInt(),daystr.toInt()));
336 datetime.setTime(QTime(hourstr.toInt(),minstr.toInt(),secstr.toInt()));
337
338 //allow for localtime
339
340 datetime=datetime.addSecs(local_timediff);
341
342 // printf("parsed %s to %s\n",datestr.latin1(),datetime.toString().latin1());
343
344 return datetime;
345 }
346
347 void EpgWindow::doProgramme(QDomElement &elem){
348 // printElem(elem);
349
350 QString start_str=elem.attribute("start");
351 QString stop_str=elem.attribute("stop");
352 QString channel_str=elem.attribute("channel");
353
354 if(start_str.isNull() || stop_str.isNull() || channel_str.isNull()){
355 printf("didnt get attribute in programme\n");
356 return;
357 }
358
359 QDateTime start_date=parseDate(start_str);
360 QDateTime stop_date=parseDate(stop_str);
361 QString title;
362 QString desc;
363
364 QDomNode n=elem.firstChild();
365
366 while(!n.isNull()){
367 QDomElement e=n.toElement();
368 if(!e.isNull()){
369 if(e.tagName()=="title"){
370 title=e.text();
371 }
372 else if(e.tagName()=="desc"){
373 desc=e.text();
374 }
375 else{
376 //ignore
377 }
378 }
379 n=n.nextSibling();
380 }
381
382 addEntry(start_date,stop_date,channel_str,title,desc);
383 }
384
385 void EpgWindow::printElem(QDomElement &elem){
386 printf("tagname=%s ",elem.tagName().latin1());
387
388 QDomNamedNodeMap attrmap=elem.attributes();
389
390 for(uint i=0; i<attrmap.length();i++){
391 QDomNode node=attrmap.item(i);
392 printf("%s=%s ",node.nodeName().latin1(),node.nodeValue().latin1());
393 }
394 printf("\n");
395 }
396
397 void EpgWindow::parse(QDomDocument &dom){
398 QDomElement tv_elem=dom.documentElement();
399
400 printElem(tv_elem);
401 if(tv_elem.tagName()!="tv"){
402 printf("error: node tv expected\n");
403 return;
404 }
405
406 QDomNode n=tv_elem.firstChild();
407
408 while(!n.isNull()){
409 QDomElement e=n.toElement();
410 if(!e.isNull()){
411 if(e.tagName()=="channel"){
412 doChannel(e);
413 }
414 else if(e.tagName()=="programme"){
415 doProgramme(e);
416 }
417 else{
418 printf("unexpected tag\n");
419 printElem(e);
420 return;
421 }
422 }
423 n=n.nextSibling();
424 }
425 }
426
427 void EpgWindow::load(){
428 load(RS("Epg-ProviderFilename","/tmp/epg.xml"));
429 }
430
431 void EpgWindow::load(QString fname){
432 printf("loading epg xml file\n");
433
434 QDomDocument epgxml("epg xml");
435 QFile epgfile(fname);
436 if(!epgfile.open(IO_ReadOnly)){
437 epgfile.close();
438 printf("could not openfile\n");
439 return;
440 }
441 printf("before setcontent\n");
442 if( !epgxml.setContent(&epgfile)){
443 epgfile.close();
444 return;
445 }
446 printf("after setcontent\n");
447 epgfile.close();
448
449 provider=fname;
450
451 printf("before parse\n");
452 parse(epgxml);
453 printf("after parse\n");
454
455 }
456
457 void EpgWindow::initWidgets(){
458 setCaption(tr("EPG Browser"));
459 setBaseSize(600,600);
460 //setMaximumSize(800,700);
461
462 QWidget *topwin=this;
463 // QVBoxLayout *vb1=new QVBoxLayout(topwin->layout());
464 QHBoxLayout *lay1=new QHBoxLayout(topwin);
465
466 ctable=new QListView(topwin);
467 lay1->addWidget(ctable);
468
469 ctable->addColumn(tr("Channel"));
470 ctable->setMaximumSize(150,1000);
471 ctable->setAllColumnsShowFocus(true);
472 ctable->setShowSortIndicator(true);
473 ctable->setSorting(0,true);
474 ctable->sort();
475
476 centralw=new QWidget(topwin);
477 lay1->addWidget(centralw);
478 QVBoxLayout *lay4=new QVBoxLayout(centralw);
479
480 QWidget *topstrip=new QWidget(centralw);
481 lay4->addWidget(topstrip);
482 QHBoxLayout *lay6=new QHBoxLayout(topstrip);
483 lay6->setMargin(5);
484 lay6->setSpacing(5);
485
486 day_selector=new QComboBox(topstrip);
487 lay6->addWidget(day_selector);
488
489 zoom_in_button=new QPushButton(topstrip);
490 zoom_in_button->setText(tr("ZoomIn"));
491 lay6->addWidget(zoom_in_button);
492
493 zoom_out_button=new QPushButton(topstrip);
494 zoom_out_button->setText(tr("ZoomOut"));
495 lay6->addWidget(zoom_out_button);
496
497 display_toggle=new QPushButton(topstrip);
498 display_toggle->setText(tr("toggle display"));
499 lay6->addWidget(display_toggle);
500
501 config_button=new QPushButton(topstrip);
502 config_button->setText(tr("EPG Config"));
503 lay6->addWidget(config_button);
504
505 regexp_button=new QPushButton(topstrip);
506 regexp_button->setText(tr("Edit Regexps"));
507 lay6->addWidget(regexp_button);
508
509 // QVBoxLayout *lay5=new QVBoxLayout(centralw);
510
511 gridtable=new QTable(centralw);
512 lay4->addWidget(gridtable);
513 #if 0
514 gridscroll=new QScrollView(centralw);
515 lay4->addWidget(gridscroll);
516 QHBoxLayout *lay3=new QHBoxLayout(gridscroll->viewport());
517
518 gridheader=new QHeader(gridscroll);
519 gridheader->setOrientation(Qt::Horizontal);
520 // gridscroll->addChild(gridheader);
521
522 lay3->addWidget(gridheader);
523
524 gridview=new QWidget(gridscroll->viewport());
525 gridscroll->addChild(gridview);
526 lay3->addWidget(gridview);
527
528 //gridview->setMinimumSize(300,strip_y);
529 //gridscroll->setMaximumSize(600,strip_y);
530 //gridscroll->resizeContents(2000,strip_y);
531 //gridscroll->viewport()->resize(1000,strip_y);
532 gridscroll->setResizePolicy(QScrollView::AutoOneFit);
533 gridscroll->setVScrollBarMode(QScrollView::AlwaysOn);
534 gridscroll->setHScrollBarMode(QScrollView::AlwaysOn);
535
536 gridlayout=new QHBoxLayout(gridview);
537 gridlayout->setMargin(5);
538 gridlayout->setSpacing(5);
539 #endif
540
541 ptable=new QListView(centralw);
542 lay4->addWidget(ptable);
543
544 ptable->addColumn(tr("Title"));
545 ptable->addColumn(tr("Channel"));
546 ptable->addColumn(tr("Start Date"));
547 ptable->addColumn(tr("Stop Date"));
548 ptable->addColumn(tr("Description"));
549 ptable->setAllColumnsShowFocus(true);
550 ptable->setShowSortIndicator(true);
551 ptable->setSorting(2,true);
552 ptable->sort();
553 ptable->hide();
554 #if 0
555 bottom_label=new QLabel("Title\nDescription\n",centralw);
556 bottom_label->setAlignment(Qt::WordBreak);
557 lay4->addWidget(bottom_label);
558 #endif
559 bottom_text=new QTextEdit(centralw);
560 #if QT_VERSION>=300
561 bottom_text->setTextFormat(Qt::PlainText);
562 #endif
563 bottom_text->setReadOnly(TRUE);
564 lay4->addWidget(bottom_text);
565
566 //show();
567
568 // resizeStrips();
569
570 connect(day_selector,SIGNAL(activated(int)),this,SLOT(day_selected(int)));
571 connect(display_toggle,SIGNAL(pressed()),this,SLOT(display_toggled()));
572 connect(config_button,SIGNAL(pressed()),this,SLOT(show_config()));
573 connect(regexp_button,SIGNAL(pressed()),this,SLOT(show_regexps()));
574
575 connect(timertable,SIGNAL(currentRecordingChanged(TimerTableItem *)),this,SLOT(setCurrentRecording(TimerTableItem *)));
576 connect(timertable,SIGNAL(nextRecordingChanged(TimerTableItem *)),this,SLOT(setNextRecording(TimerTableItem *)));
577 connect(timertable,SIGNAL(timertableChanged()),this,SLOT(timertableModified()));
578
579 connect(zoom_in_button,SIGNAL(pressed()),this,SLOT(zoomIn()));
580 connect(zoom_out_button,SIGNAL(pressed()),this,SLOT(zoomOut()));
581
582 display_mode=0;
583 }
584
585 void EpgWindow::show_config(){
586 config_widget->show();
587 }
588
589 void EpgWindow::show_regexps(){
590 printf("showing regexps\n");
591 regexp_box->show();
592 }
593
594 void EpgWindow::display_toggled(){
595 if(display_mode==0){
596 ptable->show();
597 gridtable->hide();
598 display_mode=1;
599 }
600 else if(display_mode==1){
601 ptable->hide();
602 gridtable->show();
603 display_mode=0;
604 }
605 }
606
607 void EpgWindow::day_selected(int nr){
608 if(current_date_item!=nr){
609 //a new day selected
610 regexp_dirty=true;
611 }
612 else{
613 //just a normal redraw
614 }
615
616 current_date_item=nr;
617 //printf("selected day %d\n",nr);
618 day_selector->setCurrentItem(nr);
619 #if 0
620 gridview->repaint();
621 gridview->update();
622 #endif
623 // gridtable->repaint();
624 //gridtable->update();
625
626 resizeStrips();
627
628 regexp_dirty=false;
629 }
630
631 void EpgWindow::resizeStrips(){
632 calcStripSize();
633
634 // int strip_y=strip_y_size;
635
636 EpgChIdListIterator it;
637 for(it=epgChannels.begin();it!=epgChannels.end();it++){
638 EpgIdChannel *idch=*it;
639 if(idch->strip!=NULL){
640 //printf("check1\n");
641 gridtable->setColumnWidth(idch->chnr-1,strip_x);
642 //printf("check2\n");
643 gridtable->setRowHeight(idch->chnr-1,strip_y_size);
644 //printf("check3\n");
645 idch->strip->setFixedSize(strip_x,strip_y_size);
646 //printf("check4\n");
647 //idch->strip->resize(strip_x,strip_y_size);
648 //idch->strip->updateGeometry();
649 idch->strip->repaint();
650 }
651 }
652
653 }
654
655 void EpgWindow::makeChannelStrips(){
656 gridtable->setNumRows(1);
657 gridtable->setNumCols(ACnumChannels());
658 gridtable->setVScrollBarMode(QScrollView::AlwaysOn);
659 gridtable->setHScrollBarMode(QScrollView::AlwaysOn);
660 gridtable->setRowHeight(0,strip_y_default);
661
662 for(int i=1;i<ACnumChannels();i++){
663 gridtable->horizontalHeader()->setLabel(i-1,ACchannelName(i-1));
664 EpgChIdListIterator ic;
665 bool found_channel=false;
666 for(ic=epgChannels.begin();!found_channel && ic!=epgChannels.end();ic++){
667 EpgIdChannel *channelid=*ic;
668 if(channelid->chnr==i){
669 found_channel=true;
670 #if 0
671 EpgChannelStrip *newstrip=new EpgChannelStrip(gridview,this,channelid);
672 gridlayout->addWidget(newstrip);
673 #endif
674
675 EpgChannelStrip *newstrip=new EpgChannelStrip(gridtable,this,channelid);
676 gridtable->setCellWidget(0,i-1,newstrip);
677 gridtable->setColumnWidth(i-1,strip_x_default);
678
679 channelid->strip=newstrip;
680
681 //,strip_x);
682 }
683 }
684 }
685
686 }
687
688 void EpgWindow::addRecording(EpgProgram *prog){
689 if(prog){
690 emit emitAddRecording(prog);
691 }
692 }
693
694 void EpgWindow::timertableModified(){
695 day_selected(current_date_item);
696 }
697
698 void EpgWindow::setNextRecording(TimerTableItem *titem){
699 next_recording=titem;
700 day_selected(current_date_item);
701 }
702
703 void EpgWindow::setCurrentRecording(TimerTableItem *titem){
704 current_recording=titem;
705 day_selected(current_date_item);
706 }
707
708 void EpgWindow::zoomIn(){
709 zoom_step++;
710 day_selected(current_date_item);
711 }
712 void EpgWindow::zoomOut(){
713 zoom_step--;
714 day_selected(current_date_item);
715 }
716
717 void EpgWindow::timer(){
718 day_selected(current_date_item);
719 }
720
721 bool EpgWindow::isBlocked(int channelnr){
722 EpgDay *day=NULL;
723 EpgDayListIterator id;
724 QDateTime currentdatetime=QDateTime::currentDateTime();
725
726 for(id=epglist.begin(); id!=epglist.end();id++){
727 day=*id;
728
729 bool found_channel=false;
730 EpgChannelListIterator ic;
731 for(ic=day->channels.begin();!found_channel && ic!=day->channels.end();ic++){
732 EpgChannel *ch=*ic;
733 if(ch->channelnr==channelnr){
734 found_channel=true;
735
736 bool found_prog=false;
737 EpgProgramListIterator ip;
738 for(ip=ch->programs.begin();!found_prog && ip!=ch->programs.end();ip++){
739 EpgProgram *prog=*ip;
740
741 if(prog->start<currentdatetime && currentdatetime<prog->stop){
742 //current program
743 if(ch->idchannel->strip->blockMode(prog)== regexp_block){
744 return true;
745 }
746 }
747 }//for programs
748 }//if channel
749 }//for channels
750 }//for all days
751
752 return false;
753
754 }
755
756 QString EpgWindow::findNameToId(QString channel){
757 EpgChIdListIterator it;
758 for(it=epgChannels.begin();it!=epgChannels.end();it++){
759 EpgIdChannel *idch=*it;
760 if(idch->epgid==channel){
761 return idch->epgname;
762 }
763 }
764 return "noname";
765 }
766
767 EpgTableItem::~EpgTableItem()
768 {
769 }
770
771 EpgTableItem::EpgTableItem(QListView *parent,EpgWindow *epgwindow,QDateTime start,QDateTime stop,QString channelstr,QString titlestr,QString descstr) : QCheckListItem(parent,"test",QCheckListItem::CheckBox){
772
773 start_date=start;
774 stop_date=stop;
775 channel=channelstr;
776 title=titlestr;
777 desc=descstr;
778 epgwin=epgwindow;
779
780 QString startstr=start_date.toString(epg_startdateformat);
781 QString stopstr=stop_date.toString(epg_stopdateformat);
782
783 chname=epgwin->findNameToId(channel);
784
785 setText(0,title);
786 setText(1,chname);
787 setText(2,startstr);
788 setText(3,stopstr);
789 setText(4,desc);
790 }
791
792 int EpgTableItem::compare(QListViewItem *other,int col, bool ascend) const {
793 if(other==NULL){
794 return 0;
795 }
796
797 EpgTableItem *other_tti=(EpgTableItem *)other;
798 int result=0;
799
800 if(col==2){
801 //start time
802 if(getStartTime()==other_tti->getStartTime()){
803 result=0;
804 }
805 else{
806 result=(getStartTime()>other_tti->getStartTime()) ? -1 : 1 ;
807 }
808 }
809 else if(col==3){
810 //stop time
811 if(getStopDateTime()==other_tti->getStopDateTime()){
812 result=0;
813 }
814 else{
815 result=(getStopDateTime()>other_tti->getStopDateTime()) ? -1 : 1;
816 }
817 }
818 else{
819 #if QT_VERSION>=300
820 result=QListViewItem::compare(other,col,ascend);
821 #else
822 #warning "no QListViewItem::compare"
823 #endif
824 }
825
826 return result;
827 }
828
829
830 EpgChannelStrip::EpgChannelStrip(QWidget *parent,EpgWindow *win,EpgIdChannel *new_channel) : QWidget(parent){
831
832 // printf("strip created for %s\n",new_channel->epgname.latin1());
833
834 //setMinimumSize(strip_x,strip_y);
835 //setBaseSize(strip_x,strip_y);
836 setFixedSize(strip_x_default,strip_y_default);
837 setBackgroundColor(white);
838 resize(strip_x_default,strip_y_default);
839 updateGeometry();
840 setMouseTracking(true);
841
842 chid=new_channel;
843 epgwin=win;
844 last_mouse_program=NULL;
845 popmenu=NULL;
846 mid_move=false;
847
848 // QVBoxLayout *lay1=new QVBoxLayout(this);
849
850 //QHeader *head=new QHeader(this);
851 //lay1->addWidget(head);
852
853 //head->addLabel(new_channel->epgname);
854
855 show();
856 }
857
858 int EpgChannelStrip::blockMode(EpgProgram *prog){
859 int j=0;
860 EpgRegexpListIterator it;
861
862 #if QT_VERSION<300
863 #define exactMatch(str) match(str)
864 #endif
865
866 for(it=epgwin->regexpList.begin();it!=epgwin->regexpList.end();it++){
867 EpgRegexp *epgreg=*it;
868
869 if(epgreg->blockmode==regexp_errorblock || epgreg->wheremode==regexp_errorwhere){
870 return regexp_block;
871 }
872 if(epgreg->wheremode==regexp_both){
873 if(epgreg->regexp.exactMatch(prog->title) || epgreg->regexp.exactMatch(prog->desc)){
874 return epgreg->blockmode;
875 }
876 }
877 else if(epgreg->wheremode==regexp_title){
878 if(epgreg->regexp.exactMatch(prog->title)){
879 return epgreg->blockmode;
880 }
881 }
882 else if(epgreg->wheremode==regexp_desc){
883 if(epgreg->regexp.exactMatch(prog->desc)){
884 return epgreg->blockmode;
885 }
886 }
887 }
888 return regexp_nomatch;
889
890 #if QT_VERSION<300
891 #undef exactMatch
892 #endif
893 }
894
895 void EpgWindow::calcStripSize(){
896 strip_x=strip_x_default+(int)(((float)strip_x_default)*(zoom_increment*zoom_step));
897 strip_y=strip_y_default+(int)(((float)strip_y_default)*(zoom_increment*zoom_step));
898
899 int pixel_per_hour=strip_y_default/24;
900 hours_before=RI("EpgHoursBeforeDay",0);
901 hours_after=RI("EpgHoursAfterDay",0);
902
903 strip_y_before=0;
904 strip_y_after=0;
905 strip_y_today=strip_y_default;
906
907 if(hours_before<0){
908 strip_y_before=-hours_before*60;
909 }
910 else{
911 strip_y_today-=hours_before*60;
912 }
913 if(hours_after>0){
914 strip_y_after=hours_after*60;
915 }
916 else{
917 strip_y_today-=-hours_after*60;
918 }
919
920 strip_y_alldays=strip_y_before+strip_y_today+strip_y_after;
921
922 y_subtract=0;
923 if(hours_before>0){
924 y_subtract=hours_before*60;
925 }
926
927 strip_y_size=strip_y_alldays;
928 }
929
930 void EpgChannelStrip::calcYfromTime(int &y_start,int &y_stop,QTime starttime,QTime stoptime){
931 y_start=(starttime.hour()*60)+starttime.minute();
932
933 y_stop=(stoptime.hour()*60)+stoptime.minute();
934
935 if(y_stop<y_start){
936 y_stop+=60*24;
937 }
938
939 }
940
941 void EpgChannelStrip::drawStrip(int mx,int my){
942 QColor colorNow=QColor(255,255,160); //light yellow
943 QColor colorMouse=QColor(230,140,140); //brownish
944 QColor colorBlock=QColor(100,100,100); //dark grey
945 QColor colorHigh=QColor(220,170,230); // purple
946 QColor colorTimer=QColor(0,0,255); //blue
947 QColor colorNextRec=QColor(0,255,0); //green
948 QColor colorCurRec=QColor(255,0,0); //red
949
950 epgwin->calcStripSize();
951
952 int strip_x=epgwin->strip_x;
953 int strip_y=epgwin->strip_y;
954 int hours_after=epgwin->hours_after;
955 int hours_before=epgwin->hours_before;
956
957 int strip_y_before=epgwin->strip_y_before;
958 int strip_y_today=epgwin->strip_y_today;
959 int strip_y_after=epgwin->strip_y_after;
960 int strip_y_alldays=epgwin->strip_y_alldays;
961 int strip_y_size=epgwin->strip_y_size;
962 int y_subtract=epgwin->y_subtract;
963
964 if(my!=-1){
965 if(last_mouse_program){
966 if(last_mouse_program->y_start<=my && my<=last_mouse_program->y_stop-1){
967 // printf("returned early\n");
968 return;
969 }
970 }
971 }
972 QPainter paint(this);
973 paint.setWindow(0,0,strip_x,strip_y_alldays);
974 if(my==-1){
975 paint.eraseRect(0,-20,strip_x,strip_y_alldays);
976
977 paint.setPen(Qt::black);
978 //paint.drawText(0,20,chid->epgname);
979 paint.lineTo(0,0);
980 paint.lineTo(strip_x,strip_y_alldays);
981 paint.lineTo(0,strip_y_alldays);
982 paint.lineTo(strip_x,0);
983 }
984
985 EpgProgram *mouse_program=NULL;
986
987 int today=epgwin->current_date_item;
988 int yesterday=today-1;
989 int tomorrow=today+1;
990
991 int startday=yesterday;
992 int stopday=tomorrow;
993 if(hours_before>0){
994 startday=today;
995 }
996 if(hours_after<0){
997 stopday=today;
998 }
999 //printf("yesterday=%d today=%d tomorrow=%d\n",yesterday,today,tomorrow);
1000 //printf("hours_before=%d hours_after=%d\n",hours_before,hours_after);
1001 //printf("startday=%d stopday=%d\n",startday,stopday);
1002 //printf("strip_y_before=%d strip_y_today=%d strip_y_after=%d\n"
1003 // strip_y_before,strip_y_today,strip_y_after);
1004 //printf("strip_y_alldays=%d\n",strip_y_alldays);
1005
1006 for(int daynr=startday;daynr<=stopday;daynr++){
1007
1008 bool found_day=false;
1009 EpgDay *day=NULL;
1010 //printf("drawing strip %s for day %d\n",chid->epgname.latin1(),daynr);
1011 EpgDayListIterator id;
1012 for(id=epgwin->epglist.begin();!found_day && id!=epgwin->epglist.end();id++){
1013 day=*id;
1014 if(day->itemnr==daynr){
1015 found_day=true;
1016 }
1017 }
1018
1019 if(!found_day){
1020 printf("ERROR: day not found\n");
1021 return;
1022 }
1023
1024 bool found_channel=false;
1025 int row=0;
1026 printf("drawing day %s nr=%d channel %s\n",day->date.toString().latin1(),day->itemnr,chid->epgname.latin1());
1027
1028 EpgChannelListIterator ic;
1029 for(ic=day->channels.begin();!found_channel && ic!=day->channels.end();ic++){
1030 EpgChannel *ch=*ic;
1031 if(ch->chid==chid->epgid){
1032 found_channel=true;
1033 //printf("found my channel\n");
1034
1035 //paint.drawText(0,0,chid->epgname);
1036 //we iterate over programs
1037
1038 bool found_prog=false;
1039 EpgProgramListIterator ip;
1040 for(ip=ch->programs.begin();!found_prog && ip!=ch->programs.end();ip++){
1041 EpgProgram *prog=*ip;
1042
1043 QColor color=chid->color;
1044
1045 QTime starttime=prog->start.time();
1046 QTime stoptime=prog->stop.time();
1047 int y_start,y_stop;
1048
1049 calcYfromTime(y_start,y_stop,starttime,stoptime);
1050
1051 int drawit=false;
1052 if(daynr==yesterday && starttime.hour()>(24+hours_before)){
1053 y_start=y_start-(strip_y_default-strip_y_before);
1054 y_stop=y_stop-(strip_y_default-strip_y_before);
1055 drawit=true;
1056 }
1057 else if(daynr==tomorrow && starttime.hour()<hours_after){
1058 #if 0
1059 y_start=y_start+strip_y_before+strip_y_default;
1060 y_stop=y_stop+strip_y_before+strip_y_default;
1061 #endif
1062 y_start=y_start+strip_y_before+strip_y_today;
1063 y_stop=y_stop+strip_y_before+strip_y_today;
1064
1065 drawit=true;
1066 }
1067 else if(daynr==today){
1068 //today
1069
1070 y_start=y_start+strip_y_before-y_subtract;
1071 y_stop=y_stop+strip_y_before-y_subtract;
1072
1073 #if 1
1074 if((hours_before<=0 && hours_after>=0) || \
1075 (hours_before>0 && starttime.hour()>hours_before) ||
1076 (hours_after<0 && starttime.hour()>(24+hours_after))){
1077 drawit=true;
1078 }
1079 #endif
1080 drawit=true;
1081 }
1082
1083 if(drawit){
1084 //printf("start=%s (%d) stop=%s (%d)\n",starttime.toString().latin1(),y_start,stoptime.toString().latin1(),y_stop);
1085
1086 prog->y_start=y_start;
1087 prog->y_stop=y_stop;
1088
1089 int ydiff=y_stop-y_start;
1090 int y_currenttime=-1;
1091 QDateTime currentdatetime=QDateTime::currentDateTime();
1092 if(prog->start<currentdatetime && currentdatetime<prog->stop){
1093 color=colorNow;
1094 y_currenttime=strip_y_before+(currentdatetime.time().hour()*60)+currentdatetime.time().minute()-y_subtract;
1095 //printf("current prog %s yc=%d\n",prog->title.latin1(),y_currenttime);
1096 //printf("strip_y_before=%d y_subtract=%d\n",strip_y_before,y_subtract);
1097 }
1098
1099 QString startstr=starttime.toString(epg_timeformat);
1100 QString stopstr=stoptime.toString(epg_timeformat);
1101 QFont font;
1102 bool repaint_prog=false;
1103 if(prog==last_mouse_program){
1104 if(my!=-2 && (y_start<=my && my<=y_stop-1)){
1105 repaint_prog=false;
1106 }
1107 else{
1108 repaint_prog=true;
1109 }
1110 }
1111 if(my!=-2 && (y_start<=my && my<=y_stop-1) && prog!=last_mouse_program){
1112 printf("%s %d < %d < %d %s-%s\n",prog->title.latin1(),y_start,my,y_stop,startstr.latin1(),stopstr.latin1());
1113 QString datestr=prog->start.date().toString();
1114 QString fulltext=datestr+" / "+startstr+"-"+stopstr+" "+prog->title+prog->desc;
1115 epgwin->bottom_text->setText(fulltext);
1116 //color=color.dark(130);
1117 color=colorMouse;
1118 mouse_program=prog;
1119 repaint_prog=true;
1120 //found_prog=true;
1121 }
1122 if(my==-1 || repaint_prog){ //true){ //my==-1 || (y_start<my && my<y_stop)){
1123
1124 int bmode=regexp_unset;
1125 if(epgwin->regexp_dirty || prog->blockmode==regexp_unset){
1126 //printf("\nre-evaluating blockmode for %s\n",prog->title.latin1());
1127 bmode=blockMode(prog);
1128 }
1129 else{
1130 bmode=prog->blockmode;
1131 }
1132 //printf("bmode is %d\n",bmode);
1133 if(bmode==regexp_block){
1134 //block
1135 color=colorBlock;
1136 }
1137 else if(bmode==regexp_highlight){
1138 //highlight
1139 color=colorHigh;
1140 }
1141 prog->blockmode=bmode;
1142
1143 if(row==0){
1144 color=color.dark(110);
1145 row=1;
1146 }
1147 else{
1148 row=0;
1149 }
1150
1151
1152 TimerTableItem *titem=epgwin->timertable->firstTableItem();
1153 int by_start=y_start;
1154 int by_stop=y_stop;
1155 int by_diff=by_stop-by_start;
1156 QColor timercol=colorTimer;
1157 //const QBrush tbrush(timercol,Qt::BDiagPattern);
1158 QBrush tbrush(timercol,Qt::Dense6Pattern);
1159 QBrush pbrush(color,Qt::SolidPattern);
1160 QBrush xbrush;
1161 while(titem!=NULL){
1162 if((titem->getChannel()+1)==prog->channelnr){
1163 if(titem==epgwin->next_recording){
1164 xbrush=QBrush(colorNextRec,Qt::Dense5Pattern);
1165 }
1166 else if(titem==epgwin->current_recording){
1167 xbrush=QBrush(colorCurRec,Qt::Dense5Pattern);
1168 }
1169 else{
1170 xbrush=tbrush;
1171 }
1172 if(titem->getStopDateTime()>prog->start && titem->getStopDateTime()<prog->stop){
1173 //titem ends at the start of my block
1174 QDateTime tidatetime=titem->getStopDateTime();
1175 QDateTime mydatetime=prog->start;
1176
1177 int timediff_secs=mydatetime.secsTo(tidatetime);
1178 int timediff_mins=timediff_secs/60;
1179 #if 0
1180 QTime titime=titem->getStopDateTime().time();
1181
1182 int t_end=(titime.hour()*60)+titime.minute();
1183 if(t_end<y_start){
1184 t_end+=60*24;
1185 }
1186 #endif
1187 int t_end=y_start+timediff_mins;
1188
1189 paint.fillRect(0,y_start,strip_x,t_end-y_start,pbrush);
1190 paint.fillRect(0,y_start,strip_x,t_end-y_start,xbrush);
1191 by_start=t_end;
1192 //printf("%s ends at start of my block y_start=%d t_end=%d\n",prog->title.latin1(),y_start,t_end);
1193 }
1194 if(titem->getStartTime()>prog->start && titem->getStartTime()<prog->stop){
1195 //titem begins at the end of my block
1196 QDateTime tidatetime=titem->getStartTime();
1197 QDateTime mydatetime=prog->stop;
1198
1199 int timediff_mins=(tidatetime.secsTo(mydatetime)/60);
1200
1201 //printf("%s begins at end of my block\n",prog->title.latin1());
1202 #if 0
1203 QTime titime=titem->getStartTime().time();
1204 int t_begin=(titime.hour()*60)+titime.minute();
1205 #endif
1206 int t_begin=y_stop-timediff_mins;
1207
1208 paint.fillRect(0,t_begin,strip_x,y_stop-t_begin,pbrush);
1209 paint.fillRect(0,t_begin,strip_x,y_stop-t_begin,xbrush);
1210 by_stop=t_begin;
1211 }
1212 if(titem->getStartTime()<prog->start && titem->getStopDateTime()>prog->stop){
1213 //we are completely recorded
1214 paint.fillRect(0,by_start,strip_x,by_diff,pbrush);
1215 pbrush=xbrush;
1216 }
1217
1218 }
1219 titem=(TimerTableItem *)titem->nextSibling();
1220 }
1221
1222
1223
1224
1225 by_diff=by_stop-by_start;
1226 if(ydiff>=24){
1227 paint.fillRect(0,by_start,strip_x,by_diff,pbrush);
1228 font=QFont("Times",12);
1229 paint.setFont(font);
1230 paint.drawText(0,y_start+12,prog->title);
1231 paint.drawText(0,y_start+24,startstr+"-"+stopstr);
1232 }
1233 else if(ydiff>=10){
1234 paint.fillRect(0,by_start,strip_x,by_diff,pbrush);
1235 font=QFont("Times",10);
1236 paint.setFont(font);
1237 paint.drawText(0,y_start+10,prog->title);
1238 //paint.drawText(0,y_start+20,startstr+"-"+stopstr);
1239 }
1240 else if(ydiff>=5){
1241 paint.fillRect(0,by_start-2,strip_x,by_diff+2,pbrush);
1242 font=QFont("Times",10);
1243 paint.setFont(font);
1244 paint.drawText(0,y_start+5,prog->title);
1245 }
1246 else{
1247 //no text, too small
1248 }
1249 if(y_currenttime!=-1){
1250 QPen oldpen=paint.pen();
1251 QColor newcolor=color.light(110);
1252 paint.setPen(newcolor);
1253 paint.drawLine(0,y_currenttime,strip_x,y_currenttime);
1254 paint.setPen(oldpen);
1255 }
1256 }
1257 }//end if drawit
1258
1259 }//iter programs
1260 }//end we have found our channel
1261 }//iter channels
1262 }//end for day
1263
1264 if(mouse_program){
1265 last_mouse_program=mouse_program;
1266 }
1267
1268 paint.end();
1269 // epgwin->regexp_dirty=false;
1270 }
1271
1272 void EpgChannelStrip::resizeEvent(QResizeEvent *event){
1273 //printf("strip: resizeEvent()\n");
1274 //resize(strip_x,strip_y);
1275 // updateGeometry();
1276 // drawStrip(-1,-1);
1277 }
1278
1279 void EpgChannelStrip::paintEvent(QPaintEvent *event){
1280 //printf("strip: paintEvent()\n");
1281 //resize(strip_x,strip_y);
1282 //setFixedSize(strip_x,strip_y);
1283 //adjustSize();
1284 // epgwin->gridtable->adjustSize();
1285 drawStrip(-1,-1);
1286 }
1287
1288 void EpgChannelStrip::leaveEvent(QEvent *e){
1289 //printf("leaveevent\n");
1290 drawStrip(-1,-2);
1291 last_mouse_program=NULL;
1292 }
1293
1294 void EpgChannelStrip::mouseReleaseEvent(QMouseEvent *e){
1295 if(e->button()==Qt::MidButton){
1296 //printf("mid released while moving mouse\n");
1297 mid_move=false;
1298 }
1299 }
1300
1301 void EpgChannelStrip::mouseMoveEvent(QMouseEvent *e){
1302 // return;
1303 // printf("mousemove\n");
1304 drawStrip(-1,e->y());
1305 if(mid_move){
1306 int x=e->globalX();
1307 int y=e->globalY();
1308 int dx=x-mid_move_x;
1309 int dy=y-mid_move_y;
1310 // printf("mid pressed while moving mouse x=%d y=%d mx=%d my=%d dx=%d dy=%d\n",x,y,mid_move_x,mid_move_y,dx,dy);
1311 //epgwin->gridtable->scrollBy(dx,dy);
1312 //dx=(dx>=0)?1:-1;
1313 //dy=(dy>=0)?1:-1;
1314 epgwin->gridtable->scrollBy(-dx,-dy);
1315 mid_move_x=x;
1316 mid_move_y=y;
1317 }
1318 }
1319
1320 void EpgChannelStrip::addrecording(){
1321 if(popmenu && pop_program){
1322 epgwin->addRecording(pop_program);
1323 }
1324 }
1325
1326 void EpgChannelStrip::addblock(){
1327 if(popmenu && pop_program){
1328 epgwin->regexp_edit->append("title:block:^"+pop_program->title+"$");
1329 epgwin->okSettings();
1330 }
1331 }
1332 void EpgChannelStrip::addhighlight(){
1333 if(popmenu && pop_program){
1334 epgwin->regexp_edit->append("title:high:^"+pop_program->title+"$");
1335 epgwin->okSettings();
1336 }
1337 }
1338
1339 void EpgChannelStrip::mousePressEvent(QMouseEvent *e){
1340 if(e->button()==Qt::MidButton){
1341 //printf("midbutton press\n");
1342 mid_move=true;
1343 mid_move_x=e->globalX();
1344 mid_move_y=e->globalY();
1345 }
1346 else if(e->button()==Qt::RightButton){
1347
1348 if(popmenu){
1349 delete popmenu;
1350 popmenu=NULL;
1351 pop_program=NULL;
1352 }
1353
1354 if(last_mouse_program){
1355 pop_program=last_mouse_program;
1356 popmenu=new QPopupMenu();
1357
1358 QString startstr=last_mouse_program->start.time().toString(epg_timeformat);
1359 QString stopstr=last_mouse_program->stop.time().toString(epg_timeformat);
1360 QString header=startstr+"-"+stopstr+" "+last_mouse_program->title;
1361 popmenu->insertItem(header);
1362
1363 QString regstr="^"+last_mouse_program->title+"$";
1364
1365 popmenu->insertItem(tr("block title ")+regstr,this,SLOT(addblock()));
1366 popmenu->insertItem(tr("highlight title ")+regstr,this,SLOT(addhighlight()));
1367 popmenu->insertItem(tr("add to recordings"),this,SLOT(addrecording()));
1368
1369 popmenu->insertItem(tr("Description"));
1370 //popmenu->insertItem(last_mouse_program->desc);
1371
1372 popmenu->popup(mapToGlobal(e->pos()));
1373 }
1374
1375 }//rightbutton
1376 }
1377
1378
1379 void EpgWindow::makeConfigWidget(QWidget *parent){
1380 config_widget=new QVGroupBox("EPG Settings",parent);
1381 config_widget->setBaseSize(600,400);
1382 config_widget->setCaption("EPG Config");
1383
1384 QHBoxLayout *lay1=new QHBoxLayout(config_widget);
1385
1386 QLabel *l1=new QLabel(tr("EPG xml filename\nchanges take effect only after restart of avicap"),config_widget);
1387 lay1->addWidget(l1);
1388
1389 conf_dir_edit=new QLineEdit(config_widget);
1390 lay1->addWidget(conf_dir_edit);
1391
1392 conf_dir_edit->setText(RS("Epg-ProviderFilename","/tmp/epg.xml"));
1393
1394 QHBox *hbox_hours=new QHBox(config_widget);
1395
1396 hours_before_spinbox=new QSpinBox(-24,24,1,hbox_hours);
1397 hours_before_spinbox->setPrefix(tr("day starts at "));
1398 hours_before_spinbox->setSuffix(tr(" hours"));
1399 hours_before_spinbox->setValue(RI("EpgHoursBeforeDay",0));
1400
1401 hours_after_spinbox=new QSpinBox(-24,24,1,hbox_hours);
1402 hours_after_spinbox->setPrefix(tr("day ends at "));
1403 hours_after_spinbox->setSuffix(tr(" hours"));
1404 hours_after_spinbox->setValue(RI("EpgHoursAfterDay",0));
1405
1406 QHBox *hbox_mins=new QHBox(config_widget);
1407
1408 mins_before_spinbox=new QSpinBox(0,60,1,hbox_mins);
1409 mins_before_spinbox->setPrefix(tr("recording starts "));
1410 mins_before_spinbox->setSuffix(tr(" mins before program"));
1411 int minbefore=RI("EpgMinBeforeProgram",5);
1412 mins_before_spinbox->setValue(minbefore);
1413
1414
1415 mins_after_spinbox=new QSpinBox(0,60,1,hbox_mins);
1416 mins_after_spinbox->setPrefix(tr("recording ends "));
1417 mins_after_spinbox->setSuffix(tr(" mins after program"));
1418 mins_after_spinbox->setValue(RI("EpgMinAfterProgram",5));
1419
1420 QVBoxLayout *lay2=new QVBoxLayout(config_widget);
1421
1422 QVGroupBox *sbox=new QVGroupBox(tr("EPG Provider to Avicap channel mappings"),config_widget);
1423 conf_channel_scroll=new QScrollView(sbox);
1424 // lay2->addWidget(conf_channel_scroll);
1425
1426 //QHBoxLayout *lay20=new QHBoxLayout(conf_channel_scroll->viewport());
1427 conf_channel_view=new QVBox(conf_channel_scroll->viewport());
1428 conf_channel_scroll->addChild(conf_channel_view);
1429 //lay20->addWidget(conf_channel_view);
1430
1431 conf_channel_scroll->setResizePolicy(QScrollView::AutoOneFit);
1432 conf_channel_scroll->setVScrollBarMode(QScrollView::AlwaysOn);
1433 conf_channel_scroll->setHScrollBarMode(QScrollView::AlwaysOn);
1434 conf_channel_scroll->setBaseSize(400,300);
1435
1436 //conf_channel_lay=new QGridLayout(conf_channel_view,1,1);
1437 //conf_channel_lay->setSpacing(5);
1438 //conf_channel_lay->setMargin(5);
1439
1440 regexp_box=new QVGroupBox(tr("Edit Regexps"),0);
1441 regexp_box->setCaption(tr("EPG Edit Regexps"));
1442 regexp_box->setBaseSize(400,600);
1443 regexp_edit=new QTextEdit(regexp_box);
1444 #if QT_VERSION>=300
1445 regexp_edit->setTextFormat(Qt::PlainText);
1446 #endif
1447 regexp_edit->setReadOnly(false);
1448
1449 QHGroupBox *regexp_abox=new QHGroupBox(tr("actions"),regexp_box);
1450 reg_ok_button=new QPushButton(tr("Ok/Save"),regexp_abox);
1451 reg_reread_button=new QPushButton(tr("Re-read from file"),regexp_abox);
1452
1453 connect(reg_ok_button,SIGNAL(pressed()),this,SLOT(okSettings()));
1454 connect(reg_reread_button,SIGNAL(pressed()),this,SLOT(rereadRegexps()));
1455
1456
1457 QHGroupBox *bbox=new QHGroupBox(tr("actions"),config_widget);
1458
1459 ok_button=new QPushButton(tr("Ok/Save"),bbox);
1460 connect(ok_button,SIGNAL(pressed()),this,SLOT(okSettings()));
1461
1462 rereadRegexps();
1463 //okSettings();
1464
1465 }
1466
1467 void EpgWindow::colorSelector(){
1468 EpgChIdListIterator ic;
1469 int i=0;
1470 bool found_button=false;
1471 for(ic=epgChannels.begin();!found_button && ic!=epgChannels.end();ic++){
1472 EpgIdChannel *channelid=*ic;
1473 if(channelid->color_button->isDown()){
1474 found_button=true;
1475 //this button was pressed
1476 #if QT_VERSION>=300
1477 channelid->color=QColorDialog::getColor();
1478 //channelid->color_button->setPaletteForegroundColor(channelid->color);
1479 channelid->color_button->setPaletteBackgroundColor(channelid->color);
1480 #else
1481 channelid->color=QColorDialog::getColor(channelid->color);
1482 #endif
1483 channelid->color_button->setOn(false);
1484 channelid->color_button->setDown(false);
1485 }
1486 }
1487 }
1488
1489 void EpgWindow::rereadRegexps(){
1490
1491 struct passwd* pwent = getpwuid(getuid());
1492 QString homedir = pwent->pw_dir;
1493 QString filename=homedir+"/.avm/avicap-regexps";
1494
1495 QFile file(filename);
1496 bool ok=file.open(IO_ReadOnly);
1497 if(ok){
1498 QTextStream stream(&file);
1499 regexp_edit->setText(stream.read());
1500 file.close();
1501 }
1502 else{
1503 printf("cannot read regexp file\n");
1504 }
1505
1506 okSettings();
1507 }
1508
1509 void EpgWindow::okSettings(){
1510 EpgChIdListIterator ic;
1511 int i=0;
1512 WS("Epg-ProviderFilename",conf_dir_edit->text());
1513 for(ic=epgChannels.begin();ic!=epgChannels.end();ic++){
1514 EpgIdChannel *channelid=*ic;
1515
1516 int channelnum=channelid->conf_channel_box->currentItem();
1517 channelid->chnr=channelnum;
1518
1519 #define WS_CH(sub,str,count) { \
1520 WS(QString().sprintf("EpgChMap-%02d-%s",count,sub),str); \
1521 }
1522
1523 //WS_CH("EpgId",channelid->epgid,i);
1524 //WS_CH("Provider",provider,i);
1525 //WS_CH("ChannelNum",QString::number(channelnum),i);
1526 #if 0
1527 WI(QString().sprintf("Epg-%s-%s",provider.latin1(),channelid->epgid.latin1()),QString::number(channelnum));
1528 WS(QString().sprintf("Epg-%s-%s-Color",provider.latin1(),channelid->epgid.latin1()),channelid->color.name());
1529 #endif
1530 WI(QString().sprintf("Epg-%s-%s","Provider",channelid->epgid.latin1()),QString::number(channelnum));
1531 WS(QString().sprintf("Epg-%s-%s-Color","Provider",channelid->epgid.latin1()),channelid->color.name());
1532
1533
1534 i++;
1535 }
1536
1537 WI("EpgHoursBeforeDay",hours_before_spinbox->value());
1538 WI("EpgHoursAfterDay",hours_after_spinbox->value());
1539
1540 WI("EpgMinBeforeProgram",mins_before_spinbox->value());
1541 WI("EpgMinAfterProgram",mins_after_spinbox->value());
1542
1543 //write regexps to plain file
1544 struct passwd* pwent = getpwuid(getuid());
1545 QString homedir = pwent->pw_dir;
1546 QString filename=homedir+"/.avm/avicap-regexps";
1547
1548 QFile file(filename);
1549 bool ok=file.open(IO_WriteOnly);
1550 if(ok){
1551 QTextStream stream(&file);
1552 stream << regexp_edit->text();
1553 file.close();
1554 }
1555 else{
1556 printf("cannot write regexp file\n");
1557 }
1558
1559
1560 QStringList strlist=QStringList::split("\n",regexp_edit->text(),false);
1561 #if 0
1562 //delete old regexps
1563 for(uint k=0;k<regexpList.count();k++){
1564 EpgRegexp *epgreg=regexpList.last();
1565 delete epgreg;
1566 regexpList.pop_back();
1567 }
1568 #endif
1569
1570 while(regexpList.count()>0){
1571 QValueListIterator<EpgRegexp *> it;
1572 it=regexpList.begin();
1573 regexpList.remove(it);
1574 }
1575 //create new regexps
1576 int j=0;
1577 for (QStringList::Iterator it=strlist.begin(); it != strlist.end();it++ ) {
1578 QString str=*it;
1579 //printf("+%s+\n",str.latin1());
1580 //WS(QString().sprintf("Epg-Regexp-%02d",j),str);
1581
1582 EpgRegexp *epgreg=new EpgRegexp();
1583
1584
1585 QString regexp0=str;
1586
1587 if(regexp0[0]!='#'){
1588 QString regexp;
1589 int mode=regexp_errorwhere;;
1590 if(regexp0.left(both_string.length())==both_string){
1591 mode=regexp_both;
1592 regexp=regexp0.right(regexp0.length()-both_string.length());
1593 //printf("both!\n");
1594 }
1595 else if(regexp0.left(title_string.length())==title_string){
1596 mode=regexp_title;
1597 regexp=regexp0.right(regexp0.length()-title_string.length());
1598 }
1599 else if(regexp0.left(desc_string.length())==desc_string){
1600 mode=regexp_desc;
1601 regexp=regexp0.right(regexp0.length()-desc_string.length());
1602 }
1603 else{
1604 printf("error in regexp: %s\n",regexp0.latin1());
1605 mode=regexp_errorwhere;
1606 }
1607 int bmode=regexp_block;
1608
1609 if(regexp.left(block_string.length())==block_string){
1610 //printf("checking block for %s\n",regexp.latin1());
1611 epgreg->regstr=regexp.right(regexp.length()-block_string.length());
1612 //printf("regexp is +%s+\n",reg.latin1());
1613
1614 bmode=regexp_block;
1615 }
1616 else if(regexp.left(high_string.length())==high_string){
1617 //printf("checking high for %s\n",regexp.latin1());
1618 epgreg->regstr=regexp.right(regexp.length()-high_string.length());
1619 //printf("regexp is +%s+\n",reg.latin1());
1620
1621 bmode=regexp_highlight;
1622 }
1623 else{
1624 printf("error in regexp: %s\n",regexp.latin1());
1625 bmode=regexp_errorblock;
1626 }
1627 epgreg->regexp=QRegExp(epgreg->regstr,false,false);
1628 epgreg->wheremode=mode;
1629 epgreg->blockmode=bmode;
1630
1631 regexpList.append(epgreg);
1632 }
1633 j++;
1634 }
1635
1636 // WS(QString().sprintf("Epg-Regexp-%02d",j),"NONE");
1637
1638 avm::RegSave();
1639
1640 regexp_dirty=true;
1641
1642 day_selected(current_date_item);
1643
1644 // WS_CH("EpgId","NONE",i);
1645 }
1646
1647
1648 #include "epgwindow.moc"
1649
1650 #else
1651 #warning "no epgwindow"
1652 #endif