PageRenderTime 37ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLNOTIFICATIONHANDLER_H
  27. #define LL_LLNOTIFICATIONHANDLER_H
  28. #include "llwindow.h"
  29. //#include "llnotificationsutil.h"
  30. #include "llchannelmanager.h"
  31. #include "llchat.h"
  32. #include "llinstantmessage.h"
  33. #include "llnotificationptr.h"
  34. class LLIMFloater;
  35. namespace LLNotificationsUI
  36. {
  37. // ENotificationType enumerates all possible types of notifications that could be met
  38. //
  39. typedef enum e_notification_type
  40. {
  41. NT_NOTIFY,
  42. NT_NOTIFYTIP,
  43. NT_GROUPNOTIFY,
  44. NT_IMCHAT,
  45. NT_GROUPCHAT,
  46. NT_NEARBYCHAT,
  47. NT_ALERT,
  48. NT_ALERTMODAL,
  49. NT_OFFER
  50. } ENotificationType;
  51. /**
  52. * Handler of notification events.
  53. * This handler manages events related to toasts and chicklets. This is base class
  54. * for chat and system notification handlers.
  55. */
  56. // LLEventHandler is a base class that specifies a common interface for all
  57. // notification handlers. It states, that every handler must react on the follofing
  58. // events:
  59. // - deleting of a toast;
  60. // - initialization of a corresponding channel;
  61. // Also every handler must have the following attributes:
  62. // - type of the notification that this handler is responsible to;
  63. // - pointer to a correspondent screen channel, in which all toasts of the handled notification's
  64. // type should be displayed
  65. // This class also provides the following signald:
  66. // - increment counter signal
  67. // - decrement counter signal
  68. // - update counter signal
  69. // - signal, that emits ID of the notification that is being processed
  70. //
  71. class LLEventHandler
  72. {
  73. public:
  74. virtual ~LLEventHandler() {};
  75. // callbacks for counters
  76. typedef boost::function<void (void)> notification_callback_t;
  77. typedef boost::signals2::signal<void (void)> notification_signal_t;
  78. notification_signal_t mNewNotificationSignal;
  79. notification_signal_t mDelNotificationSignal;
  80. boost::signals2::connection setNewNotificationCallback(notification_callback_t cb) { return mNewNotificationSignal.connect(cb); }
  81. boost::signals2::connection setDelNotification(notification_callback_t cb) { return mDelNotificationSignal.connect(cb); }
  82. // callback for notification/toast
  83. typedef boost::function<void (const LLUUID id)> notification_id_callback_t;
  84. typedef boost::signals2::signal<void (const LLUUID id)> notification_id_signal_t;
  85. notification_id_signal_t mNotificationIDSignal;
  86. boost::signals2::connection setNotificationIDCallback(notification_id_callback_t cb) { return mNotificationIDSignal.connect(cb); }
  87. protected:
  88. virtual void onDeleteToast(LLToast* toast)=0;
  89. // arrange handler's channel on a screen
  90. // is necessary to unbind a moment of creation of a channel and a moment of positioning of it
  91. // it is useful when positioning depends on positions of other controls, that could not be created
  92. // at the moment, when a handlers creates a channel.
  93. virtual void initChannel()=0;
  94. LLScreenChannelBase* mChannel;
  95. e_notification_type mType;
  96. };
  97. // LLSysHandler and LLChatHandler are more specific base classes
  98. // that divide all notification handlers on to groups:
  99. // - handlers for different system notifications (script dialogs, tips, group notices, alerts and IMs);
  100. // - handlers for different messaging notifications (nearby chat)
  101. /**
  102. * Handler for system notifications.
  103. */
  104. class LLSysHandler : public LLEventHandler
  105. {
  106. public:
  107. LLSysHandler();
  108. virtual ~LLSysHandler() {};
  109. virtual bool processNotification(const LLSD& notify)=0;
  110. protected :
  111. static void init();
  112. void removeExclusiveNotifications(const LLNotificationPtr& notif);
  113. typedef std::list< std::set<std::string> > exclusive_notif_sets;
  114. static exclusive_notif_sets sExclusiveNotificationGroups;
  115. };
  116. /**
  117. * Handler for chat message notifications.
  118. */
  119. class LLChatHandler : public LLEventHandler
  120. {
  121. public:
  122. virtual ~LLChatHandler() {};
  123. virtual void processChat(const LLChat& chat_msg, const LLSD &args)=0;
  124. };
  125. /**
  126. * Handler for IM notifications.
  127. * It manages life time of IMs, group messages.
  128. */
  129. class LLIMHandler : public LLSysHandler
  130. {
  131. public:
  132. LLIMHandler(e_notification_type type, const LLSD& id);
  133. virtual ~LLIMHandler();
  134. // base interface functions
  135. virtual bool processNotification(const LLSD& notify);
  136. protected:
  137. virtual void onDeleteToast(LLToast* toast);
  138. virtual void initChannel();
  139. };
  140. /**
  141. * Handler for system informational notices.
  142. * It manages life time of tip notices.
  143. */
  144. class LLTipHandler : public LLSysHandler
  145. {
  146. public:
  147. LLTipHandler(e_notification_type type, const LLSD& id);
  148. virtual ~LLTipHandler();
  149. // base interface functions
  150. virtual bool processNotification(const LLSD& notify);
  151. protected:
  152. virtual void onDeleteToast(LLToast* toast);
  153. virtual void onRejectToast(const LLUUID& id);
  154. virtual void initChannel();
  155. };
  156. /**
  157. * Handler for system informational notices.
  158. * It manages life time of script notices.
  159. */
  160. class LLScriptHandler : public LLSysHandler
  161. {
  162. public:
  163. LLScriptHandler(e_notification_type type, const LLSD& id);
  164. virtual ~LLScriptHandler();
  165. // base interface functions
  166. virtual bool processNotification(const LLSD& notify);
  167. protected:
  168. virtual void onDeleteToast(LLToast* toast);
  169. virtual void initChannel();
  170. // own handlers
  171. void onRejectToast(LLUUID& id);
  172. };
  173. /**
  174. * Handler for group system notices.
  175. */
  176. class LLGroupHandler : public LLSysHandler
  177. {
  178. public:
  179. LLGroupHandler(e_notification_type type, const LLSD& id);
  180. virtual ~LLGroupHandler();
  181. // base interface functions
  182. virtual bool processNotification(const LLSD& notify);
  183. protected:
  184. virtual void onDeleteToast(LLToast* toast);
  185. virtual void initChannel();
  186. // own handlers
  187. void onRejectToast(LLUUID& id);
  188. };
  189. /**
  190. * Handler for alert system notices.
  191. */
  192. class LLAlertHandler : public LLSysHandler
  193. {
  194. public:
  195. LLAlertHandler(e_notification_type type, const LLSD& id);
  196. virtual ~LLAlertHandler();
  197. void setAlertMode(bool is_modal) { mIsModal = is_modal; }
  198. // base interface functions
  199. virtual bool processNotification(const LLSD& notify);
  200. protected:
  201. virtual void onDeleteToast(LLToast* toast);
  202. virtual void initChannel();
  203. bool mIsModal;
  204. };
  205. /**
  206. * Handler for offers notices.
  207. * It manages life time of offer notices.
  208. */
  209. class LLOfferHandler : public LLSysHandler
  210. {
  211. public:
  212. LLOfferHandler(e_notification_type type, const LLSD& id);
  213. virtual ~LLOfferHandler();
  214. // base interface functions
  215. virtual bool processNotification(const LLSD& notify);
  216. protected:
  217. virtual void onDeleteToast(LLToast* toast);
  218. virtual void initChannel();
  219. // own handlers
  220. void onRejectToast(LLUUID& id);
  221. };
  222. /**
  223. * Handler for UI hints.
  224. */
  225. class LLHintHandler : public LLSingleton<LLHintHandler>
  226. {
  227. public:
  228. LLHintHandler();
  229. virtual ~LLHintHandler();
  230. // base interface functions
  231. virtual bool processNotification(const LLSD& notify);
  232. };
  233. /**
  234. * Handler for browser notifications
  235. */
  236. class LLBrowserNotification : public LLSingleton<LLBrowserNotification>
  237. {
  238. public:
  239. virtual bool processNotification(const LLSD& notify);
  240. };
  241. /**
  242. * Handler for outbox notifications
  243. */
  244. class LLOutboxNotification : public LLSingleton<LLOutboxNotification>
  245. {
  246. public:
  247. virtual bool processNotification(const LLSD& notify);
  248. };
  249. class LLHandlerUtil
  250. {
  251. public:
  252. /**
  253. * Checks sufficient conditions to log notification message to IM session.
  254. */
  255. static bool canLogToIM(const LLNotificationPtr& notification);
  256. /**
  257. * Checks sufficient conditions to log notification message to nearby chat session.
  258. */
  259. static bool canLogToNearbyChat(const LLNotificationPtr& notification);
  260. /**
  261. * Checks sufficient conditions to spawn IM session.
  262. */
  263. static bool canSpawnIMSession(const LLNotificationPtr& notification);
  264. /**
  265. * Checks sufficient conditions to add notification toast panel IM floater.
  266. */
  267. static bool canAddNotifPanelToIM(const LLNotificationPtr& notification);
  268. /**
  269. * Checks whether notification can be used multiple times or not.
  270. */
  271. static bool isNotificationReusable(const LLNotificationPtr& notification);
  272. /**
  273. * Checks if passed notification can create IM session and be written into it.
  274. *
  275. * This method uses canLogToIM() & canSpawnIMSession().
  276. */
  277. static bool canSpawnSessionAndLogToIM(const LLNotificationPtr& notification);
  278. /**
  279. * Checks if passed notification can create toast.
  280. */
  281. static bool canSpawnToast(const LLNotificationPtr& notification);
  282. /**
  283. * Determines whether IM floater is opened.
  284. */
  285. static bool isIMFloaterOpened(const LLNotificationPtr& notification);
  286. /**
  287. * Determines whether IM floater is focused.
  288. */
  289. static bool isIMFloaterFocused(const LLNotificationPtr& notification);
  290. /**
  291. * Writes notification message to IM session.
  292. */
  293. static void logToIM(const EInstantMessage& session_type,
  294. const std::string& session_name, const std::string& from_name,
  295. const std::string& message, const LLUUID& session_owner_id,
  296. const LLUUID& from_id);
  297. /**
  298. * Writes notification message to IM p2p session.
  299. */
  300. static void logToIMP2P(const LLNotificationPtr& notification);
  301. /**
  302. * Writes notification message to IM p2p session.
  303. */
  304. static void logToIMP2P(const LLNotificationPtr& notification, bool to_file_only);
  305. /**
  306. * Writes group notice notification message to IM group session.
  307. */
  308. static void logGroupNoticeToIMGroup(const LLNotificationPtr& notification);
  309. /**
  310. * Writes notification message to nearby chat.
  311. */
  312. static void logToNearbyChat(const LLNotificationPtr& notification, EChatSourceType type);
  313. /**
  314. * Spawns IM session.
  315. */
  316. static LLUUID spawnIMSession(const std::string& name, const LLUUID& from_id);
  317. /**
  318. * Returns name from the notification's substitution.
  319. *
  320. * Methods gets "NAME" or "[NAME]" from the substitution map.
  321. *
  322. * @param notification - Notification which substitution's name will be returned.
  323. */
  324. static std::string getSubstitutionName(const LLNotificationPtr& notification);
  325. /**
  326. * Adds notification panel to the IM floater.
  327. */
  328. static void addNotifPanelToIM(const LLNotificationPtr& notification);
  329. /**
  330. * Updates messages of IM floater.
  331. */
  332. static void updateIMFLoaterMesages(const LLUUID& session_id);
  333. /**
  334. * Updates messages of visible IM floater.
  335. */
  336. static void updateVisibleIMFLoaterMesages(const LLNotificationPtr& notification);
  337. /**
  338. * Decrements counter of IM messages.
  339. */
  340. static void decIMMesageCounter(const LLNotificationPtr& notification);
  341. private:
  342. /**
  343. * Find IM floater based on "from_id"
  344. */
  345. static LLIMFloater* findIMFloater(const LLNotificationPtr& notification);
  346. };
  347. }
  348. #endif