12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "widget.h"
- #include "ui_widget.h"
- #include <QShortcut>
-
- Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
- {
- ui->setupUi(this);
-
- QShortcut* quit = new QShortcut(QKeySequence("Ctrl+Q"), this);
- connect(quit, SIGNAL(activated()), qApp, SLOT(quit()));
-
- 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<QLineEdit*>())
- 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<EpiUser>(ui->comboLogin->itemData(ui->comboLogin->currentIndex()));
- Epimafia::removeUser(usr);
- foreach(QLineEdit* line, findChildren<QLineEdit*>())
- 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<EpiUser>(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<EpiUser>(ui->comboLogin->itemData(index)));
- }
|