Skip to content

Commit

Permalink
Added BaseChannelChatStateInterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine committed Aug 10, 2014
1 parent 678c162 commit a6f99ea
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
22 changes: 22 additions & 0 deletions TelepathyQt/base-channel-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,28 @@ class TP_QT_NO_EXPORT BaseChannelSecurableInterface::Adaptee : public QObject
BaseChannelSecurableInterface *mInterface;
};

class TP_QT_NO_EXPORT BaseChannelChatStateInterface::Adaptee : public QObject
{
Q_OBJECT
Q_PROPERTY(Tp::ChatStateMap chatStates READ chatStates)

public:
Adaptee(BaseChannelChatStateInterface *interface);
~Adaptee();

Tp::ChatStateMap chatStates() const;

private Q_SLOTS:
void setChatState(uint state,
const Tp::Service::ChannelInterfaceChatStateAdaptor::SetChatStateContextPtr &context);

signals:
void chatStateChanged(uint contact, uint state);

private:
BaseChannelChatStateInterface *mInterface;
};

class TP_QT_NO_EXPORT BaseChannelGroupInterface::Adaptee : public QObject
{
Q_OBJECT
Expand Down
114 changes: 114 additions & 0 deletions TelepathyQt/base-channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,120 @@ void BaseChannelSecurableInterface::createAdaptor()
mPriv->adaptee, dbusObject());
}

// Chan.I.ChatState
struct TP_QT_NO_EXPORT BaseChannelChatStateInterface::Private {
Private(BaseChannelChatStateInterface *parent)
: adaptee(new BaseChannelChatStateInterface::Adaptee(parent))
{
}

Tp::ChatStateMap chatStates;
SetChatStateCallback setChatStateCB;
BaseChannelChatStateInterface::Adaptee *adaptee;
};

BaseChannelChatStateInterface::Adaptee::Adaptee(BaseChannelChatStateInterface *interface)
: QObject(interface),
mInterface(interface)
{
}

BaseChannelChatStateInterface::Adaptee::~Adaptee()
{
}

Tp::ChatStateMap BaseChannelChatStateInterface::Adaptee::chatStates() const
{
return mInterface->chatStates();
}

void BaseChannelChatStateInterface::Adaptee::setChatState(uint state,
const Tp::Service::ChannelInterfaceChatStateAdaptor::SetChatStateContextPtr &context)
{
qDebug() << "BaseChannelChatStateInterface::Adaptee::setChatState";
DBusError error;
mInterface->setChatState(state, &error);
if (error.isValid()) {
context->setFinishedWithError(error.name(), error.message());
return;
}
context->setFinished();
}

/**
* \class BaseChannelChatStateInterface
* \ingroup servicecm
* \headerfile TelepathyQt/base-channel.h <TelepathyQt/BaseChannel>
*
* \brief Base class for implementations of Channel.Interface.Chat.State
*/

/**
* Class constructor.
*/
BaseChannelChatStateInterface::BaseChannelChatStateInterface()
: AbstractChannelInterface(TP_QT_IFACE_CHANNEL_INTERFACE_CHAT_STATE),
mPriv(new Private(this))
{
}

/**
* Class destructor.
*/
BaseChannelChatStateInterface::~BaseChannelChatStateInterface()
{
delete mPriv;
}

/**
* Return the immutable properties of this interface.
*
* Immutable properties cannot change after the interface has been registered
* on a service on the bus with registerInterface().
*
* \return The immutable properties of this interface.
*/
QVariantMap BaseChannelChatStateInterface::immutableProperties() const
{
QVariantMap map;
return map;
}

Tp::ChatStateMap BaseChannelChatStateInterface::chatStates() const
{
return mPriv->chatStates;
}

void BaseChannelChatStateInterface::setChatStates(const Tp::ChatStateMap &chatStates)
{
mPriv->chatStates = chatStates;
}

void BaseChannelChatStateInterface::createAdaptor()
{
(void) new Service::ChannelInterfaceChatStateAdaptor(dbusObject()->dbusConnection(),
mPriv->adaptee, dbusObject());
}

void BaseChannelChatStateInterface::setSetChatStateCallback(const BaseChannelChatStateInterface::SetChatStateCallback &cb)
{
mPriv->setChatStateCB = cb;
}

void BaseChannelChatStateInterface::setChatState(uint state, DBusError *error)
{
if (!mPriv->setChatStateCB.isValid()) {
error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
return;
}
return mPriv->setChatStateCB(state, error);
}

void BaseChannelChatStateInterface::chatStateChanged(uint contact, uint state)
{
QMetaObject::invokeMethod(mPriv->adaptee, "chatStateChanged", Q_ARG(uint, contact), Q_ARG(uint, state)); //Can simply use emit in Qt5
}

//Chan.I.Group
BaseChannelGroupInterface::Adaptee::Adaptee(BaseChannelGroupInterface *interface)
: QObject(interface),
Expand Down
43 changes: 43 additions & 0 deletions TelepathyQt/base-channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,49 @@ class TP_QT_EXPORT BaseChannelSecurableInterface : public AbstractChannelInterfa
Private *mPriv;
};

class TP_QT_EXPORT BaseChannelChatStateInterface : public AbstractChannelInterface
{
Q_OBJECT
Q_DISABLE_COPY(BaseChannelChatStateInterface)

public:
static BaseChannelChatStateInterfacePtr create()
{
return BaseChannelChatStateInterfacePtr(new BaseChannelChatStateInterface());
}
template<typename BaseChannelChatStateInterfaceSubclass>
static SharedPtr<BaseChannelChatStateInterfaceSubclass> create()
{
return SharedPtr<BaseChannelChatStateInterfaceSubclass>(
new BaseChannelChatStateInterfaceSubclass());
}

virtual ~BaseChannelChatStateInterface();

QVariantMap immutableProperties() const;

Tp::ChatStateMap chatStates() const;
void setChatStates(const Tp::ChatStateMap &chatStates);

typedef Callback2<void, uint, DBusError*> SetChatStateCallback;
void setSetChatStateCallback(const SetChatStateCallback &cb);
void setChatState(uint state, DBusError *error);

void chatStateChanged(uint contact, uint state);

protected:
BaseChannelChatStateInterface();

private:
void createAdaptor();

class Adaptee;
friend class Adaptee;
struct Private;
friend struct Private;
Private *mPriv;
};

class TP_QT_EXPORT BaseChannelGroupInterface : public AbstractChannelInterface
{
Q_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions TelepathyQt/service-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BaseChannelServerAuthenticationType;
class BaseChannelSASLAuthenticationInterface;
class BaseChannelCaptchaAuthenticationInterface;
class BaseChannelSecurableInterface;
class BaseChannelChatStateInterface;
class BaseChannelGroupInterface;
class DBusService;

Expand Down Expand Up @@ -83,6 +84,7 @@ typedef SharedPtr<BaseChannelServerAuthenticationType> BaseChannelServerAuthenti
typedef SharedPtr<BaseChannelSASLAuthenticationInterface> BaseChannelSASLAuthenticationInterfacePtr;
typedef SharedPtr<BaseChannelCaptchaAuthenticationInterface> BaseChannelCaptchaAuthenticationInterfacePtr;
typedef SharedPtr<BaseChannelSecurableInterface> BaseChannelSecurableInterfacePtr;
typedef SharedPtr<BaseChannelChatStateInterface> BaseChannelChatStateInterfacePtr;
typedef SharedPtr<BaseChannelGroupInterface> BaseChannelGroupInterfacePtr;
typedef SharedPtr<DBusService> DBusServicePtr;

Expand Down

0 comments on commit a6f99ea

Please sign in to comment.