Skip to content
Snippets Groups Projects
Commit 7c0a57bd authored by Nicolas Jager's avatar Nicolas Jager Committed by Sébastien Blin
Browse files

BehaviorController: implementation


- this class is an helper for clients. Clients can connect
signals from this class to easily update their views.

- for now, this class has the following signals:
  - showChatView: the client should open the chat view.
  - showCallView: the client should open the call view.
  - showIncomingCallView: the client should open the incoming call
    view.

Change-Id: I9f51859c08aeadacf46d3c828dc9ab012c19b8f1
Reviewed-by: default avatarGuillaume Roguez <guilaume.roguez@savoirfairelinux.com>
parent db1375e5
Branches
No related tags found
No related merge requests found
...@@ -309,6 +309,7 @@ SET( libringclient_LIB_SRCS ...@@ -309,6 +309,7 @@ SET( libringclient_LIB_SRCS
src/lrc.cpp src/lrc.cpp
src/newaccountmodel.cpp src/newaccountmodel.cpp
src/callbackshandler.cpp src/callbackshandler.cpp
src/behaviorcontroller.cpp
#Data collections #Data collections
src/transitionalpersonbackend.cpp src/transitionalpersonbackend.cpp
...@@ -474,6 +475,7 @@ SET(libringclient_api_LIB_HDRS ...@@ -474,6 +475,7 @@ SET(libringclient_api_LIB_HDRS
src/api/contactmodel.h src/api/contactmodel.h
src/api/conversationmodel.h src/api/conversationmodel.h
src/api/profile.h src/api/profile.h
src/api/behaviorcontroller.h
) )
......
/****************************************************************************
* Copyright (C) 2017 Savoir-faire Linux *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#pragma once
// Std
#include <memory>
// Qt
#include <qobject.h>
// Lrc
#include "typedefs.h"
namespace lrc
{
class BehaviorControllerPimpl;
namespace api
{
class Lrc;
namespace conversation
{
class Info;
}
/**
* @brief Class that helps to control behaviors from the client side.
* @note This class must only refer to the common behaviors.
*/
class BehaviorController : public QObject {
Q_OBJECT
public:
BehaviorController();
~BehaviorController();
Q_SIGNALS:
/**
* Emitted when the client should open the chat view.
*/
void showChatView(const std::string& accountId, const api::conversation::Info& conversationInfo) const;
/**
* Emitted when the client should open the call view.
*/
void showCallView(const std::string& accountId, const api::conversation::Info& conversationInfo) const;
/**
* Emitted when the client should open the incoming call view.
*/
void showIncomingCallView(const std::string& accountId, const api::conversation::Info& conversationInfo) const;
};
} // namespace api
} // namespace lrc
...@@ -46,6 +46,7 @@ namespace api ...@@ -46,6 +46,7 @@ namespace api
namespace account { struct Info; } namespace account { struct Info; }
namespace interaction { struct Info; } namespace interaction { struct Info; }
class BehaviorController;
class NewAccountModel; class NewAccountModel;
/** /**
...@@ -58,7 +59,10 @@ public: ...@@ -58,7 +59,10 @@ public:
const account::Info& owner; const account::Info& owner;
ConversationModel(const account::Info& owner, Database& db, const CallbacksHandler& callbacksHandler); ConversationModel(const account::Info& owner,
Database& db,
const CallbacksHandler& callbacksHandler,
const api::BehaviorController& behaviorController);
~ConversationModel(); ~ConversationModel();
/** /**
......
...@@ -32,6 +32,7 @@ class LrcPimpl; ...@@ -32,6 +32,7 @@ class LrcPimpl;
namespace api namespace api
{ {
class BehaviorController;
class NewAccountModel; class NewAccountModel;
class LIB_EXPORT Lrc { class LIB_EXPORT Lrc {
...@@ -43,6 +44,11 @@ public: ...@@ -43,6 +44,11 @@ public:
* @return a NewAccountModel&. * @return a NewAccountModel&.
*/ */
const NewAccountModel& getAccountModel() const; const NewAccountModel& getAccountModel() const;
/**
* get a reference on the behavior controller.
* @return a BehaviorController&.
*/
const BehaviorController& getBehaviorController() const;
private: private:
std::unique_ptr<LrcPimpl> lrcPimpl_; std::unique_ptr<LrcPimpl> lrcPimpl_;
......
...@@ -39,6 +39,7 @@ class NewAccountModelPimpl; ...@@ -39,6 +39,7 @@ class NewAccountModelPimpl;
namespace api namespace api
{ {
class BehaviorController;
namespace account { struct Info; } namespace account { struct Info; }
...@@ -50,7 +51,10 @@ class LIB_EXPORT NewAccountModel : public QObject { ...@@ -50,7 +51,10 @@ class LIB_EXPORT NewAccountModel : public QObject {
public: public:
using AccountInfoMap = std::map<std::string, account::Info>; using AccountInfoMap = std::map<std::string, account::Info>;
NewAccountModel(Database& database, const CallbacksHandler& callbackHandler); NewAccountModel(Database& database,
const CallbacksHandler& callbackHandler,
const api::BehaviorController& behaviorController);
~NewAccountModel(); ~NewAccountModel();
/** /**
* get a list of all acountId. * get a list of all acountId.
......
/****************************************************************************
* Copyright (C) 2017 Savoir-faire Linux *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "api/behaviorcontroller.h"
// Models and database
#include "api/lrc.h"
namespace lrc
{
using namespace api;
BehaviorController::BehaviorController()
: QObject()
{
}
BehaviorController::~BehaviorController()
{
}
} // namespace lrc
#include "api/moc_behaviorcontroller.cpp"
#include "behaviorcontroller.moc"
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <algorithm> #include <algorithm>
// LRC // LRC
#include "api/behaviorcontroller.h"
#include "api/contactmodel.h" #include "api/contactmodel.h"
#include "api/newcallmodel.h" #include "api/newcallmodel.h"
#include "api/newaccountmodel.h" #include "api/newaccountmodel.h"
...@@ -52,7 +53,8 @@ class ConversationModelPimpl : public QObject ...@@ -52,7 +53,8 @@ class ConversationModelPimpl : public QObject
public: public:
ConversationModelPimpl(const ConversationModel& linked, ConversationModelPimpl(const ConversationModel& linked,
Database& db, Database& db,
const CallbacksHandler& callbacksHandler); const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController);
~ConversationModelPimpl(); ~ConversationModelPimpl();
...@@ -104,6 +106,7 @@ public: ...@@ -104,6 +106,7 @@ public:
Database& db; Database& db;
const CallbacksHandler& callbacksHandler; const CallbacksHandler& callbacksHandler;
const std::string accountProfileId; const std::string accountProfileId;
const BehaviorController& behaviorController;
ConversationModel::ConversationQueue conversations; ///< non-filtered conversations ConversationModel::ConversationQueue conversations; ///< non-filtered conversations
ConversationModel::ConversationQueue filteredConversations; ConversationModel::ConversationQueue filteredConversations;
...@@ -166,9 +169,12 @@ public Q_SLOTS: ...@@ -166,9 +169,12 @@ public Q_SLOTS:
}; };
ConversationModel::ConversationModel(const account::Info& owner, Database& db, const CallbacksHandler& callbacksHandler) ConversationModel::ConversationModel(const account::Info& owner,
Database& db,
const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController)
: QObject() : QObject()
, pimpl_(std::make_unique<ConversationModelPimpl>(*this, db, callbacksHandler)) , pimpl_(std::make_unique<ConversationModelPimpl>(*this, db, callbacksHandler, behaviorController))
, owner(owner) , owner(owner)
{ {
...@@ -275,14 +281,14 @@ ConversationModel::selectConversation(const std::string& uid) const ...@@ -275,14 +281,14 @@ ConversationModel::selectConversation(const std::string& uid) const
case call::Status::CONNECTING: case call::Status::CONNECTING:
case call::Status::SEARCHING: case call::Status::SEARCHING:
// We are currently in a call // We are currently in a call
// TODO fully functional behaviour not implemented in this patch emit pimpl_->behaviorController.showIncomingCallView(owner.id, conversation);
break; break;
case call::Status::PAUSED: case call::Status::PAUSED:
case call::Status::PEER_PAUSED: case call::Status::PEER_PAUSED:
case call::Status::CONNECTED: case call::Status::CONNECTED:
case call::Status::IN_PROGRESS: case call::Status::IN_PROGRESS:
// We are currently receiving a call // We are currently receiving a call
// TODO fully functional behaviour not implemented in this patch emit pimpl_->behaviorController.showCallView(owner.id, conversation);
break; break;
case call::Status::INVALID: case call::Status::INVALID:
case call::Status::OUTGOING_REQUESTED: case call::Status::OUTGOING_REQUESTED:
...@@ -292,11 +298,10 @@ ConversationModel::selectConversation(const std::string& uid) const ...@@ -292,11 +298,10 @@ ConversationModel::selectConversation(const std::string& uid) const
case call::Status::AUTO_ANSWERING: case call::Status::AUTO_ANSWERING:
default: default:
// We are not in a call, show the chatview // We are not in a call, show the chatview
// TODO fully functional behaviour not implemented in this patch emit pimpl_->behaviorController.showChatView(owner.id, conversation);
break;
} }
} catch (const std::out_of_range&) { } catch (const std::out_of_range&) {
// TODO fully functional behaviour not implemented in this patch emit pimpl_->behaviorController.showChatView(owner.id, conversation);
} }
} }
...@@ -361,7 +366,7 @@ ConversationModel::placeCall(const std::string& uid) ...@@ -361,7 +366,7 @@ ConversationModel::placeCall(const std::string& uid)
conversation = pimpl_->conversations.at(conversationIdx); conversation = pimpl_->conversations.at(conversationIdx);
} }
pimpl_->dirtyConversations = true; pimpl_->dirtyConversations = true;
// fully functional behaviour not implemented in this patch emit pimpl_->behaviorController.showIncomingCallView(owner.id, conversation);
} }
void void
...@@ -466,12 +471,14 @@ ConversationModel::clearHistory(const std::string& uid) ...@@ -466,12 +471,14 @@ ConversationModel::clearHistory(const std::string& uid)
ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked, ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked,
Database& db, Database& db,
const CallbacksHandler& callbacksHandler) const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController)
: linked(linked) : linked(linked)
, db(db) , db(db)
, callbacksHandler(callbacksHandler) , callbacksHandler(callbacksHandler)
, typeFilter(profile::Type::INVALID) , typeFilter(profile::Type::INVALID)
, accountProfileId(database::getProfileId(db, linked.owner.profileInfo.uri)) , accountProfileId(database::getProfileId(db, linked.owner.profileInfo.uri))
, behaviorController(behaviorController)
{ {
initConversations(); initConversations();
...@@ -721,7 +728,7 @@ ConversationModelPimpl::slotIncomingCall(const std::string& fromId, const std::s ...@@ -721,7 +728,7 @@ ConversationModelPimpl::slotIncomingCall(const std::string& fromId, const std::s
qDebug() << "Add call to conversation with " << fromId.c_str(); qDebug() << "Add call to conversation with " << fromId.c_str();
conversation.callId = callId; conversation.callId = callId;
dirtyConversations = true; dirtyConversations = true;
// fully functional behaviour not implemented in this patch emit behaviorController.showIncomingCallView(linked.owner.id, conversation);
} }
void void
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
// Models and database // Models and database
#include "api/newaccountmodel.h" #include "api/newaccountmodel.h"
#include "api/behaviorcontroller.h"
#include "database.h" #include "database.h"
#include "callbackshandler.h" #include "callbackshandler.h"
#include "dbus/instancemanager.h" #include "dbus/instancemanager.h"
...@@ -36,6 +37,7 @@ public: ...@@ -36,6 +37,7 @@ public:
LrcPimpl(const Lrc& linked); LrcPimpl(const Lrc& linked);
const Lrc& linked; const Lrc& linked;
std::unique_ptr<BehaviorController> behaviorController;
std::unique_ptr<CallbacksHandler> callbackHandler; std::unique_ptr<CallbacksHandler> callbackHandler;
std::unique_ptr<Database> database; std::unique_ptr<Database> database;
std::unique_ptr<NewAccountModel> accountModel; std::unique_ptr<NewAccountModel> accountModel;
...@@ -59,11 +61,18 @@ Lrc::getAccountModel() const ...@@ -59,11 +61,18 @@ Lrc::getAccountModel() const
return *lrcPimpl_->accountModel; return *lrcPimpl_->accountModel;
} }
const BehaviorController&
Lrc::getBehaviorController() const
{
return *lrcPimpl_->behaviorController;
}
LrcPimpl::LrcPimpl(const Lrc& linked) LrcPimpl::LrcPimpl(const Lrc& linked)
: linked(linked) : linked(linked)
, behaviorController(std::make_unique<BehaviorController>())
, callbackHandler(std::make_unique<CallbacksHandler>(linked)) , callbackHandler(std::make_unique<CallbacksHandler>(linked))
, database(std::make_unique<Database>()) , database(std::make_unique<Database>())
, accountModel(std::make_unique<NewAccountModel>(*database, *callbackHandler)) , accountModel(std::make_unique<NewAccountModel>(*database, *callbackHandler, *behaviorController))
{ {
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "api/contactmodel.h" #include "api/contactmodel.h"
#include "api/conversationmodel.h" #include "api/conversationmodel.h"
#include "api/account.h" #include "api/account.h"
#include "api/behaviorcontroller.h"
#include "authority/databasehelper.h" #include "authority/databasehelper.h"
#include "callbackshandler.h" #include "callbackshandler.h"
#include "database.h" #include "database.h"
...@@ -44,13 +45,15 @@ class NewAccountModelPimpl: public QObject ...@@ -44,13 +45,15 @@ class NewAccountModelPimpl: public QObject
public: public:
NewAccountModelPimpl(NewAccountModel& linked, NewAccountModelPimpl(NewAccountModel& linked,
Database& database, Database& database,
const CallbacksHandler& callbackHandler); const CallbacksHandler& callbackHandler,
const BehaviorController& behaviorController);
~NewAccountModelPimpl(); ~NewAccountModelPimpl();
NewAccountModel& linked; NewAccountModel& linked;
const CallbacksHandler& callbacksHandler; const CallbacksHandler& callbacksHandler;
Database& database; Database& database;
NewAccountModel::AccountInfoMap accounts; NewAccountModel::AccountInfoMap accounts;
const BehaviorController& behaviorController;
/** /**
* Add the profile information from an account to the db then add it to accounts. * Add the profile information from an account to the db then add it to accounts.
...@@ -73,9 +76,11 @@ public Q_SLOTS: ...@@ -73,9 +76,11 @@ public Q_SLOTS:
void slotAccountRemoved(Account* account); void slotAccountRemoved(Account* account);
}; };
NewAccountModel::NewAccountModel(Database& database, const CallbacksHandler& callbacksHandler) NewAccountModel::NewAccountModel(Database& database,
const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController)
: QObject() : QObject()
, pimpl_(std::make_unique<NewAccountModelPimpl>(*this, database, callbacksHandler)) , pimpl_(std::make_unique<NewAccountModelPimpl>(*this, database, callbacksHandler, behaviorController))
{ {
} }
...@@ -106,8 +111,10 @@ NewAccountModel::getAccountInfo(const std::string& accountId) const ...@@ -106,8 +111,10 @@ NewAccountModel::getAccountInfo(const std::string& accountId) const
NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked, NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked,
Database& database, Database& database,
const CallbacksHandler& callbacksHandler) const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController)
: linked(linked) : linked(linked)
, behaviorController(behaviorController)
, callbacksHandler(callbacksHandler) , callbacksHandler(callbacksHandler)
, database(database) , database(database)
{ {
...@@ -171,7 +178,7 @@ NewAccountModelPimpl::addToAccounts(const std::string& accountId) ...@@ -171,7 +178,7 @@ NewAccountModelPimpl::addToAccounts(const std::string& accountId)
// Init models for this account // Init models for this account
owner.callModel = std::make_unique<NewCallModel>(owner, callbacksHandler); owner.callModel = std::make_unique<NewCallModel>(owner, callbacksHandler);
owner.contactModel = std::make_unique<ContactModel>(owner, database, callbacksHandler); owner.contactModel = std::make_unique<ContactModel>(owner, database, callbacksHandler);
owner.conversationModel = std::make_unique<ConversationModel>(owner, database, callbacksHandler); owner.conversationModel = std::make_unique<ConversationModel>(owner, database, callbacksHandler, behaviorController);
owner.accountModel = &linked; owner.accountModel = &linked;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment