summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/jingle/jinglevoicesessiondialog.cpp
blob: 8a55c499d412545bc0a66e6f3020b49c18c0a25a (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
    jinglevoicesessiondialog.cpp - GUI for a voice session.

    Copyright (c) 2006      by Michaƫl Larouche     <michael.larouche@kdemail.net>

    Kopete    (c) 2001-2006 by the Kopete developers <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 "jinglevoicesessiondialog.h"

// TQt includes
#include <tqlabel.h>
#include <tqpixmap.h>
#include <tqimage.h>

// Jingle includes
// #include "jinglevoicesession.h"
// #include "jinglesessionmanager.h"
#include "voicecaller.h"

// KDE includes
#include <tdelocale.h>
#include <kpushbutton.h>

// Kopete includes
#include "jabberaccount.h"
#include "jabbercontact.h"
#include "jabbercontactpool.h"

#include "kopeteglobal.h"
#include "kopetemetacontact.h"

using namespace XMPP;

JingleVoiceSessionDialog::JingleVoiceSessionDialog(const Jid &peerJid, VoiceCaller *caller, TQWidget *parent, const char *name)
 : JingleVoiceSessionDialogBase(parent, name), m_session(caller), m_peerJid(peerJid), m_sessionState(Incoming)
{
	TQString contactJid = m_peerJid.full();
	setCaption( i18n("Voice session with %1").arg(contactJid) );

	connect(buttonAccept, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotAcceptClicked()));
	connect(buttonDecline, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotDeclineClicked()));
	connect(buttonTerminate, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotTerminateClicked()));

// NOTE: Disabled for 0.12
#if 0
	connect(m_session, TQ_SIGNAL(sessionStarted()), this, TQ_SLOT(sessionStarted()));
	connect(m_session, TQ_SIGNAL(accepted()), this, TQ_SLOT(sessionAccepted()));
	connect(m_session, TQ_SIGNAL(declined()), this, TQ_SLOT(sessionDeclined()));
	connect(m_session, TQ_SIGNAL(terminated()), this, TQ_SLOT(sessionTerminated()));
#endif
	connect(m_session, TQ_SIGNAL(accepted( const Jid & )), this, TQ_SLOT( sessionAccepted(const Jid &) ));
	connect(m_session, TQ_SIGNAL(in_progress( const Jid & )), this, TQ_SLOT( sessionStarted(const Jid &) ));
	connect(m_session, TQ_SIGNAL(rejected( const Jid& )), this, TQ_SLOT( sessionDeclined(const Jid &) ));
	connect(m_session, TQ_SIGNAL(terminated( const Jid& )), this, TQ_SLOT( sessionTerminated(const Jid &) ));

	// Find JabberContact for the peer and fill this dialog with contact information.
	JabberContact *peerContact = static_cast<JabberContact*>( m_session->account()->contactPool()->findRelevantRecipient( m_peerJid ) );
	if( peerContact )
	{
		setContactInformation( peerContact );
	}
	
	labelSessionStatus->setText( i18n("Incoming Session...") );
	buttonAccept->setEnabled(true);
	buttonDecline->setEnabled(true);
}

JingleVoiceSessionDialog::~JingleVoiceSessionDialog()
{
	//m_session->account()->sessionManager()->removeSession(m_session);
}

void JingleVoiceSessionDialog::setContactInformation(JabberContact *contact)
{
	if( contact->metaContact() )
	{
		labelDisplayName->setText( contact->metaContact()->displayName() );
		labelContactPhoto->setPixmap( TQPixmap(contact->metaContact()->photo()) );
	}
	else
	{
		labelDisplayName->setText( contact->nickName() );
		labelDisplayName->setPixmap( TQPixmap(contact->property(Kopete::Global::Properties::self()->photo()).value().toString()) );
	}
}

void JingleVoiceSessionDialog::start()
{
	labelSessionStatus->setText( i18n("Waiting for other peer...") );
	buttonAccept->setEnabled(false);
	buttonDecline->setEnabled(false);
	buttonTerminate->setEnabled(true);
	//m_session->start();
	m_session->call( m_peerJid );
	m_sessionState = Waiting;
}

void JingleVoiceSessionDialog::slotAcceptClicked()
{
	labelSessionStatus->setText( i18n("Session accepted.") );
	buttonAccept->setEnabled(false);
	buttonDecline->setEnabled(false);
	buttonTerminate->setEnabled(true);
	
	//m_session->accept();
	m_session->accept( m_peerJid );
	m_sessionState = Accepted;
}

void JingleVoiceSessionDialog::slotDeclineClicked()
{
	labelSessionStatus->setText( i18n("Session declined.") );
	buttonAccept->setEnabled(false);
	buttonDecline->setEnabled(false);
	buttonTerminate->setEnabled(false);

	//m_session->decline();
	m_session->reject( m_peerJid );
	m_sessionState = Declined;
	finalize();
}

void JingleVoiceSessionDialog::slotTerminateClicked()
{
	labelSessionStatus->setText( i18n("Session terminated.") );
	buttonAccept->setEnabled(false);
	buttonDecline->setEnabled(false);
	buttonTerminate->setEnabled(false);

	//m_session->terminate();
	m_session->terminate( m_peerJid );
	m_sessionState = Terminated;
	finalize();
	close();
}

void JingleVoiceSessionDialog::sessionStarted(const Jid &jid)
{
	if( m_peerJid.compare(jid) )
	{
		labelSessionStatus->setText( i18n("Session in progress.") );
		buttonAccept->setEnabled(false);
		buttonDecline->setEnabled(false);
		buttonTerminate->setEnabled(true);
		m_sessionState = Started;
	}
}

void JingleVoiceSessionDialog::sessionAccepted(const Jid &jid)
{
	if( m_peerJid.compare(jid) )
	{
		labelSessionStatus->setText( i18n("Session accepted.") );
		buttonAccept->setEnabled(false);
		buttonDecline->setEnabled(false);
		buttonTerminate->setEnabled(true);
		m_sessionState = Accepted;
	}
}

void JingleVoiceSessionDialog::sessionDeclined(const Jid &jid)
{
	if( m_peerJid.compare(jid) )
	{
		labelSessionStatus->setText( i18n("Session declined.") );
		buttonAccept->setEnabled(false);
		buttonDecline->setEnabled(false);
		buttonTerminate->setEnabled(false);
		m_sessionState = Declined;
	}
}

void JingleVoiceSessionDialog::sessionTerminated(const Jid &jid)
{
	if( m_peerJid.compare(jid) )
	{
		labelSessionStatus->setText( i18n("Session terminated.") );
		buttonAccept->setEnabled(false);
		buttonDecline->setEnabled(false);
		buttonTerminate->setEnabled(false);
		m_sessionState = Terminated;
	}
}

void JingleVoiceSessionDialog::reject()
{
	finalize();
	TQDialog::reject();
}

void JingleVoiceSessionDialog::finalize()
{
	disconnect(m_session, TQ_SIGNAL(accepted( const Jid & )), this, TQ_SLOT( sessionAccepted(const Jid &) ));
	disconnect(m_session, TQ_SIGNAL(in_progress( const Jid & )), this, TQ_SLOT( sessionStarted(const Jid &) ));
	disconnect(m_session, TQ_SIGNAL(rejected( const Jid& )), this, TQ_SLOT( sessionDeclined(const Jid &) ));
	disconnect(m_session, TQ_SIGNAL(terminated( const Jid& )), this, TQ_SLOT( sessionTerminated(const Jid &) ));
}

#include "jinglevoicesessiondialog.moc"