~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/gui/qt4/components/epg/EPGWidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * EPGWidget.h : EPGWidget
 
3
 ****************************************************************************
 
4
 * Copyright © 2009-2010 VideoLAN
 
5
 * $Id: b614846a2a55ccc57f7e13aa1444b8184428425a $
 
6
 *
 
7
 * Authors: Ludovic Fauvet <etix@l0cal.com>
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
21
 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 
22
 *****************************************************************************/
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
# include <config.h>
 
26
#endif
 
27
 
 
28
#include "EPGWidget.hpp"
 
29
 
 
30
#include <QVBoxLayout>
 
31
#include <QScrollBar>
 
32
#include <QDebug>
 
33
#include <QLabel>
 
34
#include "qt4.hpp"
 
35
 
 
36
EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
 
37
{
 
38
    m_rulerWidget = new EPGRuler( this );
 
39
    m_epgView = new EPGView( this );
 
40
    m_channelsWidget = new EPGChannels( this, m_epgView );
 
41
 
 
42
    m_channelsWidget->setMinimumWidth( 100 );
 
43
 
 
44
    m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
 
45
    setZoom( 1 );
 
46
 
 
47
    QGridLayout* layout = new QGridLayout( this );
 
48
    layout->addWidget( m_rulerWidget, 0, 1 );
 
49
    layout->addWidget( m_channelsWidget, 1, 0 );
 
50
    layout->addWidget( m_epgView, 1, 1 );
 
51
    layout->setSpacing( 0 );
 
52
    setLayout( layout );
 
53
 
 
54
    connect( m_epgView, SIGNAL( startTimeChanged(QDateTime) ),
 
55
             m_rulerWidget, SLOT( setStartTime(QDateTime) ) );
 
56
    connect( m_epgView, SIGNAL( durationChanged(int) ),
 
57
             m_rulerWidget, SLOT( setDuration(int) ) );
 
58
    connect( m_epgView->horizontalScrollBar(), SIGNAL( valueChanged(int) ),
 
59
             m_rulerWidget, SLOT( setOffset(int) ) );
 
60
    connect( m_epgView->verticalScrollBar(), SIGNAL( valueChanged(int) ),
 
61
             m_channelsWidget, SLOT( setOffset(int) ) );
 
62
    connect( m_epgView, SIGNAL( eventFocusedChanged(EPGEvent*)),
 
63
             this, SIGNAL(itemSelectionChanged(EPGEvent*)) );
 
64
}
 
65
 
 
66
void EPGWidget::setZoom( int level )
 
67
{
 
68
    double scale = (double)level / 20;
 
69
    m_epgView->setScale( scale );
 
70
    m_rulerWidget->setScale( scale );
 
71
}
 
72
 
 
73
void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
 
74
{
 
75
    for ( int i = 0; i < i_epg; ++i )
 
76
    {
 
77
        vlc_epg_t *p_epg = pp_epg[i];
 
78
        QString channelName = qfu( p_epg->psz_name );
 
79
 
 
80
        for ( int j = 0; j < p_epg->i_event; ++j )
 
81
        {
 
82
            vlc_epg_event_t *p_event = p_epg->pp_event[j];
 
83
            QString eventName = qfu( p_event->psz_name );
 
84
            QDateTime eventStart = QDateTime::fromTime_t( p_event->i_start );
 
85
 
 
86
            QList<EPGEvent*> events = m_events.values( channelName );
 
87
 
 
88
            EPGEvent *item = new EPGEvent( eventName );
 
89
            item->description = qfu( p_event->psz_description );
 
90
            item->shortDescription = qfu( p_event->psz_short_description );
 
91
            item->start = eventStart;
 
92
            item->duration = p_event->i_duration;
 
93
            item->channelName = channelName;
 
94
            item->current = ( p_epg->p_current == p_event ) ? true : false;
 
95
 
 
96
            bool alreadyIn = false;
 
97
 
 
98
            for ( int k = 0; k < events.count(); ++k )
 
99
            {
 
100
                if ( *events.at( k ) == *item )
 
101
                {
 
102
                    alreadyIn = true;
 
103
                    events.at( k )->updated = true;
 
104
                    break;
 
105
                }
 
106
            }
 
107
 
 
108
            if ( !alreadyIn )
 
109
            {
 
110
                m_events.insert( channelName, item );
 
111
                if ( item->start < m_epgView->startTime() )
 
112
                    m_epgView->setStartTime( item->start );
 
113
 
 
114
                m_epgView->addEvent( item );
 
115
            }
 
116
            else
 
117
                delete item;
 
118
        }
 
119
    }
 
120
 
 
121
    // Remove old items
 
122
    QMap<QString, EPGEvent*>::iterator i = m_events.begin();
 
123
    while ( i != m_events.end() )
 
124
    {
 
125
        EPGEvent* item = i.value();
 
126
        if ( !item->updated )
 
127
        {
 
128
            m_epgView->delEvent( item );
 
129
            delete item;
 
130
            i = m_events.erase( i );
 
131
        }
 
132
        else
 
133
            item->updated = false;
 
134
 
 
135
        ++i;
 
136
    }
 
137
 
 
138
    // Update the global duration
 
139
    m_epgView->updateDuration();
 
140
}
 
141