summaryrefslogblamecommitdiff
path: root/src/pincodemanager.cpp
blob: 4ee8abd3a0e299f0d100638417df64705458080b (plain) (tree)





















                                                                         











                                              




                                  
                  
              


                              










                                 
                                

 
                                                                          
 

                                 

 
                                  
 



















                                                            

 
                                                              
 







































                                                                

 
                            





                               
/*
 *  The ManaPlus Client
 *  Copyright (C) 2018  The ManaPlus Developers
 *
 *  This file is part of The ManaPlus Client.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "pincodemanager.h"

#include "gui/windows/okdialog.h"
#include "gui/windows/pincodedialog.h"

#include "gui/widgets/createwidget.h"

#include "listeners/newpincodelistener.h"
#include "listeners/newpincoderetrylistener.h"

#include "net/charserverhandler.h"

#include "utils/gettext.h"

#include "debug.h"

PincodeManager pincodeManager;

PincodeManager::PincodeManager() :
    mNewPincode(),
    mSeed(0U),
    mAccountId(BeingId_zero),
    mDialog(nullptr),
    mState(PincodeState::None)
{
}

PincodeManager::~PincodeManager()
{
}

void PincodeManager::init()
{
    mSeed = 0;
    mAccountId = BeingId_zero;
    mState = PincodeState::None;
}

void PincodeManager::clearDialog(const PincodeDialog *const PincodeDialog)
{
    if (mDialog == PincodeDialog)
        mDialog = nullptr;
}

void PincodeManager::updateState()
{
    switch (mState)
    {
        case PincodeState::None:
        case PincodeState::Ask:
        case PincodeState::Change:
        default:
            break;
        case PincodeState::Create:
            CREATEWIDGETV(mDialog, PincodeDialog,
                // TRANSLATORS: dialog caption
                _("New pincode"),
                // TRANSLATORS: dialog label
                _("Set new pincode"),
                mSeed,
                nullptr);
            mDialog->requestFocus();
            mDialog->setActionEventId("ok");
            mDialog->addActionListener(&newPincodeListener);
            break;
    }
}

void PincodeManager::setNewPincode(const std::string &pincode)
{
    if (mNewPincode.empty())
    {   // first pincode
        mNewPincode = pincode;
        CREATEWIDGETV(mDialog, PincodeDialog,
            // TRANSLATORS: dialog caption
            _("New pincode"),
            // TRANSLATORS: dialog label
            _("Confirm new pincode"),
            mSeed,
            nullptr);
        mDialog->requestFocus();
        mDialog->setActionEventId("ok");
        mDialog->addActionListener(&newPincodeListener);
    }
    else
    {   // pincode confirmation
        if (mNewPincode != pincode)
        {
            mNewPincode.clear();
            OkDialog *const dialog = CREATEWIDGETR(OkDialog,
                // TRANSLATORS: error header
                _("Pincode"),
                // TRANSLATORS: error message
                _("Wrong pincode confirmation!"),
                // TRANSLATORS: ok dialog button
                _("OK"),
                DialogType::ERROR,
                Modal_true,
                ShowCenter_true,
                nullptr,
                260);
            dialog->addActionListener(&newPincodeRetryListener);
        }
        else
        {
            charServerHandler->setNewPincode(mAccountId,
                mNewPincode);
            mNewPincode.clear();
        }
    }
}

void PincodeManager::pinOk()
{
}

void PincodeManager::wrongPin()
{
}