diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,18 +23,20 @@ DBus Widgets Xml + WebEngineWidgets ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Archive Bookmarks + Completion Config CoreAddons DBusAddons DocTools I18n Init - KHtml + KIO Service WindowSystem ) @@ -95,7 +97,6 @@ application.cpp treebuilder.cpp infotree.cpp - fontdialog.cpp plugintraverser.cpp scrollkeepertreebuilder.cpp bookmarkowner.cpp @@ -107,7 +108,7 @@ kf5_add_kdeinit_executable( khelpcenter ${khelpcenter_KDEINIT_SRCS}) target_compile_definitions(kdeinit_khelpcenter PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") -target_link_libraries(kdeinit_khelpcenter KF5::KHtml KF5::Service KF5::DBusAddons KF5::ConfigGui KF5::WindowSystem KF5::Bookmarks Qt5::Xml Grantlee5::Templates) +target_link_libraries(kdeinit_khelpcenter KF5::I18n KF5::XmlGui KF5::KIOCore KF5::KIOWidgets KF5::Completion Qt5::WebEngineWidgets KF5::Service KF5::DBusAddons KF5::ConfigGui KF5::WindowSystem KF5::Bookmarks Qt5::Xml Grantlee5::Templates) target_link_libraries(kdeinit_khelpcenter KF5::DocTools) install(TARGETS kdeinit_khelpcenter ${INSTALL_TARGETS_DEFAULT_ARGS} ) install(TARGETS khelpcenter ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/bookmarkowner.cpp b/bookmarkowner.cpp --- a/bookmarkowner.cpp +++ b/bookmarkowner.cpp @@ -23,8 +23,6 @@ #include "view.h" -#include - using namespace KHC; BookmarkOwner::BookmarkOwner( View *view, QObject *parent ) @@ -39,12 +37,12 @@ QString BookmarkOwner::currentTitle() const { - return currentUrl().isValid() ? mView->htmlDocument().title().string() : QString(); + return currentUrl().isValid() ? mView->title() : QString(); } QUrl BookmarkOwner::currentUrl() const { - const QUrl url = mView->baseURL(); + const QUrl url = mView->url(); // khelpcenter: URLs are internal, hence to not bookmark return url.scheme() == QLatin1String( "khelpcenter" ) ? QUrl() : url; } diff --git a/fontdialog.h b/fontdialog.h deleted file mode 100644 --- a/fontdialog.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of the KDE Help Center - * - * Copyright (C) 2003 Frerich Raabe - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#ifndef KHC_FONTDIALOG_H -#define KHC_FONTDIALOG_H - -#include - -class QSpinBox; - -class KComboBox; -class QFontComboBox; - -namespace KHC { - - class FontDialog : public QDialog - { - Q_OBJECT - - public: - explicit FontDialog( QWidget *parent ); - - protected Q_SLOTS: - virtual void slotOk(); - - private: - void setupFontSizesBox(); - void setupFontTypesBox(); - void setupFontEncodingBox(); - - void load(); - void save(); - - QSpinBox *m_minFontSize; - QSpinBox *m_medFontSize; - QFontComboBox *m_standardFontCombo; - QFontComboBox *m_fixedFontCombo; - QFontComboBox *m_serifFontCombo; - QFontComboBox *m_sansSerifFontCombo; - QFontComboBox *m_italicFontCombo; - QFontComboBox *m_fantasyFontCombo; - KComboBox *m_defaultEncoding; - QSpinBox *m_fontSizeAdjustement; - }; - -} - -#endif // KHC_FONTDIALOG_H -// vim:ts=4:sw=4:noet diff --git a/fontdialog.cpp b/fontdialog.cpp deleted file mode 100644 --- a/fontdialog.cpp +++ /dev/null @@ -1,236 +0,0 @@ - -/* - * This file is part of the KDE Help Center - * - * Copyright (C) 2003 Frerich Raabe - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "fontdialog.h" - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace KHC; - -FontDialog::FontDialog( QWidget *parent ) - : QDialog( parent ) -{ - setModal( true ); - setWindowTitle( i18n( "Font Configuration" ) ); - QVBoxLayout *mainLayout = new QVBoxLayout; - setLayout(mainLayout); - - setupFontSizesBox(); - setupFontTypesBox(); - setupFontEncodingBox(); - - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); - QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); - okButton->setDefault(true); - okButton->setShortcut(Qt::CTRL | Qt::Key_Return); - connect(buttonBox, &QDialogButtonBox::accepted, this, &FontDialog::slotOk); - connect(buttonBox, &QDialogButtonBox::rejected, this, &FontDialog::reject); - mainLayout->addWidget(buttonBox); - - load(); -} - -void FontDialog::slotOk() -{ - save(); - accept(); -} - -void FontDialog::setupFontSizesBox() -{ - QGroupBox *gb = new QGroupBox( i18n( "Sizes" ), this ); - layout()->addWidget( gb ); - - QGridLayout *layout = new QGridLayout( gb ); -//TODO PORT QT5 layout->setSpacing( QDialog::spacingHint() ); -//TODO PORT QT5 layout->setMargin( QDialog::marginHint() * 2 ); - - QLabel *lMinFontSize = new QLabel( i18nc( "The smallest size a will have", "M&inimum font size:" ), gb ); - layout->addWidget( lMinFontSize, 0, 0 ); - m_minFontSize = new QSpinBox( gb ); - layout->addWidget( m_minFontSize, 0, 1 ); - m_minFontSize->setRange( 1, 20 ); - lMinFontSize->setBuddy( m_minFontSize ); - - QLabel *lMedFontSize = new QLabel( i18nc( "The normal size a font will have", "M&edium font size:" ), gb ); - layout->addWidget( lMedFontSize, 1, 0 ); - m_medFontSize = new QSpinBox( gb ); - layout->addWidget( m_medFontSize, 1, 1 ); - m_medFontSize->setRange( 4, 28 ); - lMedFontSize->setBuddy( m_medFontSize ); -} - -void FontDialog::setupFontTypesBox() -{ - QGroupBox *gb = new QGroupBox( i18n( "Fonts" ), this ); - layout()->addWidget( gb ); - - QGridLayout *layout = new QGridLayout( gb ); -//TODO PORT QT5 layout->setSpacing( QDialog::spacingHint() ); -//TODO PORT QT5 layout->setMargin( QDialog::marginHint() * 2 ); - - QLabel *lStandardFont = new QLabel( i18n( "S&tandard font:" ), gb ); - layout->addWidget( lStandardFont, 0, 0 ); - m_standardFontCombo = new QFontComboBox( gb ); - layout->addWidget( m_standardFontCombo, 0, 1 ); - lStandardFont->setBuddy( m_standardFontCombo ); - - QLabel *lFixedFont = new QLabel( i18n( "F&ixed font:" ), gb ); - layout->addWidget( lFixedFont, 1, 0 ); - m_fixedFontCombo = new QFontComboBox( gb ); - layout->addWidget( m_fixedFontCombo, 1, 1 ); - lFixedFont->setBuddy( m_fixedFontCombo ); - - QLabel *lSerifFont = new QLabel( i18n( "S&erif font:" ), gb ); - layout->addWidget( lSerifFont, 2, 0 ); - m_serifFontCombo = new QFontComboBox( gb ); - layout->addWidget( m_serifFontCombo, 2, 1 ); - lSerifFont->setBuddy( m_serifFontCombo ); - - QLabel *lSansSerifFont = new QLabel( i18n( "S&ans serif font:" ), gb ); - layout->addWidget( lSansSerifFont, 3, 0 ); - m_sansSerifFontCombo = new QFontComboBox( gb ); - layout->addWidget( m_sansSerifFontCombo, 3, 1 ); - lSansSerifFont->setBuddy( m_sansSerifFontCombo ); - - QLabel *lItalicFont = new QLabel( i18n( "&Italic font:" ), gb ); - layout->addWidget( lItalicFont, 4, 0 ); - m_italicFontCombo = new QFontComboBox( gb ); - layout->addWidget( m_italicFontCombo, 4, 1 ); - lItalicFont->setBuddy( m_italicFontCombo ); - - QLabel *lFantasyFont = new QLabel( i18n( "&Fantasy font:" ), gb ); - layout->addWidget( lFantasyFont, 5, 0 ); - m_fantasyFontCombo = new QFontComboBox( gb ); - layout->addWidget( m_fantasyFontCombo, 5, 1 ); - lFantasyFont->setBuddy( m_fantasyFontCombo ); -} - -void FontDialog::setupFontEncodingBox() -{ - QGroupBox *gb = new QGroupBox( i18n( "Encoding" ), this ); - layout()->addWidget( gb ); - - QGridLayout *layout = new QGridLayout( gb ); -//TODO PORT QT5 layout->setSpacing( QDialog::spacingHint() ); -//TODO PORT QT5 layout->setMargin( QDialog::marginHint() * 2 ); - - QLabel *lDefaultEncoding = new QLabel( i18n( "&Default encoding:" ), gb ); - layout->addWidget( lDefaultEncoding, 0, 0 ); - m_defaultEncoding = new KComboBox( false, gb ); - layout->addWidget( m_defaultEncoding, 0, 1 ); - QStringList encodings = KCharsets::charsets()->availableEncodingNames(); - encodings.prepend( i18n( "Use Language Encoding" ) ); - m_defaultEncoding->addItems( encodings ); - lDefaultEncoding->setBuddy( m_defaultEncoding ); - - QLabel *lFontSizeAdjustement = new QLabel( i18n( "&Font size adjustment:" ), gb ); - layout->addWidget( lFontSizeAdjustement, 1, 0 ); - m_fontSizeAdjustement = new QSpinBox( gb ); - m_fontSizeAdjustement->setRange( -5, 5 ); - m_fontSizeAdjustement->setSingleStep( 1 ); - layout->addWidget( m_fontSizeAdjustement, 1, 1 ); - lFontSizeAdjustement->setBuddy( m_fontSizeAdjustement ); -} - -void FontDialog::load() -{ - KSharedConfig::Ptr cfg = KSharedConfig::openConfig(); - { - KConfigGroup configGroup( cfg, "HTML Settings" ); - - m_minFontSize->setValue( configGroup.readEntry( "MinimumFontSize", static_cast(HTML_DEFAULT_MIN_FONT_SIZE) ) ); - m_medFontSize->setValue( configGroup.readEntry( "MediumFontSize", 10 ) ); - - QStringList fonts = configGroup.readEntry( "Fonts" , QStringList() ); - if ( fonts.isEmpty() ) { - fonts << QFontDatabase::systemFont(QFontDatabase::GeneralFont).family() - << QFontDatabase::systemFont(QFontDatabase::FixedFont).family() - << QStringLiteral(HTML_DEFAULT_VIEW_SERIF_FONT) - << QStringLiteral(HTML_DEFAULT_VIEW_SANSSERIF_FONT) - << QStringLiteral(HTML_DEFAULT_VIEW_CURSIVE_FONT) - << QStringLiteral(HTML_DEFAULT_VIEW_FANTASY_FONT) - << QString(); - } - - m_standardFontCombo->setCurrentFont( fonts[ 0 ] ); - m_fixedFontCombo->setCurrentFont( fonts[ 1 ] ); - m_serifFontCombo->setCurrentFont( fonts[ 2 ] ); - m_sansSerifFontCombo->setCurrentFont( fonts[ 3 ] ); - m_italicFontCombo->setCurrentFont( fonts[ 4 ] ); - m_fantasyFontCombo->setCurrentFont( fonts[ 5 ] ); - - QString encoding = configGroup.readEntry( "DefaultEncoding" ); - if (encoding.isEmpty()) m_defaultEncoding->setCurrentIndex( 0 ); - else m_defaultEncoding->setCurrentItem( encoding ); - m_fontSizeAdjustement->setValue( fonts[ 6 ].toInt() ); - } -} - -void FontDialog::save() -{ - KSharedConfig::Ptr cfg = KSharedConfig::openConfig(); - Prefs::setUseKonqSettings( false ); - { - KConfigGroup configGroup( cfg, "HTML Settings" ); - - configGroup.writeEntry( "MinimumFontSize", m_minFontSize->value() ); - configGroup.writeEntry( "MediumFontSize", m_medFontSize->value() ); - - QStringList fonts; - fonts << m_standardFontCombo->currentFont().family() - << m_fixedFontCombo->currentFont().family() - << m_serifFontCombo->currentFont().family() - << m_sansSerifFontCombo->currentFont().family() - << m_italicFontCombo->currentFont().family() - << m_fantasyFontCombo->currentFont().family() - << QString::number( m_fontSizeAdjustement->value() ); - - configGroup.writeEntry( "Fonts", fonts ); - - if ( m_defaultEncoding->currentText() == i18n( "Use Language Encoding" ) ) - configGroup.writeEntry( "DefaultEncoding", QString() ); - else - configGroup.writeEntry( "DefaultEncoding", m_defaultEncoding->currentText() ); - } - cfg->sync(); -} - -// vim:ts=4:sw=4:noet diff --git a/glossary.cpp b/glossary.cpp --- a/glossary.cpp +++ b/glossary.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/history.cpp b/history.cpp --- a/history.cpp +++ b/history.cpp @@ -130,9 +130,6 @@ Entry *current = *m_entries_current; - QDataStream stream( ¤t->buffer, QIODevice::WriteOnly ); - view->browserExtension()->saveState( stream ); - current->view = view; if ( url.isEmpty() ) { @@ -243,9 +240,8 @@ QDataStream stream( h.buffer ); - h.view->closeUrl(); + h.view->stop(); updateCurrentEntry( h.view ); - h.view->browserExtension()->restoreState( stream ); updateActions(); diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -24,13 +24,12 @@ #include -#include - #include "glossary.h" class QSplitter; class LogDialog; +class KJob; namespace KIO { @@ -58,7 +57,6 @@ Q_SCRIPTABLE void lastSearch(); public Q_SLOTS: - void print(); void statusBarRichTextMessage(const QString &m); void statusBarMessage(const QString &m); void slotShowHome(); @@ -81,9 +79,7 @@ /** Show document corresponding to given URL in viewer part. */ - void viewUrl( const QUrl &url, - const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments() ); + void viewUrl( const QUrl &url); void saveProperties( KConfigGroup &config ) override; void readProperties( const KConfigGroup &config ) override; @@ -100,19 +96,14 @@ private Q_SLOTS: void slotGlossSelected(const GlossaryEntry &entry); - void slotStarted(KIO::Job *job); + void slotStarted(); void slotInfoMessage(KJob *, const QString &); void goInternalUrl( const QUrl & ); /** This function is called when the user clicks on a link in the viewer part. */ - void slotOpenURLRequest( const QUrl &url, - const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments()); + void slotOpenURLRequest( const QUrl &url); void documentCompleted(); - void slotIncFontSizes(); - void slotDecFontSizes(); - void slotConfigureFonts(); void slotCopySelectedText(); private: diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -24,7 +24,6 @@ #include "history.h" #include "view.h" #include "searchengine.h" -#include "fontdialog.h" #include "khc_debug.h" #include "navigator.h" #include "grantleeformatter.h" @@ -51,8 +50,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -113,20 +111,17 @@ QDBusConnection::sessionBus().registerObject(QStringLiteral("/KHelpCenter"), this, QDBusConnection::ExportScriptableSlots); mSplitter = new QSplitter( this ); - mDoc = new View( mSplitter, this, KHTMLPart::DefaultGUI, actionCollection() ); - connect( mDoc, &View::setWindowCaption, this, &MainWindow::setWindowTitle ); - connect( mDoc, &KParts::Part::setStatusBarText, this, &MainWindow::statusBarRichTextMessage ); - connect( mDoc, &View::onURL, this, &MainWindow::statusBarMessage ); - connect( mDoc, &View::started, this, &MainWindow::slotStarted ); - connect( mDoc, QOverload<>::of(&View::completed), this, &MainWindow::documentCompleted ); + mDoc = new View( mSplitter, actionCollection() ); + connect( mDoc, &View::titleChanged, this, &MainWindow::setWindowTitle ); + connect( mDoc->page(), &QWebEnginePage::linkHovered, this, &MainWindow::statusBarMessage ); + connect( mDoc, &QWebEngineView::loadStarted, this, &MainWindow::slotStarted ); + connect( mDoc, &View::loadFinished, this, &MainWindow::documentCompleted ); connect( mDoc, &View::searchResultCacheAvailable, this, &MainWindow::enableLastSearchAction ); connect( mDoc, &View::selectionChanged, this, &MainWindow::enableCopyTextAction ); statusBar()->showMessage(i18n("Preparing Index")); - connect( mDoc->browserExtension(), &KParts::BrowserExtension::openUrlRequest, this, &MainWindow::slotOpenURLRequest ); - mNavigator = new Navigator( mDoc, mSplitter ); mNavigator->setObjectName( QStringLiteral("nav") ); connect( mNavigator, &Navigator::itemSelected, this, QOverload::of(&MainWindow::viewUrl) ); @@ -140,19 +135,8 @@ sizes << 220 << 580; mSplitter->setSizes(sizes); - { - if ( Prefs::useKonqSettings() ) { - KConfig konqCfg( QStringLiteral("konquerorrc") ); - const_cast( mDoc->settings() )->init( &konqCfg ); - } - const int fontScaleFactor = Prefs::fontzoomfactor(); - mDoc->setFontScaleFactor( fontScaleFactor ); - } - setupActions(); - foreach (QAction *act, mDoc->actionCollection()->actions()) - actionCollection()->addAction(act->objectName(), act); setupBookmarks(); @@ -182,7 +166,7 @@ void MainWindow::saveProperties( KConfigGroup &config ) { - config.writePathEntry( "URL" , mDoc->baseURL().url() ); + config.writePathEntry( "URL" , mDoc->url().toString() ); } void MainWindow::readProperties( const KConfigGroup &config ) @@ -214,18 +198,6 @@ actionCollection()->addAction( KStandardAction::Quit, this, SLOT(close()) ); actionCollection()->addAction( KStandardAction::Print, this, SLOT(print()) ); - QAction *prevPage = actionCollection()->addAction( QStringLiteral("prevPage") ); - prevPage->setText( i18n( "Previous Page" ) ); - actionCollection()->setDefaultShortcut(prevPage, Qt::CTRL+Qt::Key_PageUp ); - prevPage->setWhatsThis( i18n( "Moves to the previous page of the document" ) ); - connect( prevPage, &QAction::triggered, mDoc, &View::prevPage ); - - QAction *nextPage = actionCollection()->addAction( QStringLiteral("nextPage") ); - nextPage->setText( i18n( "Next Page" ) ); - actionCollection()->setDefaultShortcut(nextPage, Qt::CTRL + Qt::Key_PageDown ); - nextPage->setWhatsThis( i18n( "Moves to the next page of the document" ) ); - connect( nextPage, &QAction::triggered, mDoc, &View::nextPage ); - QAction *home = KStandardAction::home( this, SLOT(slotShowHome()), this ); actionCollection()->addAction( home->objectName(), home ); home->setText(i18n("Table of &Contents")); @@ -253,19 +225,6 @@ */ History::self().setupActions( actionCollection() ); - QAction *action = actionCollection()->addAction(QStringLiteral("configure_fonts" )); - action->setText( i18n( "Configure Fonts..." ) ); - connect( action, &QAction::triggered, this, &MainWindow::slotConfigureFonts ); - - action = actionCollection()->addAction(QStringLiteral("incFontSizes")); - action->setText( i18n( "Increase Font Sizes" ) ); - action->setIcon( QIcon::fromTheme( QStringLiteral("zoom-in") ) ); - connect( action, &QAction::triggered, this, &MainWindow::slotIncFontSizes ); - - action = actionCollection()->addAction(QStringLiteral("decFontSizes")); - action->setText( i18n( "Decrease Font Sizes" ) ); - action->setIcon( QIcon::fromTheme( QStringLiteral("zoom-out") ) ); - connect( action, &QAction::triggered, this, &MainWindow::slotDecFontSizes ); } void MainWindow::setupBookmarks() @@ -289,41 +248,31 @@ mDoc->copySelectedText(); } -void MainWindow::print() +void MainWindow::slotStarted() { - mDoc->view()->print(); -} - -void MainWindow::slotStarted(KIO::Job *job) -{ - if (job) - connect(job, &KIO::Job::infoMessage, this, &MainWindow::slotInfoMessage); - History::self().updateActions(); } void MainWindow::goInternalUrl( const QUrl &url ) { - mDoc->closeUrl(); + mDoc->stop(); slotOpenURLRequest( url ); } -void MainWindow::slotOpenURLRequest( const QUrl &url, - const KParts::OpenUrlArguments &args, - const KParts::BrowserArguments &browserArgs ) +void MainWindow::slotOpenURLRequest( const QUrl &url) { qCDebug(KHC_LOG) << url.url(); mNavigator->selectItem( url ); - viewUrl( url, args, browserArgs ); + viewUrl( url ); } void MainWindow::viewUrl( const QString &url ) { viewUrl( QUrl( url ) ); } -void MainWindow::viewUrl( const QUrl &url, const KParts::OpenUrlArguments &args, const KParts::BrowserArguments &browserArgs ) +void MainWindow::viewUrl( const QUrl &url ) { stop(); @@ -359,15 +308,12 @@ History::self().createEntry(); - mDoc->setArguments( args ); - mDoc->browserExtension()->setBrowserArguments( browserArgs ); - if ( proto == QLatin1String("glossentry") ) { QString decodedEntryId = QUrl::fromPercentEncoding( QUrl::toPercentEncoding(url.path()) ); slotGlossSelected( mNavigator->glossEntry( decodedEntryId ) ); mNavigator->slotSelectGlossEntry( decodedEntryId ); } else { - mDoc->openUrl( url ); + mDoc->load( url ); } } @@ -418,14 +364,12 @@ { stop(); History::self().createEntry(); - mDoc->begin( QUrl( QStringLiteral("glossentry:") + entry.id() ) ); - mDoc->write( mDoc->grantleeFormatter()->formatGlossaryEntry( entry ) ); - mDoc->end(); + mDoc->setInternalHtml( mDoc->grantleeFormatter()->formatGlossaryEntry( entry ), QUrl( QStringLiteral("glossentry:") + entry.id() ) ); } void MainWindow::stop() { - mDoc->closeUrl(); + mDoc->stop(); History::self().updateCurrentEntry( mDoc ); } @@ -468,40 +412,5 @@ mLogDialog->raise(); } -void MainWindow::slotIncFontSizes() -{ - mDoc->slotIncFontSizes(); - updateFontScaleActions(); -} - -void MainWindow::slotDecFontSizes() -{ - mDoc->slotDecFontSizes(); - updateFontScaleActions(); -} - -void MainWindow::updateFontScaleActions() -{ - actionCollection()->action( QStringLiteral("incFontSizes") )->setEnabled( mDoc->fontScaleFactor() + mDoc->fontScaleStepping() <= 300 ); - actionCollection()->action( QStringLiteral("decFontSizes") )->setEnabled( mDoc->fontScaleFactor() - mDoc->fontScaleStepping() >= 20 ); - - Prefs::setFontzoomfactor( mDoc->fontScaleFactor() ); - Prefs::self()->save(); -} - -void MainWindow::slotConfigureFonts() -{ - FontDialog dlg( this ); - if ( dlg.exec() == QDialog::Accepted ) - { - if (mDoc->baseURL().isEmpty()) - { - const_cast( mDoc->settings() )->init( KSharedConfig::openConfig().data() ); - slotShowHome(); - } - else mDoc->slotReload(); - } -} - // vim:ts=2:sw=2:et diff --git a/navigator.cpp b/navigator.cpp --- a/navigator.cpp +++ b/navigator.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "navigatoritem.h" #include "navigatorappitem.h" @@ -363,7 +364,7 @@ if ( url.scheme() == QLatin1String("khelpcenter") ) { - mView->closeUrl(); + mView->stop(); History::self().updateCurrentEntry( mView ); History::self().createEntry(); showOverview( item, url ); @@ -404,8 +405,6 @@ void Navigator::showOverview( NavigatorItem *item, const QUrl &url ) { - mView->beginInternal( url ); - QString title,name,content; uint childCount; @@ -434,9 +433,8 @@ else content += QLatin1String("

"); - mView->write( mView->grantleeFormatter()->formatOverview( title, name, content ) ); + mView->setInternalHtml( mView->grantleeFormatter()->formatOverview( title, name, content ), url ); - mView->end(); } QString Navigator::createChildrenList( QTreeWidgetItem *child, int level ) diff --git a/searchengine.cpp b/searchengine.cpp --- a/searchengine.cpp +++ b/searchengine.cpp @@ -29,6 +29,8 @@ #include +#include + namespace KHC { diff --git a/view.h b/view.h --- a/view.h +++ b/view.h @@ -22,83 +22,52 @@ #ifndef KHC_VIEW_H #define KHC_VIEW_H -#include +#include class KActionCollection; -namespace DOM { - class Node; - class HTMLLinkElement; -} - namespace KHC { class GrantleeFormatter; -class View : public KHTMLPart +class View : public QWebEngineView { Q_OBJECT public: - View( QWidget *parentWidget, QObject *parent, KHTMLPart::GUIProfile prof, - KActionCollection *col ); + View( QWidget *parentWidget, KActionCollection *col ); ~View(); - bool openUrl( const QUrl &url ) override; - - void saveState( QDataStream &stream ) override; - void restoreState( QDataStream &stream ) override; - enum State { Docu, About, Search }; int state() const { return mState; } - QString title() const { return mTitle; } static QString langLookup( const QString &fname ); void beginSearchResult(); void writeSearchResult( const QString & ); void endSearchResult(); - void beginInternal( const QUrl & ); + void setInternalHtml(const QString&, const QUrl&); QUrl internalUrl() const; - int fontScaleStepping() const { return m_fontScaleStepping; } - GrantleeFormatter *grantleeFormatter() const { return mGrantleeFormatter; } void copySelectedText(); public Q_SLOTS: void lastSearch(); - void slotIncFontSizes(); - void slotDecFontSizes(); void slotReload( const QUrl &url = QUrl() ); - void slotCopyLink(); - bool nextPage(bool checkOnly = false); - bool prevPage(bool checkOnly = false); Q_SIGNALS: void searchResultCacheAvailable(); - protected: - bool eventFilter( QObject *o, QEvent *e ) override; - - private Q_SLOTS: - void setTitle( const QString &title ); - void showMenu( const QString& url, const QPoint& pos); - private: - QUrl urlFromLinkNode( const DOM::HTMLLinkElement &link ) const; - int mState; - QString mTitle; QString mSearchResult; QUrl mInternalUrl; - int m_fontScaleStepping; - GrantleeFormatter *mGrantleeFormatter; KActionCollection *mActionCollection; QString mCopyURL; diff --git a/view.cpp b/view.cpp --- a/view.cpp +++ b/view.cpp @@ -25,18 +25,21 @@ #include "history.h" #include "khc_debug.h" -#include -#include -#include - #include -#include -#include #include #include +#include #include +#include #include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -46,36 +49,72 @@ #include #include #include +#include + + using namespace KHC; -View::View( QWidget *parentWidget, QObject *parent, KHTMLPart::GUIProfile prof, KActionCollection *col ) - : KHTMLPart( parentWidget, parent, prof ), mState( Docu ), mActionCollection(col) +class HelpUrlSchemeHandler : public QWebEngineUrlSchemeHandler { + void requestStarted(QWebEngineUrlRequestJob* job) { + qCDebug(KHC_LOG) << job->requestUrl(); + KIO::TransferJob* kiojob = KIO::get(job->requestUrl(), KIO::NoReload); + QByteArray result; + connect(kiojob, &KIO::TransferJob::data, this, [&result](KJob*, QByteArray data) { + result += data; + }); + kiojob->exec(); + auto buffer = new QBuffer(job); + buffer->setData(result); + job->reply("text/html", buffer); + + + } +}; + +View::View( QWidget *parentWidget, KActionCollection *col ) + : QWebEngineView( parentWidget), mState( Docu ), mActionCollection(col) { - setJScriptEnabled(false); - setJavaEnabled(false); - setPluginsEnabled(false); + page()->settings()->setUnknownUrlSchemePolicy(QWebEngineSettings::AllowAllUnknownUrlSchemes); + page()->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled,true); - mGrantleeFormatter = new GrantleeFormatter; + page()->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false); + page()->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); + + page()->profile()->installUrlSchemeHandler("help",new HelpUrlSchemeHandler); + page()->profile()->installUrlSchemeHandler("khelpcenter",new HelpUrlSchemeHandler); + page()->profile()->installUrlSchemeHandler("man",new HelpUrlSchemeHandler); + page()->profile()->installUrlSchemeHandler("file",new HelpUrlSchemeHandler); - m_fontScaleStepping = 10; - connect(this, &View::setWindowCaption, this, &View::setTitle); - connect( this, QOverload::of(&View::popupMenu), this, &View::showMenu ); + mGrantleeFormatter = new GrantleeFormatter; QString css = langLookup(QStringLiteral("kdoctools5-common/kde-default.css")); if (!css.isEmpty()) { - QFile css_file(css); - if (css_file.open(QIODevice::ReadOnly)) - { - QTextStream s(&css_file); - QString stylesheet = s.readAll(); - preloadStyleSheet(QStringLiteral("help:/kdoctools5-common/kde-default.css"), stylesheet); + QFile css_file(css); + if (css_file.open(QIODevice::ReadOnly)) + { + QTextStream stream(&css_file); + QString stylesheet = stream.readAll().replace(QLatin1Char('"'),QLatin1Char(' ')); + QWebEngineScript script; + QString s = QString::fromLatin1("(function() {"\ + " css = document.createElement('style');"\ + " css.type = 'text/css';"\ + " css.id = '%1';"\ + " document.head.appendChild(css);"\ + " css.innerText = \"%2\";"\ + "})()").arg(QStringLiteral("default")).arg(stylesheet.simplified()); + script.setName(QStringLiteral("default")); + script.setSourceCode(s); + script.setInjectionPoint(QWebEngineScript::DocumentReady); + script.setRunsOnSubFrames(true); + script.setWorldId(QWebEngineScript::ApplicationWorld); + page()->scripts().insert(script); } } - view()->installEventFilter( this ); + page()->installEventFilter( this ); } View::~View() @@ -88,26 +127,6 @@ qobject_cast(qApp)->clipboard()->setText( selectedText() ); } -bool View::openUrl( const QUrl &url ) -{ - mState = Docu; - return KHTMLPart::openUrl( url ); -} - -void View::saveState( QDataStream &stream ) -{ - stream << mState; - if ( mState == Docu ) - KHTMLPart::saveState( stream ); -} - -void View::restoreState( QDataStream &stream ) -{ - stream >> mState; - if ( mState == Docu ) - KHTMLPart::restoreState( stream ); -} - QString View::langLookup( const QString &fname ) { QStringList search; @@ -153,35 +172,28 @@ return QString(); } -void View::setTitle( const QString &title ) -{ - mTitle = title; -} - void View::beginSearchResult() { mState = Search; - begin( QUrl( QStringLiteral( "khelpcenter:search/result" ) ) ); mSearchResult = QString(); } void View::writeSearchResult( const QString &str ) { - write( str ); mSearchResult += str; } void View::endSearchResult() { - end(); + setInternalHtml(mSearchResult, QUrl( QStringLiteral( "khelpcenter:search/result" ) ) ); if ( !mSearchResult.isEmpty() ) emit searchResultCacheAvailable(); } -void View::beginInternal( const QUrl &url ) +void View::setInternalHtml(const QString& data, const QUrl &url ) { mInternalUrl = url; - begin( mInternalUrl ); + setHtml(data, url); } QUrl View::internalUrl() const @@ -195,170 +207,15 @@ mState = Search; - begin( QUrl( QStringLiteral( "khelpcenter:search/last" ) ) ); - write( mSearchResult ); - end(); -} - -void View::slotIncFontSizes() -{ - setFontScaleFactor( fontScaleFactor() + m_fontScaleStepping ); -} - -void View::slotDecFontSizes() -{ - setFontScaleFactor( fontScaleFactor() - m_fontScaleStepping ); -} - -void View::showMenu( const QString& url, const QPoint& pos) -{ - QMenu pop(view()); - - if (url.isEmpty()) - { - QAction *action; - action = mActionCollection->action(QStringLiteral("go_home")); - if (action) pop.addAction( action ); - - pop.addSeparator(); - - action = mActionCollection->action(QStringLiteral("prevPage")); - if (action) pop.addAction( action ); - action = mActionCollection->action(QStringLiteral("nextPage")); - if (action) pop.addAction( action); - - pop.addSeparator(); - - pop.addAction( History::self().m_backAction ); - pop.addAction( History::self().m_forwardAction ); - } - else - { - QAction *action = pop.addAction(i18n("Copy Link Address")); - connect(action, &QAction::triggered, this, &View::slotCopyLink); - - mCopyURL = completeURL(url).url(); - } - - pop.exec(pos); -} - -void View::slotCopyLink() -{ - QGuiApplication::clipboard()->setText(mCopyURL); -} - -static DOM::HTMLLinkElement findLink(const DOM::NodeList& links, const char *rel) -{ - for (unsigned i = 0; i <= links.length(); ++i) { - DOM::HTMLLinkElement link(links.item(i)); - if (link.isNull()) - continue; - - if (link.rel() == rel) - return link; - } - return DOM::HTMLLinkElement(); -} - -bool View::prevPage(bool checkOnly) -{ - const DOM::NodeList links = document().getElementsByTagName("link"); - - QUrl prevURL = urlFromLinkNode( findLink(links, "prev") ); - - if (!prevURL.isValid()) - return false; - - if (!checkOnly) - emit browserExtension()->openUrlRequest(prevURL); - return true; -} - -bool View::nextPage(bool checkOnly) -{ - const DOM::NodeList links = document().getElementsByTagName("link"); - - QUrl nextURL = urlFromLinkNode( findLink(links, "next") ); - - if (!nextURL.isValid()) - return false; - - if (!checkOnly) - emit browserExtension()->openUrlRequest(nextURL); - return true; -} - -bool View::eventFilter( QObject *o, QEvent *e ) -{ - if ( htmlDocument().links().length() == 0 ) - return KHTMLPart::eventFilter( o, e ); - - switch ( e->type() ) { - case QEvent::KeyPress: { - QKeyEvent *ke = static_cast( e ); - if ( ke->modifiers() & Qt::ShiftModifier && ke->key() == Qt::Key_Space ) { - // If we're on the first page, it does not make sense to go back. - if ( baseURL().path().endsWith( QLatin1String("/index.html") ) ) - return KHTMLPart::eventFilter( o, e ); - - const QScrollBar * const scrollBar = view()->verticalScrollBar(); - if ( scrollBar->value() == scrollBar->minimum() ) { - if (prevPage()) - return true; - } - } else if ( ke->key() == Qt::Key_Space ) { - const QScrollBar * const scrollBar = view()->verticalScrollBar(); - if ( scrollBar->value() == scrollBar->maximum() ) { - if (nextPage()) - return true; - } - } - break; - } - case QEvent::WhatsThis: { - QHelpEvent *he = static_cast( e ); - const QString text = i18n( "

Read the topic documentation in this window.

Press Space/Shift+Space to scroll, %1 to find something, Tab/Shift+Tab to jump, and Enter to follow.

", - actionCollection()->action( QStringLiteral("find") )->shortcut().toString( QKeySequence::NativeText ) ); - QWhatsThis::showText( he->globalPos(), text, qobject_cast( o ) ); - e->accept(); - return true; - } - case QEvent::QueryWhatsThis: - e->accept(); - return true; - default: - break; - } - return KHTMLPart::eventFilter( o, e ); -} - -QUrl View::urlFromLinkNode( const DOM::HTMLLinkElement &link ) const -{ - if ( link.isNull() ) - return QUrl(); - - DOM::DOMString domHref = link.href(); - if (domHref.isNull()) - return QUrl(); - - const QUrl domHrefUrl( domHref.string() ); - if ( !domHrefUrl.isRelative() ) - return domHrefUrl; - - return QUrl(baseURL().toString() +QLatin1Char('/')+ domHref.string()); + setHtml( mSearchResult, QUrl( QStringLiteral( "khelpcenter:search/last" ) ) ); } void View::slotReload( const QUrl &url ) { - const_cast( settings() )->init( KSharedConfig::openConfig().data() ); - KParts::OpenUrlArguments args = arguments(); - args.setReload( true ); - setArguments( args ); if ( url.isEmpty() ) - openUrl( baseURL() ); + reload(); else - openUrl( url ); + load( url ); }