Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

widget.cpp 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }