diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fa534d77de68316df83493692959c3f96c8a1fd..bf307281f37f5cbf3558d86fd8b432d56a1f3249 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/src/api/behaviorcontroller.h b/src/api/behaviorcontroller.h new file mode 100644 index 0000000000000000000000000000000000000000..762a127da70b7bf3615234fb22642ed365667d8b --- /dev/null +++ b/src/api/behaviorcontroller.h @@ -0,0 +1,71 @@ +/**************************************************************************** + * 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 diff --git a/src/api/conversationmodel.h b/src/api/conversationmodel.h index 70a6b5f113df59754beb4048cfa1a8ed4c500be6..2fa3544e85d5da7ac6f5e8f439abc9b46bf71d4f 100644 --- a/src/api/conversationmodel.h +++ b/src/api/conversationmodel.h @@ -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(); /** diff --git a/src/api/lrc.h b/src/api/lrc.h index 121e416a43c1b58916e291499231b57baca57b49..4c0fbdecd0f997fa378a374325856ee9ff5bd07e 100644 --- a/src/api/lrc.h +++ b/src/api/lrc.h @@ -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_; diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h index bfae21e29d61168c3039c79ca97ab904ea8c9185..ea4b644a432afd966ffb7d438b474c8729ee5d77 100644 --- a/src/api/newaccountmodel.h +++ b/src/api/newaccountmodel.h @@ -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. diff --git a/src/behaviorcontroller.cpp b/src/behaviorcontroller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8412c8f53aa2fc38831e64733792481ebad9adeb --- /dev/null +++ b/src/behaviorcontroller.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** + * 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" diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 543c872790e1726289c5119a5b8122a91633bc93..f751f1ec5f0e045e1027248df7c2bcf8ce07bbf0 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -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 diff --git a/src/lrc.cpp b/src/lrc.cpp index 46d0cfe96e45a996ee30dbf01d2b3a8866cb9950..7ceda39258633855bbee3cfbcfd17461a9d4440a 100644 --- a/src/lrc.cpp +++ b/src/lrc.cpp @@ -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)) { } diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index cc9da8b7f605cb6d37cd7da410f9fb351b805227..fd814ae9cabcd5257344e333b977799637c66ce6 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -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; }