summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/ui/dlgjabberregister.cpp
blob: 5f6b05a2e04a87c3ae6fc520622544cff293a5c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

/***************************************************************************
                          dlgjabberregister.cpp  -  description
                             -------------------
    begin                : Mon Dec 9 2002
    copyright            : (C) 2002-2003 by Till Gerken <till@tantalo.net>
    email                : kopete-devel@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tqpushbutton.h>

#include <kmessagebox.h>
#include <klocale.h>

#include "jabberaccount.h"
#include "jabberprotocol.h"
#include "jabberclient.h"
#include "dlgjabberregister.h"

dlgJabberRegister::dlgJabberRegister (JabberAccount *account, const XMPP::Jid & jid, TQWidget * tqparent, const char *name):dlgRegister (tqparent, name)
{
	m_account = account;

	XMPP::JT_Register * task = new XMPP::JT_Register(m_account->client()->rootTask ());

	connect (task, TQT_SIGNAL (finished ()), this, TQT_SLOT (slotGotForm ()));

	task->getForm (jid);
	task->go (true);

	translator = 0;

}

void dlgJabberRegister::slotGotForm ()
{
	XMPP::JT_Register * task = (XMPP::JT_Register *) sender ();

	// remove the "wait" message
	delete lblWait;

	if (!task->success ())
	{
		KMessageBox::error (this, i18n ("Unable to retrieve registration form.\nReason: \"%1\"").arg (task->statusString (), 1), i18n ("Jabber Error"));

		deleteLater ();

		return;
	}

	// translate the form and create it inside the box widget
	translator = new JabberFormTranslator (task->form (), grpForm);
	static_cast<TQBoxLayout*>(grpForm->tqlayout())->insertWidget(1, translator);
	translator->show();
	resize(tqsizeHint());

	// enable the send button
	btnRegister->setEnabled (true);

	connect (btnRegister, TQT_SIGNAL (clicked ()), this, TQT_SLOT (slotSendForm ()));

}

void dlgJabberRegister::slotSendForm ()
{
	if(!translator)
		return;
	XMPP::JT_Register * task = new XMPP::JT_Register (m_account->client()->rootTask ());

	connect (task, TQT_SIGNAL (finished ()), this, TQT_SLOT (slotSentForm ()));

	task->setForm (translator->resultData ());
	task->go (true);

	btnRegister->setEnabled (false);
	btnCancel->setEnabled (false);

}

void dlgJabberRegister::slotSentForm ()
{
	XMPP::JT_Register * task = (XMPP::JT_Register *) sender ();

	if (task->success ())
	{
		KMessageBox::information (this, i18n ("Registration sent successfully."), i18n ("Jabber Registration"));

		deleteLater ();
	}
	else
	{
		KMessageBox::error (this,
							i18n ("The server denied the registration form.\nReason: \"%1\"").arg (task->statusString (), 1), i18n ("Jabber Registration"));

		btnRegister->setEnabled (true);
		btnRegister->setEnabled (true);
	}

}

dlgJabberRegister::~dlgJabberRegister ()
{

	delete translator;

}

#include "dlgjabberregister.moc"