summaryrefslogtreecommitdiff
path: root/wizard/usercfg.cpp
blob: 0e625d6522d88cc909c3c22b5a1b7812cbf43f4b (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
#include <QtGui>
#include "usercfg.h"
#include "../listdelegate.h"
#include "../listitem.h"

wpUserCfg::wpUserCfg(QWidget *parent) : QWizardPage(parent)
{
  setupUi(this);
  connect(realname, SIGNAL(editingFinished()), this, SLOT(realnameChanged()));
  connect(realname, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
  connect(username, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
  
  QValidator* usernameValidator = new QRegExpValidator(QRegExp("[a-zA-Z0-9-_.]*"), this);
  username->setValidator( usernameValidator );
  
  backend = Backend::instance();
  complete = false;
  updateStatus();
}

void wpUserCfg::initializePage()
{
}

void wpUserCfg::realnameChanged()
{
  if(username->text().length()) return;
  if(realname->text().contains(" "))
    username->setText(backend->cleanUsername(realname->text().section(" ",0,0).toLower()));
  updateStatus();
}

void wpUserCfg::updateStatus()
{
  complete = false;
  if(realname->text().length() && username->text().length()) complete = true;
  emit completeChanged();
}

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

bool wpUserCfg::validatePage()
{
  if(!complete) return false;
  backend->cfg("username", username->text());
  backend->cfg("realname", realname->text());
  return true;
}