]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/interaction.cpp
Handle blocking errors, fix layout for login
[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 <QMessageBox>
24 #include "dialogs/interaction.hpp"
25 #include "util/qvlcframe.hpp"
26 #include <vlc/intf.h>
27 #include "qt4.hpp"
28
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 )
32 {
33     QVBoxLayout *layout = new QVBoxLayout( this );
34     int i_ret = -1;
35     uiLogin = NULL;
36     uiProgress = NULL;
37     uiInput = NULL;
38     panel = NULL;
39
40     if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR )
41     {
42         i_ret = QMessageBox::critical( this, qfu( p_dialog->psz_title ),
43                                        qfu( p_dialog->psz_description ),
44                                        QMessageBox::Ok, 0, 0 );
45     }
46     else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
47     {
48         // Create instance of the errors dialog
49         //  QApplication::style()->standardPixmap(QStyle::SP_MessageBoxCritical)
50     }
51     else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
52     {
53         i_ret = QMessageBox::question( this,
54               qfu( p_dialog->psz_title), qfu( p_dialog->psz_description ),
55               p_dialog->psz_default_button ?
56                     qfu( p_dialog->psz_default_button ) : QString::null,
57               p_dialog->psz_alternate_button ?
58                     qfu( p_dialog->psz_alternate_button ) : QString::null,
59               p_dialog->psz_other_button ?
60                     qfu( p_dialog->psz_other_button ) : QString::null, 0,
61               p_dialog->psz_other_button ? 2 : -1 );
62     }
63     else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
64     {
65         panel = new QWidget( 0 );
66         uiLogin = new Ui::LoginDialog;
67         uiLogin->setupUi( panel );
68         uiLogin->description->setText( qfu(p_dialog->psz_description) );
69         layout->addWidget( panel );
70     }
71     else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
72     {
73     }
74     else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
75     {
76     }
77     else
78         msg_Err( p_intf, "unknown dialog type" );
79
80     /* We used a message box */
81     if( i_ret != -1 )
82     {
83         if( i_ret == 0 ) Finish( DIALOG_OK_YES );
84         else if ( i_ret == 1 ) Finish( DIALOG_NO );
85         else Finish( DIALOG_CANCELLED );
86     }
87     else
88     /* Custom box, finish it */
89     {
90         QVLCFrame::doButtons( this, layout,
91                               &defaultButton, p_dialog->psz_default_button,
92                               &altButton, p_dialog->psz_alternate_button,
93                               &otherButton, p_dialog->psz_other_button );
94         if( p_dialog->psz_default_button )
95             connect( defaultButton, SIGNAL( clicked() ),
96                      this, SLOT( defaultB() ) );
97         if( p_dialog->psz_alternate_button )
98             connect( altButton, SIGNAL( clicked() ), this, SLOT( altB() ) );
99         if( p_dialog->psz_other_button )
100             connect( otherButton, SIGNAL( clicked() ), this, SLOT( otherB() ) );
101         setLayout( layout );
102         setWindowTitle( qfu( p_dialog->psz_title ) );
103     }
104 }
105
106 void InteractionDialog::Update()
107 {
108 }
109
110 InteractionDialog::~InteractionDialog()
111 {
112     if( panel ) delete panel;
113     if( uiInput ) delete uiInput;
114     if( uiProgress) delete uiProgress;
115     if( uiLogin ) delete uiLogin;
116 }
117
118 void InteractionDialog::defaultB()
119 {
120     Finish( DIALOG_OK_YES );
121 }
122 void InteractionDialog::altB()
123 {
124     Finish( DIALOG_NO );
125 }
126 void InteractionDialog::otherB()
127 {
128     Finish( DIALOG_CANCELLED );
129 }
130
131 void InteractionDialog::Finish( int i_ret )
132 {
133     vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
134
135     if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
136     {
137         p_dialog->psz_returned[0] = strdup(
138                                uiLogin->loginEdit->text().toUtf8().data() );
139         p_dialog->psz_returned[1] = strdup(
140                                uiLogin->passwordEdit->text().toUtf8().data() );
141     }
142     else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
143     {
144         p_dialog->psz_returned[0] = strdup(
145                                uiInput->inputEdit->text().toUtf8().data() );
146     }
147     p_dialog->i_status = ANSWERED_DIALOG;
148     p_dialog->i_return = i_ret;
149     hide();
150     vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
151 }