選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

widget.cpp 3.8KB

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