• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

akregator

  • sources
  • kde-4.12
  • kdepim
  • akregator
  • src
notificationmanager.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2005 Frank Osterfeld <osterfeld@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "notificationmanager.h"
26 #include "feed.h"
27 
28 #include <klocale.h>
29 #include <knotification.h>
30 #include <kurl.h>
31 #include <kglobal.h>
32 
33 #include <QTimer>
34 #include <QList>
35 
36 
37 namespace Akregator {
38 
39 NotificationManager::NotificationManager() : QObject()
40 {
41  m_intervalsLapsed = 0;
42  m_checkInterval = 2000;
43  m_maxIntervals = 10;
44  m_running = false;
45  m_addedInLastInterval = false;
46  m_maxArticles = 20;
47  m_widget = NULL;
48 }
49 
50 NotificationManager::~NotificationManager()
51 {
52  m_self = 0;
53 }
54 
55 void NotificationManager::setWidget(QWidget* widget, const KComponentData &inst)
56 {
57  m_widget = widget;
58  m_instance = inst.isValid() ? inst : KGlobal::mainComponent();
59 }
60 
61 void NotificationManager::slotNotifyArticle(const Article& article)
62 {
63  m_articles.append(article);
64  m_addedInLastInterval = true;
65  if (m_articles.count() >= m_maxArticles)
66  doNotify();
67  else if (!m_running)
68  {
69  m_running = true;
70  QTimer::singleShot(m_checkInterval, this, SLOT(slotIntervalCheck()));
71  }
72 }
73 
74 void NotificationManager::slotNotifyFeeds(const QStringList& feeds)
75 {
76  if (feeds.count() == 1)
77  {
78  //KNotifyClient::Instance inst(m_instance);
79  KNotification::event(QLatin1String("FeedAdded"), i18n("Feed added:\n %1", feeds[0]), QPixmap() ,m_widget, KNotification::CloseOnTimeout, m_instance);
80  }
81  else if (feeds.count() > 1)
82  {
83  QString message;
84  for (QStringList::ConstIterator it = feeds.constBegin(); it != feeds.constEnd(); ++it)
85  message += *it + QLatin1Char('\n');
86  //KNotifyClient::Instance inst(m_instance);
87  KNotification::event(QLatin1String("FeedAdded"), i18n("Feeds added:\n %1", message), QPixmap() ,m_widget, KNotification::CloseOnTimeout, m_instance);
88  }
89 }
90 
91 void NotificationManager::doNotify()
92 {
93  QString message = QLatin1String("<html><body>");
94  QString feedTitle;
95 
96  Q_FOREACH( const Article& i, m_articles )
97  {
98  if (feedTitle != i.feed()->title())
99  {
100  feedTitle = i.feed()->title();
101  message += QString::fromLatin1("<p><b>%1:</b></p>").arg(feedTitle);
102  }
103  message += i.title() + QLatin1String("<br>");
104  }
105  message += QLatin1String("</body></html>");
106  KNotification::event(QLatin1String("NewArticles"), message, QPixmap() ,m_widget, KNotification::CloseOnTimeout, m_instance);
107 
108  m_articles.clear();
109  m_running = false;
110  m_intervalsLapsed = 0;
111  m_addedInLastInterval = false;
112 }
113 
114 void NotificationManager::slotIntervalCheck()
115 {
116  if (!m_running)
117  return;
118  m_intervalsLapsed++;
119  if (!m_addedInLastInterval || m_articles.count() >= m_maxArticles || m_intervalsLapsed >= m_maxIntervals)
120  doNotify();
121  else
122  {
123  m_addedInLastInterval = false;
124  QTimer::singleShot(m_checkInterval, this, SLOT(slotIntervalCheck()));
125  }
126 
127 }
128 
129 NotificationManager* NotificationManager::m_self = 0;
130 
131 NotificationManager* NotificationManager::self()
132 {
133  static NotificationManager self;
134  if (!m_self)
135  m_self = &self;
136  return m_self;
137 }
138 
139 } // namespace Akregator
140 
141 #include "notificationmanager.moc"
Akregator::NotificationManager::slotNotifyFeeds
void slotNotifyFeeds(const QStringList &feeds)
notifies the addition of feeds (used when added via DCOP or command line)
Definition: notificationmanager.cpp:74
Akregator::TreeNode::title
QString title() const
Get title of node.
Definition: treenode.cpp:87
QWidget
Akregator::NotificationManager::slotNotifyArticle
void slotNotifyArticle(const Akregator::Article &article)
notifies an article.
Definition: notificationmanager.cpp:61
Akregator::NotificationManager
this class collects notification requests (new articles etc.) and processes them using KNotify...
Definition: notificationmanager.h:39
QObject
feed.h
Akregator::Article::feed
Feed * feed() const
Definition: article.cpp:508
Akregator::NotificationManager::setWidget
void setWidget(QWidget *widget, const KComponentData &inst=KComponentData())
the widget used for notification, normally either the mainwindow or the tray icon ...
Definition: notificationmanager.cpp:55
Akregator::NotificationManager::slotIntervalCheck
void slotIntervalCheck()
Definition: notificationmanager.cpp:114
Akregator::Article::title
QString title() const
Definition: article.cpp:374
Akregator::NotificationManager::self
static NotificationManager * self()
singleton instance of notification manager
Definition: notificationmanager.cpp:131
Akregator::NotificationManager::~NotificationManager
~NotificationManager()
Definition: notificationmanager.cpp:50
Akregator::NotificationManager::doNotify
void doNotify()
Definition: notificationmanager.cpp:91
Akregator::Article
A proxy class for Syndication::ItemPtr with some additional methods to assist sorting.
Definition: article.h:61
notificationmanager.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

Skip menu "akregator"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal