Teleport history now saved to teleport_history.xml. TeleportHistoryMaxEntries specifies how many entries to allow in floater before old entries are dropped.

This commit is contained in:
Shyotl
2011-07-16 23:32:01 -05:00
parent 04ff884c5f
commit 2870d44824
8 changed files with 140 additions and 16 deletions

View File

@@ -9,6 +9,18 @@
<string>settings_rlv.xml</string>
</array>
<key>TeleportHistoryMaxEntries</key>
<map>
<key>Comment</key>
<string>Maximum number of entries to allow in teleport history list.</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>S32</string>
<key>Value</key>
<integer>100</integer>
</map>
<key>AllowLargeSounds</key>
<map>
<key>Comment</key>

View File

@@ -79,6 +79,7 @@
#include "llrender.h"
#include "llfont.h"
#include "llvocache.h"
#include "llfloaterteleporthistory.h"
#include "llweb.h"
#include "llsecondlifeurls.h"
@@ -1450,6 +1451,8 @@ bool LLAppViewer::cleanup()
// Save file- and dirpicker {context, default paths} map.
AIFilePicker::saveFile("filepicker_contexts.xml");
LLFloaterTeleportHistory::saveFile("teleport_history.xml");
// save mute list. gMuteList used to also be deleted here too.
LLMuteList::getInstance()->cache(gAgent.getID());

View File

@@ -49,11 +49,9 @@
#include "llviewercontrol.h"
#include "llviewerwindow.h"
#include "llweb.h"
#include "llsdserialize.h"
// globals
LLFloaterTeleportHistory* gFloaterTeleportHistory;
LLFloaterTeleportHistory::LLFloaterTeleportHistory()
LLFloaterTeleportHistory::LLFloaterTeleportHistory(const LLSD& seed)
: LLFloater(std::string("teleporthistory")),
mPlacesList(NULL),
mID(0)
@@ -171,10 +169,18 @@ void LLFloaterTeleportHistory::addEntry(std::string parcelName)
value["columns"][LIST_SIMSTRING]["value"] = mPendingSimString;
// add the new list entry on top of the list, deselect all and disable the buttons
const S32 max_entries = gSavedSettings.getS32("TeleportHistoryMaxEntries");
S32 num_entries = mPlacesList->getItemCount();
while(num_entries >= max_entries)
{
mPlacesList->deleteItems(LLSD(mID - num_entries--));
}
mPlacesList->addElement(value, ADD_TOP);
mPlacesList->deselectAllItems(TRUE);
setButtonsEnabled(FALSE);
mID++;
saveFile("teleport_history.xml"); //Comment out to disable saving after every teleport.
}
else
{
@@ -191,6 +197,95 @@ void LLFloaterTeleportHistory::setButtonsEnabled(BOOL on)
childSetEnabled("show_on_map", on);
childSetEnabled("copy_slurl", on);
}
//static
void LLFloaterTeleportHistory::loadFile(const std::string &file_name)
{
LLFloaterTeleportHistory *pFloaterHistory = LLFloaterTeleportHistory::findInstance();
if(!pFloaterHistory)
return;
LLScrollListCtrl* pScrollList = pFloaterHistory->mPlacesList;
if(!pScrollList)
return;
std::string temp_str(gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter() + file_name);
llifstream file(temp_str);
if (file.is_open())
{
llinfos << "Loading "<< file_name << " file at " << temp_str << llendl;
LLSD data;
LLSDSerialize::fromXML(data, file);
if (data.isUndefined())
{
llinfos << "file missing, ill-formed, "
"or simply undefined; not reading the"
" file" << llendl;
}
else
{
const S32 max_entries = gSavedSettings.getS32("TeleportHistoryMaxEntries");
const S32 num_entries = llmin(max_entries,(const S32)data.size());
pScrollList->clear();
for(S32 i = 0; i < num_entries; i++) //Lower entry = newer
{
pScrollList->addElement(data[i], ADD_BOTTOM);
}
pScrollList->deselectAllItems(TRUE);
pFloaterHistory->mID = pScrollList->getItemCount();
pFloaterHistory->setButtonsEnabled(FALSE);
}
}
}
//static
void LLFloaterTeleportHistory::saveFile(const std::string &file_name)
{
LLFloaterTeleportHistory *pFloaterHistory = LLFloaterTeleportHistory::findInstance();
if(!pFloaterHistory)
return;
std::string temp_str = gDirUtilp->getLindenUserDir(true);
if( temp_str.empty() )
{
llinfos << "Can't save teleport history - no user directory set yet." << llendl;
return;
}
temp_str += gDirUtilp->getDirDelimiter() + file_name;
llofstream export_file(temp_str);
if (!export_file.good())
{
llwarns << "Unable to open " << file_name << " for output." << llendl;
return;
}
llinfos << "Writing "<< file_name << " file at " << temp_str << llendl;
LLSD elements;
LLScrollListCtrl* pScrollList = pFloaterHistory->mPlacesList;
if (pScrollList)
{
std::vector<LLScrollListItem*> data_list = pScrollList->getAllData();
struct SortByAge {
bool operator() (LLScrollListItem* i,LLScrollListItem* j) { return (i->getValue().asInteger()>j->getValue().asInteger());}
} sorter;
std::sort(data_list.begin(),data_list.end(),sorter);//Re-sort. Column sorting may have mucked the list up. Newer entries in front.
for (std::vector<LLScrollListItem*>::iterator itr = data_list.begin(); itr != data_list.end(); ++itr)
{
//Pack into LLSD mimicing one passed to addElement
LLSD data_entry;
//id is actually reverse of the indexing of the element LLSD. Higher id = newer.
data_entry["id"] = pScrollList->getItemCount() - elements.size() - 1;
for(S32 i = 0; i < (*itr)->getNumColumns(); ++i)
{
data_entry["columns"][i]["column"]=pScrollList->getColumn(i)->mName;
data_entry["columns"][i]["value"]=(*itr)->getColumn(i)->getValue();
}
elements.append(data_entry);
}
}
LLSDSerialize::toXML(elements, export_file);
export_file.close();
}
// virtual
void LLFloaterTeleportHistory::onClose(bool app_quitting)

