QTfrontend/ui/page/pagedata.cpp
author alfadur
Sun, 08 Oct 2017 19:04:20 +0200
changeset 12679 8d266b2d0f9c
parent 12487 eeeb7e8de95c
child 13289 b504131f7405
permissions -rw-r--r--
Improve error messages when feedback or DLC fail to reach Internet Problems with a missing SSL library are hinted at.
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
5271
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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
5271
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>
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
    26
#include <QDebug>
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
    27
#include <QProgressBar>
5756
b451fd21ff4c Extract downloaded content into temp dir
unc0rr
parents: 5755
diff changeset
    28
#include <QBuffer>
9829
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    29
#include <QDesktopServices>
5271
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
#include "pagedata.h"
5755
a079b4dea081 Implement DataBrowser which downloads resources (images, css) on its own.
unc0rr
parents: 5754
diff changeset
    32
#include "databrowser.h"
5762
0d6a338bf377 Extract to cfgdir
unc0rr
parents: 5756
diff changeset
    33
#include "hwconsts.h"
6932
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
    34
#include "DataManager.h"
8055
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
    35
#include "FileEngine.h"
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
    36
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    37
QLayout * PageDataDownload::bodyLayoutDefinition()
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    38
{
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    39
    QGridLayout * pageLayout = new QGridLayout();
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    40
    pageLayout->setColumnStretch(0, 1);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    41
    pageLayout->setColumnStretch(1, 1);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    42
    pageLayout->setColumnStretch(2, 1);
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    43
5755
a079b4dea081 Implement DataBrowser which downloads resources (images, css) on its own.
unc0rr
parents: 5754
diff changeset
    44
    web = new DataBrowser(this);
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    45
    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
    46
5769
09aca6e1317a Prevent runtime warning
unc0rr
parents: 5768
diff changeset
    47
    progressBarsLayout = new QVBoxLayout();
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
    48
    pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3);
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    49
    return pageLayout;
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    50
}
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
    51
9829
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    52
QLayout * PageDataDownload::footerLayoutDefinition()
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    53
{
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    54
    QHBoxLayout * bottomLayout = new QHBoxLayout();
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    55
    bottomLayout->setStretch(0, 1);
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    56
12239
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    57
    pbHome = addButton(":/res/home.png", bottomLayout, 1, true, Qt::AlignBottom);
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    58
    pbHome->setMinimumHeight(50);
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    59
    pbHome->setMinimumWidth(50);
12243
41267eea2f96 Clariy home button in DLC
Wuzzy <almikes@aol.com>
parents: 12241
diff changeset
    60
    pbHome->setWhatsThis(tr("Load the start page"));
12239
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    61
12487
eeeb7e8de95c Add folder icon for main menu
Wuzzy <almikes@aol.com>
parents: 12245
diff changeset
    62
    pbOpenDir = addButton(":/res/folder.png", bottomLayout, 2, true, Qt::AlignBottom);
12241
a0ed4caa6d35 Apply minimal padding to all text buttons in frontend
Wuzzy <almikes@aol.com>
parents: 12239
diff changeset
    63
    pbOpenDir->setStyleSheet("padding: 5px 10px");
12487
eeeb7e8de95c Add folder icon for main menu
Wuzzy <almikes@aol.com>
parents: 12245
diff changeset
    64
    pbOpenDir->setWhatsThis(tr("Open packages directory"));
11824
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11631
diff changeset
    65
    pbOpenDir->setMinimumHeight(50);
9829
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    66
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    67
    bottomLayout->setStretch(2, 1);
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    68
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    69
    return bottomLayout;
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    70
}
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    71
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    72
void PageDataDownload::connectSignals()
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    73
{
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    74
    connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(request(const QUrl&)));
6932
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
    75
    connect(this, SIGNAL(goBack()), this, SLOT(onPageLeave()));
9829
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
    76
    connect(pbOpenDir, SIGNAL(clicked()), this, SLOT(openPackagesDir()));
