Added user managment page and dialog.new_installer
parent
0f5f131a46
commit
618cf3d2ec
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
class QString;
|
||||
|
||||
struct UserInfo
|
||||
{
|
||||
QString name;
|
||||
QString psw;
|
||||
};
|
@ -0,0 +1,238 @@
|
||||
#include "pageusers.h"
|
||||
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <QGroupBox>
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QListWidget>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <QScopedPointer>
|
||||
#include <QTimer>
|
||||
|
||||
#include "userinfodialog.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
PageUsers::PageUsers()
|
||||
: InstallerPage()
|
||||
{
|
||||
setupUi();
|
||||
|
||||
// connect
|
||||
connect( m_butAddUser, SIGNAL(clicked()), this, SLOT(addUser()) );
|
||||
connect( m_butDelUser, SIGNAL(clicked()), this, SLOT(delUser()) );
|
||||
connect( m_lstUsers, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyUser()) );
|
||||
|
||||
connect( m_edRootPsw, SIGNAL(textChanged(QString)), this, SLOT(checkPasswords()) );
|
||||
connect( m_edRootPswRep, SIGNAL(textChanged(QString)), this, SLOT(checkPasswords()) );
|
||||
|
||||
// add default guest user
|
||||
m_lstUsers->addItem("guest");
|
||||
checkPasswords();
|
||||
}
|
||||
|
||||
void PageUsers::setupUi()
|
||||
{
|
||||
m_labRoot = new QLabel;
|
||||
|
||||
QHBoxLayout* hbox_0 = new QHBoxLayout;
|
||||
hbox_0->addWidget(m_labRoot);
|
||||
hbox_0->addStretch();
|
||||
|
||||
m_labRootPsw = new QLabel;
|
||||
m_edRootPsw = new QLineEdit;
|
||||
m_edRootPsw->setEchoMode( QLineEdit::Password );
|
||||
|
||||
m_labRootPswRep = new QLabel;
|
||||
m_edRootPswRep = new QLineEdit;
|
||||
m_edRootPswRep->setEchoMode( QLineEdit::Password );
|
||||
|
||||
QGridLayout* gbox_0 = new QGridLayout;
|
||||
gbox_0->setContentsMargins(0, 0, 0, 0);
|
||||
gbox_0->addWidget(m_labRootPsw, 0, 0);
|
||||
gbox_0->addWidget(m_edRootPsw, 0, 1);
|
||||
gbox_0->addWidget(m_labRootPswRep, 1, 0);
|
||||
gbox_0->addWidget(m_edRootPswRep, 1, 1);
|
||||
|
||||
m_labMatch = new QLabel;
|
||||
QHBoxLayout* hbox_1 = new QHBoxLayout;
|
||||
hbox_1->addStretch();
|
||||
hbox_1->addWidget(m_labMatch);
|
||||
|
||||
m_labUsers = new QLabel;
|
||||
|
||||
QHBoxLayout* hbox_users = new QHBoxLayout;
|
||||
hbox_users->addWidget(m_labUsers);
|
||||
hbox_users->addStretch();
|
||||
|
||||
m_butAddUser = new QToolButton;
|
||||
m_butAddUser->setIcon( QIcon::fromTheme("list-add-user") );
|
||||
|
||||
m_butDelUser = new QToolButton;
|
||||
m_butDelUser->setIcon( QIcon::fromTheme("list-remove") );
|
||||
|
||||
QHBoxLayout* hbox_but = new QHBoxLayout;
|
||||
hbox_but->addWidget( m_butAddUser );
|
||||
hbox_but->addWidget( m_butDelUser );
|
||||
hbox_but->addStretch();
|
||||
|
||||
m_lstUsers = new QListWidget;
|
||||
|
||||
QVBoxLayout* vbox_0 = new QVBoxLayout;
|
||||
vbox_0->addLayout(hbox_0);
|
||||
vbox_0->addLayout(gbox_0);
|
||||
vbox_0->addLayout(hbox_1);
|
||||
vbox_0->addLayout(hbox_users);
|
||||
vbox_0->addLayout(hbox_but);
|
||||
vbox_0->addWidget(m_lstUsers);
|
||||
//vbox_0->addStretch();
|
||||
|
||||
setLayout(vbox_0);
|
||||
|
||||
retranslateUi();
|
||||
|
||||
}
|
||||
|
||||
void PageUsers::retranslateUi()
|
||||
{
|
||||
setTitle( tr("Users") );
|
||||
|
||||
m_labRoot->setText( tr("Root password:") );
|
||||
m_labRootPsw->setText( tr("Password") );
|
||||
m_labRootPswRep->setText( tr("Confirm Password") );
|
||||
|
||||
m_labUsers->setText( tr("Create users:") );
|
||||
}
|
||||
|
||||
void PageUsers::show()
|
||||
{
|
||||
emit changeNext( m_pswState );
|
||||
}
|
||||
|
||||
void PageUsers::addUser()
|
||||
{
|
||||
qDebug() << "add user";
|
||||
|
||||
QScopedPointer<UserInfoDialog> userDlg( new UserInfoDialog(this) );
|
||||
|
||||
if ( userDlg->exec() == QDialog::Accepted )
|
||||
{
|
||||
if (m_lstUserInfo.isEmpty())
|
||||
{
|
||||
// delete guest from list
|
||||
m_lstUsers->clear();
|
||||
}
|
||||
|
||||
UserInfo userInfo = userDlg->getUserInfo();
|
||||
|
||||
if ( findUserName(userInfo) == -1 )
|
||||
{
|
||||
m_lstUserInfo << userInfo;
|
||||
m_lstUsers->addItem( userInfo.name );
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical( this, tr("Error"), tr("User %1 already exists.").arg(userInfo.name) );
|
||||
QTimer::singleShot(0, this, SLOT(addUser()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PageUsers::delUser()
|
||||
{
|
||||
qDebug() << "del user";
|
||||
|
||||
if (m_lstUserInfo.isEmpty())
|
||||
{
|
||||
QMessageBox::critical( this, tr("Error"), tr("User guest can't be deleted.") );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = m_lstUsers->currentRow();
|
||||
if (index != -1)
|
||||
{
|
||||
delete m_lstUsers->takeItem(index);
|
||||
m_lstUserInfo.removeAt(index);
|
||||
|
||||
if (m_lstUserInfo.isEmpty())
|
||||
{
|
||||
m_lstUsers->addItem("guest");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PageUsers::modifyUser()
|
||||
{
|
||||
qDebug() << "modify user";
|
||||
if (m_lstUserInfo.isEmpty())
|
||||
{
|
||||
QMessageBox::critical( this, tr("Error"), tr("User guest can't be modified.") );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = m_lstUsers->currentRow();
|
||||
if (index != -1)
|
||||
{
|
||||
QScopedPointer<UserInfoDialog> userDlg( new UserInfoDialog(this, m_lstUserInfo.at(index)) );
|
||||
|
||||
if ( userDlg->exec() == QDialog::Accepted )
|
||||
{
|
||||
UserInfo userInfo = userDlg->getUserInfo();
|
||||
|
||||
int index_0 = findUserName(userInfo);
|
||||
if ( (index_0 == -1) || (index_0 == index) )
|
||||
{
|
||||
delete m_lstUsers->takeItem(index);
|
||||
m_lstUsers->insertItem(index, userInfo.name);
|
||||
m_lstUserInfo.replace(index, userInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical( this, tr("Error"), tr("User %1 already exists.").arg(userInfo.name) );
|
||||
QTimer::singleShot(0, this, SLOT(modifyUser()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PageUsers::checkPasswords()
|
||||
{
|
||||
qDebug() << "check passwords";
|
||||
|
||||
m_pswState = false;
|
||||
|
||||
if ( (!m_edRootPsw->text().isEmpty()) && (m_edRootPsw->text() == m_edRootPswRep->text()) )
|
||||
m_pswState = true;
|
||||
|
||||
QString pswState;
|
||||
if (m_pswState )
|
||||
{
|
||||
pswState = tr("Passwords match");
|
||||
}
|
||||
else
|
||||
{
|
||||
pswState = tr("Passwords do not match");
|
||||
}
|
||||
m_labMatch->setText( pswState );
|
||||
|
||||
emit changeNext( m_pswState );
|
||||
}
|
||||
|
||||
int PageUsers::findUserName( const UserInfo& userInfo )
|
||||
{
|
||||
int i = 0;
|
||||
foreach(const UserInfo& info, m_lstUserInfo)
|
||||
{
|
||||
if (info.name.compare(userInfo.name, Qt::CaseInsensitive) == 0)
|
||||
return i;
|
||||
++i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "installerpage.h"
|
||||
|
||||
#include "commons.h"
|
||||
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QToolButton;
|
||||
class QListWidget;
|
||||
|
||||
class PageUsers : public InstallerPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PageUsers();
|
||||
|
||||
void retranslateUi();
|
||||
|
||||
protected:
|
||||
void setupUi();
|
||||
|
||||
public slots:
|
||||
void show();
|
||||
|
||||
private slots:
|
||||
void addUser();
|
||||
void delUser();
|
||||
void modifyUser();
|
||||
void checkPasswords();
|
||||
|
||||
private:
|
||||
int findUserName(const UserInfo& userInfo);
|
||||
|
||||
private:
|
||||
QLabel* m_labRoot;
|
||||
QLabel* m_labRootPsw;
|
||||
QLineEdit* m_edRootPsw;
|
||||
QLabel* m_labRootPswRep;
|
||||
QLineEdit* m_edRootPswRep;
|
||||
QLabel* m_labMatch;
|
||||
|
||||
QLabel* m_labUsers;
|
||||
|
||||
QToolButton* m_butAddUser;
|
||||
QToolButton* m_butDelUser;
|
||||
|
||||
QListWidget* m_lstUsers;
|
||||
|
||||
bool m_pswState;
|
||||
QList<UserInfo> m_lstUserInfo;
|
||||
};
|
@ -0,0 +1,123 @@
|
||||
#include "userinfodialog.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QLayout>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
UserInfoDialog::UserInfoDialog ( QWidget* parent, const UserInfo& userInfo)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setupUi();
|
||||
|
||||
if (userInfo.name.isEmpty())
|
||||
{
|
||||
setWindowTitle( tr("Add user") );
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindowTitle( tr("Modify user") );
|
||||
|
||||
m_edUserName->setText(userInfo.name);
|
||||
m_edPsw->setText(userInfo.psw);
|
||||
m_edPswRep->setText(userInfo.psw);
|
||||
}
|
||||
|
||||
connect( m_edPsw, SIGNAL(textChanged(QString)), this, SLOT(checkPasswords()) );
|
||||
connect( m_edPswRep, SIGNAL(textChanged(QString)), this, SLOT(checkPasswords()) );
|
||||
|
||||
connect( m_butOk, SIGNAL(clicked(bool)), this, SLOT(preAccept()) );
|
||||
connect( m_butCancel, SIGNAL(clicked(bool)), this, SLOT(reject()) );
|
||||
|
||||
checkPasswords();
|
||||
}
|
||||
|
||||
UserInfoDialog::~UserInfoDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void UserInfoDialog::setupUi()
|
||||
{
|
||||
m_labUserName = new QLabel( tr("User name:") );
|
||||
m_edUserName = new QLineEdit;
|
||||
|
||||
QHBoxLayout* hbox_0 = new QHBoxLayout;
|
||||
hbox_0->addWidget(m_labUserName);
|
||||
hbox_0->addWidget(m_edUserName);
|
||||
|
||||
m_labPsw = new QLabel( tr("Password") );
|
||||
m_edPsw = new QLineEdit;
|
||||
m_edPsw->setEchoMode( QLineEdit::Password );
|
||||
|
||||
m_labPswRep = new QLabel( tr("Confirm Password") );
|
||||
m_edPswRep = new QLineEdit;
|
||||
m_edPswRep->setEchoMode( QLineEdit::Password );
|
||||
|
||||
QGridLayout* gbox_0 = new QGridLayout;
|
||||
gbox_0->setContentsMargins(0, 0, 0, 0);
|
||||
gbox_0->addWidget(m_labPsw, 0, 0);
|
||||
gbox_0->addWidget(m_edPsw, 0, 1);
|
||||
gbox_0->addWidget(m_labPswRep, 1, 0);
|
||||
gbox_0->addWidget(m_edPswRep, 1, 1);
|
||||
|
||||
m_labMatch = new QLabel;
|
||||
QHBoxLayout* hbox_1 = new QHBoxLayout;
|
||||
hbox_1->addStretch();
|
||||
hbox_1->addWidget(m_labMatch);
|
||||
|
||||
m_butOk = new QPushButton( tr("OK") );
|
||||
m_butCancel = new QPushButton( tr("Cancel") );
|
||||
|
||||
QHBoxLayout* hbox_but = new QHBoxLayout;
|
||||
hbox_but->addStretch();
|
||||
hbox_but->addWidget(m_butOk);
|
||||
hbox_but->addWidget(m_butCancel);
|
||||
|
||||
QVBoxLayout* vbox_0 = new QVBoxLayout;
|
||||
vbox_0->addLayout(hbox_0);
|
||||
vbox_0->addLayout(gbox_0);
|
||||
vbox_0->addLayout(hbox_1);
|
||||
vbox_0->addLayout(hbox_but);
|
||||
|
||||
setLayout(vbox_0);
|
||||
}
|
||||
|
||||
void UserInfoDialog::checkPasswords()
|
||||
{
|
||||
bool pswMatch = false;
|
||||
|
||||
if ( (!m_edPsw->text().isEmpty()) && (m_edPsw->text() == m_edPswRep->text()) )
|
||||
pswMatch = true;
|
||||
|
||||
m_butOk->setEnabled( pswMatch );
|
||||
|
||||
QString pswState;
|
||||
if ( pswMatch )
|
||||
{
|
||||
pswState = tr("Passwords match");
|
||||
}
|
||||
else
|
||||
{
|
||||
pswState = tr("Passwords do not match");
|
||||
}
|
||||
m_labMatch->setText( pswState );
|
||||
}
|
||||
|
||||
void UserInfoDialog::preAccept()
|
||||
{
|
||||
if ( m_edUserName->text().isEmpty() )
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("User name is empty") );
|
||||
m_edUserName->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
m_UserInfo.name = m_edUserName->text();
|
||||
m_UserInfo.psw = m_edPsw->text();
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
#include "commons.h"
|
||||
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
|
||||
class UserInfoDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UserInfoDialog(QWidget* parent = 0, const UserInfo& userInfo = UserInfo() );
|
||||
~UserInfoDialog();
|
||||
|
||||
UserInfo getUserInfo() { return m_UserInfo; }
|
||||
|
||||
private slots:
|
||||
void checkPasswords();
|
||||
void preAccept();
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
|
||||
private:
|
||||
QLabel* m_labUserName;
|
||||
QLineEdit* m_edUserName;
|
||||
QLabel* m_labPsw;
|
||||
QLineEdit* m_edPsw;
|
||||
QLabel* m_labPswRep;
|
||||
QLineEdit* m_edPswRep;
|
||||
QLabel* m_labMatch;
|
||||
|
||||
QPushButton* m_butOk;
|
||||
QPushButton* m_butCancel;
|
||||
|
||||
UserInfo m_UserInfo;
|
||||
};
|
Loading…
Reference in new issue