1 /*****************************************************************************
2 * external.cpp : Dialogs from other LibVLC core and other plugins
3 ****************************************************************************
4 * Copyright (C) 2009 RĂ©mi Denis-Courmont
5 * Copyright (C) 2006 the VideoLAN team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
27 #include "external.hpp"
29 #include <vlc_dialog.h>
32 #include <QDialogButtonBox>
35 #include <QMessageBox>
36 #include <QProgressDialog>
39 DialogHandler::DialogHandler (intf_thread_t *intf)
41 message (VLC_OBJECT(intf), "dialog-fatal", VLC_VAR_ADDRESS),
42 login (VLC_OBJECT(intf), "dialog-login", VLC_VAR_ADDRESS),
43 question (VLC_OBJECT(intf), "dialog-question", VLC_VAR_ADDRESS),
44 progressBar (VLC_OBJECT(intf), "dialog-progress-bar", VLC_VAR_ADDRESS)
46 connect (&message, SIGNAL(pointerChanged(vlc_object_t *, void *)),
47 SLOT(displayMessage(vlc_object_t *, void *)),
48 Qt::BlockingQueuedConnection);
49 connect (&login, SIGNAL(pointerChanged(vlc_object_t *, void *)),
50 SLOT(requestLogin(vlc_object_t *, void *)),
51 Qt::BlockingQueuedConnection);
52 connect (&question, SIGNAL(pointerChanged(vlc_object_t *, void *)),
53 SLOT(requestAnswer(vlc_object_t *, void *)),
54 Qt::BlockingQueuedConnection);
55 connect (&progressBar, SIGNAL(pointerChanged(vlc_object_t *, void *)),
56 SLOT(startProgressBar(vlc_object_t *, void *)),
57 Qt::BlockingQueuedConnection);
59 SIGNAL(progressBarDestroyed(QWidget *)),
60 SLOT(stopProgressBar(QWidget *)));
62 dialog_Register (intf);
65 DialogHandler::~DialogHandler (void)
67 dialog_Unregister (intf);
70 void DialogHandler::displayMessage (vlc_object_t *, void *value)
72 const dialog_fatal_t *dialog = (const dialog_fatal_t *)value;
75 QMessageBox::critical (NULL, qfu(dialog->title), qfu(dialog->message),
78 if (config_GetInt (intf, "qt-error-dialogs"))
79 ErrorsDialog::getInstance (intf)->addError(qfu(dialog->title),
80 qfu(dialog->message));
83 void DialogHandler::requestLogin (vlc_object_t *, void *value)
85 dialog_login_t *data = (dialog_login_t *)value;
86 QDialog *dialog = new QDialog;
87 QLayout *layout = new QVBoxLayout (dialog);
89 dialog->setWindowTitle (qfu(data->title));
90 layout->setMargin (2);
92 /* User name and password fields */
93 QWidget *panel = new QWidget (dialog);
94 QGridLayout *grid = new QGridLayout;
95 grid->addWidget (new QLabel (qfu(data->message)), 0, 0, 1, 2);
97 QLineEdit *userLine = new QLineEdit;
98 grid->addWidget (new QLabel (qtr("User name")), 1, 0);
99 grid->addWidget (userLine, 1, 1);
101 QLineEdit *passLine = new QLineEdit;
102 passLine->setEchoMode (QLineEdit::Password);
103 grid->addWidget (new QLabel (qtr("Password")), 2, 0);
104 grid->addWidget (passLine, 2, 1);
106 panel->setLayout (grid);
107 layout->addWidget (panel);
109 /* OK, Cancel buttons */
110 QDialogButtonBox *buttonBox;
111 buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok
112 | QDialogButtonBox::Cancel);
113 connect (buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
114 connect (buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
115 layout->addWidget (buttonBox);
118 dialog->setLayout (layout);
122 *data->username = strdup (qtu(userLine->text ()));
123 *data->password = strdup (qtu(passLine->text ()));
126 *data->username = *data->password = NULL;
131 void DialogHandler::requestAnswer (vlc_object_t *, void *value)
133 dialog_question_t *data = (dialog_question_t *)value;
135 QMessageBox *box = new QMessageBox (QMessageBox::Question,
136 qfu(data->title), qfu(data->message));
137 QAbstractButton *yes = (data->yes != NULL)
138 ? box->addButton ("&" + qfu(data->yes), QMessageBox::YesRole) : NULL;
139 QAbstractButton *no = (data->no != NULL)
140 ? box->addButton ("&" + qfu(data->no), QMessageBox::NoRole) : NULL;
141 QAbstractButton *cancel = (data->cancel != NULL)
142 ? box->addButton ("&" + qfu(data->cancel), QMessageBox::RejectRole)
148 if (box->clickedButton () == yes)
151 if (box->clickedButton () == no)
157 data->answer = answer;
161 QVLCProgressDialog::QVLCProgressDialog (DialogHandler *parent,
162 struct dialog_progress_bar_t *data)
163 : QProgressDialog (qfu(data->message),
164 data->cancel ? ("&" + qfu(data->cancel)) : 0, 0, 1000),
168 if (data->title != NULL)
169 setWindowTitle (qfu(data->title));
170 setMinimumDuration (0);
172 connect (this, SIGNAL(progressed(int)), SLOT(setValue(int)));
173 connect (this, SIGNAL(described(const QString&)),
174 SLOT(setLabelText(const QString&)));
175 connect (this, SIGNAL(canceled(void)), SLOT(saveCancel(void)));
177 data->pf_update = update;
178 data->pf_check = check;
179 data->pf_destroy = destroy;
183 QVLCProgressDialog::~QVLCProgressDialog (void)
187 void QVLCProgressDialog::update (void *priv, const char *text, float value)
189 QVLCProgressDialog *self = static_cast<QVLCProgressDialog *>(priv);
192 emit self->described (qfu(text));
193 emit self->progressed ((int)(value * 1000.));
196 static QMutex cancel_mutex;
198 bool QVLCProgressDialog::check (void *priv)
200 QVLCProgressDialog *self = static_cast<QVLCProgressDialog *>(priv);
201 QMutexLocker locker (&cancel_mutex);
202 return self->cancelled;
205 void QVLCProgressDialog::destroy (void *priv)
207 QVLCProgressDialog *self = static_cast<QVLCProgressDialog *>(priv);
209 emit self->handler->progressBarDestroyed (self);
212 void QVLCProgressDialog::saveCancel (void)
214 QMutexLocker locker (&cancel_mutex);
218 void DialogHandler::startProgressBar (vlc_object_t *, void *value)
220 dialog_progress_bar_t *data = (dialog_progress_bar_t *)value;
221 QWidget *dlg = new QVLCProgressDialog (this, data);
226 void DialogHandler::stopProgressBar (QWidget *dlg)