summaryrefslogtreecommitdiff
path: root/wizard/userpwd.cpp
blob: 67ab84d578aa88b62179ae47699701f1c7759d06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <QtGui>
#include "userpwd.h"
#include "../listdelegate.h"
#include "../listitem.h"

wpUserPwd::wpUserPwd(QWidget *parent) : QWizardPage(parent)
{
  setupUi(this);
  connect(password, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
  connect(retypePassword, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
  backend = Backend::instance();
  updateStatus();
}

void wpUserPwd::initializePage()
{
}

void wpUserPwd::updateStatus()
{
  QString pw1 = password->text();
  QString pw2 = retypePassword->text();
  
  passwordStatus->setPixmap(QPixmap());
  retypePasswordStatus->setPixmap(QPixmap());
  
  complete = true;
  
  if(!pw1.length())
  {
    passwordStatus->setToolTip(tr("Please enter a password!"));
    passwordStatus->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24,24));
    complete = false;
  }
  else if(pw1.length() < 6)
  {
    passwordStatus->setToolTip(tr("Password must have at least 6 characters!"));
    passwordStatus->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24,24));
    complete = false;
  }
  else
  {
    passwordStatus->setToolTip(tr("Password OK"));
    passwordStatus->setPixmap(QIcon::fromTheme("dialog-ok").pixmap(24,24));
    
    if(pw1 != pw2)
    {
      retypePasswordStatus->setToolTip(tr("Passwords don't match!"));
      retypePasswordStatus->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24,24));
      complete = false;
    }
    else
    {
      retypePasswordStatus->setToolTip(tr("Password OK"));
      retypePasswordStatus->setPixmap(QIcon::fromTheme("dialog-ok").pixmap(24,24));
    }
  }
  emit completeChanged();
}

bool wpUserPwd::isComplete() const
{
  return complete;
}

bool wpUserPwd::validatePage()
{
  if(!complete) return false;
  backend->cfg("userpwd", backend->encryptPassword(password->text()));
  backend->cfg("autologin", (autologin->isChecked() ? "on" : "off"));
  return true;
}