llfloaterim.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /**
  2. * @file llfloaterim.h
  3. * @brief LLFloaterIM and LLFloaterIMSession classes definition
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_FLOATERIM_H
  33. #define LL_FLOATERIM_H
  34. #include "llavatarnamecache.h"
  35. #include "hbfastset.h"
  36. #include "llfloater.h"
  37. #include "llinstantmessage.h"
  38. #include "llstyle.h"
  39. #include "lluistring.h"
  40. class LLButton;
  41. class LLLineEditor;
  42. class LLViewerTextEditor;
  43. class LLInventoryItem;
  44. class LLInventoryCategory;
  45. class LLIMSpeakerMgr;
  46. class LLPanelActiveSpeakers;
  47. class LLSliderCtrl;
  48. class LLVoiceChannel;
  49. class LLFloaterIMSession final : public LLFloater
  50. {
  51. protected:
  52. LOG_CLASS(LLFloaterIMSession);
  53. public:
  54. // The session id is the id of the session this is for. The target refers
  55. // to the user (or group) that where this session serves as the default.
  56. // For example, if you open a session though a calling card, a new session
  57. // id will be generated, but the target_id will be the agent referenced by
  58. // the calling card.
  59. LLFloaterIMSession(const std::string& session_label,
  60. const LLUUID& session_id, const LLUUID& target_id,
  61. EInstantMessage dialog);
  62. LLFloaterIMSession(const std::string& session_label,
  63. const LLUUID& session_id, const LLUUID& target_id,
  64. const uuid_vec_t& ids, const LLSD& voice_channel_info,
  65. EInstantMessage dialog);
  66. ~LLFloaterIMSession() override;
  67. void lookupName();
  68. static void onAvatarNameLookup(const LLUUID& id,
  69. const LLAvatarName& avatar_name,
  70. void* user_data);
  71. bool postBuild() override;
  72. void draw() override;
  73. void onClose(bool app_quitting = false) override;
  74. void setVisible(bool b) override;
  75. void onVisibilityChange(bool new_visibility) override;
  76. // Add target ids to the session.
  77. // Return true if successful, otherwise false.
  78. bool inviteToSession(const uuid_vec_t& agent_ids);
  79. void addHistoryLine(const std::string& utf8msg,
  80. const LLColor4& color = LLColor4::white,
  81. bool log_to_file = true,
  82. const LLUUID& source = LLUUID::null,
  83. const std::string& name = LLStringUtil::null);
  84. void setInputFocus(bool b);
  85. void selectAll();
  86. void selectNone();
  87. LL_INLINE S32 getNumUnreadMessages() { return mNumUnreadMessages; }
  88. bool handleKeyHere(KEY key, MASK mask) override;
  89. bool handleDragAndDrop(S32 x, S32 y, MASK mask,
  90. bool drop, EDragAndDropType cargo_type,
  91. void* cargo_data, EAcceptance* accept,
  92. std::string& tooltip_msg) override;
  93. // Callbacks for P2P muting and volume control
  94. static void onClickMuteVoice(void* user_data);
  95. static void onVolumeChange(LLUICtrl* source, void* user_data);
  96. LL_INLINE const LLUUID& getSessionID() const { return mSessionUUID; }
  97. LL_INLINE const LLUUID& getOtherParticipantID() const
  98. {
  99. return mOtherParticipantUUID;
  100. }
  101. void updateSpeakersList(const LLSD& speaker_updates);
  102. void processSessionUpdate(const LLSD& update);
  103. void setSpeakers(const LLSD& speaker_list);
  104. LL_INLINE LLVoiceChannel* getVoiceChannel() { return mVoiceChannel; }
  105. LL_INLINE EInstantMessage getDialogType() const { return mDialog; }
  106. LL_INLINE bool isGroupSession() const { return mIsGroupSession; }
  107. LL_INLINE const std::string& getSessionName() const { return mSessionLabel; }
  108. void requestAutoConnect();
  109. void sessionInitReplyReceived(const LLUUID& im_session_id);
  110. // Handle other participant in the session typing.
  111. void processIMTyping(const LLUUID& from_id, const std::string& name,
  112. bool typing);
  113. static void chatFromLog(S32 type, const LLSD& data, void* userdata);
  114. //show error statuses to the user
  115. void showSessionStartError(const std::string& error_string);
  116. void showSessionEventError(const std::string& event_string,
  117. const std::string& error_string);
  118. void showSessionForceClose(const std::string& reason);
  119. static bool onConfirmForceCloseError(const LLSD& notification,
  120. const LLSD& response);
  121. static LLFloaterIMSession* findInstance(const LLUUID& session_id);
  122. static void closeAllInstances();
  123. // Used before invoking close() in order to snooze a group IM session
  124. // instead of leaving it for good. 'duration' is in minutes. If the IM
  125. // session is not a group one, the method aborts and returns false.
  126. bool setSnoozeDuration(U32 duration);
  127. void sendText(LLWString text);
  128. // Used by llimmgr.cpp
  129. static void onClickStartCall(void* userdata);
  130. private:
  131. // Called by constructors
  132. void init(const std::string& session_label);
  133. // Called by UI methods.
  134. void sendMsg();
  135. void addQueuedMessages();
  136. void logToFile(const std::string& line, bool allow_timestamp = true);
  137. // For adding agents via the UI. Return true if possible, do it if
  138. bool dropCallingCard(LLInventoryItem* item, bool drop);
  139. bool dropCategory(LLInventoryCategory* category, bool drop);
  140. // Test if local agent can add agents.
  141. bool isInviteAllowed() const;
  142. // Called whenever the user starts or stops typing.
  143. // Sends the typing state to the other user if necessary.
  144. void setTyping(bool typing);
  145. // Static, callback version
  146. static void setIMTyping(void* caller, bool typing);
  147. // Add the "User is typing..." indicator.
  148. void addTypingIndicator(const LLUUID& from_id,
  149. const std::string& from_name);
  150. // Remove the "User is typing..." indicator.
  151. void removeTypingIndicator(const LLUUID& from_id = LLUUID::null);
  152. void sendTypingState(bool typing);
  153. void disableWhileSessionStarting();
  154. static void onInputEditorFocusReceived(LLFocusableElement* caller,
  155. void* userdata);
  156. static void onInputEditorFocusLost(LLFocusableElement* caller,
  157. void* userdata);
  158. static void onInputEditorKeystroke(LLLineEditor* caller, void* userdata);
  159. static void onInputEditorScrolled(LLLineEditor* caller, void* userdata);
  160. static void onCommitChat(LLUICtrl* caller, void* userdata);
  161. static void onTabClick(void* userdata);
  162. static void onCommitAvatar(LLUICtrl* ctrl, void* userdata);
  163. static void onClickViewLog(void* userdata);
  164. static void onClickGroupInfo(void* userdata);
  165. static void onClickClose(void* userdata);
  166. static void onClickSnooze(void* userdata);
  167. static void onClickEndCall(void* userdata);
  168. static void onClickSend(void* userdata);
  169. static void onClickOpenTextEditor(void* userdata);
  170. static void onClickToggleActiveSpeakers(void* userdata);
  171. static void* createSpeakersPanel(void* data);
  172. private:
  173. LLLineEditor* mInputEditor;
  174. LLViewerTextEditor* mHistoryEditor;
  175. LLButton* mOpenTextEditorButton;
  176. LLButton* mSendButton;
  177. LLButton* mStartCallButton;
  178. LLButton* mEndCallButton;
  179. LLButton* mSnoozeButton;
  180. LLButton* mViewLogButton;
  181. LLButton* mToggleSpeakersButton;
  182. LLButton* mMuteButton;
  183. LLSliderCtrl* mSpeakerVolumeSlider;
  184. // The value of the mSessionUUID depends on how the IM session was started:
  185. // one-on-one ==> random id
  186. // group ==> group_id
  187. // inventory folder ==> folder item_id
  188. // 911 ==> Gaurdian_Angel_Group_ID ^ gAgentID
  189. LLUUID mSessionUUID;
  190. std::string mSessionLabel;
  191. std::string mSessionLog;
  192. std::string mLogFileName;
  193. LLVoiceChannel* mVoiceChannel;
  194. LLSD mVoiceChannelInfo;
  195. LLSD mQueuedMsgsForInit;
  196. // The value mOtherParticipantUUID depends on how the IM session was
  197. // started:
  198. // one-on-one = recipient's id
  199. // group ==> group_id
  200. // inventory folder ==> first target id in list
  201. // 911 ==> sender
  202. LLUUID mOtherParticipantUUID;
  203. uuid_vec_t mSessionInitialTargetIDs;
  204. EInstantMessage mDialog;
  205. // Name of other user who is currently typing
  206. std::string mOtherTypingName;
  207. // Where does the "User is typing..." line start ?
  208. S32 mTypingLineStartIndex;
  209. S32 mNumUnreadMessages;
  210. U32 mSnoozeDuration;
  211. LLIMSpeakerMgr* mSpeakers;
  212. LLPanelActiveSpeakers* mSpeakerPanel;
  213. // Optimization: Don't send "User is typing..." until the user has
  214. // actually been typing for a little while. Prevents extra IMs for brief
  215. // "lol" type utterences.
  216. LLFrameTimer mFirstKeystrokeTimer;
  217. // Timer to detect when user has stopped typing.
  218. LLFrameTimer mLastKeystrokeTimer;
  219. // Used while fetching the log from the server, to queue incoming mesages
  220. // and avoid out of order displaying in mHistoryEditor. HB
  221. struct QueuedMessage
  222. {
  223. LL_INLINE QueuedMessage(const LLUUID& src_id, const std::string& from,
  224. const std::string& text, const LLColor4& color,
  225. bool log)
  226. : mSourceId(src_id),
  227. mFrom(from),
  228. mText(text),
  229. mColor(color),
  230. mLog(log)
  231. {
  232. }
  233. LLUUID mSourceId;
  234. std::string mFrom;
  235. std::string mText;
  236. LLColor4 mColor;
  237. bool mLog;
  238. };
  239. typedef std::vector<QueuedMessage> messages_buffer_t;
  240. messages_buffer_t mMessagesBuffer;
  241. // Set to true when fetching the server log and needing to queue incoming
  242. // messages till done. HB
  243. bool mFetchingLog;
  244. bool mSessionInitialized;
  245. bool mIsGroupSession;
  246. bool mHasScrolledOnce;
  247. // Are you currently typing ?
  248. bool mTyping;
  249. // Is other user currently typing ?
  250. bool mOtherTyping;
  251. bool mSentTypingState;
  252. bool mShowSpeakersOnConnect;
  253. bool mAutoConnect;
  254. bool mProfileButtonEnabled;
  255. typedef fast_hset<LLFloaterIMSession*> instances_list_t;
  256. static instances_list_t sFloaterIMSessions;
  257. };
  258. class LLFloaterIM final : public LLMultiFloater
  259. {
  260. public:
  261. LLFloaterIM();
  262. bool postBuild() override;
  263. public:
  264. // Used as well by llimmgr.cpp
  265. static std::string sOfflineMessage;
  266. static std::string sOnlyUserMessage;
  267. static std::string sMutedMessage;
  268. typedef std::map<std::string, std::string> strings_map_t;
  269. static strings_map_t sMsgStringsMap;
  270. };
  271. #endif // LL_FLOATERIM_H