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

akregator

  • sources
  • kde-4.14
  • 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 
35 
36 namespace Akregator {
37 
38 NotificationManager::NotificationManager() : QObject()
39 {
40  m_intervalsLapsed = 0;
41  m_checkInterval = 2000;
42  m_maxIntervals = 10;
43  m_running = false;
44  m_addedInLastInterval = false;
45  m_maxArticles = 20;
46  m_widget = NULL;
47 }
48 
49 NotificationManager::~NotificationManager()
50 {
51  m_self = 0;
52 }
53 
54 void NotificationManager::setWidget(QWidget* widget, const KComponentData &inst)
55 {
56  m_widget = widget;
57  m_instance = inst.isValid() ? inst : KGlobal::mainComponent();
58 }
59 
60 void NotificationManager::slotNotifyArticle(const Article& article)
61 {
62  m_articles.append(article);
63  m_addedInLastInterval = true;
64  if (m_articles.count() >= m_maxArticles)
65  doNotify();
66  else if (!m_running)
67  {
68  m_running = true;
69  QTimer::singleShot(m_checkInterval, this, SLOT(slotIntervalCheck()));
70  }
71 }
72 
73 void NotificationManager::slotNotifyFeeds(const QStringList& feeds)
74 {
75  if (feeds.count() == 1)
76  {
77  //KNotifyClient::Instance inst(m_instance);
78  KNotification::event(QLatin1String("FeedAdded"), i18n("Feed added:\n %1", feeds[0]), QPixmap() ,m_widget, KNotification::CloseOnTimeout, m_instance);
79  }
80  else if (feeds.count() > 1)
81  {
82  QString message;
83  for (QStringList::ConstIterator it = feeds.constBegin(); it != feeds.constEnd(); ++it)
84  message += *it + QLatin1Char('\n');
85  //KNotifyClient::Instance inst(m_instance);
86  KNotification::event(QLatin1String("FeedAdded"), i18n("Feeds added:\n %1", message), QPixmap() ,m_widget, KNotification::CloseOnTimeout, m_instance);
87  }
88 }
89 
90 void NotificationManager::doNotify()
91 {
92  QString message = QLatin1String("<html><body>");
93  QString feedTitle;
94 
95  Q_FOREACH( const Article& i, m_articles )
96  {
97  if (feedTitle != i.feed()->title())
98  {
99  feedTitle = i.feed()->title();
100  message += QString::fromLatin1("<p><b>%1:</b></p>").arg(feedTitle);
101  }
102  message += i.title() + QLatin1String("<br>");
103  }
104  message += QLatin1String("</body></html>");
105  KNotification::event(QLatin1String("NewArticles"), message, QPixmap() ,m_widget, KNotification::CloseOnTimeout, m_instance);
106 
107  m_articles.clear();
108  m_running = false;
109  m_intervalsLapsed = 0;
110  m_addedInLastInterval = false;
111 }
112 
113 void NotificationManager::slotIntervalCheck()
114 {
115  if (!m_running)
116  return;
117  m_intervalsLapsed++;
118  if (!m_addedInLastInterval || m_articles.count() >= m_maxArticles || m_intervalsLapsed >= m_maxIntervals)
119  doNotify();
120  else
121  {
122  m_addedInLastInterval = false;
123  QTimer::singleShot(m_checkInterval, this, SLOT(slotIntervalCheck()));
124  }
125 
126 }
127 
128 NotificationManager* NotificationManager::m_self = 0;
129 
130 NotificationManager* NotificationManager::self()
131 {
132  static NotificationManager self;
133  if (!m_self)
134  m_self = &self;
135  return m_self;
136 }
137 
138 } // namespace Akregator
139 
QWidget
Akregator::NotificationManager::slotNotifyFeeds
void slotNotifyFeeds(const QStringList &feeds)
notifies the addition of feeds (used when added via DCOP or command line)
Definition: notificationmanager.cpp:73
Akregator::TreeNode::title
QString title() const
Get title of node.
Definition: treenode.cpp:87
Akregator::NotificationManager::slotNotifyArticle
void slotNotifyArticle(const Akregator::Article &article)
notifies an article.
Definition: notificationmanager.cpp:60
Akregator::NotificationManager
this class collects notification requests (new articles etc.) and processes them using KNotify...
Definition: notificationmanager.h:39
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:54
Akregator::NotificationManager::slotIntervalCheck
void slotIntervalCheck()
Definition: notificationmanager.cpp:113
QList::count
int count(const T &value) const
Akregator::Article::title
QString title() const
Definition: article.cpp:374
QObject
Akregator::NotificationManager::self
static NotificationManager * self()
singleton instance of notification manager
Definition: notificationmanager.cpp:130
Akregator::NotificationManager::~NotificationManager
~NotificationManager()
Definition: notificationmanager.cpp:49
QString
QStringList
QPixmap
QLatin1Char
Akregator::NotificationManager::doNotify
void doNotify()
Definition: notificationmanager.cpp:90
QLatin1String
QList::ConstIterator
typedef ConstIterator
Akregator::Article
A proxy class for Syndication::ItemPtr with some additional methods to assist sorting.
Definition: article.h:63
QString::fromLatin1
QString fromLatin1(const char *str, int size)
notificationmanager.h
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:00 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
  • pimprint

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