diff options
author | McCabe Maxsted | 2010-06-05 11:23:13 -0700 |
---|---|---|
committer | Jacek Antonelli | 2010-06-19 02:43:31 -0500 |
commit | f96a6b0675c218b3671085e5c228eb52a1718906 (patch) | |
tree | 3e4b271c15c7bfce830fc2a5cb9b99aa315a233c /linden/indra/newview/hbfloatergrouptitles.cpp | |
parent | Updated llcharacter with some bits from Emerald and SnowGlobe (diff) | |
download | meta-impy-f96a6b0675c218b3671085e5c228eb52a1718906.zip meta-impy-f96a6b0675c218b3671085e5c228eb52a1718906.tar.gz meta-impy-f96a6b0675c218b3671085e5c228eb52a1718906.tar.bz2 meta-impy-f96a6b0675c218b3671085e5c228eb52a1718906.tar.xz |
Ported group titles window from the Cool Viewer and placed it in the groups list
Diffstat (limited to 'linden/indra/newview/hbfloatergrouptitles.cpp')
-rw-r--r-- | linden/indra/newview/hbfloatergrouptitles.cpp | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/linden/indra/newview/hbfloatergrouptitles.cpp b/linden/indra/newview/hbfloatergrouptitles.cpp new file mode 100644 index 0000000..bd6de9e --- /dev/null +++ b/linden/indra/newview/hbfloatergrouptitles.cpp | |||
@@ -0,0 +1,246 @@ | |||
1 | /** | ||
2 | * @file hbfloatergrouptitles.h | ||
3 | * @brief HBFloaterGroupTitles class implementation | ||
4 | * | ||
5 | * This class implements a floater where all available group titles are | ||
6 | * listed, allowing the user to activate any via simple double-click. | ||
7 | * | ||
8 | * $LicenseInfo:firstyear=2010&license=viewergpl$ | ||
9 | * | ||
10 | * Copyright (c) 2010, Henri Beauchamp. | ||
11 | * | ||
12 | * Second Life Viewer Source Code | ||
13 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
14 | * to you under the terms of the GNU General Public License, version 2.0 | ||
15 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
16 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
17 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
18 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
19 | * | ||
20 | * There are special exceptions to the terms and conditions of the GPL as | ||
21 | * it is applied to this Source Code. View the full text of the exception | ||
22 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
23 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
24 | * | ||
25 | * By copying, modifying or distributing this software, you acknowledge | ||
26 | * that you have read and understood your obligations described above, | ||
27 | * and agree to abide by those obligations. | ||
28 | * | ||
29 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
30 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
31 | * COMPLETENESS OR PERFORMANCE. | ||
32 | * $/LicenseInfo$ | ||
33 | */ | ||
34 | |||
35 | #include "llviewerprecompiledheaders.h" | ||
36 | |||
37 | #include "message.h" | ||
38 | #include "roles_constants.h" | ||
39 | |||
40 | #include "hbfloatergrouptitles.h" | ||
41 | |||
42 | #include "llagent.h" | ||
43 | #include "lluictrlfactory.h" | ||
44 | #include "llviewercontrol.h" | ||
45 | |||
46 | // static variable | ||
47 | HBFloaterGroupTitles* HBFloaterGroupTitles::sInstance = NULL; | ||
48 | |||
49 | // helper function | ||
50 | void update_titles_list(HBFloaterGroupTitles* self); | ||
51 | |||
52 | |||
53 | // HBFloaterGroupTitlesObserver class | ||
54 | |||
55 | HBFloaterGroupTitlesObserver::HBFloaterGroupTitlesObserver(HBFloaterGroupTitles* instance, const LLUUID& group_id) | ||
56 | : LLGroupMgrObserver(group_id), | ||
57 | mFloaterInstance(instance) | ||
58 | { | ||
59 | LLGroupMgr::getInstance()->addObserver(this); | ||
60 | } | ||
61 | |||
62 | // virtual | ||
63 | HBFloaterGroupTitlesObserver::~HBFloaterGroupTitlesObserver() | ||
64 | { | ||
65 | LLGroupMgr::getInstance()->removeObserver(this); | ||
66 | } | ||
67 | |||
68 | // virtual | ||
69 | void HBFloaterGroupTitlesObserver::changed(LLGroupChange gc) | ||
70 | { | ||
71 | if (gc == GC_TITLES) | ||
72 | { | ||
73 | update_titles_list(mFloaterInstance); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | |||
78 | // HBFloaterGroupTitles class | ||
79 | |||
80 | HBFloaterGroupTitles::HBFloaterGroupTitles() | ||
81 | : LLFloater(std::string("group titles")), | ||
82 | mFirstUse(true) | ||
83 | { | ||
84 | LLUICtrlFactory::getInstance()->buildFloater(this, "floater_group_titles.xml", NULL); | ||
85 | sInstance = this; | ||
86 | } | ||
87 | |||
88 | // virtual | ||
89 | HBFloaterGroupTitles::~HBFloaterGroupTitles() | ||
90 | { | ||
91 | while (!mObservers.empty()) | ||
92 | { | ||
93 | HBFloaterGroupTitlesObserver* observer = mObservers.back(); | ||
94 | delete observer; | ||
95 | mObservers.pop_back(); | ||
96 | } | ||
97 | sInstance = NULL; | ||
98 | } | ||
99 | |||
100 | // static | ||
101 | void HBFloaterGroupTitles::toggle() | ||
102 | { | ||
103 | // I hate things that don't toggle -- MC | ||
104 | if (!sInstance) | ||
105 | { | ||
106 | sInstance = new HBFloaterGroupTitles(); | ||
107 | sInstance->setFocus(TRUE); | ||
108 | sInstance->open(); | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | if (sInstance->getVisible()) | ||
113 | { | ||
114 | sInstance->close(); | ||
115 | } | ||
116 | else | ||
117 | { | ||
118 | sInstance->open(); | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | |||
123 | BOOL HBFloaterGroupTitles::postBuild() | ||
124 | { | ||
125 | mTitlesList = getChild<LLScrollListCtrl>("titles_list"); | ||
126 | if (!mTitlesList) | ||
127 | { | ||
128 | return FALSE; | ||
129 | } | ||
130 | mTitlesList->setCallbackUserData(this); | ||
131 | mTitlesList->setDoubleClickCallback(onActivate); | ||
132 | childSetAction("activate", onActivate, this); | ||
133 | update_titles_list(this); | ||
134 | return TRUE; | ||
135 | } | ||
136 | |||
137 | // static | ||
138 | void HBFloaterGroupTitles::onActivate(void* userdata) | ||
139 | { | ||
140 | HBFloaterGroupTitles* self = (HBFloaterGroupTitles*) userdata; | ||
141 | LLScrollListItem *item = self->mTitlesList->getFirstSelected(); | ||
142 | if (!item) return; | ||
143 | |||
144 | // Set the group if needed. | ||
145 | LLUUID old_group_id = gAgent.getGroupID(); | ||
146 | LLUUID group_id = item->getColumn(LIST_GROUP_ID)->getValue().asUUID(); | ||
147 | if (group_id != old_group_id) | ||
148 | { | ||
149 | LLMessageSystem* msg = gMessageSystem; | ||
150 | msg->newMessageFast(_PREHASH_ActivateGroup); | ||
151 | msg->nextBlockFast(_PREHASH_AgentData); | ||
152 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
153 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
154 | msg->addUUIDFast(_PREHASH_GroupID, group_id); | ||
155 | gAgent.sendReliableMessage(); | ||
156 | } | ||
157 | |||
158 | // Set the title | ||
159 | LLGroupMgr::getInstance()->sendGroupTitleUpdate(group_id, item->getUUID()); | ||
160 | // Force a refresh via the observer | ||
161 | if (group_id == LLUUID::null) | ||
162 | { | ||
163 | group_id = old_group_id; | ||
164 | } | ||
165 | LLGroupMgr::getInstance()->sendGroupTitlesRequest(group_id); | ||
166 | } | ||
167 | |||
168 | void update_titles_list(HBFloaterGroupTitles* self) | ||
169 | { | ||
170 | S32 i; | ||
171 | S32 count = gAgent.mGroups.count(); | ||
172 | LLUUID id; | ||
173 | LLUUID highlight_id = LLUUID::null; | ||
174 | LLUUID current_group_id = gAgent.getGroupID(); | ||
175 | std::vector<LLGroupTitle>::const_iterator citer; | ||
176 | std::string style; | ||
177 | LLGroupData* group_datap; | ||
178 | LLGroupMgrGroupData* gmgr_datap; | ||
179 | |||
180 | if (!self || !self->mTitlesList) return; | ||
181 | LLCtrlListInterface *title_list = self->mTitlesList->getListInterface(); | ||
182 | |||
183 | self->mTitlesList->deleteAllItems(); | ||
184 | |||
185 | for (i = 0; i < count; ++i) | ||
186 | { | ||
187 | group_datap = &gAgent.mGroups.get(i); | ||
188 | id = group_datap->mID; | ||
189 | if (self->mFirstUse) | ||
190 | { | ||
191 | HBFloaterGroupTitlesObserver* observer = new HBFloaterGroupTitlesObserver(self, id); | ||
192 | self->mObservers.push_back(observer); | ||
193 | } | ||
194 | gmgr_datap = LLGroupMgr::getInstance()->getGroupData(id); | ||
195 | if (!gmgr_datap) | ||
196 | { | ||
197 | LLGroupMgr::getInstance()->sendGroupTitlesRequest(id); | ||
198 | continue; | ||
199 | } | ||
200 | for (citer = gmgr_datap->mTitles.begin(); citer != gmgr_datap->mTitles.end(); citer++) | ||
201 | { | ||
202 | style = "NORMAL"; | ||
203 | if (current_group_id == id && citer->mSelected) | ||
204 | { | ||
205 | style = "BOLD"; | ||
206 | highlight_id = citer->mRoleID; | ||
207 | } | ||
208 | LLSD element; | ||
209 | element["id"] = citer->mRoleID; | ||
210 | element["columns"][LIST_TITLE]["column"] = "title"; | ||
211 | element["columns"][LIST_TITLE]["value"] = citer->mTitle; | ||
212 | element["columns"][LIST_TITLE]["font-style"] = style; | ||
213 | element["columns"][LIST_GROUP_NAME]["column"] = "group_name"; | ||
214 | element["columns"][LIST_GROUP_NAME]["value"] = group_datap->mName; | ||
215 | element["columns"][LIST_GROUP_NAME]["font-style"] = style; | ||
216 | element["columns"][LIST_GROUP_ID]["column"] = "group_id"; | ||
217 | element["columns"][LIST_GROUP_ID]["value"] = id; | ||
218 | |||
219 | title_list->addElement(element, ADD_SORTED); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | // add "none" to list at top | ||
224 | { | ||
225 | style = "NORMAL"; | ||
226 | if (current_group_id.isNull()) | ||
227 | { | ||
228 | style = "BOLD"; | ||
229 | } | ||
230 | LLSD element; | ||
231 | element["id"] = LLUUID::null; | ||
232 | element["columns"][LIST_TITLE]["column"] = "title"; | ||
233 | element["columns"][LIST_TITLE]["value"] = "none"; | ||
234 | element["columns"][LIST_TITLE]["font-style"] = style; | ||
235 | element["columns"][LIST_GROUP_NAME]["column"] = "group_name"; | ||
236 | element["columns"][LIST_GROUP_NAME]["value"] = "none"; | ||
237 | element["columns"][LIST_GROUP_NAME]["font-style"] = style; | ||
238 | element["columns"][LIST_GROUP_ID]["column"] = "group_id"; | ||
239 | element["columns"][LIST_GROUP_ID]["value"] = LLUUID::null; | ||
240 | |||
241 | title_list->addElement(element, ADD_TOP); | ||
242 | } | ||
243 | |||
244 | title_list->selectByValue(highlight_id); | ||
245 | self->mFirstUse = false; | ||
246 | } | ||