...
 
Commits (3)
......@@ -39,11 +39,11 @@
class LLExperienceLogDispatchHandler : public LLDispatchHandler
{
public:
virtual bool operator()(
bool operator()(
const LLDispatcher* dispatcher,
const std::string& key,
const LLUUID& invoice,
const sparam_t& strings)
const sparam_t& strings) override
{
LLSD message;
......@@ -90,7 +90,8 @@ void LLExperienceLog::handleExperienceMessage(LLSD& message)
std::string day = daybuf;
if(!mEvents.has(day))
auto iter = mEvents.find(day);
if(iter == mEvents.end())
{
mEvents[day] = LLSD::emptyArray();
}
......@@ -112,7 +113,6 @@ void LLExperienceLog::handleExperienceMessage(LLSD& message)
}
message["Time"] = time_of_day;
mEvents[day].append(message);
mEventsToSave[day].append(message);
mSignals(message);
}
......@@ -177,8 +177,14 @@ void LLExperienceLog::notify( LLSD& message )
void LLExperienceLog::saveEvents()
{
eraseExpired();
std::string filename = getFilename();
LLSD settings = LLSD::emptyMap().with("Events", mEventsToSave);
LLSD temp_events;
for (const auto& event_pair : mEvents)
{
temp_events[event_pair.first] = event_pair.second;
}
LLSD settings = LLSD::emptyMap().with("Events", temp_events);
settings["MaxDays"] = (int)mMaxDays;
settings["Notify"] = mNotifyNewEvent;
......@@ -212,9 +218,11 @@ void LLExperienceLog::loadEvents()
mEvents.clear();
if(mMaxDays > 0 && settings.has("Events"))
{
mEvents = settings["Events"];
mEventsToSave = mEvents;
const auto& events = settings["Events"];
mEvents.insert(events.beginMap(), events.endMap());
}
eraseExpired();
}
LLExperienceLog::~LLExperienceLog()
......@@ -224,35 +232,28 @@ LLExperienceLog::~LLExperienceLog()
void LLExperienceLog::eraseExpired()
{
while(mEvents.size() > mMaxDays && mMaxDays > 0)
for (auto it = mEvents.begin(), end = mEvents.end(); it != end;)
{
mEvents.erase(mEvents.beginMap()->first);
auto event_it = it++;
if (isExpired(event_it->first))
{
mEvents.erase(event_it);
}
}
}
bool LLExperienceLog::isNotExpired(std::string& date)
bool LLExperienceLog::isExpired(const std::string& date)
{
LLDate event_date;
S32 month, day, year;
if (date.empty())
return true;
S32 month, day, year = 0;
S32 matched = sscanf(date.c_str(), "%d-%d-%d", &year, &month, &day);
if (matched != 3) return false;
LLDate event_date;
event_date.fromYMDHMS(year, month, day);
const U32 seconds_in_day = 24 * 60 * 60;
S32 curr_year = 0, curr_month = 0, curr_day = 0;
LLDate curr_date = LLDate::now();
curr_date.split(&curr_year, &curr_month, &curr_day);
curr_date.fromYMDHMS(curr_year, curr_month, curr_day); // Set hour, min, and sec to 0
LLDate boundary_date = LLDate(curr_date.secondsSinceEpoch() - seconds_in_day*getMaxDays());
return event_date >= boundary_date;
}
const LLSD& LLExperienceLog::getEvents() const
{
return mEvents;
return event_date.secondsSinceEpoch() <= (LLDate::now().secondsSinceEpoch() - F64(getMaxDays() * 86400U));
}
void LLExperienceLog::clear()
......@@ -279,6 +280,6 @@ void LLExperienceLog::setNotifyNewEvent( bool val )
}
else if( val && !mNotifyConnection.connected())
{
mNotifyConnection = addUpdateSignal(boost::function<void(LLSD&)>(LLExperienceLog::notify));
mNotifyConnection = addUpdateSignal(std::function<void(LLSD&)>(LLExperienceLog::notify));
}
}
......@@ -52,7 +52,7 @@ class LLExperienceLog final : public LLSingleton<LLExperienceLog>
U32 getPageSize() const { return mPageSize; }
void setPageSize(U32 val) { mPageSize = val; }
const LLSD& getEvents()const;
const auto& getEvents() const { return mEvents; };
void clear();
virtual ~LLExperienceLog();
......@@ -60,8 +60,7 @@ class LLExperienceLog final : public LLSingleton<LLExperienceLog>
static void notify(LLSD& message);
static std::string getFilename();
static std::string getPermissionString(const LLSD& message, const std::string& base);
void setEventsToSave(LLSD new_events){mEventsToSave = new_events; }
bool isNotExpired(std::string& date);
bool isExpired(const std::string& date);
void handleExperienceMessage(LLSD& message);
protected:
......@@ -69,10 +68,7 @@ class LLExperienceLog final : public LLSingleton<LLExperienceLog>
void saveEvents();
void eraseExpired();
LLSD mEvents;
LLSD mEventsToSave;
std::map<std::string, LLSD> mEvents;
callback_signal_t mSignals;
callback_connection_t mNotifyConnection;
U32 mMaxDays;
......
......@@ -47,7 +47,7 @@ static LLPanelInjector<LLPanelExperienceLog> register_experiences_panel("experie
LLPanelExperienceLog::LLPanelExperienceLog( )
: mEventList(NULL)
: mEventList(nullptr)
, mPageSize(25)
, mCurrentPage(0)
{
......@@ -94,9 +94,9 @@ void LLPanelExperienceLog::refresh()
{
S32 selected = mEventList->getFirstSelectedIndex();
mEventList->deleteAllItems();
const LLSD events = LLExperienceLog::instance().getEvents();
const auto& events = LLExperienceLog::instance().getEvents();
if(events.size() == 0)
if(events.empty())
{
mEventList->setCommentText(getString("no_events"));
return;
......@@ -109,23 +109,17 @@ void LLPanelExperienceLog::refresh()
LLUUID waiting_id;
int itemsToSkip = mPageSize*mCurrentPage;
int items = 0;
U32 items = 0;
bool moreItems = false;
LLSD events_to_save = events;
if (events.size() != 0)
for (auto day = events.crbegin(), end_day = events.crend(); day != end_day; ++day)
{
LLSD::map_const_iterator day = events.endMap();
do
const std::string date = day->first;
if (LLExperienceLog::instance().isExpired(date))
{
--day;
const LLSD& dayArray = day->second;
std::string date = day->first;
if(!LLExperienceLog::instance().isNotExpired(date))
{
events_to_save.erase(day->first);
continue;
}
}
const LLSD& dayArray = day->second;
int size = dayArray.size();
if(itemsToSkip > size)
{
......@@ -168,9 +162,8 @@ void LLPanelExperienceLog::refresh()
}
++items;
}
} while (day != events.beginMap());
}
LLExperienceLog::getInstance()->setEventsToSave(events_to_save);
if(waiting)
{
mEventList->deleteAllItems();
......
......@@ -31,7 +31,7 @@
#include "llpanel.h"
class LLScrollListCtrl;
class LLPanelExperienceLog
class LLPanelExperienceLog final
: public LLPanel
{
public:
......@@ -40,9 +40,9 @@ class LLPanelExperienceLog
static LLPanelExperienceLog* create();
/*virtual*/ BOOL postBuild(void);
/*virtual*/ BOOL postBuild(void) override;
void refresh();
void refresh() override;
protected:
void logSizeChanged();
void notifyChanged();
......
......@@ -226,7 +226,7 @@ get_region(const LLSD & sd, U64 region_handle1)
llsd_val["grid_x"].asInteger() == grid_x &&
llsd_val["grid_y"].asInteger() == grid_y)
{
return *it;
return llsd_val;
}
}
return LLSD();
......