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 "dialogs/interaction.hpp"
27 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
28 interaction_dialog_t *_p_dialog ) : QWidget( 0 ),
29 p_intf( _p_intf), p_dialog( _p_dialog )
37 if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
39 uiOkCancel = new Ui::OKCancelDialog;
40 uiOkCancel->setupUi( this );
41 uiOkCancel->description->setText( qfu(p_dialog->psz_description) );
42 connect( uiOkCancel->okButton, SIGNAL( clicked() ),
44 connect( uiOkCancel->cancelButton, SIGNAL( clicked() ),
45 this, SLOT( cancel() ) );
47 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
49 uiYesNoCancel = new Ui::YesNoCancelDialog;
50 uiYesNoCancel->setupUi( this );
51 uiYesNoCancel->description->setText( qfu(p_dialog->psz_description) );
52 connect( uiYesNoCancel->yesButton, SIGNAL( clicked() ),
53 this, SLOT( yes() ) );
54 connect( uiYesNoCancel->noButton, SIGNAL( clicked() ),
56 connect( uiYesNoCancel->cancelButton, SIGNAL( clicked() ),
57 this, SLOT( cancel() ) );
59 else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
61 uiLogin = new Ui::LoginDialog;
62 uiLogin->setupUi( this );
63 uiLogin->description->setText( qfu(p_dialog->psz_description) );
64 connect( uiLogin->okButton, SIGNAL( clicked() ),
66 connect( uiLogin->cancelButton, SIGNAL( clicked() ),
67 this, SLOT( cancel() ) );
69 else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
73 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
77 msg_Err( p_intf, "unknown dialog type" );
78 setWindowTitle( qfu( p_dialog->psz_title ) );
81 void InteractionDialog::Update()
85 InteractionDialog::~InteractionDialog()
87 if( uiYesNoCancel ) delete uiYesNoCancel;
88 if( uiOkCancel ) delete uiOkCancel;
89 if( uiInput ) delete uiInput;
90 if( uiProgress) delete uiProgress;
91 if( uiLogin ) delete uiLogin;
94 void InteractionDialog::yes()
96 Finish( DIALOG_OK_YES );
98 void InteractionDialog::no()
102 void InteractionDialog::OK()
104 Finish( DIALOG_OK_YES );
107 void InteractionDialog::cancel()
109 Finish( DIALOG_CANCELLED );
112 void InteractionDialog::Finish( int i_ret )
114 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
116 if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
118 p_dialog->psz_returned[0] = strdup(
119 uiLogin->loginEdit->text().toUtf8().data() );
120 p_dialog->psz_returned[1] = strdup(
121 uiLogin->passwordEdit->text().toUtf8().data() );
123 else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
125 p_dialog->psz_returned[0] = strdup(
126 uiInput->inputEdit->text().toUtf8().data() );
128 p_dialog->i_status = ANSWERED_DIALOG;
129 p_dialog->i_return = i_ret;
131 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );