llfloaternewim.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /**
  2. * @file llfloaternewim.cpp
  3. * @brief Panel allowing the user to create a new IM session.
  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. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaternewim.h"
  34. #include "llnamelistctrl.h"
  35. #include "lltabcontainer.h"
  36. #include "lluictrlfactory.h"
  37. #include "llimmgr.h"
  38. #include "llmutelist.h"
  39. LLFloaterNewIM::LLFloaterNewIM()
  40. {
  41. LLUICtrlFactory::getInstance()->buildFloater(this, "floater_new_im.xml");
  42. }
  43. bool LLFloaterNewIM::postBuild()
  44. {
  45. childSetAction("start_btn", &LLFloaterNewIM::onStart, this);
  46. childSetAction("close_btn", &LLFloaterNewIM::onClickClose, this);
  47. mGroupList = getChild<LLNameListCtrl>("group_list");
  48. mGroupList->setCommitOnSelectionChange(true);
  49. childSetCommitCallback("group_list", onSelectGroup, this);
  50. mGroupList->setDoubleClickCallback(&LLFloaterNewIM::onStart);
  51. mGroupList->setCallbackUserData(this);
  52. mAgentList = getChild<LLNameListCtrl>("user_list");
  53. mAgentList->setCommitOnSelectionChange(true);
  54. childSetCommitCallback("user_list", onSelectAgent, this);
  55. mAgentList->setDoubleClickCallback(&LLFloaterNewIM::onStart);
  56. mAgentList->setCallbackUserData(this);
  57. setDefaultBtn("start_btn");
  58. return true;
  59. }
  60. LLFloaterNewIM::~LLFloaterNewIM()
  61. {
  62. clearAllTargets();
  63. }
  64. void LLFloaterNewIM::clearAllTargets()
  65. {
  66. mGroupList->deleteAllItems();
  67. mAgentList->deleteAllItems();
  68. }
  69. void LLFloaterNewIM::addGroup(const LLUUID& uuid, void* data)
  70. {
  71. uuid_vec_t selection = mGroupList->getSelectedIDs();
  72. LLSD row;
  73. row["id"] = uuid;
  74. row["target"] = "GROUP";
  75. row["columns"][0]["value"] = ""; // name will be looked up
  76. row["columns"][0]["font"] = "SANSSERIF";
  77. bool muted = LLMuteList::isMuted(uuid, LLMute::flagTextChat);
  78. row["columns"][0]["font-style"] = muted ? "NORMAL" : "BOLD";
  79. LLScrollListItem* itemp = mGroupList->addElement(row, ADD_SORTED);
  80. itemp->setUserdata(data);
  81. itemp->setEnabled(!muted);
  82. mGroupList->selectMultiple(selection);
  83. if (mGroupList->getFirstSelectedIndex() == -1)
  84. {
  85. mGroupList->selectFirstItem();
  86. }
  87. }
  88. void LLFloaterNewIM::addAgent(const LLUUID& uuid, void* data, bool online)
  89. {
  90. uuid_vec_t selection = mAgentList->getSelectedIDs();
  91. std::string fullname;
  92. if (gCacheNamep)
  93. {
  94. gCacheNamep->getFullName(uuid, fullname);
  95. }
  96. LLSD row;
  97. row["id"] = uuid;
  98. row["columns"][0]["value"] = fullname;
  99. row["columns"][0]["font"] = "SANSSERIF";
  100. row["columns"][0]["font-style"] = online ? "BOLD" : "NORMAL";
  101. LLScrollListItem* itemp = mAgentList->addElement(row);
  102. itemp->setUserdata(data);
  103. mAgentList->selectMultiple(selection);
  104. if (mAgentList->getFirstSelectedIndex() == -1)
  105. {
  106. mAgentList->selectFirstItem();
  107. }
  108. }
  109. //static
  110. void LLFloaterNewIM::onSelectGroup(LLUICtrl*, void* userdata)
  111. {
  112. LLFloaterNewIM* self = (LLFloaterNewIM*)userdata;
  113. LLScrollListItem *item = self->mAgentList->getFirstSelected();
  114. if (item)
  115. {
  116. item->setSelected(false);
  117. }
  118. }
  119. //static
  120. void LLFloaterNewIM::onSelectAgent(LLUICtrl*, void* userdata)
  121. {
  122. LLFloaterNewIM* self = (LLFloaterNewIM*)userdata;
  123. LLScrollListItem *item = self->mGroupList->getFirstSelected();
  124. if (item)
  125. {
  126. item->setSelected(false);
  127. }
  128. }
  129. //static
  130. void LLFloaterNewIM::onStart(void* userdata)
  131. {
  132. if (!gIMMgrp) return;
  133. LLFloaterNewIM* self = (LLFloaterNewIM*)userdata;
  134. LLScrollListItem* item = self->mGroupList->getFirstSelected();
  135. if (!item)
  136. {
  137. item = self->mAgentList->getFirstSelected();
  138. }
  139. if (item)
  140. {
  141. const LLScrollListCell* cell = item->getColumn(0);
  142. std::string name(cell->getValue());
  143. // *NOTE: Do a live determination of what type of session it should be.
  144. EInstantMessage type;
  145. EInstantMessage* t = (EInstantMessage*)item->getUserdata();
  146. if (t)
  147. {
  148. type = *t;
  149. }
  150. else
  151. {
  152. type = LLIMMgr::defaultIMTypeForAgent(item->getUUID());
  153. }
  154. if (type != IM_SESSION_GROUP_START)
  155. {
  156. if (gCacheNamep)
  157. {
  158. // Needed to avoid catching a display name, which would make us
  159. // use a wrong IM log file...
  160. gCacheNamep->getFullName(item->getUUID(), name);
  161. }
  162. }
  163. else if (LLMuteList::isMuted(item->getUUID(), LLMute::flagTextChat))
  164. {
  165. make_ui_sound("UISndInvalidOp");
  166. return;
  167. }
  168. gIMMgrp->addSession(name, type, item->getUUID());
  169. make_ui_sound("UISndStartIM");
  170. }
  171. else
  172. {
  173. make_ui_sound("UISndInvalidOp");
  174. }
  175. }
  176. // static
  177. void LLFloaterNewIM::onClickClose(void *userdata)
  178. {
  179. if (gIMMgrp)
  180. {
  181. gIMMgrp->setFloaterOpen(false);
  182. }
  183. }
  184. bool LLFloaterNewIM::handleKeyHere(KEY key, MASK mask)
  185. {
  186. bool handled = LLFloater::handleKeyHere(key, mask);
  187. if (KEY_ESCAPE == key && mask == MASK_NONE)
  188. {
  189. handled = true;
  190. // Close talk panel on escape
  191. if (gIMMgrp)
  192. {
  193. gIMMgrp->toggle(NULL);
  194. }
  195. }
  196. // Might need to call base class here if not handled
  197. return handled;
  198. }
  199. bool LLFloaterNewIM::canClose()
  200. {
  201. if (getHost())
  202. {
  203. LLMultiFloater* hostp = (LLMultiFloater*)getHost();
  204. // if we are the only tab in the im view, go ahead and close
  205. return hostp->getFloaterCount() == 1;
  206. }
  207. return true;
  208. }
  209. void LLFloaterNewIM::close(bool app_quitting)
  210. {
  211. if (getHost())
  212. {
  213. LLMultiFloater* hostp = (LLMultiFloater*)getHost();
  214. hostp->close();
  215. }
  216. else
  217. {
  218. LLFloater::close(app_quitting);
  219. }
  220. }
  221. S32 LLFloaterNewIM::getGroupScrollPos()
  222. {
  223. return mGroupList->getScrollPos();
  224. }
  225. void LLFloaterNewIM::setGroupScrollPos(S32 pos)
  226. {
  227. mGroupList->setScrollPos(pos);
  228. }
  229. S32 LLFloaterNewIM::getAgentScrollPos()
  230. {
  231. return mAgentList->getScrollPos();
  232. }
  233. void LLFloaterNewIM::setAgentScrollPos(S32 pos)
  234. {
  235. mAgentList->setScrollPos(pos);
  236. }