This method is reimplemented from the <tt>Decibel::ChannelHandler</tt> interface. It is called when ever a new incoming communication channel (<tt>QtTapioca::Channel</tt>) comes into existence. In this method, we must decide whether to accept the incoming channel, and if so, to deal with it appropriately.

+

+

First we check the incoming channel and connection objects are not invalid (=0) and we fail if this is the case. In a proper application, these error cases should be handled more gracefully, but for the purpose of this demo, we will just use <tt>Q_ASSERT()</tt> to handle them.

+

+

Next we check if the <tt>m_connection</tt> member variable is set to 0. If it is not, then we are already handling a channel. This demo can only handle one channel at a time, so we return <tt>false</tt> to reject the new incoming channel.

+

+

There are multiple types of channel we could possible receive. In this demo we are only interested in the <tt>TextChannel</tt> type. So the next step is to try and cast it to a <tt>QtTapioca::TextChannel</tt> object. We then evaluate if this cast was successful (not = 0) and if it was not, we again return <tt>false</tt> to reject the channel.

Abstract

This tutorial will walk you through the process of creating a simple application that uses Decibel's TextChannels to communicate via arbitrary instant messaging networks using telepathy. From the result of this tutorial, only a few more lines of code are needed to produce a functioning text based instant messaging client.

This tutorial is based on the simpleclient demo included with Decibel. An explanation of using the simpleclient demo can be found here.

In this tutorial, we only pick out the important parts of the source code to discuss. The complete working source code for this example can be found here in KDE's SVN Repository.

ChannelHandler class

The first class we will need to create is an implementation of the Decibel::ChannelHandler interface.

The Class Definition

Here is the class definition for our implementation of the Decibel::ChannelHandler interface. It is explained below.

We must inherit from Decibel::ChannelHandler which is the interface definition for handling incoming Channels. We reimplement the constructor, Destructor and the handleChannel() method as well as adding two slots of our own. We also create the member variables m_connecion and m_channel which will hold the QtTapioca::Connection and QtTapioca::Channel objects that are received by the handleChannel method.

The Class Implementation

Now that we have defined our Decibel::ChannelHandler subclass, we need to implement its methods.

Constructor

MyTextChannelHandler::MyTextChannelHandler(QObject * parent) :

ChannelHandler(parent),
m_connection(0),
m_channel(0)

{ }
The constructor is very simple. We just pass the parent object on to the parent class and initialise our member variables to 0.

Destructor

MyTextChannelHandler::~MyTextChannelHandler()
{ }
The destructor is even simpler. We don't need to do anything in it because Qt will handle the deletion of child objects automatically.

}
This method is reimplemented from the Decibel::ChannelHandler interface. It is called when ever a new incoming communication channel (QtTapioca::Channel) comes into existence. In this method, we must decide whether to accept the incoming channel, and if so, to deal with it appropriately.

First we check the incoming channel and connection objects are not invalid (=0) and we fail if this is the case. In a proper application, these error cases should be handled more gracefully, but for the purpose of this demo, we will just use Q_ASSERT() to handle them.

Next we check if the m_connection member variable is set to 0. If it is not, then we are already handling a channel. This demo can only handle one channel at a time, so we return false to reject the new incoming channel.

There are multiple types of channel we could possible receive. In this demo we are only interested in the TextChannel type. So the next step is to try and cast it to a QtTapioca::TextChannel object. We then evaluate if this cast was successful (not = 0) and if it was not, we again return false to reject the channel.