]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/gototime.cpp
qt4 - Copyright, CRs and unwanted commits.
[vlc] / modules / gui / qt4 / dialogs / gototime.cpp
1 /*****************************************************************************
2  * GotoTime.cpp : GotoTime and About dialogs
3  ****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id: Messages.cpp 16024 2006-07-13 13:51:05Z xtophe $
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) 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
24 #include "dialogs/gototime.hpp"
25
26 #include "dialogs_provider.hpp"
27 #include "main_interface.hpp"
28 #include "util/qvlcframe.hpp"
29 #include "qt4.hpp"
30 #include "input_manager.hpp"
31
32 #include <QTabWidget>
33 #include <QFile>
34 #include <QLabel>
35 #include <QTimeEdit>
36 #include <QGroupBox>
37 #include <QDialogButtonBox>
38
39 GotoTimeDialog *GotoTimeDialog::instance = NULL;
40
41 GotoTimeDialog::GotoTimeDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
42 {
43     setWindowFlags( Qt::Tool );
44     setWindowTitle( qtr( "Go to Time" ) );
45     resize( 250, 180 );
46
47     QGridLayout *mainLayout = new QGridLayout( this );
48
49     QPushButton *gotoButton = new QPushButton( qtr( "&Go" ) );
50     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
51     QDialogButtonBox *buttonBox = new QDialogButtonBox;
52
53     gotoButton->setDefault( true );
54     buttonBox->addButton( gotoButton, QDialogButtonBox::AcceptRole );
55     buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
56
57     QGroupBox *timeGroupBox = new QGroupBox( qtr("Time") );
58     QGridLayout *boxLayout = new QGridLayout( timeGroupBox );
59
60     QLabel *timeIntro = new
61         QLabel( "Enter below the desired time you want to go in the media." );
62     timeIntro->setWordWrap( true );
63     timeIntro->setAlignment( Qt::AlignCenter );
64
65     timeEdit = new QTimeEdit();
66     timeEdit->setDisplayFormat( "hh : mm : ss" );
67     timeEdit->setAlignment( Qt::AlignRight );
68     timeEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
69
70     QLabel *helpFormat = new QLabel( timeEdit->displayFormat() );
71     helpFormat->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
72
73     QSpacerItem *spacerBox = new QSpacerItem(20, 10, QSizePolicy::Minimum,
74                                         QSizePolicy::Fixed);
75
76     QSpacerItem *spacerItem = new QSpacerItem(20, 3, QSizePolicy::Minimum,
77                                         QSizePolicy::Expanding);
78
79     boxLayout->addWidget( timeIntro, 0, 0, 1, 2 );
80     boxLayout->addItem( spacerBox, 1, 0, 1, 2 );
81     boxLayout->addWidget( timeEdit, 2, 0, 1, 1 );
82     boxLayout->addWidget( helpFormat, 2, 1, 1, 1 );
83
84     mainLayout->addWidget( timeGroupBox, 0, 0, 1, 4 );
85     mainLayout->addItem( spacerItem, 1, 0 );
86     mainLayout->addWidget( buttonBox, 2, 3 );
87
88     BUTTONACT( gotoButton, close() );
89     BUTTONACT( cancelButton, cancel() );
90 }
91
92 GotoTimeDialog::~GotoTimeDialog()
93 {
94 }
95
96 void GotoTimeDialog::cancel()
97 {
98     timeEdit->setTime( QTime( 0, 0, 0) );
99     this->toggleVisible();
100 }
101
102 void GotoTimeDialog::close()
103 {
104     if ( THEMIM->getIM()->hasInput() )
105     {
106         int64_t i_time = (int64_t)
107             ( QTime( 0, 0, 0 ).msecsTo( timeEdit->time() ) ) * 1000;
108         var_SetTime( THEMIM->getInput(), "time", i_time );
109     }
110     this->toggleVisible();
111 }