void MEventsTab::updateEvents()
{
+ //get events
MTGetAllEvents gae=req->queryGetAllEvents();
if(gae.stage()!=gae.Success){
qDebug("Error getting all events (%s): %s",gae.errorType().toAscii().data(),gae.errorString().toAscii().data());
return;
}
QList<MOEvent>evl=gae.getevents();
- eventmodel->clear();
- eventmodel->insertColumns(0,6);
- eventmodel->setHorizontalHeaderLabels(QStringList()<<tr("Start Time")<<tr("Title")<<tr("Free")<<tr("Reserved")<<tr("Sold")<<tr("Capacity"));
- QDateTime now=QDateTime::currentDateTime();
+ //calculate max age
+ QDateTime now=QDateTime::currentDateTime().addDays(-1);
+ bool showveryold=false;
bool showold;
if(showoldevents)showold=showoldevents->isChecked();
else showold=QSettings().value("profiles/"+profilekey+"/showOldEvents",false).toBool();
+ if(showold){
+ QSettings set;
+ set.beginGroup("profiles/"+profilekey);
+ int maxage=set.value("maxeventage", 0).toInt();
+ if(maxage==0)showveryold=true;
+ now=now.addDays(-maxage);
+ }
+ //fill model
+ eventmodel->clear();
+ eventmodel->insertColumns(0,6);
+ eventmodel->setHorizontalHeaderLabels(QStringList()<<tr("Start Time")<<tr("Title")<<tr("Free")<<tr("Reserved")<<tr("Sold")<<tr("Capacity"));
for(int i=0,j=0;i<evl.size();i++){
+ //filter by time
QDateTime stime=QDateTime::fromTime_t(evl[i].start());
- if(stime<now && !showold)continue;
+ if(!showveryold && stime<now)continue;
+ //show
eventmodel->insertRow(j);
eventmodel->setData(eventmodel->index(j,0),evl[i].id().value(),Qt::UserRole);
eventmodel->setData(eventmodel->index(j,0),stime.toString(tr("ddd MMMM d yyyy, h:mm ap","time format")));