1 /*****************************************************************************
2 * interaction.cpp : Interaction stuff
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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. *****************************************************************************/
24 #include "dialogs/errors.hpp"
25 #include "dialogs/interaction.hpp"
26 #include "util/qvlcframe.hpp"
30 #include <QPushButton>
31 #include <QProgressBar>
32 #include <QMessageBox>
36 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
37 interaction_dialog_t *_p_dialog ) : QWidget( 0 ),
38 p_intf( _p_intf), p_dialog( _p_dialog )
40 QVBoxLayout *layout = new QVBoxLayout( this );
44 if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR )
46 i_ret = QMessageBox::critical( this, qfu( p_dialog->psz_title ),
47 qfu( p_dialog->psz_description ),
48 QMessageBox::Ok, 0, 0 );
50 else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
52 if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
53 ErrorsDialog::getInstance( p_intf )->addError(
54 qfu( p_dialog->psz_title ), qfu( p_dialog->psz_description ) );
56 // QApplication::style()->standardPixmap(QStyle::SP_MessageBoxCritical)
58 else if( p_dialog->i_flags & DIALOG_WARNING )
60 if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
61 ErrorsDialog::getInstance( p_intf )->addWarning(
62 qfu( p_dialog->psz_title ),qfu( p_dialog->psz_description ) );
65 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
67 i_ret = QMessageBox::question( this,
68 qfu( p_dialog->psz_title), qfu( p_dialog->psz_description ),
69 p_dialog->psz_default_button ?
70 qfu( p_dialog->psz_default_button ) : QString::null,
71 p_dialog->psz_alternate_button ?
72 qfu( p_dialog->psz_alternate_button ) : QString::null,
73 p_dialog->psz_other_button ?
74 qfu( p_dialog->psz_other_button ) : QString::null, 0,
75 p_dialog->psz_other_button ? 2 : -1 );
77 else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
79 panel = new QWidget( 0 );
80 QGridLayout *grid = new QGridLayout;
82 description = new QLabel( qfu( p_dialog->psz_description ) );
83 grid->addWidget( description, 0, 0, 1, 2 );
85 grid->addWidget( new QLabel( qtr( "Login") ), 1, 0 );
86 loginEdit = new QLineEdit;
87 grid->addWidget( loginEdit, 1, 1 );
89 grid->addWidget( new QLabel( qtr("Password") ), 2, 0);
90 passwordEdit = new QLineEdit;
91 grid->addWidget( passwordEdit, 2, 1 );
93 panel->setLayout( grid );
94 layout->addWidget( panel );
96 else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
98 description = new QLabel( qfu( p_dialog->psz_description ) );
99 layout->addWidget( description );
101 progressBar = new QProgressBar;
102 progressBar->setMaximum( 1000 );
103 progressBar->setTextVisible( true );
104 progressBar->setOrientation(Qt::Horizontal);
105 layout->addWidget( progressBar );
107 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
109 description = new QLabel( qfu( p_dialog->psz_description ) );
110 layout->addWidget( description );
112 inputEdit = new QLineEdit;
113 layout->addWidget( inputEdit );
116 msg_Err( p_intf, "unknown dialog type" );
118 /* We used a message box */
121 if( i_ret == 0 ) Finish( DIALOG_OK_YES );
122 else if ( i_ret == 1 ) Finish( DIALOG_NO );
123 else Finish( DIALOG_CANCELLED );
126 /* Custom box, finish it */
128 QVLCFrame::doButtons( this, layout,
129 &defaultButton, p_dialog->psz_default_button,
130 &altButton, p_dialog->psz_alternate_button,
131 &otherButton, p_dialog->psz_other_button );
132 if( p_dialog->psz_default_button )
133 BUTTONACT( defaultButton, defaultB );
134 if( p_dialog->psz_alternate_button )
135 BUTTONACT( altButton, altB );
136 if( p_dialog->psz_other_button )
137 BUTTONACT( otherButton, otherB );
139 setWindowTitle( qfu( p_dialog->psz_title ) );
143 void InteractionDialog::Update()
145 if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
147 assert( progressBar );
148 progressBar->setValue( (int)(p_dialog->val.f_float*1000) );
152 InteractionDialog::~InteractionDialog()
154 if( panel ) delete panel;
157 void InteractionDialog::defaultB()
159 Finish( DIALOG_OK_YES );
161 void InteractionDialog::altB()
165 void InteractionDialog::otherB()
167 Finish( DIALOG_CANCELLED );
170 void InteractionDialog::Finish( int i_ret )
172 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
174 if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
176 p_dialog->psz_returned[0] = strdup( qtu( loginEdit->text() ) );
177 p_dialog->psz_returned[1] = strdup( qtu( passwordEdit->text() ) );
179 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
181 p_dialog->psz_returned[0] = strdup( qtu( inputEdit->text() ) );
183 p_dialog->i_status = ANSWERED_DIALOG;
184 p_dialog->i_return = i_ret;
186 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );