1 #include "konq_aboutpage.h"
2 
3 #include <QApplication>
4 #include <QDir>
5 #include <QSaveFile>
6 #include <QStandardPaths>
7 #include <QTextCodec>
8 #include <QTextStream>
9 #include <QUrl>
10 #include <QBuffer>
11 #include <QWebEngineUrlRequestJob>
12 
13 #include <kiconloader.h>
14 #include <KI18n/KLocalizedString>
15 
16 #include <webenginepart_debug.h>
17 
Q_GLOBAL_STATIC(KonqAboutPageSingleton,s_staticData)18 Q_GLOBAL_STATIC(KonqAboutPageSingleton, s_staticData)
19 
20 static QString loadFile(const QString &file)
21 {
22     QString res;
23     if (file.isEmpty()) {
24         return res;
25     }
26 
27     QFile f(file);
28 
29     if (!f.open(QIODevice::ReadOnly)) {
30         return res;
31     }
32 
33     QTextStream t(&f);
34 
35     res = t.readAll();
36 
37     // otherwise all embedded objects are referenced as konq/...
38     QString basehref = QLatin1String("<BASE HREF=\"file:") +
39                        file.left(file.lastIndexOf('/')) +
40                        QLatin1String("/\">\n");
41     res.replace(QLatin1String("<head>"), "<head>\n\t" + basehref, Qt::CaseInsensitive);
42     return res;
43 }
44 
launch()45 QString KonqAboutPageSingleton::launch()
46 {
47     if (!m_launch_html.isEmpty()) {
48         return m_launch_html;
49     }
50 
51     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/launch.html")));
52     if (res.isEmpty()) {
53         return res;
54     }
55 
56     KIconLoader *iconloader = KIconLoader::global();
57     int iconSize = iconloader->currentSize(KIconLoader::Desktop);
58     QString home_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("user-home"), KIconLoader::Desktop)).toString();
59     QString remote_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("folder-remote"), KIconLoader::Desktop)).toString();
60     QString wastebin_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("user-trash-full"), KIconLoader::Desktop)).toString();
61     QString bookmarks_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("bookmarks"), KIconLoader::Desktop)).toString();
62     QString home_folder = QUrl::fromLocalFile(QDir::homePath()).toString();
63     QString continue_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-previous" : "go-next", KIconLoader::Small)).toString();
64 
65     res = res.arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage.css"))).toString());
66     if (qApp->layoutDirection() == Qt::RightToLeft) {
67         res = res.arg(QStringLiteral("@import \"%1\";")).arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage_rtl.css"))).toString());
68     } else {
69         res = res.arg(QLatin1String(""));
70     }
71 
72     res = res.arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
73           .arg(i18n("Konqueror"))
74           .arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
75           .arg(i18n("Konqueror is a web browser, file manager and universal document viewer."))
76           .arg(i18nc("Link that points to the first page of the Konqueror 'about page', Starting Points contains links to Home, Network Folders, Trash, etc.", "Starting Points"))
77           .arg(i18n("Introduction"))
78           .arg(i18n("Tips"))
79           .arg(i18n("Specifications"))
80           .arg(home_folder)
81           .arg(home_icon_path)
82           .arg(iconSize).arg(iconSize)
83           .arg(home_folder)
84           .arg(i18n("Home Folder"))
85           .arg(i18n("Your personal files"))
86           .arg(wastebin_icon_path)
87           .arg(iconSize).arg(iconSize)
88           .arg(i18n("Trash"))
89           .arg(i18n("Browse and restore the trash"))
90           .arg(remote_icon_path)
91           .arg(iconSize).arg(iconSize)
92           .arg(i18n("Network Folders"))
93           .arg(i18n("Shared files and folders"))
94           .arg(bookmarks_icon_path)
95           .arg(iconSize).arg(iconSize)
96           .arg(i18n("Bookmarks"))
97           .arg(i18n("Quick access to your bookmarks"))
98           .arg(continue_icon_path)
99           .arg(KIconLoader::SizeSmall).arg(KIconLoader::SizeSmall)
100           .arg(i18n("Next: An Introduction to Konqueror"))
101           ;
102     i18n("Search the Web");//i18n for possible future use
103 
104     m_launch_html = res;
105     qCDebug(WEBENGINEPART_LOG) << " HTML : "<<res;
106     return res;
107 }
108 
intro()109 QString KonqAboutPageSingleton::intro()
110 {
111     if (!m_intro_html.isEmpty()) {
112         return m_intro_html;
113     }
114 
115     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/intro.html")));
116     if (res.isEmpty()) {
117         return res;
118     }
119 
120     KIconLoader *iconloader = KIconLoader::global();
121     QString back_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-next" : "go-previous", KIconLoader::Small)).toString();
122     QString gohome_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("go-home"), KIconLoader::Small)).toString();
123     QString continue_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-previous" : "go-next", KIconLoader::Small)).toString();
124 
125     res = res.arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage.css"))).toString());
126     if (qApp->layoutDirection() == Qt::RightToLeft) {
127         res = res.arg(QStringLiteral("@import \"%1\";")).arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage_rtl.css"))).toString());
128     } else {
129         res = res.arg(QLatin1String(""));
130     }
131 
132     res = res.arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
133           .arg(i18n("Konqueror"))
134           .arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
135           .arg(i18n("Konqueror is a web browser, file manager and universal document viewer."))
136           .arg(i18nc("Link that points to the first page of the Konqueror 'about page', Starting Points contains links to Home, Network Folders, Trash, etc.", "Starting Points"))
137           .arg(i18n("Introduction"))
138           .arg(i18n("Tips"))
139           .arg(i18n("Specifications"))
140           .arg(i18n("Konqueror makes working with and managing your files easy. You can browse "
141                     "both local and networked folders while enjoying advanced features "
142                     "such as the powerful sidebar and file previews."
143                    ))
144           .arg(i18n("Konqueror is also a full featured and easy to use web browser which you "
145                     "can use to explore the Internet. "
146                     "Enter the address (e.g. <a href=\"http://www.kde.org\">http://www.kde.org</a>) "
147                     "of a web page you would like to visit in the location bar and press Enter, "
148                     "or choose an entry from the Bookmarks menu."))
149           .arg(i18n("To return to the previous "
150                     "location, press the back button <img width='16' height='16' src=\"%1\"></img> "
151                     "in the toolbar. ",  back_icon_path))
152           .arg(i18n("To quickly go to your Home folder press the "
153                     "home button <img width='16' height='16' src=\"%1\"></img>.", gohome_icon_path))
154           .arg(i18n("For more detailed documentation on Konqueror click <a href=\"%1\">here</a>.",
155                     QStringLiteral("exec:/khelpcenter help:/konqueror")))
156           .arg(QStringLiteral("<img width='16' height='16' src=\"%1\">")).arg(continue_icon_path)
157           .arg(i18n("Next: Tips & Tricks"))
158           ;
159 
160     m_intro_html = res;
161     return res;
162 }
163 
specs()164 QString KonqAboutPageSingleton::specs()
165 {
166     if (!m_specs_html.isEmpty()) {
167         return m_specs_html;
168     }
169 
170     KIconLoader *iconloader = KIconLoader::global();
171     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/specs.html")));
172     QString continue_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-previous" : "go-next", KIconLoader::Small)).toString();
173     if (res.isEmpty()) {
174         return res;
175     }
176 
177     res = res.arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage.css"))).toString());
178     if (qApp->layoutDirection() == Qt::RightToLeft) {
179         res = res.arg(QStringLiteral("@import \"%1\";")).arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage_rtl.css"))).toString());
180     } else {
181         res = res.arg(QLatin1String(""));
182     }
183 
184     res = res.arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
185           .arg(i18n("Konqueror"))
186           .arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
187           .arg(i18n("Konqueror is a web browser, file manager and universal document viewer."))
188           .arg(i18nc("Link that points to the first page of the Konqueror 'about page', Starting Points contains links to Home, Network Folders, Trash, etc.", "Starting Points"))
189           .arg(i18n("Introduction"))
190           .arg(i18n("Tips"))
191           .arg(i18n("Specifications"))
192           .arg(i18n("Specifications"))
193           .arg(i18n("Konqueror is designed to embrace and support Internet standards. "
194                     "The aim is to fully implement the officially sanctioned standards "
195                     "from organizations such as the W3 and OASIS, while also adding "
196                     "extra support for other common usability features that arise as "
197                     "de facto standards across the Internet. Along with this support, "
198                     "for such functions as favicons, Web Shortcuts, and <A HREF=\"%1\">XBEL bookmarks</A>, "
199                     "Konqueror also implements:", QStringLiteral("http://xbel.sourceforge.net/")))
200           .arg(i18n("Web Browsing"))
201           .arg(i18n("Supported standards"))
202           .arg(i18n("Additional requirements*"))
203           .arg(i18n("<A HREF=\"%1\">DOM</A> (Level 1, partially Level 2) based "
204                     "<A HREF=\"%2\">HTML 4.01</A>", QStringLiteral("http://www.w3.org/DOM"), QStringLiteral("http://www.w3.org/TR/html4/")))
205           .arg(i18n("built-in"))
206           .arg(i18n("<A HREF=\"%1\">Cascading Style Sheets</A> (CSS 1, partially CSS 2)", QStringLiteral("http://www.w3.org/Style/CSS/")))
207           .arg(i18n("built-in"))
208           .arg(i18n("<A HREF=\"%1\">ECMA-262</A> Edition 3 (roughly equals JavaScript 1.5)",
209                     QStringLiteral("http://www.ecma-international.org/publications/standards/ECMA-262.HTM")))
210           .arg(i18n("JavaScript disabled (globally). Enable JavaScript <A HREF=\"%1\">here</A>.", QStringLiteral("exec:/kcmshell5 khtml_java_js")))
211           .arg(i18n("JavaScript enabled (globally). Configure JavaScript <A HREF=\\\"%1\\\">here</A>.", QStringLiteral("exec:/kcmshell5 khtml_java_js")))   // leave the double backslashes here, they are necessary for javascript !
212           .arg(i18n("Secure <A HREF=\"%1\">Java</A><SUP>&reg;</SUP> support", QStringLiteral("http://www.oracle.com/technetwork/java/index.html")))
213           .arg(i18n("JDK 1.2.0 (Java 2) compatible VM (<A HREF=\"%1\">OpenJDK</A> or <A HREF=\"%2\">Sun/Oracle</A>)",
214                     QStringLiteral("http://openjdk.java.net/"), QStringLiteral("http://www.oracle.com/technetwork/java/index.html")))
215           .arg(i18n("Enable Java (globally) <A HREF=\"%1\">here</A>.", QStringLiteral("exec:/kcmshell5 khtml_java_js")))   // TODO Maybe test if Java is enabled ?
216           .arg(i18n("NPAPI <A HREF=\"%2\">plugins</A> (for viewing <A HREF=\"%1\">Flash<SUP>&reg;</SUP></A>, etc.)",
217                     QStringLiteral("https://get.adobe.com/flashplayer/"),
218                     QStringLiteral("konq:plugins")))
219           .arg(i18n("built-in"))
220           .arg(i18n("Secure Sockets Layer"))
221           .arg(i18n("(TLS/SSL v2/3) for secure communications up to 168bit"))
222           .arg(i18n("OpenSSL"))
223           .arg(i18n("Bidirectional 16bit unicode support"))
224           .arg(i18n("built-in"))
225           .arg(i18n("AutoCompletion for forms"))
226           .arg(i18n("built-in"))
227           .arg(i18nc("Title of an html 'group box' explaining konqueror features", "General"))
228           .arg(i18n("Feature"))
229           .arg(i18n("Details"))
230           .arg(i18n("Image formats"))
231           .arg(i18n("PNG<br />JPG<br />GIF"))
232           .arg(i18n("Transfer protocols"))
233           .arg(i18n("HTTP 1.1 (including gzip/bzip2 compression)"))
234           .arg(i18n("FTP"))
235           .arg(i18n("and <A HREF=\"%1\">many more (see Kioslaves in KHelpCenter)...</A>", QStringLiteral("exec:/khelpcenter")))
236           .arg(i18nc("A feature of Konqueror", "URL-Completion"))
237           .arg(i18n("Manual"))
238           .arg(i18n("Popup"))
239           .arg(i18n("(Short-) Automatic"))
240           .arg(QStringLiteral("<img width='16' height='16' src=\"%1\">")).arg(continue_icon_path)
241           .arg(i18nc("Link that points to the first page of the Konqueror 'about page', Starting Points contains links to Home, Network Folders, Trash, etc.", "<a href=\"%1\">Return to Starting Points</a>", QStringLiteral("konq:konqueror")))
242 
243           ;
244 
245     m_specs_html = res;
246     return res;
247 }
248 
tips()249 QString KonqAboutPageSingleton::tips()
250 {
251     if (!m_tips_html.isEmpty()) {
252         return m_tips_html;
253     }
254 
255     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/tips.html")));
256     if (res.isEmpty()) {
257         return res;
258     }
259 
260     KIconLoader *iconloader = KIconLoader::global();
261     QString viewmag_icon_path =
262         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("format-font-size-more"), KIconLoader::Small)).toString();
263     QString history_icon_path =
264         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("view-history"), KIconLoader::Small)).toString();
265     QString openterm_icon_path =
266         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("utilities-terminal"), KIconLoader::Small)).toString();
267     QString locationbar_erase_rtl_icon_path =
268         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("edit-clear-locationbar-ltr"), KIconLoader::Small)).toString();
269     QString locationbar_erase_icon_path =
270         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("edit-clear-locationbar-rtl"), KIconLoader::Small)).toString();
271     QString window_fullscreen_icon_path =
272         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("view-fullscreen"), KIconLoader::Small)).toString();
273     QString view_left_right_icon_path =
274         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("view-split-left-right"), KIconLoader::Small)).toString();
275     QString continue_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-previous" : "go-next", KIconLoader::Small)).toString();
276 
277     res = res.arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage.css"))).toString());
278     if (qApp->layoutDirection() == Qt::RightToLeft) {
279         res = res.arg(QStringLiteral("@import \"%1\";")).arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage_rtl.css"))).toString());
280     } else {
281         res = res.arg(QLatin1String(""));
282     }
283 
284     res = res.arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
285           .arg(i18n("Konqueror"))
286           .arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
287           .arg(i18n("Konqueror is a web browser, file manager and universal document viewer."))
288           .arg(i18nc("Link that points to the first page of the Konqueror 'about page', Starting Points contains links to Home, Network Folders, Trash, etc.", "Starting Points"))
289           .arg(i18n("Introduction"))
290           .arg(i18n("Tips"))
291           .arg(i18n("Specifications"))
292           .arg(i18n("Tips & Tricks"))
293           .arg(i18n("Use Web-Shortcuts: by typing \"gg: KDE\" one can search the Internet, "
294                     "using Google, for the search phrase \"KDE\". There are a lot of "
295                     "Web-Shortcuts predefined to make searching for software or looking "
296                     "up certain words in an encyclopedia a breeze. You can even "
297                     "<a href=\"%1\">create your own</a> Web-Shortcuts.", QStringLiteral("exec:/kcmshell5 webshortcuts")))
298           .arg(i18n("Use the magnifier button <img width='16' height='16' src=\"%1\"></img> in the HTML"
299                     " toolbar to increase the font size on your web page.", viewmag_icon_path))
300           .arg(i18n("When you want to paste a new address into the Location toolbar you might want to "
301                     "clear the current entry by pressing the black arrow with the white cross "
302                     "<img width='16' height='16' src=\"%1\"></img> in the toolbar.",
303                     QApplication::isRightToLeft() ? locationbar_erase_rtl_icon_path : locationbar_erase_icon_path))
304           .arg(i18n("To create a link on your desktop pointing to the current page, "
305                     "simply drag the icon (favicon) that is to the left of the Location toolbar, drop it on to "
306                     "the desktop, and choose \"Icon\"."))
307           .arg(i18n("You can also find <img width='16' height='16' src=\"%1\" /> \"Full-Screen Mode\" "
308                     "in the Settings menu. This feature is very useful for \"Talk\" "
309                     "sessions.", window_fullscreen_icon_path))
310           .arg(i18n("Divide et impera (lat. \"Divide and conquer\") - by splitting a window "
311                     "into two parts (e.g. Window -> <img width='16' height='16' src=\"%1\" /> Split View "
312                     "Left/Right) you can make Konqueror appear the way you like.", view_left_right_icon_path))
313           .arg(i18n("Use the <a href=\"%1\">user-agent</a> feature if the website you are visiting "
314                     "asks you to use a different browser "
315                     "(and do not forget to send a complaint to the webmaster!)", QStringLiteral("exec:/kcmshell5 useragent")))
316           .arg(i18n("The <img width='16' height='16' src=\"%1\"></img> History in your Sidebar ensures "
317                     "that you can keep track of the pages you have visited recently.", history_icon_path))
318           .arg(i18n("Use a caching <a href=\"%1\">proxy</a> to speed up your"
319                     " Internet connection.", QStringLiteral("exec:/kcmshell5 proxy")))
320           .arg(i18n("Advanced users will appreciate the Konsole which you can embed into "
321                     "Konqueror (Settings -> <img width='16' height='16' SRC=\"%1\"></img> Show "
322                     "Terminal Emulator).", openterm_icon_path))
323           .arg(QStringLiteral("<img width='16' height='16' src=\"%1\">")).arg(continue_icon_path)
324           .arg(i18n("Next: Specifications"))
325           ;
326 
327     m_tips_html = res;
328     return res;
329 }
330 
plugins()331 QString KonqAboutPageSingleton::plugins()
332 {
333     if (!m_plugins_html.isEmpty()) {
334         return m_plugins_html;
335     }
336 
337     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, qApp->layoutDirection() == Qt::RightToLeft ? "konqueror/about/plugins_rtl.html" : "konqueror/about/plugins.html"))
338                   .arg(i18n("Installed Plugins"))
339                   .arg(i18n("<td>Plugin</td><td>Description</td><td>File</td><td>Types</td>"))
340                   .arg(i18n("Installed"))
341                   .arg(i18n("<td>Mime Type</td><td>Description</td><td>Suffixes</td><td>Plugin</td>"));
342     if (res.isEmpty()) {
343         return res;
344     }
345 
346     m_plugins_html = res;
347     return res;
348 }
349 
KonqUrlSchemeHandler(QObject * parent)350 KonqUrlSchemeHandler::KonqUrlSchemeHandler(QObject *parent) : QWebEngineUrlSchemeHandler(parent)
351 {
352 }
353 
~KonqUrlSchemeHandler()354 KonqUrlSchemeHandler::~KonqUrlSchemeHandler()
355 {
356 }
357 
requestStarted(QWebEngineUrlRequestJob * req)358 void KonqUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *req)
359 {
360   QBuffer* buf = new QBuffer(this);
361   buf->open(QBuffer::ReadWrite);
362   connect(buf, &QIODevice::aboutToClose, buf, &QObject::deleteLater);
363   QString data;
364   QString path = req->requestUrl().path();
365   if (path.endsWith("specs")) {
366     data = s_staticData->specs();
367   } else if (path.endsWith("intro")) {
368     data = s_staticData->intro();
369   } else if (path.endsWith("tips")) {
370     data = s_staticData->tips();
371   } else if (path.endsWith("plugins")) {
372     data = s_staticData->plugins();
373   } else {
374     data = s_staticData->launch();
375   }
376   buf->write(data.toUtf8());
377   buf->seek(0);
378   req->reply("text/html", buf);
379 }
380