<commit_before>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "emptymainloophelper.h"

#include <MTheme>
#include <MComponentData>

#include <QApplication>
#include <QTimer>

#include <MDebug>
#include <QString>

#include <cstdlib>

#ifdef Q_OS_LINUX
#include <sys/time.h>
#endif


EmptyMainLoopHelper::EmptyMainLoopHelper() :
    terminationType( QuitOnEmpty )
{
}

void EmptyMainLoopHelper::triggerTermination(TerminationType type)
{
    terminationType = type;
    QTimer::singleShot(0, this, SLOT(terminateOnEmptyMainLoop()));
}

void EmptyMainLoopHelper::terminateOnEmptyMainLoop()
{
    if (qApp->hasPendingEvents() || MTheme::hasPendingRequests()) {
        QTimer::singleShot(0, this, SLOT(terminateOnEmptyMainLoop()));
    } else {
        QTimer::singleShot(20, this, SLOT(terminateOnEmptyMainLoop2()));
    }
}

void EmptyMainLoopHelper::terminateOnEmptyMainLoop2()
{
    if (qApp->hasPendingEvents()) {
        QTimer::singleShot(0, this, SLOT(terminateOnEmptyMainLoop()));
    } else {
        if (terminationType == ExitOnEmpty) {
            exit(0);
        } else {
#ifdef Q_OS_LINUX
            struct timeval t;
            gettimeofday(&t, 0);

            mDebug("EmptyMainLoopHelper") << QString("%1[%2%3]: quitting")
                   .arg(MComponentData::instance()->appName())
                   .arg((int)t.tv_sec)
                   .arg((int)(t.tv_usec % 1000000), 6, 10, (const QChar)'0');
#endif

            qApp->quit();
        }
    }
}<commit_msg>Fixes: NB#174469 - widgetsgallery -quitimmediately stuck<commit_after>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "emptymainloophelper.h"

#include <MTheme>
#include <MComponentData>

#include <QApplication>
#include <QTimer>

#include <MDebug>
#include <QString>

#include <cstdlib>

#ifdef Q_OS_LINUX
#include <sys/time.h>
#endif


EmptyMainLoopHelper::EmptyMainLoopHelper() :
    terminationType( QuitOnEmpty )
{
}

void EmptyMainLoopHelper::triggerTermination(TerminationType type)
{
    terminationType = type;
    QTimer::singleShot(0, this, SLOT(terminateOnEmptyMainLoop()));
}

void EmptyMainLoopHelper::terminateOnEmptyMainLoop()
{
    qApp->processEvents();
    if (qApp->hasPendingEvents() || MTheme::hasPendingRequests()) {
        QTimer::singleShot(0, this, SLOT(terminateOnEmptyMainLoop()));
    } else {
        QTimer::singleShot(20, this, SLOT(terminateOnEmptyMainLoop2()));
    }
}

void EmptyMainLoopHelper::terminateOnEmptyMainLoop2()
{
    if (qApp->hasPendingEvents()) {
        QTimer::singleShot(0, this, SLOT(terminateOnEmptyMainLoop()));
    } else {
        if (terminationType == ExitOnEmpty) {
            exit(0);
        } else {
#ifdef Q_OS_LINUX
            struct timeval t;
            gettimeofday(&t, 0);

            mDebug("EmptyMainLoopHelper") << QString("%1[%2%3]: quitting")
                   .arg(MComponentData::instance()->appName())
                   .arg((int)t.tv_sec)
                   .arg((int)(t.tv_usec % 1000000), 6, 10, (const QChar)'0');
#endif

            qApp->quit();
        }
    }
}
{'fraction_non_alphanumeric': 0.19148451730418944, 'fraction_numerical': 0.014571948998178506, 'mean_word_length': 3.9248878923766815, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3867836', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1274, 'n_words': 321}