File indexing completed on 2024-05-19 15:57:54

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  *
0006  */
0007 
0008 #ifndef KACCOUNTSUIPLUGIN_H
0009 #define KACCOUNTSUIPLUGIN_H
0010 
0011 #include "kaccounts_export.h"
0012 
0013 #include <QObject>
0014 
0015 class QWindow;
0016 
0017 namespace KAccounts
0018 {
0019 
0020 class KACCOUNTS_EXPORT KAccountsUiPlugin : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     enum UiType {
0026         NewAccountDialog,
0027         ConfigureAccountDialog,
0028     };
0029 
0030     explicit KAccountsUiPlugin(QObject *parent = nullptr);
0031     ~KAccountsUiPlugin() override;
0032 
0033     virtual void init(UiType type) = 0;
0034 
0035     /**
0036      * Sets the selected Accounts-SSO provider to the plugin
0037      */
0038     virtual void setProviderName(const QString &providerName) = 0;
0039 
0040     /**
0041      * Called when the dialog for creating new account should show
0042      */
0043     virtual void showNewAccountDialog() = 0;
0044 
0045     /**
0046      * Called when an existing account should be configured
0047      * @param accountId The ID of the account that should be configured
0048      */
0049     virtual void showConfigureAccountDialog(const quint32 accountId) = 0;
0050 
0051     /**
0052      * Returns a list of services which this plugin supports
0053      * configuration of, for example "IM" supports config
0054      * of IM/KTp accounts
0055      */
0056     virtual QStringList supportedServicesForConfig() const = 0;
0057 
0058     QWindow *transientParent() const;
0059 
0060 Q_SIGNALS:
0061     /**
0062      * Sometimes the plugins might take time to initialize the UI
0063      * completely, whenever they are ready, this signal should be
0064      * emitted to tell kaccounts that the plugin is ready to display
0065      * the dialog
0066      */
0067     void uiReady();
0068 
0069     /**
0070      * This should be emitted when the plugin finishes building the UI
0071      * for configuring the selected account
0072      */
0073     void configUiReady();
0074 
0075     /**
0076      * Emitted when user successfully authenticated using this plugin
0077      * The params are the username & password that the user used to
0078      * authenticate themselves and any additional data that might be needed
0079      */
0080     void success(const QString &username, const QString &password, const QVariantMap &additionalData);
0081 
0082     /**
0083      * Emit this to start an auth session. Any values in data are passed to the started session.
0084      * This is useful e.g. when doing oauth login but you need to show a UI to get some data before.
0085      */
0086     void startAuthSession(const QVariantMap &data);
0087 
0088     /**
0089      * Emitted when there has been an error during the authentication
0090      *
0091      * @param errorString The error that has occurred
0092      */
0093     void error(const QString &errorString);
0094 
0095     /**
0096      * Emitted when the user cancels the account creation
0097      */
0098     void canceled();
0099 };
0100 
0101 };
0102 
0103 Q_DECLARE_INTERFACE(KAccounts::KAccountsUiPlugin, "org.kde.kaccounts.UiPlugin")
0104 
0105 #endif // KACCOUNTSUIPLUGIN_H