Andreas Traczyk | fdc7f9b | 2018-08-14 18:42:03 -0400 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | | Copyright (C) 2015-2018 by Savoir-faire Linux | |
| 3 | | Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> | |
| 4 | | | |
| 5 | | This program is free software; you can redistribute it and/or modify | |
| 6 | | it under the terms of the GNU General Public License as published by | |
| 7 | | the Free Software Foundation; either version 3 of the License, or | |
| 8 | | (at your option) any later version. | |
| 9 | | | |
| 10 | | This program is distributed in the hope that it will be useful, | |
| 11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | | GNU General Public License for more details. | |
| 14 | | | |
| 15 | | You should have received a copy of the GNU General Public License | |
| 16 | | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | **************************************************************************/ |
| 18 | #pragma once |
| 19 | |
| 20 | #ifdef _MSC_VER |
| 21 | #undef ERROR |
| 22 | #endif |
| 23 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame^] | 24 | #include <QSettings> |
| 25 | |
Andreas Traczyk | fdc7f9b | 2018-08-14 18:42:03 -0400 | [diff] [blame] | 26 | #include "api/lrc.h" |
| 27 | #include "api/account.h" |
| 28 | #include "api/newaccountmodel.h" |
| 29 | #include "api/newcallmodel.h" |
| 30 | #include "api/behaviorcontroller.h" |
| 31 | #include "api/conversation.h" |
| 32 | #include "api/contactmodel.h" |
| 33 | #include "api/contact.h" |
| 34 | #include "api/datatransfermodel.h" |
| 35 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame^] | 36 | #include <settingskey.h> |
| 37 | |
Andreas Traczyk | fdc7f9b | 2018-08-14 18:42:03 -0400 | [diff] [blame] | 38 | class LRCInstance { |
| 39 | public: |
| 40 | static void init() { |
| 41 | instance(); |
| 42 | }; |
| 43 | static lrc::api::Lrc& getAPI() { |
| 44 | return *(instance().lrc_); |
| 45 | }; |
| 46 | static void connectivityChanged() { |
| 47 | instance().lrc_->connectivityChanged(); |
| 48 | }; |
| 49 | static const lrc::api::NewAccountModel& accountModel() { |
| 50 | return instance().lrc_->getAccountModel(); |
| 51 | }; |
| 52 | static const lrc::api::BehaviorController& behaviorController() { |
| 53 | return instance().lrc_->getBehaviorController(); |
| 54 | }; |
| 55 | static const lrc::api::DataTransferModel& dataTransferModel() { |
| 56 | return instance().lrc_->getDataTransferModel(); |
| 57 | }; |
| 58 | static bool isConnected() { |
| 59 | return instance().lrc_->isConnected(); |
| 60 | }; |
| 61 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame^] | 62 | static const lrc::api::account::Info& |
| 63 | getCurrentAccountInfo() { |
| 64 | return accountModel().getAccountInfo(instance().selectedAccountId); |
| 65 | }; |
| 66 | |
| 67 | static lrc::api::ConversationModel* |
| 68 | getCurrentConversationModel() { |
| 69 | return getCurrentAccountInfo().conversationModel.get(); |
| 70 | }; |
| 71 | |
| 72 | static lrc::api::NewCallModel* |
| 73 | getCurrentCallModel() { |
| 74 | return getCurrentAccountInfo().callModel.get(); |
| 75 | }; |
| 76 | |
| 77 | static const std::string& getSelectedAccountId() { |
| 78 | return instance().selectedAccountId; |
| 79 | }; |
| 80 | |
| 81 | static void setSelectedAccountId(const std::string& accountId) { |
| 82 | instance().selectedAccountId = accountId; |
| 83 | QSettings settings; |
| 84 | settings.setValue(SettingsKey::selectedAccount, QString::fromStdString(accountId)); |
| 85 | }; |
| 86 | |
| 87 | static const std::string& getSelectedConvUid() { |
| 88 | return instance().selectedConvUid; |
| 89 | }; |
| 90 | |
| 91 | static void setSelectedConvId(const std::string& convUid) { |
| 92 | instance().selectedConvUid = convUid; |
| 93 | }; |
| 94 | |
Andreas Traczyk | fdc7f9b | 2018-08-14 18:42:03 -0400 | [diff] [blame] | 95 | private: |
| 96 | std::unique_ptr<lrc::api::Lrc> lrc_; |
| 97 | |
| 98 | static LRCInstance& instance() { |
| 99 | static LRCInstance instance_; |
| 100 | return instance_; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame^] | 101 | }; |
Andreas Traczyk | fdc7f9b | 2018-08-14 18:42:03 -0400 | [diff] [blame] | 102 | |
| 103 | LRCInstance() { |
| 104 | lrc_ = std::make_unique<lrc::api::Lrc>(); |
| 105 | }; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame^] | 106 | |
| 107 | std::string selectedAccountId; |
| 108 | std::string selectedConvUid; |
Andreas Traczyk | fdc7f9b | 2018-08-14 18:42:03 -0400 | [diff] [blame] | 109 | }; |