Beispiel #1
0
void PCapThread::slotStart(const QString &devDesc)
{
    /* Start the poll timer, kBps update timer, and the elapsed timer */
    spTimer_ = QSharedPointer<QTimer>(new QTimer);
    spTimer_->setInterval(0);
    spkBpsTimer_ = QSharedPointer<QTimer>(new QTimer);
    spkBpsTimer_->setInterval(500);
    spElapsed_ = QSharedPointer<QElapsedTimer>(new QElapsedTimer);
    connect(spTimer_.data(), SIGNAL(timeout()), this, SLOT(slotPoll()) );
    connect(spkBpsTimer_.data(), SIGNAL(timeout()), this, SLOT(slotKbps()) );
    std::string errmsg;
    std::map<std::string, std::string>::iterator it;
    if ( devMap_.end() == ( it = devMap_.find( devDesc.toUtf8().constData() ) ) )
    {
        emit sigError("Device not found");
        emit sigDone();
    }   
    else if ( spPCapImpl_->init(it->second, errmsg) )
    {   
        emit sigError("Error initializing " + devDesc + " " + QString::fromStdString(errmsg) ); 
        emit sigDone();
    }
    else
    {
        spkBpsTimer_->start();
        spElapsed_->start();
        spTimer_->start();
    }
}
Beispiel #2
0
void UIPopupPane::done(int iResultCode)
{
    /* Close the window: */
    close();

    /* Was the popup auto-confirmed? */
    if (m_pTextPane->isAutoConfirmed())
        iResultCode |= AlertOption_AutoConfirmed;

    /* Notify listeners: */
    emit sigDone(iResultCode);
}
Beispiel #3
0
void PCapThread::slotStop()
{
    /* Stop the two timers and disconnect their signals */
    spTimer_->stop();
    spkBpsTimer_->stop();
    if ( !disconnect(spTimer_.data(), SIGNAL(timeout()), this, SLOT(slotPoll())) )
        emit sigError("Error Disconnecting timer slot");
    if (!disconnect(spkBpsTimer_.data(), SIGNAL(timeout()), this, SLOT(slotKbps())) )
        emit sigError("Error Disconnecting kBps slot");
    spPCapImpl_->shutDown();
    emit sigDone();
}
Beispiel #4
0
void PCapThread::slotPoll()
{
    /* Get the next DNS entry string */
    std::string pktStr;
    int ret = spPCapImpl_->getNextPacket(pktStr);
    if ( 0 > ret )
    {
        emit sigError("Error reading from interface");
        spTimer_->stop();
        emit sigDone();
    }
    else if ( 0 < ret && !pktStr.empty() )
    {
        QString qStr =  QString::fromStdString(pktStr);
        emit sigDataReady(qStr);
    }
}
void UIPopupPane::done(int iResultCode)
{
    /* Notify listeners: */
    emit sigDone(iResultCode);
}
// Constructor
Battleship::Battleship(QWidget *parent) : QMainWindow(parent)
{
	QApplication::setStyle("plastique");
	setupUi(this);
	gridLayoutHuman->sizePolicy().setHeightForWidth(true);
	gridLayoutEnemy->sizePolicy().setHeightForWidth(true);
	labelStatus = new QLabel(QString::fromUtf8("Press Ön to start the Game"), statusbar);
	statusbar->setSizeGripEnabled(true);
	statusbar->addWidget(labelStatus, 3);
	imageDialog = new ImageDialog(this);
	alignment = h;	// set default alignment
	enemyPlayer = new AI(enemy, this);		// Create players and their fields
	setupField(enemyPlayer);
	humanPlayer = new Human(human, this);
	setupField(humanPlayer);

	round = 0;		// for first round

	gridLayoutHuman->installEventFilter(this);	// EventFilter for right mouse button

	gridLayoutEnemy->setCursor(QCursor(Qt::ForbiddenCursor));
	gridLayoutHuman->setCursor(QCursor(Qt::ForbiddenCursor));


	// Buttons:
	connect(pushButtonEwo, SIGNAL(toggled(bool)), this, SLOT(slotSetEwoMode(bool)));
	connect(pushButtonStartGame, SIGNAL(clicked()), this, SLOT(slotStartGame()));

	// Place fleet & ships
	connect(this, SIGNAL(sigHumanPlaceShip(int, int, int)), humanPlayer, SLOT(slotPlaceShip(int, int, int)));
	connect(this, SIGNAL(sigPlaceFleet()), humanPlayer, SLOT(slotPlaceFleet()));
	connect(this, SIGNAL(sigPlaceFleet()), enemyPlayer, SLOT(slotPlaceFleet()));
	connect(humanPlayer, SIGNAL(sigFleetComplete()), this, SLOT(slotPlayerReady()));
	connect(enemyPlayer, SIGNAL(sigFleetComplete()), this, SLOT(slotPlayerReady()));

	// players get shot
	connect(this, SIGNAL(sigShotAtEnemy(int, int)), enemyPlayer, SLOT(slotShotAt(int, int)));
	connect(enemyPlayer, SIGNAL(sigShotAtHuman(int, int)), humanPlayer, SLOT(slotShotAt(int, int)));

	// toggle player turn
	connect(enemyPlayer, SIGNAL(sigDone(PlayerT)), this, SLOT(slotPlayerTurn(PlayerT)));
	connect(humanPlayer, SIGNAL(sigDone(PlayerT)), this, SLOT(slotPlayerTurn(PlayerT)));

	// AI shall shoot
	connect(this, SIGNAL(sigRequestShotFromEnemy()), enemyPlayer, SLOT(slotFire()));
	connect(humanPlayer, SIGNAL(sigEnemyTryAgain()), this, SLOT(slotRequestShotNow()));

	//Feedback of shots for AI
	connect(humanPlayer, SIGNAL(sigFireFeedback(int, int, ConditionT)), enemyPlayer, SLOT(slotFireFeedback(int, int, ConditionT)));

	// Game Over
	connect(enemyPlayer, SIGNAL(sigGameOver(PlayerT)), this, SLOT(slotGameOver(PlayerT)));
	connect(humanPlayer, SIGNAL(sigGameOver(PlayerT)), this, SLOT(slotGameOver(PlayerT)));

	// console output
	connect(humanPlayer, SIGNAL(sigPrint(QString)), this, SLOT(slotPrintToConsole(QString)));
	connect(enemyPlayer, SIGNAL(sigPrint(QString)), this, SLOT(slotPrintToConsole(QString)));

	//sound output
	connect(humanPlayer, SIGNAL(sigPlaySound(QString)), this, SLOT(slotPlaySound(QString)));
	connect(enemyPlayer, SIGNAL(sigPlaySound(QString)), this, SLOT(slotPlaySound(QString)));
	connect(humanPlayer, SIGNAL(sigPlayDelayedSound(QString, int)), this, SLOT(slotPlayDelayedSound(QString, int)));
	connect(enemyPlayer, SIGNAL(sigPlayDelayedSound(QString, int)), this, SLOT(slotPlayDelayedSound(QString, int)));

	// help menu -> display info
	infoDialog = new InfoDialog(this);
	connect(actionManual, SIGNAL(triggered()), infoDialog, SLOT(slotLoadTutorial()));
	connect(actionAbout, SIGNAL(triggered()), infoDialog, SLOT(slotLoadAbout()));
	connect(actionLicense, SIGNAL(triggered()), infoDialog, SLOT(slotLoadLicense()));

	//options menu
	connect(actionSound_on, SIGNAL(triggered()), this, SLOT(slotSoundOn()));

	if(QSound::isAvailable()) {
		soundAvailable = true;
		soundOn = true;
		slotPrintToConsole("Sound is availiable\n");
	} else {
		soundAvailable = false;
		soundOn = false;
		slotPrintToConsole("Sound is not availiable\n");
	}
}
Beispiel #7
0
void
NwReqTracker::onReplyFinished()
{
    replyTimer.stop ();

    bool rv = false, done = false;
    QByteArray response;
    QNetworkReply *origReply = reply;

    do { // Begin cleanup block (not a loop)
        if (aborted) {
            Q_WARN("Reply was aborted");
            break;
        }

        if (QNetworkReply::NoError != origReply->error ()) {
            Q_WARN("Response error: ") << origReply->errorString ();
            break;
        }

        response = origReply->readAll ();
        rv = true;
    } while (0); // End cleanup block (not a loop)

    do { // Begin cleanup block (not a loop)
        done = true;

        if (!rv) {
            break;
        }

        if (!autoRedirect) {
            break;
        }

        QUrl urlMoved = hasMoved (origReply);
        if (urlMoved.isEmpty ()) {
            break;
        }

        QNetworkRequest req(urlMoved);
        req.setRawHeader("User-Agent", uaString);

        NwReqTracker::setCookies (jar, req);
        QNetworkReply *nextReply = nwMgr.get(req);
        if (!nextReply) {
            break;
        }

        disconnectReply ();
        init (nextReply, ctx, emitLog, autoDelete);
        autoRedirect = true;

        done = false;
    } while (0); // End cleanup block (not a loop)

    if (done) {
        if (!autoRedirect && response.contains ("Moved Temporarily")) {
            QString msg = "Auto-redirect not requested, but page content "
                          "probably indicates that this page has been "
                          "temporarily moved. Original request = %1";

            msg = msg.arg (origReply->request().url().toString ());

            QString strResp = response;
            int pos = strResp.indexOf ("a href=", 0, Qt::CaseInsensitive);
            if (-1 != pos) {
                int endpos = strResp.indexOf ("</a>", pos, Qt::CaseInsensitive);
                if (-1 != endpos) {
                    msg += "\nRedirect URL = " + strResp.mid(pos+8, endpos-pos);
                }
            }

            Q_WARN(msg);
        }

        emit sigDone (rv, response, origReply, ctx);
    }

    origReply->deleteLater ();
    if (done && autoDelete) {
        this->deleteLater ();
    }
}//NwReqTracker::onReplyFinished