~ubuntu-branches/ubuntu/feisty/psi/feisty

« back to all changes in this revision

Viewing changes to src/adduserdlg.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
** 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
****************************************************************************/
 
20
 
 
21
#include"adduserdlg.h"
 
22
 
 
23
#include<qlabel.h>
 
24
#include<qlayout.h>
 
25
#include<qpushbutton.h>
 
26
#include<qpixmap.h>
 
27
#include<qframe.h>
 
28
#include<qmessagebox.h>
 
29
#include<qgroupbox.h>
 
30
#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);
 
50
 
 
51
        QStringList::ConstIterator it1 = services.begin();
 
52
        QStringList::ConstIterator it2 = names.begin();
 
53
        for(; it1 != services.end(); ++it1, ++it2)
 
54
                cb_service->insertItem(transport2icon(*it1, STATUS_ONLINE), *it2);
 
55
        connect(cb_service, SIGNAL(activated(int)), SLOT(serviceActivated(int)));
 
56
 
 
57
        QString str = tr("<None>");
 
58
        cb_group->insertItem(str);
 
59
        cb_group->insertStringList(groups);
 
60
        cb_group->setAutoCompletion(TRUE);
 
61
 
 
62
        pb_add->setDefault(TRUE);
 
63
        connect(pb_add, SIGNAL(clicked()), SLOT(ok()));
 
64
        connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
 
65
        connect(pb_transGet, SIGNAL(clicked()), SLOT(getTransID()));
 
66
        //connect(le_transPrompt, SIGNAL(returnPressed()), SLOT(getTransID()));
 
67
 
 
68
        cb_service->setFocus();
 
69
}
 
70
 
 
71
AddUserDlg::~AddUserDlg()
 
72
{
 
73
        add_ptr = 0;
 
74
 
 
75
        if(active)
 
76
                signalCancelTransaction(id);
 
77
}
 
78
 
 
79
/* static */ AddUserDlg *AddUserDlg::find()
 
80
{
 
81
        return add_ptr;
 
82
}
 
83
 
 
84
void AddUserDlg::ok()
 
85
{
 
86
        if(le_jid->text().isEmpty()) {
 
87
                QMessageBox::information(this, tr("Add User: Error"), tr("Please fill in the Jabber ID of the person you wish to add."));
 
88
                return;
 
89
        }
 
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\"."));
 
92
                return;
 
93
        }
 
94
 
 
95
        Info info;
 
96
        info.jid = le_jid->text();
 
97
        info.nick = le_nick->text();
 
98
 
 
99
        QString gname = cb_group->currentText();
 
100
        if(gname == tr("<None>"))
 
101
                gname = "";
 
102
        info.group = gname;
 
103
 
 
104
        add(info);
 
105
 
 
106
        accept();
 
107
}
 
108
 
 
109
void AddUserDlg::serviceActivated(int x)
 
110
{
 
111
        if(active) {
 
112
                signalCancelTransaction(id);
 
113
                active = FALSE;
 
114
                busy->stop();
 
115
        }
 
116
        gb_trans->setEnabled(FALSE);
 
117
        le_transPrompt->setText("");
 
118
 
 
119
        // Jabber entry
 
120
        if(x == 0)
 
121
                return;
 
122
        --x;
 
123
 
 
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
        }
 
185
}
 
186
 
 
187
void AddUserDlg::getTransID()
 
188
{
 
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()
 
199
{
 
200
        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
        );
 
212
}