PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llnotificationhandler.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 420 lines | 174 code | 72 blank | 174 comment | 0 complexity | eb31d3ace3a9677467296dbd57bb4c78 MD5 | raw file
  1/** 
  2 * @file llnotificationhandler.h
  3 * @brief Here are implemented Notification Handling Classes.
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLNOTIFICATIONHANDLER_H
 28#define LL_LLNOTIFICATIONHANDLER_H
 29
 30
 31#include "llwindow.h"
 32
 33//#include "llnotificationsutil.h"
 34#include "llchannelmanager.h"
 35#include "llchat.h"
 36#include "llinstantmessage.h"
 37#include "llnotificationptr.h"
 38
 39class LLIMFloater;
 40
 41namespace LLNotificationsUI
 42{
 43// ENotificationType enumerates all possible types of notifications that could be met
 44// 
 45typedef enum e_notification_type
 46{
 47	NT_NOTIFY, 
 48	NT_NOTIFYTIP,
 49	NT_GROUPNOTIFY,
 50	NT_IMCHAT, 
 51	NT_GROUPCHAT, 
 52	NT_NEARBYCHAT, 
 53	NT_ALERT,
 54	NT_ALERTMODAL,
 55	NT_OFFER
 56} ENotificationType;
 57
 58/**
 59 * Handler of notification events.
 60 * This handler manages events related to toasts and chicklets. This is  base class
 61 * for chat and system notification handlers.
 62 */
 63
 64// LLEventHandler is a base class that specifies a common interface for all
 65// notification handlers. It states, that every handler must react on the follofing
 66// events:
 67//			- deleting of a toast;
 68//			- initialization of a corresponding channel;
 69// Also every handler must have the following attributes:
 70//			- type of the notification that this handler is responsible to;
 71//			- pointer to a correspondent screen channel, in which all toasts of the handled notification's
 72//			  type should be displayed
 73// This class also provides the following signald:
 74//			- increment counter signal
 75//			- decrement counter signal
 76//			- update counter signal
 77//			- signal, that emits ID of the notification that is being processed
 78//
 79class LLEventHandler
 80{
 81public:
 82	virtual ~LLEventHandler() {};
 83
 84	// callbacks for counters
 85	typedef boost::function<void (void)> notification_callback_t;
 86	typedef boost::signals2::signal<void (void)> notification_signal_t;
 87	notification_signal_t mNewNotificationSignal;
 88	notification_signal_t mDelNotificationSignal;
 89	boost::signals2::connection setNewNotificationCallback(notification_callback_t cb) { return mNewNotificationSignal.connect(cb); }
 90	boost::signals2::connection setDelNotification(notification_callback_t cb) { return mDelNotificationSignal.connect(cb); }
 91	// callback for notification/toast
 92	typedef boost::function<void (const LLUUID id)> notification_id_callback_t;
 93	typedef boost::signals2::signal<void (const LLUUID id)> notification_id_signal_t;
 94	notification_id_signal_t mNotificationIDSignal;
 95	boost::signals2::connection setNotificationIDCallback(notification_id_callback_t cb) { return mNotificationIDSignal.connect(cb); }
 96
 97protected:
 98	virtual void onDeleteToast(LLToast* toast)=0;
 99
100	// arrange handler's channel on a screen
101	// is necessary to unbind a moment of creation of a channel and a moment of positioning of it
102	// it is useful when positioning depends on positions of other controls, that could not be created
103	// at the moment, when a handlers creates a channel.
104	virtual void initChannel()=0;
105
106	LLScreenChannelBase*	mChannel;
107	e_notification_type		mType;
108
109};
110
111// LLSysHandler and LLChatHandler are more specific base classes
112// that divide all notification handlers on to groups:
113//			- handlers for different system notifications (script dialogs, tips, group notices, alerts and IMs);
114//			- handlers for different messaging notifications (nearby chat)
115/**
116 * Handler for system notifications.
117 */
118class LLSysHandler : public LLEventHandler
119{
120public:
121	LLSysHandler();
122	virtual ~LLSysHandler() {};
123
124	virtual bool processNotification(const LLSD& notify)=0;
125
126protected :
127	static void init();
128	void removeExclusiveNotifications(const LLNotificationPtr& notif);
129
130	typedef std::list< std::set<std::string> > exclusive_notif_sets;
131	static exclusive_notif_sets sExclusiveNotificationGroups;
132};
133
134/**
135 * Handler for chat message notifications.
136 */
137class LLChatHandler : public LLEventHandler
138{
139public:
140	virtual ~LLChatHandler() {};
141
142	virtual void processChat(const LLChat& chat_msg, const LLSD &args)=0;
143};
144
145/**
146 * Handler for IM notifications.
147 * It manages life time of IMs, group messages.
148 */
149class LLIMHandler : public LLSysHandler
150{
151public:
152	LLIMHandler(e_notification_type type, const LLSD& id);
153	virtual ~LLIMHandler();
154
155	// base interface functions
156	virtual bool processNotification(const LLSD& notify);
157
158protected:
159	virtual void onDeleteToast(LLToast* toast);
160	virtual void initChannel();
161};
162
163/**
164 * Handler for system informational notices.
165 * It manages life time of tip notices.
166 */
167class LLTipHandler : public LLSysHandler
168{
169public:
170	LLTipHandler(e_notification_type type, const LLSD& id);
171	virtual ~LLTipHandler();
172
173	// base interface functions
174	virtual bool processNotification(const LLSD& notify);
175
176protected:
177	virtual void onDeleteToast(LLToast* toast);
178	virtual void onRejectToast(const LLUUID& id);
179	virtual void initChannel();
180};
181
182/**
183 * Handler for system informational notices.
184 * It manages life time of script notices.
185 */
186class LLScriptHandler : public LLSysHandler
187{
188public:
189	LLScriptHandler(e_notification_type type, const LLSD& id);
190	virtual ~LLScriptHandler();
191
192	// base interface functions
193	virtual bool processNotification(const LLSD& notify);
194
195protected:
196	virtual void onDeleteToast(LLToast* toast);
197	virtual void initChannel();
198
199	// own handlers
200	void onRejectToast(LLUUID& id);
201};
202
203
204/**
205 * Handler for group system notices.
206 */
207class LLGroupHandler : public LLSysHandler
208{
209public:
210	LLGroupHandler(e_notification_type type, const LLSD& id);
211	virtual ~LLGroupHandler();
212	
213	// base interface functions
214	virtual bool processNotification(const LLSD& notify);
215
216protected:
217	virtual void onDeleteToast(LLToast* toast);
218	virtual void initChannel();
219
220	// own handlers
221	void onRejectToast(LLUUID& id);
222};
223
224/**
225 * Handler for alert system notices.
226 */
227class LLAlertHandler : public LLSysHandler
228{
229public:
230	LLAlertHandler(e_notification_type type, const LLSD& id);
231	virtual ~LLAlertHandler();
232
233	void setAlertMode(bool is_modal) { mIsModal = is_modal; }
234
235	// base interface functions
236	virtual bool processNotification(const LLSD& notify);
237
238protected:
239	virtual void onDeleteToast(LLToast* toast);
240	virtual void initChannel();
241
242	bool	mIsModal;
243};
244
245/**
246 * Handler for offers notices.
247 * It manages life time of offer notices.
248 */
249class LLOfferHandler : public LLSysHandler
250{
251public:
252	LLOfferHandler(e_notification_type type, const LLSD& id);
253	virtual ~LLOfferHandler();
254
255	// base interface functions
256	virtual bool processNotification(const LLSD& notify);
257
258protected:
259	virtual void onDeleteToast(LLToast* toast);
260	virtual void initChannel();
261
262	// own handlers
263	void onRejectToast(LLUUID& id);
264};
265
266/**
267 * Handler for UI hints.
268 */
269class LLHintHandler : public LLSingleton<LLHintHandler>
270{
271public:
272	LLHintHandler();
273	virtual ~LLHintHandler();
274
275	// base interface functions
276	virtual bool processNotification(const LLSD& notify);
277};
278
279/**
280 * Handler for browser notifications
281 */
282class LLBrowserNotification : public LLSingleton<LLBrowserNotification>
283{
284public:
285	virtual bool processNotification(const LLSD& notify);
286};
287	
288/**
289 * Handler for outbox notifications
290 */
291class LLOutboxNotification : public LLSingleton<LLOutboxNotification>
292{
293public:
294	virtual bool processNotification(const LLSD& notify);
295};
296	
297class LLHandlerUtil
298{
299public:
300	/**
301	 * Checks sufficient conditions to log notification message to IM session.
302	 */
303	static bool canLogToIM(const LLNotificationPtr& notification);
304
305	/**
306	 * Checks sufficient conditions to log notification message to nearby chat session.
307	 */
308	static bool canLogToNearbyChat(const LLNotificationPtr& notification);
309
310	/**
311	 * Checks sufficient conditions to spawn IM session.
312	 */
313	static bool canSpawnIMSession(const LLNotificationPtr& notification);
314
315	/**
316	 * Checks sufficient conditions to add notification toast panel IM floater.
317	 */
318	static bool canAddNotifPanelToIM(const LLNotificationPtr& notification);
319
320	/**
321	 * Checks whether notification can be used multiple times or not.
322	 */
323	static bool isNotificationReusable(const LLNotificationPtr& notification);
324
325	/**
326	 * Checks if passed notification can create IM session and be written into it.
327	 *
328	 * This method uses canLogToIM() & canSpawnIMSession().
329	 */
330	static bool canSpawnSessionAndLogToIM(const LLNotificationPtr& notification);
331
332	/**
333	 * Checks if passed notification can create toast.
334	 */
335	static bool canSpawnToast(const LLNotificationPtr& notification);
336
337	/**
338	 * Determines whether IM floater is opened.
339	 */
340	static bool isIMFloaterOpened(const LLNotificationPtr& notification);
341
342	/**
343	* Determines whether IM floater is focused.
344	*/
345	static bool isIMFloaterFocused(const LLNotificationPtr& notification);
346
347	/**
348	 * Writes notification message to IM session.
349	 */
350	static void logToIM(const EInstantMessage& session_type,
351			const std::string& session_name, const std::string& from_name,
352			const std::string& message, const LLUUID& session_owner_id,
353			const LLUUID& from_id);
354
355	/**
356	 * Writes notification message to IM  p2p session.
357	 */
358	static void logToIMP2P(const LLNotificationPtr& notification);
359
360	/**
361	 * Writes notification message to IM  p2p session.
362	 */
363	static void logToIMP2P(const LLNotificationPtr& notification, bool to_file_only);
364
365	/**
366	 * Writes group notice notification message to IM  group session.
367	 */
368	static void logGroupNoticeToIMGroup(const LLNotificationPtr& notification);
369
370	/**
371	 * Writes notification message to nearby chat.
372	 */
373	static void logToNearbyChat(const LLNotificationPtr& notification, EChatSourceType type);
374
375	/**
376	 * Spawns IM session.
377	 */
378	static LLUUID spawnIMSession(const std::string& name, const LLUUID& from_id);
379
380	/**
381	 * Returns name from the notification's substitution.
382	 *
383	 * Methods gets "NAME" or "[NAME]" from the substitution map.
384	 *
385	 * @param notification - Notification which substitution's name will be returned.
386	 */
387	static std::string getSubstitutionName(const LLNotificationPtr& notification);
388
389	/**
390	 * Adds notification panel to the IM floater.
391	 */
392	static void addNotifPanelToIM(const LLNotificationPtr& notification);
393
394	/**
395	 * Updates messages of IM floater.
396	 */
397	static void updateIMFLoaterMesages(const LLUUID& session_id);
398
399	/**
400	 * Updates messages of visible IM floater.
401	 */
402	static void updateVisibleIMFLoaterMesages(const LLNotificationPtr& notification);
403
404	/**
405	 * Decrements counter of IM messages.
406	 */
407	static void decIMMesageCounter(const LLNotificationPtr& notification);
408
409private:
410
411	/**
412	 * Find IM floater based on "from_id"
413	 */
414	static LLIMFloater* findIMFloater(const LLNotificationPtr& notification);
415
416};
417
418}
419#endif
420