]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/interaction.cpp
qt4 - Include cleanup.
[vlc] / modules / gui / qt4 / dialogs / interaction.cpp
index 914c83e8b8a34030997bfe518b10983264d5a092..1d843cbbc5f39066de8692992277bc1d325d5894 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * interaction.cpp : Interaction stuff
  ****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
- * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
+ * Copyright (C) 2006 the VideoLAN team
+ * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
 
+#include "qt4.hpp"
+#include "dialogs/errors.hpp"
 #include "dialogs/interaction.hpp"
-#include <vlc/intf.h>
+#include "util/qvlcframe.hpp"
+
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QProgressBar>
+#include <QMessageBox>
+
+#include <assert.h>
 
 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
-                                      interaction_dialog_t *_p_dialog ) :
-                                        p_intf( _p_intf), p_dialog( _p_dialog )
+                         interaction_dialog_t *_p_dialog ) : QObject( 0 ),
+                          p_intf( _p_intf), p_dialog( _p_dialog )
 {
-    if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
+    QVBoxLayout *layout = NULL;
+    int i_ret = -1;
+    panel = NULL;
+    dialog = NULL;
+
+    if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR )
+    {
+        i_ret = QMessageBox::critical( NULL, qfu( p_dialog->psz_title ),
+                                       qfu( p_dialog->psz_description ),
+                                       QMessageBox::Ok, 0, 0 );
+    }
+    else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
+    {
+        if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
+            ErrorsDialog::getInstance( p_intf )->addError(
+                 qfu( p_dialog->psz_title ), qfu( p_dialog->psz_description ) );
+        i_ret = 0;
+        //  QApplication::style()->standardPixmap(QStyle::SP_MessageBoxCritical)
+    }
+    else if( p_dialog->i_flags & DIALOG_WARNING )
     {
-        uiOkCancel = new Ui::OKCancelDialog;
-        uiOkCancel->setupUi( this );
-        uiOkCancel->description->setText( p_dialog->psz_description );
-        connect( uiOkCancel->okButton, SIGNAL( clicked() ),
-                 this, SLOT( OK() ) );
-        connect( uiOkCancel->cancelButton, SIGNAL( clicked() ),
-                 this, SLOT( cancel() ) );
+        if( config_GetInt( p_intf, "errors-dialog" ) != 0 )
+            ErrorsDialog::getInstance( p_intf )->addWarning(
+                qfu( p_dialog->psz_title ),qfu( p_dialog->psz_description ) );
+        i_ret = 0;
     }
     else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
     {
-      
+        p_dialog->i_status = SENT_DIALOG;
+        i_ret = QMessageBox::question( NULL,
+              qfu( p_dialog->psz_title), qfu( p_dialog->psz_description ),
+              p_dialog->psz_default_button ?
+                    qfu( p_dialog->psz_default_button ) : QString::null,
+              p_dialog->psz_alternate_button ?
+                    qfu( p_dialog->psz_alternate_button ) : QString::null,
+              p_dialog->psz_other_button ?
+                    qfu( p_dialog->psz_other_button ) : QString::null, 0,
+              p_dialog->psz_other_button ? 2 : -1 );
     }
     else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
     {
+        dialog = new QWidget( 0 ); layout = new QVBoxLayout( dialog );
+        layout->setMargin( 2 );
+        panel = new QWidget( 0 );
+        QGridLayout *grid = new QGridLayout;
 
+        description = new QLabel( qfu( p_dialog->psz_description ) );
+        grid->addWidget( description, 0, 0, 1, 2 );
+
+        grid->addWidget( new QLabel( qtr( "Login") ), 1, 0 );
+        loginEdit = new QLineEdit;
+        grid->addWidget( loginEdit, 1, 1 );
+
+        grid->addWidget( new QLabel( qtr("Password") ), 2, 0);
+        passwordEdit = new QLineEdit;
+        passwordEdit->setEchoMode( QLineEdit::Password );
+        grid->addWidget( passwordEdit, 2, 1 );
+
+        panel->setLayout( grid );
+        layout->addWidget( panel );
     }
