2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License version 3, as published by
6
* the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
21
#include <TelepathyQt/Constants>
22
#include <TelepathyQt/DBusObject>
24
#include "speakeriface.h"
27
BaseChannelSpeakerInterface::Adaptee::Adaptee(BaseChannelSpeakerInterface *interface)
33
struct TP_QT_NO_EXPORT BaseChannelSpeakerInterface::Private {
34
Private(BaseChannelSpeakerInterface *parent)
36
adaptee(new BaseChannelSpeakerInterface::Adaptee(parent)) {
39
turnOnSpeakerCallback turnOnSpeakerCB;
40
BaseChannelSpeakerInterface::Adaptee *adaptee;
43
BaseChannelSpeakerInterface::Adaptee::~Adaptee()
47
void BaseChannelSpeakerInterface::Adaptee::turnOnSpeaker(bool active, const ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr &context)
49
if (!mInterface->mPriv->turnOnSpeakerCB.isValid()) {
50
context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
54
mInterface->mPriv->turnOnSpeakerCB(active, &error);
55
if (error.isValid()) {
56
context->setFinishedWithError(error.name(), error.message());
59
context->setFinished();
62
BaseChannelSpeakerInterface::BaseChannelSpeakerInterface()
63
: AbstractChannelInterface(TP_QT_IFACE_CHANNEL_SPEAKER),
64
mPriv(new Private(this))
68
BaseChannelSpeakerInterface::~BaseChannelSpeakerInterface()
73
bool BaseChannelSpeakerInterface::speakerMode() const
75
return mPriv->speakerMode;
78
void BaseChannelSpeakerInterface::setTurnOnSpeakerCallback(const turnOnSpeakerCallback &cb)
80
mPriv->turnOnSpeakerCB = cb;
83
void BaseChannelSpeakerInterface::setSpeakerMode(bool active)
85
mPriv->speakerMode = active;
86
Q_EMIT mPriv->adaptee->speakerChanged(active);
89
QVariantMap BaseChannelSpeakerInterface::immutableProperties() const
95
void BaseChannelSpeakerInterface::createAdaptor()
97
(void) new ChannelInterfaceSpeakerAdaptor(dbusObject()->dbusConnection(),
98
mPriv->adaptee, dbusObject());
102
ChannelInterfaceSpeakerAdaptor::ChannelInterfaceSpeakerAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
103
: Tp::AbstractAdaptor(bus, adaptee, parent)
105
connect(adaptee, SIGNAL(speakerChanged(bool)), SIGNAL(SpeakerChanged(bool)));
108
ChannelInterfaceSpeakerAdaptor::~ChannelInterfaceSpeakerAdaptor()
112
void ChannelInterfaceSpeakerAdaptor::turnOnSpeaker(bool active, const QDBusMessage& dbusMessage)
114
if (!adaptee()->metaObject()->indexOfMethod("turnOnSpeaker(bool,ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr)") == -1) {
115
dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
119
turnOnSpeakerContextPtr ctx = turnOnSpeakerContextPtr(
120
new Tp::MethodInvocationContext< bool >(dbusConnection(), dbusMessage));
121
QMetaObject::invokeMethod(adaptee(), "turnOnSpeaker",
123
Q_ARG(ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr, ctx));
127
bool ChannelInterfaceSpeakerAdaptor::SpeakerMode() const
129
return qvariant_cast< bool >(adaptee()->property("speakerMode"));