ImagingTools Core SDK
CStandardLoginGuiComp.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QThread>
7
8// ACF includes
9#include <iauth/ILogin.h>
10#include <iauth/IRightsProvider.h>
11#include <iqt/ISettingsProvider.h>
12#include <iqtgui/TDesignerGuiCompBase.h>
13#include <iqtgui/TRestorableGuiWrap.h>
14#include <ilog/IMessageConsumer.h>
15#include <iqtgui/TDesignerGuiObserverCompBase.h>
16#include <imtcom/IConnectionStatusProvider.h>
17
18// ImtCore includes
19#include <imtauth/ISuperuserController.h>
20#include <imtauth/ISuperuserProvider.h>
21#include <imtbase/TModelUpdateBinder.h>
22#include <GeneratedFiles/imtauthgui/ui_CStandardLoginGuiComp.h>
23
24
25namespace imtauthgui
26{
27
28
29class CStandardLoginGuiComp: public iqtgui::TRestorableGuiWrap<
30 iqtgui::TDesignerGuiCompBase<Ui::CStandardLoginGuiComp>>
31{
32 Q_OBJECT
33public:
34
35 enum UiState
36 {
37 US_USER_PASSWORD_LOGIN,
38 US_ENTER_SU_PASSWORD,
39 US_NO_CONNECTION_TO_SERVER,
40 US_WAIT_INDICATOR
41 };
42
43 typedef iqtgui::TRestorableGuiWrap<
44 iqtgui::TDesignerGuiCompBase<Ui::CStandardLoginGuiComp>> BaseClass;
45
46 I_BEGIN_COMPONENT(CStandardLoginGuiComp);
47 I_REGISTER_SUBELEMENT(LoginLog);
48 I_REGISTER_SUBELEMENT_INTERFACE(LoginLog, ilog::IMessageConsumer, ExtractLoginLog);
49 I_ASSIGN(m_loginCompPtr, "Login", "Login", false, "Login");
50 I_ASSIGN(m_superuserProviderCompPtr, "SuperuserProvider", "Superuser provider", false, "SuperuserProvider");
51 I_ASSIGN(m_superuserControllerCompPtr, "SuperuserController", "Superuser controller", false, "SuperuserController");
52 I_ASSIGN(m_connectionStatusProviderCompPtr, "ConnectionStatusProvider", "Connection status provider", false, "ConnectionStatusProvider");
53 I_END_COMPONENT;
54
55 CStandardLoginGuiComp();
56
57protected:
58 virtual bool eventFilter(QObject* watched, QEvent* event) override;
59
60 // reimplemented (icomp::CComponentBase)
61 virtual void OnComponentCreated() override;
62 virtual void OnComponentDestroyed() override;
63
64 // reimplemented (iqtgui::CGuiComponentBase)
65 virtual void OnGuiShown() override;
66 virtual void OnGuiHidden() override;
67 virtual void OnGuiCreated() override;
68 virtual void OnGuiDestroyed() override;
69
70 // reimplemented (iqtgui::TRestorableGuiWrap)
71 virtual void OnRestoreSettings(const QSettings& settings) override;
72 virtual void OnSaveSettings(QSettings& settings) const override;
73
74private Q_SLOTS:
75 void on_LoginButton_clicked();
76 void on_SetPasswordButton_clicked();
77 void on_PasswordEdit_textEdited(const QString& text);
78 void on_SuPasswordEdit_textEdited(const QString& text);
79 void on_SuConfirmPasswordEdit_textEdited(const QString& text);
80 void OnSetSuPasswordFinished();
81
82private:
83 void OnLoginUpdate(const istd::IChangeable::ChangeSet& changeSet, const iauth::ILogin* objectPtr);
84 void OnConnectionStatusChanged(const istd::IChangeable::ChangeSet& changeSet, const imtcom::IConnectionStatusProvider* objectPtr);
85 void UpdateLoginButtonsState();
86 void CheckMatchingPassword();
87 void ShowLoadingPage();
88
89 // Helper methods for refresh token management
90 bool TryRestoreSessionWithRefreshToken(const QString& userName, const QByteArray& refreshToken);
91 void SaveRefreshTokenIfRememberMe(QSettings& settings) const;
92 void ClearRefreshTokenIfNeeded(QSettings& settings) const;
93
94private:
95 class LoginLog: public ilog::IMessageConsumer
96 {
97 public:
98 LoginLog(CStandardLoginGuiComp& parent);
99
100 // reimplemented (ilog::IMessageConsumer)
101 virtual bool IsMessageSupported(int messageCategory = -1, int messageId = -1, const istd::IInformationProvider* messagePtr = NULL) const override;
102 virtual void AddMessage(const MessagePtr& messagePtr) override;
103
104 private:
105 CStandardLoginGuiComp& m_parent;
106 };
107
108 template <typename InterfaceType>
109 static InterfaceType* ExtractLoginLog(CStandardLoginGuiComp& parent)
110 {
111 return &parent.m_loginLog;
112 }
113
114 class SetSuPasswordThread: public QThread
115 {
116 public:
117 enum ThreadState
118 {
119 TS_UNKNOWN = 0,
120 TS_OK,
121 TS_FAILED
122 };
123
124 SetSuPasswordThread(CStandardLoginGuiComp& parent);
125
126 void Start(const QByteArray& suPassword);
127 ThreadState GetState();
128
129 protected:
130 // reimplemented (QThread)
131 virtual void run() override;
132
133 private:
134 CStandardLoginGuiComp& m_parent;
135 QByteArray m_suPassword;
136 ThreadState m_state;
137 };
138
139private:
140 I_REF(imtauth::ISuperuserProvider, m_superuserProviderCompPtr);
141 I_REF(imtauth::ISuperuserController, m_superuserControllerCompPtr);
142 I_REF(iauth::ILogin, m_loginCompPtr);
143 I_REF(imtcom::IConnectionStatusProvider, m_connectionStatusProviderCompPtr);
144
147
148 LoginLog m_loginLog;
149 SetSuPasswordThread m_setSuPasswordThread;
150
151 QMovie* m_loadingMovie = nullptr;
152};
153
154
155} // namespace imtauthgui
156
157
Interface for monitoring network connection status with observable state changes.
Authentication UI Components Module.