1
/* This file is part of the KDE project
3
* Copyright (C) Hamish Rodda, Urs Wolfer, Davide Bettio
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
21
#include <QApplication>
24
#include <QNetworkReply>
25
#include <QTextDocument>
28
#include <kio/global.h>
29
#include <KIconLoader>
31
#include <KStandardDirs>
33
#include "errorpage.h"
35
int webKitErrorToKIOError(int eValue)
38
case QNetworkReply::NoError:
41
case QNetworkReply::ConnectionRefusedError:
42
return KIO::ERR_COULD_NOT_CONNECT;
44
case QNetworkReply::HostNotFoundError:
45
return KIO::ERR_UNKNOWN_HOST;
47
case QNetworkReply::TimeoutError:
48
return KIO::ERR_SERVER_TIMEOUT;
50
case QNetworkReply::OperationCanceledError:
51
return KIO::ERR_ABORTED;
53
case QNetworkReply::ProxyNotFoundError:
54
return KIO::ERR_UNKNOWN_PROXY_HOST;
56
case QNetworkReply::ContentAccessDenied:
57
return KIO::ERR_ACCESS_DENIED;
59
case QNetworkReply::ContentOperationNotPermittedError:
60
return KIO::ERR_WRITE_ACCESS_DENIED;
62
case QNetworkReply::ContentNotFoundError:
63
return KIO::ERR_NO_CONTENT;
65
case QNetworkReply::AuthenticationRequiredError:
66
return KIO::ERR_COULD_NOT_AUTHENTICATE;
68
case QNetworkReply::ProtocolUnknownError:
69
return KIO::ERR_UNSUPPORTED_PROTOCOL;
71
case QNetworkReply::ProtocolInvalidOperationError:
72
return KIO::ERR_UNSUPPORTED_ACTION;
75
return KIO::ERR_UNKNOWN;
80
* from khtml_part code
82
QString errorPageHtml( int errorCode, const QString& text, const KUrl& reqUrl )
84
QString errorName, techName, description;
85
QStringList causes, solutions;
87
QByteArray raw = KIO::rawErrorDetail( errorCode, text, &reqUrl );
88
QDataStream stream(raw);
90
stream >> errorName >> techName >> description >> causes >> solutions;
92
QString url, protocol, datetime;
93
url = Qt::escape( reqUrl.prettyUrl() );
94
protocol = reqUrl.protocol();
95
datetime = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(),
98
QString filename( KStandardDirs::locate( "data", "khtml/error.html" ) );
99
QFile file( filename );
100
bool isOpened = file.open( QIODevice::ReadOnly );
102
kWarning(6050) << "Could not open error html template:" << filename;
104
QString html = QString( QLatin1String( file.readAll() ) );
106
html.replace( QLatin1String( "TITLE" ), i18n( "Error: %1 - %2", errorName, url ) );
107
html.replace( QLatin1String( "DIRECTION" ), QApplication::isRightToLeft() ? "rtl" : "ltr" );
108
KUrl iconUrl(KIconLoader::global()->iconPath( "dialog-warning", -KIconLoader::SizeHuge ));
109
iconUrl.setProtocol("file://");
110
html.replace( QLatin1String( "ICON_PATH" ), iconUrl.url());
112
QString doc = QLatin1String( "<h1>" );
113
doc += i18n( "The requested operation could not be completed" );
114
doc += QLatin1String( "</h1><h2>" );
116
doc += QLatin1String( "</h2>" );
117
if ( !techName.isNull() ) {
118
doc += QLatin1String( "<h2>" );
119
doc += i18n( "Technical Reason: " );
121
doc += QLatin1String( "</h2>" );
123
doc += QLatin1String( "<h3>" );
124
doc += i18n( "Details of the Request:" );
125
doc += QLatin1String( "</h3><ul><li>" );
126
doc += i18n( "URL: %1" , url );
127
doc += QLatin1String( "</li><li>" );
128
if ( !protocol.isNull() ) {
129
doc += i18n( "Protocol: %1", protocol );
130
doc += QLatin1String( "</li><li>" );
132
doc += i18n( "Date and Time: %1" , datetime );
133
doc += QLatin1String( "</li><li>" );
134
doc += i18n( "Additional Information: %1" , text );
135
doc += QLatin1String( "</li></ul><h3>" );
136
doc += i18n( "Description:" );
137
doc += QLatin1String( "</h3><p>" );
139
doc += QLatin1String( "</p>" );
140
if ( causes.count() ) {
141
doc += QLatin1String( "<h3>" );
142
doc += i18n( "Possible Causes:" );
143
doc += QLatin1String( "</h3><ul><li>" );
144
doc += causes.join( "</li><li>" );
145
doc += QLatin1String( "</li></ul>" );
147
if ( solutions.count() ) {
148
doc += QLatin1String( "<h3>" );
149
doc += i18n( "Possible Solutions:" );
150
doc += QLatin1String( "</h3><ul><li>" );
151
doc += solutions.join( "</li><li>" );
152
doc += QLatin1String( "</li></ul>" );
155
html.replace( QLatin1String("TEXT"), doc );