#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
+#include <QProgressDialog>
+#include <QMutex>
-DialogHandler::DialogHandler (intf_thread_t *intf)
+QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type)
+ : object (obj), name (qfu(varname))
{
- this->intf = intf;
+ var_Create (object, qtu(name), type);
+ var_AddCallback (object, qtu(name), callback, this);
+}
+
+QVLCVariable::~QVLCVariable (void)
+{
+ var_DelCallback (object, qtu(name), callback, this);
+ var_Destroy (object, qtu(name));
+}
+
+int QVLCVariable::callback (vlc_object_t *object, const char *,
+ vlc_value_t, vlc_value_t cur, void *data)
+{
+ QVLCVariable *self = (QVLCVariable *)data;
+
+ emit self->pointerChanged (object, cur.p_address);
+ return VLC_SUCCESS;
+}
- connect (this, SIGNAL(message(const struct dialog_fatal_t *)),
- this, SLOT(displayMessage(const struct dialog_fatal_t *)),
- Qt::BlockingQueuedConnection);
- var_Create (intf, "dialog-fatal", VLC_VAR_ADDRESS);
- var_AddCallback (intf, "dialog-fatal", MessageCallback, this);
- connect (this, SIGNAL(authentication(struct dialog_login_t *)),
- this, SLOT(requestLogin(struct dialog_login_t *)),
+DialogHandler::DialogHandler (intf_thread_t *intf, QObject *_parent)
+ : intf (intf), QObject( _parent ),
+ 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),
+ progressBar (VLC_OBJECT(intf), "dialog-progress-bar", VLC_VAR_ADDRESS)
+{
+ connect (&message, SIGNAL(pointerChanged(vlc_object_t *, void *)),
+ SLOT(displayMessage(vlc_object_t *, void *)),
+ Qt::BlockingQueuedConnection);
+ connect (&login, SIGNAL(pointerChanged(vlc_object_t *, void *)),
+ SLOT(requestLogin(vlc_object_t *, void *)),
Qt::BlockingQueuedConnection);
- var_Create (intf, "dialog-login", VLC_VAR_ADDRESS);
- var_AddCallback (intf, "dialog-login", LoginCallback, this);
+ 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);
+ dialog_Register (intf);
}
DialogHandler::~DialogHandler (void)
{
dialog_Unregister (intf);
- var_DelCallback (intf, "dialog-login", LoginCallback, this);
- var_DelCallback (intf, "dialog-fatal", MessageCallback, this);
}
-int DialogHandler::MessageCallback (vlc_object_t *obj, const char *var,
- vlc_value_t, vlc_value_t value,
- void *data)
+void DialogHandler::displayMessage (vlc_object_t *, void *value)
{
- DialogHandler *self = (DialogHandler *)data;
- const dialog_fatal_t *dialog = (const dialog_fatal_t *)value.p_address;
-
- emit self->message (dialog);
- return VLC_SUCCESS;
-}
+ const dialog_fatal_t *dialog = (const dialog_fatal_t *)value;
-void DialogHandler::displayMessage (const struct dialog_fatal_t *dialog)
-{
if (dialog->modal)
QMessageBox::critical (NULL, qfu(dialog->title), qfu(dialog->message),
QMessageBox::Ok);
qfu(dialog->message));
}
-int DialogHandler::LoginCallback (vlc_object_t *obj, const char *var,
- vlc_value_t, vlc_value_t value, void *data)
-{
- DialogHandler *self = (DialogHandler *)data;
- dialog_login_t *dialog = (dialog_login_t *)value.p_address;
-
- emit self->authentication (dialog);
- return VLC_SUCCESS;
-}
-
-void DialogHandler::requestLogin (struct dialog_login_t *data)
+void DialogHandler::requestLogin (vlc_object_t *, void *value)
{
+ dialog_login_t *data = (dialog_login_t *)value;
QDialog *dialog = new QDialog;
QLayout *layout = new QVBoxLayout (dialog);
delete dialog;
}
+
+void DialogHandler::requestAnswer (vlc_object_t *, void *value)
+{
+ dialog_question_t *data = (dialog_question_t *)value;
+
+ QMessageBox *box = new QMessageBox (QMessageBox::Question,
+ qfu(data->title), qfu(data->message));
+ QAbstractButton *yes = (data->yes != NULL)
+ ? box->addButton ("&" + qfu(data->yes), QMessageBox::YesRole) : NULL;
+ QAbstractButton *no = (data->no != NULL)
+ ? box->addButton ("&" + qfu(data->no), QMessageBox::NoRole) : NULL;
+ QAbstractButton *cancel = (data->cancel != NULL)
+ ? box->addButton ("&" + qfu(data->cancel), QMessageBox::RejectRole)
+ : NULL;
+
+ box->exec ();
+
+ int answer;
+ if (box->clickedButton () == yes)
+ answer = 1;
+ else
+ if (box->clickedButton () == no)
+ answer = 2;
+ else
+ answer = 3;
+
+ 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(described(const QString&)),
+ SLOT(setLabelText(const QString&)));
+ 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, const char *text, float value)
+{
+ QVLCProgressDialog *self = static_cast<QVLCProgressDialog *>(priv);
+
+ if (text != NULL)
+ emit self->described (qfu(text));
+ 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;
+}