123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include "widget.h"
- #include "ui_widget.h"
-
- Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
- {
- ui->setupUi(this);
- setFixedSize(size());
- m_netsoul = new NetSoul(this);
- if(qApp->arguments().size() == 3)
- {
- if(qApp->arguments().at(1) == "-login")
- {
- ui->lineLogin->setText(qApp->arguments().at(2));
- on_lineLogin_returnPressed();
- }
- else if(qApp->arguments().at(1) == "-ip")
- {
- ui->lineIp->setText(qApp->arguments().at(2));
- on_lineIp_returnPressed();
- }
- }
- }
-
- Widget::~Widget()
- {
- delete ui;
- }
-
- void Widget::on_lineLogin_returnPressed()
- {
- ui->lineIp->clear();
- m_netsoul->disconnect(this);
- connect(m_netsoul, SIGNAL(stateChanged(NetSoul::State)), this, SLOT(loginStateChanged(NetSoul::State)));
- m_netsoul->login();
- m_netsoul->listUsers(this, SLOT(loginList(NetSoul::Users)), ui->lineLogin->text());
- }
-
- void Widget::on_lineIp_returnPressed()
- {
- ui->lineLogin->clear();
- m_netsoul->disconnect(this);
- connect(m_netsoul, SIGNAL(stateChanged(NetSoul::State)), this, SLOT(ipStateChanged(NetSoul::State)));
- m_netsoul->login();
- m_netsoul->listUsers(this, SLOT(ipList(NetSoul::Users)));
- }
-
- void Widget::ipList(NetSoul::Users users)
- {
- QString res;
- for(int i = 0; i < users.size(); ++i)
- {
- if(users.at(i).ip != ui->lineIp->text())
- continue;
- res += users.at(i).login + "; ";
- }
- res.remove(res.size() - 2, 2);
- if(!res.isEmpty())
- ui->lineLogin->setText(res);
- else
- ui->lineLogin->setText("#notFound#");
- m_netsoul->logout();
- }
-
- void Widget::loginList(NetSoul::Users users)
- {
- if(!users.isEmpty())
- {
- QString res;
- for(int i = 0; i < users.size(); ++i)
- {
- res += users.at(i).ip;
- if(i < users.size() - 1)
- res += "; ";
- }
- ui->lineIp->setText(res);
- }
- else
- ui->lineIp->setText("#notFound#");
- m_netsoul->logout();
- }
-
- void Widget::ipStateChanged(NetSoul::State state)
- {
- if(state == NetSoul::NetworkError || state == NetSoul::ProtocolError)
- ui->lineLogin->setText("#error#");
- setStatus(state);
- }
-
- void Widget::loginStateChanged(NetSoul::State state)
- {
- if(state == NetSoul::NetworkError || state == NetSoul::ProtocolError)
- ui->lineIp->setText("#error#");
- setStatus(state);
- }
-
- void Widget::setStatus(NetSoul::State state)
- {
- if(state == NetSoul::Disconnected)
- ui->labelStatus->setText("idle");
- else if(state == NetSoul::HostLookUp)
- ui->labelStatus->setText("Searching Host...");
- else if(state == NetSoul::Connecting)
- ui->labelStatus->setText("Host Found. Connecting...");
- else if(state == NetSoul::Connected || state == NetSoul::LoggedIn)
- ui->labelStatus->setText("Connected. Searching...");
- else if(state == NetSoul::Disconnecting)
- ui->labelStatus->setText("Finished. Disconnecting...");
- else if(state == NetSoul::NetworkError)
- ui->labelStatus->setText("Network Error: " + QString::number((int)m_netsoul->getLastNetworkError()));
- else if(state == NetSoul::ProtocolError)
- ui->labelStatus->setText("Protocol Error");
- else if(state == NetSoul::BadLogin)
- ui->labelStatus->setText("Bad Login");
- else
- ui->labelStatus->setText("Illegal State");
- }
-
- void Widget::on_btnSearchLogin_clicked()
- {
- QString logins = ui->lineLogin->text();
- if(logins.isEmpty() || (logins.startsWith("#") && logins.endsWith("#")))
- return;
- QString exe;
- #ifdef Q_OS_WIN
- exe = "intrabocal.exe";
- #else
- #ifdef Q_OS_LINUX
- exe = "intrabocal";
- #else
- #error "OS specific"
- #endif
- #endif
- QProcess::startDetached(exe, QStringList() << "-logins" << logins);
- }
|