-    else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
+    else if( p_dialog->i_flags & DIALOG_USER_PROGRESS ||
+             /* TEMPORARY ! */ p_dialog->i_flags & DIALOG_INTF_PROGRESS )
     {
+        dialog = new QWidget( 0 );layout = new QVBoxLayout( dialog );
+        layout->setMargin( 2 );
+        description = new QLabel( qfu( p_dialog->psz_description ) );
+        layout->addWidget( description );
 
+        progressBar = new QProgressBar;
+        progressBar->setMaximum( 1000 );
+        progressBar->setTextVisible( true );
+        progressBar->setOrientation(Qt::Horizontal);
+        layout->addWidget( progressBar );
     }
     else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
     {
+        dialog = new QWidget( 0 );layout = new QVBoxLayout( dialog );
+        layout->setMargin( 2 );
+        description = new QLabel( qfu( p_dialog->psz_description ) );
+        layout->addWidget( description );
+
+        inputEdit = new QLineEdit;
+        layout->addWidget( inputEdit );
     }
     else
-        msg_Err( p_intf, "unknown dialog type" );
+        msg_Err( p_intf, "unknown dialog type %i", p_dialog->i_flags );
+
+    /* We used a message box */
+    if( i_ret != -1 )
+    {
+        if( i_ret == 0 ) Finish( DIALOG_OK_YES );
+        else if ( i_ret == 1 ) Finish( DIALOG_NO );
+        else Finish( DIALOG_CANCELLED );
+    }
+    else
+    /* Custom box, finish it */
+    {
+        QVLCFrame::doButtons( dialog, layout,
+                              &defaultButton, p_dialog->psz_default_button,
+                              &altButton, p_dialog->psz_alternate_button,
+                              &otherButton, p_dialog->psz_other_button );
+        if( p_dialog->psz_default_button )
+            BUTTONACT( defaultButton, defaultB() );
+        if( p_dialog->psz_alternate_button )
+            BUTTONACT( altButton, altB() );
+        if( p_dialog->psz_other_button )
+            BUTTONACT( otherButton, otherB() );
+        dialog->setLayout( layout );
+        dialog->setWindowTitle( qfu( p_dialog->psz_title ) );
+    }
 }
 
-void InteractionDialog::Update()
+void InteractionDialog::update()
 {
+    if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
+    {
+        assert( progressBar );
+        progressBar->setValue( (int)(p_dialog->val.f_float*1000) );
+        fprintf (stderr, "Setting progress to %i\n", progressBar->value() );
+    }
 }
 
 InteractionDialog::~InteractionDialog()
 {
+//    if( panel ) delete panel;
+    if( dialog ) delete dialog;
 }
 
-void InteractionDialog::OK()
+void InteractionDialog::defaultB()
 {
-    Finish( DIALOG_OK_YES, NULL, NULL );
+    Finish( DIALOG_OK_YES );
 }
-
-void InteractionDialog::cancel()
+void InteractionDialog::altB()
 {
-    Finish( DIALOG_CANCELLED, NULL, NULL );
+    Finish( DIALOG_NO );
+}
+void InteractionDialog::otherB()
+{
+    Finish( DIALOG_CANCELLED );
 }
 
-void InteractionDialog::Finish( int i_ret, QString *r1, QString *r2 )
+void InteractionDialog::Finish( int i_ret )
 {
-   vlc_mutex_lock( &p_dialog->p_interaction->object_lock ); 
+    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
 
-   p_dialog->i_status = ANSWERED_DIALOG;
-   p_dialog->i_return = i_ret;
-   hide();
-   vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); 
+    if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
+    {
+        p_dialog->psz_returned[0] = strdup( qtu( loginEdit->text() ) );
+        p_dialog->psz_returned[1] = strdup( qtu( passwordEdit->text() ) );
+    }
+    else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
+    {
+        p_dialog->psz_returned[0] = strdup( qtu( inputEdit->text() ) );
+    }
+    p_dialog->i_status = ANSWERED_DIALOG;
+    p_dialog->i_return = i_ret;
+    hide();
+    vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
+    playlist_Signal( THEPL );
 }