File indexing completed on 2024-05-12 05:22:14

0001 /*
0002     SPDX-FileCopyrightText: 2012, 2013 Daniel Vrátil <dvratil@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "account.h"
0008 #include "utils_p.h"
0009 
0010 #include <QDateTime>
0011 
0012 using namespace KGAPI2;
0013 
0014 class Q_DECL_HIDDEN Account::Private
0015 {
0016 public:
0017     Private();
0018     Private(const Private &other);
0019 
0020     QString accName;
0021     QString accessToken;
0022     QString refreshToken;
0023     QDateTime expireDateTime;
0024     QList<QUrl> scopes;
0025 };
0026 
0027 Account::Private::Private()
0028     : expireDateTime(QDateTime())
0029 {
0030 }
0031 
0032 Account::Private::Private(const Private &other)
0033     : accName(other.accName)
0034     , accessToken(other.accessToken)
0035     , refreshToken(other.refreshToken)
0036     , expireDateTime(other.expireDateTime)
0037     , scopes(other.scopes)
0038 {
0039 }
0040 
0041 Account::Account()
0042     : d(new Private)
0043     , m_scopesChanged(false)
0044 {
0045 }
0046 
0047 Account::Account(const QString &accName, const QString &accessToken, const QString &refreshToken, const QList<QUrl> &scopes)
0048     : d(new Private)
0049     , m_scopesChanged(false)
0050 {
0051     d->accName = accName;
0052     d->accessToken = accessToken;
0053     d->refreshToken = refreshToken;
0054     d->scopes = scopes;
0055 }
0056 
0057 Account::Account(const Account &other)
0058     : d(new Private(*(other.d)))
0059     , m_scopesChanged(other.m_scopesChanged)
0060 {
0061 }
0062 
0063 Account::~Account()
0064 {
0065     delete d;
0066 }
0067 
0068 bool Account::operator==(const Account &other) const
0069 {
0070     if (d == other.d) {
0071         return true;
0072     }
0073 
0074     GAPI_COMPARE(accName)
0075     GAPI_COMPARE(accessToken)
0076     GAPI_COMPARE(refreshToken)
0077     GAPI_COMPARE(expireDateTime)
0078     GAPI_COMPARE(scopes)
0079 
0080     return true;
0081 }
0082 
0083 QString Account::accountName() const
0084 {
0085     return d->accName;
0086 }
0087 
0088 void Account::setAccountName(const QString &accountName)
0089 {
0090     d->accName = accountName;
0091 }
0092 
0093 QString Account::accessToken() const
0094 {
0095     return d->accessToken;
0096 }
0097 
0098 void Account::setAccessToken(const QString &accessToken)
0099 {
0100     d->accessToken = accessToken;
0101 }
0102 
0103 QString Account::refreshToken() const
0104 {
0105     return d->refreshToken;
0106 }
0107 
0108 void Account::setRefreshToken(const QString &refreshToken)
0109 {
0110     d->refreshToken = refreshToken;
0111 }
0112 
0113 QList<QUrl> Account::scopes() const
0114 {
0115     return d->scopes;
0116 }
0117 
0118 void Account::setScopes(const QList<QUrl> &scopes)
0119 {
0120     d->scopes = scopes;
0121     m_scopesChanged = true;
0122 }
0123 
0124 void Account::addScope(const QUrl &scope)
0125 {
0126     if (!d->scopes.contains(scope)) {
0127         d->scopes.append(scope);
0128         m_scopesChanged = true;
0129     }
0130 }
0131 
0132 void Account::removeScope(const QUrl &scope)
0133 {
0134     if (d->scopes.contains(scope)) {
0135         d->scopes.removeOne(scope);
0136         m_scopesChanged = true;
0137     }
0138 }
0139 
0140 QDateTime Account::expireDateTime() const
0141 {
0142     return d->expireDateTime;
0143 }
0144 
0145 void Account::setExpireDateTime(const QDateTime &expire)
0146 {
0147     d->expireDateTime = expire;
0148 }
0149 
0150 QUrl Account::accountInfoScopeUrl()
0151 {
0152     return QUrl(QStringLiteral("https://www.googleapis.com/auth/userinfo.profile"));
0153 }
0154 
0155 QUrl Account::accountInfoEmailScopeUrl()
0156 {
0157     return QUrl(QStringLiteral("https://www.googleapis.com/auth/userinfo.email"));
0158 }
0159 
0160 QUrl Account::calendarScopeUrl()
0161 {
0162     return QUrl(QStringLiteral("https://www.googleapis.com/auth/calendar"));
0163 }
0164 
0165 QUrl Account::peopleScopeUrl()
0166 {
0167     return QUrl(QStringLiteral("https://www.googleapis.com/auth/contacts"));
0168 }
0169 
0170 QUrl Account::latitudeScopeUrl()
0171 {
0172     return QUrl(QStringLiteral("https://www.googleapis.com/auth/latitude.all.best"));
0173 }
0174 
0175 QUrl Account::tasksScopeUrl()
0176 {
0177     return QUrl(QStringLiteral("https://www.googleapis.com/auth/tasks"));
0178 }
0179 
0180 QUrl Account::bloggerScopeUrl()
0181 {
0182     return QUrl(QStringLiteral("https://www.googleapis.com/auth/blogger"));
0183 }
0184 
0185 QUrl Account::mailScopeUrl()
0186 {
0187     return QUrl(QStringLiteral("https://mail.google.com/"));
0188 }
0189 
0190 QUrl Account::driveScopeUrl()
0191 {
0192     return QUrl(QStringLiteral("https://www.googleapis.com/auth/drive"));
0193 }