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.
22 *****************************************************************************/
25 #include "dialogs/errors.hpp"
26 #include "dialogs/interaction.hpp"
27 #include "util/qvlcframe.hpp"
31 #include <QPushButton>
32 #include <QProgressBar>
33 #include <QMessageBox>
34 #include <QDialogButtonBox>
38 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
39 interaction_dialog_t *_p_dialog ) : QObject( 0 ),
40 p_intf( _p_intf), p_dialog( _p_dialog )
42 QVBoxLayout *layout = NULL;
47 if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR )
49 i_ret = QMessageBox::critical( NULL, qfu( p_dialog->psz_title ),
50 qfu( p_dialog->psz_description ),
51 QMessageBox::Ok, 0, 0 );
53 else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
55 if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
56 ErrorsDialog::getInstance( p_intf )->addError(
57 qfu( p_dialog->psz_title ), qfu( p_dialog->psz_description ) );
59 // QApplication::style()->standardPixmap(QStyle::SP_MessageBoxCritical)
61 else if( p_dialog->i_flags & DIALOG_WARNING )
63 if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
64 ErrorsDialog::getInstance( p_intf )->addWarning(
65 qfu( p_dialog->psz_title ),qfu( p_dialog->psz_description ) );
68 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
70 p_dialog->i_status = SENT_DIALOG;
71 i_ret = QMessageBox::question( NULL,
72 qfu( p_dialog->psz_title), qfu( p_dialog->psz_description ),
73 p_dialog->psz_default_button ?
74 qfu( p_dialog->psz_default_button ) : QString::null,
75 p_dialog->psz_alternate_button ?
76 qfu( p_dialog->psz_alternate_button ) : QString::null,
77 p_dialog->psz_other_button ?
78 qfu( p_dialog->psz_other_button ) : QString::null, 0,
79 p_dialog->psz_other_button ? 2 : -1 );
81 else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
83 dialog = new QWidget( 0 ); layout = new QVBoxLayout( dialog );
84 layout->setMargin( 2 );
85 panel = new QWidget( 0 );
86 QGridLayout *grid = new QGridLayout;
88 description = new QLabel( qfu( p_dialog->psz_description ) );
89 grid->addWidget( description, 0, 0, 1, 2 );
91 grid->addWidget( new QLabel( qtr( "Login") ), 1, 0 );
92 loginEdit = new QLineEdit;
93 grid->addWidget( loginEdit, 1, 1 );
95 grid->addWidget( new QLabel( qtr("Password") ), 2, 0);
96 passwordEdit = new QLineEdit;
97 passwordEdit->setEchoMode( QLineEdit::Password );
98 grid->addWidget( passwordEdit, 2, 1 );
100 panel->setLayout( grid );
101 layout->addWidget( panel );
103 else if( p_dialog->i_flags & DIALOG_USER_PROGRESS ||
104 /* TEMPORARY ! */ p_dialog->i_flags & DIALOG_INTF_PROGRESS )
106 dialog = new QWidget( 0 );layout = new QVBoxLayout( dialog );
107 layout->setMargin( 2 );
108 description = new QLabel( qfu( p_dialog->psz_description ) );
109 layout->addWidget( description );
111 progressBar = new QProgressBar;
112 progressBar->setMaximum( 1000 );
113 progressBar->setTextVisible( true );
114 progressBar->setOrientation(Qt::Horizontal);
115 layout->addWidget( progressBar );
117 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
119 dialog = new QWidget( 0 );layout = new QVBoxLayout( dialog );
120 layout->setMargin( 2 );
121 description = new QLabel( qfu( p_dialog->psz_description ) );
122 layout->addWidget( description );
124 inputEdit = new QLineEdit;
125 layout->addWidget( inputEdit );
128 msg_Err( p_intf, "unknown dialog type %i", p_dialog->i_flags );
130 /* We used a message box */
133 if( i_ret == 0 ) Finish( DIALOG_OK_YES );
134 else if ( i_ret == 1 ) Finish( DIALOG_NO );
135 else Finish( DIALOG_CANCELLED );
138 /* Custom box, finish it */
140 QDialogButtonBox *buttonBox = new QDialogButtonBox;
142 if( p_dialog->psz_default_button )
144 defaultButton = new QPushButton;
145 defaultButton->setFocus();
146 defaultButton->setText( qfu( p_dialog->psz_default_button ) );
147 buttonBox->addButton( defaultButton, QDialogButtonBox::AcceptRole );
149 if( p_dialog->psz_alternate_button )
151 altButton = new QPushButton;
152 altButton->setText( qfu( p_dialog->psz_alternate_button ) );
153 buttonBox->addButton( altButton, QDialogButtonBox::RejectRole );
155 if( p_dialog->psz_other_button )
157 otherButton = new QPushButton;
158 otherButton->setText( qfu( p_dialog->psz_other_button ) );
159 buttonBox->addButton( otherButton, QDialogButtonBox::ActionRole );
161 layout->addWidget( buttonBox );
162 if( p_dialog->psz_default_button )
163 BUTTONACT( defaultButton, defaultB() );
164 if( p_dialog->psz_alternate_button )
165 BUTTONACT( altButton, altB() );
166 if( p_dialog->psz_other_button )
167 BUTTONACT( otherButton, otherB() );
168 dialog->setLayout( layout );
169 dialog->setWindowTitle( qfu( p_dialog->psz_title ) );
173 void InteractionDialog::update()
175 if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
177 assert( progressBar );
178 progressBar->setValue( (int)(p_dialog->val.f_float*1000) );
179 msg_Err( p_intf, "Setting progress to %i\n", progressBar->value() );
183 InteractionDialog::~InteractionDialog()
185 // if( panel ) delete panel;
186 if( dialog ) delete dialog;
189 void InteractionDialog::defaultB()
191 Finish( DIALOG_OK_YES );
193 void InteractionDialog::altB()
197 void InteractionDialog::otherB()
199 Finish( DIALOG_CANCELLED );
202 void InteractionDialog::Finish( int i_ret )
204 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
206 if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
208 p_dialog->psz_returned[0] = strdup( qtu( loginEdit->text() ) );
209 p_dialog->psz_returned[1] = strdup( qtu( passwordEdit->text() ) );
211 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
213 p_dialog->psz_returned[0] = strdup( qtu( inputEdit->text() ) );
215 p_dialog->i_status = ANSWERED_DIALOG;
216 p_dialog->i_return = i_ret;
218 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
219 playlist_Signal( THEPL );