~ubuntu-branches/ubuntu/dapper/psi/dapper

« back to all changes in this revision

Viewing changes to src/infodlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** infodlg.cpp - show contact info
 
3
** Copyright (C) 2001, 2002  Justin Karneges
 
4
**
 
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.
 
9
**
 
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.
 
14
**
 
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.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
#include"infodlg.h"
 
22
#include<qlayout.h>
 
23
#include<qtabwidget.h>
 
24
#include<qpushbutton.h>
 
25
#include<qlineedit.h>
 
26
#include<qmessagebox.h>
 
27
 
 
28
 
 
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))
 
31
{
 
32
        v_jid = jid;
 
33
        vcard = _vcard;
 
34
 
 
35
        isBusy = FALSE;
 
36
 
 
37
        QWidget *w = new QWidget(this);
 
38
        busy = new BusyWidget(w);
 
39
        QHBoxLayout *hb1 = new QHBoxLayout(w);
 
40
        hb1->addStretch(1);
 
41
        hb1->addWidget(busy);
 
42
 
 
43
        int n = InfoDialog1Layout->findWidget(tabwidget);
 
44
        InfoDialog1Layout->insertWidget(n+1, w);
 
45
 
 
46
        setCaption(v_jid);
 
47
        setIcon(*pix_info);
 
48
 
 
49
        if(_localStatus == STATUS_OFFLINE) {
 
50
                pb_refresh->setEnabled(FALSE);
 
51
                pb_submit->setEnabled(FALSE);
 
52
        }
 
53
 
 
54
        connect(pb_refresh, SIGNAL(clicked()), this, SLOT(doRefresh()));
 
55
        connect(te_desc, SIGNAL(textChanged()), this, SLOT(textChanged()));
 
56
 
 
57
        type = _type;
 
58
        if(type == INFODLG_USER) {
 
59
                connect(pb_submit, SIGNAL(clicked()), this, SLOT(doSubmit()));
 
60
        }
 
61
        else {
 
62
                pb_submit->hide();
 
63
                setReadOnly(TRUE);
 
64
        }
 
65
 
 
66
        setData(vcard);
 
67
}
 
68
 
 
69
void InfoDlg::closeEvent(QCloseEvent *e)
 
70
{
 
71
        // don't close if submitting
 
72
        if(isBusy && actionType == 1) {
 
73
                e->ignore();
 
74
                return;
 
75
        }
 
76
 
 
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"));
 
79
                if(x != 0) {
 
80
                        e->ignore();
 
81
                        return;
 
82
                }
 
83
        }
 
84
 
 
85
        // cancel active transaction (refresh only)
 
86
        if(isBusy && actionType == 0) {
 
87
                signalCancelTransaction(id);
 
88
        }
 
89
 
 
90
        e->accept();
 
91
}
 
92
 
 
93
void InfoDlg::localUpdate(const JabRosterEntry &e)
 
94
{
 
95
        int localStatus = e.localStatus();
 
96
 
 
97
        // if the user goes offline then cancel the request
 
98
        if(localStatus == STATUS_OFFLINE) {
 
99
                if(isBusy) {
 
100
                        busy->stop();
 
101
                        isBusy = FALSE;
 
102
 
 
103
//                      if(actionType == 1)
 
104
//                              QMessageBox::critical(this, tr("Error"), QString(tr("Disconnected")));
 
105
                }
 
106
                pb_refresh->setEnabled(FALSE);
 
107
                pb_submit->setEnabled(FALSE);
 
108
                fieldsEnable(TRUE);
 
109
        }
 
110
        else {
 
111
                if(!isBusy) {
 
112
                        pb_refresh->setEnabled(TRUE);
 
113
                        pb_submit->setEnabled(TRUE);
 
114
                }
 
115
        }
 
116
 
 
117
        pb_close->setEnabled(TRUE);
 
118
}
 
