Commit 165e9dbb authored by Nicolas Jager's avatar Nicolas Jager Committed by Guillaume Roguez

CallbacksHandler : implementation

- CallbacksHandler recieves callbacks from the daemon (through legacy
lrc interfaces) and emits his own signals.

- Signals from CallbacksHandler have to be use only inside LRC.
It is not intended to connect those signals from a client.

- Until we rely on legacy lrc, CallbacksHandler will convert Qt
objects to STL equivalents.

Change-Id: I1f08279e5b432b995614ffc5e2b3daceddca1065
Reviewed-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 288c1e92
......@@ -18,13 +18,43 @@
***************************************************************************/
#include "callbackshandler.h"
// Models and database
#include "api/lrc.h"
#include "api/newaccountmodel.h"
// Dbus
#include "dbus/configurationmanager.h"
#include "dbus/presencemanager.h"
namespace lrc
{
CallbacksHandler::CallbacksHandler()
using namespace api;
CallbacksHandler::CallbacksHandler(const Lrc& parent)
: QObject()
, parent(parent)
{
// Get signals from daemon
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::incomingAccountMessage,
this,
&CallbacksHandler::slotNewAccountMessage);
connect(&PresenceManager::instance(),
&PresenceManagerInterface::newBuddyNotification,
this,
&CallbacksHandler::slotNewBuddySubscription);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::contactAdded,
this,
&CallbacksHandler::slotContactAdded);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::contactRemoved,
this,
&CallbacksHandler::slotContactRemoved);
}
CallbacksHandler::~CallbacksHandler()
......@@ -35,9 +65,14 @@ CallbacksHandler::~CallbacksHandler()
void
CallbacksHandler::slotNewAccountMessage(const QString& accountId,
const QString& from,
const MapStringString& payloads)
const QMap<QString,QString>& payloads)
{
std::map<std::string,std::string> stdPayloads;
for (auto item : payloads.keys())
stdPayloads[item.toStdString()] = payloads.value(item).toStdString();
emit NewAccountMessage(accountId.toStdString(), from.toStdString(), stdPayloads);
}
void
......@@ -46,7 +81,23 @@ CallbacksHandler::slotNewBuddySubscription(const QString& accountId,
bool status,
const QString& message)
{
emit NewBuddySubscription(uri.toStdString());
}
void
CallbacksHandler::slotContactAdded(const QString& accountId,
const QString& contactUri,
bool confirmed)
{
emit contactAdded(accountId.toStdString(), contactUri.toStdString(), confirmed);
}
void
CallbacksHandler::slotContactRemoved(const QString& accountId,
const QString& contactUri,
bool banned)
{
emit contactRemoved(accountId.toStdString(), contactUri.toStdString(), banned);
}
} // namespace lrc
......@@ -18,6 +18,9 @@
***************************************************************************/
#pragma once
// Std
#include <memory>
// Qt
#include <qobject.h>
......@@ -27,16 +30,81 @@
namespace lrc
{
namespace api
{
class Lrc;
}
class CallbacksHandler : public QObject {
Q_OBJECT
public:
CallbacksHandler();
CallbacksHandler(const api::Lrc& parent);
~CallbacksHandler();
public Q_SLOTS:
void slotNewAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads);
void slotNewBuddySubscription(const QString& accountId, const QString& uri, bool status, const QString& message);
Q_SIGNALS:
/**
* Connect this signal to get incoming message.
* @param accountId, message reciever.
* @param from, message sender.
* @param payloads.
*/
void NewAccountMessage(const std::string& accountId,
const std::string& toStdString,
const std::map<std::string,std::string> payloads) const;
/**
* Connect this signal to get information when a peer is online.
* @param contactUri, the peer.
*/
void NewBuddySubscription(const std::string& contactUri) const;
/**
* Connect this signal to know when a contact was removed by the daemon.
* @param accountId, the one who lost a contact.
* @param contactUri, the contact removed.
* @param banned, true if the contact was banned
*/
void contactRemoved(const std::string& accountId, const std::string& contactUri, bool banned) const;
/**
* Connect this signal to know when a contact was addeb by the daemon.
* @param accountId, the one who got a new contact.
* @param contactUri, the new contact.
* @param confirmed, true if the contact is trusted.
*/
void contactAdded(const std::string& accountId, const std::string& contactUri, bool confirmed) const;
private Q_SLOTS:
/**
* Add the incoming message from the daemon to the database
* @param accountId
* @param from
* @param payloads of the message
*/
void slotNewAccountMessage(const QString& accountId, const QString& from, const QMap<QString,QString>& payloads);
/**
* Update the presence of a contact for an account
* @param accountId
* @param contactUri
* @param status if the contact is present
* @param message unused for now
*/
void slotNewBuddySubscription(const QString& accountId, const QString& contactUri, bool status, const QString& message);
/**
* Add a contact in the contact list of an account
* @param accountId
* @param contactUri
* @param confirmed
*/
void slotContactAdded(const QString& accountId, const QString& contactUri, bool confirmed);
/**
* Remove a contact from a contact list of an account
* @param accountId
* @param contactUri
* @param banned
*/
void slotContactRemoved(const QString& accountId, const QString& contactUri, bool banned);
private:
const api::Lrc& parent;
};
} // namespace lrc
......@@ -35,8 +35,8 @@ public:
LrcPimpl(const Lrc& linked);
const Lrc& linked;
std::unique_ptr<Database> database;
std::unique_ptr<CallbacksHandler> callbackHandler;
std::unique_ptr<Database> database;
std::unique_ptr<NewAccountModel> accountModel;
};
......@@ -57,11 +57,10 @@ Lrc::getAccountModel() const
LrcPimpl::LrcPimpl(const Lrc& linked)
: linked(linked)
, callbackHandler(std::make_unique<CallbacksHandler>(linked))
, database(std::make_unique<Database>())
, callbackHandler(std::make_unique<CallbacksHandler>())
, accountModel(std::make_unique<NewAccountModel>(*database))
{
}
} // namespace lrc
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment