aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterteleporthistory.cpp
blob: 70a2d71cf31b5d6d44003c3fd20ad7c12be2e802 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/**
 * @file llfloaterteleporthistory.cpp
 * @author Zi Ree
 * @brief LLFloaterTeleportHistory class implementation
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 *
 * Copyright (c) 2008, Linden Research, Inc.
 *
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 *
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
 *
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 *
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "linden_common.h"

#include "llfloaterteleporthistory.h"
#include "llfloaterworldmap.h"
#include "lltimer.h"
#include "lluictrlfactory.h"
#include "llurldispatcher.h"
#include "llurlsimstring.h"
#include "llviewercontrol.h"   // gSavedSettings
#include "llviewerwindow.h"
#include "llweb.h"

#include "apr_time.h"

// [RLVa:KB] - Emerald specific
#include "rlvhandler.h"
#include "llsdserialize.h"
// [/RLVa:KB]

// globals
LLFloaterTeleportHistory* gFloaterTeleportHistory;

LLFloaterTeleportHistory::LLFloaterTeleportHistory()
:	LLFloater(std::string("teleporthistory")),
	mPlacesInList(NULL),
	mPlacesOutList(NULL),
	pItem(NULL),
	id(0)
{
	LLUICtrlFactory::getInstance()->buildFloater(this, "floater_teleport_history.xml", NULL);
}

// virtual
LLFloaterTeleportHistory::~LLFloaterTeleportHistory()
{
}

// virtual
void LLFloaterTeleportHistory::onFocusReceived()
{
	// take care to enable or disable buttons depending on the selection in the places list
	if(pItem)
	{
		setButtonsEnabled(TRUE);
	}
	else
	{
		setButtonsEnabled(FALSE);
	}
	LLFloater::onFocusReceived();
}

BOOL LLFloaterTeleportHistory::postBuild()
{
	// make sure the cached pointer to the scroll list is valid
	mPlacesInList=getChild<LLScrollListCtrl>("places_list_in");
	if(!mPlacesInList)
	{
		llwarns << "coud not get pointer to places list in" << llendl;
		return FALSE;
	}
	mPlacesOutList=getChild<LLScrollListCtrl>("places_list_out");
	if(!mPlacesOutList)
	{
		llwarns << "coud not get pointer to places list out" << llendl;
		return FALSE;
	}

	// setup callbacks for the scroll list
	mPlacesInList->setDoubleClickCallback(onTeleport);
	mPlacesOutList->setDoubleClickCallback(onTeleport);
	childSetCommitCallback("places_list_in", onInPlacesSelected, this);
	childSetCommitCallback("places_list_out", onOutPlacesSelected, this);
	childSetAction("teleport", onTeleport, this);
	childSetAction("show_on_map", onShowOnMap, this);
	childSetAction("copy_slurl", onCopySLURL, this);
	loadEntrys();

	return TRUE;
}
void LLFloaterTeleportHistory::saveEntry(LLSD toSave)
{
	tpList.append(toSave);
	std::string filename=getFileName();
	llofstream file;
	file.open(filename.c_str());
	LLSDSerialize::toPrettyXML(tpList, file);
	file.close();
}

std::string LLFloaterTeleportHistory::getFileName()
{
	std::string path=gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "");

	if (!path.empty())
	{
		path = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "teleport_history.xml");
	}
	return path;
}
void LLFloaterTeleportHistory::loadEntrys()
{
	std::string filename=getFileName();
	if (filename.empty())
	{
		llinfos << "no valid user directory." << llendl;
		return;
	}
	llifstream file;
	file.open(filename.c_str());
	if (file.is_open())
		LLSDSerialize::fromXML(tpList, file);
	file.close();

	for(int i = 0;i<(int)tpList.size();i++)
	{
		LLSD data = tpList[i];
		LLScrollListCtrl* pItemPointer;
		if(data["out"].asBoolean())
			pItemPointer=mPlacesOutList;
		else
			pItemPointer=mPlacesInList;

		pItemPointer->addElement(data, ADD_TOP);
		pItemPointer->deselectAllItems(TRUE);
		setButtonsEnabled(FALSE);
		id++;
	}
}
void LLFloaterTeleportHistory::addEntry(std::string regionName, S16 x, S16 y, S16 z,bool outList)
{
	LLScrollListCtrl* pItemPointer;
	if(outList)
		pItemPointer=mPlacesOutList;
	else
		pItemPointer=mPlacesInList;
	// only if the cached scroll list pointer is valid
	if(pItemPointer)
	{
		// prepare display of position
		std::string position=llformat("%d, %d, %d", x, y, z);
		// prepare simstring for later parsing
		std::string simString = regionName + llformat("/%d/%d/%d", x, y, z);
		simString = LLWeb::escapeURL(simString);

		// check if we are in daylight savings time
		std::string timeZone = "PST";
		if(is_daylight_savings()) timeZone = "PDT";

		// do all time related stuff as closely together as possible, because every other operation
		// might change the internal tm* buffer
		struct tm* internal_time;
		internal_time = utc_to_pacific_time(time_corrected(), is_daylight_savings());
		std::string timeString=llformat("%02d/%02d/%04d - %02d:%02d:%02d ",internal_time->tm_mon+1,internal_time->tm_mday,internal_time->tm_year+1900,internal_time->tm_hour, internal_time->tm_min, internal_time->tm_sec)+timeZone;

		// build the list entry
		LLSD value;
		value["id"] = id;
		value["columns"][0]["column"] = "region";
		value["columns"][0]["value"] = regionName;
		value["columns"][1]["column"] = "position";
		value["columns"][1]["value"] = position;
		value["columns"][2]["column"] = "visited";
		value["columns"][2]["value"] = timeString;

		// these columns are hidden and serve as data storage for simstring and SLURL
		value["columns"][3]["column"] = "slurl";
		value["columns"][3]["value"] = LLURLDispatcher::buildSLURL(regionName, x, y, z);
		value["columns"][4]["column"] = "simstring";
		value["columns"][4]["value"] = simString;
		value["out"]=outList;

// [RLVa:KB] - Alternate: Emerald-370
		if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
		{
			// TODO: This is the original code from Emerald. It
			// uses the class RlvStrings, defined in rlvcommon.cpp
			// to load localized strings. For Imprudence we use the
			// old fashioned way via RlvHandler with English
			// strings only!
			// value["columns"][0]["value"] = RlvStrings::getString(RLV_STRING_HIDDEN_REGION);
			// value["columns"][1]["value"] = RlvStrings::getString(RLV_STRING_HIDDEN);
			// value["columns"][3]["value"] = RlvStrings::getString(RLV_STRING_HIDDEN);
			// value["columns"][4]["value"] = RlvStrings::getString(RLV_STRING_HIDDEN);

			 value["columns"][0]["value"] = RlvHandler::cstrHiddenRegion;
			 value["columns"][1]["value"] = RlvHandler::cstrHidden;
			 value["columns"][3]["value"] = RlvHandler::cstrHidden;
			 value["columns"][4]["value"] = RlvHandler::cstrHidden;
		}
// [/RLVa:KB]
		saveEntry(value);
		// add the new list entry on top of the list, deselect all and disable the buttons
		pItemPointer->addElement(value, ADD_TOP);
		pItemPointer->deselectAllItems(TRUE);
		setButtonsEnabled(FALSE);
		id++;
	}
	else
	{
		llwarns << "pointer to places list is NULL" << llendl;
	}
}

void LLFloaterTeleportHistory::setButtonsEnabled(BOOL on)
{
// [RLVa:KB] - Alternate: Emerald-370
	if (rlv_handler_t::isEnabled())
	{
		// TODO: This is the original code from Emerald. It
		// uses the class RlvStrings, defined in rlvcommon.cpp
		// to load localized strings. For Imprudence we use the
		// old fashioned way via RlvHandler with English
		// strings only!
		//if ( (pItem) && (pItem->getColumn(4)) && (RlvStrings::getString(RLV_STRING_HIDDEN) == pItem->getColumn(4)->getValue().asString()) )
		if ( (pItem) && (pItem->getColumn(4)) && (RlvHandler::cstrHidden == pItem->getColumn(4)->getValue().asString()) )
		{
			on = FALSE;
		}
	}
// [/RLVa:K]

	// enable or disable buttons
	childSetEnabled("teleport", on);
	childSetEnabled("show_on_map", on);
	childSetEnabled("copy_slurl", on);
}

// virtual
void LLFloaterTeleportHistory::onClose(bool app_quitting)
{
	LLFloater::setVisible(FALSE);
}

// virtual
BOOL LLFloaterTeleportHistory::canClose()
{
	return !LLApp::isExiting();
}

// callbacks

// static
void LLFloaterTeleportHistory::onInPlacesSelected(LLUICtrl* /* ctrl */, void* data)
{
	LLFloaterTeleportHistory* self = (LLFloaterTeleportHistory*) data;
	self->mPlacesOutList->deselectAllItems();
	self->pItem = self->mPlacesInList->getFirstSelected();
	// on selection change check if we need to enable or disable buttons
	if(self->pItem)
	{
		self->setButtonsEnabled(TRUE);
	}
	else
	{
		self->setButtonsEnabled(FALSE);
	}
}

