]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
8d397996c23e5c796f261310d0c18dcf78b883ef
[vlc] / modules / gui / qt4 / main_interface.cpp
1 /*****************************************************************************
2  * main_inteface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
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
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
22
23 #include "main_interface.hpp"
24 #include "input_manager.hpp"
25 #include "util/input_slider.hpp"
26 #include "util/qvlcframe.hpp"
27 #include "dialogs_provider.hpp"
28 #include <QCloseEvent>
29 #include <assert.h>
30 #include <QPushButton>
31
32 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QMainWindow(), p_intf( _p_intf )
33 {
34     /* All UI stuff */
35     QVLCFrame::fixStyle( this );
36     QWidget *main = new QWidget( this );
37     setCentralWidget( main );
38     setWindowTitle( _("VLC media player") );
39     ui.setupUi( centralWidget() );
40     slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
41     QVBoxLayout *box_layout = new QVBoxLayout();
42     box_layout->addWidget( slider );
43     ui.sliderBox->setLayout( box_layout );
44     resize( QSize( 450, 80 ) );
45
46     /* Init input manager */
47     MainInputManager::getInstance( p_intf );
48
49     /* Get timer updates */
50     connect( DialogsProvider::getInstance(NULL)->fixed_timer,
51              SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
52
53     /* Connect the input manager to the GUI elements it manages */
54     connect( MainInputManager::getInstance( p_intf )->getIM(),
55              SIGNAL(positionUpdated( float, int, int ) ),
56              slider, SLOT( setPosition( float,int, int ) ) );
57     connect( slider, SIGNAL( sliderDragged( float ) ),
58              MainInputManager::getInstance( p_intf )->getIM(),
59              SLOT( sliderUpdate( float ) ) );
60     connect( MainInputManager::getInstance( p_intf )->getIM(),
61              SIGNAL( positionUpdated( float, int, int ) ),
62              this, SLOT( setDisplay( float, int, int ) ) );
63
64     /* Actions */
65     connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
66     connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
67     connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
68     connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
69
70     connect( ui.playlistButton, SLOT(clicked() ), 
71              DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
72 }
73
74 MainInterface::~MainInterface()
75 {
76 }
77
78 void MainInterface::stop()
79 {
80     /// \todo store playlist globally
81     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
82                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
83     if( !p_playlist ) return;
84     playlist_Stop( p_playlist );
85     vlc_object_release( p_playlist );
86 }
87 void MainInterface::play()
88 {
89     /// \todo store playlist globally
90     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
91                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
92     if( !p_playlist ) return;
93     playlist_Play( p_playlist );
94     vlc_object_release( p_playlist );
95 }
96 void MainInterface::prev()
97 {
98     /// \todo store playlist globally
99     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
100                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
101     if( !p_playlist ) return;
102     playlist_Prev( p_playlist );
103     vlc_object_release( p_playlist );
104 }
105 void MainInterface::next()
106 {
107     /// \todo store playlist globally
108     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
109                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
110     if( !p_playlist ) return;
111     playlist_Next( p_playlist );
112     vlc_object_release( p_playlist );
113 }
114
115
116
117
118
119
120 void MainInterface::setDisplay( float pos, int time, int length )
121 {
122     char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
123     secstotimestr( psz_length, length );
124     secstotimestr( psz_time, time );
125     QString title;
126     title.sprintf( "%s/%s", psz_time, psz_length );
127     ui.sliderBox->setTitle( title );
128 }
129
130 void MainInterface::updateOnTimer()
131 {
132     if( p_intf->b_die )
133     {
134         QApplication::quit();
135     }
136 }
137
138 void MainInterface::closeEvent( QCloseEvent *e )
139 {
140     hide();
141     p_intf->b_die = VLC_TRUE;
142 }