@@ -21,10 +21,10 @@ AuthFlow::AuthFlow(AuthRequest* request, QList<Identity*>&& identities, QObject*
2121 : QObject(parent)
2222 , mRequest (request)
2323 , mIdentities (std::move(identities))
24- , mSelectedIdentity (this ->mIdentities .isEmpty() ? nullptr : this ->mIdentities .first()) {
24+ , bSelectedIdentity (this ->mIdentities .isEmpty() ? nullptr : this ->mIdentities .first()) {
2525 // We reject auth requests with no identities before a flow is created.
2626 // This should never happen.
27- if (!this ->mSelectedIdentity )
27+ if (!this ->bSelectedIdentity . value () )
2828 qCFatal (logPolkitState) << " AuthFlow created with no valid identities!" ;
2929
3030 for (auto * identity: this ->mIdentities ) {
@@ -42,38 +42,35 @@ const QString& AuthFlow::actionId() const { return this->mRequest->actionId; }
4242const QString& AuthFlow::cookie () const { return this ->mRequest ->cookie ; }
4343const QList<Identity*>& AuthFlow::identities () const { return this ->mIdentities ; }
4444
45- Identity* AuthFlow::selectedIdentity () const { return this ->mSelectedIdentity ; }
45+ QBindable< Identity*> AuthFlow::selectedIdentity () { return & this ->bSelectedIdentity ; }
4646
4747void AuthFlow::setSelectedIdentity (Identity* identity) {
48- if (this ->mSelectedIdentity == identity) return ;
48+ if (this ->bSelectedIdentity . value () == identity) return ;
4949 if (!identity) {
5050 qmlWarning (this ) << " Cannot set selected identity to null." ;
5151 return ;
5252 }
53- for (auto * id: this ->mIdentities ) {
54- if (id == identity) {
55- this ->mSelectedIdentity = id;
56- emit this ->selectedIdentityChanged ();
57- return ;
58- }
59- }
53+ this ->bSelectedIdentity = identity;
54+ this ->currentSession ->cancel ();
55+ this ->setupSession ();
6056}
6157
62- bool AuthFlow::isResponseRequired () const { return this ->mIsResponseRequired ; }
63- const QString& AuthFlow::inputPrompt () const { return this ->mResponseMessage ; }
64- bool AuthFlow::responseVisible () const { return this ->mResponseVisible ; }
65- const QString& AuthFlow::supplementaryMessage () const { return this ->mExtraMessage ; }
66- bool AuthFlow::supplementaryIsError () const { return this ->mExtraIsError ; }
67- bool AuthFlow::isCompleted () const { return this ->mIsCompleted ; }
68- bool AuthFlow::isSuccessful () const { return this ->mIsSuccessful ; }
58+ QBindable<bool > AuthFlow::isResponseRequired () { return &this ->bIsResponseRequired ; }
59+ QBindable<QString> AuthFlow::inputPrompt () { return &this ->bInputPrompt ; }
60+ QBindable<bool > AuthFlow::responseVisible () { return &this ->bResponseVisible ; }
61+ QBindable<QString> AuthFlow::supplementaryMessage () { return &this ->bSupplementaryMessage ; }
62+ QBindable<bool > AuthFlow::supplementaryIsError () { return &this ->bSupplementaryIsError ; }
63+ QBindable<bool > AuthFlow::isCompleted () { return &this ->bIsCompleted ; }
64+ QBindable<bool > AuthFlow::isSuccessful () { return &this ->bIsSuccessful ; }
65+ QBindable<bool > AuthFlow::isCancelled () { return &this ->bIsCancelled ; }
6966AuthRequest* AuthFlow::authRequest () const { return this ->mRequest ; }
7067
7168void AuthFlow::cancelFromAgent () {
7269 if (!this ->currentSession ) return ;
7370
7471 qCDebug (logPolkitState) << " cancelling authentication request from agent" ;
7572
76- this ->mIsCancelled = true ;
73+ this ->bIsCancelled = true ;
7774 this ->currentSession ->cancel ();
7875
7976 emit this ->authenticationRequestCancelled ();
@@ -88,18 +85,17 @@ void AuthFlow::submit(const QString& value) {
8885
8986 this ->currentSession ->respond (value);
9087
91- this ->mIsResponseRequired = false ;
92- this ->mResponseMessage .clear ();
93- this ->mResponseVisible = false ;
94- emit this ->responseRequestChanged ();
88+ this ->bIsResponseRequired = false ;
89+ this ->bInputPrompt = QString {};
90+ this ->bResponseVisible = false ;
9591}
9692
9793void AuthFlow::cancelAuthenticationRequest () {
9894 if (!this ->currentSession ) return ;
9995
10096 qCDebug (logPolkitState) << " cancelling authentication request by user request" ;
10197
102- this ->mIsCancelled = true ;
98+ this ->bIsCancelled = true ;
10399 this ->currentSession ->cancel ();
104100
105101 this ->mRequest ->cancel (" Authentication request cancelled by user." );
@@ -108,10 +104,14 @@ void AuthFlow::cancelAuthenticationRequest() {
108104void AuthFlow::setupSession () {
109105 delete this ->currentSession ;
110106
111- qCDebug (logPolkitState) << " setting up session for identity" << this ->mSelectedIdentity ->name ();
107+ qCDebug (logPolkitState) << " setting up session for identity"
108+ << this ->bSelectedIdentity .value ()->name ();
112109
113- this ->currentSession =
114- new Session (this ->mSelectedIdentity ->polkitIdentity .get (), this ->mRequest ->cookie , this );
110+ this ->currentSession = new Session (
111+ this ->bSelectedIdentity .value ()->polkitIdentity .get (),
112+ this ->mRequest ->cookie ,
113+ this
114+ );
115115 QObject::connect (this ->currentSession , &Session::request, this , &AuthFlow::request);
116116 QObject::connect (this ->currentSession , &Session::completed, this , &AuthFlow::completed);
117117 QObject::connect (this ->currentSession , &Session::showError, this , &AuthFlow::showError);
@@ -120,39 +120,32 @@ void AuthFlow::setupSession() {
120120}
121121
122122void AuthFlow::clearState () {
123- this ->mIsResponseRequired = false ;
124- this ->mResponseMessage .clear ();
125- this ->mResponseVisible = false ;
126- this ->mExtraMessage .clear ();
127- this ->mExtraIsError = false ;
128-
129- emit this ->responseRequestChanged ();
130- emit this ->supplementaryChanged ();
123+ this ->bIsResponseRequired = false ;
124+ this ->bInputPrompt = QString {};
125+ this ->bResponseVisible = false ;
126+ this ->bSupplementaryMessage = QString {};
127+ this ->bSupplementaryIsError = false ;
131128}
132129
133130void AuthFlow::request (const QString& message, bool echo) {
134- this ->mIsResponseRequired = true ;
135- this ->mResponseMessage = message;
136- this ->mResponseVisible = echo;
137- emit this ->responseRequestChanged ();
131+ this ->bIsResponseRequired = true ;
132+ this ->bInputPrompt = message;
133+ this ->bResponseVisible = echo;
138134}
139135
140136void AuthFlow::completed (bool gainedAuthorization) {
141137 qCDebug (logPolkitState) << " authentication session completed, gainedAuthorization ="
142- << gainedAuthorization << " , isCancelled =" << this ->mIsCancelled ;
138+ << gainedAuthorization << " , isCancelled =" << this ->bIsCancelled . value () ;
143139
144140 if (gainedAuthorization) {
145- this ->mIsCompleted = true ;
146- this ->mIsSuccessful = true ;
141+ this ->bIsCompleted = true ;
142+ this ->bIsSuccessful = true ;
147143 this ->mRequest ->complete ();
148144
149- emit this ->completedChanged ();
150145 emit this ->authenticationSucceeded ();
151- } else if (this ->mIsCancelled ) {
152- this ->mIsCompleted = true ;
153- this ->mIsSuccessful = false ;
154-
155- emit this ->completedChanged ();
146+ } else if (this ->bIsCancelled .value ()) {
147+ this ->bIsCompleted = true ;
148+ this ->bIsSuccessful = false ;
156149 } else {
157150 emit this ->authenticationFailed ();
158151
@@ -162,14 +155,12 @@ void AuthFlow::completed(bool gainedAuthorization) {
162155}
163156
164157void AuthFlow::showError (const QString& message) {
165- this ->mExtraMessage = message;
166- this ->mExtraIsError = true ;
167- emit this ->supplementaryChanged ();
158+ this ->bSupplementaryMessage = message;
159+ this ->bSupplementaryIsError = true ;
168160}
169161
170162void AuthFlow::showInfo (const QString& message) {
171- this ->mExtraMessage = message;
172- this ->mExtraIsError = false ;
173- emit this ->supplementaryChanged ();
163+ this ->bSupplementaryMessage = message;
164+ this ->bSupplementaryIsError = false ;
174165}
175166} // namespace qs::service::polkit
0 commit comments