QTfrontend/pagedata.cpp
branch0.9.16
changeset 5999 dad168522e3b
parent 5769 09aca6e1317a
equal deleted inserted replaced
5997:a9495e0bd418 5999:dad168522e3b
    49     pageLayout->addWidget(web, 0, 0, 1, 3);
    49     pageLayout->addWidget(web, 0, 0, 1, 3);
    50 
    50 
    51     progressBarsLayout = new QVBoxLayout();
    51     progressBarsLayout = new QVBoxLayout();
    52     pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3);
    52     pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3);
    53 
    53 
    54     fetchList();
    54     web->setHtml("<center><h2>Hedgewars Downloadable Content</h2><br><br><i>Loading, please wait</i></center>");
    55 }
    55 }
    56 
    56 
    57 void PageDataDownload::request(const QUrl &url)
    57 void PageDataDownload::request(const QUrl &url)
    58 {
    58 {
    59     QUrl finalUrl;
    59     QUrl finalUrl;
    93 
    93 
    94 void PageDataDownload::pageDownloaded()
    94 void PageDataDownload::pageDownloaded()
    95 {
    95 {
    96     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
    96     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
    97 
    97 
    98     if(reply)
    98     if(reply && (reply->error() == QNetworkReply::NoError))
    99     {
    99     {
   100         QString html = QString::fromUtf8(reply->readAll());
   100         QString html = QString::fromUtf8(reply->readAll());
   101         int begin = html.indexOf("<!-- BEGIN -->");
   101         int begin = html.indexOf("<!-- BEGIN -->");
   102         int end = html.indexOf("<!-- END -->");
   102         int end = html.indexOf("<!-- END -->");
   103         if(begin != -1 && begin < end)
   103         if(begin != -1 && begin < end)
   105             html.truncate(end);
   105             html.truncate(end);
   106             html.remove(0, begin);
   106             html.remove(0, begin);
   107         }
   107         }
   108         web->setHtml(html);
   108         web->setHtml(html);
   109     }
   109     }
       
   110     else
       
   111     {
       
   112         web->setHtml("<center><h2>Hedgewars Downloadable Content</h2><br><br><p><i><h4>This page requires an internet connection.</i></h4></center>");
       
   113     }
   110 }
   114 }
   111 
   115 
   112 void PageDataDownload::fileDownloaded()
   116 void PageDataDownload::fileDownloaded()
   113 {
   117 {
   114     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
   118     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
   144     }
   148     }
   145 }
   149 }
   146 
   150 
   147 void PageDataDownload::fetchList()
   151 void PageDataDownload::fetchList()
   148 {
   152 {
   149     request(QUrl("http://hedgewars.org/content.html"));
   153     request(QUrl("http://www.hedgewars.org/content.html"));
   150 }
   154 }
   151 
   155 
   152 bool PageDataDownload::extractDataPack(QByteArray * buf)
   156 bool PageDataDownload::extractDataPack(QByteArray * buf)
   153 {
   157 {
   154     QBuffer buffer;
   158     QBuffer buffer;