All pastes #455920 Raw Edit

kevents.diff

public cpp v1 · immutable
#455920 ·published 2007-04-24 15:19 UTC
rendered paste body
Index: kevents.h===================================================================--- kevents.h	(revision 657539)+++ kevents.h	(working copy)@@ -33,6 +33,7 @@ class DvbStream; class DVBevents; class ChannelDesc;+class QCheckBox;   @@ -41,10 +42,11 @@  public: -	EListViewItem( QListView *parent, QString chanName, QString eBegin, QString eDuration, QString eTitle, EventDesc *desc );+	EListViewItem( QListView *parent, QString chanName, QString eBegin, QString eDuration, QString eTitle, EventDesc *desc, QString follow_begin ); 	virtual int compare( QListViewItem *i, int col, bool ascending ) const;  	EventDesc *event;+	QString followBegin; };  @@ -61,24 +63,31 @@ private slots:  	void checkNewEvent();+	void checkEpgSearch(QString searchword); 	void mouseClickedSlot( int btn, QListViewItem *it, const QPoint &p, int c ); 	void reset(); 	void setMode( int m, QString name="" ); 	void setScheduled(); 	void setCurrentNext(); 	void setCurrentChannelEpg();+	void epgSearch(); 	void zap( QListViewItem* it, const QPoint &p, int col );  private:  	QPtrList<DvbStream> *dvb; 	KListView *listView;-	KPushButton *resetBtn, *currentNextBtn, *allBtn, *currentChannelEpg;+	KPushButton *resetBtn, *currentNextBtn, *allBtn, *currentChannelEpgBtn, *searchBtn;+	QCheckBox *titleCb; 	QPtrList<ChannelDesc> *channels; 	QTextBrowser *textBrow; 	int mode; 	ChannelDesc *chan; +protected:++	QLineEdit *searchLineEdit;+ signals:  	void addTimer( QString channel, QString name, QDateTime begin, QTime duration );Index: kevents.cpp===================================================================--- kevents.cpp	(revision 657539)+++ kevents.cpp	(working copy)@@ -24,6 +24,7 @@ #include <qpopupmenu.h> #include <qcursor.h> #include <qwhatsthis.h>+#include <qcheckbox.h>  #include <klocale.h> #include <kiconloader.h>@@ -33,11 +34,13 @@ #include "dvbevents.h" #include "dvbstream.h" +#define MAX_FOLLOW 10  -EListViewItem::EListViewItem( QListView *parent, QString chanName, QString eBegin, QString eDuration, QString eTitle, EventDesc *desc ) : KListViewItem( parent, chanName, eBegin, eDuration, eTitle )+EListViewItem::EListViewItem( QListView *parent, QString chanName, QString eBegin, QString eDuration, QString eTitle, EventDesc *desc, QString follow_begin) : KListViewItem( parent, chanName, eBegin, eDuration, eTitle, follow_begin) { 	event = desc;+	followBegin=follow_begin; }  @@ -74,8 +77,15 @@ 	hbox->addWidget( allBtn ); 	currentNextBtn = new KPushButton( i18n("Current/Next"), this ); 	hbox->addWidget( currentNextBtn );-	currentChannelEpg = new KPushButton( i18n("Current Channel"), this );-	hbox->addWidget( currentChannelEpg );+	currentChannelEpgBtn = new KPushButton( i18n("Current Channel"), this );+	hbox->addWidget( currentChannelEpgBtn );+	searchLineEdit = new QLineEdit(this);+	hbox->addWidget( searchLineEdit );+	titleCb  = new QCheckBox(i18n("only Title"), this );+	titleCb->setChecked(true);+	hbox->addWidget( titleCb);+	searchBtn = new KPushButton( i18n("Search"), this );+	hbox->addWidget( searchBtn );  	QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); 	hbox->addItem( spacer );@@ -100,14 +110,17 @@ 	resetBtn->setGuiItem( KGuiItem(i18n("Refresh"), icon->loadIconSet("reload", KIcon::Small) ) ); 	allBtn->setGuiItem( KGuiItem(i18n("Scheduled"), icon->loadIconSet("date", KIcon::Small) ) ); 	currentNextBtn->setGuiItem( KGuiItem(i18n("Current/Next"), icon->loadIconSet("toggle_log", KIcon::Small) ) );-	currentChannelEpg->setGuiItem( KGuiItem(i18n("Current Channel"), icon->loadIconSet("date", KIcon::Small) ) );-	new EListViewItem( (QListView*)listView, "Une chaine", "99/99/99  99:99 9999", "99:99 99", "un titre de programme", 0 );+	currentChannelEpgBtn->setGuiItem( KGuiItem(i18n("Current Channel"), icon->loadIconSet("date", KIcon::Small) ) );+	searchBtn->setGuiItem( KGuiItem(i18n("EPG-Search"), icon->loadIconSet("find", KIcon::Small) ) );+	new EListViewItem( (QListView*)listView, "Une chaine", "99/99/99  99:99 9999", "99:99 99", "un titre de programme", 0,0 );  	resize( size ); 	connect( resetBtn			, SIGNAL( clicked() ), this, SLOT( reset() ) ); 	connect( allBtn				, SIGNAL( clicked() ), this, SLOT( setScheduled() ) ); 	connect( currentNextBtn		, SIGNAL( clicked() ), this, SLOT( setCurrentNext() ) );-	connect( currentChannelEpg	, SIGNAL( clicked() ), this, SLOT( setCurrentChannelEpg() ) );+	connect( currentChannelEpgBtn, SIGNAL( clicked() ), this, SLOT( setCurrentChannelEpg() ) );+	connect( searchBtn			, SIGNAL( clicked() ), this, SLOT( epgSearch() ) );+ 	connect( listView, SIGNAL( mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), 		this, SLOT(mouseClickedSlot(int,QListViewItem*,const QPoint&,int)) ); 	connect( listView, SIGNAL(doubleClicked(QListViewItem*,const QPoint &,int)),@@ -117,6 +130,113 @@         delete icon; } +void KEvents::checkEpgSearch(QString searchword)+{+	int i, j, k, m, n,l,follow=0;+	DVBevents *events=0;+	EventSourceList *slist;+	EventTsidList *tlist;+	EListViewItem *itt=0;++	QString s, channel, begin, duration, title, follow_begin;+	bool found;+	EventDesc *desc,*desctmp;+	QPixmap pix;+	for( k=0; k<(int)dvb->count(); k++ ) {+		events = dvb->at(k)->dvbEvents;+		events->mutex.lock();+		for ( m=0; m<(int)events->srcList.count(); m++ ) {+			slist = events->srcList.at(m);+			for ( n=0; n<(int)slist->tsidList.count(); n++ ) {+				tlist = slist->tsidList.at(n);+				for ( j=0; j<(int)tlist->events.count(); j++ ) {+					desc = tlist->events.at(j);++					if ( desc->title.isEmpty() )+						continue;++					for ( i=0; i<(int)channels->count(); i++ ) {+						if ( desc->source==channels->at(i)->tp.source && desc->sid==channels->at(i)->sid && desc->tsid==channels->at(i)->tp.tsid ) {+							channel = channels->at(i)->name;++						found=false;+						if(desc->title.upper().find(searchword.upper())!=-1)+							found=true;+						if(!titleCb->isChecked()) {+							if(!found) {+								for ( l=0; l<(int)desc->extEvents.count(); l++ ) {+									s = *desc->extEvents.at(l);+									if(!s.isEmpty()) {+										if(s.upper().find(searchword.upper())!=-1) {+											found=true;+											s="";+											break;+										}+									}+								}+							}+							if(!found) {+								for ( l=0; l<(int)desc->shortEvents.count(); l++ ) {+									s = s + desc->shortEvents.at(l)->name;+									s += s + desc->shortEvents.at(l)->text;+									if(!s.isEmpty()) {+										if(s.upper().find(searchword.upper())!=-1) {+											found=true;+											s="";+											break;+										}+									}+								}+							}+						}+						if(!found)+							continue;++						pix = channels->at(i)->pix;+						begin = KGlobal::locale()->formatDateTime( desc->startDateTime );+						duration = desc->duration.toString("hh:mm");+						title = desc->title;++						for (int x=0; x<(int)tlist->events.count() && follow < MAX_FOLLOW; x++ ) {+							desctmp = tlist->events.at(x);+							if ( !desc->title.isEmpty() && !desctmp->title.isEmpty()) {+								if (desc->title==desctmp->title && desctmp->startDateTime > desc->startDateTime) {+									for (int y=0; y<(int)channels->count(); y++ ) {+										if ( desctmp->source==channels->at(y)->tp.source && desctmp->sid==channels->at(y)->sid && desctmp->tsid==channels->at(y)->tp.tsid ) {+	 										follow_begin+=channels->at(y)->name;+											follow_begin+=": ";+											break;+										}+									}+									follow_begin+=KGlobal::locale()->formatDateTime( desctmp->startDateTime, true );+									follow_begin+="#";+									follow++;+								}+							}+						}+						itt = new EListViewItem( (QListView*)listView, channel, begin, duration, title, desc, follow_begin );++						follow_begin="";+						follow=0;+						if ( !pix.isNull() )+							itt->setPixmap( 0, pix );+						}+					}+				}+			}+		}+		events->mutex.unlock();+	}+}++void KEvents::epgSearch()+{+    QString text = searchLineEdit->text();+    if (text.stripWhiteSpace().isEmpty()) return;+ 	listView->clear();+	checkEpgSearch(text);+}+ void KEvents::setCurrentChannelEpg() { 	ChannelDesc curchan;@@ -206,6 +326,18 @@ 			for ( i=0; i<(int)ei->event->extEvents.count(); i++ ) { 				s = s+ *ei->event->extEvents.at(i); 			}+			if(!ei->followBegin.isEmpty()) {+				int pos2=0,pos=0;+				s = s+ "<br>";+				for(int i=0;i<MAX_FOLLOW;i++) {+					pos=ei->followBegin.find("#",pos2);+					if(pos==-1)+						break;+					s = s+"<br><font color=\"blue\">";+					s=s+ei->followBegin.mid(pos2,pos-pos2);+					pos2=pos+1;+				}+			} 			s = s+"</qt>"; 			textBrow->setText( s ); 			break;@@ -264,17 +396,16 @@ }  - void KEvents::checkNewEvent() {-	int i, j, k, m, n;+	int i, j, k, m, n,follow=0; 	DVBevents *events=0; 	EventSourceList *slist; 	EventTsidList *tlist; 	EListViewItem *itt=0;-	QString s, t, channel, begin, duration, title;+	QString s, channel, begin, duration, title, follow_begin; 	bool ret;-	EventDesc *desc;+	EventDesc *desc,*desctmp; 	QPixmap pix; 	QValueList<int> sids; @@ -288,6 +419,8 @@ 				sids.clear(); 				for ( j=0; j<(int)tlist->events.count(); j++ ) { 					desc = tlist->events.at(j);+					if ( desc->title.isEmpty() )+						continue; 					//if ( mode==1 && desc->tid>0x4f ) 					if ( sids.contains( desc->sid ) ) 						continue;@@ -299,6 +432,7 @@ 							continue; 						channel = chan->name; 						pix = chan->pix;+ 					} 					else { 						ret = true;@@ -317,9 +451,30 @@ 					begin = KGlobal::locale()->formatDateTime( desc->startDateTime ); 					duration = desc->duration.toString("hh:mm"); 					title = desc->title;-					if ( title.isEmpty() )-						continue;-					itt = new EListViewItem( (QListView*)listView, channel, begin, duration, title, desc );++					for (int x=0; x<(int)tlist->events.count() && follow < MAX_FOLLOW; x++ ) {+						desctmp = tlist->events.at(x);+						if ( !desc->title.isEmpty() && !desctmp->title.isEmpty()) {+							if (desc->title==desctmp->title && desctmp->startDateTime > desc->startDateTime) {+								for (int y=0; y<(int)channels->count(); y++ ) {+									if ( desctmp->source==channels->at(y)->tp.source && desctmp->sid==channels->at(y)->sid && desctmp->tsid==channels->at(y)->tp.tsid ) {+	 									follow_begin+=channels->at(y)->name;+										follow_begin+=": ";+										break;+									}+								}+								follow_begin+=KGlobal::locale()->formatDateTime( desctmp->startDateTime, true );+								follow_begin+="#";+								follow++;+							}+						}+					}++					itt = new EListViewItem( (QListView*)listView, channel, begin, duration, title, desc, follow_begin );++					follow_begin="";+					follow=0;+ 					if ( !pix.isNull() ) 						itt->setPixmap( 0, pix ); 				}