1
/****************************************************************************
2
** adduserdlg.cpp - a dialog for adding a contact
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
****************************************************************************/
2
* adduserdlg.cpp - dialog for adding 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 library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
21
#include"adduserdlg.h"
24
24
#include<qlayout.h>
25
25
#include<qpushbutton.h>
28
26
#include<qmessagebox.h>
29
28
#include<qgroupbox.h>
29
#include<qstringlist.h>
32
#include"xmpp_tasks.h"
33
#include"psiaccount.h"
34
#include"busywidget.h"
33
static AddUserDlg *add_ptr = 0;
35
AddUserDlg::AddUserDlg(const QStringList &_services, const QStringList &names, const QStringList &groups, int _localStatus, QWidget *parent, const char *name)
36
:AddUserUI(parent, name, FALSE, WDestructiveClose)
41
localStatus = _localStatus;
45
setCaption(CAP(tr("Add User")));
48
busy = new BusyWidget(this);
49
hb_bottom->insertWidget(0, busy);
36
#include"iconwidget.h"
38
class AddUserDlg::Private
49
AddUserDlg::AddUserDlg(const QStringList &services, const QStringList &names, const QStringList &groups, PsiAccount *pa)
50
:AddUserUI(0, 0, false, WDestructiveClose)
54
d->pa->dialogRegister(this);
55
connect(d->pa, SIGNAL(updatedActivity()), SLOT(pa_updatedActivity()));
56
d->services = services;
59
setCaption(CAP(caption()));
60
setIcon(IconsetFactory::icon("psi/addContact"));
51
64
QStringList::ConstIterator it1 = services.begin();
52
65
QStringList::ConstIterator it2 = names.begin();
53
66
for(; it1 != services.end(); ++it1, ++it2)
54
cb_service->insertItem(transport2icon(*it1, STATUS_ONLINE), *it2);
67
cb_service->insertItem(is->status(*it1, STATUS_ONLINE), *it2);
55
68
connect(cb_service, SIGNAL(activated(int)), SLOT(serviceActivated(int)));
70
connect(le_transPrompt, SIGNAL(textChanged(const QString &)), SLOT(le_transPromptChanged(const QString &)));
71
pb_transGet->setEnabled(false);
57
73
QString str = tr("<None>");
58
74
cb_group->insertItem(str);
59
75
cb_group->insertStringList(groups);
60
cb_group->setAutoCompletion(TRUE);
76
str = ContactView::tr("Hidden");
77
if(!groups.contains(str))
78
cb_group->insertItem(str);
79
cb_group->setAutoCompletion(true);
62
pb_add->setDefault(TRUE);
81
pb_add->setDefault(true);
63
82
connect(pb_add, SIGNAL(clicked()), SLOT(ok()));
64
83
connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
65
84
connect(pb_transGet, SIGNAL(clicked()), SLOT(getTransID()));
66
//connect(le_transPrompt, SIGNAL(returnPressed()), SLOT(getTransID()));
68
cb_service->setFocus();
86
ck_authreq->setChecked(true);
87
ck_close->setChecked(true);
71
92
AddUserDlg::~AddUserDlg()
76
signalCancelTransaction(id);
95
d->pa->dialogUnregister(this);
79
/* static */ AddUserDlg *AddUserDlg::find()
99
void AddUserDlg::pa_updatedActivity()
101
if(!d->pa->loggedIn())
84
105
void AddUserDlg::ok()
87
108
QMessageBox::information(this, tr("Add User: Error"), tr("Please fill in the Jabber ID of the person you wish to add."));
90
if(le_jid->text().find('@') == -1) {
91
QMessageBox::information(this, tr("Add User: Error"), tr("The Jabber ID you entered does not contain a '@' symbol.\nMake sure you enter a fully qualified Jabber ID in the form \"user@hostname\"."));
111
Jid j(le_jid->text().stripWhiteSpace());
113
QMessageBox::information(this, tr("Add User: Error"), tr("The Jabber ID you entered is not valid!\nMake sure you enter a fully qualified Jabber ID."));
96
info.jid = le_jid->text();
97
info.nick = le_nick->text();
99
117
QString gname = cb_group->currentText();
100
if(gname == tr("<None>"))
119
if(gname != tr("<None>"))
122
add(j, le_nick->text(), list, ck_authreq->isChecked());
124
QMessageBox::information(this, tr("Add User: Success"), tr("Added %1 to your roster.").arg(j.full()));
126
if(ck_close->isChecked())
130
le_nick->setText("");
109
135
void AddUserDlg::serviceActivated(int x)
112
signalCancelTransaction(id);
137
if(d->busy->isActive()) {
116
gb_trans->setEnabled(FALSE);
142
gb_trans->setEnabled(false);
117
143
le_transPrompt->setText("");
124
if(x >= 0 && x < (int)services.count()) {
125
//printf("Selected: [%s]\n", services[x].latin1());
126
signalGetGateway(services[x], &id);
132
void AddUserDlg::localUpdate(const JabRosterEntry &e)
134
localStatus = e.localStatus();
136
if(localStatus == STATUS_OFFLINE)
140
void AddUserDlg::slotGetGatewayResponse(const QString &_id, bool ok, const QString &desc)
149
gb_trans->setEnabled(TRUE);
150
lb_transDesc->setText(desc);
158
void AddUserDlg::slotSetGatewayResponse(const QString &_id, bool ok, const QString &jid)
164
cb_service->setEnabled(TRUE);
165
le_transPrompt->setEnabled(TRUE);
166
pb_transGet->setEnabled(TRUE);
171
le_jid->setText(jid);
172
le_nick->setText(le_transPrompt->text());
173
le_transPrompt->setText("");
174
le_jid->setCursorPosition(0);
175
le_nick->setCursorPosition(0);
178
le_nick->selectAll();
182
le_transPrompt->setFocus();
150
if(x >= 0 && x < (int)d->services.count()) {
151
d->jt = new JT_Gateway(d->pa->client()->rootTask());
152
connect(d->jt, SIGNAL(finished()), SLOT(jt_getFinished()));
153
d->jt->get(Jid(d->services[x]));
159
void AddUserDlg::le_transPromptChanged(const QString &str)
161
pb_transGet->setEnabled(!str.isEmpty());
187
164
void AddUserDlg::getTransID()
189
cb_service->setEnabled(FALSE);
190
le_transPrompt->setEnabled(FALSE);
191
pb_transGet->setEnabled(FALSE);
193
signalSetGateway(services[cb_service->currentItem()-1], le_transPrompt->text(), &id);
198
void AddUserDlg::errorGateway()
166
cb_service->setEnabled(false);
167
le_transPrompt->setEnabled(false);
168
pb_transGet->setEnabled(false);
170
d->jt = new JT_Gateway(d->pa->client()->rootTask());
171
connect(d->jt, SIGNAL(finished()), SLOT(jt_setFinished()));
172
d->jt->set(Jid(d->services[cb_service->currentItem()-1]), le_transPrompt->text());
177
void AddUserDlg::jt_getFinished()
180
JT_Gateway *jt = d->jt;
184
gb_trans->setEnabled(true);
185
lb_transDesc->setText(jt->desc());
188
errorGateway(cb_service->currentText(), jt->statusString());
192
void AddUserDlg::jt_setFinished()
195
cb_service->setEnabled(true);
196
le_transPrompt->setEnabled(true);
197
pb_transGet->setEnabled(true);
199
JT_Gateway *jt = d->jt;
203
le_jid->setText(jt->prompt());
204
le_nick->setText(le_transPrompt->text());
205
le_transPrompt->setText("");
206
le_jid->setCursorPosition(0);
207
le_nick->setCursorPosition(0);
210
le_nick->selectAll();
213
errorGateway(cb_service->currentText(), jt->statusString());
214
le_transPrompt->setFocus();
218
void AddUserDlg::errorGateway(const QString &str, const QString &err)
200
220
QMessageBox::information(this, CAP(tr("Error")), tr("<qt>\n"
201
"There was an error getting the Service ID translation information. "
202
"The \"%1\" service may not support this feature. In this case you "
203
"will need to enter the Jabber ID manually for the contact you wish "
204
"to add. Examples:<br>\n"
206
" jabberuser@somehost.com<br>\n"
207
" aoluser@[Jabber ID of AIM Transport]<br>\n"
208
" 1234567@[Jabber ID of ICQ Transport]<br>\n"
209
" joe%hotmail.com@[Jabber ID of MSN Transport]<br>\n"
210
).arg(cb_service->currentText())
221
"There was an error getting the Service ID translation information from \"%1\".<br>"
224
"The service may not support this feature. In this case you "
225
"will need to enter the Jabber ID manually for the contact you wish "
226
"to add. Examples:<br>"
228
" jabberuser@somehost.com<br>"
229
" aoluser@[Jabber ID of AIM Transport]<br>"
230
" 1234567@[Jabber ID of ICQ Transport]<br>"
231
" joe%hotmail.com@[Jabber ID of MSN Transport]<br>"
232
" yahooUser@[Jabber ID of Yahoo Transport]<br>"
234
).arg(str).arg(err));