From 647860bb8f64dd1cbe3b8abaa61a63a444c88a7f Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Tue, 12 Jul 2016 00:00:40 +0200 Subject: [PATCH] fix crash in eventview --- commonlib/widgets/eventview.cpp | 90 +++++++++++++++++++++++++++++--------- commonlib/widgets/eventview.h | 11 ++++- 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/commonlib/widgets/eventview.cpp b/commonlib/widgets/eventview.cpp index e77bb5a..1f22532 100644 --- a/commonlib/widgets/eventview.cpp +++ b/commonlib/widgets/eventview.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -37,8 +38,31 @@ MEventView::MEventView ( QWidget* parent ) : QTextBrowser ( parent ) qDebug()<<"Setting path"<parentUrl()<<"for URL"<url(); setSearchPaths(QStringList()<parentUrl().toString()); resetPattern(); + mNam=new QNetworkAccessManager(this); + connect(mNam,SIGNAL(sslErrors(QNetworkReply*,QList)), req,SLOT(sslErrors(QNetworkReply*,QList))); + initCacheDir(); } +void MEventView::initCacheDir() +{ + mCacheDir=req->dataDir()+"/eventcache"; + QDir d(req->dataDir()); + if(!d.exists("eventcache")){ + if(!d.mkdir("eventcache")) + qDebug()<<"Warning: cannot create event data cache"<url().resolved(name); - QNetworkAccessManager nam; - connect(&nam,SIGNAL(sslErrors(QNetworkReply*,QList)),req,SLOT(sslErrors(QNetworkReply*,QList))); - QNetworkReply*rpl= nam.get(QNetworkRequest(url)); + QString encoded=url2base64(url); + //find in cache + if(QDir(mCacheDir).exists(encoded)){ + qDebug()<<"Found resource"<get(QNetworkRequest(url)); qDebug()<<"Trying to GET"<readAll(); - qDebug()<<"...got"<readAll()); + qDebug()<<"...got"<deleteLater(); + renderEvent(); + } + +} + + void MEventView::clearEvent() { clearHistory(); @@ -71,28 +112,33 @@ void MEventView::clearEvent() void MEventView::setEvent ( MOEvent event ) { clearEvent(); + mCurrentEvent=event; + renderEvent(); +} +void MEventView::renderEvent() +{ //generate HTML - QString detail="

"+htmlize(event.title())+"

\n"; - detail+=tr("Artist: %1").arg(htmlize(event.artist().value().name()))+"

\n"; - detail+=tr("Starttime: %1").arg(htmlize(event.startTimeString()))+"
\n"; - detail+=tr("Endtime: %1").arg(htmlize(event.endTimeString()))+"

\n"; - detail+=tr("Room: %1").arg(htmlize(event.room()))+"
\n"; - detail+=tr("Seats: %1 max. (%2 sold out; %3 reserved; %4 free)").arg(event.capacity()).arg(event.amountSold()).arg(event.amountReserved()).arg(event.amountFree())+"

\n"; + QString detail="

"+htmlize(mCurrentEvent.title())+"

\n"; + detail+=tr("Artist: %1").arg(htmlize(mCurrentEvent.artist().value().name()))+"

\n"; + detail+=tr("Starttime: %1").arg(htmlize(mCurrentEvent.startTimeString()))+"
\n"; + detail+=tr("Endtime: %1").arg(htmlize(mCurrentEvent.endTimeString()))+"

\n"; + detail+=tr("Room: %1").arg(htmlize(mCurrentEvent.room()))+"
\n"; + detail+=tr("Seats: %1 max. (%2 sold out; %3 reserved; %4 free)").arg(mCurrentEvent.capacity()).arg(mCurrentEvent.amountSold()).arg(mCurrentEvent.amountReserved()).arg(mCurrentEvent.amountFree())+"

\n"; const QString bgsold=tr("

Sold Out!
","Colored display for sold out tickets"); const QString bgavail=tr("
","Colored display for ordering tickets"); const QString bghide=tr("
Unable to sell.
","Colored display for tickets unavailable to this user"); - const bool showevent=req->checkFlags(event.flags()); + const bool showevent=req->checkFlags(mCurrentEvent.flags()); if(showevent) - detail+=event.amountFree()>0?bgavail.arg(QString("order:?ev=%1").arg(event.id())):bgsold; + detail+=mCurrentEvent.amountFree()>0?bgavail.arg(QString("order:?ev=%1").arg(mCurrentEvent.id())):bgsold; else detail+=bghide; detail+="

"+tr("Prices")+"

\n"; detail+="" "\n"; - QListprices=event.price(); + QListprices=mCurrentEvent.price(); qSort(prices.begin(),prices.end(),[](const MOEventPrice&p1,const MOEventPrice&p2){return p1.prio()checkFlags(ctg.flags())) detail+="
"+tr("Category")+""+tr("Price")+""+tr("Available")+""+tr("Max. Seats")+""+tr("Order")+"
"+ (avail>0? - bgavail.arg(QString("order:?ev=%1&pr=%2").arg(event.id()).arg(ctg.pricecategoryid())) + bgavail.arg(QString("order:?ev=%1&pr=%2").arg(mCurrentEvent.id()).arg(ctg.pricecategoryid())) :bgsold); else detail+=""+bghide; @@ -111,9 +157,9 @@ void MEventView::setEvent ( MOEvent event ) } detail+="

\n"; - detail+="

"+tr("Description")+"

\n"+event.description()+"

\n"; + detail+="

"+tr("Description")+"

\n"+mCurrentEvent.description()+"

\n"; detail+="

"+tr("Comment")+"

\n"; - QString comment=event.comment(); + QString comment=mCurrentEvent.comment(); if(!comment.trimmed().startsWith(""))comment=htmlize(comment); detail+=comment; //set value diff --git a/commonlib/widgets/eventview.h b/commonlib/widgets/eventview.h index d336860..525b5e1 100644 --- a/commonlib/widgets/eventview.h +++ b/commonlib/widgets/eventview.h @@ -19,6 +19,9 @@ #include "commonexport.h" +class QNetworkAccessManager; +class QNetworkReply; + ///Event Viewer class MAGICSMOKE_COMMON_EXPORT MEventView:public QTextBrowser { @@ -40,7 +43,13 @@ signals: /**order ticket from event tab*/ void eventOrderTicket(qint64,qint64); private: - QString mPattern; + QString mPattern,mCacheDir; + QNetworkAccessManager*mNam; + MOEvent mCurrentEvent; + + void initCacheDir(); + void saveReply(QNetworkReply*,QString); + void renderEvent(); }; -- 1.7.2.5