File: articlewebpage.cpp

package info (click to toggle)
goldendict-webengine 23.02.05-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,148 kB
  • sloc: cpp: 58,537; javascript: 9,942; ansic: 9,242; xml: 41; makefile: 15; sh: 9
file content (38 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "articlewebpage.h"
#include "utils.hh"

ArticleWebPage::ArticleWebPage(QObject *parent)
  : QWebEnginePage{parent}
{
}
bool ArticleWebPage::acceptNavigationRequest( const QUrl & resUrl, NavigationType type, bool isMainFrame )
{
  QUrl url = resUrl;
  if( url.scheme() == "bword" || url.scheme() == "entry" )
  {
    url.setScheme( "gdlookup" );
    url.setHost( "localhost" );
    url.setPath( "" );
    auto [ valid, word ] = Utils::Url::getQueryWord( resUrl );
    Utils::Url::addQueryItem( url, "word", word );
    Utils::Url::addQueryItem( url, "group", lastReq.group );
    Utils::Url::addQueryItem( url, "muted", lastReq.mutedDicts );
    setUrl( url );
    return false;
  }

  //save current gdlookup's values.
  if( url.scheme() == "gdlookup" )
  {
    lastReq.group      = Utils::Url::queryItemValue( url, "group" );
    lastReq.mutedDicts = Utils::Url::queryItemValue( url, "muted" );
  }

  if( type == QWebEnginePage::NavigationTypeLinkClicked )
  {
    emit linkClicked( url );
    return false;
  }

  return QWebEnginePage::acceptNavigationRequest( url, type, isMainFrame );
}