diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c6efcf694f0ae13f97fcdca25e3a2545a14486e..81d89a185b0000a2f4ac973cf5b5e5cd136da435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ SET(QT5_MODULE_PATH ${QT5_PATH}/lib/cmake) FIND_PACKAGE(Ring REQUIRED) FIND_PACKAGE(Qt5Core REQUIRED) FIND_PACKAGE(Qt5LinguistTools) # translations +FIND_PACKAGE(Qt5Sql REQUIRED) IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT ENABLE_LIBWRAP) FIND_PACKAGE(Qt5DBus) @@ -205,13 +206,13 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_BINARY_DIR}) -# Build dbus interfaces +# Build dbus api IF(DEFINED RING_XML_INTERFACES_DIR) SET (dbus_xml_introspecs_path ${RING_XML_INTERFACES_DIR}) ELSEIF(EXISTS "${RING_BUILD_DIR}/../bin/dbus") SET (dbus_xml_introspecs_path ${RING_BUILD_DIR}/../bin/dbus) ELSE() - SET (dbus_xml_introspecs_path ${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces) + SET (dbus_xml_introspecs_path ${CMAKE_INSTALL_PREFIX}/share/dbus-1/api) ENDIF() #File to compile @@ -293,6 +294,13 @@ SET( libringclient_LIB_SRCS src/audio/settings.cpp src/media/recordingmodel.cpp src/bannedcontactmodel.cpp + src/contactmodel.cpp + src/newcallmodel.cpp + src/conversationmodel.cpp + src/database.cpp + src/lrc.cpp + src/newaccountmodel.cpp + src/callbackshandler.cpp #Data collections src/transitionalpersonbackend.cpp @@ -446,6 +454,20 @@ SET( libringclient_LIB_HDRS src/bannedcontactmodel.h ) +SET(libringclient_api_LIB_HDRS + src/api/message.h + src/api/conversation.h + src/api/contact.h + src/api/call.h + src/api/account.h + src/api/lrc.h + src/api/newaccountmodel.h + src/api/newcallmodel.h + src/api/contactmodel.h + src/api/conversationmodel.h +) + + SET(libringclient_video_LIB_HDRS src/video/device.h src/video/devicemodel.h @@ -637,6 +659,7 @@ IF(NOT ${ENABLE_STATIC} MATCHES false) -lpthread ${QT_QTDBUS_LIBRARY} ${QT_QTCORE_LIBRARY} + Qt5::Sql ) SET_TARGET_PROPERTIES( ringclient_static PROPERTIES VERSION ${GENERIC_LIB_VERSION} @@ -661,6 +684,7 @@ ENDIF() TARGET_LINK_LIBRARIES( ringclient -lpthread ${QT_QTCORE_LIBRARY} + Qt5::Sql ) IF(${ENABLE_LIBWRAP} MATCHES true) @@ -736,6 +760,12 @@ INSTALL( FILES ${libringclient_interface_LIB_HDRS} COMPONENT Devel ) +INSTALL( FILES ${libringclient_api_LIB_HDRS} + DESTINATION ${INCLUDE_INSTALL_DIR}/libringclient/api + COMPONENT Devel +) + + #This hack force Debian based system to return a non multi-arch path #this is required to prevent the .deb libringclient.so from having an #higher priority than the prefixed one. diff --git a/doc/Diagram1.dia b/doc/Diagram1.dia new file mode 100644 index 0000000000000000000000000000000000000000..7cf3e1844f468be4caaa64d3b2309b2b7b5b87d1 Binary files /dev/null and b/doc/Diagram1.dia differ diff --git a/doc/Diagram2.dia b/doc/Diagram2.dia new file mode 100644 index 0000000000000000000000000000000000000000..dba8decb55f0c3d4da6b2129dcf1588921389394 Binary files /dev/null and b/doc/Diagram2.dia differ diff --git a/src/api/account.h b/src/api/account.h new file mode 100644 index 0000000000000000000000000000000000000000..6742433f82f68f256818d31f0af82976aff808c2 --- /dev/null +++ b/src/api/account.h @@ -0,0 +1,56 @@ +/**************************************************************************** + * 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 + +#include <string> +#include <memory> + +namespace lrc +{ + +namespace api +{ + +class NewCallModel; +class ContactModel; +class ConversationModel; +class NewAccountModel; + +namespace account +{ + +enum class Type { + INVALID, + RING, + SIP +}; + +struct Info +{ + std::string id; + Type type = account::Type::INVALID; + std::unique_ptr<lrc::api::NewCallModel> callModel; + std::unique_ptr<lrc::api::ContactModel> contactModel; + std::unique_ptr<lrc::api::ConversationModel> conversationModel; + std::unique_ptr<lrc::api::NewAccountModel> accountModel; +}; + +} // namespace account +} // namespace api +} // namespace lrc diff --git a/src/api/call.h b/src/api/call.h new file mode 100644 index 0000000000000000000000000000000000000000..35dd998dbea69e2353e2a65f5493795e35a338bb --- /dev/null +++ b/src/api/call.h @@ -0,0 +1,60 @@ +/**************************************************************************** + * 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 <string> +#include <ctime> + +namespace lrc +{ + +namespace api +{ + +namespace call +{ + +enum class Status { + INVALID, + OUTGOING_REQUESTED, + INCOMING_RINGING, + OUTGOING_RINGING, + CONNECTING, + SEARCHING, + IN_PROGRESS, + PAUSED, + PEER_PAUSED, + INACTIVE, + ENDED, + TERMINATING, + CONNECTED, + AUTO_ANSWERING +}; + +struct Info +{ + std::string id; + std::time_t startTime = 0; + Status status = Status::INVALID; +}; + +} // namespace call +} // namespace api +} // namespace lrc diff --git a/src/api/contact.h b/src/api/contact.h new file mode 100644 index 0000000000000000000000000000000000000000..7cb65363613aeb822d6a3e9b346e4d3f37c49c5e --- /dev/null +++ b/src/api/contact.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * 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 <string> + +namespace lrc +{ + +namespace api +{ + +namespace contact +{ + +enum class Type { + INVALID, + RING, + SIP +}; + +struct Info +{ + std::string uri; + std::string avatar; + std::string registeredName; + std::string alias; + bool isTrusted = false; + bool isPresent = false; + Type type = Type::INVALID; +}; + +} // namespace contact +} // namespace api +} // namespace lrc diff --git a/src/api/contactmodel.h b/src/api/contactmodel.h new file mode 100644 index 0000000000000000000000000000000000000000..d11d46df1e7386dd964e73b86105bd76a6355b77 --- /dev/null +++ b/src/api/contactmodel.h @@ -0,0 +1,74 @@ +/**************************************************************************** + * 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 <string> +#include <memory> +#include <map> + +// Qt +#include <qobject.h> + +// LRC +#include "typedefs.h" + +namespace lrc +{ + +class Database; +class ContactModelPimpl; + +namespace api +{ + +namespace contact { struct Info; } +namespace account { struct Info; } +class NewAccountModel; +class ConversationModel; + +class LIB_EXPORT ContactModel : public QObject { + Q_OBJECT +public: + using ContactInfoMap = std::map<std::string, std::shared_ptr<contact::Info>>; + + const account::Info& owner; + + ContactModel(NewAccountModel& parent, + const Database& database, + const account::Info& info); + ~ContactModel(); + + const contact::Info& getContact(const std::string& uri) const; + const ContactInfoMap& getAllContacts() const; + void addContact(const std::string& uri); + void removeContact(const std::string& uri); + void nameLookup(const std::string& uri) const; + void addressLookup(const std::string& name) const; + +Q_SIGNALS: + void contactsChanged(); + +private: + std::unique_ptr<ContactModelPimpl> pimpl_; + +}; + +} // namespace api +} // namespace lrc diff --git a/src/api/conversation.h b/src/api/conversation.h new file mode 100644 index 0000000000000000000000000000000000000000..90b195ee8d78d980a05a28983ee191868222cd66 --- /dev/null +++ b/src/api/conversation.h @@ -0,0 +1,51 @@ +/**************************************************************************** + * 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 <vector> +#include <map> + +// Data +#include "message.h" + +namespace lrc +{ + +namespace api +{ + +namespace conversation +{ + +struct Info +{ + std::string uid; + std::string accountId; + std::vector<std::string> participants; + std::string callId; + std::map<int, message::Info> messages; + unsigned int lastMessageUid = 0; + bool isUsed = false; + unsigned int unreadMessages = 0; +}; + +} // namespace conversation +} // namespace api +} // namespace lrc diff --git a/src/api/conversationmodel.h b/src/api/conversationmodel.h new file mode 100644 index 0000000000000000000000000000000000000000..8f58d3479f742f264b5655c3f2bb9d46ec978540 --- /dev/null +++ b/src/api/conversationmodel.h @@ -0,0 +1,88 @@ +/**************************************************************************** + * 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> +#include <map> +#include <string> +#include <deque> + +// Qt +#include <qobject.h> + +// Lrc +#include "typedefs.h" + +// Data +#include "api/conversation.h" + +namespace lrc +{ + +class Database; +class ConversationModelPimpl; + +namespace api +{ + +namespace account { struct Info; } +namespace message { struct Info; } +class NewAccountModel; + +class LIB_EXPORT ConversationModel : public QObject { + Q_OBJECT +public: + using ConversationQueue = std::deque<conversation::Info>; + + const account::Info& owner; + + ConversationModel(const NewAccountModel& parent, + const Database& database, + const account::Info& info); + ~ConversationModel(); + + const ConversationQueue& getFilteredConversations() const; + conversation::Info getConversation(unsigned int row) const; + void addConversation(const std::string& uri) const; + void removeConversation(const std::string& uid); + void selectConversation(const std::string& uid); + void placeCall(const std::string& uid) const; + void sendMessage(const std::string& uid, const std::string& body) const; + void setFilter(const std::string& filter); + void addParticipant(const std::string& uid, const::std::string& uri); + void clearHistory(const std::string& uid); + +Q_SIGNALS: + void newMessageAdded(const std::string& uid, const message::Info& msg); + void conversationUpdated(unsigned int row); + void modelUpdated() const; + void newContactAdded(const std::string& uri); + void incomingCallFromItem(const unsigned int row); + + void showChatView(const conversation::Info& conversationInfo); + void showCallView(const conversation::Info& conversationInfo); + void showIncomingCallView(const conversation::Info& conversationInfo); + +private: + std::unique_ptr<ConversationModelPimpl> pimpl_; +}; + +} // namespace api +} // namespace lrc diff --git a/src/api/lrc.h b/src/api/lrc.h new file mode 100644 index 0000000000000000000000000000000000000000..67b7a50b97dfcc5407e3633d4f4740194c777ae7 --- /dev/null +++ b/src/api/lrc.h @@ -0,0 +1,51 @@ +/**************************************************************************** + * 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> + +// Lrc +#include "typedefs.h" + +namespace lrc +{ + +class Database; +class CallbacksHandler; +class LrcPimpl; + +namespace api +{ + +class NewAccountModel; + +class LIB_EXPORT Lrc { +public: + Lrc(); + ~Lrc(); + + NewAccountModel& getAccountModel(); + +private: + std::unique_ptr<LrcPimpl> lrcPipmpl_; +}; + +} // namespace api +} // namespace lrc diff --git a/src/api/message.h b/src/api/message.h new file mode 100644 index 0000000000000000000000000000000000000000..be99b91da0e31466f548f418f8378553048dc476 --- /dev/null +++ b/src/api/message.h @@ -0,0 +1,60 @@ +/**************************************************************************** + * 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 <ctime> +#include <string> + +namespace lrc +{ + +namespace api +{ + +namespace message +{ + +enum class Type { + INVALID, + TEXT, + CALL, + CONTACT +}; + +enum class Status { + INVALID, + SENDING, + FAILED, + SUCCEED, + READ +}; + +struct Info +{ + std::string contact; + std::string body; + std::time_t timestamp = 0; + Type type = Type::INVALID; + Status status = Status::INVALID; +}; + +} // namespace message +} // namespace api +} // namespace lrc diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h new file mode 100644 index 0000000000000000000000000000000000000000..6b67d5e133b30cd00ddc0248dcba3b5afc5f979b --- /dev/null +++ b/src/api/newaccountmodel.h @@ -0,0 +1,59 @@ +/**************************************************************************** + * 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 <vector> +#include <map> +#include <memory> +#include <string> + +// Qt +#include <qobject.h> + +// Lrc +#include "typedefs.h" + +namespace lrc +{ + +class Database; +class NewAccountModelPimpl; + +namespace api +{ + +namespace account { struct Info; } + +class LIB_EXPORT NewAccountModel : public QObject { +public: + using AccountInfoMap = std::map<std::string, account::Info>; + + NewAccountModel(const Database& database); + ~NewAccountModel(); + + const std::vector<std::string> getAccountList() const; + const account::Info& getAccountInfo(const std::string& accountId); + +private: + std::unique_ptr<NewAccountModelPimpl> pimpl_; +}; + +} // namespace api +} // namespace lrc diff --git a/src/api/newcallmodel.h b/src/api/newcallmodel.h new file mode 100644 index 0000000000000000000000000000000000000000..a2223c6fcaa7534089c4e7d7949114e56c36a6a9 --- /dev/null +++ b/src/api/newcallmodel.h @@ -0,0 +1,73 @@ +/**************************************************************************** + * 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> +#include <string> +#include <map> + +// Qt +#include <qobject.h> + +namespace lrc +{ + +class NewCallModelPimpl; + +namespace api +{ + +namespace account { struct Info; } +namespace call { struct Info; } +class NewAccountModel; + +class NewCallModel : public QObject { + Q_OBJECT +public: + using CallInfoMap = std::map<std::string, std::shared_ptr<call::Info>>; + + const account::Info& owner; + + enum class Media { + NONE, + AUDIO, + VIDEO + }; + + NewCallModel(NewAccountModel& parent, const account::Info& info); + ~NewCallModel(); + + const call::Info& createCall(const std::string& contactUri); + + void hangUp(const std::string& callId) const; + void togglePause(const std::string& callId) const; + void toggleMedia(const std::string& callId, const Media media) const; + void toggleRecoringdAudio(const std::string& callId) const; + void setQuality(const std::string& callId, const double quality) const; + void transfer(const std::string& callId, const std::string& to) const; + void addParticipant(const std::string& callId, const std::string& participant); + void removeParticipant(const std::string& callId, const std::string& participant); + +private: + std::unique_ptr<NewCallModelPimpl> pimpl_; +}; + +} // namespace api +} // namespace lrc diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f3dbba5a76920089c6513657cf177d4e9e8dbb1 --- /dev/null +++ b/src/callbackshandler.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** + * 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 "callbackshandler.h" + +namespace lrc +{ + +CallbacksHandler::CallbacksHandler() +: QObject() +{ + +} + +CallbacksHandler::~CallbacksHandler() +{ + +} + +void +CallbacksHandler::slotNewAccountMessage(const QString& accountId, + const QString& from, + const MapStringString& payloads) +{ + +} + +void +CallbacksHandler::slotNewBuddySubscription(const QString& accountId, + const QString& uri, + bool status, + const QString& message) +{ + +} + +} // namespace lrc diff --git a/src/callbackshandler.h b/src/callbackshandler.h new file mode 100644 index 0000000000000000000000000000000000000000..363150386fffe28e87c684d68525ed283203421c --- /dev/null +++ b/src/callbackshandler.h @@ -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/>. * + ***************************************************************************/ +#pragma once + +// Qt +#include <qobject.h> + +// Lrc +#include "typedefs.h" + +namespace lrc +{ + +class CallbacksHandler : public QObject { + Q_OBJECT + +public: + CallbacksHandler(); + ~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); +}; + +} // namespace lrc diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6c901157d39e479ed6a1e637318ba9fbe213987 --- /dev/null +++ b/src/contactmodel.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** + * 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/contactmodel.h" + +// LRC +#include "api/newaccountmodel.h" +#include "api/contact.h" + +#include "database.h" + +namespace lrc +{ + +using namespace api; + +class ContactModelPimpl : public QObject +{ + Q_OBJECT +public: + ContactModelPimpl(NewAccountModel& p, const Database& d); + ~ContactModelPimpl(); + ContactModelPimpl(const ContactModelPimpl& contactModelPimpl); + + bool fillsWithContacts(); + void sendMessage(const std::string& uri, const std::string& body) const; + void setContactPresent(const std::string& uri, bool status); + + const Database& db; + ContactModel::ContactInfoMap contacts; + NewAccountModel& parent; + +public Q_SLOTS: + // TODO remove this from here when LRC signals are added + void slotContactsAdded(const QString &accountID, const QString &uri, bool confirmed); + void slotContactsRemoved(const QString &accountID, const QString &uri, bool status); +}; + + +ContactModel::ContactModel(NewAccountModel& parent, const Database& database, const account::Info& info) +: QObject() +, pimpl_(std::make_unique<ContactModelPimpl>(parent, database)) +, owner(info) +{ + +} + +ContactModel::~ContactModel() +{ + +} + +const contact::Info& +ContactModel::getContact(const std::string& uri) const +{ + throw std::invalid_argument("no contact found for given uri"); +} + +const ContactModel::ContactInfoMap& +ContactModel::getAllContacts() const +{ + return pimpl_->contacts; +} + +void +ContactModel::addContact(const std::string& uri) +{ + +} + +void +ContactModel::removeContact(const std::string& uri) +{ + +} + +void +ContactModel::nameLookup(const std::string& uri) const +{ + +} + +void +ContactModel::addressLookup(const std::string& name) const +{ + +} + +ContactModelPimpl::ContactModelPimpl(NewAccountModel& p, const Database& d) +: db(d) +, parent(p) +{ + +} + +ContactModelPimpl::~ContactModelPimpl() +{ + +} + +ContactModelPimpl::ContactModelPimpl(const ContactModelPimpl& contactModelPimpl) +: db(contactModelPimpl.db) +, contacts(contactModelPimpl.contacts) +, parent(contactModelPimpl.parent) +{ + +} + +void +ContactModelPimpl::sendMessage(const std::string& uri, const std::string& body) const +{ + +} + +bool +ContactModelPimpl::fillsWithContacts() +{ + return false; +} + +void +ContactModelPimpl::setContactPresent(const std::string& uri, bool status) +{ + +} + +void +ContactModelPimpl::slotContactsAdded(const QString &accountID, const QString &uri, bool confirmed) +{ + +} + +void +ContactModelPimpl::slotContactsRemoved(const QString &accountID, const QString &uri, bool status) +{ + +} + +} // namespace lrc + +#include "api/moc_contactmodel.cpp" +#include "contactmodel.moc" diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..462655d249097daaa4bd785ca7e393269a069fe1 --- /dev/null +++ b/src/conversationmodel.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** + * 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/conversationmodel.h" + +// std +#include <regex> + +// LRC +#include "api/newcallmodel.h" +#include "api/newaccountmodel.h" +#include "api/account.h" + +#include "database.h" +#include "namedirectory.h" + +namespace lrc +{ + +using namespace api; + +class ConversationModelPimpl : public QObject +{ + Q_OBJECT +public: + ConversationModelPimpl(const NewAccountModel& p, const Database& d, const account::Info& o); + ~ConversationModelPimpl(); + + // shortcuts in owner + NewCallModel& callModel; + + /** + * Search a conversation in conversations_ + * @param uid the contact to search + * @return the index in conversations_ + */ + int find(const std::string& uid) const; + /** + * Initialize conversations_ and filteredConversations_ + */ + void initConversations(); + /** + * Sort conversation by last action + */ + void sortConversations(); + void search(); + + const NewAccountModel& parent; + const Database& database; + + ConversationModel::ConversationQueue conversations; + mutable ConversationModel::ConversationQueue filteredConversations; + std::string filter; + +public Q_SLOTS: + void slotContactsChanged(); + void slotMessageAdded(int uid, const std::string& accountId, const message::Info& msg); + void slotRegisteredNameFound(const Account* account, NameDirectory::LookupStatus status, + const QString& address, const QString& name); + +}; + +ConversationModel::ConversationModel(const NewAccountModel& parent, + const Database& database, + const account::Info& info) +: QObject() +,pimpl_(std::make_unique<ConversationModelPimpl>(parent, database, owner)) +, owner(info) +{ + +} + +ConversationModel::~ConversationModel() +{ + +} + +const ConversationModel::ConversationQueue& +ConversationModel::getFilteredConversations() const +{ + return pimpl_->conversations; +} + +conversation::Info +ConversationModel::getConversation(const unsigned int row) const +{ + return {}; +} + +void +ConversationModel::addConversation(const std::string& uri) const +{ + +} + +void +ConversationModel::selectConversation(const std::string& uid) +{ + +} + +void +ConversationModel::removeConversation(const std::string& uid) +{ + +} + +void +ConversationModel::placeCall(const std::string& uid) const +{ +} + +void +ConversationModel::sendMessage(const std::string& uid, const std::string& body) const +{ + +} + +void +ConversationModel::setFilter(const std::string& filter) +{ + +} + +void +ConversationModel::addParticipant(const std::string& uid, const::std::string& uri) +{ + +} + +void +ConversationModel::clearHistory(const std::string& uid) +{ + +} + +ConversationModelPimpl::ConversationModelPimpl(const NewAccountModel& p, const Database& d, const account::Info& o) +: parent(p) +, database(d) +, callModel(*o.callModel) +{ + +} + +ConversationModelPimpl::~ConversationModelPimpl() +{ + +} + +int +ConversationModelPimpl::find(const std::string& uid) const +{ + return -1; +} + +void +ConversationModelPimpl::search() +{ + +} + +void +ConversationModelPimpl::initConversations() +{ + +} + +void +ConversationModelPimpl::sortConversations() +{ + +} + +void +ConversationModelPimpl::slotContactsChanged() +{ + +} + +void +ConversationModelPimpl::slotMessageAdded(int uid, const std::string& account, const message::Info& msg) +{ + +} + +void +ConversationModelPimpl::slotRegisteredNameFound(const Account* account, NameDirectory::LookupStatus status, + const QString& address, const QString& name) +{ + +} + +} // namespace lrc + +#include "api/moc_conversationmodel.cpp" +#include "conversationmodel.moc" diff --git a/src/database.cpp b/src/database.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1613ef77f07bc83ab3045628cc3b97ff0c7c6225 --- /dev/null +++ b/src/database.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** + * 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 "database.h" + +// Data +#include "api/message.h" + +namespace lrc +{ + +using namespace api; + +Database::Database() +: QObject() +{ + +} + +Database::~Database() +{ + +} + +void +Database::addMessage(const std::string& accountId, const message::Info& message) const +{ + +} + +void +Database::clearHistory(const std::string& accountId, const std::string& uid, bool removeContact) const +{ + +} + +Database::MessagesMap +Database::getHistory(const std::string& accountId, const std::string& uid) const +{ + return {}; +} + +std::size_t +Database::numberOfUnreads(const std::string& accountId, const std::string& uid) const +{ + return 0; +} + +void +Database::setMessageRead(int uid) const +{ + +} + +void +Database::addContact(const std::string& contact, const QByteArray& payload) const +{ + +} + +std::string +Database::getContactAttribute(const std::string& uid, const std::string& attribute) const +{ + return {}; +} + +void +Database::slotRegisteredNameFound(Account const*, NameDirectory::LookupStatus, QString const&, QString const&) const +{ + +} + +} // namespace lrc diff --git a/src/database.h b/src/database.h new file mode 100644 index 0000000000000000000000000000000000000000..b61bbd1ffce94ef573e6fe0c1e03a6c1b81c1dd8 --- /dev/null +++ b/src/database.h @@ -0,0 +1,78 @@ +/**************************************************************************** + * 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> +#include <string> + +// Qt +#include <qobject.h> +#include <QtSql/QSqlQuery> + +// Lrc +#include "namedirectory.h" + +class Account; // TODO: move this class into lrc ns + +namespace lrc +{ + +namespace api { namespace message { struct Info; }} + +class Database : public QObject { + Q_OBJECT + +public: + using MessagesMap = std::map<int, api::message::Info>; + + static constexpr auto ringDB = "ring.db"; // TODO: set path correctly for tests and release. + + Database(); + ~Database(); + + // Messages related + void addMessage(const std::string& accountId, const api::message::Info& message) const; + void clearHistory(const std::string& accountId, + const std::string& uid, + bool removeContact = false) const; + MessagesMap getHistory(const std::string& accountId, const std::string& uid) const; + std::size_t numberOfUnreads(const std::string& accountId, const std::string& uid) const; + void setMessageRead(int uid) const; + + // Contacts related + void addContact(const std::string& contact, const QByteArray& payload) const; + std::string getContactAttribute(const std::string& uid, const std::string& attribute) const; + +Q_SIGNALS: + void messageAdded(int uid, const std::string& accountId, const api::message::Info& msg) const; + void contactAdded(const std::string& uid) const; + +private Q_SLOTS: + void slotRegisteredNameFound(const Account* account, + NameDirectory::LookupStatus status, + const QString& address, + const QString& name) const; + +private: + std::unique_ptr<QSqlQuery> query_; + QSqlDatabase db_; +}; + +} // namespace lrc diff --git a/src/lrc.cpp b/src/lrc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e73838d2e406ec6724915c8fc5cea39839281347 --- /dev/null +++ b/src/lrc.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** + * 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/lrc.h" + +// Models and database +#include "api/newaccountmodel.h" +#include "database.h" +#include "callbackshandler.h" + +namespace lrc +{ + +using namespace api; + +class LrcPimpl +{ + +public: + LrcPimpl(); + + std::unique_ptr<Lrc> parent; + std::unique_ptr<Database> database; + std::unique_ptr<NewAccountModel> accountModel; + std::unique_ptr<CallbacksHandler> callbackHandler; +}; + +Lrc::Lrc() +: lrcPipmpl_(std::make_unique<LrcPimpl>()) +{ +} + +Lrc::~Lrc() +{ +} + +NewAccountModel& +Lrc::getAccountModel() +{ + return *lrcPipmpl_->accountModel; +} + +LrcPimpl::LrcPimpl() +{ + database = std::make_unique<Database>(); +} + +} // namespace lrc diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8128c92b93f84a8663bbda309512eb9d28a9613d --- /dev/null +++ b/src/newaccountmodel.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** + * 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/newaccountmodel.h" + + +// LRC +#include "api/newcallmodel.h" +#include "api/contactmodel.h" +#include "api/conversationmodel.h" +#include "api/account.h" + +#include "database.h" + +namespace lrc +{ + +using namespace api; + +class NewAccountModelPimpl +{ +public: + NewAccountModelPimpl(const Database& database); + ~NewAccountModelPimpl(); + + const Database& database; + NewAccountModel::AccountInfoMap accounts; +}; + +NewAccountModel::NewAccountModel(const Database& database) +: QObject() +, pimpl_(std::make_unique<NewAccountModelPimpl>(database)) +{ +} + +NewAccountModel::~NewAccountModel() +{ +} + +const std::vector<std::string> +NewAccountModel::getAccountList() const +{ + return {}; +} + +const account::Info& +NewAccountModel::getAccountInfo(const std::string& accountId) +{ + return pimpl_->accounts[accountId]; +} + +NewAccountModelPimpl::NewAccountModelPimpl(const Database& database) +: database(database) +{ + +} + +NewAccountModelPimpl::~NewAccountModelPimpl() +{ + +} + +} // namespace lrc + +#include "api/moc_newaccountmodel.cpp" diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f834430ba8fe65c3bfe4e7b0f78b9f926dc505a1 --- /dev/null +++ b/src/newcallmodel.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** + * 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/newcallmodel.h" + +// LRC +#include "api/newaccountmodel.h" + +namespace lrc +{ + +using namespace api; + +class NewCallModelPimpl +{ +public: + NewCallModelPimpl(NewAccountModel& parent); + ~NewCallModelPimpl(); + + void sendMessage(const std::string& callId, const std::string& body) const; + + NewCallModel::CallInfoMap calls; + NewAccountModel& parent; +}; + +NewCallModel::NewCallModel(NewAccountModel& parent, const account::Info& info) +: QObject() +, owner(info) +, pimpl_(std::make_unique<NewCallModelPimpl>(parent)) +{ + +} + +NewCallModel::~NewCallModel() +{ + +} + +const call::Info& +NewCallModel::createCall(const std::string& contactUri) +{ + +} + +void +NewCallModel::hangUp(const std::string& callId) const +{ + +} + +void +NewCallModel::togglePause(const std::string& callId) const +{ + +} + +void +NewCallModel::toggleMedia(const std::string& callId, const Media media) const +{ + +} + +void +NewCallModel::toggleRecoringdAudio(const std::string& callId) const +{ + +} + +void +NewCallModel::setQuality(const std::string& callId, const double quality) const +{ + +} + +void +NewCallModel::transfer(const std::string& callId, const std::string& to) const +{ + +} + +void +NewCallModel::addParticipant(const std::string& callId, const std::string& participant) +{ + +} + +void +NewCallModel::removeParticipant(const std::string& callId, const std::string& participant) +{ + +} + +NewCallModelPimpl::NewCallModelPimpl(NewAccountModel& p) +: parent(p) +{ + +} + +NewCallModelPimpl::~NewCallModelPimpl() +{ + +} + +void +NewCallModelPimpl::sendMessage(const std::string& callId, const std::string& body) const +{ + +} + +} // namespace lrc + +#include "api/moc_newcallmodel.cpp"