~tatokis/unity/gcc-72-errors

« back to all changes in this revision

Viewing changes to lockscreen/UserPromptView.cpp

  • Committer: Bileto Bot
  • Author(s): Andrea Azzarone
  • Date: 2017-09-25 16:03:52 UTC
  • mfrom: (4253.3.3 fix-missing-entry-lockscreen)
  • Revision ID: ci-train-bot@canonical.com-20170925160352-kqd3v7i3wdwhixjn
Refactor the way UserAuthenticator is created and passed around. Handle failures to create new threads and fallback to a "Switch to greeter..." button in case of failure. (LP: #1311316)

Approved by: Marco Trevisan (Treviño)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <glib/gi18n-lib.h>
24
24
 
25
25
#include <boost/algorithm/string/trim.hpp>
 
26
#include <NuxCore/Logger.h>
26
27
#include <Nux/VLayout.h>
27
28
 
28
29
#include "LockScreenSettings.h"
38
39
{
39
40
namespace
40
41
{
 
42
 
 
43
DECLARE_LOGGER(logger, "unity.lockscreen");
 
44
 
41
45
const RawPixel PADDING              = 10_em;
42
46
const RawPixel LAYOUT_MARGIN        = 10_em;
43
47
const RawPixel MSG_LAYOUT_MARGIN    = 15_em;
101
105
 
102
106
}
103
107
 
104
 
UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)
105
 
  : AbstractUserPromptView(session_manager)
106
 
  , session_manager_(session_manager)
 
108
UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager,
 
109
                               UserAuthenticator::Ptr const& user_authenticator)
 
110
  : AbstractUserPromptView(session_manager, user_authenticator)
107
111
  , username_(nullptr)
108
112
  , msg_layout_(nullptr)
109
113
  , prompt_layout_(nullptr)
110
114
  , button_layout_(nullptr)
111
115
  , prompted_(false)
112
116
  , unacknowledged_messages_(false)
 
117
  , num_retry_auth_(0)
113
118
{
114
 
  user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
 
119
  user_authenticator_->start_failed.connect(sigc::track_obj([this](){
 
120
    HandleAuthenticationStartFailure();
 
121
  }, *this));
 
122
 
 
123
  user_authenticator_->echo_on_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){
115
124
    prompted_ = true;
116
125
    unacknowledged_messages_ = false;
117
126
    AddPrompt(message, /* visible */ true, promise);
118
 
  });
 
127
  }, *this));
119
128
 
120
 
  user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
 
129
  user_authenticator_->echo_off_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){
121
130
    prompted_ = true;
122
131
    unacknowledged_messages_ = false;
123
132
    AddPrompt(message, /* visible */ false, promise);
124
 
  });
 
133
  }, *this));
125
134
 
126
 
  user_authenticator_.message_requested.connect([this](std::string const& message){
 
135
  user_authenticator_->message_requested.connect(sigc::track_obj([this](std::string const& message){
127
136
    unacknowledged_messages_ = true;
128
137
    AddMessage(message, nux::color::White);
129
 
  });
 
138
  }, *this));
130
139
 
131
 
  user_authenticator_.error_requested.connect([this](std::string const& message){
 
140
  user_authenticator_->error_requested.connect(sigc::track_obj([this](std::string const& message){
132
141
    unacknowledged_messages_ = true;
133
142
    AddMessage(message, nux::color::Red);
134
 
  });
 
143
  }, *this));
135
144
 
136
 
  user_authenticator_.clear_prompts.connect([this](){
 
145
  user_authenticator_->clear_prompts.connect(sigc::track_obj([this](){
137
146
    ResetLayout();
138
 
  });
 
147
  }, *this));
139
148
 
140
149
  scale.changed.connect(sigc::hide(sigc::mem_fun(this, &UserPromptView::UpdateSize)));
141
150
 
469
478
  prompted_ = false;
470
479
  unacknowledged_messages_ = false;
471
480
 
472
 
  user_authenticator_.AuthenticateStart(session_manager_->UserName(),
473
 
                                        sigc::mem_fun(this, &UserPromptView::AuthenticationCb));
 
481
  if(!user_authenticator_->AuthenticateStart(session_manager_->UserName(),
 
482
                                             sigc::mem_fun(this, &UserPromptView::AuthenticationCb)))
 
483
  {
 
484
    HandleAuthenticationStartFailure();
 
485
  }
474
486
}
475
487
 
476
488
void UserPromptView::DoUnlock()
478
490
  session_manager_->unlock_requested.emit();
479
491
}
480
492
 
 
493
void UserPromptView::HandleAuthenticationStartFailure()
 
494
{
 
495
  ++num_retry_auth_;
 
496
 
 
497
  if (num_retry_auth_ <= 5)
 
498
  {
 
499
    LOG_WARNING(logger) << "Failed to start the authentication process. Retrying for " << num_retry_auth_ << " time.";
 
500
    source_manager_.AddTimeout(100, [this] {
 
501
      StartAuthentication();
 
502
      return false;
 
503
    });
 
504
  }
 
505
  else
 
506
  {
 
507
    num_retry_auth_ = 0;
 
508
 
 
509
    AddMessage(_("Authentication failure"), nux::color::Red);
 
510
    AddButton(_("Switch to greeter…"), [this] {
 
511
      session_manager_->SwitchToGreeter();
 
512
    });
 
513
    GetLayout()->AddLayout(button_layout_);
 
514
  }
 
515
}
 
516
 
481
517
}
482
518
}