Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

connectwidget.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "connectwidget.h"
  2. #include "ui_connectwidget.h"
  3. ConnectWidget::ConnectWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ConnectWidget)
  4. {
  5. ui->setupUi(this);
  6. connect(ui->btnConnect, SIGNAL(clicked()), this, SLOT(login()));
  7. connect(ui->btnManage, SIGNAL(clicked()), this, SLOT(launchUsrManager()));
  8. connect(ui->btnReload, SIGNAL(clicked()), this, SLOT(loadUsers()));
  9. loadUsers();
  10. if(ui->lineLogin->count() == 0)
  11. {
  12. QMessageBox* msg = new QMessageBox(this);
  13. msg->setIcon(QMessageBox::Question);
  14. msg->setWindowTitle("No logins available");
  15. msg->setText("No logins with socks are available.\nDo you want to open User Manager to create one?");
  16. connect(msg->addButton(QMessageBox::Yes), SIGNAL(clicked()), this, SLOT(launchUsrManager()));
  17. connect(msg->addButton(QMessageBox::No), SIGNAL(clicked()), this, SLOT(loadUsers()));
  18. msg->show();
  19. }
  20. }
  21. ConnectWidget::~ConnectWidget()
  22. {
  23. delete ui;
  24. }
  25. bool ConnectWidget::hasLogin(QString login)
  26. {
  27. for(int i = 0; i < ui->lineLogin->count(); ++i)
  28. if(ui->lineLogin->itemText(i) == login)
  29. return true;
  30. return false;
  31. }
  32. void ConnectWidget::nsStateChanged(NetSoul::State s)
  33. {
  34. ui->btnConnect->setEnabled(s == NetSoul::Disconnected || s == NetSoul::ProtocolError || s == NetSoul::NetworkError || s == NetSoul::BadLogin);
  35. ui->lineLogin->setEnabled(ui->btnConnect->isEnabled());
  36. }
  37. void ConnectWidget::login()
  38. {
  39. if(ui->lineLogin->count() > 0)
  40. emit loginRequested(qvariant_cast<EpiUser>(ui->lineLogin->itemData(ui->lineLogin->currentIndex())));
  41. }
  42. void ConnectWidget::loadUsers()
  43. {
  44. ui->lineLogin->clear();
  45. EpiUsers users = Epimafia::loadUsers();
  46. foreach(EpiUser user, users)
  47. if(!user.isUnknown() && user.hasLogin() && user.hasPwd_socks())
  48. ui->lineLogin->addItem(user.getLogin(), user.toVariant());
  49. QString login = Options::instance()->getDefaultLogin();
  50. for(int i = 0; i < ui->lineLogin->count(); ++i)
  51. if(ui->lineLogin->itemText(i) == login)
  52. {
  53. ui->lineLogin->setCurrentIndex(i);
  54. return;
  55. }
  56. }
  57. void ConnectWidget::launchUsrManager()
  58. {
  59. QProcess* p = new QProcess(this);
  60. connect(p, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
  61. QString exe;
  62. #ifdef Q_OS_WIN
  63. exe = "usermgr.exe";
  64. #else
  65. #error "OS specific"
  66. #endif
  67. p->start(exe);
  68. }
  69. void ConnectWidget::processFinished(int)
  70. {
  71. loadUsers();
  72. }