| 1 | /* |
| 2 | * This file is part of libOnlineAccounts |
| 3 | * |
| 4 | * Copyright (C) 2016 Canonical Ltd. |
| 5 | * |
| 6 | * Contact: Alberto Mardegan <[email protected]> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU Lesser General Public License version 3, as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #ifndef ONLINE_ACCOUNTS_SERVICE_H |
| 22 | #define ONLINE_ACCOUNTS_SERVICE_H |
| 23 | |
| 24 | #include <QObject> |
| 25 | #include <QSharedData> |
| 26 | #include <QSharedDataPointer> |
| 27 | #include <QUrl> |
| 28 | #include <QVariantMap> |
| 29 | |
| 30 | #include "global.h" |
| 31 | |
| 32 | namespace OnlineAccounts { |
| 33 | |
| 34 | class Manager; |
| 35 | class ManagerPrivate; |
| 36 | |
| 37 | class ONLINE_ACCOUNTS_EXPORT Service |
| 38 | { |
| 39 | Q_GADGET |
| 40 | Q_PROPERTY(QString serviceId READ id CONSTANT) |
| 41 | Q_PROPERTY(QString displayName READ displayName CONSTANT) |
| 42 | Q_PROPERTY(QUrl iconSource READ iconSource CONSTANT) |
| 43 | |
| 44 | private: |
| 45 | class ServiceData: public QSharedData { |
| 46 | ServiceData(const QVariantMap &map); |
| 47 | friend class ManagerPrivate; |
| 48 | friend class Service; |
| 49 | QString m_id; |
| 50 | QString m_displayName; |
| 51 | QUrl m_iconSource; |
| 52 | }; |
| 53 | |
| 54 | public: |
| 55 | Service(); |
| 56 | ~Service() {} |
| 57 | |
| 58 | Service(const Service &other): d(other.d) {} |
| 59 | |
| 60 | bool isValid() const { return !d->m_id.isEmpty(); } |
| 61 | QString id() const { return d->m_id; } |
| 62 | QString displayName() const { return d->m_displayName; } |
| 63 | QUrl iconSource() const { return d->m_iconSource; } |
| 64 | |
| 65 | #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) |
| 66 | QVariantMap toMap() const; |
| 67 | #endif |
| 68 | |
| 69 | protected: |
| 70 | Service(const QVariantMap &map); |
| 71 | |
| 72 | private: |
| 73 | friend class Manager; |
| 74 | friend class ManagerPrivate; |
| 75 | Service(ServiceData *d): d(d) {}; |
| 76 | QSharedDataPointer<ServiceData> d; |
| 77 | }; |
| 78 | |
| 79 | } // namespace |
| 80 | |
| 81 | Q_DECLARE_METATYPE(OnlineAccounts::Service) |
| 82 | |
| 83 | #endif // ONLINE_ACCOUNTS_SERVICE_H |