119
 
 
120
void InfoDlg::updateVCard(const VCard &_vcard)
 
121
{
 
122
        vcard = _vcard;
 
123
        setData(vcard);
 
124
 
 
125
        if(isBusy) {
 
126
                busy->stop();
 
127
                isBusy = FALSE;
 
128
                pb_refresh->setEnabled(TRUE);
 
129
                pb_submit->setEnabled(TRUE);
 
130
                pb_close->setEnabled(TRUE);
 
131
                fieldsEnable(TRUE);
 
132
        }
 
133
}
 
134
 
 
135
void InfoDlg::error()
 
136
{
 
137
        if(isBusy) {
 
138
                busy->stop();
 
139
                isBusy = FALSE;
 
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.")));
 
142
                else
 
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);
 
147
                fieldsEnable(TRUE);
 
148
        }
 
149
}
 
150
 
 
151
void InfoDlg::result(bool x)
 
152
{
 
153
        if(!isBusy)
 
154
                return;
 
155
 
 
156
        busy->stop();
 
157
        isBusy = FALSE;
 
158
 
 
159
        if(x) {
 
160
                QMessageBox::information(this, tr("Success"), QString(tr("Your account information has been published.")));
 
161
                vcard = submit_vcard;
 
162
                setData(submit_vcard);
 
163
        }
 
164
        else {
 
165
                QMessageBox::critical(this, tr("Error"), QString(tr("Unable to publish your account information.")));
 
166
        }
 
167
 
 
168
        pb_refresh->setEnabled(TRUE);
 
169
        pb_submit->setEnabled(TRUE);
 
170
        pb_close->setEnabled(TRUE);
 
171
        fieldsEnable(TRUE);
 
172
}
 
173
 
 
174
void InfoDlg::setData(const VCard &i)
 
175
{
 
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]);
 
193
 
 
194
        setEdited(FALSE);
 
195
}
 
196
 
 
197
void InfoDlg::fieldsEnable(bool x)
 
198
{
 
199
        le_fullname->setEnabled(x);
 
200
        le_nickname->setEnabled(x);
 
201
        le_bday->setEnabled(x);
 
202
        le_email->setEnabled(x);
 
203
        le_homepage->setEnabled(x);
 
204
        le_phone->setEnabled(x);
 
205
 
 
206
        le_street->setEnabled(x);
 
207
        le_ext->setEnabled(x);
 
208
        le_city->setEnabled(x);
 
209
        le_state->setEnabled(x);
 
210
        le_pcode->setEnabled(x);
 
211
        le_country->setEnabled(x);
 
212
 
 
213
        le_orgName->setEnabled(x);
 
214
        le_orgUnit->setEnabled(x);
 
215
        le_title->setEnabled(x);
 
216
        le_role->setEnabled(x);
 
217
        te_desc->setEnabled(x);
 
218
 
 
219
        setEdited(FALSE);
 
220
}
 
221
 
 
222
void InfoDlg::setEdited(bool x)
 
223
{
 
224
        le_fullname->setEdited(x);
 
225
        le_nickname->setEdited(x);
 
226
        le_bday->setEdited(x);
 
227
        le_email->setEdited(x);
 
228
        le_homepage->setEdited(x);
 
229
        le_phone->setEdited(x);
 
230
        le_street->setEdited(x);
 
231
        le_ext->setEdited(x);
 
232
        le_city->setEdited(x);
 
233
        le_state->setEdited(x);
 
234
        le_pcode->setEdited(x);
 
235
        le_country->setEdited(x);
 
236
        le_orgName->setEdited(x);
 
237
        le_orgUnit->setEdited(x);
 
238
        le_title->setEdited(x);
 
239
        le_role->setEdited(x);
 
240
 
 
241
        te_edited = x;
 
242
}
 
243
 
 
244
bool InfoDlg::edited()
 
