You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

widget.cpp 3.0KB

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