diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp index 7f3dbba5a76920089c6513657cf177d4e9e8dbb1..f6371dbe3772a14981329889ec8a06e528431ac7 100644 --- a/src/callbackshandler.cpp +++ b/src/callbackshandler.cpp @@ -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 diff --git a/src/callbackshandler.h b/src/callbackshandler.h index 363150386fffe28e87c684d68525ed283203421c..ecf7a506f00dd2effcea0a3b6d6593eea9fa1bac 100644 --- a/src/callbackshandler.h +++ b/src/callbackshandler.h @@ -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 diff --git a/src/lrc.cpp b/src/lrc.cpp index 8275afaf6fe6f3c00432718fb47ecc6281ef581c..eb512d0680c918649aa2c93d5c15e071ce87f344 100644 --- a/src/lrc.cpp +++ b/src/lrc.cpp @@ -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