]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/interaction.cpp
Improve Qt interaction stuff
[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 "util/qvlcframe.hpp"
25 #include <vlc/intf.h>
26 #include "qt4.hpp"
27
28 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
29                          interaction_dialog_t *_p_dialog ) : QWidget( 0 ),
30                           p_intf( _p_intf), p_dialog( _p_dialog )
31 {
32     QVBoxLayout *layout = new QVBoxLayout;
33     uiLogin = NULL;
34     uiProgress = NULL;
35     uiInput = NULL;
36
37
38     if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR )
39     {
40
41     }
42     else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
43     {
44         // Create instance of the errors dialog
45     }
46     else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
47     {
48         description = new QLabel( 0 );
49         description->setText( qfu(p_dialog->psz_description) );
50         layout->addWidget(description);
51     }
52     else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
53     {
54         uiLogin = new Ui::LoginDialog;
55         uiLogin->setupUi( this );
56         uiLogin->description->setText( qfu(p_dialog->psz_description) );
57     }
58     else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
59     {
60
61     }
62     else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
63     {
64     }
65     else
66         msg_Err( p_intf, "unknown dialog type" );
67
68     QVLCFrame::doButtons( this, layout,
69                           defaultButton, p_dialog->psz_default_button,
70                           altButton, p_dialog->psz_alternate_button,
71                           otherButton, p_dialog->psz_other_button );
72     if( p_dialog->psz_default_button )
73         connect( defaultButton, SIGNAL( clicked() ), this, SLOT( defaultB() ) );
74     if( p_dialog->psz_alternate_button )
75         connect( altButton, SIGNAL( clicked() ), this, SLOT( altB() ) );
76     if( p_dialog->psz_other_button )
77         connect( otherButton, SIGNAL( clicked() ), this, SLOT( otherB() ) );
78  
79     setLayout( layout );
80     setWindowTitle( qfu( p_dialog->psz_title ) );
81 }
82
83 void InteractionDialog::Update()
84 {
85 }
86
87 InteractionDialog::~InteractionDialog()
88 {
89     if( uiInput ) delete uiInput;
90     if( uiProgress) delete uiProgress;
91     if( uiLogin ) delete uiLogin;
92 }
93
94 void InteractionDialog::defaultB()
95 {
96     Finish( DIALOG_OK_YES );
97 }
98 void InteractionDialog::altB()
99 {
100     Finish( DIALOG_NO );
101 }
102 void InteractionDialog::otherB()
103 {
104     Finish( DIALOG_CANCELLED );
105 }
106
107 void InteractionDialog::Finish( int i_ret )
108 {
109     vlc_mutex_lock( &p_dialog->p_interaction->object_lock ); 
110
111     if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
112     {
113         p_dialog->psz_returned[0] = strdup(
114                                uiLogin->loginEdit->text().toUtf8().data() );
115         p_dialog->psz_returned[1] = strdup(
116                                uiLogin->passwordEdit->text().toUtf8().data() );
117     }
118     else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
119     {
120         p_dialog->psz_returned[0] = strdup(
121                                uiInput->inputEdit->text().toUtf8().data() );
122     }
123     p_dialog->i_status = ANSWERED_DIALOG;
124     p_dialog->i_return = i_ret;
125     hide();
126     vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); 
127 }