// static
void LLFloaterTeleportHistory::onOutPlacesSelected(LLUICtrl* /* ctrl */, void* data)
{
	LLFloaterTeleportHistory* self = (LLFloaterTeleportHistory*) data;
	self->mPlacesInList->deselectAllItems();
	self->pItem = self->mPlacesOutList->getFirstSelected();
	// on selection change check if we need to enable or disable buttons
	if(self->pItem)
	{
		self->setButtonsEnabled(TRUE);
	}
	else
	{
		self->setButtonsEnabled(FALSE);
	}
}

// static
void LLFloaterTeleportHistory::onTeleport(void* data)
{
	LLFloaterTeleportHistory* self = (LLFloaterTeleportHistory*) data;

	// build secondlife::/app link from simstring for instant teleport to destination
	std::string slapp="secondlife:///app/teleport/" + self->pItem->getColumn(4)->getValue().asString();
	LLURLDispatcher::dispatch(slapp, NULL, true);
}

// static
void LLFloaterTeleportHistory::onShowOnMap(void* data)
{
	LLFloaterTeleportHistory* self = (LLFloaterTeleportHistory*) data;

	// get simstring from selected entry and parse it for its components
	std::string simString = self->pItem->getColumn(4)->getValue().asString();
	std::string region = "";
	S32 x = 128;
	S32 y = 128;
	S32 z = 20;

	LLURLSimString::parse(simString, &region, &x, &y, &z);

	// point world map at position
	gFloaterWorldMap->trackURL(region, x, y, z);
	LLFloaterWorldMap::show(NULL, TRUE);
}

// static
void LLFloaterTeleportHistory::onCopySLURL(void* data)
{
	LLFloaterTeleportHistory* self = (LLFloaterTeleportHistory*) data;

	// get SLURL of the selected entry and copy it to the clipboard
	std::string SLURL=self->pItem->getColumn(3)->getValue().asString();
	gViewerWindow->mWindow->copyTextToClipboard(utf8str_to_wstring(SLURL));
}