QTfrontend/pagedata.cpp
author unc0rr
Sat, 03 Sep 2011 21:23:20 +0400
changeset 5746 fbc52bb92cad
parent 5582 48ced03a9949
child 5754 583b7a683b17
permissions -rw-r--r--
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     1
/*
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     3
 * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     4
 *
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     8
 *
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    12
 * GNU General Public License for more details.
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    13
 *
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    17
 */
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    18
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    19
#include <QGridLayout>
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    20
#include <QPushButton>
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    21
#include <QNetworkAccessManager>
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    22
#include <QNetworkRequest>
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    23
#include <QNetworkReply>
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    24
#include <QFileInfo>
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    25
#include <QFileDialog>
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    26
#include <QTextBrowser>
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    27
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    28
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    29
#include "pagedata.h"
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    30
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    31
PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent)
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    32
{
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    33
    QGridLayout * pageLayout = new QGridLayout(this);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    34
    pageLayout->setColumnStretch(0, 1);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    35
    pageLayout->setColumnStretch(1, 1);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    36
    pageLayout->setColumnStretch(2, 1);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    37
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    38
    BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    39
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    40
    web = new QTextBrowser(this);
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    41
    connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(install(const QUrl&)));
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    42
    web->setOpenLinks(false);
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    43
    //web->setSource();
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    44
    //web->load(QUrl("http://m8y.org/hw/downloads/"));
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    45
    //web->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    46
    pageLayout->addWidget(web, 0, 0, 1, 3);
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    47
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    48
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    49
    QNetworkRequest newRequest(QUrl("http://m8y.org/hw/downloads/index.xhtml"));
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    50
    //newRequest.setAttribute(QNetworkRequest::User, fileName);
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    51
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    52
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    53
    QNetworkReply *reply = manager->get(newRequest);
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    54
    connect(reply, SIGNAL(finished()), this, SLOT(downloadIssueFinished()));
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    55
}
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    56
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    57
void PageDataDownload::install(const QUrl &url)
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    58
{
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    59
qWarning("Download Request");
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    60
QString fileName = QFileInfo(url.toString()).fileName();
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    61
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    62
QNetworkRequest newRequest(url);
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    63
newRequest.setAttribute(QNetworkRequest::User, fileName);
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    64
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    65
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    66
QNetworkReply *reply = manager->get(newRequest);
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    67
//connect( reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)) );
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    68
}
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    69
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    70
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    71
void PageDataDownload::downloadIssueFinished()
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    72
{
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    73
    QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    74
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    75
    if(reply)
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    76
    {
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    77
        web->setHtml(QString::fromUtf8(reply->readAll()));
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    78
    }
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    79
}
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    80
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    81
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    82
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    83