1
/****************************************************************************
2
** searchdlg.cpp - a dialog for searching for Jabber contacts
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
****************************************************************************/
24
#include<qpushbutton.h>
29
SearchDlg::SearchDlg(const QString &jid, const JabForm &_form, int _localStatus, QWidget *parent, const char *name)
30
:SearchUI(parent, name, WDestructiveClose), UniqueWindow(TRUE, "SearchDlg", this, cleanJid(jid))
34
localStatus = _localStatus;
36
setCaption(QString(tr("Search: %1")).arg(jid));
37
//setIcon(transport2icon("", STATUS_ONLINE));
44
w = new QWidget(this);
45
busy = new BusyWidget(w);
46
QHBoxLayout *hb1 = new QHBoxLayout(w);
50
int i = SearchUILayout->findWidget(line);
51
SearchUILayout->insertWidget(i, w);
54
lb = new QLabel(QString("<qt>%1</qt>").arg(form.instructions), gb_search);
55
lb->setFrameStyle( QFrame::Panel | QFrame::Sunken );
56
gb_searchLayout->insertWidget(0, lb);
59
w = new QWidget(gb_search);
60
QGridLayout *gr = new QGridLayout(w, 2, 1, 4, 8);
62
lb_field.setAutoDelete(TRUE);
63
le_field.setAutoDelete(TRUE);
64
QPtrListIterator<JabFormField> it(form);
66
for(; (f = it.current()); ++it) {
67
QLabel *lb = new QLabel(f->fieldName(), w);
68
QLineEdit *le = new QLineEdit(w);
69
le->setMinimumWidth(120);
70
if(f->type() == JabFormField::password)
71
le->setEchoMode(QLineEdit::Password);
72
le->setText(f->value());
77
gr->addWidget(lb, at, 0);
78
gr->addWidget(le, at, 1);
81
connect(le, SIGNAL(returnPressed()), this, SLOT(doSubmitForm()));
83
gb_searchLayout->insertWidget(1, w);
86
pb_add->setEnabled(FALSE);
87
pb_info->setEnabled(FALSE);
88
pb_stop->setEnabled(FALSE);
90
if(localStatus == STATUS_OFFLINE)
91
pb_search->setEnabled(FALSE);
93
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
94
connect(pb_search, SIGNAL(clicked()), SLOT(doSubmitForm()));
95
connect(pb_stop, SIGNAL(clicked()), SLOT(doStop()));
96
connect(pb_add, SIGNAL(clicked()), SLOT(doAdd()));
97
connect(pb_info, SIGNAL(clicked()), SLOT(doInfo()));
98
connect(lv_results, SIGNAL(selectionChanged()), SLOT(selectionChanged()));
101
SearchDlg::~SearchDlg()
105
/* static */ SearchDlg *SearchDlg::find(const QString &xjid)
107
return (SearchDlg *)UniqueWindowBank::find("SearchDlg", cleanJid(xjid));
110
void SearchDlg::closeEvent(QCloseEvent *e)
112
// cancel active transaction
114
signalCancelTransaction(id);
120
void SearchDlg::localUpdate(const JabRosterEntry &e)
122
int oldstate = localStatus;
123
localStatus = e.localStatus();
125
if(localStatus == STATUS_OFFLINE) {
131
pb_search->setEnabled(FALSE);
132
pb_stop->setEnabled(FALSE);
137
if(oldstate == STATUS_OFFLINE) {
138
pb_search->setEnabled(TRUE);
143
void SearchDlg::addEntry(const QString &jid, const QString &nick, const QString &first, const QString &last, const QString &email)
145
QListViewItem *lvi = new QListViewItem(lv_results);
146
lvi->setText(0, nick);
147
//lvi->setPixmap(0, *pix_online);
148
lvi->setText(1, first);
149
lvi->setText(2, last);
150
lvi->setText(3, email);
151
lvi->setText(4, jid);
154
void SearchDlg::clear()
158
pb_add->setEnabled(FALSE);
159
pb_info->setEnabled(FALSE);
162
void SearchDlg::doSubmitForm()
164
if(isBusy || !pb_search->isEnabled())
169
JabForm submitform = form;
171
// import the changes back into the form.
172
// the QPtrList of QLineEdits should be in the same order
173
QPtrListIterator<JabFormField> it(submitform);
174
QPtrListIterator<QLineEdit> lit(le_field);
176
for(; (f = it.current());) {
177
QLineEdit *le = lit.current();
178
f->setValue(le->text());
183
pb_search->setEnabled(FALSE);
184
pb_stop->setEnabled(TRUE);
189
signalSubmitForm(submitform, &id);
192
void SearchDlg::doStop()
194
if(!isBusy || !pb_stop->isEnabled())
197
signalCancelTransaction(id);
201
pb_search->setEnabled(TRUE);
202
pb_stop->setEnabled(FALSE);
205
void SearchDlg::putSearchFormResponse(JabRoster *p)
211
pb_search->setEnabled(TRUE);
212
pb_stop->setEnabled(FALSE);
216
// fill out the results
217
for(JabRosterEntry *entry = p->first(); entry; entry = p->next())
218
addEntry(entry->jid, entry->nick, entry->first, entry->last, entry->email);
221
QMessageBox::information(this, tr("Error"), tr("There was an error retrieving search results."));
225
void SearchDlg::selectionChanged()
227
QListViewItem *i = lv_results->selectedItem();
229
pb_add->setEnabled(FALSE);
230
pb_info->setEnabled(FALSE);
233
pb_add->setEnabled(TRUE);
234
pb_info->setEnabled(TRUE);
237
void SearchDlg::doAdd()
239
QListViewItem *i = lv_results->selectedItem();
243
aAdd(i->text(4), i->text(0), "");
245
QMessageBox::information(this, tr("Add User"), QString(tr("%1 has been added to your contact list.")).arg(i->text(0)));
248
void SearchDlg::doInfo()
250
QListViewItem *i = lv_results->selectedItem();