Skip to content

Commit

Permalink
Merge pull request cryptonotefoundation#24 from aivve/feature/splash_log
Browse files Browse the repository at this point in the history
Display on splash screen what's going on while loading
  • Loading branch information
aivve authored Dec 30, 2019
2 parents e59c691 + 05b8c5a commit 4cb4b89
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 2 deletions.
57 changes: 57 additions & 0 deletions src/LogFileWatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2015-2017, The Bytecoin developers
// Copyright (c) 2017-2018, The Karbo developers
//
// This file is part of Karbo.
//
// Karbovanets is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Karbovanets is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Karbovanets. If not, see <http://www.gnu.org/licenses/>.

#include <QFile>
#include <QFileSystemWatcher>
#include <QTextStream>
#include <QTimerEvent>

#include "LogFileWatcher.h"

namespace WalletGui {

LogFileWatcher::LogFileWatcher(const QString& _fileName, QObject* _parent) : QObject(_parent),
m_logFile(new QFile(_fileName, this)) {
if (m_logFile->open(QFile::ReadOnly | QFile::Text)) {
m_logFile->seek(m_logFile->size());
m_fileCheckTimer = startTimer(300);
}
}

LogFileWatcher::~LogFileWatcher() {
}

void LogFileWatcher::timerEvent(QTimerEvent* _event) {
if (_event->timerId() == m_fileCheckTimer) {
if (!m_logFile->atEnd()) {
fileChanged();
}
}

QObject::timerEvent(_event);
}

void LogFileWatcher::fileChanged() {
QTextStream stream(m_logFile);
while(!stream.atEnd()) {
QString line = stream.readLine();
Q_EMIT newLogStringSignal(line);
}
}

}
49 changes: 49 additions & 0 deletions src/LogFileWatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2015-2017, The Bytecoin developers
// Copyright (c) 2017-2018, The Karbo developers
//
// This file is part of Karbo.
//
// Karbovanets is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Karbovanets is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Karbovanets. If not, see <http://www.gnu.org/licenses/>.

#pragma once

#include <QObject>

class QFile;
class QFileSystemWatcher;

namespace WalletGui {

class LogFileWatcher : public QObject {
Q_OBJECT
Q_DISABLE_COPY(LogFileWatcher)

public:
LogFileWatcher(const QString& _filePath, QObject* _parent);
~LogFileWatcher();

protected:
void timerEvent(QTimerEvent* _event) override;

private:
int m_fileCheckTimer;
QFile* m_logFile;

void fileChanged();

Q_SIGNALS:
void newLogStringSignal(const QString& _string);
};

}
38 changes: 36 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2011-2015 The Cryptonote developers
// Copyright (c) 2016-2017 The Karbowanec developers
// Copyright (c) 2016-2020 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <QApplication>
Expand All @@ -9,6 +9,7 @@
#include <QLockFile>
#include <QMessageBox>
#include <QProcess>
#include <QRegularExpression>
#include <QSplashScreen>
#include <QStyleFactory>
#include <QSettings>
Expand All @@ -25,11 +26,24 @@
#include "Update.h"
#include "PaymentServer.h"
#include "TranslatorManager.h"
#include "LogFileWatcher.h"

#define DEBUG 1

using namespace WalletGui;

const QRegularExpression LOG_SPLASH_REG_EXP("\\] ");

QSplashScreen* splash(nullptr);

inline void newLogString(const QString& _string) {
QRegularExpressionMatch match = LOG_SPLASH_REG_EXP.match(_string);
if (match.hasMatch()) {
QString message = _string.mid(match.capturedEnd());
splash->showMessage(message, Qt::AlignLeft | Qt::AlignBottom, Qt::white);
}
}

int main(int argc, char* argv[]) {

QApplication app(argc, argv);
Expand Down Expand Up @@ -111,22 +125,42 @@ int main(int argc, char* argv[]) {
SignalHandler::instance().init();
QObject::connect(&SignalHandler::instance(), &SignalHandler::quitSignal, &app, &QApplication::quit);

QSplashScreen* splash = new QSplashScreen(QPixmap(":images/splash"), /*Qt::WindowStaysOnTopHint |*/ Qt::X11BypassWindowManagerHint);
if (splash == nullptr) {
splash = new QSplashScreen(QPixmap(":images/splash"), Qt::X11BypassWindowManagerHint);
}

if (!splash->isVisible()) {
splash->show();
}

splash->showMessage(QObject::tr("Loading blockchain..."), Qt::AlignLeft | Qt::AlignBottom, Qt::white);

LogFileWatcher* logWatcher(nullptr);
if (logWatcher == nullptr) {
logWatcher = new LogFileWatcher(Settings::instance().getDataDir().absoluteFilePath(QCoreApplication::applicationName() + ".log"), &app);
QObject::connect(logWatcher, &LogFileWatcher::newLogStringSignal, &app, &newLogString);
}

app.processEvents();
qRegisterMetaType<CryptoNote::TransactionId>("CryptoNote::TransactionId");
qRegisterMetaType<quintptr>("quintptr");
if (!NodeAdapter::instance().init()) {
return 0;
}

splash->finish(&MainWindow::instance());

if (logWatcher != nullptr) {
logWatcher->deleteLater();
logWatcher = nullptr;
}

splash->deleteLater();
splash = nullptr;

Updater *d = new Updater();
d->checkForUpdate();

MainWindow::instance().show();
WalletAdapter::instance().open("");

Expand Down

0 comments on commit 4cb4b89

Please sign in to comment.