llpaneldirevents.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llpaneldirevents.h"
00035 
00036 #include <sstream>
00037 
00038 // linden library includes
00039 #include "llenum.h"
00040 #include "message.h"
00041 #include "llqueryflags.h"
00042 
00043 // viewer project includes
00044 #include "llagent.h"
00045 #include "llviewercontrol.h"
00046 #include "lleventinfo.h"
00047 #include "llpaneldirbrowser.h"
00048 #include "llresmgr.h"
00049 #include "lluiconstants.h"
00050 #include "llpanelevent.h"
00051 #include "viewer.h"
00052 
00053 BOOL gDisplayEventHack = FALSE;
00054 
00055 LLPanelDirEvents::LLPanelDirEvents(const std::string& name, LLFloaterDirectory* floater)
00056         :       LLPanelDirBrowser(name, floater),
00057         mDoneQuery(FALSE),
00058         mDay(0)
00059 {
00060         // more results per page for this
00061         mResultsPerPage = 200;
00062 }
00063 
00064 BOOL LLPanelDirEvents::postBuild()
00065 {
00066         LLPanelDirBrowser::postBuild();
00067 
00068         childSetCommitCallback("date_mode", onDateModeCallback, this);
00069 
00070         childSetAction("<<", onBackBtn, this);
00071         childSetAction(">>", onForwardBtn, this);
00072 
00073         childSetAction("Today", onClickToday, this);
00074 
00075         childSetCommitCallback("mature", onCommitMature, this);
00076 
00077         childSetAction("Search", LLPanelDirBrowser::onClickSearchCore, this);
00078         setDefaultBtn("Search");
00079 
00080         childSetAction("Delete", onClickDelete, this);
00081         childDisable("Delete");
00082         childHide("Delete");
00083 
00084         onDateModeCallback(NULL, this);
00085 
00086         mCurrentSortColumn = "time";
00087 
00088         if (!gDisplayEventHack)
00089         {
00090                 setDay(0);      // for today
00091                 //performQuery(); // Temporary change to help DB - Sabin
00092         }
00093         gDisplayEventHack = FALSE;
00094 
00095         return TRUE;
00096 }
00097 
00098 LLPanelDirEvents::~LLPanelDirEvents()
00099 {
00100         // Children all cleaned up by default view destructor.
00101 }
00102 
00103 
00104 void LLPanelDirEvents::draw()
00105 {
00106         refresh();
00107 
00108         LLPanelDirBrowser::draw();
00109 }
00110 
00111 void LLPanelDirEvents::refresh()
00112 {
00113         // You only have a choice if you are mature
00114         childSetVisible("incmature", !gAgent.isTeen());
00115 
00116         BOOL godlike = gAgent.isGodlike();
00117         childSetVisible("Delete", godlike);
00118         childSetEnabled("Delete", godlike);
00119 }
00120 
00121 
00122 void LLPanelDirEvents::setDay(S32 day)
00123 {
00124         mDay = day;
00125 
00126         // Get time UTC
00127         time_t utc_time = time_corrected();
00128 
00129         // Correct for offset
00130         utc_time += day * 24 * 60 * 60;
00131 
00132         // There's only one internal tm buffer.
00133         struct tm* internal_time;
00134 
00135         // Convert to Pacific, based on server's opinion of whether
00136         // it's daylight savings time there.
00137         internal_time = utc_to_pacific_time(utc_time, gPacificDaylightTime);
00138 
00139         LLString buffer = llformat("%d/%d",
00140                         1 + internal_time->tm_mon,              // Jan = 0
00141                         internal_time->tm_mday);        // 2001 = 101
00142         childSetValue("date_text", buffer);
00143 }
00144 
00145 // virtual
00146 void LLPanelDirEvents::performQuery()
00147 {
00148         // event_id 0 will perform no delete action.
00149         performQueryOrDelete(0);
00150 }
00151 
00152 void LLPanelDirEvents::performQueryOrDelete(U32 event_id)
00153 {
00154         S32 relative_day = mDay;
00155         // Update the date field to show the date IN THE SERVER'S
00156         // TIME ZONE, as that is what will be displayed in each event
00157 
00158         // Get time UTC
00159         time_t utc_time = time_corrected();
00160 
00161         // Correct for offset
00162         utc_time += relative_day * 24 * 60 * 60;
00163 
00164         // There's only one internal tm buffer.
00165         struct tm* internal_time;
00166 
00167         // Convert to Pacific, based on server's opinion of whether
00168         // it's daylight savings time there.
00169         internal_time = utc_to_pacific_time(utc_time, gPacificDaylightTime);
00170 
00171         LLString buffer = llformat("%d/%d",
00172                         1 + internal_time->tm_mon,              // Jan = 0
00173                         internal_time->tm_mday);        // 2001 = 101
00174         childSetValue("date_text", buffer);
00175 
00176         // Record the relative day so back and forward buttons
00177         // offset from this day.
00178         mDay = relative_day;
00179 
00180         mDoneQuery = TRUE;
00181 
00182         setupNewSearch();
00183 
00184         U32 scope = DFQ_DATE_EVENTS;
00185         if ( gAgent.isTeen()) scope |= DFQ_PG_SIMS_ONLY;
00186         if ( !childGetValue("incmature").asBoolean() ) scope |= DFQ_PG_EVENTS_ONLY;
00187 
00188         std::ostringstream params;
00189 
00190         // Date mode for the search
00191         if ("current" == childGetValue("date_mode").asString())
00192         {
00193                 params << "u|";
00194         }
00195         else
00196         {
00197                 params << mDay << "|";
00198         }
00199 
00200         // Categories are stored in the database in table indra.event_category
00201         // XML must match.
00202         U32 cat_id = childGetValue("category combo").asInteger();
00203 
00204         params << cat_id << "|";
00205         params << childGetValue("event_search_text").asString();
00206 
00207         // send the message
00208         if (0 == event_id)
00209         {
00210                 sendDirFindQuery(gMessageSystem, mSearchID, params.str().c_str(), scope, mSearchStart);
00211         }
00212         else
00213         {
00214                 // This delete will also perform a query.
00215                 LLMessageSystem* msg = gMessageSystem;
00216 
00217                 msg->newMessageFast(_PREHASH_EventGodDelete);
00218 
00219                 msg->nextBlockFast(_PREHASH_AgentData);
00220                 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00221                 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00222 
00223                 msg->nextBlockFast(_PREHASH_EventData);
00224                 msg->addU32Fast(_PREHASH_EventID, event_id);
00225 
00226                 msg->nextBlockFast(_PREHASH_QueryData);
00227                 msg->addUUIDFast(_PREHASH_QueryID, mSearchID);
00228                 msg->addStringFast(_PREHASH_QueryText, params.str());
00229                 msg->addU32Fast(_PREHASH_QueryFlags, scope);
00230                 msg->addS32Fast(_PREHASH_QueryStart, mSearchStart);
00231                 gAgent.sendReliableMessage();
00232         }
00233 }
00234 
00235 // static
00236 void LLPanelDirEvents::onDateModeCallback(LLUICtrl* ctrl, void *data)
00237 {
00238         LLPanelDirEvents* self = (LLPanelDirEvents*)data;
00239         if (self->childGetValue("date_mode").asString() == "date")
00240         {
00241                 self->childEnable("Today");
00242                 self->childEnable(">>");
00243                 self->childEnable("<<");
00244         }
00245         else
00246         {
00247                 self->childDisable("Today");
00248                 self->childDisable(">>");
00249                 self->childDisable("<<");
00250         }
00251 }
00252 
00253 // static
00254 void LLPanelDirEvents::onClickToday(void *userdata)
00255 {
00256         LLPanelDirEvents *self = (LLPanelDirEvents *)userdata;
00257         self->resetSearchStart();
00258         self->setDay(0);
00259         self->performQuery();
00260 }
00261 
00262 
00263 // static
00264 void LLPanelDirEvents::onBackBtn(void* data)
00265 {
00266         LLPanelDirEvents* self = (LLPanelDirEvents*)data;
00267         self->resetSearchStart();
00268         self->setDay(self->mDay - 1);
00269         self->performQuery();
00270 }
00271 
00272 
00273 // static
00274 void LLPanelDirEvents::onForwardBtn(void* data)
00275 {
00276         LLPanelDirEvents* self = (LLPanelDirEvents*)data;
00277         self->resetSearchStart();
00278         self->setDay(self->mDay + 1);
00279         self->performQuery();
00280 }
00281 
00282 
00283 // static
00284 void LLPanelDirEvents::onCommitMature(LLUICtrl* ctrl, void* data)
00285 {
00286         // just perform another search
00287         onClickSearchCore(data);
00288 }
00289 
00290 
00291 // static
00292 void LLPanelDirEvents::onClickDelete(void *userdata)
00293 {
00294         LLPanelDirEvents *self = (LLPanelDirEvents *)userdata;
00295         if (!self) return;
00296 
00297         U32 event_id;
00298         event_id = self->getSelectedEventID();
00299         if (!event_id) return;
00300 
00301         self->performQueryOrDelete(event_id);
00302 }

Generated on Thu Jul 1 06:08:56 2010 for Second Life Viewer by  doxygen 1.4.7