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>
37 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
38 interaction_dialog_t *_p_dialog ) : QObject( 0 ),
39 p_intf( _p_intf), p_dialog( _p_dialog )
41 QVBoxLayout *layout = NULL;
46 if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR )
48 i_ret = QMessageBox::critical( NULL, qfu( p_dialog->psz_title ),
49 qfu( p_dialog->psz_description ),
50 QMessageBox::Ok, 0, 0 );
52 else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
54 if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
55 ErrorsDialog::getInstance( p_intf )->addError(
56 qfu( p_dialog->psz_title ), qfu( p_dialog->psz_description ) );
58 // QApplication::style()->standardPixmap(QStyle::SP_MessageBoxCritical)
60 else if( p_dialog->i_flags & DIALOG_WARNING )
62 if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
63 ErrorsDialog::getInstance( p_intf )->addWarning(
64 qfu( p_dialog->psz_title ),qfu( p_dialog->psz_description ) );
67 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
69 p_dialog->i_status = SENT_DIALOG;
70 i_ret = QMessageBox::question( NULL,
71 qfu( p_dialog->psz_title), qfu( p_dialog->psz_description ),
72 p_dialog->psz_default_button ?
73 qfu( p_dialog->psz_default_button ) : QString::null,
74 p_dialog->psz_alternate_button ?
75 qfu( p_dialog->psz_alternate_button ) : QString::null,
76 p_dialog->psz_other_button ?
77 qfu( p_dialog->psz_other_button ) : QString::null, 0,
78 p_dialog->psz_other_button ? 2 : -1 );
80 else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
82 dialog = new QWidget( 0 ); layout = new QVBoxLayout( dialog );
83 layout->setMargin( 2 );
84 panel = new QWidget( 0 );
85 QGridLayout *grid = new QGridLayout;
87 description = new QLabel( qfu( p_dialog->psz_description ) );
88 grid->addWidget( description, 0, 0, 1, 2 );
90 grid->addWidget( new QLabel( qtr( "Login") ), 1, 0 );
91 loginEdit = new QLineEdit;
92 grid->addWidget( loginEdit, 1, 1 );
94 grid->addWidget( new QLabel( qtr("Password") ), 2, 0);
95 passwordEdit = new QLineEdit;
96 passwordEdit->setEchoMode( QLineEdit::Password );
97 grid->addWidget( passwordEdit, 2, 1 );
99 panel->setLayout( grid );
100 layout->addWidget( panel );
102 else if( p_dialog->i_flags & DIALOG_USER_PROGRESS ||
103 /* TEMPORARY ! */ p_dialog->i_flags & DIALOG_INTF_PROGRESS )
105 dialog = new QWidget( 0 );layout = new QVBoxLayout( dialog );
106 layout->setMargin( 2 );
107 description = new QLabel( qfu( p_dialog->psz_description ) );
108 layout->addWidget( description );
110 progressBar = new QProgressBar;
111 progressBar->setMaximum( 1000 );
112 progressBar->setTextVisible( true );
113 progressBar->setOrientation(Qt::Horizontal);
114 layout->addWidget( progressBar );
116 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
118 dialog = new QWidget( 0 );layout = new QVBoxLayout( dialog );
119 layout->setMargin( 2 );
120 description = new QLabel( qfu( p_dialog->psz_description ) );
121 layout->addWidget( description );
123 inputEdit = new QLineEdit;
124 layout->addWidget( inputEdit );
127 msg_Err( p_intf, "unknown dialog type %i", p_dialog->i_flags );
129 /* We used a message box */
132 if( i_ret == 0 ) Finish( DIALOG_OK_YES );
133 else if ( i_ret == 1 ) Finish( DIALOG_NO );
134 else Finish( DIALOG_CANCELLED );
137 /* Custom box, finish it */
139 QVLCFrame::doButtons( dialog, layout,
140 &defaultButton, p_dialog->psz_default_button,
141 &altButton, p_dialog->psz_alternate_button,
142 &otherButton, p_dialog->psz_other_button );
143 if( p_dialog->psz_default_button )
144 BUTTONACT( defaultButton, defaultB() );
145 if( p_dialog->psz_alternate_button )
146 BUTTONACT( altButton, altB() );
147 if( p_dialog->psz_other_button )
148 BUTTONACT( otherButton, otherB() );
149 dialog->setLayout( layout );
150 dialog->setWindowTitle( qfu( p_dialog->psz_title ) );
154 void InteractionDialog::update()
156 if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
158 assert( progressBar );
159 progressBar->setValue( (int)(p_dialog->val.f_float*1000) );
160 fprintf (stderr, "Setting progress to %i\n", progressBar->value() );
164 InteractionDialog::~InteractionDialog()
166 // if( panel ) delete panel;
167 if( dialog ) delete dialog;
170 void InteractionDialog::defaultB()
172 Finish( DIALOG_OK_YES );
174 void InteractionDialog::altB()
178 void InteractionDialog::otherB()
180 Finish( DIALOG_CANCELLED );
183 void InteractionDialog::Finish( int i_ret )
185 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
187 if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
189 p_dialog->psz_returned[0] = strdup( qtu( loginEdit->text() ) );
190 p_dialog->psz_returned[1] = strdup( qtu( passwordEdit->text() ) );
192 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
194 p_dialog->psz_returned[0] = strdup( qtu( inputEdit->text() ) );
196 p_dialog->i_status = ANSWERED_DIALOG;
197 p_dialog->i_return = i_ret;
199 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
200 playlist_Signal( THEPL );