--- /dev/null
+//
+// C++ Interface: event
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef EVENT_H
+#define EVENT_H
+
+#include <QString>
+
+class MWebRequest;
+
+class MEvent
+{
+ public:
+ MEvent(MWebRequest*,int);
+ ~MEvent();
+
+ void save();
+
+ QString title();
+ private:
+ MWebRequest*req;
+ int eventid;
+ //display data
+ QString m_title,m_artist,m_description;
+ //timing and location
+ int m_starttime,m_endtime;
+ QString m_roomid;
+ //initially a copy from room, can be adjusted
+ int m_capacity;
+ //default pricing in cents
+ int m_defaultprice;
+ //if not null/empty: event has been cancelled
+ QString m_cancelreason;
+};
+
+#endif
#include <QBoxLayout>
#include <QPushButton>
#include <QTableView>
+#include <QStandardItemModel>
#include <QLabel>
#include <QTextEdit>
#include <QFrame>
m->addAction(tr("&Close Session"),this,SLOT(close()));
m=mb->addMenu(tr("&Event"));
+ m->addAction(tr("&Update Event List"),this,SLOT(updateEvents()))->setEnabled(req->hasRole("geteventlist"));
m->addAction(tr("&Show details..."));
m->addAction(tr("&New Event..."),this,SLOT(newEvent()))->setEnabled(req->hasRole("createevent"));
m->addAction(tr("&Cancel Event..."));
tab->addTab(eventtab=new QWidget,tr("Events"));
QVBoxLayout*vl;QHBoxLayout*hl;
eventtab->setLayout(hl=new QHBoxLayout);
- hl->addWidget(new QTableView,10);
+ hl->addWidget(eventtable=new QTableView,10);
+ eventtable->setModel(eventmodel=new QStandardItemModel(this));
+ eventtable->setSelectionMode(QAbstractItemView::SingleSelection);
+ eventtable->setEditTriggers(QAbstractItemView::NoEditTriggers);
hl->addSpacing(5);
hl->addLayout(vl=new QVBoxLayout,0);
QPushButton*p;
vl->addWidget(p=new QPushButton(tr("New Event...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(newEvent()));
p->setEnabled(req->hasRole("createevent"));
- vl->addWidget(new QPushButton(tr("Details...")),0);
+ vl->addWidget(p=new QPushButton(tr("Details...")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(editEvent()));
+ p->setEnabled(req->hasRole("geteventdata"));
vl->addSpacing(15);
vl->addWidget(new QPushButton(tr("Order Ticket...")),0);
vl->addStretch(10);
//status bar
statusBar()->setSizeGripEnabled(true);
+
+ //fill tables
+ if(req->hasRole("geteventlist")){
+ updateEvents();
+ }else{
+ eventtab->setEnabled(false);
+ }
+}
+
+void MOverview::updateEvents()
+{
+ QList<MWebRequest::Eventlet>evl=req->getAllEvents();
+ eventmodel->clear();
+ eventmodel->insertColumns(0,2);
+ eventmodel->insertRows(0,evl.size());
+ eventmodel->setHorizontalHeaderLabels(QStringList()<<tr("Start Time")<<tr("Title"));
+ for(int i=0;i<evl.size();i++){
+ eventmodel->setData(eventmodel->index(i,0),evl[i].id,Qt::UserRole);
+ eventmodel->setData(eventmodel->index(i,0),evl[i].start.toString(tr("ddd MMMM d yyyy, h:mm ap","time format")));
+ eventmodel->setData(eventmodel->index(i,1),evl[i].title);
+ }
+ eventtable->resizeColumnToContents(0);
+ eventtable->resizeColumnToContents(1);
}
void MOverview::closeEvent(QCloseEvent*ce)
void MOverview::newEvent()
{
- MEventEditor ed(this);
+ MEventEditor ed(this,req);
+ ed.exec();
+ updateEvents();
+}
+
+void MOverview::editEvent()
+{
+ int id;
+ QModelIndexList ilst=eventtable->selectionModel()->selectedIndexes();
+ if(ilst.size()<1)return;
+ QModelIndex idx=eventmodel->index(ilst[0].row(),0);
+ id=eventmodel->data(idx,Qt::UserRole).toInt();
+ if(id<0)return;
+ MEventEditor ed(this,req,id);
ed.exec();
+ updateEvents();
}
roles<<rl;
}
//if none: put in a dummy to avoid asking again
- if(roles.size()==0)roles<<"__none__";
+ if(roles.size()==0)roles<<" __ none __ ";
}
//check whether we are admin
if(roles.contains("_admin"))return true;
//check whether we have role
return roles.contains(r.toLower());
}
+
+QList<MWebRequest::Eventlet> MWebRequest::getAllEvents()
+{
+ errstr="";
+ if(!request("geteventlist"))return QList<Eventlet>();
+ //parse return document
+ QDomDocument doc;
+ QString msg;int ln,cl;
+ if(!doc.setContent(rspdata,&msg,&ln,&cl)){
+ errstr=tr("Error parsing EventList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg);
+ return QList<Eventlet>();
+ }
+ QDomElement root=doc.documentElement();
+ QDomNodeList nl=root.elementsByTagName("Event");
+ QList<Eventlet>ret;
+ for(int i=0;i<nl.size();i++){
+ QDomElement el=nl.at(i).toElement();
+ if(el.isNull())continue;
+ Eventlet ev;
+ ev.title=el.text();
+ bool b;
+ ev.id=el.attribute("id").toInt(&b);
+ if(!b || ev.id<0)continue;
+ ev.start=QDateTime::fromTime_t(el.attribute("start").toInt(&b));
+ if(!b)continue;
+ ret.append(ev);
+ }
+ return ret;
+}