25 #include <tdelocale.h>
26 #include <knotifyclient.h>
27 #include <kstaticdeleter.h>
34 #include "notificationmanager.h"
38 NotificationManager::NotificationManager() : TQObject()
40 m_intervalsLapsed = 0;
41 m_checkInterval = 2000;
44 m_addedInLastInterval =
false;
50 NotificationManager::~NotificationManager()
55 void NotificationManager::setWidget(TQWidget* widget, TDEInstance* inst)
58 m_instance = inst != NULL ? inst : TDEGlobal::instance();
61 void NotificationManager::slotNotifyArticle(
const Article& article)
63 m_articles.append(article);
64 m_addedInLastInterval =
true;
65 if (m_articles.count() >= m_maxArticles)
70 TQTimer::singleShot(m_checkInterval,
this, TQ_SLOT(slotIntervalCheck()));
74 void NotificationManager::slotNotifyFeeds(
const TQStringList& feeds)
76 if (feeds.count() == 1)
78 KNotifyClient::Instance inst(m_instance);
79 KNotifyClient::event(m_widget->winId(),
"feed_added", i18n(
"Feed added:\n %1").arg(feeds[0]));
81 else if (feeds.count() > 1)
84 for (TQStringList::ConstIterator it = feeds.begin(); it != feeds.end(); ++it)
85 message += *it +
"\n";
86 KNotifyClient::Instance inst(m_instance);
87 KNotifyClient::event(m_widget->winId(),
"feed_added", i18n(
"Feeds added:\n %1").arg(message));
91 void NotificationManager::doNotify()
93 TQString message =
"<html><body>";
95 TQValueList<Article>::ConstIterator it = m_articles.begin();
96 TQValueList<Article>::ConstIterator en = m_articles.end();
97 for (; it != en; ++it)
99 if (feedTitle != (*it).feed()->title())
101 feedTitle = (*it).feed()->title();
102 message += TQString(
"<p><b>%1:</b></p>").arg(feedTitle);
104 message += (*it).title() +
"<br>";
106 message +=
"</body></html>";
107 KNotifyClient::Instance inst(m_instance);
108 KNotifyClient::event(m_widget->winId(),
"new_articles", message);
112 m_intervalsLapsed = 0;
113 m_addedInLastInterval =
false;
116 void NotificationManager::slotIntervalCheck()
121 if (!m_addedInLastInterval || m_articles.count() >= m_maxArticles || m_intervalsLapsed >= m_maxIntervals)
125 m_addedInLastInterval =
false;
126 TQTimer::singleShot(m_checkInterval,
this, TQ_SLOT(slotIntervalCheck()));
131 NotificationManager* NotificationManager::m_self;
132 static KStaticDeleter<NotificationManager> notificationmanagersd;
143 #include "notificationmanager.moc"
A proxy class for RSS::Article with some additional methods to assist sorting.
this class collects notification requests (new articles etc.) and processes them using KNotify.