X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtui.cpp;h=3bdb6e1c1ee74818a291aefb1831f386736daa63;hp=0082bd06d1a869d762bce80d36f8f3bef2dba92f;hb=6eefdfc697067d184a589fc8a231b16316c09106;hpb=3abd4b7d5ab303f8d990c104748e5d5aef4db355 diff --git a/src/qtui/qtui.cpp b/src/qtui/qtui.cpp index 0082bd06..3bdb6e1c 100644 --- a/src/qtui/qtui.cpp +++ b/src/qtui/qtui.cpp @@ -25,11 +25,13 @@ #include #include #include +#include #include "abstractnotificationbackend.h" #include "buffermodel.h" #include "chatlinemodel.h" #include "contextmenuactionprovider.h" +#include "icon.h" #include "mainwin.h" #include "qtuimessageprocessor.h" #include "qtuisettings.h" @@ -39,59 +41,54 @@ #include "types.h" #include "util.h" -QtUi *QtUi::_instance = nullptr; -MainWin *QtUi::_mainWin = nullptr; QList QtUi::_notificationBackends; QList QtUi::_notifications; + +QtUi *QtUi::instance() +{ + return static_cast(GraphicalUi::instance()); +} + + QtUi::QtUi() : GraphicalUi() , _systemIconTheme{QIcon::themeName()} { - if (_instance != nullptr) { - qWarning() << "QtUi has been instantiated again!"; - return; - } - _instance = this; + QtUiSettings uiSettings; + Quassel::loadTranslation(uiSettings.value("Locale", QLocale::system()).value()); if (Quassel::isOptionSet("icontheme")) { _systemIconTheme = Quassel::optionValue("icontheme"); QIcon::setThemeName(_systemIconTheme); } - - QtUiSettings uiSettings; - Quassel::loadTranslation(uiSettings.value("Locale", QLocale::system()).value()); - setupIconTheme(); - - QApplication::setWindowIcon(QIcon::fromTheme("quassel")); - - setContextMenuActionProvider(new ContextMenuActionProvider(this)); - setToolBarActionProvider(new ToolBarActionProvider(this)); + QApplication::setWindowIcon(icon::get("quassel")); setUiStyle(new QtUiStyle(this)); - _mainWin = new MainWin(); - - setMainWidget(_mainWin); - - connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &))); - connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore())); - connect(Client::instance(), SIGNAL(bufferMarkedAsRead(BufferId)), SLOT(closeNotifications(BufferId))); } QtUi::~QtUi() { unregisterAllNotificationBackends(); - delete _mainWin; - _mainWin = nullptr; - _instance = nullptr; } void QtUi::init() { + setContextMenuActionProvider(new ContextMenuActionProvider(this)); + setToolBarActionProvider(new ToolBarActionProvider(this)); + + _mainWin = std::make_unique(); + setMainWidget(_mainWin.get()); + + connect(_mainWin.get(), &MainWin::connectToCore, this, &QtUi::connectToCore); + connect(_mainWin.get(), &MainWin::disconnectFromCore, this, &QtUi::disconnectFromCore); + connect(Client::instance(), &Client::bufferMarkedAsRead, this, &QtUi::closeNotifications); + _mainWin->init(); + QtUiSettings uiSettings; uiSettings.initAndNotify("UseSystemTrayIcon", this, SLOT(useSystemTrayChanged(QVariant)), true); @@ -170,7 +167,7 @@ void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) { if (!_notificationBackends.contains(backend)) { _notificationBackends.append(backend); - instance()->connect(backend, SIGNAL(activated(uint)), SLOT(notificationActivated(uint))); + connect(backend, &AbstractNotificationBackend::activated, instance(), &QtUi::notificationActivated); } } @@ -273,7 +270,9 @@ std::vector> QtUi::availableIconThemes() const static const std::vector> supported { { "breeze", tr("Breeze") }, { "breeze-dark", tr("Breeze Dark") }, +#ifdef WITH_OXYGEN_ICONS { "oxygen", tr("Oxygen") } +#endif }; std::vector> result; @@ -290,6 +289,12 @@ std::vector> QtUi::availableIconThemes() const } +QString QtUi::systemIconTheme() const +{ + return _systemIconTheme; +} + + void QtUi::setupIconTheme() { // Add paths to our own icon sets to the theme search paths @@ -336,13 +341,13 @@ void QtUi::refreshIconTheme() } } - if (_systemIconTheme.isEmpty() || _systemIconTheme == fallbackTheme || s.value("Icons/OverrideSystemTheme", false).toBool()) { + if (_systemIconTheme.isEmpty() || _systemIconTheme == fallbackTheme || s.value("Icons/OverrideSystemTheme", true).toBool()) { // We have a valid fallback theme and want to override the system theme (if it's even defined), so we're basically done QIcon::setThemeName(fallbackTheme); + emit iconThemeRefreshed(); return; } -#if QT_VERSION >= 0x050000 // At this point, we have a system theme that we don't want to override, but that may not contain all // required icons. // We create a dummy theme that inherits first from the system theme, then from the supported fallback. @@ -351,10 +356,11 @@ void QtUi::refreshIconTheme() // Since we can't get notified when the system theme changes, this means that a restart may be required // to apply a theme change... but you can't have everything, I guess. if (!_dummyThemeDir) { - _dummyThemeDir.reset(new QTemporaryDir{}); + _dummyThemeDir = std::make_unique(); if (!_dummyThemeDir->isValid() || !QDir{_dummyThemeDir->path()}.mkpath("icons/quassel-icon-proxy/apps/32")) { qWarning() << "Could not create temporary directory for proxying the system icon theme, using fallback"; QIcon::setThemeName(fallbackTheme); + emit iconThemeRefreshed(); return; } // Add this to XDG_DATA_DIRS, otherwise KIconLoader complains @@ -371,6 +377,7 @@ void QtUi::refreshIconTheme() if (!indexFile.open(QFile::WriteOnly|QFile::Truncate)) { qWarning() << "Could not create index file for proxying the system icon theme, using fallback"; QIcon::setThemeName(fallbackTheme); + emit iconThemeRefreshed(); return; } @@ -385,13 +392,9 @@ void QtUi::refreshIconTheme() if (indexFile.write(indexContents.toLatin1()) < 0) { qWarning() << "Could not write index file for proxying the system icon theme, using fallback"; QIcon::setThemeName(fallbackTheme); + emit iconThemeRefreshed(); return; } indexFile.close(); QIcon::setThemeName("quassel-icon-proxy"); -#else - // Qt4 doesn't support QTemporaryDir. Since it's deprecated and slated to be removed soon anyway, we don't bother - // writing a replacement and simply don't support not overriding the system theme. - QIcon::setThemeName(fallbackTheme); -#endif }