]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/interaction.cpp
Some more Qt interaction support
[vlc] / modules / gui / qt4 / dialogs / interaction.cpp
1 /*****************************************************************************
2  * interaction.cpp : Interaction stuff
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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
23 #include "dialogs/interaction.hpp"
24 #include <vlc/intf.h>
25 #include "qt4.hpp"
26
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 )
30 {
31     uiOkCancel = NULL;
32     uiYesNoCancel = NULL;
33     uiLogin = NULL;
34     uiProgress = NULL;
35     uiInput = NULL;
36
37     if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
38     {
39         uiOkCancel = new Ui::OKCancelDialog;
40         uiOkCancel->setupUi( this );
41         uiOkCancel->description->setText( qfu(p_dialog->psz_description) );
42         connect( uiOkCancel->okButton, SIGNAL( clicked() ),
43                  this, SLOT( OK() ) );
44         connect( uiOkCancel->cancelButton, SIGNAL( clicked() ),
45                  this, SLOT( cancel() ) );
46     }
47     else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
48     {
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() ),
55                  this, SLOT( no() ) );
56         connect( uiYesNoCancel->cancelButton, SIGNAL( clicked() ),
57                  this, SLOT( cancel() ) );
58     }
59     else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
60     {
61         uiLogin = new Ui::LoginDialog;
62         uiLogin->setupUi( this );
63         uiLogin->description->setText( qfu(p_dialog->psz_description) );
64         connect( uiLogin->okButton, SIGNAL( clicked() ),
65                  this, SLOT( OK() ) );
66         connect( uiLogin->cancelButton, SIGNAL( clicked() ),
67                  this, SLOT( cancel() ) );
68     }
69     else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
70     {
71
72     }
73     else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
74     {
75     }
76     else
77         msg_Err( p_intf, "unknown dialog type" );
78     setWindowTitle( qfu( p_dialog->psz_title ) );
79 }
80
81 void InteractionDialog::Update()
82 {
83 }
84
85 InteractionDialog::~InteractionDialog()
86 {
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;
92 }
93
94 void InteractionDialog::yes()
95 {
96     Finish( DIALOG_OK_YES );
97 }
98 void InteractionDialog::no()
99 {
100     Finish( DIALOG_NO );
101 }
102 void InteractionDialog::OK()
103 {
104     Finish( DIALOG_OK_YES );
105 }
106
107 void InteractionDialog::cancel()
108 {
109     Finish( DIALOG_CANCELLED );
110 }
111
112 void InteractionDialog::Finish( int i_ret )
113 {
114     vlc_mutex_lock( &p_dialog->p_interaction->object_lock ); 
115
116     if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
117     {
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() );
122     }
123     else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
124     {
125         p_dialog->psz_returned[0] = strdup(
126                                uiInput->inputEdit->text().toUtf8().data() );
127     }
128     p_dialog->i_status = ANSWERED_DIALOG;
129     p_dialog->i_return = i_ret;
130     hide();
131     vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); 
132 }