File: notifybypopup.h

package info (click to toggle)
kde-runtime 4%3A17.08.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 25,204 kB
  • sloc: cpp: 111,675; ansic: 5,030; perl: 1,579; xml: 793; sh: 407; makefile: 42; python: 28
file content (128 lines) | stat: -rw-r--r-- 4,381 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
   Copyright (C) 2005-2006 by Olivier Goffart <ogoffart at kde.org>
   Copyright (C) 2008 by Dmitry Suzdalev <dimsuz@gmail.com>


   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

 */

#ifndef NOTIFYBYPOPUP_H
#define NOTIFYBYPOPUP_H

#include "knotifyplugin.h"
#include <QMap>
#include <QHash>
#include <QStringList>
#include <QXmlStreamEntityResolver>

class KPassivePopup;

class NotifyByPopup : public KNotifyPlugin
{ Q_OBJECT
	public:
		NotifyByPopup(QObject *parent=0l);
		virtual ~NotifyByPopup();
		
		virtual QString optionName() { return "Popup"; }
		virtual void notify(int id , KNotifyConfig *config);
		virtual void close( int id );
		virtual void update(int id, KNotifyConfig *config);

		QStringList popupServerCapabilities();

	private:
		QMap<int, KPassivePopup * > m_popups;
		// the y coordinate of the next position popup should appears
		int m_nextPosition;
		int m_animationTimer;
		void fillPopup(KPassivePopup *,int id,KNotifyConfig *config);
		/**
		 * Make sure a popup is completely supported by the notification backend.
		 * Changes the popup to be compatible if needed.
		 * @param config the notification data to check
		 * @return the new notification data allocated with 'new'
		 */
		KNotifyConfig *ensurePopupCompatibility( const KNotifyConfig *config );
		/**
		 * Removes HTML from a given string. Replaces line breaks with \n and
		 * HTML entities by their 'normal forms'.
		 * @param string the HTML to remove.
		 * @return the cleaned string.
		 */
		QString stripHtml( const QString &text );
		/**
		 * Sends notification to DBus "/Notifications" interface.
		 * @param id knotify-sid identifier of notification
		 * @param replacesId knotify-side notification identifier. If not 0, will
		 * request DBus service to replace existing notification with data in config
		 * @param config notification data
		 * @return true for success or false if there was an error.
		 */
		bool sendNotificationDBus(int id, int replacesId, KNotifyConfig* config);
		/**
		 * Sends request to close Notification with id to DBus "/Notification" interface
		 *  @param id knotify-side notification ID to close
		 */
		void closeNotificationDBus(int id);
		/**
		 * Specifies if DBus Notifications interface exists on session bus
		 */
		bool m_dbusServiceExists;
		/**
		 * DBus notification daemon capabilities cache.
		 * Do not use this variable. Use #popupServerCapabilities() instead.
		 * @see popupServerCapabilities
		 */
		QStringList m_dbusServiceCapabilities;
		/**
		 * Whether the DBus notification daemon capability cache is up-to-date.
		 */
		bool m_dbusServiceCapCacheDirty;
		/**
		 * Find the caption and the icon name of the application
		 */
		void getAppCaptionAndIconName(KNotifyConfig *config, QString *appCaption, QString *iconName);
		
	protected:
		void timerEvent(QTimerEvent *event);

	private Q_SLOTS:
		void slotPopupDestroyed();
		void slotLinkClicked(const QString & );
		// slot to catch appearance or dissapearance of Notifications DBus service
		void slotServiceOwnerChanged(const QString &, const QString &, const QString &);
		// slot which gets called when DBus signals that some notification action was invoked
		void slotDBusNotificationActionInvoked(uint, const QString&);
		// slot which gets called when DBus signals that some notification was closed
		void slotDBusNotificationClosed(uint, uint);

        private:
		/**
		 * Maps knotify notification IDs to DBus notifications IDs
		 */
		QHash<int,uint> m_idMap;

		/**
		 * A class for resolving HTML entities in XML documents (used
		 * during HTML stripping)
		 */
		class HtmlEntityResolver : public QXmlStreamEntityResolver
		{
			QString resolveUndeclaredEntity( const QString &name );
		};
};

#endif