[vlc-devel] commit: Qt4: back-end for dialog_Progress ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Mar 8 21:11:07 CET 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar  8 22:06:29 2009 +0200| [143011b417b3ebefabece74ad355b3310723cdb9] | committer: Rémi Denis-Courmont 

Qt4: back-end for dialog_Progress

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=143011b417b3ebefabece74ad355b3310723cdb9
---

 modules/gui/qt4/dialogs/external.cpp |   77 +++++++++++++++++++++++++++++++++-
 modules/gui/qt4/dialogs/external.hpp |   35 +++++++++++++++
 2 files changed, 111 insertions(+), 1 deletions(-)

diff --git a/modules/gui/qt4/dialogs/external.cpp b/modules/gui/qt4/dialogs/external.cpp
index 4baeda6..dba8cfd 100644
--- a/modules/gui/qt4/dialogs/external.cpp
+++ b/modules/gui/qt4/dialogs/external.cpp
@@ -33,6 +33,8 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QMessageBox>
+#include <QProgressDialog>
+#include <QMutex>
 
 QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type)
     : object (obj), name (qfu(varname))
@@ -59,7 +61,8 @@ DialogHandler::DialogHandler (intf_thread_t *intf)
     : intf (intf),
       message (VLC_OBJECT(intf), "dialog-fatal", VLC_VAR_ADDRESS),
       login (VLC_OBJECT(intf), "dialog-login", VLC_VAR_ADDRESS),
-      question (VLC_OBJECT(intf), "dialog-question", VLC_VAR_ADDRESS)
+      question (VLC_OBJECT(intf), "dialog-question", VLC_VAR_ADDRESS),
+      progressBar (VLC_OBJECT(intf), "dialog-progress-bar", VLC_VAR_ADDRESS)
 {
     connect (&message, SIGNAL(pointerChanged(vlc_object_t *, void *)),
              SLOT(displayMessage(vlc_object_t *, void *)),
@@ -70,6 +73,12 @@ DialogHandler::DialogHandler (intf_thread_t *intf)
     connect (&question, SIGNAL(pointerChanged(vlc_object_t *, void *)),
              SLOT(requestAnswer(vlc_object_t *, void *)),
              Qt::BlockingQueuedConnection);
+    connect (&progressBar, SIGNAL(pointerChanged(vlc_object_t *, void *)),
+             SLOT(startProgressBar(vlc_object_t *, void *)),
+             Qt::BlockingQueuedConnection);
+    connect (this,
+             SIGNAL(progressBarDestroyed(QWidget *)),
+             SLOT(stopProgressBar(QWidget *)));
 
     dialog_Register (intf);
 }
@@ -168,3 +177,69 @@ void DialogHandler::requestAnswer (vlc_object_t *, void *value)
     delete box;
     data->answer = answer;
 }
+
+
+QVLCProgressDialog::QVLCProgressDialog (DialogHandler *parent,
+                                        struct dialog_progress_bar_t *data)
+    : QProgressDialog (qfu(data->message),
+                       data->cancel ? ("&" + qfu(data->cancel)) : 0, 0, 1000),
+      cancelled (false),
+      handler (parent)
+{
+    if (data->title != NULL)
+        setWindowTitle (qfu(data->title));
+    setMinimumDuration (0);
+
+    connect (this, SIGNAL(progressed(int)), SLOT(setValue(int)));
+    connect (this, SIGNAL(canceled(void)), SLOT(saveCancel(void)));
+
+    data->pf_update = update;
+    data->pf_check = check;
+    data->pf_destroy = destroy;
+    data->p_sys = this;
+}
+
+QVLCProgressDialog::~QVLCProgressDialog (void)
+{
+}
+
+void QVLCProgressDialog::update (void *priv, float value)
+{
+    QVLCProgressDialog *self = static_cast<QVLCProgressDialog *>(priv);
+    emit self->progressed ((int)(value * 1000.));
+}
+
+static QMutex cancel_mutex;
+
+bool QVLCProgressDialog::check (void *priv)
+{
+    QVLCProgressDialog *self = static_cast<QVLCProgressDialog *>(priv);
+    QMutexLocker locker (&cancel_mutex);
+    return self->cancelled;
+}
+
+void QVLCProgressDialog::destroy (void *priv)
+{
+    QVLCProgressDialog *self = static_cast<QVLCProgressDialog *>(priv);
+
+    emit self->handler->progressBarDestroyed (self);
+}
+
+void QVLCProgressDialog::saveCancel (void)
+{
+    QMutexLocker locker (&cancel_mutex);
+    cancelled = true;
+}
+
+void DialogHandler::startProgressBar (vlc_object_t *, void *value)
+{
+    dialog_progress_bar_t *data = (dialog_progress_bar_t *)value;
+    QWidget *dlg = new QVLCProgressDialog (this, data);
+
+    dlg->show ();
+}
+
+void DialogHandler::stopProgressBar (QWidget *dlg)
+{
+    delete dlg;
+}
\ No newline at end of file
diff --git a/modules/gui/qt4/dialogs/external.hpp b/modules/gui/qt4/dialogs/external.hpp
index 23aa263..f50c54e 100644
--- a/modules/gui/qt4/dialogs/external.hpp
+++ b/modules/gui/qt4/dialogs/external.hpp
@@ -42,10 +42,14 @@ signals:
 };
 
 struct intf_thread_t;
+class QProgressDialog;
 
 class DialogHandler : public QObject
 {
     Q_OBJECT
+
+    friend class QVLCProgressDialog;
+
 public:
     DialogHandler (intf_thread_t *);
     ~DialogHandler (void);
@@ -55,11 +59,42 @@ private:
     QVLCVariable message;
     QVLCVariable login;
     QVLCVariable question;
+    QVLCVariable progressBar;
+signals:
+    void progressBarDestroyed (QWidget *);
 
 private slots:
     void displayMessage (vlc_object_t *, void *);
     void requestLogin (vlc_object_t *, void *);
     void requestAnswer (vlc_object_t *, void *);
+    void startProgressBar (vlc_object_t *, void *);
+    void stopProgressBar (QWidget *);
+};
+
+/* Put here instead of .cpp because of MOC */
+#include <QProgressDialog>
+
+class QVLCProgressDialog : public QProgressDialog
+{
+    Q_OBJECT
+public:
+    QVLCProgressDialog (DialogHandler *parent,
+                        struct dialog_progress_bar_t *);
+    virtual ~QVLCProgressDialog (void);
+
+private:
+    DialogHandler *handler;
+    bool cancelled;
+
+    static void update (void *, float);
+    static bool check (void *);
+    static void destroy (void *);
+private slots:
+    void saveCancel (void);
+
+signals:
+    void progressed (int);
+    void destroyed (void);
 };
 
 #endif




More information about the vlc-devel mailing list