Revised API attached.
BR
Andrunko
typedef uint OperationHandle;
typedef SharedPtr<ChannelDispatchOperation> ChannelDispatchOperationPtr;
typedef SharedPtr<ChannelRequest> ChannelRequestPtr;
class ChannelDispatchOperation : public StatefulDBusProxy,
private OptionalInterfaceFactory<ChannelDispatchOperation>,
public ReadyObject,
public SharedData
{
Q_OBJECT
public:
static ChannelDispatchOperationPtr create(const QString &objectPath,
const QVariantMap &immutableProperties);
~ChannelDispatchOperation();
AccountPtr account() const;
ConnectionPtr connection() const;
QList<ChannelPtr> channels() const;
QStringList possibleHandlers() const;
PendingOperation *handleWith(const QString &handler);
PendingOperation *claim();
Q_SIGNALS:
void channelLost(const QString &channelObjectPath, const QString &errorName,
const QString &errorMessage);
// TODO should we have finished, or use invalidated?
};
class ChannelRequest : public StatefulDBusProxy,
private OptionalInterfaceFactory<ChannelDispatchOperation>,
public ReadyObject,
public SharedData
{
Q_OBJECT
public:
static ChannelRequestPtr create(const QString &objectPath,
const QVariantMap &immutableProperties);
~ChannelRequest();
AccountPtr account() const;
QDateTime userActionTime() const;
QVariantMap requests() const;
PendingOperation *proceed();
PendingOperation *cancel();
Q_SIGNALS:
void failed(const QString &errorName, const QString &errorMessage);
void succeeded();
};
class BaseClient : public QObject
{
Q_OBJECT
public:
BaseClient(QObject *parent = 0);
~BaseClient();
QVariantMap filters() const;
// enable future expansion, for now it will fail if the client is already
// registered on ClientRegister
bool addFilters(const QVariantMap &filters);
// when finished processing an operation (observeChannels, handlerChannels,
// ...), the client should call setOperationFinished/WithError with the
// given operationHandle.
// This allows operations to be threated asynchronously
void setOperationFinished(OperationHandle operationHandle);
void setOperationFinishedWithError(OperationHandle operationHandle,
const QString &errorName, const QString &errorMessage);
Q_SIGNALS:
void operationFinished(OperationHandle operationHandle);
void operationFinishedWithError(OperationHandle operationHandle,
const QString &errorName, const QString &errorMessage);
};
class BaseObserverClient : public BaseClient
{
public:
BaseObserver(QObject *parent = 0);
virtual ~BaseObserver();
virtual void observeChannels(OperationHandle operationHandle,
const AccountPtr &account,
const ConnectionPtr &connection,
const QList<ChannelPtr> &channels,
const ChannelDispatchOperationPtr &dispatchOperation) = 0;
};
class BaseApproverClient : public BaseClient
{
public:
BaseApprover(QObject *parent = 0);
virtual ~BaseApprover();
virtual void addDispatchOperation(OperationHandle operationHandle,
const ChannelDispatchOperationPtr &dispatchOperation) = 0;
};
class BaseHandlerClient : public BaseClient
{
public:
BaseHandler(QObject *parent = 0);
virtual ~BaseHandler();
// addRequest/removeFailedRequest will only be called if true, default =
// true
void listenRequests(bool listen);
virtual void handleChannels(OperationHandle operationHandle,
const AccountPtr &account,
const ConnectionPtr &connection,
const QList<ChannelPtr> &channels,
const QList<ChannelRequestPtr> &requestsSatisfied,
const QDateTime &userActionTime) = 0;
virtual void addRequest(const ChannelRequestPtr &request);
virtual void removeFailedRequest(const ChannelRequestPtr &request,
const QString &error, const QString &message) = 0;
};
class ClientRegister : public QObject
{
public:
// clientName is the name to be used
ClientRegister(const QString &clientName, bool unique = false,
QObject *parent = 0);
~ClientRegister();
QString clientName() const;
bool addObserverClient(ObserverClient *client);
bool addApproverClient(ApproverClient *client);
bool addHandlerClient(HandlerClient *client);
bool registerClients();
};
void MyHandler : public BaseHandlerClient
{
public:
MyHandler(QObject *parent = 0);
~MyHandler();
void handleChannels(OperationHandle operationHandle,
const AccountPtr &account,
const ConnectionPtr &connection,
const QList<ChannelPtr> &channels,
const QStringList &requestsSatisfiedObjectPaths,
const QDateTime &userActionTime)
{
foreach (const ChannelPtr &channel, channels) {
MyHandlerUI *handlerUI = lookupHandlerUIByChannel(channel);
if (!handlerUI) {
// create handler UI to handle channel
...
}
handlerUI->show();
}
setOperationFinished(operationHandle);
}
virtual void addRequest(const QString &requestObjectPath,
const QVariantMap &requestProperties)
{
...
setOperationFinished(operationHandle);
}
virtual void removeFailedRequest(OperationHandle operationHandle,
const QString &requestObjectPath,
const QString &error, const QString &message)
{
...
setOperationFinished(operationHandle);
}
};
ClientRegister *r = new ClientRegister("myclient");
MyHandler *h = new MyHandler(r);
QVariantMap map;
map.insert("org.freedesktop.Telepathy.Channel.ChannelType",
"org.freedesktop.Telepathy.Channel.Type.Text");
map.insert("org.freedesktop.Telepathy.Channel.TargetHandleType",
Telepathy::HandleTypeContact);
h->addFilters(map);
r->addHandlerClient(h);
r->registerClients();
_______________________________________________
telepathy mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/telepathy