Hmmmm.
This commit is contained in:
parent
b35d10f319
commit
3d320bbaf1
@ -19,12 +19,17 @@
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
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<QString, QString>()) {
|
||||
|
||||
// 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");
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QHash>
|
||||
|
||||
|
||||
@ -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<QString, QString> m_parsedArguments;
|
||||
|
||||
static FormUpdater *s_instance;
|
||||
};
|
||||
|
||||
#endif // FORMUPDATER_H
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
|
||||
// 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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user