Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

connectwidget.cpp 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifdef Q_OS_LINUX
  66. exe = "usermgr";
  67. #else
  68. #error "OS specific"
  69. #endif
  70. #endif
  71. p->start(exe);
  72. }
  73. void ConnectWidget::processFinished(int)
  74. {
  75. loadUsers();
  76. }