File indexing completed on 2024-05-05 04:39:54

0001 /*
0002     SPDX-FileCopyrightText: 2012-2013 Miquel Sabaté <mikisabate@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef GH_ACCOUNT_H
0008 #define GH_ACCOUNT_H
0009 
0010 
0011 #include <KConfigGroup>
0012 
0013 
0014 namespace gh
0015 {
0016 class Resource;
0017 
0018 /**
0019  * @class Account
0020  *
0021  * This class holds the configuration of the Github account.
0022  */
0023 class Account
0024 {
0025 public:
0026     /**
0027      * Constructor.
0028      *
0029      * @param resource The Github resource.
0030      */
0031     explicit Account(Resource *resource);
0032 
0033     /**
0034      * Invalidate the current account.
0035      *
0036      * @param password The password for the current user. The Github API
0037      * requires it when revoking an access token.
0038      */
0039     void invalidate(const QString &password);
0040 
0041     /// @returns true if the current account is still valid.
0042     bool validAccount() const;
0043 
0044     /// @returns the Github resource.
0045     inline Resource *resource() const
0046     {
0047         return m_resource;
0048     }
0049 
0050     /// Set the user's name to @p name.
0051     void setName(const QString &name);
0052 
0053     /// @returns the user's name.
0054     const QString name() const;
0055 
0056     /// Set the public and private orgs for the current user.
0057     void setOrgs(const QStringList &orgs);
0058 
0059     /// @returns the public and private orgs for the current user.
0060     const QStringList orgs() const;
0061 
0062     /**
0063      * Saves the authorization token.
0064      *
0065      * @param id The id of the authorization.
0066      * @param token The authorization token itself.
0067      */
0068     void saveToken(const QByteArray &id, const QByteArray &token);
0069 
0070     /// @returns the authorization token.
0071     const QString token() const;
0072 
0073 private:
0074     Resource *m_resource;
0075     KConfigGroup m_group;
0076 };
0077 
0078 } // End of namespace gh
0079 
0080 
0081 #endif /* GH_ACCOUNT_H */