]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
Icons
[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
41     slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
42     QVBoxLayout *box_layout = new QVBoxLayout();
43     box_layout->addWidget( slider );
44     ui.sliderBox->setLayout( box_layout );
45     ui.prevButton->setIcon( QIcon( ":/pixmaps/previous.png" ) );
46     ui.nextButton->setIcon( QIcon( ":/pixmaps/next.png" ) );
47     ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
48     ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
49     ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
50     ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
51
52     resize( QSize( 450, 80 ) );
53
54     //QVLCMenu::createMenuBar();
55
56     /* Init input manager */
57     MainInputManager::getInstance( p_intf );
58
59     /* Get timer updates */
60     connect( DialogsProvider::getInstance(NULL)->fixed_timer,
61              SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
62
63     /* Connect the input manager to the GUI elements it manages */
64     connect( MainInputManager::getInstance( p_intf )->getIM(),
65              SIGNAL(positionUpdated( float, int, int ) ),
66              slider, SLOT( setPosition( float,int, int ) ) );
67     connect( slider, SIGNAL( sliderDragged( float ) ),
68              MainInputManager::getInstance( p_intf )->getIM(),
69              SLOT( sliderUpdate( float ) ) );
70     connect( MainInputManager::getInstance( p_intf )->getIM(),
71              SIGNAL( positionUpdated( float, int, int ) ),
72              this, SLOT( setDisplay( float, int, int ) ) );
73
74     /* Actions */
75     connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
76     connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
77     connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
78     connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
79
80     connect( ui.playlistButton, SLOT(clicked() ), 
81              DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
82 }
83
84 MainInterface::~MainInterface()
85 {
86 }
87
88 void MainInterface::stop()
89 {
90     /// \todo store playlist globally
91     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
92                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
93     if( !p_playlist ) return;
94     playlist_Stop( p_playlist );
95     vlc_object_release( p_playlist );
96 }
97 void MainInterface::play()
98 {
99     /// \todo store playlist globally
100     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
101                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
102     if( !p_playlist ) return;
103     playlist_Play( p_playlist );
104     vlc_object_release( p_playlist );
105 }
106 void MainInterface::prev()
107 {
108     /// \todo store playlist globally
109     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
110                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
111     if( !p_playlist ) return;
112     playlist_Prev( p_playlist );
113     vlc_object_release( p_playlist );
114 }
115 void MainInterface::next()
116 {
117     /// \todo store playlist globally
118     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
119                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
120     if( !p_playlist ) return;
121     playlist_Next( p_playlist );
122     vlc_object_release( p_playlist );
123 }
124
125
126
127
128
129
130 void MainInterface::setDisplay( float pos, int time, int length )
131 {
132     char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
133     secstotimestr( psz_length, length );
134     secstotimestr( psz_time, time );
135     QString title;
136     title.sprintf( "%s/%s", psz_time, psz_length );
137     ui.sliderBox->setTitle( title );
138 }
139
140 void MainInterface::updateOnTimer()
141 {
142     if( p_intf->b_die )
143     {
144         QApplication::quit();
145     }
146 }
147
148 void MainInterface::closeEvent( QCloseEvent *e )
149 {
150     hide();
151     p_intf->b_die = VLC_TRUE;
152 }