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.

widget.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. m_netsoul = new NetSoul(this);
  11. if(qApp->arguments().size() == 3)
  12. {
  13. if(qApp->arguments().at(1) == "-login")
  14. {
  15. ui->lineLogin->setText(qApp->arguments().at(2));
  16. on_lineLogin_returnPressed();
  17. }
  18. else if(qApp->arguments().at(1) == "-ip")
  19. {
  20. ui->lineIp->setText(qApp->arguments().at(2));
  21. on_lineIp_returnPressed();
  22. }
  23. }
  24. }
  25. Widget::~Widget()
  26. {
  27. delete ui;
  28. }
  29. void Widget::on_lineLogin_returnPressed()
  30. {
  31. ui->lineIp->clear();
  32. m_netsoul->disconnect(this);
  33. connect(m_netsoul, SIGNAL(stateChanged(NetSoul::State)), this, SLOT(loginStateChanged(NetSoul::State)));
  34. m_netsoul->login();
  35. m_netsoul->listUsers(this, SLOT(loginList(NetSoul::Users)), ui->lineLogin->text());
  36. }
  37. void Widget::on_lineIp_returnPressed()
  38. {
  39. ui->lineLogin->clear();
  40. m_netsoul->disconnect(this);
  41. connect(m_netsoul, SIGNAL(stateChanged(NetSoul::State)), this, SLOT(ipStateChanged(NetSoul::State)));
  42. m_netsoul->login();
  43. m_netsoul->listUsers(this, SLOT(ipList(NetSoul::Users)));
  44. }
  45. void Widget::ipList(NetSoul::Users users)
  46. {
  47. QString res;
  48. for(int i = 0; i < users.size(); ++i)
  49. {
  50. if(users.at(i).ip != ui->lineIp->text())
  51. continue;
  52. res += users.at(i).login + "; ";
  53. }
  54. res.remove(res.size() - 2, 2);
  55. if(!res.isEmpty())
  56. ui->lineLogin->setText(res);
  57. else
  58. ui->lineLogin->setText("#notFound#");
  59. m_netsoul->logout();
  60. }
  61. void Widget::loginList(NetSoul::Users users)
  62. {
  63. if(!users.isEmpty())
  64. {
  65. QString res;
  66. for(int i = 0; i < users.size(); ++i)
  67. {
  68. res += users.at(i).ip;
  69. if(i < users.size() - 1)
  70. res += "; ";
  71. }
  72. ui->lineIp->setText(res);
  73. }
  74. else
  75. ui->lineIp->setText("#notFound#");
  76. m_netsoul->logout();
  77. }
  78. void Widget::ipStateChanged(NetSoul::State state)
  79. {
  80. if(state == NetSoul::NetworkError || state == NetSoul::ProtocolError)
  81. ui->lineLogin->setText("#error#");
  82. setStatus(state);
  83. }
  84. void Widget::loginStateChanged(NetSoul::State state)
  85. {
  86. if(state == NetSoul::NetworkError || state == NetSoul::ProtocolError)
  87. ui->lineIp->setText("#error#");
  88. setStatus(state);
  89. }
  90. void Widget::setStatus(NetSoul::State state)
  91. {
  92. if(state == NetSoul::Disconnected)
  93. ui->labelStatus->setText("idle");
  94. else if(state == NetSoul::HostLookUp)
  95. ui->labelStatus->setText("Searching Host...");
  96. else if(state == NetSoul::Connecting)
  97. ui->labelStatus->setText("Host Found. Connecting...");
  98. else if(state == NetSoul::Connected || state == NetSoul::LoggedIn)
  99. ui->labelStatus->setText("Connected. Searching...");
  100. else if(state == NetSoul::Disconnecting)
  101. ui->labelStatus->setText("Finished. Disconnecting...");
  102. else if(state == NetSoul::NetworkError)
  103. ui->labelStatus->setText("Network Error: " + QString::number((int)m_netsoul->getLastNetworkError()));
  104. else if(state == NetSoul::ProtocolError)
  105. ui->labelStatus->setText("Protocol Error");
  106. else if(state == NetSoul::BadLogin)
  107. ui->labelStatus->setText("Bad Login");
  108. else
  109. ui->labelStatus->setText("Illegal State");
  110. }
  111. void Widget::on_btnSearchLogin_clicked()
  112. {
  113. QString logins = ui->lineLogin->text();
  114. if(logins.isEmpty() || (logins.startsWith("#") && logins.endsWith("#")))
  115. return;
  116. QString exe;
  117. #ifdef Q_OS_WIN
  118. exe = "intrabocal.exe";
  119. #else
  120. #ifdef Q_OS_LINUX
  121. exe = "intrabocal";
  122. #else
  123. #error "OS specific"
  124. #endif
  125. #endif
  126. QProcess::startDetached(exe, QStringList() << "-logins" << logins);
  127. }