X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtui.cpp;fp=src%2Fqtui%2Fqtui.cpp;h=333b79b623158d967eff4b5824fcae1ff2b755bc;hp=c69bf5ea4fe06081a03f9d31a290e4db82c4b6fa;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/qtui/qtui.cpp b/src/qtui/qtui.cpp index c69bf5ea..333b79b6 100644 --- a/src/qtui/qtui.cpp +++ b/src/qtui/qtui.cpp @@ -20,12 +20,13 @@ #include "qtui.h" +#include + #include #include #include #include #include -#include #include "abstractnotificationbackend.h" #include "buffermodel.h" @@ -41,16 +42,14 @@ #include "types.h" #include "util.h" -QList QtUi::_notificationBackends; +QList QtUi::_notificationBackends; QList QtUi::_notifications; - -QtUi *QtUi::instance() +QtUi* QtUi::instance() { return static_cast(GraphicalUi::instance()); } - QtUi::QtUi() : GraphicalUi() , _systemIconTheme{QIcon::themeName()} @@ -68,13 +67,11 @@ QtUi::QtUi() setUiStyle(new QtUiStyle(this)); } - QtUi::~QtUi() { unregisterAllNotificationBackends(); } - void QtUi::init() { setContextMenuActionProvider(new ContextMenuActionProvider(this)); @@ -92,39 +89,34 @@ void QtUi::init() QtUiSettings uiSettings; uiSettings.initAndNotify("UseSystemTrayIcon", this, &QtUi::useSystemTrayChanged, true); - GraphicalUi::init(); // needs to be called after the mainWin is initialized + GraphicalUi::init(); // needs to be called after the mainWin is initialized } - -MessageModel *QtUi::createMessageModel(QObject *parent) +MessageModel* QtUi::createMessageModel(QObject* parent) { return new ChatLineModel(parent); } - -AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) +AbstractMessageProcessor* QtUi::createMessageProcessor(QObject* parent) { return new QtUiMessageProcessor(parent); } - void QtUi::connectedToCore() { _mainWin->connectedToCore(); } - void QtUi::disconnectedFromCore() { _mainWin->disconnectedFromCore(); GraphicalUi::disconnectedFromCore(); } - -void QtUi::useSystemTrayChanged(const QVariant &v) +void QtUi::useSystemTrayChanged(const QVariant& v) { _useSystemTray = v.toBool(); - SystemTray *tray = mainWindow()->systemTray(); + SystemTray* tray = mainWindow()->systemTray(); if (_useSystemTray) { if (tray->isSystemTrayAvailable()) tray->setVisible(true); @@ -135,22 +127,19 @@ void QtUi::useSystemTrayChanged(const QVariant &v) } } - bool QtUi::haveSystemTray() { return mainWindow()->systemTray()->isSystemTrayAvailable() && instance()->_useSystemTray; } - bool QtUi::isHidingMainWidgetAllowed() const { return haveSystemTray(); } - void QtUi::minimizeRestore(bool show) { - SystemTray *tray = mainWindow()->systemTray(); + SystemTray* tray = mainWindow()->systemTray(); if (show) { if (tray && !_useSystemTray) tray->setVisible(false); @@ -162,8 +151,7 @@ void QtUi::minimizeRestore(bool show) GraphicalUi::minimizeRestore(show); } - -void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) +void QtUi::registerNotificationBackend(AbstractNotificationBackend* backend) { if (!_notificationBackends.contains(backend)) { _notificationBackends.append(backend); @@ -171,71 +159,65 @@ void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) } } - -void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) +void QtUi::unregisterNotificationBackend(AbstractNotificationBackend* backend) { _notificationBackends.removeAll(backend); } - void QtUi::unregisterAllNotificationBackends() { _notificationBackends.clear(); } - -const QList &QtUi::notificationBackends() +const QList& QtUi::notificationBackends() { return _notificationBackends; } - -uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text) +uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString& sender, const QString& text) { static int notificationId = 0; AbstractNotificationBackend::Notification notification(++notificationId, bufId, type, sender, text); _notifications.append(notification); - foreach(AbstractNotificationBackend *backend, _notificationBackends) - backend->notify(notification); + foreach (AbstractNotificationBackend* backend, _notificationBackends) + backend->notify(notification); return notificationId; } - void QtUi::closeNotification(uint notificationId) { QList::iterator i = _notifications.begin(); while (i != _notifications.end()) { if (i->notificationId == notificationId) { - foreach(AbstractNotificationBackend *backend, _notificationBackends) - backend->close(notificationId); + foreach (AbstractNotificationBackend* backend, _notificationBackends) + backend->close(notificationId); i = _notifications.erase(i); } - else ++i; + else + ++i; } } - void QtUi::closeNotifications(BufferId bufferId) { QList::iterator i = _notifications.begin(); while (i != _notifications.end()) { if (!bufferId.isValid() || i->bufferId == bufferId) { - foreach(AbstractNotificationBackend *backend, _notificationBackends) - backend->close(i->notificationId); + foreach (AbstractNotificationBackend* backend, _notificationBackends) + backend->close(i->notificationId); i = _notifications.erase(i); } - else ++i; + else + ++i; } } - -const QList &QtUi::activeNotifications() +const QList& QtUi::activeNotifications() { return _notifications; } - void QtUi::notificationActivated(uint notificationId) { if (notificationId != 0) { @@ -255,7 +237,6 @@ void QtUi::notificationActivated(uint notificationId) activateMainWidget(); } - void QtUi::bufferMarkedAsRead(BufferId bufferId) { if (bufferId.isValid()) { @@ -263,21 +244,19 @@ void QtUi::bufferMarkedAsRead(BufferId bufferId) } } - std::vector> QtUi::availableIconThemes() const { //: Supported icon theme names - static const std::vector> supported { - { "breeze", tr("Breeze") }, - { "breeze-dark", tr("Breeze Dark") }, + static const std::vector> supported{{"breeze", tr("Breeze")}, + {"breeze-dark", tr("Breeze Dark")}, #ifdef WITH_OXYGEN_ICONS - { "oxygen", tr("Oxygen") } + {"oxygen", tr("Oxygen")} #endif }; std::vector> result; - for (auto &&themePair : supported) { - for (auto &&dir : QIcon::themeSearchPaths()) { + for (auto&& themePair : supported) { + for (auto&& dir : QIcon::themeSearchPaths()) { if (QFileInfo{dir + "/" + themePair.first + "/index.theme"}.exists()) { result.push_back(themePair); break; @@ -288,19 +267,17 @@ std::vector> QtUi::availableIconThemes() const return result; } - QString QtUi::systemIconTheme() const { return _systemIconTheme; } - void QtUi::setupIconTheme() { // Add paths to our own icon sets to the theme search paths QStringList themePaths = QIcon::themeSearchPaths(); themePaths.removeAll(":/icons"); // this should come last - for (auto &&dataDir : Quassel::dataDirPaths()) { + for (auto&& dataDir : Quassel::dataDirPaths()) { QString iconDir{dataDir + "icons"}; if (QFileInfo{iconDir}.isDir()) { themePaths << iconDir; @@ -312,12 +289,11 @@ void QtUi::setupIconTheme() refreshIconTheme(); } - void QtUi::refreshIconTheme() { // List of available fallback themes QStringList availableThemes; - for (auto &&themePair : availableIconThemes()) { + for (auto&& themePair : availableIconThemes()) { availableThemes << themePair.first; } @@ -325,7 +301,8 @@ void QtUi::refreshIconTheme() // We could probably introduce a more sophisticated fallback handling, such as putting the "most important" icons into hicolor, // but this just gets complex for no good reason. We really rely on a supported theme to be installed, if not system-wide, then // as part of the Quassel installation (which is enabled by default anyway). - qWarning() << tr("No supported icon theme installed, you'll lack icons! Supported are the KDE/Plasma themes Breeze, Breeze Dark and Oxygen."); + qWarning() << tr( + "No supported icon theme installed, you'll lack icons! Supported are the KDE/Plasma themes Breeze, Breeze Dark and Oxygen."); return; } @@ -374,7 +351,7 @@ void QtUi::refreshIconTheme() } QFile indexFile{_dummyThemeDir->path() + "/icons/quassel-icon-proxy/index.theme"}; - if (!indexFile.open(QFile::WriteOnly|QFile::Truncate)) { + 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(); @@ -382,13 +359,12 @@ void QtUi::refreshIconTheme() } // Write a dummy index file that is sufficient to make QIconLoader happy - auto indexContents = QString{ - "[Icon Theme]\n" - "Name=quassel-icon-proxy\n" - "Inherits=%1,%2\n" - "Directories=apps/32\n" - "[apps/32]\nSize=32\nType=Fixed\n" - }.arg(_systemIconTheme, fallbackTheme); + auto indexContents = QString{"[Icon Theme]\n" + "Name=quassel-icon-proxy\n" + "Inherits=%1,%2\n" + "Directories=apps/32\n" + "[apps/32]\nSize=32\nType=Fixed\n"} + .arg(_systemIconTheme, fallbackTheme); if (indexFile.write(indexContents.toLatin1()) < 0) { qWarning() << "Could not write index file for proxying the system icon theme, using fallback"; QIcon::setThemeName(fallbackTheme);