Example #1
0
/**
 * SLOT
 * Takes a shot from the local player.
 * Places the shot on the oponents board or send the
 * coordinates through the network.
 * @param index
 */
bool Battleships::playersShoot(const int index)
{
    setLocalePlayersTurn(false);
    addShoot();
    bool isHit = false;
    if (m_playerMode == SinglePlayer) {
        const Ship *hiddenShip = m_foesGameBoard->shootAt(index);
        if (hiddenShip) {
            setInfoText("You hit one of the ships.");
        } else {
            setInfoText("You shot into the water.");
        }
        if (! m_foesGameBoard->hasUndestroyedShip()) {
            setWinnerName(playerName());
            setCurrentView("GameOverDialog");
        }
        emit botShoot();
    } else {
        m_indexLastShot = index;
        QJsonObject object;
        object.insert("type", "SHOT");
        QJsonObject options;
        QPoint pt = m_foesGameBoard->getPointObject(index);
        options.insert("x", pt.x());
        options.insert("y", pt.y());
        object.insert("options", options);
        QJsonDocument *message = new QJsonDocument(object);
        emit sendMessage(message);
    }

    return isHit;
}
void IqHelpViewerMainWindow::showPage(const QUrl &url)
{
    qDebug() << tr("Show page \"%0\".")
                .arg(url.toString());
    IqHelpViewWidget *view = NULL;

    if (m_currentView && m_currentView->canShowPage(url)) {
        view = m_currentView;
    }
    else {
        foreach (IqHelpViewWidget *viewCandidate, m_helpViewWidgets) {
            if (!viewCandidate)
                continue;
            if (!viewCandidate->canShowPage(url))
                continue;

            view = viewCandidate;
            break;
        }
    }

    if (view) {
        setCurrentView(view);

        if (view->url() != url) {
            m_urlLineEdit->setText(url.toString());

            view->showPage(url);
        }
    }
}
Example #3
0
/**
 * Got a finished message over network.
 * Interpret the reason.
 * @param object
 */
void Battleships::finishedMessage(const QJsonObject &object)
{
    QJsonObject options = object.value("options").toObject();
    if (options.value("reason") == "won") {
        setInfoText("You have won the game.");
        setWinnerName(m_playerName);
        setCurrentView("GameOverDialog");
    }
    else if (options.value("reason") == "quit") {
        setWinnerName("No one");
        setCurrentView("GameOverDialog");
    }
    else if (options.value("reason") == "error") {
        // Error ?
    }
    emit closeConnection();
}
void WlanSnifferMainWindow::toListView(const QString &title)
{
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_TOLISTVIEW_ENTRY);
    
    // Show the list view
    mListView->setTitle(title);
    setCurrentView(mListView);
    show();

    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_TOLISTVIEW_EXIT);
}
Example #5
0
/**
 * Got a game offer replay.
 * If game offer was accepted the game can start.
 * If not accepted ?
 * @param object
 */
void Battleships::gameOfferReplay(const QJsonObject &object)
{
    QJsonObject options = object.value("options").toObject();
    QString name = options.value("player_name").toString();
    bool accepted = options.value("success").toBool();
    if (accepted) {
        m_foesGameBoard->setPlayerName(name);
        setLocalePlayersTurn(true);
        setCurrentView("GamePlayDialog");
    }
}
Example #6
0
/**
 * Got a game offer.
 * Show terms of game offer on screen and ask the player
 * to accept it.
 * @param object
 */
void Battleships::takeGameOffer(const QJsonObject &object)
{
    QJsonObject options = object.value("options").toObject();
    QStringList list;
    list << options.value("player_name").toString();
    list << options.value("board_size_x").toString();
    list << options.value("board_size_y").toString();
    list << options.value("ships_present").toString();
    setGameOfferValueList(list);
    setCurrentView("GameOfferView");
}
Example #7
0
void DangerScene::changeMode (int mode) {
	
	modeToGo = mode;
	fade();
	return;
	
	
	if ( mode == currentMode ) return;
	currentMode = mode;
	setCurrentView(currentView);
	if ( mode == DGSCENEVIEWMODE_VIDEOS ) videoView.init();
	
}
Example #8
0
/**
 * Simulates a bot behaviour. Shoots randomly to the locale
 * players game board.
 * @return          True if bot hit a ship.
 */
