/*****************************************************************************
- * Epg.cpp : Epg Viewer dialog
+ * epg.cpp : Epg Viewer dialog
****************************************************************************
* Copyright © 2010 VideoLAN and AUTHORS
*
#include "dialogs/epg.hpp"
#include "components/epg/EPGWidget.hpp"
+#include <vlc_playlist.h>
#include <QVBoxLayout>
#include <QSplitter>
#include <QLabel>
#include <QGroupBox>
#include <QPushButton>
+#include <QTextEdit>
+#include <QDialogButtonBox>
+#include <QTimer>
+
+#include "qt4.hpp"
+#include "input_manager.hpp"
EpgDialog::EpgDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
{
- setWindowTitle( "Program Guide" );
+ setWindowTitle( qtr( "Program Guide" ) );
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 0 );
- QSplitter *splitter = new QSplitter( this );
- EPGWidget *epg = new EPGWidget( this );
- splitter->addWidget( epg );
- splitter->setOrientation(Qt::Vertical);
+ epg = new EPGWidget( this );
QGroupBox *descBox = new QGroupBox( qtr( "Description" ), this );
QVBoxLayout *boxLayout = new QVBoxLayout( descBox );
- description = new QLabel( this );
+ description = new QTextEdit( this );
+ description->setReadOnly( true );
description->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel );
description->setAutoFillBackground( true );
+ description->setAlignment( Qt::AlignLeft | Qt::AlignTop );
+ description->setFixedHeight( 100 );
QPalette palette;
palette.setBrush(QPalette::Active, QPalette::Window, palette.brush( QPalette::Base ) );
description->setPalette( palette );
title = new QLabel( qtr( "Title" ), this );
+ title->setWordWrap( true );
boxLayout->addWidget( title );
- boxLayout->addWidget( description, 10 );
+ boxLayout->addWidget( description );
+
+ layout->addWidget( epg, 10 );
+ layout->addWidget( descBox );
+
+ CONNECT( epg, itemSelectionChanged( EPGItem *), this, displayEvent( EPGItem *) );
+ CONNECT( THEMIM->getIM(), epgChanged(), this, updateInfos() );
+ CONNECT( THEMIM, inputChanged( input_thread_t * ), this, updateInfos() );
+
+ QDialogButtonBox *buttonsBox = new QDialogButtonBox( this );
- splitter->addWidget( epg );
- splitter->addWidget( descBox );
- layout->addWidget( splitter );
+#if 0
+ QPushButton *update = new QPushButton( qtr( "Update" ) ); // Temporary to test
+ buttonsBox->addButton( update, QDialogButtonBox::ActionRole );
+ BUTTONACT( update, updateInfos() );
+#endif
- CONNECT( epg, itemSelectionChanged( EPGEvent *), this, showEvent( EPGEvent *) );
+ buttonsBox->addButton( new QPushButton( qtr( "&Close" ) ),
+ QDialogButtonBox::RejectRole );
+ boxLayout->addWidget( buttonsBox );
+ CONNECT( buttonsBox, rejected(), this, close() );
- QPushButton *close = new QPushButton( qtr( "&Close" ) );
- layout->addWidget( close, 0, Qt::AlignRight );
- BUTTONACT( close, close() );
+ timer = new QTimer( this );
+ timer->setSingleShot( true );
+ timer->setInterval( 1000 * 60 );
+ CONNECT( timer, timeout(), this, updateInfos() );
- resize( 650, 400 );
+ updateInfos();
+ restoreWidgetPosition( "EPGDialog", QSize( 650, 450 ) );
}
EpgDialog::~EpgDialog()
{
+ saveWidgetPosition( "EPGDialog" );
}
-void EpgDialog::showEvent( EPGEvent *event )
+void EpgDialog::displayEvent( EPGItem *epgItem )
{
- if( !event ) return;
-
- title->setText( event->name );
- description->setText( event->description );
+ if( !epgItem ) return;
+
+ QDateTime end = epgItem->start().addSecs( epgItem->duration() );
+ title->setText( QString("%1 - %2 : %3")
+ .arg( epgItem->start().toString( "hh:mm" ) )
+ .arg( end.toString( "hh:mm" ) )
+ .arg( epgItem->name() )
+ );
+ description->setText( epgItem->description() );
}
+void EpgDialog::updateInfos()
+{
+ timer->stop();
+ input_item_t *p_input_item = NULL;
+ playlist_t *p_playlist = THEPL;
+ input_thread_t *p_input_thread = playlist_CurrentInput( p_playlist ); /* w/hold */
+ if( p_input_thread )
+ {
+ PL_LOCK; /* as input_GetItem still unfixed */
+ p_input_item = input_GetItem( p_input_thread );
+ if ( p_input_item ) vlc_gc_incref( p_input_item );
+ PL_UNLOCK;
+ vlc_object_release( p_input_thread );
+ if ( p_input_item )
+ {
+ epg->updateEPG( p_input_item );
+ vlc_gc_decref( p_input_item );
+ if ( isVisible() ) timer->start();
+ }
+ }
+}