| 1 | /************************************************************************** |
| 2 | Copyright (C) 2016 Dan Chapman <[email protected]> |
| 3 | |
| 4 | This file is part of Dekko email client for Ubuntu devices |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU General Public License as |
| 8 | published by the Free Software Foundation; either version 2 of |
| 9 | the License or (at your option) version 3 |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **************************************************************************/ |
| 19 | #include "PolicyManager.h" |
| 20 | #include <QPointer> |
| 21 | #include <QScopedPointer> |
| 22 | |
| 23 | PolicyManager::PolicyManager(QObject *parent) : QObject(parent) |
| 24 | { |
| 25 | // Maintain instances of global policies |
| 26 | m_privacy = new PrivacyPolicy(this); |
| 27 | m_view = new ViewPolicy(this); |
| 28 | } |
| 29 | |
| 30 | static QPointer<PolicyManager> s_mgr; |
| 31 | PolicyManager *PolicyManager::instance() |
| 32 | { |
| 33 | if (s_mgr.isNull()) { |
| 34 | s_mgr = new PolicyManager(); |
| 35 | } |
| 36 | return s_mgr; |
| 37 | } |
| 38 | |
| 39 | QObject *PolicyManager::factory(QQmlEngine *engine, QJSEngine *scriptEngine) |
| 40 | { |
| 41 | Q_UNUSED(engine) |
| 42 | Q_UNUSED(scriptEngine) |
| 43 | return PolicyManager::instance(); |
| 44 | } |
| 45 | |
| 46 | MailPolicy *PolicyManager::mailPolicy(const int &accountId) |
| 47 | { |
| 48 | return mailPolicy(QMailAccountId(accountId)); |
| 49 | } |
| 50 | |
| 51 | MailPolicy *PolicyManager::mailPolicy(const QMailAccountId &accountId) |
| 52 | { |
| 53 | return new MailPolicy(this, accountId); |
| 54 | } |
| 55 | |
| 56 | PrivacyPolicy *PolicyManager::privacyPolicy() |
| 57 | { |
| 58 | if (m_privacy->isValid()) { |
| 59 | return m_privacy; |
| 60 | } |
| 61 | return Q_NULLPTR; |
| 62 | } |
| 63 | |
| 64 | ViewPolicy *PolicyManager::viewPolicy() |
| 65 | { |
| 66 | return m_view; |
| 67 | } |
| 68 | |
| 69 | void PolicyManager::setDefaultPolicies(const int &accountId) { |
| 70 | setDefaultPolicies(QMailAccountId(accountId)); |
| 71 | } |
| 72 | |
| 73 | void PolicyManager::setDefaultPolicies(const QMailAccountId &accountId) |
| 74 | { |
| 75 | QMailAccountId id(accountId); |
| 76 | if (id.isValid()) { |
| 77 | mailPolicy(accountId)->setDefaults(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | bool PolicyManager::idValid(const int &id) |
| 82 | { |
| 83 | return QMailAccountId(id).isValid(); |
| 84 | } |
| 85 |