View File

@@ -43,10 +43,10 @@
#include "llfloater.h"
#include "llscrolllistctrl.h"
class LLFloaterTeleportHistory : public LLFloater
class LLFloaterTeleportHistory : public LLFloater, public LLUISingleton<LLFloaterTeleportHistory, LLFloaterTeleportHistory>
{
public:
LLFloaterTeleportHistory();
LLFloaterTeleportHistory(const LLSD& seed);
virtual ~LLFloaterTeleportHistory();
/// @brief: reimplemented to check for selection changes in the places list scrolllist
@@ -65,6 +65,8 @@ public:
/// @brief: adds the destination to the list of visited places
void addEntry(std::string parcelName);
static void loadFile(const std::string &file_name);
static void saveFile(const std::string &file_name);
private:
enum HISTORY_COLUMN_ORDER
{
@@ -93,9 +95,21 @@ private:
std::string mPendingSimString;
std::string mPendingTimeString;
std::string mPendingSLURL;
public:
// visibility policy for LLUISingleton
static bool visible(LLFloater* instance, const LLSD& key)
{
return VisibilityPolicy<LLFloater>::visible(instance, key);
}
static void show(LLFloater* instance, const LLSD& key)
{
VisibilityPolicy<LLFloater>::show(instance, key);
}
static void hide(LLFloater* instance, const LLSD& key)
{
VisibilityPolicy<LLFloater>::hide(instance, key);
}
};
// globals
extern LLFloaterTeleportHistory* gFloaterTeleportHistory;
#endif

View File

@@ -6393,7 +6393,7 @@ class LLShowFloater : public view_listener_t
}
else if (floater_name == "teleport history")
{
gFloaterTeleportHistory->setVisible(!gFloaterTeleportHistory->getVisible());
LLFloaterTeleportHistory::toggleInstance();
}
else if (floater_name == "im")
{
@@ -6556,7 +6556,7 @@ class LLFloaterVisible : public view_listener_t
}
else if (floater_name == "teleport history")
{
new_value = (gFloaterTeleportHistory && gFloaterTeleportHistory->getVisible());
new_value = LLFloaterTeleportHistory::instanceVisible();
}
else if (floater_name == "im")
{

View File

@@ -3904,7 +3904,7 @@ void process_agent_movement_complete(LLMessageSystem* msg, void**)
}
// add teleport destination to the list of visited places
gFloaterTeleportHistory->addPendingEntry(regionp->getName(), (S16)agent_pos.mV[VX], (S16)agent_pos.mV[VY], (S16)agent_pos.mV[VZ]);
LLFloaterTeleportHistory::getInstance()->addPendingEntry(regionp->getName(), (S16)agent_pos.mV[VX], (S16)agent_pos.mV[VY], (S16)agent_pos.mV[VZ]);
}
else
{

View File

@@ -1546,7 +1546,7 @@ void LLViewerParcelMgr::processParcelProperties(LLMessageSystem *msg, void **use
}
// Add any pending entry to the TP history now that we got the *new* parcel name.
gFloaterTeleportHistory->addEntry(LLViewerParcelMgr::getInstance()->getAgentParcelName());
LLFloaterTeleportHistory::getInstance()->addEntry(LLViewerParcelMgr::getInstance()->getAgentParcelName());
// Handle updating selections, if necessary.
if (sequence_id == SELECTED_PARCEL_SEQ_ID)

View File

@@ -2005,8 +2005,8 @@ void LLViewerWindow::initWorldUI_postLogin()
gFloaterWorldMap->setVisible(FALSE);
// open teleport history floater and hide it initially
gFloaterTeleportHistory = new LLFloaterTeleportHistory();
gFloaterTeleportHistory->setVisible(FALSE);
LLFloaterTeleportHistory::getInstance()->setVisible(FALSE);
LLFloaterTeleportHistory::loadFile("teleport_history.xml");
LLFloaterChatterBox::createInstance(LLSD());
}