implemented max age for events
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 29 Dec 2009 17:27:59 +0000 (17:27 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 29 Dec 2009 17:27:59 +0000 (17:27 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@369 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/mwin/eventstab.cpp

index 5ab6ee3..071b851 100644 (file)
@@ -100,22 +100,35 @@ QMenu*MEventsTab::menu()
 
 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")));