~ubuntu-branches/ubuntu/hoary/psi/hoary

« back to all changes in this revision

Viewing changes to src/adduserdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** adduserdlg.cpp - a dialog for adding a contact
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
 
****************************************************************************/
 
1
/*
 
2
 * adduserdlg.cpp - dialog for adding contacts
 
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 library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
20
20
 
21
21
#include"adduserdlg.h"
22
22
 
23
23
#include<qlabel.h>
24
24
#include<qlayout.h>
25
25
#include<qpushbutton.h>
26
 
#include<qpixmap.h>
27
 
#include<qframe.h>
28
26
#include<qmessagebox.h>
 
27
#include<qcombobox.h>
29
28
#include<qgroupbox.h>
 
29
#include<qstringlist.h>
 
30
#include<qlineedit.h>
 
31
#include<qcheckbox.h>
 
32
#include"xmpp_tasks.h"
 
33
#include"psiaccount.h"
 
34
#include"busywidget.h"
30
35
#include"common.h"
31
 
 
32
 
 
33
 
static AddUserDlg *add_ptr = 0;
34
 
 
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)
37
 
{
38
 
        add_ptr = this;
39
 
 
40
 
        services = _services;
41
 
        localStatus = _localStatus;
42
 
 
43
 
        active = FALSE;
44
 
 
45
 
        setCaption(CAP(tr("Add User")));
46
 
        setIcon(*pix_add);
47
 
 
48
 
        busy = new BusyWidget(this);
49
 
        hb_bottom->insertWidget(0, busy);
 
36
#include"iconwidget.h"
 
37
 
 
38
class AddUserDlg::Private
 
39
{
 
40
public:
 
41
        Private() {}
 
42
 
 
43
        PsiAccount *pa;
 
44
        BusyWidget *busy;
 
45
        QStringList services;
 
46
        JT_Gateway *jt;
 
47
};
 
48
 
 
49
AddUserDlg::AddUserDlg(const QStringList &services, const QStringList &names, const QStringList &groups, PsiAccount *pa)
 
50
:AddUserUI(0, 0, false, WDestructiveClose)
 
51
{
 
52
        d = new Private;
 
53
        d->pa = pa;
 
54
        d->pa->dialogRegister(this);
 
55
        connect(d->pa, SIGNAL(updatedActivity()), SLOT(pa_updatedActivity()));
 
56
        d->services = services;
 
57
        d->jt = 0;
 
58
 
 
59
        setCaption(CAP(caption()));
 
60
        setIcon(IconsetFactory::icon("psi/addContact"));
 
61
 
 
62
        d->busy = busy;
50
63
 
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)));
56
69
 
 
70
        connect(le_transPrompt, SIGNAL(textChanged(const QString &)), SLOT(le_transPromptChanged(const QString &)));
 
71
        pb_transGet->setEnabled(false);
 
72
 
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);
61
80
 
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()));
67
 
 
68
 
        cb_service->setFocus();
 
85
 
 
86
        ck_authreq->setChecked(true);
 
87
        ck_close->setChecked(true);
 
88
 
 
89
        le_jid->setFocus();
69
90
}
70
91
 
71
92
AddUserDlg::~AddUserDlg()
72
93
{
73
 
        add_ptr = 0;
74
 
 
75
 
        if(active)
76
 
                signalCancelTransaction(id);
 
94
        delete d->jt;
 
95
        d->pa->dialogUnregister(this);
 
96
        delete d;
77
97
}
78
98
 
79
 
/* static */ AddUserDlg *AddUserDlg::find()
 
99
void AddUserDlg::pa_updatedActivity()
80
100
{
81
 
        return add_ptr;
 
101
        if(!d->pa->loggedIn())
 
102
                close();
82
103
}
83
104
 
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."));
88
109
                return;
89
110
        }
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());
 
112
        if(!j.isValid()) {
 
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."));
92
114
                return;
93
115
        }
94
116
 
95
 
        Info info;
96
 
        info.jid = le_jid->text();
97
 
        info.nick = le_nick->text();
98
 
 
99
117
        QString gname = cb_group->currentText();
100
 
        if(gname == tr("<None>"))
101
 
                gname = "";
102
 
        info.group = gname;
103
 
 
104
 
        add(info);
105
 
 
106
 
        accept();
 
118
        QStringList list;
 
119
        if(gname != tr("<None>"))
 
120
                list += gname;
 
121
 
 
122
        add(j, le_nick->text(), list, ck_authreq->isChecked());
 
123
 
 
124
        QMessageBox::information(this, tr("Add User: Success"), tr("Added %1 to your roster.").arg(j.full()));
 
125
 
 
126
        if(ck_close->isChecked())
 
127
                accept();
 
128
        else {
 
129
                le_jid->setText("");
 
130
                le_nick->setText("");
 
131
                le_jid->setFocus();
 
132
        }
107
133
}
108
134
 
