#include "widget.h" #include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); setFixedSize(size()); connect(ui->btnAdd, SIGNAL(clicked()), this, SLOT(addUser())); connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeCurrent())); connect(ui->btnSave, SIGNAL(clicked()), this, SLOT(saveCurrent())); foreach(QLineEdit* line, findChildren()) connect(line, SIGNAL(returnPressed()), this, SLOT(saveCurrent())); load(); } Widget::~Widget() { delete ui; } void Widget::load() { EpiUsers users = Epimafia::loadUsers(); foreach(EpiUser user, users) ui->comboLogin->addItem(user.getLogin(), user.toVariant()); ui->btnRemove->setEnabled(users.size() != 0); } void Widget::removeCurrent() { EpiUser usr = qvariant_cast(ui->comboLogin->itemData(ui->comboLogin->currentIndex())); Epimafia::removeUser(usr); foreach(QLineEdit* line, findChildren()) line->clear(); ui->comboLogin->removeItem(ui->comboLogin->currentIndex()); ui->btnRemove->setEnabled(ui->comboLogin->count() != 0); } void Widget::addUser() { EpiUser usr; usr.setLogin(Epimafia::getUnknownUser()); Epimafia::saveUser(usr); ui->comboLogin->addItem(usr.getLogin(), usr.toVariant()); ui->comboLogin->setCurrentIndex(ui->comboLogin->count() - 1); ui->btnRemove->setEnabled(true); } void Widget::saveCurrent() { EpiUser usr = qvariant_cast(ui->comboLogin->itemData(ui->comboLogin->currentIndex())); usr.setLogin(ui->lineLogin->text()); usr.setPassword(ui->linePass->text()); usr.setPwd_num(ui->linePwdNum->text()); usr.setPwd_ppp(ui->linePwdPPP->text()); usr.setPwd_socks(ui->linePwdSocks->text()); ui->comboLogin->setItemData(ui->comboLogin->currentIndex(), usr.toVariant()); ui->comboLogin->setItemText(ui->comboLogin->currentIndex(), ui->lineLogin->text()); Epimafia::saveUser(usr); } void Widget::setUser(EpiUser user) { ui->lineLogin->setText(user.getLogin()); ui->linePass->setText(user.getPassword()); ui->linePwdNum->setText(user.getPwd_num()); ui->linePwdPPP->setText(user.getPwd_ppp()); ui->linePwdSocks->setText(user.getPwd_socks()); } void Widget::on_comboLogin_currentIndexChanged(int index) { setUser(qvariant_cast(ui->comboLogin->itemData(index))); }