245
{
 
246
        bool x = FALSE;
 
247
 
 
248
        if(le_fullname->edited()) x = TRUE;
 
249
        if(le_nickname->edited()) x = TRUE;
 
250
        if(le_bday->edited()) x = TRUE;
 
251
        if(le_email->edited()) x = TRUE;
 
252
        if(le_homepage->edited()) x = TRUE;
 
253
        if(le_phone->edited()) x = TRUE;
 
254
        if(le_street->edited()) x = TRUE;
 
255
        if(le_ext->edited()) x = TRUE;
 
256
        if(le_city->edited()) x = TRUE;
 
257
        if(le_state->edited()) x = TRUE;
 
258
        if(le_pcode->edited()) x = TRUE;
 
259
        if(le_country->edited()) x = TRUE;
 
260
        if(le_orgName->edited()) x = TRUE;
 
261
        if(le_orgUnit->edited()) x = TRUE;
 
262
        if(le_title->edited()) x = TRUE;
 
263
        if(le_role->edited()) x = TRUE;
 
264
        if(te_edited) x = TRUE;
 
265
 
 
266
        return x;
 
267
}
 
268
 
 
269
void InfoDlg::setReadOnly(bool x)
 
270
{
 
271
        le_fullname->setReadOnly(x);
 
272
        le_nickname->setReadOnly(x);
 
273
        le_bday->setReadOnly(x);
 
274
        le_email->setReadOnly(x);
 
275
        le_homepage->setReadOnly(x);
 
276
        le_phone->setReadOnly(x);
 
277
        le_street->setReadOnly(x);
 
278
        le_ext->setReadOnly(x);
 
279
        le_city->setReadOnly(x);
 
280
        le_state->setReadOnly(x);
 
281
        le_pcode->setReadOnly(x);
 
282
        le_country->setReadOnly(x);
 
283
        le_orgName->setReadOnly(x);
 
284
        le_orgUnit->setReadOnly(x);
 
285
        le_title->setReadOnly(x);
 
286
        le_role->setReadOnly(x);
 
287
        te_desc->setReadOnly(x);
 
288
}
 
289
 
 
290
void InfoDlg::doRefresh()
 
291
{
 
292
        if(!pb_refresh->isEnabled())
 
293
                return;
 
294
        if(isBusy)
 
295
                return;
 
296
 
 
297
        pb_submit->setEnabled(FALSE);
 
298
        pb_refresh->setEnabled(FALSE);
 
299
        fieldsEnable(FALSE);
 
300
 
 
301
        signalGetVCard(v_jid, &id);
 
302
        isBusy = TRUE;
 
303
        actionType = 0;
 
304
        busy->start();
 
305
}
 
306
 
 
307
void InfoDlg::doSubmit()
 
308
{
 
309
        if(!pb_submit->isEnabled())
 
310
                return;
 
311
        if(isBusy)
 
312
                return;
 
313
 
 
314
        pb_submit->setEnabled(FALSE);
 
315
        pb_refresh->setEnabled(FALSE);
 
316
        pb_close->setEnabled(FALSE);
 
317
 
 
318
        makeVCard();
 
319
 
 
320
        fieldsEnable(FALSE);
 
321
        signalSetVCard(submit_vcard, &id);
 
322
        isBusy = TRUE;
 
323
        actionType = 1;
 
324
        busy->start();
 
325
}
 
326
 
 
327
void InfoDlg::makeVCard()
 
328
{
 
329
        VCard *v = &submit_vcard;
 
330
 
 
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();
 
337
 
 
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();
 
344
 
 
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();
 
350
}
 
351
 
 
352
void InfoDlg::textChanged()
 
353
{
 
354
        te_edited = TRUE;
 
355
}
 
356
 
 
357
 
 
358
/*static*/ InfoDlg * InfoDlg::find(const QString &xjid)
 
359
{
 
360
        return (InfoDlg *)UniqueWindowBank::find("InfoDlg", cleanJid(xjid));
 
361
}