Beispiel #1
0
	ServerInfoStorage::ServerInfoStorage (ClientConnection *conn, AccountSettingsHolder *settings)
	: QObject (conn)
	, Conn_ (conn)
	, Settings_ (settings)
	{
		connect (Conn_->GetClient (),
				SIGNAL (connected ()),
				this,
				SLOT (handleConnected ()));
	}
Beispiel #2
0
void FtpClient::init()
{
    qDebug() << "FtpClient:: " << port << " Init";
    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

    qDebug() << "FtpClient:: " << port << " Init connect";
    // from abtractsocket
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(handleError(QAbstractSocket::SocketError)));
    connect(tcpSocket, SIGNAL(connected()), this, SLOT(handleConnected()));
    connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(handleDisconnected()));
    connect(tcpSocket, SIGNAL(hostFound()), this, SLOT(handleHostFound()));
    connect(tcpSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)), this, SLOT(handleProxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)));
    connect(tcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(handleStateChanged(QAbstractSocket::SocketState)));
    // from QIODevice
    connect(tcpSocket, SIGNAL(aboutToClose()), this, SLOT(handleAboutToClose()));
    connect(tcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(handleBytesWritten(qint64)));
    connect(tcpSocket, SIGNAL(readChannelFinished()), this, SLOT(handleReadChannelFinished()));
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));


    qDebug() << "FtpClient:: " << port << " Init NetworkConfigurationManager manager";
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        qDebug() << "FtpClient::Init QNetworkConfigurationManager::NetworkSessionRequired";
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String(SETTING_STR));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        QNetworkConfiguration config = manager.configurationFromIdentifier(id);
        if ((config.state() & QNetworkConfiguration::Discovered) !=
            QNetworkConfiguration::Discovered) {
            config = manager.defaultConfiguration();
        }

        qDebug() << "FtpClient:: " << port << " Init new QNetworkSession(config, this)";
        networkSession = new QNetworkSession(config, this);
        qDebug() << "FtpClient:: " << port << " Init connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()))";
        connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()));

        qDebug() << "FtpClient:: " << port << " Init networkSession->open()";
        networkSession->open();
    } else {
        qDebug() << "FtpClient:: Init " << port << " tcpSocket->connectToHost())" << " ipAddress " << ipAddress << " port " << port;
        tcpSocket->connectToHost(QHostAddress(ipAddress),  port);
    }

    mInitiated = true;
}
void SshRemoteProcessRunner::runInternal(const QByteArray &command,
    const SshConnectionParameters &sshParams)
{
    setState(Connecting);

    d->m_lastConnectionError = SshNoError;
    d->m_lastConnectionErrorString.clear();
    d->m_processErrorString.clear();
    d->m_exitSignal = SshRemoteProcess::NoSignal;
    d->m_exitCode = -1;
    d->m_command = command;
    d->m_connection = SshConnectionManager::instance().acquireConnection(sshParams);
    connect(d->m_connection, SIGNAL(error(QSsh::SshError)),
        SLOT(handleConnectionError(QSsh::SshError)));
    connect(d->m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
    if (d->m_connection->state() == SshConnection::Connected) {
        handleConnected();
    } else {
        connect(d->m_connection, SIGNAL(connected()), SLOT(handleConnected()));
        if (d->m_connection->state() == SshConnection::Unconnected)
            d->m_connection->connectToHost();
    }
}
Beispiel #4
0
void CodaSignalHandler::tcfEvent(const Coda::CodaEvent &event)
{
    reportMessage(tr("CODA event: Type: %1 Message: %2").arg(event.type()).arg(event.toString()));

    switch (event.type()) {
    case Coda::CodaEvent::LocatorHello:
        handleConnected(event);
        break;
    case Coda::CodaEvent::ProcessExitedEvent:
        handleAppExited(event);
        break;
    default:
        reportMessage(tr("CODA unhandled event: Type: %1 Message: %2").arg(event.type()).arg(event.toString()));
        break;
    }
}
Beispiel #5
0
void IRCNetworkPlugin::handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
	// Server is in server-mode, so user is JID of server when we want to connect
	if (CONFIG_BOOL(config, "service.server_mode")) {
		MyIrcSession *session = new MyIrcSession(user, this);
		std::string h = user.substr(0, user.find("@"));
		session->setNickName(FROM_UTF8(h.substr(0, h.find("%"))));
		session->setHost(FROM_UTF8(h.substr(h.find("%") + 1)));
		session->setPort(6667);
		session->open();
		std::cout << "CONNECTING IRC NETWORK " << h.substr(h.find("%") + 1) << "\n";
		m_sessions[user] = session;
	}
	else {
		handleConnected(user);
	}
}
Beispiel #6
0
void IRCNetworkPlugin::handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
	if (!m_servers.empty()) {
		// legacy name is user's nickname
		if (m_sessions[user] != NULL) {
			LOG4CXX_WARN(logger, user << ": Already logged in.");
			return;
		}

		m_sessions[user] = createSession(user, m_servers[m_currentServer], legacyName, password, "");
	}
	else {
		// We are waiting for first room join to connect user to IRC network, because we don't know which
		// network he chooses...
		LOG4CXX_INFO(logger, user << ": Ready for connections");
		handleConnected(user);
	}
}
Beispiel #7
0
void Component::start() {
	if (m_component && !m_component->isAvailable()) {
		LOG4CXX_INFO(logger, "Connecting XMPP server " << CONFIG_STRING(m_config, "service.server") << " port " << CONFIG_INT(m_config, "service.port"));
		m_reconnectCount++;
		m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port"));
		m_reconnectTimer->stop();
	}
	else if (m_server) {
		LOG4CXX_INFO(logger, "Starting component in server mode on port " << CONFIG_INT(m_config, "service.port"));
		m_server->start();

		//Type casting to BoostConnectionServer since onStopped signal is not defined in ConnectionServer
		//Ideally, onStopped must be defined in ConnectionServer
		boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())->onStopped.connect(boost::bind(&Component::handleServerStopped, this, _1));
		
		// We're connected right here, because we're in server mode...
		handleConnected();
	}
}
Beispiel #8
0
ClientNet::ClientNet(Logic* pLogic)
:	m_isConnected(false), m_sentBuf(""), m_recvBuf(""),
	m_pLogic(pLogic)
{
	m_pLog = LogManager::getSingleton().getLog("ClientNet");
	// 打开控制台输出开头-注:正式发布时不打开
	m_pLog->setStdStreamActive(true);
	m_pTcpSocket = new QTcpSocket(this);
	// 添加网络消息回调函数
	connect( m_pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
			 this, SLOT(handleError(QAbstractSocket::SocketError)) );
	connect( m_pTcpSocket, SIGNAL(connected()),
			 this, SLOT(handleConnected()) );
	connect( m_pTcpSocket, SIGNAL(readyRead()),
			 this, SLOT(handleReadyRead()) );
	QSettings ini("config.ini", QSettings::IniFormat);
	QString ip = ini.value("ip").toString();
	int32 port = ini.value("port").toInt();
	m_pLog->info(std::string("connect to ") + ip.toLocal8Bit().data() + ":" + SConvert::toString(port));
	m_pTcpSocket->connectToHost(ip, port);
}
Beispiel #9
0
void XMPPFrontend::connectToServer() {
	if (m_component && !m_component->isAvailable()) {
		LOG4CXX_INFO(logger, "Connecting XMPP server " << CONFIG_STRING(m_config, "service.server") << " port " << CONFIG_INT(m_config, "service.port"));
		if (CONFIG_INT(m_config, "service.port") == 5222) {
			LOG4CXX_WARN(logger, "Port 5222 is usually used for client connections, not for component connections! Are you sure you are using right port?");
		}
		m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port"));
	}
	else if (m_server) {
		LOG4CXX_INFO(logger, "Starting XMPPFrontend in server mode on port " << CONFIG_INT(m_config, "service.port"));
		m_server->start();

		//Type casting to BoostConnectionServer since onStopped signal is not defined in ConnectionServer
		//Ideally, onStopped must be defined in ConnectionServer
		if (boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())) {
			boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())->onStopped.connect(boost::bind(&XMPPFrontend::handleServerStopped, this, _1));
		}
		
		// We're connected right here, because we're in server mode...
		handleConnected();
	}
}
QPointF KoConnectionShapePrivate::escapeDirection(int handleId) const
{
    Q_Q(const KoConnectionShape);
    QPointF direction;
    if (handleConnected(handleId)) {
        KoShape *attachedShape = handleId == KoConnectionShape::StartHandle ? shape1 : shape2;
        int connectionPointId = handleId == KoConnectionShape::StartHandle ? connectionPointId1 : connectionPointId2;
        KoConnectionPoint::EscapeDirection ed = attachedShape->connectionPoint(connectionPointId).escapeDirection;
        if (ed == KoConnectionPoint::AllDirections) {
            QPointF handlePoint = q->shapeToDocument(handles[handleId]);
            QPointF centerPoint = attachedShape->absolutePosition(KoFlake::CenteredPosition);

            /*
             * Determine the best escape direction from the position of the handle point
             * and the position and orientation of the attached shape.
             * The idea is to define 4 sectors, one for each edge of the attached shape.
             * Each sector starts at the center point of the attached shape and has it
             * left and right edge going through the two points which define the edge.
             * Then we check which sector contains our handle point, for which we can
             * simply calculate the corresponding direction which is orthogonal to the
             * corresponding bounding box edge.
             * From that we derive the escape direction from looking at the main coordinate
             * of the orthogonal direction.
             */
            // define our edge points in the right order
            const KoFlake::Position corners[4] = {
                KoFlake::BottomRightCorner,
                KoFlake::BottomLeftCorner,
                KoFlake::TopLeftCorner,
                KoFlake::TopRightCorner
            };

            QPointF vHandle = handlePoint-centerPoint;
            for (int i = 0; i < 4; ++i) {
                // first point of bounding box edge
                QPointF p1 = attachedShape->absolutePosition(corners[i]);
                // second point of bounding box edge
                QPointF p2 = attachedShape->absolutePosition(corners[(i+1)%4]);
                // check on which side of the first sector edge our second sector edge is
                const qreal c0 = crossProd(p1-centerPoint, p2-centerPoint);
                // check on which side of the first sector edge our handle point is
                const qreal c1 = crossProd(p1-centerPoint, vHandle);
                // second egde and handle point must be on the same side of first edge
                if ((c0 < 0 && c1 > 0) || (c0 > 0 && c1 < 0))
                    continue;
                // check on which side of the handle point our second sector edge is
                const qreal c2 = crossProd(vHandle, p2-centerPoint);
                // second edge must be on the same side of the handle point as on first edge
                if ((c0 < 0 && c2 > 0) || (c0 > 0 && c2 < 0))
                    continue;
                // now we found the correct edge
                QPointF vDir = 0.5 *(p1+p2) - centerPoint;
                // look at coordinate with the greatest absolute value
                // and construct our escape direction accordingly
                const qreal xabs = qAbs<qreal>(vDir.x());
                const qreal yabs = qAbs<qreal>(vDir.y());
                if (xabs > yabs) {
                    direction.rx() = vDir.x() > 0 ? 1.0 : -1.0;
                    direction.ry() = 0.0;
                } else {
                    direction.rx() = 0.0;
                    direction.ry() = vDir.y() > 0 ? 1.0 : -1.0;
                }
                break;
            }
        } else if (ed == KoConnectionPoint::HorizontalDirections) {
            QPointF handlePoint = q->shapeToDocument(handles[handleId]);
            QPointF centerPoint = attachedShape->absolutePosition(KoFlake::CenteredPosition);
            // use horizontal direction pointing away from center point
            if (handlePoint.x() < centerPoint.x())
                direction = QPointF(-1.0, 0.0);
            else
                direction = QPointF(1.0, 0.0);
        } else if (ed == KoConnectionPoint::VerticalDirections) {
            QPointF handlePoint = q->shapeToDocument(handles[handleId]);
            QPointF centerPoint = attachedShape->absolutePosition(KoFlake::CenteredPosition);
            // use vertical direction pointing away from center point
            if (handlePoint.y() < centerPoint.y())
                direction = QPointF(0.0, -1.0);
            else
                direction = QPointF(0.0, 1.0);
        } else if (ed == KoConnectionPoint::LeftDirection) {
            direction = QPointF(-1.0, 0.0);
        } else if (ed == KoConnectionPoint::RightDirection) {
            direction = QPointF(1.0, 0.0);
        } else if (ed == KoConnectionPoint::UpDirection) {
            direction = QPointF(0.0, -1.0);
        } else if (ed == KoConnectionPoint::DownDirection) {
            direction = QPointF(0.0, 1.0);
        }

        // transform escape direction by using our own transformation matrix
        QTransform invMatrix = q->absoluteTransformation(0).inverted();
        direction = invMatrix.map(direction) - invMatrix.map(QPointF());
        direction /= sqrt(direction.x() * direction.x() + direction.y() * direction.y());
    }

    return direction;
}
Beispiel #11
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    server(BUFSIZE + 1, this),
    client(BUFSIZE + 1, this)
{
    setMenuBar(new QMenuBar(this));
    QMenu *gameMenu = new QMenu("Game", menuBar());
    createAction = new QAction("Create", gameMenu);
    createAction->setIcon(QIcon(":/create.icns"));
    joinAction = new QAction("Join in", gameMenu);
    joinAction->setIcon(QIcon(":/join.icns"));
    abortAction = new QAction("Abort", gameMenu);
    abortAction->setIcon(QIcon(":/abort.icns"));
    menuBar()->addMenu(gameMenu);
    gameMenu->addAction(createAction);
    gameMenu->addAction(joinAction);
    gameMenu->addAction(abortAction);
    QToolBar *toolbar = new QToolBar(this);
    toolbar->setMovable(0);
    addToolBar(Qt::LeftToolBarArea, toolbar);
    toolbar->addAction(createAction);
    toolbar->addAction(joinAction);
    toolbar->addAction(abortAction);
    abortAction->setEnabled(0);

    setStatusBar(new QStatusBar(this));


    setCentralWidget(new QWidget(this));
    QHBoxLayout *mainLayout = new QHBoxLayout();
    centralWidget()->setLayout(mainLayout);

    chessBoard = new ChessBoard(centralWidget());
    mainLayout->addWidget(chessBoard);

    opp = new UserWidget(this);
    loc = new UserWidget(this);
    oppName = new QLabel(this);
    locName = new QLabel(this);
    QVBoxLayout *rightLayout = new QVBoxLayout();
    mainLayout->addLayout(rightLayout);

    rightLayout->addWidget(opp);
    rightLayout->addWidget(oppName);
    startButton = new QPushButton("Start", this);
    startButton->setEnabled(0);
    rightLayout->addWidget(startButton);
    tieButton = new QPushButton("Tie", this);
    tieButton->setEnabled(0);
    rightLayout->addWidget(tieButton);
    surButton = new QPushButton("Surrender", this);
    surButton->setEnabled(0);
    rightLayout->addWidget(surButton);
    rightLayout->addWidget(tieButton);

    number = new QLCDNumber(this);
    rightLayout->addWidget(number);
    rightLayout->addWidget(loc);
    rightLayout->addWidget(locName);
    tieTimer.setSingleShot(1);
    //TODO rightLayout for some information


    QObject::connect(createAction, SIGNAL(triggered()), this, SLOT(createGame()));
    QObject::connect(joinAction, SIGNAL(triggered()), this, SLOT(joinGame()));
    QObject::connect(abortAction, SIGNAL(triggered()), this, SLOT(abortLink()));
    QObject::connect(chessBoard, SIGNAL(clickPiece(QPair<int,int>)), this, SLOT(handleClick(QPair<int, int>)));
    QObject::connect(&server, SIGNAL(received(void*, int)), this, SLOT(handleReceive(void*, int)));
    QObject::connect(&server, SIGNAL(connected()), this, SLOT(handleConnected()));
    QObject::connect(&client, SIGNAL(received(void*,int)), this, SLOT(handleReceive(void*, int)));
    QObject::connect(startButton, SIGNAL(clicked()), this, SLOT(startGame()));
    QObject::connect(&tieTimer, SIGNAL(timeout()), this, SLOT(enableTie()));
    QObject::connect(tieButton, SIGNAL(clicked()), this, SLOT(handleTie()));
    QObject::connect(surButton, SIGNAL(clicked()), this, SLOT(abortLink()));
    QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeOut()));
}