~paulliu/unity8/lp1378469_MessageMenu

« back to all changes in this revision

Viewing changes to tests/mocks/LightDM/full/GreeterPrivate.cpp

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Michael Terry <michael.terry@canonical.com>
 
17
 */
 
18
 
 
19
#include "../Greeter.h"
 
20
#include "../GreeterPrivate.h"
 
21
 
 
22
namespace QLightDM
 
23
{
 
24
 
 
25
GreeterPrivate::GreeterPrivate(Greeter* parent)
 
26
  : authenticated(false),
 
27
    authenticationUser(),
 
28
    twoFactorDone(false),
 
29
    q_ptr(parent)
 
30
{
 
31
}
 
32
 
 
33
void GreeterPrivate::handleAuthenticate()
 
34
{
 
35
    Q_Q(Greeter);
 
36
 
 
37
    // Send out any messages we need to
 
38
    if (authenticationUser == "info-prompt")
 
39
        Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
 
40
    else if (authenticationUser == "wide-info-prompt")
 
41
        Q_EMIT q->showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
 
42
    else if (authenticationUser == "html-info-prompt")
 
43
        Q_EMIT q->showMessage("<b>&</b>", Greeter::MessageTypeInfo);
 
44
    else if (authenticationUser == "long-info-prompt")
 
45
        Q_EMIT q->showMessage("Welcome to Unity Greeter\n\nWe like to annoy you with super ridiculously long messages.\nLike this one\n\nThis is the last line of a multiple line message.", Greeter::MessageTypeInfo);
 
46
    else if (authenticationUser == "multi-info-prompt") {
 
47
        Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
 
48
        Q_EMIT q->showMessage("This is an error", Greeter::MessageTypeError);
 
49
        Q_EMIT q->showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
 
50
    }
 
51
 
 
52
    // OK, now actually do the prompt
 
53
    if (authenticationUser == "no-password") {
 
54
        authenticated = true;
 
55
        Q_EMIT q->authenticationComplete();
 
56
    } else if (authenticationUser == "auth-error") {
 
57
        authenticated = false;
 
58
        Q_EMIT q->authenticationComplete();
 
59
    } else if (authenticationUser == "different-prompt") {
 
60
        Q_EMIT q->showPrompt("Secret word: ", Greeter::PromptTypeSecret);
 
61
    } else {
 
62
        Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
 
63
    }
 
64
}
 
65
 
 
66
void GreeterPrivate::handleRespond(const QString &response)
 
67
{
 
68
    Q_Q(Greeter);
 
69
 
 
70
    if (authenticationUser == "no-response")
 
71
        return;
 
72
    else if (authenticationUser == "two-factor") {
 
73
        if (!twoFactorDone) {
 
74
            if (response == "password") {
 
75
                twoFactorDone = true;
 
76
                Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
 
77
            } else {
 
78
                authenticated = false;
 
79
                Q_EMIT q->authenticationComplete();
 
80
            }
 
81
        } else {
 
82
            authenticated = (response == "otp");
 
83
            Q_EMIT q->authenticationComplete();
 
84
        }
 
85
        return;
 
86
    }
 
87
 
 
88
    authenticated = (response == "password");
 
89
    Q_EMIT q->authenticationComplete();
 
90
}
 
91
 
 
92
}