12239
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    77
    connect(pbHome, SIGNAL(clicked()), this, SLOT(fetchList()));
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    78
}
6009
14f6fc9869f2 code cleanup/etc
sheepluva
parents: 5769
diff changeset
    79
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    80
PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent)
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    81
{
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    82
    initPage();
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    83
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    84
    web->setOpenLinks(false);
6384
8b7e8ff1b16a Disable loading content.html on startup, it is fetched on pushing to top of stack already.
nemo
parents: 6131
diff changeset
    85
//    fetchList();
8876
bd8df772dbe6 reintroduce the notification message in case you access dlc page without internet connection
koda
parents: 8059
diff changeset
    86
    web->setHtml(QString(
bd8df772dbe6 reintroduce the notification message in case you access dlc page without internet connection
koda
parents: 8059
diff changeset
    87
        "<center><h2>Hedgewars Downloadable Content</h2><br><br>"
bd8df772dbe6 reintroduce the notification message in case you access dlc page without internet connection
koda
parents: 8059
diff changeset
    88
        "<i>%1</i></center>")
bd8df772dbe6 reintroduce the notification message in case you access dlc page without internet connection
koda
parents: 8059
diff changeset
    89
        .arg(tr("Loading, please wait.")));
6932
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
    90
    m_contentDownloaded = false;
5271
48d18e329298 ack. forgot to add my stub files
nemo
parents:
diff changeset
    91
}
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    92
5765
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
    93
void PageDataDownload::request(const QUrl &url)
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
    94
{
5768
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
    95
    QUrl finalUrl;
12239
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    96
    if(url.isEmpty())
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    97
    {
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    98
        qWarning() << "Empty URL requested";
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
    99
        return;
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
   100
    }
2e725778e107 Add home button to DLC page
Wuzzy <almikes@aol.com>
parents: 11824
diff changeset
   101
    else if(url.host().isEmpty())
11631
6225dfeba347 https4dlc
sheepluva
parents: 11046
diff changeset
   102
        finalUrl = QUrl("https://www.hedgewars.org" + url.path());
5768
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
   103
    else
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
   104
        finalUrl = url;
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
   105
8059
07661fb20586 Download .zip too, and store them to .hwp
unc0rr
parents: 8055
diff changeset
   106
    if(url.path().endsWith(".hwp") || url.path().endsWith(".zip"))
5765
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   107
    {
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   108
        qWarning() << "Download Request" << url.toString();
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   109
        QString fileName = QFileInfo(url.toString()).fileName();
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   110
5768
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
   111
        QNetworkRequest newRequest(finalUrl);
5765
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   112
        newRequest.setAttribute(QNetworkRequest::User, fileName);
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
   113
5765
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   114
        QNetworkAccessManager *manager = new QNetworkAccessManager(this);
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   115
        QNetworkReply *reply = manager->get(newRequest);
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   116
        connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded()));
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   117
        connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
   118
5765
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   119
        QProgressBar *progressBar = new QProgressBar(this);
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   120
        progressBarsLayout->addWidget(progressBar);
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   121
        progressBars.insert(reply, progressBar);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6384
diff changeset
   122
    }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6384
diff changeset
   123
    else
5765
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   124
    {
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   125
        qWarning() << "Page Request" << url.toString();
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   126
5768
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
   127
        QNetworkRequest newRequest(finalUrl);
5765
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   128
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   129
        QNetworkAccessManager *manager = new QNetworkAccessManager(this);
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   130
        QNetworkReply *reply = manager->get(newRequest);
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   131
        connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded()));
e87f6756773e Allow surfing, download and extract only .zip files
unc0rr
parents: 5764
diff changeset
   132
    }
