X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtuiapplication.cpp;h=e5b0b773675cb270178669ffa526c67fc0784f39;hp=73e67b294fce4f7a88c2fc9a6b3c6a4096885a69;hb=a65f42197839da536975b3e2858eedcef420035f;hpb=a49af6149b21e0aaf717fc827c55a2c43a2fd778 diff --git a/src/qtui/qtuiapplication.cpp b/src/qtui/qtuiapplication.cpp index 73e67b29..e5b0b773 100644 --- a/src/qtui/qtuiapplication.cpp +++ b/src/qtui/qtuiapplication.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,19 +20,21 @@ #include "qtuiapplication.h" -#include #include +#include #include #ifdef HAVE_KDE4 # include #endif -#include "client.h" +#include "chatviewsettings.h" #include "cliparser.h" +#include "logmessage.h" #include "mainwin.h" #include "qtui.h" #include "qtuisettings.h" +#include "types.h" QtUiApplication::QtUiApplication(int &argc, char **argv) #ifdef HAVE_KDE4 @@ -80,16 +82,9 @@ QtUiApplication::QtUiApplication(int &argc, char **argv) #endif /* HAVE_KDE4 */ -#if defined(HAVE_KDE4) || defined(Q_OS_MAC) - Quassel::disableCrashHandler(); -#endif /* HAVE_KDE4 || Q_OS_MAC */ - Quassel::setRunMode(Quassel::ClientOnly); -#if QT_VERSION < 0x050000 - qInstallMsgHandler(Client::logMessage); -#else - qInstallMessageHandler(Client::logMessage); +#if QT_VERSION >= 0x050000 connect(this, &QGuiApplication::commitDataRequest, this, &QtUiApplication::commitData, Qt::DirectConnection); connect(this, &QGuiApplication::saveStateRequest, this, &QtUiApplication::saveState, Qt::DirectConnection); #endif @@ -100,70 +95,47 @@ QtUiApplication::QtUiApplication(int &argc, char **argv) } -bool QtUiApplication::init() +void QtUiApplication::init() { - if (Quassel::init()) { - // Settings upgrade/downgrade handling - if (!migrateSettings()) { - qCritical() << "Could not load or upgrade client settings, terminating!"; - return false; - } - - // Checking if settings Icon Theme is valid - QString savedIcontheme = QtUiSettings().value("IconTheme", QVariant("")).toString(); -#ifndef WITH_OXYGEN - if (savedIcontheme == "oxygen") - QtUiSettings().remove("IconTheme"); -#endif -#ifndef WITH_BREEZE - if (savedIcontheme == "breeze") - QtUiSettings().remove("IconTheme"); -#endif -#ifndef WITH_BREEZE_DARK - if (savedIcontheme == "breezedark") - QtUiSettings().remove("IconTheme"); -#endif - - // Set the icon theme - if (Quassel::isOptionSet("icontheme")) - QIcon::setThemeName(Quassel::optionValue("icontheme")); - else if (QtUiSettings().value("IconTheme", QVariant("")).toString() != "") - QIcon::setThemeName(QtUiSettings().value("IconTheme").toString()); - else if (QIcon::themeName().isEmpty()) - // Some platforms don't set a default icon theme; chances are we can find our bundled theme though - QIcon::setThemeName("breeze"); - - Client::init(new QtUi()); - - // Init UI only after the event loop has started - // TODO Qt5: Make this a lambda - QTimer::singleShot(0, this, SLOT(initUi())); - - Quassel::registerQuitHandler([]() { - QtUi::mainWindow()->quit(); - }); - + if (!Quassel::init()) { + throw ExitException{EXIT_FAILURE, tr("Could not initialize Quassel!")}; + } - return true; + // Settings upgrade/downgrade handling + if (!migrateSettings()) { + throw ExitException{EXIT_FAILURE, tr("Could not load or upgrade client settings!")}; } - return false; -} + _client.reset(new Client(std::unique_ptr(new QtUi()))); // TODO C++14: std::make_unique -QtUiApplication::~QtUiApplication() -{ - Client::destroy(); - Quassel::destroy(); + // Init UI only after the event loop has started + // TODO Qt5: Make this a lambda + QTimer::singleShot(0, this, SLOT(initUi())); } void QtUiApplication::initUi() { QtUi::instance()->init(); + + // Needs to happen after UI init, so the MainWin quit handler is registered first + Quassel::registerQuitHandler(quitHandler()); + resumeSessionIfPossible(); } +Quassel::QuitHandler QtUiApplication::quitHandler() +{ + // Wait until the Client instance is destroyed before quitting the event loop + return [this]() { + quInfo() << "Client shutting down..."; + connect(_client.get(), SIGNAL(destroyed()), QCoreApplication::instance(), SLOT(quit())); + _client.release()->deleteLater(); + }; +} + + bool QtUiApplication::migrateSettings() { // -------- @@ -183,7 +155,7 @@ bool QtUiApplication::migrateSettings() // // NOTE: If you increase the minor version, you MUST ALSO add new version upgrade logic in // applySettingsMigration()! Otherwise, settings upgrades will fail. - const uint VERSION_MINOR_CURRENT = 8; + const uint VERSION_MINOR_CURRENT = 9; // Stored minor version uint versionMinor = s.versionMinor(); @@ -248,6 +220,25 @@ bool QtUiApplication::applySettingsMigration(QtUiSettings settings, const uint n // saved. Exceptions will be noted below. // NOTE: If you add new upgrade logic here, you MUST ALSO increase VERSION_MINOR_CURRENT in // migrateSettings()! Otherwise, your upgrade logic won't ever be called. + case 9: + { + // New default changes: show highest sender prefix mode, if available + + // -------- + // ChatView settings + ChatViewSettings chatViewSettings; + const QString senderPrefixModeId = "SenderPrefixMode"; + if (!chatViewSettings.valueExists(senderPrefixModeId)) { + // New default is HighestMode, preserve previous behavior by setting to NoModes + chatViewSettings.setValue(senderPrefixModeId, + static_cast(UiStyle::SenderPrefixMode::NoModes)); + } + // -------- + + // Migration complete! + return true; + } + case 8: { // New default changes: RegEx checkbox now toggles Channel regular expressions, too @@ -295,6 +286,7 @@ bool QtUiApplication::applySettingsMigration(QtUiSettings settings, const uint n // -------- // Migration complete! + return true; } case 7: {