ClientControllerWidget::ClientControllerWidget(Client *client, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), _client(client) { _ui.setupUi(this); _ui.savePath->setObjectName(QDir::homePath()); _ui.filesView->setModel(new ClientFilesModel(_client, this)); connect(_ui.savePathButton, SIGNAL(clicked()), SLOT(onSavePathButtonClicked())); connect(_client, SIGNAL(serverConnected()), SLOT(updateGuiState())); connect(_client, SIGNAL(serverDisconnected()), SLOT(updateGuiState())); }
void CWebSocketClient::onConnected() { qDebug() << "WebSocket connected"; connect(&m_webSocket, &QWebSocket::textMessageReceived, this, &CWebSocketClient::onTextMessageReceived); connect(&m_webSocket, &QWebSocket::binaryMessageReceived, this, &CWebSocketClient::onBinaryMessageReceived); m_webSocket.sendTextMessage(QStringLiteral("3")); emit serverConnected(m_url.toString()); }
Client::Client(QObject *parent) : QObject(parent), _serverConnection(0) { qRegisterMetaType<QHostAddress>("QHostAddress"); _serverConnection = new ClientServerConnectionHandler(this, this); connect(_serverConnection->getSocket(), SIGNAL(connected()), SIGNAL(serverConnected())); connect(_serverConnection->getSocket(), SIGNAL(disconnected()), SIGNAL(serverDisconnected())); _dataSocket = new ClientUdpSocket(this, this); }
void PingPong::addService(const QBluetoothServiceInfo &service) { setMessage("Service found. Setting parameters..."); //! [Connecting the socket] socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol); socket->connectToService(service); connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(connected()), this, SLOT(serverConnected())); connect(socket, SIGNAL(disconnected()), this, SLOT(serverDisconnected())); //! [Connecting the socket] m_serviceFound = true; }
NetworkManager::NetworkManager(QString host, int port, QObject *parent) : JsonCommunication(host, port, parent) { m_logged = false; m_heartbeatManager = new HeartbeatManager(3,this); connect(m_heartbeatManager, SIGNAL(networkRequest(QString)), this, SLOT(serverRequest(QString))); connect(m_heartbeatManager, SIGNAL(queueFull()), this, SLOT(forceDisconnect())); connect(this,SIGNAL(connectedChanged(bool)),m_heartbeatManager,SLOT(setRunning(bool))); connect(this,SIGNAL(hearthbeatReceived(QString)),m_heartbeatManager,SLOT(validate(QString))); connect(this,SIGNAL(jsonReceived(QString)),this,SLOT(processJson(QString))); connect(this,SIGNAL(serverConnected()),this,SLOT(tryLogin())); connect(this,SIGNAL(serverDisconnected()),this,SLOT(setNotLogged())); }
bool INDI::BaseClientQt::connectServer() { client_socket.connectToHost(cServer.c_str(), cPort); if (client_socket.waitForConnected(timeout_sec*1000) == false) { sConnected = false; return false; } clear(); lillp = newLilXML(); sConnected = true; serverConnected(); char * orig = setlocale(LC_NUMERIC,"C"); QString getProp; if (cDeviceNames.empty()) { getProp = QString("<getProperties version='%1'/>\n").arg(QString::number(INDIV)); client_socket.write(getProp.toLatin1()); if (verbose) std::cerr << getProp.toLatin1().constData() << std::endl; } else { vector<string>::const_iterator stri; for ( stri = cDeviceNames.begin(); stri != cDeviceNames.end(); stri++) { getProp = QString("<getProperties version='%1' device='%2'/>\n").arg(QString::number(INDIV)).arg( (*stri).c_str()); client_socket.write(getProp.toLatin1()); if (verbose) std::cerr << getProp.toLatin1().constData() << std::endl; } } setlocale(LC_NUMERIC,orig); return true; }
//Waits for a connection from a psp: void doServer() { int skip = 0; int quit = 0; char message[100] = ""; int dialog = OSL_DIALOG_NONE; int connected = 0; int init = oslAdhocInit("ULUS99999"); if (init) { snprintf(message, sizeof(message), "adhocInit error: %i", init); oslMessageBox(message, "Debug", oslMake3Buttons(OSL_KEY_CROSS, OSL_MB_OK , 0, 0, 0, 0)); return; } while(!osl_quit && !quit){ struct remotePsp *reqPsp = oslAdhocGetConnectionRequest(); if (!skip){ oslStartDrawing(); printInfo(); oslDrawString(10, 40, "Press O to abort"); if (reqPsp == NULL) { oslDrawString(10, 100, "Waiting for a connection request..."); } else { snprintf(message, sizeof(message), "Accept request from psp : %s", reqPsp->name); oslDrawString(10, 100, message); if (oslGetDialogType() == OSL_DIALOG_NONE) oslInitMessageDialog(message, 1); } dialog = oslGetDialogType(); if (dialog){ oslDrawDialog(); if (oslGetDialogStatus() == PSP_UTILITY_DIALOG_NONE){ if (dialog == OSL_DIALOG_MESSAGE){ int button = oslGetDialogButtonPressed(); if (button == PSP_UTILITY_MSGDIALOG_RESULT_YES) { oslAdhocAcceptConnection(reqPsp); connected = 1; } else if (button == PSP_UTILITY_MSGDIALOG_RESULT_NO) { oslAdhocRejectConnection(reqPsp); } } oslEndDialog(); } } oslEndDrawing(); } oslEndFrame(); skip = oslSyncFrame(); if (connected) serverConnected(reqPsp); oslReadKeys(); if (dialog == OSL_DIALOG_NONE) { if (osl_keys->released.circle) { quit = 1; } } } oslAdhocTerm(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { _port = new QSpinBox(this); _port->setMaximum(99999); _port->setValue(8796); _host = new QLineEdit(this); _host->setFixedWidth(100); _connectServer = new QPushButton(tr("Connect"), this); _connectServer->setCheckable(true); _consult = new QPushButton(tr("Consult"), this); _sendCmd = new QPushButton(tr("Send"), this); _cmd = new QLineEdit(this); _serverOutput = new QTextEdit(this); _serverOutput->setReadOnly(true); _codeEditor = new CodeEditor(this); _consult->setEnabled(false); _cmd->setEnabled(false); _sendCmd->setEnabled(false); _client = new Client(); QObject::connect(_connectServer, SIGNAL(clicked(bool)), this, SLOT(changeServerStatus(bool))); QObject::connect(_client, SIGNAL(connected()), this, SLOT(serverConnected())); QObject::connect(_client, SIGNAL(disconnected()), this, SLOT(serverDisconnected())); QObject::connect(_client, SIGNAL(dataReceived(QString)), this, SLOT(writeServerOutput(QString))); QObject::connect(_client, SIGNAL(errorSocket(QString)), this, SLOT(writeServerOutput(QString))); QObject::connect(_sendCmd, SIGNAL(clicked()), this, SLOT(sendCmd())); QObject::connect(_consult, SIGNAL(clicked()), this, SLOT(consultFile())); QHBoxLayout *layoutHeader = new QHBoxLayout; layoutHeader->setContentsMargins(10,0,0,10); layoutHeader->addWidget(new QLabel(tr("Host"), this)); layoutHeader->addWidget(_host); layoutHeader->addSpacing(10); layoutHeader->addWidget(new QLabel(tr("Port"), this)); layoutHeader->addWidget(_port); layoutHeader->addStretch(100); layoutHeader->addWidget(_connectServer); QSplitter *centralSplitter = new QSplitter(this); centralSplitter->addWidget(_codeEditor); centralSplitter->addWidget(_serverOutput); QHBoxLayout *layoutBottom = new QHBoxLayout; layoutBottom->addWidget(_consult, 1); layoutBottom->addWidget(_cmd, 100); layoutBottom->addWidget(_sendCmd, 1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setMargin(0); mainLayout->setSpacing(0); mainLayout->addLayout(layoutHeader, 1); mainLayout->addWidget(centralSplitter); mainLayout->addLayout(layoutBottom, 1); QWidget *centralWidget = new QWidget(this); centralWidget->setLayout(mainLayout); this->setCentralWidget(centralWidget); }
void CTransaction::serverConnectedSlot() { m_offLine = false; emit serverConnected(); }
Tennis::Tennis(QWidget *parent) : QDialog(parent), ui(new Ui_Tennis), board(new Board), controller(new Controller), socket(0), m_discoveryAgent(new QBluetoothServiceDiscoveryAgent), m_handover(0) { // start Bluetooth if not started QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); device->powerOn(); delete device; device = 0; //! [Construct UI] ui->setupUi(this); isClient = false; isConnected = false; quickDiscovery = true; #if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) setWindowState(Qt::WindowMaximized); #endif ui->pongView->setScene(board->getScene()); connect(ui->pongView, SIGNAL(mouseMove(int, int)), this, SLOT(mouseMove(int, int))); ui->pongView->setMouseTracking(false); connect(board, SIGNAL(ballCollision(Board::Edge)), controller, SLOT(ballCollision(Board::Edge))); connect(board, SIGNAL(scored(Board::Edge)), controller, SLOT(scored(Board::Edge))); connect(controller, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); connect(this, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); connect(this, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); connect(controller, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); connect(controller, SIGNAL(fps(const QString&)), this, SLOT(fps(const QString&))); setFocusPolicy(Qt::WheelFocus); paddle_pos = (Board::Height-12)/2-Board::Paddle/2; endPaddlePos = paddle_pos; emit moveLeftPaddle(paddle_pos); board->setRightPaddle(paddle_pos); server = new TennisServer(this); connect(controller, SIGNAL(moveBall(int,int)), server, SLOT(moveBall(int,int))); connect(controller, SIGNAL(score(int,int)), server, SLOT(score(int,int))); connect(this, SIGNAL(moveLeftPaddle(int)), server, SLOT(moveLeftPaddle(int))); connect(server, SIGNAL(clientConnected(QString)), this, SLOT(serverConnected(QString))); connect(server, SIGNAL(clientDisconnected(QString)), this, SLOT(serverDisconnected())); connect(server, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); connect(server, SIGNAL(lag(int)), this, SLOT(lagReport(int))); connect(server, SIGNAL(clientConnected(QString)), controller, SLOT(refresh())); server->startServer(); client = new TennisClient(this); connect(client, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); connect(client, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); connect(client, SIGNAL(connected(QString)), this, SLOT(clientConnected(QString))); connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); connect(this, SIGNAL(moveRightPaddle(int)), client, SLOT(moveRightPaddle(int))); connect(client, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); connect(client, SIGNAL(lag(int)), this, SLOT(lagReport(int))); connect(this, SIGNAL(moveLeftPaddle(int)), controller, SLOT(moveLeftPaddle(int))); connect(this, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); connect(server, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); // ui->pongView->setBackgroundBrush(QBrush(Qt::white)); ui->pongView->setCacheMode(QGraphicsView::CacheBackground); QNearFieldManager nearFieldManager; if (nearFieldManager.isAvailable()) { m_handover = new Handover(server->serverPort(), this); connect(m_handover, SIGNAL(bluetoothServiceChanged()), this, SLOT(nearFieldHandover())); connect(m_discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); connect(m_discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); } m_discoveryAgent->setUuidFilter(QBluetoothUuid(serviceUuid)); QString address; QString port; QStringList args = QCoreApplication::arguments(); if(args.length() >= 2){ address = args.at(1); if(args.length() >= 3){ port = args.at(2); } } if(address.isEmpty()){ QSettings settings("QtDF", "bttennis"); address = settings.value("lastclient").toString(); } if(!address.isEmpty()){ qDebug() << "Connect to" << address << port; QBluetoothDeviceInfo device = QBluetoothDeviceInfo(QBluetoothAddress(address), "", QBluetoothDeviceInfo::ComputerDevice); QBluetoothServiceInfo service; if (!port.isEmpty()) { QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) << QVariant::fromValue(port.toUShort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); qDebug() << "port" << port.toUShort() << service.protocolServiceMultiplexer(); } else { service.setServiceUuid(QBluetoothUuid(serviceUuid)); } service.setDevice(device); client->startClient(service); board->setStatus("Connecting", 100, 25); } else if (nearFieldManager.isAvailable()) { board->setStatus(tr("Touch to play"), 100, 25); } setEnabled(true); paddleAnimation = new QPropertyAnimation(this, "paddlePos", this); paddleAnimation->setEasingCurve(QEasingCurve::InOutQuad); ui->pongView->installEventFilter(this); }
CMainWindow::CMainWindow(int argc, char *argv[], QWidget *parent) : QMainWindow(parent) { //====================================================================================================================================== QStringList arguments; for (int i = 0; i < argc; i++) { arguments.append(argv[i]); arguments[i].remove("-"); } //====================================================================================================================================== qSetMessagePattern("[%{time h:mm:ss:zzz} %{if-category}%{category}%{endif} %{type}] %{function}: - %{message}"); //====================================================================================================================================== ui.setupUi(this); QSettings settings; m_EventFilter = CEventFilter::Signleton(); m_Data = new CData; //====================================================================================================================================== if (arguments.contains("ip")) { m_WebSocketClient = new CWebSocketClient(QUrl(QString("ws://%1").arg((arguments.at(arguments.indexOf("ip") + 1)))), m_Data); settings.setValue("IPAdress", arguments.at(arguments.indexOf("ip") + 1).split(":").first()); settings.setValue("Port", arguments.at(arguments.indexOf("ip") + 1).split(":").last()); } else m_WebSocketClient = new CWebSocketClient(QUrl(QString("ws://%1:%2").arg(settings.value("IPAdress").toString()).arg(settings.value("Port").toString())), m_Data); //====================================================================================================================================== ////Actions //QAction *action_Close = new QAction(QIcon(QString::fromUtf8(":/Resources/cancel.png")), "Close", this); //QAction *action_FullScreen = new QAction(QIcon(QString::fromUtf8(":/Resources/slideshow_full_screen.png")), "Fullsreen", this); //QAction *action_HomePage = new QAction(QIcon(QString::fromUtf8(":/Resources/home_page.png")), "Home Page", this); //QAction *action_Plotter = new QAction(QIcon(QString::fromUtf8(":/Resources/chart_curve.png")), "Plotter", this); ////====================================================================================================================================== ////Toolbar //ui.toolBar->addAction(action_Close); //ui.toolBar->addAction(action_FullScreen); //ui.toolBar->addSeparator(); //ui.toolBar->setIconSize(QSize(20, 20)); //ui.toolBar->addAction(action_HomePage); //ui.toolBar->addAction(action_Plotter); //====================================================================================================================================== //StartPage m_StartPage = new CStartPage(this); ui.stackedWidget->addWidget(m_StartPage->getView()); //====================================================================================================================================== //Plotter m_Plotter = new CPlotter(this); ui.stackedWidget->addWidget(m_Plotter->getView()); //====================================================================================================================================== //Settings m_Settings = new CSettings(this); ui.stackedWidget->addWidget(m_Settings); //====================================================================================================================================== //====================================================================================================================================== connect(m_EventFilter, SIGNAL(reciveClick()), this, SLOT(showNextPage())); connect(m_EventFilter, SIGNAL(reciveDoubleClick()), this, SLOT(showSettings())); connect(m_Data, SIGNAL(NewDataRecieved()), this, SLOT(onNewData())); connect(m_Settings, SIGNAL(reciveNewURL(QString)), this, SLOT(onNewURL(QString))); connect(m_Settings, SIGNAL(ready()), this, SLOT(showStartpage())); connect(m_WebSocketClient, SIGNAL(serverConnected(QString)), m_Settings, SLOT(onServerConnected(QString))); connect(m_WebSocketClient, SIGNAL(serverDisconnected()), m_Settings, SLOT(onServerDisconnected())); connect(m_WebSocketClient, SIGNAL(recievedInitialScript(QJsonObject)), m_Data, SLOT(recievedInitialScript(QJsonObject))); connect(m_WebSocketClient, SIGNAL(recievedDataScript(QJsonObject)), m_Data, SLOT(recievedDataScript(QJsonObject))); //====================================================================================================================================== //====================================================================================================================================== resize(480, 320); ui.stackedWidget->setCurrentIndex(0); }