1 /*****************************************************************************
2 * external.hpp : 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>
37 QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type)
38 : object (obj), name (qfu(varname))
40 var_Create (object, qtu(name), type);
41 var_AddCallback (object, qtu(name), callback, this);
44 QVLCVariable::~QVLCVariable (void)
46 var_DelCallback (object, qtu(name), callback, this);
47 var_Destroy (object, qtu(name));
50 int QVLCVariable::callback (vlc_object_t *object, const char *,
51 vlc_value_t, vlc_value_t cur, void *data)
53 QVLCVariable *self = (QVLCVariable *)data;
54 emit self->pointerChanged (object, cur.p_address);
58 DialogHandler::DialogHandler (intf_thread_t *intf)
60 message (VLC_OBJECT(intf), "dialog-fatal", VLC_VAR_ADDRESS),
61 login (VLC_OBJECT(intf), "dialog-login", VLC_VAR_ADDRESS),
62 question (VLC_OBJECT(intf), "dialog-question", VLC_VAR_ADDRESS)
64 connect (&message, SIGNAL(pointerChanged(vlc_object_t *, void *)),
65 SLOT(displayMessage(vlc_object_t *, void *)),
66 Qt::BlockingQueuedConnection);
67 connect (&login, SIGNAL(pointerChanged(vlc_object_t *, void *)),
68 SLOT(requestLogin(vlc_object_t *, void *)),
69 Qt::BlockingQueuedConnection);
70 connect (&question, SIGNAL(pointerChanged(vlc_object_t *, void *)),
71 SLOT(requestAnswer(vlc_object_t *, void *)),
72 Qt::BlockingQueuedConnection);
74 dialog_Register (intf);
77 DialogHandler::~DialogHandler (void)
79 dialog_Unregister (intf);
82 void DialogHandler::displayMessage (vlc_object_t *, void *value)
84 const dialog_fatal_t *dialog = (const dialog_fatal_t *)value;
87 QMessageBox::critical (NULL, qfu(dialog->title), qfu(dialog->message),
90 if (config_GetInt (intf, "qt-error-dialogs"))
91 ErrorsDialog::getInstance (intf)->addError(qfu(dialog->title),
92 qfu(dialog->message));
95 void DialogHandler::requestLogin (vlc_object_t *, void *value)
97 dialog_login_t *data = (dialog_login_t *)value;
98 QDialog *dialog = new QDialog;
99 QLayout *layout = new QVBoxLayout (dialog);
101 dialog->setWindowTitle (qfu(data->title));
102 layout->setMargin (2);
104 /* User name and password fields */
105 QWidget *panel = new QWidget (dialog);
106 QGridLayout *grid = new QGridLayout;
107 grid->addWidget (new QLabel (qfu(data->message)), 0, 0, 1, 2);
109 QLineEdit *userLine = new QLineEdit;
110 grid->addWidget (new QLabel (qtr("User name")), 1, 0);
111 grid->addWidget (userLine, 1, 1);
113 QLineEdit *passLine = new QLineEdit;
114 passLine->setEchoMode (QLineEdit::Password);
115 grid->addWidget (new QLabel (qtr("Password")), 2, 0);
116 grid->addWidget (passLine, 2, 1);
118 panel->setLayout (grid);
119 layout->addWidget (panel);
121 /* OK, Cancel buttons */
122 QDialogButtonBox *buttonBox;
123 buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok
124 | QDialogButtonBox::Cancel);
125 connect (buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
126 connect (buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
127 layout->addWidget (buttonBox);
130 dialog->setLayout (layout);
134 *data->username = strdup (qtu(userLine->text ()));
135 *data->password = strdup (qtu(passLine->text ()));
138 *data->username = *data->password = NULL;
143 void DialogHandler::requestAnswer (vlc_object_t *, void *value)
145 dialog_question_t *data = (dialog_question_t *)value;
147 QMessageBox *box = new QMessageBox (QMessageBox::Question,
148 qfu(data->title), qfu(data->message));
149 QAbstractButton *yes = (data->yes != NULL)
150 ? box->addButton ("&" + qfu(data->yes), QMessageBox::YesRole) : NULL;
151 QAbstractButton *no = (data->no != NULL)
152 ? box->addButton ("&" + qfu(data->no), QMessageBox::NoRole) : NULL;
153 QAbstractButton *cancel = (data->cancel != NULL)
154 ? box->addButton ("&" + qfu(data->cancel), QMessageBox::RejectRole)
160 if (box->clickedButton () == yes)
163 if (box->clickedButton () == no)
169 data->answer = answer;