5567
44c9a577b082 Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents: 5271
diff changeset
   133
}
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   134
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   135
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   136
void PageDataDownload::pageDownloaded()
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   137
{
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   138
    QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
12679
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   139
    const char *html =
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   140
        "<center><h2>Hedgewars Downloadable Content</h2><br><br>"
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   141
        "<h4><i>%1</i></h4></center>";
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   142
12679
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   143
    if (reply) {
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   144
        if (reply->error() == QNetworkReply::NoError)
5768
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
   145
        {
12679
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   146
            QString html = QString::fromUtf8(reply->readAll());
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   147
                    int begin = html.indexOf("<!-- BEGIN -->");
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   148
                    int end = html.indexOf("<!-- END -->");
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   149
                    if(begin != -1 && begin < end)
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   150
                    {
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   151
                        html.truncate(end);
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   152
                        html.remove(0, begin);
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   153
                    }
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   154
                    web->setHtml(html);
5768
852ba8f5685c Only prepend hedgewars.org if the url is relative
unc0rr
parents: 5766
diff changeset
   155
        }
12679
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   156
        else
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   157
        {
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   158
            QString message = reply->error() == QNetworkReply::UnknownNetworkError ?
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   159
                tr("Unknown network error (possibly missing SSL library).") :
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   160
                QString(tr("This feature requires an Internet connection, but you don't appear to be online (error code: %1).")).arg(reply->error());
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   161
            web->setHtml(QString(html).arg(message));
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   162
        }
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   163
    }
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   164
    else {
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   165
        web->setHtml(QString(html).arg(tr("Internal error: Reply object is invalid.")));
8d266b2d0f9c Improve error messages when feedback or DLC fail to reach Internet
alfadur
parents: 12487
diff changeset
   166
    }
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   167
}
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   168
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   169
void PageDataDownload::fileDownloaded()
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   170
{
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   171
    QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   172
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   173
    if(reply)
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   174
    {
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   175
        QProgressBar *progressBar = progressBars.value(reply, 0);
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   176
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   177
        if(progressBar)
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   178
        {
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   179
            progressBars.remove(reply);
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   180
            progressBar->deleteLater();
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   181
        }
5756
b451fd21ff4c Extract downloaded content into temp dir
unc0rr
parents: 5755
diff changeset
   182
8055
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   183
        QDir extractDir(*cfgdir);
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   184
        extractDir.cd("Data");
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   185
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   186
        QString fileName = extractDir.filePath(QFileInfo(reply->url().path()).fileName());
8059
07661fb20586 Download .zip too, and store them to .hwp
unc0rr
parents: 8055
diff changeset
   187
        if(fileName.endsWith(".zip"))
07661fb20586 Download .zip too, and store them to .hwp
unc0rr
parents: 8055
diff changeset
   188
            fileName = fileName.left(fileName.length() - 4) + ".hwp";
8055
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   189
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   190
        QFile out(fileName);
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   191
        if(!out.open(QFile::WriteOnly))
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   192
        {
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   193
            qWarning() << "out.open():" << out.errorString();
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   194
            return ;
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   195
        }
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   196
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   197
        out.write(reply->readAll());
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   198
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   199
        out.close();
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   200
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   201
        // now mount it
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 7824
diff changeset
   202
        FileEngineHandler::mount(fileName);
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   203
    }
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   204
}
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   205
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   206
void PageDataDownload::downloadProgress(qint64 bytesRecieved, qint64 bytesTotal)
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   207
{
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   208
    QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   209
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   210
    if(reply)
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   211
    {
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   212
        QProgressBar *progressBar = progressBars.value(reply, 0);
5746
fbc52bb92cad Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents: 5582
diff changeset
   213
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   214
        if(progressBar)
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   215
        {
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   216
            progressBar->setValue(bytesRecieved);
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   217
            progressBar->setMaximum(bytesTotal);
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   218
        }
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   219
    }
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   220
}
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   221
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   222
void PageDataDownload::fetchList()
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   223
{
11631
6225dfeba347 https4dlc
sheepluva
parents: 11046
diff changeset
   224
    request(QUrl("https://hedgewars.org/content.html"));
5754
583b7a683b17 - Implement progressbars to show download progress
unc0rr
parents: 5746
diff changeset
   225
}
5756
b451fd21ff4c Extract downloaded content into temp dir
unc0rr
parents: 5755
diff changeset
   226
6932
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
   227
void PageDataDownload::onPageLeave()
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
   228
{
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
   229
    if (m_contentDownloaded)
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
   230
    {
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
   231
        m_contentDownloaded = false;
7824
3df73ec7fcf2 disable F5 key and data refresh
sheepluva
parents: 7823
diff changeset
   232
        //DataManager::instance().reload();
6932
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
   233
    }
005393616925 make DLC trigger data reload
sheepluva
parents: 6700
diff changeset
   234
}
9829
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
   235
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
   236
void PageDataDownload::openPackagesDir()
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
   237
{
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
   238
    QString path = QDir::toNativeSeparators(cfgdir->absolutePath() + "/Data");
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
   239
    QDesktopServices::openUrl(QUrl("file:///" + path));
1804dd141015 'Open packages directory' button on dlc page
unc0rr
parents: 9080
diff changeset
   240
}