~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/mucjoindlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * mucjoindlg.cpp
3
 
 * Copyright (C) 2001, 2002  Justin Karneges
 
3
 * Copyright (C) 2001-2008  Justin Karneges, Michail Pishchagin
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
6
6
 * modify it under the terms of the GNU General Public License
29
29
#include "mucjoindlg.h"
30
30
#include "psicontactlist.h"
31
31
 
32
 
using namespace XMPP;
33
 
 
34
 
 
35
 
class MUCJoinDlg::Private
36
 
{
37
 
public:
38
 
        Private() {}
39
 
 
40
 
        PsiCon *psi;
41
 
        PsiAccount *pa;
42
 
        AccountsComboBox *cb_ident;
43
 
        BusyWidget *busy;
44
 
        QStringList rl;
45
 
        Jid jid;
46
 
};
47
 
 
48
 
MUCJoinDlg::MUCJoinDlg(PsiCon *psi, PsiAccount *pa)
 
32
MUCJoinDlg::MUCJoinDlg(PsiCon* psi, PsiAccount* pa)
49
33
        : QDialog(0)
50
34
{
51
35
        setAttribute(Qt::WA_DeleteOnClose);
52
 
        d = new Private;
53
36
        setModal(false);
54
 
        setupUi(this);
55
 
        d->psi = psi;
56
 
        d->pa = 0;
57
 
        d->psi->dialogRegister(this);
58
 
        d->busy = busy;
59
 
        ck_history->setChecked(true);
 
37
        ui_.setupUi(this);
 
38
        controller_ = psi;
 
39
        account_ = 0;
 
40
        controller_->dialogRegister(this);
 
41
        ui_.ck_history->setChecked(true);
 
42
        ui_.ck_history->hide();
 
43
        joinButton_ = ui_.buttonBox->addButton(tr("&Join"), QDialogButtonBox::AcceptRole);
 
44
        joinButton_->setDefault(true);
60
45
 
61
46
        updateIdentity(pa);
62
 
        
63
 
        d->cb_ident = d->psi->accountsComboBox(this,true);
64
 
        connect(d->cb_ident, SIGNAL(activated(PsiAccount *)), SLOT(updateIdentity(PsiAccount *)));
65
 
        d->cb_ident->setAccount(pa);
66
 
        replaceWidget(lb_ident, d->cb_ident);
67
 
 
68
 
        connect(d->psi, SIGNAL(accountCountChanged()), this, SLOT(updateIdentityVisibility()));
 
47
 
 
48
        ui_.cb_ident->setController(controller_);
 
49
        ui_.cb_ident->setOnlineOnly(true);
 
50
        connect(ui_.cb_ident, SIGNAL(activated(PsiAccount *)), SLOT(updateIdentity(PsiAccount *)));
 
51
        ui_.cb_ident->setAccount(pa);
 
52
 
 
53
        connect(controller_, SIGNAL(accountCountChanged()), this, SLOT(updateIdentityVisibility()));
69
54
        updateIdentityVisibility();
70
55
 
71
 
        d->rl = d->psi->recentGCList();
72
 
        for(QStringList::ConstIterator it = d->rl.begin(); it != d->rl.end(); ++it) {
73
 
                Jid j(*it);
74
 
                QString s = tr("%1 on %2").arg(j.resource()).arg(JIDUtil::toString(j,false));
75
 
                cb_recent->insertItem(s);
 
56
        foreach(QString j, controller_->recentGCList()) {
 
57
                Jid jid(j);
 
58
                QString s = tr("%1 on %2").arg(jid.resource()).arg(JIDUtil::toString(jid, false));
 
59
                ui_.cb_recent->addItem(s);
 
60
                ui_.cb_recent->setItemData(ui_.cb_recent->count()-1, QVariant(j));
76
61
        }
77
62
 
78
63
        setWindowTitle(CAP(caption()));
79
 
        pb_join->setDefault(true);
80
 
        connect(pb_close, SIGNAL(clicked()), SLOT(close()));
81
 
        connect(pb_join, SIGNAL(clicked()), SLOT(doJoin()));
82
 
        connect(cb_recent, SIGNAL(activated(int)), SLOT(recent_activated(int)));
83
 
        if(d->rl.isEmpty()) {
84
 
                cb_recent->setEnabled(false);
85
 
                le_host->setFocus();
 
64
        connect(ui_.cb_recent, SIGNAL(activated(int)), SLOT(recent_activated(int)));
 
65
        if (!ui_.cb_recent->count()) {
 
66
                ui_.cb_recent->setEnabled(false);
 
67
                ui_.le_host->setFocus();
86
68
        }
87
 
        else
 
69
        else {
88
70
                recent_activated(0);
 
71
        }
 
72
 
 
73
        setWidgetsEnabled(true);
 
74
        resize(sizeHint());
89
75
}
90
76
 
91
77
MUCJoinDlg::~MUCJoinDlg()
92
78
{
93
 
        if(d->psi)
94
 
                d->psi->dialogUnregister(this);
95
 
        if(d->pa)
96
 
                d->pa->dialogUnregister(this);
97
 
        delete d;
 
79
        if (controller_)
 
80
                controller_->dialogUnregister(this);
 
81
        if (account_)
 
82
                account_->dialogUnregister(this);
98
83
}
99
84
 
100
 
/*void MUCJoinDlg::closeEvent(QCloseEvent *e)
101
 
{
102
 
        e->ignore();
103
 
        reject();
104
 
}*/
105
 
 
106
85
void MUCJoinDlg::done(int r)
107
86
{
108
 
        if(d->busy->isActive()) {
 
87
        if (ui_.busy->isActive()) {
109
88
                //int n = QMessageBox::information(0, tr("Warning"), tr("Are you sure you want to cancel joining groupchat?"), tr("&Yes"), tr("&No"));
110
89
                //if(n != 0)
111
90
                //      return;
112
 
                d->pa->groupChatLeave(d->jid.host(), d->jid.user());
 
91
                account_->groupChatLeave(jid_.host(), jid_.user());
113
92
        }
114
93
        QDialog::done(r);
115
94
}
116
95
 
117
96
void MUCJoinDlg::updateIdentity(PsiAccount *pa)
118
97
{
119
 
        if(d->pa)
120
 
                disconnect(d->pa, SIGNAL(disconnected()), this, SLOT(pa_disconnected()));
121
 
 
122
 
        d->pa = pa;
123
 
        pb_join->setEnabled(d->pa);
124
 
 
125
 
        if(!d->pa) {
126
 
                d->busy->stop();
 
98
        if (account_)
 
99
                disconnect(account_, SIGNAL(disconnected()), this, SLOT(pa_disconnected()));
 
100
 
 
101
        account_ = pa;
 
102
        joinButton_->setEnabled(account_);
 
103
 
 
104
        if (!account_) {
 
105
                ui_.busy->stop();
127
106
                return;
128
107
        }
129
108
 
130
 
        connect(d->pa, SIGNAL(disconnected()), this, SLOT(pa_disconnected()));
 
109
        connect(account_, SIGNAL(disconnected()), this, SLOT(pa_disconnected()));
131
110
}
132
111
 
133
112
void MUCJoinDlg::updateIdentityVisibility()
134
113
{
135
 
        bool visible = d->psi->contactList()->enabledAccounts().count() > 1;
136
 
        d->cb_ident->setVisible(visible);
137
 
        lb_identity->setVisible(visible);
 
114
        bool visible = controller_->contactList()->enabledAccounts().count() > 1;
 
115
        ui_.cb_ident->setVisible(visible);
 
116
        ui_.lb_identity->setVisible(visible);
138
117
}
139
118
 
140
119
void MUCJoinDlg::pa_disconnected()
141
120
{
142
 
        if(d->busy->isActive()) {
143
 
                d->busy->stop();
 
121
        if (ui_.busy->isActive()) {
 
122
                ui_.busy->stop();
144
123
        }
145
124
}
146
125
 
147
126
void MUCJoinDlg::recent_activated(int x)
148
127
{
149
 
        int n = 0;
150
 
        bool found = false;
151
 
        QString str;
152
 
        for(QStringList::ConstIterator it = d->rl.begin(); it != d->rl.end(); ++it) {
153
 
                if(n == x) {
154
 
                        found = true;
155
 
                        str = *it;
156
 
                        break;
157
 
                }
158
 
                ++n;
159
 
        }
160
 
        if(!found)
 
128
        Jid jid(ui_.cb_recent->itemData(x).toString());
 
129
        if (jid.full().isEmpty())
161
130
                return;
162
131
 
163
 
        Jid j(str);
164
 
        le_host->setText(j.host());
165
 
        le_room->setText(j.user());
166
 
        le_nick->setText(j.resource());
 
132
        ui_.le_host->setText(jid.host());
 
133
        ui_.le_room->setText(jid.user());
 
134
        ui_.le_nick->setText(jid.resource());
167
135
}
168
136
 
169
137
void MUCJoinDlg::doJoin()
170
138
{
171
 
        if(!d->pa || !d->pa->checkConnected(this))
 
139
        if (!account_ || !account_->checkConnected(this))
172
140
                return;
173
141
 
174
 
        QString host = le_host->text();
175
 
        QString room = le_room->text();
176
 
        QString nick = le_nick->text();
177
 
        QString pass = le_pass->text();
 
142
        QString host = ui_.le_host->text();
 
143
        QString room = ui_.le_room->text();
 
144
        QString nick = ui_.le_nick->text();
 
145
        QString pass = ui_.le_pass->text();
178
146
 
179
 
        if(host.isEmpty() || room.isEmpty() || nick.isEmpty()) {
 
147
        if (host.isEmpty() || room.isEmpty() || nick.isEmpty()) {
180
148
                QMessageBox::information(this, tr("Error"), tr("You must fill out the fields in order to join."));
181
149
                return;
182
150
        }
183
151
 
184
152
        Jid j = room + '@' + host + '/' + nick;
185
 
        if(!j.isValid()) {
 
153
        if (!j.isValid()) {
186
154
                QMessageBox::information(this, tr("Error"), tr("You entered an invalid room name."));
187
155
                return;
188
156
        }
189
157
 
190
 
        if(!d->pa->groupChatJoin(host, room, nick, pass, !ck_history->isChecked())) {
 
158
        if (!account_->groupChatJoin(host, room, nick, pass, !ui_.ck_history->isChecked())) {
191
159
                QMessageBox::information(this, tr("Error"), tr("You are in or joining this room already!"));
192
160
                return;
193
161
        }
194
162
 
195
 
        d->psi->dialogUnregister(this);
196
 
        d->jid = room + '@' + host + '/' + nick;
197
 
        d->pa->dialogRegister(this, d->jid);
198
 
 
199
 
        disableWidgets();
200
 
        d->busy->start();
201
 
}
202
 
 
203
 
void MUCJoinDlg::disableWidgets()
204
 
{
205
 
        d->cb_ident->setEnabled(false);
206
 
        cb_recent->setEnabled(false);
207
 
        gb_info->setEnabled(false);
208
 
        pb_join->setEnabled(false);
209
 
}
210
 
 
211
 
void MUCJoinDlg::enableWidgets()
212
 
{
213
 
        d->cb_ident->setEnabled(true);
214
 
        if(!d->rl.isEmpty())
215
 
                cb_recent->setEnabled(true);
216
 
        gb_info->setEnabled(true);
217
 
        pb_join->setEnabled(true);
 
163
        controller_->dialogUnregister(this);
 
164
        jid_ = room + '@' + host + '/' + nick;
 
165
        account_->dialogRegister(this, jid_);
 
166
 
 
167
        setWidgetsEnabled(false);
 
168
        ui_.busy->start();
 
169
}
 
170
 
 
171
void MUCJoinDlg::setWidgetsEnabled(bool enabled)
 
172
{
 
173
        ui_.cb_ident->setEnabled(enabled);
 
174
        ui_.cb_recent->setEnabled(enabled && ui_.cb_recent->count() > 0);
 
175
        ui_.gb_info->setEnabled(enabled);
 
176
        joinButton_->setEnabled(enabled);
218
177
}
219
178
 
220
179
void MUCJoinDlg::joined()
221
180
{
222
 
        d->psi->recentGCAdd(d->jid.full());
223
 
        d->busy->stop();
 
181
        controller_->recentGCAdd(jid_.full());
 
182
        ui_.busy->stop();
224
183
 
225
184
        closeDialogs(this);
226
185
        deleteLater();
228
187
 
229
188
void MUCJoinDlg::error(int, const QString &str)
230
189
{
231
 
        d->busy->stop();
232
 
        enableWidgets();
233
 
 
234
 
        pb_join->setFocus();
235
 
 
236
 
        d->pa->dialogUnregister(this);
237
 
        d->psi->dialogRegister(this);
 
190
        ui_.busy->stop();
 
191
        setWidgetsEnabled(true);
 
192
 
 
193
        account_->dialogUnregister(this);
 
194
        controller_->dialogRegister(this);
238
195
 
239
196
        QMessageBox::information(this, tr("Error"), tr("Unable to join groupchat.\nReason: %1").arg(str));
240
197
}
241
198
 
242
 
 
 
199
void MUCJoinDlg::setJid(const Jid& mucJid)
 
200
{
 
201
        ui_.le_host->setText(mucJid.host());
 
202
        ui_.le_room->setText(mucJid.user());
 
203
}
 
204
 
 
205
void MUCJoinDlg::setNick(const QString nick)
 
206
{
 
207
        ui_.le_nick->setText(nick);
 
208
}
 
209
 
 
210
void MUCJoinDlg::setPassword(const QString& password)
 
211
{
 
212
        ui_.le_pass->setText(password);
 
213
}
 
214
 
 
215
void MUCJoinDlg::accept()
 
216
{
 
217
        doJoin();
 
218
}