109
135
void AddUserDlg::serviceActivated(int x)
110
136
{
111
 
        if(active) {
112
 
                signalCancelTransaction(id);
113
 
                active = FALSE;
114
 
                busy->stop();
 
137
        if(d->busy->isActive()) {
 
138
                delete d->jt;
 
139
                d->jt = 0;
 
140
                d->busy->stop();
115
141
        }
116
 
        gb_trans->setEnabled(FALSE);
 
142
        gb_trans->setEnabled(false);
117
143
        le_transPrompt->setText("");
118
144
 
119
145
        // Jabber entry
121
147
                return;
122
148
        --x;
123
149
 
124
 
        if(x >= 0 && x < (int)services.count()) {
125
 
                //printf("Selected: [%s]\n", services[x].latin1());
126
 
                signalGetGateway(services[x], &id);
127
 
                active = TRUE;
128
 
                busy->start();
129
 
        }
130
 
}
131
 
 
132
 
void AddUserDlg::localUpdate(const JabRosterEntry &e)
133
 
{
134
 
        localStatus = e.localStatus();
135
 
 
136
 
        if(localStatus == STATUS_OFFLINE)
137
 
                close();
138
 
}
139
 
 
140
 
void AddUserDlg::slotGetGatewayResponse(const QString &_id, bool ok, const QString &desc)
141
 
{
142
 
        if(!active)
143
 
                return;
144
 
 
145
 
        if(_id == id) {
146
 
                busy->stop();
147
 
                active = FALSE;
148
 
                if(ok) {
149
 
                        gb_trans->setEnabled(TRUE);
150
 
                        lb_transDesc->setText(desc);
151
 
                }
152
 
                else {
153
 
                        errorGateway();
154
 
                }
155
 
        }
156
 
}
157
 
 
158
 
void AddUserDlg::slotSetGatewayResponse(const QString &_id, bool ok, const QString &jid)
159
 
{
160
 
        if(!active)
161
 
                return;
162
 
 
163
 
        if(_id == id) {
164
 
                cb_service->setEnabled(TRUE);
165
 
                le_transPrompt->setEnabled(TRUE);
166
 
                pb_transGet->setEnabled(TRUE);
167
 
                busy->stop();
168
 
                active = FALSE;
169
 
 
170
 
                if(ok) {
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);
176
 
 
177
 
                        le_nick->setFocus();
178
 
                        le_nick->selectAll();
179
 
                }
180
 
                else {
181
 
                        errorGateway();
182
 
                        le_transPrompt->setFocus();
183
 
                }
184
 
        }
 
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]));
 
154
                d->jt->go(true);
 
155
                d->busy->start();
 
156
        }
 
157
}
 
158
 
 
159
void AddUserDlg::le_transPromptChanged(const QString &str)
 
160
{
 
161
        pb_transGet->setEnabled(!str.isEmpty());
185
162
}
186
163
 
187
164
void AddUserDlg::getTransID()
188
165
{
189
 
        cb_service->setEnabled(FALSE);
190
 
        le_transPrompt->setEnabled(FALSE);
191
 
        pb_transGet->setEnabled(FALSE);
192
 
 
193
 
        signalSetGateway(services[cb_service->currentItem()-1], le_transPrompt->text(), &id);
194
 
        active = TRUE;
195
 
        busy->start();
196
 
}
197
 
 
198
 
void AddUserDlg::errorGateway()
 
166
        cb_service->setEnabled(false);
 
167
        le_transPrompt->setEnabled(false);
 
168
        pb_transGet->setEnabled(false);
 
169
 
 
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());
 
173
        d->jt->go(true);
 
174
        d->busy->start();
 
175
}
 
176
 
 
177
void AddUserDlg::jt_getFinished()
 
178
{
 
179
        d->busy->stop();
 
180
        JT_Gateway *jt = d->jt;
 
181
        d->jt = 0;
 
182
 
 
183
        if(jt->success()) {
 
184
                gb_trans->setEnabled(true);
 
185
                lb_transDesc->setText(jt->desc());
 
186
        }
 
187
        else {
 
188
                errorGateway(cb_service->currentText(), jt->statusString());
 
189
        }
 
190
}
 
191
 
 
192
void AddUserDlg::jt_setFinished()
 
193
{
 
194
        d->busy->stop();
 
195
        cb_service->setEnabled(true);
 
196
        le_transPrompt->setEnabled(true);
 
197
        pb_transGet->setEnabled(true);
 
198
 
 
199
        JT_Gateway *jt = d->jt;
 
200
        d->jt = 0;
 
201
 
 
202
        if(jt->success()) {
 
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);
 
208
 
 
209
                le_nick->setFocus();
 
210
                le_nick->selectAll();
 
211
        }
 
212
        else {
 
213
                errorGateway(cb_service->currentText(), jt->statusString());
 
214
                le_transPrompt->setFocus();
 
215
        }
 
216
}
 
217
 
 
218
void AddUserDlg::errorGateway(const QString &str, const QString &err)
199
219
{
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"
205
 
          "<br>\n"
206
 
          "&nbsp;&nbsp;jabberuser@somehost.com<br>\n"
207
 
          "&nbsp;&nbsp;aoluser@[Jabber ID of AIM Transport]<br>\n"
208
 
          "&nbsp;&nbsp;1234567@[Jabber ID of ICQ Transport]<br>\n"
209
 
          "&nbsp;&nbsp;joe%hotmail.com@[Jabber ID of MSN Transport]<br>\n"
210
 
        ).arg(cb_service->currentText())
211
 
        );
 
221
                "There was an error getting the Service ID translation information from \"%1\".<br>"
 
222
                "Reason: %2<br>"
 
223
                "<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>"
 
227
                "<br>"
 
228
                "&nbsp;&nbsp;jabberuser@somehost.com<br>"
 
229
                "&nbsp;&nbsp;aoluser@[Jabber ID of AIM Transport]<br>"
 
230
                "&nbsp;&nbsp;1234567@[Jabber ID of ICQ Transport]<br>"
 
231
                "&nbsp;&nbsp;joe%hotmail.com@[Jabber ID of MSN Transport]<br>"
 
232
                "&nbsp;&nbsp;yahooUser@[Jabber ID of Yahoo Transport]<br>"
 
233
                "</qt>"
 
234
                ).arg(str).arg(err));
212
235
}