123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #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()));
-
- QShortcut* save = new QShortcut(QKeySequence("Ctrl+S"), this);
- connect(save, SIGNAL(activated()), this, SLOT(saveCurrent()));
-
- 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)));
- }
-
- void Widget::on_btnShowPass_toggled(bool checked)
- {
- ui->linePass->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
- }
-
- void Widget::on_pushShowNum_toggled(bool checked)
- {
- ui->linePwdNum->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
- }
-
- void Widget::on_btnShowPPP_toggled(bool checked)
- {
- ui->linePwdPPP->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
- }
-
- void Widget::on_btnShowSocks_toggled(bool checked)
- {
- ui->linePwdSocks->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
- }
|