diff --git a/src/updater/formupdater.cpp b/src/updater/formupdater.cpp index 4bf224fb7..7405e602c 100644 --- a/src/updater/formupdater.cpp +++ b/src/updater/formupdater.cpp @@ -19,12 +19,17 @@ #include +FormUpdater *FormUpdater::s_instance; + FormUpdater::FormUpdater(QWidget *parent) : QMainWindow(parent, Qt::Dialog | Qt::WindowStaysOnTopHint), m_state(NoState), m_txtOutput(new QTextEdit(this)), m_parsedArguments(QHash()) { + // Initialize singleton. + s_instance = this; + m_txtOutput->setAutoFormatting(QTextEdit::AutoNone); m_txtOutput->setAcceptRichText(true); m_txtOutput->setFontPointSize(10.0); @@ -47,6 +52,8 @@ FormUpdater::~FormUpdater() { } void FormUpdater::startUpgrade() { + qDebug("Started..."); + printHeading("Welcome to RSS Guard updater"); printText("Analyzing updater arguments."); @@ -101,6 +108,70 @@ void FormUpdater::executeMainApplication() { } } + +#if QT_VERSION >= 0x050000 +void FormUpdater::debugHandler(QtMsgType type, + const QMessageLogContext &placement, + const QString &message) { +#ifndef QT_NO_DEBUG_OUTPUT + Q_UNUSED(placement) + + switch (type) { + case QtDebugMsg: + s_instance->printText(QString("DEBUG: %1").arg(message)); + break; + + case QtWarningMsg: + s_instance->printText(QString("WARNING: %1").arg(message)); + break; + + case QtCriticalMsg: + s_instance->printText(QString("CRITICAL: %1").arg(message)); + break; + + case QtFatalMsg: + s_instance->printText(QString("FATAL: %1").arg(message)); + qApp->exit(EXIT_FAILURE); + + default: + break; + } +#else + Q_UNUSED(type) + Q_UNUSED(placement) + Q_UNUSED(message) +#endif +} +#else +void FormUpdater::debugHandler(QtMsgType type, const char *message) { +#ifndef QT_NO_DEBUG_OUTPUT + switch (type) { + case QtDebugMsg: + s_instance->printText(QString("DEBUG: %1").arg(message)); + break; + + case QtWarningMsg: + s_instance->printText(QString("WARNING: %1").arg(message)); + break; + + case QtCriticalMsg: + s_instance->printText(QString("CRITICAL: %1").arg(message)); + break; + + case QtFatalMsg: + s_instance->printText(QString("FATAL: %1").arg(message)); + qApp->exit(EXIT_FAILURE); + + default: + break; + } +#else + Q_UNUSED(type) + Q_UNUSED(message) +#endif +} +#endif + void FormUpdater::printArguments() { printNewline(); printHeading("Arguments"); diff --git a/src/updater/formupdater.h b/src/updater/formupdater.h index d2c3f612b..9df7c15f4 100644 --- a/src/updater/formupdater.h +++ b/src/updater/formupdater.h @@ -3,6 +3,7 @@ #include +#include #include @@ -13,6 +14,7 @@ class FormUpdater : public QMainWindow { Q_OBJECT public: + // Describes the state of updater. enum UpdaterState { NoState, ExitNormal, @@ -23,6 +25,11 @@ class FormUpdater : public QMainWindow { explicit FormUpdater(QWidget *parent = 0); virtual ~FormUpdater(); + // Prints various texts. + void printText(const QString &text); + void printNewline(); + void printHeading(const QString &header); + // Starts the whole update process. void startUpgrade(); @@ -35,16 +42,20 @@ class FormUpdater : public QMainWindow { bool doFinalCleanup(); void executeMainApplication(); + // Debug handlers for messages. +#if QT_VERSION >= 0x050000 + static void debugHandler(QtMsgType type, + const QMessageLogContext &placement, + const QString &message); +#else + static void debugHandler(QtMsgType type, + const char *message); +#endif + protected: // Catch the "press any key event" to exit the updater. void keyPressEvent(QKeyEvent *event); - private: - // Prints various texts. - void printText(const QString &text); - void printNewline(); - void printHeading(const QString &header); - // Moves the window into the center of the screen and resizes it. void moveToCenterAndResize(); @@ -57,8 +68,9 @@ class FormUpdater : public QMainWindow { private: UpdaterState m_state; QTextEdit *m_txtOutput; - QHash m_parsedArguments; + + static FormUpdater *s_instance; }; #endif // FORMUPDATER_H diff --git a/src/updater/main.cpp b/src/updater/main.cpp index 5d9963eb2..3fb5b78e3 100644 --- a/src/updater/main.cpp +++ b/src/updater/main.cpp @@ -29,6 +29,7 @@ #include #include + // Main entry point to "rssguard_updater.exe". // It expects 4 ARGUMENTS: // 0) - the actual path of this process, @@ -39,11 +40,13 @@ int main(int argc, char *argv[]) { // Instantiate base application object. QtSingleApplication application(APP_LOW_NAME, argc, argv); - application.setQuitOnLastWindowClosed(true); FormUpdater main_form; + // Setup message handler after main_form is created. + qInstallMessageHandler(FormUpdater::debugHandler); + main_form.show(); main_form.startUpgrade();