QTfrontend/pagedata.cpp
changeset 5768 852ba8f5685c
parent 5766 ca9c7551bc8a
child 5769 09aca6e1317a
equal deleted inserted replaced
5767:e00c0a56e80e 5768:852ba8f5685c
    54     fetchList();
    54     fetchList();
    55 }
    55 }
    56 
    56 
    57 void PageDataDownload::request(const QUrl &url)
    57 void PageDataDownload::request(const QUrl &url)
    58 {
    58 {
       
    59     QUrl finalUrl;
       
    60     if(url.host().isEmpty())
       
    61         finalUrl = QUrl("http://www.hedgewars.org" + url.path());
       
    62     else
       
    63         finalUrl = url;
       
    64 
    59     if(url.path().endsWith(".zip"))
    65     if(url.path().endsWith(".zip"))
    60     {
    66     {
    61         qWarning() << "Download Request" << url.toString();
    67         qWarning() << "Download Request" << url.toString();
    62         QString fileName = QFileInfo(url.toString()).fileName();
    68         QString fileName = QFileInfo(url.toString()).fileName();
    63 
    69 
    64         QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + url.path()));
    70         QNetworkRequest newRequest(finalUrl);
    65         newRequest.setAttribute(QNetworkRequest::User, fileName);
    71         newRequest.setAttribute(QNetworkRequest::User, fileName);
    66 
    72 
    67         QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    73         QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    68         QNetworkReply *reply = manager->get(newRequest);
    74         QNetworkReply *reply = manager->get(newRequest);
    69         connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded()));
    75         connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded()));
    74         progressBars.insert(reply, progressBar);
    80         progressBars.insert(reply, progressBar);
    75     } else
    81     } else
    76     {
    82     {
    77         qWarning() << "Page Request" << url.toString();
    83         qWarning() << "Page Request" << url.toString();
    78 
    84 
    79         QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + url.path()));
    85         QNetworkRequest newRequest(finalUrl);
    80 
    86 
    81         QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    87         QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    82         QNetworkReply *reply = manager->get(newRequest);
    88         QNetworkReply *reply = manager->get(newRequest);
    83         connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded()));
    89         connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded()));
    84     }
    90     }
    90     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
    96     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
    91 
    97 
    92     if(reply)
    98     if(reply)
    93     {
    99     {
    94         QString html = QString::fromUtf8(reply->readAll());
   100         QString html = QString::fromUtf8(reply->readAll());
    95         html.remove(0,html.indexOf("<!-- BEGIN -->"));
   101         int begin = html.indexOf("<!-- BEGIN -->");
    96         html.truncate(html.indexOf("<!-- END -->"));
   102         int end = html.indexOf("<!-- END -->");
       
   103         if(begin != -1 && begin < end)
       
   104         {
       
   105             html.truncate(end);
       
   106             html.remove(0, begin);
       
   107         }
    97         web->setHtml(html);
   108         web->setHtml(html);
    98     }
   109     }
    99 }
   110 }
   100 
   111 
   101 void PageDataDownload::fileDownloaded()
   112 void PageDataDownload::fileDownloaded()