Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

widget.cpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
  4. {
  5. ui->setupUi(this);
  6. setFixedSize(size());
  7. connect(ui->btnAdd, SIGNAL(clicked()), this, SLOT(addUser()));
  8. connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeCurrent()));
  9. connect(ui->btnSave, SIGNAL(clicked()), this, SLOT(saveCurrent()));
  10. foreach(QLineEdit* line, findChildren<QLineEdit*>())
  11. connect(line, SIGNAL(returnPressed()), this, SLOT(saveCurrent()));
  12. load();
  13. }
  14. Widget::~Widget()
  15. {
  16. delete ui;
  17. }
  18. void Widget::load()
  19. {
  20. EpiUsers users = Epimafia::loadUsers();
  21. foreach(EpiUser user, users)
  22. ui->comboLogin->addItem(user.getLogin(), user.toVariant());
  23. ui->btnRemove->setEnabled(users.size() != 0);
  24. }
  25. void Widget::removeCurrent()
  26. {
  27. EpiUser usr = qvariant_cast<EpiUser>(ui->comboLogin->itemData(ui->comboLogin->currentIndex()));
  28. Epimafia::removeUser(usr);
  29. foreach(QLineEdit* line, findChildren<QLineEdit*>())
  30. line->clear();
  31. ui->comboLogin->removeItem(ui->comboLogin->currentIndex());
  32. ui->btnRemove->setEnabled(ui->comboLogin->count() != 0);
  33. }
  34. void Widget::addUser()
  35. {
  36. EpiUser usr;
  37. usr.setLogin(Epimafia::getUnknownUser());
  38. Epimafia::saveUser(usr);
  39. ui->comboLogin->addItem(usr.getLogin(), usr.toVariant());
  40. ui->comboLogin->setCurrentIndex(ui->comboLogin->count() - 1);
  41. ui->btnRemove->setEnabled(true);
  42. }
  43. void Widget::saveCurrent()
  44. {
  45. EpiUser usr = qvariant_cast<EpiUser>(ui->comboLogin->itemData(ui->comboLogin->currentIndex()));
  46. usr.setLogin(ui->lineLogin->text());
  47. usr.setPassword(ui->linePass->text());
  48. usr.setPwd_num(ui->linePwdNum->text());
  49. usr.setPwd_ppp(ui->linePwdPPP->text());
  50. usr.setPwd_socks(ui->linePwdSocks->text());
  51. ui->comboLogin->setItemData(ui->comboLogin->currentIndex(), usr.toVariant());
  52. ui->comboLogin->setItemText(ui->comboLogin->currentIndex(), ui->lineLogin->text());
  53. Epimafia::saveUser(usr);
  54. }
  55. void Widget::setUser(EpiUser user)
  56. {
  57. ui->lineLogin->setText(user.getLogin());
  58. ui->linePass->setText(user.getPassword());
  59. ui->linePwdNum->setText(user.getPwd_num());
  60. ui->linePwdPPP->setText(user.getPwd_ppp());
  61. ui->linePwdSocks->setText(user.getPwd_socks());
  62. }
  63. void Widget::on_comboLogin_currentIndexChanged(int index)
  64. {
  65. setUser(qvariant_cast<EpiUser>(ui->comboLogin->itemData(index)));
  66. }