/* * This file contains minor utility functions */ #ifndef UTILS_H #define UTILS_H #include #include #include #include #include bool checkInternetConnection(QUrl url) { QNetworkAccessManager nam; QNetworkRequest req(url); QNetworkReply* reply = nam.get(req); QEventLoop loop; QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); QTimer request_timeout_timer; QObject::connect(&request_timeout_timer, &QTimer::timeout, &loop, &QEventLoop::quit); request_timeout_timer.start(5000); // 5 seconds connection timeout qDebug() << "LOLOLOLOL"; loop.exec(); qDebug() << "END OF LOLOLOLOLO"; return reply->bytesAvailable(); } void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QString message_type; switch (type) { case QtDebugMsg: message_type = "[DEBG]"; break; case QtInfoMsg: message_type = "[INFO]"; break; case QtWarningMsg: message_type = "[WARN]"; break; case QtCriticalMsg: message_type = "[CRIT]"; break; case QtFatalMsg: message_type = "[FATL]"; break; default: message_type = "[UNKN]"; break; } QString filename = context.category; QString function = context.function; QString line_number = QString::number(context.line); QString s = QString("%1: %2 ||| %3:%4 %5\n") .arg(message_type) .arg(msg) .arg(filename) .arg(line_number) .arg(function); #ifdef QT_DEBUG QFile log_file("legacy_v2.log"); log_file.open(QIODevice::ReadWrite | QIODevice::Append); QTextStream stream(&log_file); stream << s; log_file.close(); #endif fprintf(stderr, "%s", qUtf8Printable(s)); fflush(stderr); } #endif // UTILS_H