summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Montel <[email protected]>2018-01-20 20:55:54 +0100
committerLaurent Montel <[email protected]>2018-01-20 20:55:54 +0100
commit590cd3a860539023bccc12cef2429fff5d4b24a9 (patch)
tree373fe21a71b935c2214183d2f5d901782ada246d
parentd5b863e2ec061ca557e2892bd07279db088ea0f1 (diff)
Avoid duplicate code
-rw-r--r--src/akregator_part.cpp50
-rw-r--r--src/akregator_part.h1
2 files changed, 24 insertions, 27 deletions
diff --git a/src/akregator_part.cpp b/src/akregator_part.cpp
index d09c529..9971805 100644
--- a/src/akregator_part.cpp
+++ b/src/akregator_part.cpp
@@ -248,20 +248,9 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &)
connect(m_mainWidget.data(), &MainWidget::signalUnreadCountChanged, UnityServiceManager::instance(), &UnityServiceManager::slotSetUnread);
if (Settings::showTrayIcon() && !TrayIcon::getInstance()) {
- TrayIcon *trayIcon = new TrayIcon(m_mainWidget->window());
- TrayIcon::setInstance(trayIcon);
- m_actionManager->setTrayIcon(trayIcon);
-
- if (isTrayIconEnabled()) {
- trayIcon->setStatus(KStatusNotifierItem::Active);
- }
-
+ initializeTrayIcon();
QWidget *const notificationParent = isTrayIconEnabled() ? m_mainWidget->window() : nullptr;
NotificationManager::self()->setWidget(notificationParent, componentData().componentName());
-
- connect(m_mainWidget.data(), &MainWidget::signalUnreadCountChanged, trayIcon, &TrayIcon::slotSetUnread);
- connect(m_mainWidget.data(), &MainWidget::signalArticlesSelected,
- this, &Part::signalArticlesSelected);
}
connect(qApp, &QCoreApplication::aboutToQuit, this, &Part::slotOnShutdown);
@@ -340,26 +329,33 @@ void Part::slotOnShutdown()
//delete m_actionManager;
}
-void Part::slotSettingsChanged()
+void Part::initializeTrayIcon()
{
- NotificationManager::self()->setWidget(isTrayIconEnabled() ? m_mainWidget->window() : nullptr, componentData().componentName());
+ TrayIcon *trayIcon = new TrayIcon(m_mainWidget->window());
+ TrayIcon::setInstance(trayIcon);
+ m_actionManager->setTrayIcon(trayIcon);
- if (Settings::showTrayIcon() && !TrayIcon::getInstance()) {
- TrayIcon *trayIcon = new TrayIcon(m_mainWidget->window());
- TrayIcon::setInstance(trayIcon);
- m_actionManager->setTrayIcon(trayIcon);
+ if (isTrayIconEnabled()) {
+ trayIcon->setStatus(KStatusNotifierItem::Active);
+ }
- if (isTrayIconEnabled()) {
- trayIcon->setStatus(KStatusNotifierItem::Active);
- }
+ connect(m_mainWidget.data(), &MainWidget::signalUnreadCountChanged, trayIcon, &TrayIcon::slotSetUnread);
+ connect(m_mainWidget.data(), &MainWidget::signalArticlesSelected,
+ this, &Part::signalArticlesSelected);
- connect(m_mainWidget.data(), &MainWidget::signalUnreadCountChanged, trayIcon, &TrayIcon::slotSetUnread);
- connect(m_mainWidget.data(), &MainWidget::signalArticlesSelected,
- this, &Part::signalArticlesSelected);
+ m_mainWidget->slotSetTotalUnread();
+}
- m_mainWidget->slotSetTotalUnread();
- }
- if (!Settings::showTrayIcon()) {
+void Part::slotSettingsChanged()
+{
+ NotificationManager::self()->setWidget(isTrayIconEnabled() ? m_mainWidget->window() : nullptr, componentData().componentName());
+
+ if (Settings::showTrayIcon()) {
+ if (!TrayIcon::getInstance()) {
+ initializeTrayIcon();
+ m_mainWidget->slotSetTotalUnread();
+ }
+ } else {
TrayIcon::getInstance()->disconnect();
delete TrayIcon::getInstance();
TrayIcon::setInstance(nullptr);
diff --git a/src/akregator_part.h b/src/akregator_part.h
index 0e7c44a..5d83d3c 100644
--- a/src/akregator_part.h
+++ b/src/akregator_part.h
@@ -206,6 +206,7 @@ private: // methods
void clearCrashProperties();
private: // attributes
+ void initializeTrayIcon();
class ApplyFiltersInterceptor;
ApplyFiltersInterceptor *m_applyFiltersInterceptor = nullptr;