1
/****************************************************************************
2
** infodlg.cpp - show contact info
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
* infodlg.cpp - handle vcard
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"infodlg.h"
22
23
#include<qlayout.h>
23
25
#include<qtabwidget.h>
24
26
#include<qpushbutton.h>
25
27
#include<qlineedit.h>
26
28
#include<qmessagebox.h>
29
InfoDlg::InfoDlg(int _type, const QString &jid, const VCard &_vcard, int _localStatus, QWidget *parent, const char *name)
30
:InfoUI(parent, name, FALSE, WDestructiveClose), UniqueWindow(TRUE, "InfoDlg", this, cleanJid(jid))
37
QWidget *w = new QWidget(this);
38
busy = new BusyWidget(w);
39
QHBoxLayout *hb1 = new QHBoxLayout(w);
43
int n = InfoDialog1Layout->findWidget(tabwidget);
44
InfoDialog1Layout->insertWidget(n+1, w);
49
if(_localStatus == STATUS_OFFLINE) {
50
pb_refresh->setEnabled(FALSE);
51
pb_submit->setEnabled(FALSE);
31
#include"xmpp_vcard.h"
32
#include"xmpp_tasks.h"
33
#include"psiaccount.h"
34
#include"busywidget.h"
36
#include"vcardfactory.h"
37
#include"iconwidget.h"
41
class InfoDlg::Private
57
InfoDlg::InfoDlg(int type, const Jid &j, const VCard &vcard, PsiAccount *pa, QWidget *parent, const char *name, bool cacheVCard)
58
:InfoUI(parent, name, false, WDestructiveClose)
67
d->pa->dialogRegister(this, j);
68
d->cacheVCard = cacheVCard;
72
te_desc->setTextFormat(QTextEdit::PlainText);
74
setCaption(d->jid.full());
76
setIcon(IconsetFactory::icon("psi/vCard"));
54
79
connect(pb_refresh, SIGNAL(clicked()), this, SLOT(doRefresh()));
55
80
connect(te_desc, SIGNAL(textChanged()), this, SLOT(textChanged()));
58
if(type == INFODLG_USER) {
59
83
connect(pb_submit, SIGNAL(clicked()), this, SLOT(doSubmit()));
69
void InfoDlg::closeEvent(QCloseEvent *e)
95
d->pa->dialogUnregister(this);
99
/*void InfoDlg::closeEvent(QCloseEvent *e)
105
void InfoDlg::done(int r)
71
107
// don't close if submitting
72
if(isBusy && actionType == 1) {
108
if(d->busy->isActive() && d->actionType == 1)
77
if(type == INFODLG_USER && edited()) {
78
bool x = QMessageBox::information(this, tr("Warning"), tr("You have not published your account information changes.\nAre you sure you want to discard them?"), tr("Close and discard"), tr("Don't close"));
111
if(d->type == Self && edited()) {
112
int n = QMessageBox::information(this, tr("Warning"), tr("You have not published your account information changes.\nAre you sure you want to discard them?"), tr("Close and discard"), tr("Don't close"));
85
117
// cancel active transaction (refresh only)
86
if(isBusy && actionType == 0) {
87
signalCancelTransaction(id);
93
void InfoDlg::localUpdate(const JabRosterEntry &e)
95
int localStatus = e.localStatus();
97
// if the user goes offline then cancel the request
98
if(localStatus == STATUS_OFFLINE) {
103
// if(actionType == 1)
104
// QMessageBox::critical(this, tr("Error"), QString(tr("Disconnected")));
106
pb_refresh->setEnabled(FALSE);
107
pb_submit->setEnabled(FALSE);
112
pb_refresh->setEnabled(TRUE);
113
pb_submit->setEnabled(TRUE);
117
pb_close->setEnabled(TRUE);
120
void InfoDlg::updateVCard(const VCard &_vcard)
128
pb_refresh->setEnabled(TRUE);
129
pb_submit->setEnabled(TRUE);
130
pb_close->setEnabled(TRUE);
135
void InfoDlg::error()
140
if(type == INFODLG_USER)
141
QMessageBox::critical(this, tr("Error"), QString(tr("Unable to retrieve your account information. Perhaps you haven't entered any yet.")));
143
QMessageBox::critical(this, tr("Error"), QString(tr("Unable to retrieve information about this contact.")));
144
pb_refresh->setEnabled(TRUE);
145
pb_submit->setEnabled(TRUE);
146
pb_close->setEnabled(TRUE);
151
void InfoDlg::result(bool x)
160
QMessageBox::information(this, tr("Success"), QString(tr("Your account information has been published.")));
161
vcard = submit_vcard;
162
setData(submit_vcard);
165
QMessageBox::critical(this, tr("Error"), QString(tr("Unable to publish your account information.")));
168
pb_refresh->setEnabled(TRUE);
169
pb_submit->setEnabled(TRUE);
170
pb_close->setEnabled(TRUE);
118
if(d->busy->isActive() && d->actionType == 0) {
126
void InfoDlg::jt_finished()
129
pb_refresh->setEnabled(true);
130
pb_submit->setEnabled(true);
131
pb_close->setEnabled(true);
134
if(d->jt->success()) {
135
if(d->actionType == 0) {
136
d->vcard = d->jt->vcard();
139
else if(d->actionType == 1) {
140
d->vcard = d->jt->vcard();
142
VCardFactory::setVCard(d->jid, d->vcard);
146
if(d->jid.compare(d->pa->jid(), false)) {
147
if (!d->vcard.nickName().isEmpty())
148
d->pa->setNick(d->vcard.nickName());
150
d->pa->setNick(d->pa->jid().user());
153
if(d->actionType == 1)
154
QMessageBox::information(this, tr("Success"), tr("Your account information has been published."));
157
if(d->actionType == 0) {
159
QMessageBox::critical(this, tr("Error"), tr("Unable to retrieve your account information. Perhaps you haven't entered any yet."));
161
QMessageBox::critical(this, tr("Error"), tr("Unable to retrieve information about this contact.\nReason: %1").arg(d->jt->statusString()));
164
QMessageBox::critical(this, tr("Error"), tr("Unable to publish your account information.\nReason: %1").arg(d->jt->statusString()));
174
171
void InfoDlg::setData(const VCard &i)
176
le_fullname->setText(i.field[vFullname]);
177
le_nickname->setText(i.field[vNickname]);
178
le_bday->setText(i.field[vBday]);
179
le_email->setText(i.field[vEmail]);
180
le_homepage->setText(i.field[vHomepage]);
181
le_phone->setText(i.field[vPhone]);
182
le_street->setText(i.field[vStreet]);
183
le_ext->setText(i.field[vExt]);
184
le_city->setText(i.field[vCity]);
185
le_state->setText(i.field[vState]);
186
le_pcode->setText(i.field[vPcode]);
187
le_country->setText(i.field[vCountry]);
188
le_orgName->setText(i.field[vOrgName]);
189
le_orgUnit->setText(i.field[vOrgUnit]);
190
le_title->setText(i.field[vTitle]);
191
le_role->setText(i.field[vRole]);
192
te_desc->setText(i.field[vDesc]);
173
le_fullname->setText( i.fullName() );
174
le_nickname->setText( i.nickName() );
175
le_bday->setText( i.bdayStr() );
178
if ( !i.emailList().isEmpty() )
179
email = i.emailList()[0].userid;
180
le_email->setText( email );
182
le_homepage->setText( i.url() );
185
if ( !i.phoneList().isEmpty() )
186
phone = i.phoneList()[0].number;
187
le_phone->setText( phone );
190
if ( !i.addressList().isEmpty() )
191
addr = i.addressList()[0];
192
le_street->setText( addr.street );
193
le_ext->setText( addr.extaddr );
194
le_city->setText( addr.locality );
195
le_state->setText( addr.region );
196
le_pcode->setText( addr.pcode );
197
le_country->setText( addr.country );
199
le_orgName->setText( i.org().name );
202
if ( !i.org().unit.isEmpty() )
203
unit = i.org().unit[0];
204
le_orgUnit->setText( unit );
206
le_title->setText( i.title() );
207
le_role->setText( i.role() );
208
te_desc->setText( i.desc() );
197
213
void InfoDlg::fieldsEnable(bool x)
290
306
void InfoDlg::doRefresh()
308
if(!d->pa->checkConnected(this))
292
310
if(!pb_refresh->isEnabled())
312
if(d->busy->isActive())
297
pb_submit->setEnabled(FALSE);
298
pb_refresh->setEnabled(FALSE);
301
signalGetVCard(v_jid, &id);
315
pb_submit->setEnabled(false);
316
pb_refresh->setEnabled(false);
322
d->jt = VCardFactory::getVCard(d->jid, d->pa->client()->rootTask(), this, SLOT(jt_finished()), d->cacheVCard);
307
325
void InfoDlg::doSubmit()
327
if(!d->pa->checkConnected(this))
309
329
if(!pb_submit->isEnabled())
331
if(d->busy->isActive())
314
pb_submit->setEnabled(FALSE);
315
pb_refresh->setEnabled(FALSE);
316
pb_close->setEnabled(FALSE);
321
signalSetVCard(submit_vcard, &id);
334
VCard submit_vcard = makeVCard();
336
pb_submit->setEnabled(false);
337
pb_refresh->setEnabled(false);
338
pb_close->setEnabled(false);
344
d->jt = new JT_VCard(d->pa->client()->rootTask());
345
connect(d->jt, SIGNAL(finished()), SLOT(jt_finished()));
346
d->jt->set(submit_vcard);
327
void InfoDlg::makeVCard()
350
VCard InfoDlg::makeVCard()
329
VCard *v = &submit_vcard;
331
v->field[vFullname] = le_fullname->text();
332
v->field[vNickname] = le_nickname->text();
333
v->field[vBday] = le_bday->text();
334
v->field[vEmail] = le_email->text();
335
v->field[vHomepage] = le_homepage->text();
336
v->field[vPhone] = le_phone->text();
338
v->field[vStreet] = le_street->text();
339
v->field[vExt] = le_ext->text();
340
v->field[vCity] = le_city->text();
341
v->field[vState] = le_state->text();
342
v->field[vPcode] = le_pcode->text();
343
v->field[vCountry] = le_country->text();
345
v->field[vOrgName] = le_orgName->text();
346
v->field[vOrgUnit] = le_orgUnit->text();
347
v->field[vTitle] = le_title->text();
348
v->field[vRole] = le_role->text();
349
v->field[vDesc] = te_desc->text();
354
v.setFullName( le_fullname->text() );
355
v.setNickName( le_nickname->text() );
356
v.setBdayStr( le_bday->text() );
358
if ( !le_email->text().isEmpty() ) {
360
email.internet = true;
361
email.userid = le_email->text();
363
VCard::EmailList list;
365
v.setEmailList( list );
368
v.setUrl( le_homepage->text() );
370
if ( !le_phone->text().isEmpty() ) {
374
p.number = le_phone->text();
376
VCard::PhoneList list;
378
v.setPhoneList( list );
381
if ( !le_street->text().isEmpty() ||
382
!le_ext->text().isEmpty() ||
383
!le_city->text().isEmpty() ||
384
!le_state->text().isEmpty() ||
385
!le_pcode->text().isEmpty() ||
386
!le_country->text().isEmpty() )
390
addr.street = le_street->text();
391
addr.extaddr = le_ext->text();
392
addr.locality = le_city->text();
393
addr.region = le_state->text();
394
addr.pcode = le_pcode->text();
395
addr.country = le_country->text();
397
VCard::AddressList list;
399
v.setAddressList( list );
404
org.name = le_orgName->text();
406
if ( !le_orgUnit->text().isEmpty() )
407
org.unit << le_orgUnit->text();
411
v.setTitle( le_title->text() );
412
v.setRole( le_role->text() );
413
v.setDesc( te_desc->text() );
352
418
void InfoDlg::textChanged()
358
/*static*/ InfoDlg * InfoDlg::find(const QString &xjid)
360
return (InfoDlg *)UniqueWindowBank::find("InfoDlg", cleanJid(xjid));