~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/applets/webbrowser/errorpage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
 
 
21
#include <QApplication>
 
22
#include <QDateTime>
 
23
#include <QFile>
 
24
#include <QNetworkReply>
 
25
#include <QTextDocument>
 
26
 
 
27
#include <kdebug.h>
 
28
#include <kio/global.h>
 
29
#include <KIconLoader>
 
30
#include <KLocale>
 
31
#include <KStandardDirs>
 
32
 
 
33
#include "errorpage.h"
 
34
 
 
35
int webKitErrorToKIOError(int eValue)
 
36
{
 
37
    switch (eValue){
 
38
        case QNetworkReply::NoError:
 
39
            return 0;
 
40
 
 
41
        case QNetworkReply::ConnectionRefusedError:
 
42
            return KIO::ERR_COULD_NOT_CONNECT;
 
43
 
 
44
        case QNetworkReply::HostNotFoundError:
 
45
            return KIO::ERR_UNKNOWN_HOST;
 
46
 
 
47
        case QNetworkReply::TimeoutError:
 
48
            return KIO::ERR_SERVER_TIMEOUT;
 
49
 
 
50
        case QNetworkReply::OperationCanceledError:
 
51
            return KIO::ERR_ABORTED;
 
52
 
 
53
        case QNetworkReply::ProxyNotFoundError:
 
54
            return KIO::ERR_UNKNOWN_PROXY_HOST;
 
55
 
 
56
        case QNetworkReply::ContentAccessDenied:
 
57
            return KIO::ERR_ACCESS_DENIED;
 
58
 
 
59
        case QNetworkReply::ContentOperationNotPermittedError:
 
60
            return KIO::ERR_WRITE_ACCESS_DENIED;
 
61
 
 
62
        case QNetworkReply::ContentNotFoundError:
 
63
            return KIO::ERR_NO_CONTENT;
 
64
 
 
65
        case QNetworkReply::AuthenticationRequiredError:
 
66
            return KIO::ERR_COULD_NOT_AUTHENTICATE;
 
67
 
 
68
        case QNetworkReply::ProtocolUnknownError:
 
69
            return KIO::ERR_UNSUPPORTED_PROTOCOL;
 
70
 
 
71
        case QNetworkReply::ProtocolInvalidOperationError:
 
72
            return KIO::ERR_UNSUPPORTED_ACTION;
 
73
 
 
74
        default:
 
75
            return KIO::ERR_UNKNOWN;
 
76
    }
 
77
}
 
78
 
 
79
/*
 
80
 * from khtml_part code
 
81
 */
 
82
QString errorPageHtml( int errorCode, const QString& text, const KUrl& reqUrl )
 
83
{
 
84
  QString errorName, techName, description;
 
85
  QStringList causes, solutions;
 
86
 
 
87
  QByteArray raw = KIO::rawErrorDetail( errorCode, text, &reqUrl );
 
88
  QDataStream stream(raw);
 
89
 
 
90
  stream >> errorName >> techName >> description >> causes >> solutions;
 
91
 
 
92
  QString url, protocol, datetime;
 
93
  url = Qt::escape( reqUrl.prettyUrl() );
 
94
  protocol = reqUrl.protocol();
 
95
  datetime = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(),
 
96
                                                KLocale::LongDate );
 
97
 
 
98
  QString filename( KStandardDirs::locate( "data", "khtml/error.html" ) );
 
99
  QFile file( filename );
 
100
  bool isOpened = file.open( QIODevice::ReadOnly );
 
101
  if ( !isOpened )
 
102
    kWarning(6050) << "Could not open error html template:" << filename;
 
103
 
 
104
  QString html = QString( QLatin1String( file.readAll() ) );
 
105
 
 
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());
 
111
 
 
112
  QString doc = QLatin1String( "<h1>" );
 
113
  doc += i18n( "The requested operation could not be completed" );
 
114
  doc += QLatin1String( "</h1><h2>" );
 
115
  doc += errorName;
 
116
  doc += QLatin1String( "</h2>" );
 
117
  if ( !techName.isNull() ) {
 
118
    doc += QLatin1String( "<h2>" );
 
119
    doc += i18n( "Technical Reason: " );
 
120
    doc += techName;
 
121
    doc += QLatin1String( "</h2>" );
 
122
  }
 
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>" );
 
131
  }
 
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>" );
 
138
  doc += description;
 
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>" );
 
146
  }
 
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>" );
 
153
  }
 
154
 
 
155
  html.replace( QLatin1String("TEXT"), doc );
 
156
  
 
157
  return html;
 
158
}