| 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 |
|
|---|
| 21 | #include"adduserdlg.h"
|
|---|
| 22 |
|
|---|
| 23 | #include<qlabel.h>
|
|---|
| 24 | #include<qlayout.h>
|
|---|
| 25 | #include<qpushbutton.h>
|
|---|
| 26 | #include<qmessagebox.h>
|
|---|
| 27 | #include<qcombobox.h>
|
|---|
| 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"contactview.h"
|
|---|
| 35 | #include"busywidget.h"
|
|---|
| 36 | #include"common.h"
|
|---|
| 37 | #include"iconwidget.h"
|
|---|
| 38 | #include"tasklist.h"
|
|---|
| 39 | #include"xmpp_vcard.h"
|
|---|
| 40 | #include"vcardfactory.h"
|
|---|
| 41 | #include"infodlg.h"
|
|---|
| 42 |
|
|---|
| 43 | class AddUserDlg::Private
|
|---|
| 44 | {
|
|---|
| 45 | public:
|
|---|
| 46 | Private() {}
|
|---|
| 47 |
|
|---|
| 48 | PsiAccount *pa;
|
|---|
| 49 | BusyWidget *busy;
|
|---|
| 50 | QStringList services;
|
|---|
| 51 | JT_Gateway *jt;
|
|---|
| 52 | TaskList *tasks;
|
|---|
| 53 | };
|
|---|
| 54 |
|
|---|
| 55 | AddUserDlg::AddUserDlg(const QStringList &services, const QStringList &names, const QStringList &groups, PsiAccount *pa)
|
|---|
| 56 | :AddUserUI(0, 0, false, WDestructiveClose)
|
|---|
| 57 | {
|
|---|
| 58 | d = new Private;
|
|---|
| 59 | d->pa = pa;
|
|---|
| 60 | d->pa->dialogRegister(this);
|
|---|
| 61 | connect(d->pa, SIGNAL(updatedActivity()), SLOT(pa_updatedActivity()));
|
|---|
| 62 | d->services = services;
|
|---|
| 63 | d->jt = 0;
|
|---|
| 64 | d->tasks = new TaskList;
|
|---|
| 65 | connect(d->tasks, SIGNAL(started()), busy, SLOT(start()));
|
|---|
| 66 | connect(d->tasks, SIGNAL(finished()), busy, SLOT(stop()));
|
|---|
| 67 |
|
|---|
| 68 | setCaption(CAP(caption()));
|
|---|
| 69 | setIcon(IconsetFactory::icon("psi/addContact"));
|
|---|
| 70 |
|
|---|
| 71 | d->busy = busy;
|
|---|
| 72 |
|
|---|
| 73 | QStringList::ConstIterator it1 = services.begin();
|
|---|
| 74 | QStringList::ConstIterator it2 = names.begin();
|
|---|
| 75 | for(; it1 != services.end(); ++it1, ++it2)
|
|---|
| 76 | cb_service->insertItem(is->status(*it1, STATUS_ONLINE), *it2);
|
|---|
| 77 | connect(cb_service, SIGNAL(activated(int)), SLOT(serviceActivated(int)));
|
|---|
| 78 |
|
|---|
| 79 | connect(le_transPrompt, SIGNAL(textChanged(const QString &)), SLOT(le_transPromptChanged(const QString &)));
|
|---|
| 80 | pb_transGet->setEnabled(false);
|
|---|
| 81 |
|
|---|
| 82 | QString str = tr("<None>");
|
|---|
| 83 | cb_group->insertItem(str);
|
|---|
| 84 | cb_group->insertStringList(groups);
|
|---|
| 85 | str = ContactView::tr("Hidden");
|
|---|
| 86 | if(!groups.contains(str))
|
|---|
| 87 | cb_group->insertItem(str);
|
|---|
| 88 | cb_group->setAutoCompletion(true);
|
|---|
| 89 |
|
|---|
| 90 | pb_add->setDefault(true);
|
|---|
| 91 | connect(pb_add, SIGNAL(clicked()), SLOT(ok()));
|
|---|
| 92 | connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
|
|---|
| 93 | connect(pb_transGet, SIGNAL(clicked()), SLOT(getTransID()));
|
|---|
| 94 |
|
|---|
| 95 | connect(tb_vCard, SIGNAL(clicked()), SLOT(getVCardActivated()));
|
|---|
| 96 | connect(tb_resolveNick, SIGNAL(clicked()), SLOT(resolveNickActivated()));
|
|---|
| 97 |
|
|---|
| 98 | ck_authreq->setChecked(true);
|
|---|
| 99 | ck_close->setChecked(true);
|
|---|
| 100 |
|
|---|
| 101 | le_jid->setFocus();
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | AddUserDlg::~AddUserDlg()
|
|---|
| 105 | {
|
|---|
| 106 | delete d->tasks;
|
|---|
| 107 | d->pa->dialogUnregister(this);
|
|---|
| 108 | delete d;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | void AddUserDlg::pa_updatedActivity()
|
|---|
| 112 | {
|
|---|
| 113 | if(!d->pa->loggedIn())
|
|---|
| 114 | close();
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | void AddUserDlg::ok()
|
|---|
| 118 | {
|
|---|
| 119 | if(le_jid->text().isEmpty()) {
|
|---|
| 120 | QMessageBox::information(this, tr("Add User: Error"), tr("Please fill in the Jabber ID of the person you wish to add."));
|
|---|
| 121 | return;
|
|---|
| 122 | }
|
|---|
| 123 | Jid j(le_jid->text().stripWhiteSpace());
|
|---|
| 124 | if(!j.isValid()) {
|
|---|
| 125 | 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."));
|
|---|
| 126 | return;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | QString gname = cb_group->currentText();
|
|---|
| 130 | QStringList list;
|
|---|
| 131 | if(gname != tr("<None>"))
|
|---|
| 132 | list += gname;
|
|---|
| 133 |
|
|---|
| 134 | add(j, le_nick->text(), list, ck_authreq->isChecked());
|
|---|
| 135 |
|
|---|
| 136 | QMessageBox::information(this, tr("Add User: Success"), tr("Added %1 to your roster.").arg(j.full()));
|
|---|
| 137 |
|
|---|
| 138 | if(ck_close->isChecked())
|
|---|
| 139 | accept();
|
|---|
| 140 | else {
|
|---|
| 141 | le_jid->setText("");
|
|---|
| 142 | le_nick->setText("");
|
|---|
| 143 | le_jid->setFocus();
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | void AddUserDlg::serviceActivated(int x)
|
|---|
| 148 | {
|
|---|
| 149 | if(d->jt) {
|
|---|
| 150 | delete d->jt;
|
|---|
| 151 | d->jt = 0;
|
|---|
| 152 | d->busy->stop();
|
|---|
| 153 | }
|
|---|
| 154 | gb_trans->setEnabled(false);
|
|---|
| 155 | le_transPrompt->setText("");
|
|---|
| 156 |
|
|---|
| 157 | // Jabber entry
|
|---|
| 158 | if(x == 0)
|
|---|
| 159 | return;
|
|---|
| 160 | --x;
|
|---|
| 161 |
|
|---|
| 162 | if(x >= 0 && x < (int)d->services.count()) {
|
|---|
| 163 | d->jt = new JT_Gateway(d->pa->client()->rootTask());
|
|---|
| 164 | connect(d->jt, SIGNAL(finished()), SLOT(jt_getFinished()));
|
|---|
| 165 | d->jt->get(Jid(d->services[x]));
|
|---|
| 166 | d->jt->go(true);
|
|---|
| 167 | d->tasks->append( d->jt );
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | void AddUserDlg::le_transPromptChanged(const QString &str)
|
|---|
| 172 | {
|
|---|
| 173 | pb_transGet->setEnabled(!str.isEmpty());
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | void AddUserDlg::getTransID()
|
|---|
| 177 | {
|
|---|
| 178 | cb_service->setEnabled(false);
|
|---|
| 179 | le_transPrompt->setEnabled(false);
|
|---|
| 180 | pb_transGet->setEnabled(false);
|
|---|
| 181 |
|
|---|
| 182 | d->jt = new JT_Gateway(d->pa->client()->rootTask());
|
|---|
| 183 | connect(d->jt, SIGNAL(finished()), SLOT(jt_setFinished()));
|
|---|
| 184 | d->jt->set(Jid(d->services[cb_service->currentItem()-1]), le_transPrompt->text());
|
|---|
| 185 | d->jt->go(true);
|
|---|
| 186 | d->tasks->append( d->jt );
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | void AddUserDlg::jt_getFinished()
|
|---|
| 190 | {
|
|---|
| 191 | JT_Gateway *jt = d->jt;
|
|---|
| 192 | d->jt = 0;
|
|---|
| 193 |
|
|---|
| 194 | if(jt->success()) {
|
|---|
| 195 | gb_trans->setEnabled(true);
|
|---|
| 196 | lb_transDesc->setText(jt->desc());
|
|---|
| 197 | }
|
|---|
| 198 | else {
|
|---|
| 199 | errorGateway(cb_service->currentText(), jt->statusString());
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | void AddUserDlg::jt_setFinished()
|
|---|
| 204 | {
|
|---|
| 205 | cb_service->setEnabled(true);
|
|---|
| 206 | le_transPrompt->setEnabled(true);
|
|---|
| 207 | pb_transGet->setEnabled(true);
|
|---|
| 208 |
|
|---|
| 209 | JT_Gateway *jt = d->jt;
|
|---|
| 210 | d->jt = 0;
|
|---|
| 211 |
|
|---|
| 212 | if(jt->success()) {
|
|---|
| 213 | le_jid->setText(jt->prompt());
|
|---|
| 214 | le_nick->setText(le_transPrompt->text());
|
|---|
| 215 | le_transPrompt->setText("");
|
|---|
| 216 | le_jid->setCursorPosition(0);
|
|---|
| 217 | le_nick->setCursorPosition(0);
|
|---|
| 218 |
|
|---|
| 219 | le_nick->setFocus();
|
|---|
| 220 | le_nick->selectAll();
|
|---|
| 221 | }
|
|---|
| 222 | else {
|
|---|
| 223 | errorGateway(cb_service->currentText(), jt->statusString());
|
|---|
| 224 | le_transPrompt->setFocus();
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | void AddUserDlg::errorGateway(const QString &str, const QString &err)
|
|---|
| 229 | {
|
|---|
| 230 | QMessageBox::information(this, CAP(tr("Error")), tr("<qt>\n"
|
|---|
| 231 | "There was an error getting the Service ID translation information from \"%1\".<br>"
|
|---|
| 232 | "Reason: %2<br>"
|
|---|
| 233 | "<br>"
|
|---|
| 234 | "The service may not support this feature. In this case you "
|
|---|
| 235 | "will need to enter the Jabber ID manually for the contact you wish "
|
|---|
| 236 | "to add. Examples:<br>"
|
|---|
| 237 | "<br>"
|
|---|
| 238 | " [email protected]<br>"
|
|---|
| 239 | " aoluser@[Jabber ID of AIM Transport]<br>"
|
|---|
| 240 | " 1234567@[Jabber ID of ICQ Transport]<br>"
|
|---|
| 241 | " joe%hotmail.com@[Jabber ID of MSN Transport]<br>"
|
|---|
| 242 | " yahooUser@[Jabber ID of Yahoo Transport]<br>"
|
|---|
| 243 | "</qt>"
|
|---|
| 244 | ).arg(str).arg(err));
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | void AddUserDlg::getVCardActivated()
|
|---|
| 248 | {
|
|---|
| 249 | Jid j(le_jid->text().stripWhiteSpace());
|
|---|
| 250 |
|
|---|
| 251 | const VCard *vcard = VCardFactory::vcard(j);
|
|---|
| 252 |
|
|---|
| 253 | VCard tmp;
|
|---|
| 254 | if ( vcard )
|
|---|
| 255 | tmp = *vcard;
|
|---|
| 256 |
|
|---|
| 257 | InfoDlg *w = new InfoDlg(InfoDlg::Contact, j, tmp, d->pa, 0, 0, false);
|
|---|
| 258 | w->show();
|
|---|
| 259 |
|
|---|
| 260 | // automatically retrieve info if it doesn't exist
|
|---|
| 261 | if(!vcard)
|
|---|
| 262 | w->doRefresh();
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | void AddUserDlg::resolveNickActivated()
|
|---|
| 266 | {
|
|---|
| 267 | Jid j(le_jid->text().stripWhiteSpace());
|
|---|
| 268 | JT_VCard *jt = VCardFactory::getVCard(j, d->pa->client()->rootTask(), this, SLOT(resolveNickFinished()), false);
|
|---|
| 269 | d->tasks->append( jt );
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | void AddUserDlg::resolveNickFinished()
|
|---|
| 273 | {
|
|---|
| 274 | JT_VCard *jt = (JT_VCard *)sender();
|
|---|
| 275 |
|
|---|
| 276 | if(jt->success()) {
|
|---|
| 277 | if ( !jt->vcard().nickName().isEmpty() )
|
|---|
| 278 | le_nick->setText( jt->vcard().nickName() );
|
|---|
| 279 | }
|
|---|
| 280 | }
|
|---|