File indexing completed on 2024-12-22 04:43:19

0001 #include "konq_aboutpage.h"
0002 
0003 #include <QApplication>
0004 #include <QDir>
0005 #include <QSaveFile>
0006 #include <QStandardPaths>
0007 #include <QTextStream>
0008 #include <QUrl>
0009 #include <QBuffer>
0010 #include <QWebEngineUrlRequestJob>
0011 
0012 #include <kiconloader.h>
0013 #include <KLocalizedString>
0014 
0015 #include <webenginepart_debug.h>
0016 
0017 Q_GLOBAL_STATIC(KonqAboutPageSingleton, s_staticData)
0018 
0019 static QString loadFile(const QString &file)
0020 {
0021     QString res;
0022     if (file.isEmpty()) {
0023         return res;
0024     }
0025 
0026     QFile f(file);
0027 
0028     if (!f.open(QIODevice::ReadOnly)) {
0029         return res;
0030     }
0031 
0032     QTextStream t(&f);
0033 
0034     res = t.readAll();
0035 
0036     // otherwise all embedded objects are referenced as konq/...
0037     QString basehref = QLatin1String("<BASE HREF=\"file:") +
0038                        file.left(file.lastIndexOf('/')) +
0039                        QLatin1String("/\">\n");
0040     res.replace(QLatin1String("<head>"), "<head>\n\t" + basehref, Qt::CaseInsensitive);
0041     return res;
0042 }
0043 
0044 QString KonqAboutPageSingleton::launch()
0045 {
0046     if (!m_launch_html.isEmpty()) {
0047         return m_launch_html;
0048     }
0049 
0050     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/launch.html")));
0051     if (res.isEmpty()) {
0052         return res;
0053     }
0054 
0055     KIconLoader *iconloader = KIconLoader::global();
0056     int iconSize = iconloader->currentSize(KIconLoader::Desktop);
0057     QString home_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("user-home"), KIconLoader::Desktop)).toString();
0058     QString remote_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("folder-remote"), KIconLoader::Desktop)).toString();
0059     QString wastebin_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("user-trash-full"), KIconLoader::Desktop)).toString();
0060     QString bookmarks_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("bookmarks"), KIconLoader::Desktop)).toString();
0061     QString home_folder = QUrl::fromLocalFile(QDir::homePath()).toString();
0062     QString continue_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-previous" : "go-next", KIconLoader::Small)).toString();
0063 
0064     res = res.arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/kde_infopage.css"))).toString());
0065     if (qApp->layoutDirection() == Qt::RightToLeft) {
0066         res = res.arg(QStringLiteral("@import \"%1\";")).arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/kde_infopage_rtl.css"))).toString());
0067     } else {
0068         res = res.arg(QLatin1String(""));
0069     }
0070 
0071     res = res.arg(i18nc("KDE 4 tag line", "Be free."))
0072           .arg(i18n("Konqueror"))
0073           .arg(i18nc("KDE 4 tag line", "Be free."))
0074           .arg(i18n("Konqueror is a web browser, file manager and universal document viewer."))
0075           .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"))
0076           .arg(i18n("Introduction"))
0077           .arg(i18n("Tips"))
0078           .arg(home_folder)
0079           .arg(home_icon_path)
0080           .arg(iconSize).arg(iconSize)
0081           .arg(home_folder)
0082           .arg(i18n("Home Folder"))
0083           .arg(i18n("Your personal files"))
0084           .arg(wastebin_icon_path)
0085           .arg(iconSize).arg(iconSize)
0086           .arg(i18n("Trash"))
0087           .arg(i18n("Browse and restore the trash"))
0088           .arg(remote_icon_path)
0089           .arg(iconSize).arg(iconSize)
0090           .arg(i18n("Network Folders"))
0091           .arg(i18n("Shared files and folders"))
0092           .arg(bookmarks_icon_path)
0093           .arg(iconSize).arg(iconSize)
0094           .arg(i18n("Bookmarks"))
0095           .arg(i18n("Quick access to your bookmarks"))
0096           .arg(continue_icon_path)
0097           .arg(KIconLoader::SizeSmall).arg(KIconLoader::SizeSmall)
0098           .arg(i18n("Next: An Introduction to Konqueror"))
0099           ;
0100     i18n("Search the Web");//i18n for possible future use
0101 
0102     m_launch_html = res;
0103     qCDebug(WEBENGINEPART_LOG) << " HTML : "<<res;
0104     return res;
0105 }
0106 
0107 QString KonqAboutPageSingleton::intro()
0108 {
0109     if (!m_intro_html.isEmpty()) {
0110         return m_intro_html;
0111     }
0112 
0113     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/intro.html")));
0114     if (res.isEmpty()) {
0115         return res;
0116     }
0117 
0118     KIconLoader *iconloader = KIconLoader::global();
0119     QString back_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-next" : "go-previous", KIconLoader::Small)).toString();
0120     QString gohome_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("go-home"), KIconLoader::Small)).toString();
0121     QString continue_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-previous" : "go-next", KIconLoader::Small)).toString();
0122 
0123     res = res.arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/kde_infopage.css"))).toString());
0124     if (qApp->layoutDirection() == Qt::RightToLeft) {
0125         res = res.arg(QStringLiteral("@import \"%1\";")).arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/kde_infopage_rtl.css"))).toString());
0126     } else {
0127         res = res.arg(QLatin1String(""));
0128     }
0129 
0130     res = res.arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
0131           .arg(i18n("Konqueror"))
0132           .arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free."))
0133           .arg(i18n("Konqueror is a web browser, file manager and universal document viewer."))
0134           .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"))
0135           .arg(i18n("Introduction"))
0136           .arg(i18n("Tips"))
0137           .arg(i18n("Konqueror makes working with and managing your files easy. You can browse "
0138                     "both local and networked folders while enjoying advanced features "
0139                     "such as the powerful sidebar and file previews."
0140                    ))
0141           .arg(i18n("Konqueror is also a full featured and easy to use web browser which you "
0142                     "can use to explore the Internet. "
0143                     "Enter the address (e.g. <a href=\"http://www.kde.org\">http://www.kde.org</a>) "
0144                     "of a web page you would like to visit in the location bar and press Enter, "
0145                     "or choose an entry from the Bookmarks menu."))
0146           .arg(i18n("To return to the previous "
0147                     "location, press the back button <img width='16' height='16' src=\"%1\"></img> "
0148                     "in the toolbar. ",  back_icon_path))
0149           .arg(i18n("To quickly go to your Home folder press the "
0150                     "home button <img width='16' height='16' src=\"%1\"></img>.", gohome_icon_path))
0151           .arg(i18n("For more detailed documentation on Konqueror click <a href=\"%1\">here</a>.",
0152                     QStringLiteral("https://docs.kde.org/?application=konqueror")))
0153           .arg(QStringLiteral("<img width='16' height='16' src=\"%1\">")).arg(continue_icon_path)
0154           .arg(i18n("Next: Tips & Tricks"))
0155           ;
0156 
0157     m_intro_html = res;
0158     return res;
0159 }
0160 
0161 QString KonqAboutPageSingleton::tips()
0162 {
0163     if (!m_tips_html.isEmpty()) {
0164         return m_tips_html;
0165     }
0166 
0167     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/tips.html")));
0168     if (res.isEmpty()) {
0169         return res;
0170     }
0171 
0172     KIconLoader *iconloader = KIconLoader::global();
0173     QString viewmag_icon_path =
0174         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("format-font-size-more"), KIconLoader::Small)).toString();
0175     QString history_icon_path =
0176         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("view-history"), KIconLoader::Small)).toString();
0177     QString openterm_icon_path =
0178         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("utilities-terminal"), KIconLoader::Small)).toString();
0179     QString locationbar_erase_rtl_icon_path =
0180         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("edit-clear-locationbar-ltr"), KIconLoader::Small)).toString();
0181     QString locationbar_erase_icon_path =
0182         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("edit-clear-locationbar-rtl"), KIconLoader::Small)).toString();
0183     QString window_fullscreen_icon_path =
0184         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("view-fullscreen"), KIconLoader::Small)).toString();
0185     QString view_left_right_icon_path =
0186         QUrl::fromLocalFile(iconloader->iconPath(QStringLiteral("view-split-left-right"), KIconLoader::Small)).toString();
0187     QString continue_icon_path = QUrl::fromLocalFile(iconloader->iconPath(QApplication::isRightToLeft() ? "go-previous" : "go-next", KIconLoader::Small)).toString();
0188 
0189     res = res.arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/kde_infopage.css"))).toString());
0190     if (qApp->layoutDirection() == Qt::RightToLeft) {
0191         res = res.arg(QStringLiteral("@import \"%1\";")).arg(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konqueror/about/kde_infopage_rtl.css"))).toString());
0192     } else {
0193         res = res.arg(QLatin1String(""));
0194     }
0195 
0196     res = res.arg(i18nc("KDE 4 tag line", "Be free."))
0197           .arg(i18n("Konqueror"))
0198           .arg(i18nc("KDE 4 tag line", "Be free."))
0199           .arg(i18n("Konqueror is a web browser, file manager and universal document viewer."))
0200           .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"))
0201           .arg(i18n("Introduction"))
0202           .arg(i18n("Tips"))
0203           .arg(i18n("Tips & Tricks"))
0204           .arg(i18n("Use Web-Shortcuts: by typing \"gg: KDE\" one can search the Internet, "
0205                     "using Google, for the search phrase \"KDE\". There are a lot of "
0206                     "Web-Shortcuts predefined to make searching for software or looking "
0207                     "up certain words in an encyclopedia a breeze. You can even "
0208                     "<a href=\"%1\">create your own</a> Web-Shortcuts.", QStringLiteral("exec:kcmshell5 webshortcuts")))
0209           .arg(i18n("When you want to paste a new address into the Location toolbar you might want to "
0210                     "clear the current entry by pressing the black arrow with the white cross "
0211                     "<img width='16' height='16' src=\"%1\"></img> in the toolbar.",
0212                     QApplication::isRightToLeft() ? locationbar_erase_rtl_icon_path : locationbar_erase_icon_path))
0213           .arg(i18n("To create a link on your desktop pointing to the current page, "
0214                     "simply drag the icon (favicon) that is to the left of the Location toolbar, drop it on to "
0215                     "the desktop, and choose \"Icon\"."))
0216           .arg(i18n("You can also find <img width='16' height='16' src=\"%1\" /> \"Full-Screen Mode\" "
0217                     "in the Settings menu. This feature is very useful for \"Talk\" "
0218                     "sessions.", window_fullscreen_icon_path))
0219           .arg(i18n("Divide et impera (lat. \"Divide and conquer\") - by splitting a window "
0220                     "into two parts (e.g. Window -> <img width='16' height='16' src=\"%1\" /> Split View "
0221                     "Left/Right) you can make Konqueror appear the way you like.", view_left_right_icon_path))
0222           .arg(i18n("Use the <a href=\"%1\">user-agent</a> feature if the website you are visiting "
0223                     "asks you to use a different browser "
0224                     "(and do not forget to send a complaint to the webmaster!)", QStringLiteral("exec:kcmshell5 useragent")))
0225           .arg(i18n("The <img width='16' height='16' src=\"%1\"></img> History in your Sidebar ensures "
0226                     "that you can keep track of the pages you have visited recently.", history_icon_path))
0227           .arg(i18n("Advanced users will appreciate the Konsole which you can embed into "
0228                     "Konqueror (Settings -> <img width='16' height='16' SRC=\"%1\"></img> Show "
0229                     "Terminal Emulator).", openterm_icon_path))
0230           .arg(QStringLiteral("<img width='16' height='16' src=\"%1\">")).arg(continue_icon_path)
0231           .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")))
0232           ;
0233 
0234     m_tips_html = res;
0235     return res;
0236 }
0237 
0238 QString KonqAboutPageSingleton::plugins()
0239 {
0240     if (!m_plugins_html.isEmpty()) {
0241         return m_plugins_html;
0242     }
0243 
0244     QString res = loadFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, qApp->layoutDirection() == Qt::RightToLeft ? "konqueror/about/plugins_rtl.html" : "konqueror/about/plugins.html"))
0245                   .arg(i18n("Installed Plugins"))
0246                   .arg(i18n("<td>Plugin</td><td>Description</td><td>File</td><td>Types</td>"))
0247                   .arg(i18n("Installed"))
0248                   .arg(i18n("<td>Mime Type</td><td>Description</td><td>Suffixes</td><td>Plugin</td>"));
0249     if (res.isEmpty()) {
0250         return res;
0251     }
0252 
0253     m_plugins_html = res;
0254     return res;
0255 }
0256 
0257 KonqUrlSchemeHandler::KonqUrlSchemeHandler(QObject *parent) : QWebEngineUrlSchemeHandler(parent)
0258 {
0259 }
0260 
0261 KonqUrlSchemeHandler::~KonqUrlSchemeHandler()
0262 {
0263 }
0264 
0265 void KonqUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *req)
0266 {
0267     QBuffer* buf = new QBuffer(this);
0268     buf->open(QBuffer::ReadWrite);
0269     connect(buf, &QIODevice::aboutToClose, buf, &QObject::deleteLater);
0270     QString data;
0271     QString path = req->requestUrl().path();
0272     if (path.endsWith(QStringLiteral("blank"))) {
0273         data = QStringLiteral();
0274     } else if (path.endsWith(QStringLiteral("intro"))) {
0275         data = s_staticData->intro();
0276     } else if (path.endsWith(QStringLiteral("tips"))) {
0277         data = s_staticData->tips();
0278     } else if (path.endsWith(QStringLiteral("plugins"))) {
0279         data = s_staticData->plugins();
0280     } else {
0281         data = s_staticData->launch();
0282     }
0283     buf->write(data.toUtf8());
0284     buf->seek(0);
0285     req->reply("text/html", buf);
0286 }