bool Battleships::botShoot()
{
    ShipPosition position = getRandomShipPosition(m_playersGameBoard->getGameBoardSize());
    const Ship* hiddenShip = m_playersGameBoard->shoot(position.x, position.y);
    if (hiddenShip != 0) {
        setInfoText("One of your ships is hidden.");
    } else {
        setInfoText("Foe shot into the water.");
    }
    if (! m_playersGameBoard->hasUndestroyedShip()) {
        setWinnerName("Foe");
        setCurrentView("GameOverDialog");
    }
    setLocalePlayersTurn(true);

    return (hiddenShip != 0);
}
bool DFileManagerWindowPrivate::cdForTab(Tab *tab, const DUrl &fileUrl)
{
    Q_Q(DFileManagerWindow);

    DFMBaseView *current_view = tab->fileView();

    if (current_view && current_view->rootUrl() == fileUrl) {
        return false;
    }

    // old mount scheme support... may get removed when no other place use this...
    if (fileUrl.scheme() == "mount") {
        DUrl newUrl;
        QUrlQuery query(fileUrl);

        if (query.hasQueryItem("id")) {
            newUrl.setQuery(query.queryItemValue("id"));
            appController->actionOpenDisk(dMakeEventPointer<DFMUrlBaseEvent>(q_ptr, newUrl));

            return true;
        }
    }

    if (!current_view || !DFMViewManager::instance()->isSuited(fileUrl, current_view)) {
        DFMBaseView *view = DFMViewManager::instance()->createViewByUrl(fileUrl);

        if (view) {
            viewStackLayout->addWidget(view->widget());

            if (tab == tabBar->currentTab())
                viewStackLayout->setCurrentWidget(view->widget());

            q_ptr->handleNewView(view);
        } else {
            qWarning() << "Not support url: " << fileUrl;

            //###(zccrs):
            const DAbstractFileInfoPointer &fileInfo = DFileService::instance()->createFileInfo(q_ptr, fileUrl);

            if (fileInfo) {
                /* Call fileInfo->exists() twice. First result is false and the second one is true;
                           Maybe this is a bug of fuse when smb://10.0.10.30/people is mounted and cd to mounted folder immediately.
                        */
                qDebug() << fileInfo->exists() << fileUrl;
                qDebug() << fileInfo->exists() << fileUrl;
            }

            if (!fileInfo || !fileInfo->exists()) {
                DUrl searchUrl = current_view->rootUrl();

                if (searchUrl.isComputerFile()) {
                    searchUrl = DUrl::fromLocalFile("/");
                }

                if (searchUrl.isSearchFile()) {
                    searchUrl = searchUrl.searchTargetUrl();
                }

                if (!q_ptr->isCurrentUrlSupportSearch(searchUrl)) {
                    return false;
                }

                const DUrl &newUrl = DUrl::fromSearchFile(searchUrl, fileUrl.toString());
                const DAbstractFileInfoPointer &fileInfo = DFileService::instance()->createFileInfo(q_ptr, newUrl);

                if (!fileInfo || !fileInfo->exists()) {
                    return false;
                }

                return cdForTab(tab, newUrl);
            }

            return false;
        }

        if (current_view) {
            current_view->deleteLater();
        }

        tab->setFileView(view);

        if (tab == tabBar->currentTab())
            setCurrentView(view);

        current_view = view;
    }

    bool ok = false;

    if (current_view) {
        ok = current_view->setRootUrl(fileUrl);

        if (ok) {
            tab->onFileRootUrlChanged(fileUrl);

            if (tab == tabBar->currentTab()) {
                emit q_ptr->currentUrlChanged();
            }
        }
    }

    return ok;
}
Example #10
0
NavigationBar::~NavigationBar()
{
    setCurrentView(nullptr);
}
void IAUpdateMainWindow::toSettingView()
{
    setCurrentView(mSettingView);
}
// Slots to handle view change
void IAUpdateMainWindow::toMainView()
{
    setCurrentView(mMainView);
}
Example #13
0
/**
 * SLOT
 * Is called when a network error occures.
 * @param error
 */
void Battleships::networkConnectionError(const QString &error)
{
    m_networkConnectionError = error;
    emit networkErrorChanged();
    setCurrentView("NetworkErrorDialog");
}