Commit 7c0a57bd authored by Nicolas Jager's avatar Nicolas Jager Committed by Sébastien Blin

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
......@@ -309,6 +309,7 @@ SET( libringclient_LIB_SRCS
src/lrc.cpp
src/newaccountmodel.cpp
src/callbackshandler.cpp
src/behaviorcontroller.cpp
#Data collections
src/transitionalpersonbackend.cpp
......@@ -474,6 +475,7 @@ SET(libringclient_api_LIB_HDRS
src/api/contactmodel.h
src/api/conversationmodel.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
namespace account { struct Info; }
namespace interaction { struct Info; }
class BehaviorController;
class NewAccountModel;
/**
......@@ -58,7 +59,10 @@ public:
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();
/**
......
......@@ -32,6 +32,7 @@ class LrcPimpl;
namespace api
{
class BehaviorController;
class NewAccountModel;
class LIB_EXPORT Lrc {
......@@ -43,6 +44,11 @@ public:
* @return a NewAccountModel&.
*/
const NewAccountModel& getAccountModel() const;
/**
* get a reference on the behavior controller.
* @return a BehaviorController&.
*/
const BehaviorController& getBehaviorController() const;
private:
std::unique_ptr<LrcPimpl> lrcPimpl_;
......
......@@ -39,6 +39,7 @@ class NewAccountModelPimpl;
namespace api
{
class BehaviorController;
namespace account { struct Info; }
......@@ -50,7 +51,10 @@ class LIB_EXPORT NewAccountModel : public QObject {
public:
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();
/**
* 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 @@
#include <algorithm>
// LRC
#include "api/behaviorcontroller.h"
#include "api/contactmodel.h"
#include "api/newcallmodel.h"
#include "api/newaccountmodel.h"
......@@ -52,7 +53,8 @@ class ConversationModelPimpl : public QObject
public:
ConversationModelPimpl(const ConversationModel& linked,
Database& db,
const CallbacksHandler& callbacksHandler);
const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController);
~ConversationModelPimpl();
......@@ -104,6 +106,7 @@ public:
Database& db;
const CallbacksHandler& callbacksHandler;
const std::string accountProfileId;
const BehaviorController& behaviorController;
ConversationModel::ConversationQueue conversations; ///< non-filtered conversations
ConversationModel::ConversationQueue filteredConversations;
......@@ -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()
, pimpl_(std::make_unique<ConversationModelPimpl>(*this, db, callbacksHandler))
, pimpl_(std::make_unique<ConversationModelPimpl>(*this, db, callbacksHandler, behaviorController))
, owner(owner)
{
......@@ -275,14 +281,14 @@ ConversationModel::selectConversation(const std::string& uid) const
case call::Status::CONNECTING:
case call::Status::SEARCHING:
// We are currently in a call
// TODO fully functional behaviour not implemented in this patch
emit pimpl_->behaviorController.showIncomingCallView(owner.id, conversation);
break;
case call::Status::PAUSED:
case call::Status::PEER_PAUSED:
case call::Status::CONNECTED:
case call::Status::IN_PROGRESS:
// We are currently receiving a call
// TODO fully functional behaviour not implemented in this patch
emit pimpl_->behaviorController.showCallView(owner.id, conversation);
break;
case call::Status::INVALID:
case call::Status::OUTGOING_REQUESTED:
......@@ -292,11 +298,10 @@ ConversationModel::selectConversation(const std::string& uid) const
case call::Status::AUTO_ANSWERING:
default:
// We are not in a call, show the chatview
// TODO fully functional behaviour not implemented in this patch
break;
emit pimpl_->behaviorController.showChatView(owner.id, conversation);
}
} 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)
conversation = pimpl_->conversations.at(conversationIdx);
}
pimpl_->dirtyConversations = true;
// fully functional behaviour not implemented in this patch
emit pimpl_->behaviorController.showIncomingCallView(owner.id, conversation);
}
void
......@@ -466,12 +471,14 @@ ConversationModel::clearHistory(const std::string& uid)
ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked,
Database& db,
const CallbacksHandler& callbacksHandler)
const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController)
: linked(linked)
, db(db)
, callbacksHandler(callbacksHandler)
, typeFilter(profile::Type::INVALID)
, accountProfileId(database::getProfileId(db, linked.owner.profileInfo.uri))
, behaviorController(behaviorController)
{
initConversations();
......@@ -721,7 +728,7 @@ ConversationModelPimpl::slotIncomingCall(const std::string& fromId, const std::s
qDebug() << "Add call to conversation with " << fromId.c_str();
conversation.callId = callId;
dirtyConversations = true;
// fully functional behaviour not implemented in this patch
emit behaviorController.showIncomingCallView(linked.owner.id, conversation);
}
void
......
......@@ -20,6 +20,7 @@
// Models and database
#include "api/newaccountmodel.h"
#include "api/behaviorcontroller.h"
#include "database.h"
#include "callbackshandler.h"
#include "dbus/instancemanager.h"
......@@ -36,6 +37,7 @@ public:
LrcPimpl(const Lrc& linked);
const Lrc& linked;
std::unique_ptr<BehaviorController> behaviorController;
std::unique_ptr<CallbacksHandler> callbackHandler;
std::unique_ptr<Database> database;
std::unique_ptr<NewAccountModel> accountModel;
......@@ -59,11 +61,18 @@ Lrc::getAccountModel() const
return *lrcPimpl_->accountModel;
}
const BehaviorController&
Lrc::getBehaviorController() const
{
return *lrcPimpl_->behaviorController;
}
LrcPimpl::LrcPimpl(const Lrc& linked)
: linked(linked)
, behaviorController(std::make_unique<BehaviorController>())
, callbackHandler(std::make_unique<CallbacksHandler>(linked))
, database(std::make_unique<Database>())
, accountModel(std::make_unique<NewAccountModel>(*database, *callbackHandler))
, accountModel(std::make_unique<NewAccountModel>(*database, *callbackHandler, *behaviorController))
{
}
......
......@@ -24,6 +24,7 @@
#include "api/contactmodel.h"
#include "api/conversationmodel.h"
#include "api/account.h"
#include "api/behaviorcontroller.h"
#include "authority/databasehelper.h"
#include "callbackshandler.h"
#include "database.h"
......@@ -44,13 +45,15 @@ class NewAccountModelPimpl: public QObject
public:
NewAccountModelPimpl(NewAccountModel& linked,
Database& database,
const CallbacksHandler& callbackHandler);
const CallbacksHandler& callbackHandler,
const BehaviorController& behaviorController);
~NewAccountModelPimpl();
NewAccountModel& linked;
const CallbacksHandler& callbacksHandler;
Database& database;
NewAccountModel::AccountInfoMap accounts;
const BehaviorController& behaviorController;
/**
* Add the profile information from an account to the db then add it to accounts.
......@@ -73,9 +76,11 @@ public Q_SLOTS:
void slotAccountRemoved(Account* account);
};
NewAccountModel::NewAccountModel(Database& database, const CallbacksHandler& callbacksHandler)
NewAccountModel::NewAccountModel(Database& database,
const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController)
: 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
NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked,
Database& database,
const CallbacksHandler& callbacksHandler)
const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController)
: linked(linked)
, behaviorController(behaviorController)
, callbacksHandler(callbacksHandler)
, database(database)
{
......@@ -171,7 +178,7 @@ NewAccountModelPimpl::addToAccounts(const std::string& accountId)
// Init models for this account
owner.callModel = std::make_unique<NewCallModel>(owner, 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;
}
......
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