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. *****************************************************************************/
23 #include <QMessageBox>
24 #include "dialogs/interaction.hpp"
25 #include "util/qvlcframe.hpp"
29 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
30 interaction_dialog_t *_p_dialog ) : QWidget( 0 ),
31 p_intf( _p_intf), p_dialog( _p_dialog )
33 QVBoxLayout *layout = new QVBoxLayout( this );
39 if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR )
42 else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
44 // Create instance of the errors dialog
46 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
48 i_ret = QMessageBox::question( this,
49 qfu( p_dialog->psz_title), qfu( p_dialog->psz_description ),
50 p_dialog->psz_default_button ?
51 qfu( p_dialog->psz_default_button ) : QString::null,
52 p_dialog->psz_alternate_button ?
53 qfu( p_dialog->psz_alternate_button ) : QString::null,
54 p_dialog->psz_other_button ?
55 qfu( p_dialog->psz_other_button ) : QString::null, 0,
56 p_dialog->psz_other_button ? 2 : -1 );
58 else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
60 uiLogin = new Ui::LoginDialog;
61 uiLogin->setupUi( this );
62 uiLogin->description->setText( qfu(p_dialog->psz_description) );
64 else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
68 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
72 msg_Err( p_intf, "unknown dialog type" );
74 /* We used a message box */
77 if( i_ret == 0 ) Finish( DIALOG_OK_YES );
78 else if ( i_ret == 1 ) Finish( DIALOG_NO );
79 else Finish( DIALOG_CANCELLED );
82 /* Custom box, finish it */
84 QVLCFrame::doButtons( this, layout,
85 &defaultButton, p_dialog->psz_default_button,
86 &altButton, p_dialog->psz_alternate_button,
87 &otherButton, p_dialog->psz_other_button );
88 if( p_dialog->psz_default_button )
89 connect( defaultButton, SIGNAL( clicked() ),
90 this, SLOT( defaultB() ) );
91 if( p_dialog->psz_alternate_button )
92 connect( altButton, SIGNAL( clicked() ), this, SLOT( altB() ) );
93 if( p_dialog->psz_other_button )
94 connect( otherButton, SIGNAL( clicked() ), this, SLOT( otherB() ) );
96 setWindowTitle( qfu( p_dialog->psz_title ) );
100 void InteractionDialog::Update()
104 InteractionDialog::~InteractionDialog()
106 if( uiInput ) delete uiInput;
107 if( uiProgress) delete uiProgress;
108 if( uiLogin ) delete uiLogin;
111 void InteractionDialog::defaultB()
113 Finish( DIALOG_OK_YES );
115 void InteractionDialog::altB()
119 void InteractionDialog::otherB()
121 Finish( DIALOG_CANCELLED );
124 void InteractionDialog::Finish( int i_ret )
126 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
128 if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
130 p_dialog->psz_returned[0] = strdup(
131 uiLogin->loginEdit->text().toUtf8().data() );
132 p_dialog->psz_returned[1] = strdup(
133 uiLogin->passwordEdit->text().toUtf8().data() );
135 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
137 p_dialog->psz_returned[0] = strdup(
138 uiInput->inputEdit->text().toUtf8().data() );
140 p_dialog->i_status = ANSWERED_DIALOG;
141 p_dialog->i_return = i_ret;
143 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );