1
/****************************************************************************
2
** servicesdlg.cpp - a dialog for browsing Jabber services/agents/transports
3
** Copyright (C) 2001, 2002 Justin Karneges
5
** This program is free software; you can redistribute it and/or
6
** modify it under the terms of the GNU General Public License
7
** as published by the Free Software Foundation; either version 2
8
** of the License, or (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
19
****************************************************************************/
22
#include<qpushbutton.h>
25
#include"servicesdlg.h"
29
static ServicesDlg *services_ptr = 0;
31
ServicesDlg::ServicesDlg(int _localStatus, QWidget *parent, const char *name)
32
:ServicesUI(parent, name, FALSE, WDestructiveClose)
34
setCaption(CAP(tr("Manage Services")));
35
setIcon(transport2icon("", STATUS_ONLINE));
40
localStatus = _localStatus;
42
busy = new BusyWidget(this);
43
vb_side->addWidget(busy);
45
pb_register->setEnabled(FALSE);
46
pb_search->setEnabled(FALSE);
47
pb_refresh->setEnabled(FALSE);
49
connect(pb_refresh, SIGNAL(clicked()), SLOT(doRefresh()));
50
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
51
connect(pb_register, SIGNAL(clicked()), SLOT(serviceRegister()));
52
connect(pb_search, SIGNAL(clicked()), SLOT(serviceSearch()));
53
connect(li_services, SIGNAL(highlighted(int)), SLOT(serviceSelected(int)));
54
connect(li_services, SIGNAL(doubleClicked(QListBoxItem *)), SLOT(doubleClicked(QListBoxItem *)));
59
ServicesDlg::~ServicesDlg()
64
/* static */ ServicesDlg *ServicesDlg::find()
69
void ServicesDlg::closeEvent(QCloseEvent *e)
71
// cancel active transaction (refresh or getform)
73
signalCancelTransaction(id);
76
// accept the close event
80
void ServicesDlg::restoreWidgets()
83
pb_refresh->setEnabled(TRUE);
84
li_services->setEnabled(TRUE);
86
serviceSelected(li_services->currentItem());
90
void ServicesDlg::doRefresh()
92
if(localStatus == STATUS_OFFLINE) {
93
QMessageBox::warning(this, tr("Warning"), tr("You must be connected to the server to manage services. Please login first."));
101
pb_refresh->setEnabled(FALSE);
102
pb_register->setEnabled(FALSE);
103
pb_search->setEnabled(FALSE);
108
void ServicesDlg::loadSuccess(JabRoster *list)
110
servicesList = *list;
111
li_services->clear();
113
QPtrListIterator<JabRosterEntry> it(servicesList.list);
114
JabRosterEntry *entry;
115
for(; (entry = it.current()); ++it) {
116
li_services->insertItem(transport2icon(entry->jid), entry->nick);
125
if(li_services->count() > 0)
126
li_services->setSelected(0, TRUE);
129
void ServicesDlg::loadFail()
136
QMessageBox::critical(this, tr("Error"), tr("There was an error retrieving the list of services."));
140
void ServicesDlg::loadFormSuccess()
149
void ServicesDlg::loadFormFail()
156
if(actionType == SERVICESDLG_ACT_REGISTER)
157
QMessageBox::critical(this, tr("Error"), tr("There was an error retrieving the registration form for the %1 service.").arg(regname));
159
QMessageBox::critical(this, tr("Error"), tr("There was an error retrieving the search form for the %1 service.").arg(regname));
163
void ServicesDlg::localUpdate(const JabRosterEntry &e)
165
int oldstate = localStatus;
166
localStatus = e.localStatus();
168
if(localStatus == STATUS_OFFLINE) {
174
pb_register->setEnabled(FALSE);
175
pb_search->setEnabled(FALSE);
176
pb_refresh->setEnabled(FALSE);
177
li_services->clear();
178
servicesList.clear();
182
if(oldstate == STATUS_OFFLINE) {
183
doRefresh(); // this will also turn the refresh button on when finished
188
void ServicesDlg::doubleClicked(QListBoxItem *)
193
void ServicesDlg::serviceSelected(int x)
197
JabRosterEntry *entry = servicesList.list.at(x);
201
if(localStatus == STATUS_OFFLINE)
204
pb_register->setEnabled(entry->isRegisterable);
205
pb_search->setEnabled(entry->isSearchable);
208
void ServicesDlg::serviceRegister()
210
if(!pb_register->isEnabled())
213
JabRosterEntry *entry = servicesList.list.at(li_services->currentItem());
217
//printf("ServicesDlg: getting registration form: %s\n", entry->nick.latin1());
218
regname = entry->jid;
219
actionType = SERVICESDLG_ACT_REGISTER;
222
li_services->setEnabled(FALSE);
223
pb_refresh->setEnabled(FALSE);
224
pb_register->setEnabled(FALSE);
225
pb_search->setEnabled(FALSE);
230
signalGetRegForm(entry->jid, &id);
233
void ServicesDlg::serviceSearch()
235
JabRosterEntry *entry = servicesList.list.at(li_services->currentItem());
239
//printf("ServicesDlg: getting search form: %s\n", entry->nick.latin1());
240
regname = entry->jid;
241
actionType = SERVICESDLG_ACT_SEARCH;
244
li_services->setEnabled(FALSE);
245
pb_refresh->setEnabled(FALSE);
246
pb_register->setEnabled(FALSE);
247
pb_search->setEnabled(FALSE);
252
signalSearch(entry->jid, &id);
256
RegistrationDlg::RegistrationDlg(const JabForm &_form, QWidget *parent, const char *name)
257
:QDialog(parent, name, FALSE, WDestructiveClose), UniqueWindow(TRUE, "RegistrationDlg", this, cleanJid(_form.jid.s()))
262
setCaption(CAP(tr("Service Registration")));
265
QVBoxLayout *vb1 = new QVBoxLayout(this, 4);
267
l = new QLabel(QString(tr("Registration for \"%1\"")).arg(form.jid.s()), this);
268
l->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
270
l = new QLabel(QString("<qt>%1</qt>").arg(form.instructions), this);
271
l->setFrameStyle( QFrame::Panel | QFrame::Sunken );
274
QGridLayout *gr = new QGridLayout(vb1, 2);
276
lb_field.setAutoDelete(TRUE);
277
le_field.setAutoDelete(TRUE);
278
QPtrListIterator<JabFormField> it(form);
280
for(; (f = it.current()); ++it) {
281
QLabel *lb = new QLabel(f->fieldName(), this);
282
QLineEdit *le = new QLineEdit(this);
283
if(f->type() == JabFormField::password)
284
le->setEchoMode(QLineEdit::Password);
285
le->setText(f->value());
290
gr->addWidget(lb, at, 0);
291
gr->addWidget(le, at, 1);
295
QHBoxLayout *hb1 = new QHBoxLayout(vb1);
296
busy = new BusyWidget(this);
298
hb1->addWidget(busy);
300
QFrame *line = new QFrame(this);
301
line->setFixedHeight(2);
302
line->setFrameStyle(QFrame::HLine | QFrame::Sunken);
303
vb1->addWidget(line);
305
QHBoxLayout *hb2 = new QHBoxLayout(vb1);
306
pb_register = new QPushButton(tr("&Register"), this);
307
connect(pb_register, SIGNAL(clicked()), SLOT(doRegSubmit()));
308
hb2->addWidget(pb_register);
310
pb_close = new QPushButton(tr("&Close"), this);
311
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
312
hb2->addWidget(pb_close);
316
resize(320, height() + 80);
319
void RegistrationDlg::closeEvent(QCloseEvent *e)
322
//QMessageBox::information(this, tr("Busy"), tr("Registration has already been submitted, it cannot be canceled. Please wait for the server to respond."));
330
void RegistrationDlg::putRegFormResponse(bool ok, const QString &err)
336
QMessageBox::information(this, tr("Success"), tr("Registration was successful."));
339
QMessageBox::critical(this, tr("Failed"), QString(tr("Registration failed. Reason:\n\"%1\"")).arg(err));
345
void RegistrationDlg::doRegSubmit()
347
JabForm submitform = form;
349
// import the changes back into the form.
350
// the QPtrList of QLineEdits should be in the same order
351
QPtrListIterator<JabFormField> it(submitform);
352
QPtrListIterator<QLineEdit> lit(le_field);
354
for(; (f = it.current());) {
355
QLineEdit *le = lit.current();
356
f->setValue(le->text());
361
pb_register->setEnabled(FALSE);
362
pb_close->setEnabled(FALSE);
366
signalSubmitForm(submitform, &id);
369
void RegistrationDlg::localUpdate(const JabRosterEntry &e)
371
int localStatus = e.localStatus();
373
// if the user goes offline then cancel the form
374
if(localStatus == STATUS_OFFLINE) {
376
putRegFormResponse(FALSE, "Disconnected"); // <-- this will turn off busy also
382
/*static*/ RegistrationDlg * RegistrationDlg::find(const QString &xjid)
384
return (RegistrationDlg *)UniqueWindowBank::find("RegistrationDlg", cleanJid(xjid));