Beispiel #1
0
gboolean timerHandler(Interface *gui) {
    // if application quit or stop time outs is on, return false to stop time out
    if(quitApplication || stopTimeOuts[gui->player - 1] ) {
        stopTimeOuts[gui->player - 1] = 0;
        return FALSE;
    }

    // gets difference between current and start time
    time_t now;
    double timePassed;
    now = time(NULL);
    timePassed = difftime(now, gui->startTime);

    // if not waiting for answer anymore set time to 0 or (if answer was correct) -5
    if(!gui->waitingForAnswer) {
        timePassed = 15;
        if(gui->gotCorrectAnswer) {
            timePassed = 20;
        }
    }

    // update timer
    updateTimerLabel(&(gui->timerLabel), timePassed);

    // if time over stop timeouts
    if(timePassed >= 15) {
        gui->waitingForAnswer = FALSE;
        return FALSE;
    }
    return TRUE;
}
Beispiel #2
0
void startTimer(Interface *gui) {
    // if stop time outs is on but there's no timeout running, set it to false
    if(stopTimeOuts[gui->player - 1] ) {
        stopTimeOuts[gui->player - 1] = 0;
    }
    // sets starting time to current
    gui->startTime = time(NULL);
    
    // starts timeout to update timer every second and updates timerLabel to full time
    g_timeout_add(1000, (GSourceFunc) timerHandler, (gpointer) gui);
    updateTimerLabel(&(gui->timerLabel), 0);
}
Beispiel #3
0
void MainWindow::doKeepalive()
{
    updateTimerLabel();

    if (secondsLeft-- > 0)
        return;

    secondsLeft = this->keepAliveDelay;

    if (ui->btnToggleAfk->isChecked())
        sendMessage(ui->txtAfkMessage->text());
    else
        sendMessage("");
}