2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
2023-04-17 20:12:27 +00:00
|
|
|
#include "articleview.hh"
|
2023-05-30 06:31:07 +00:00
|
|
|
#include "dict/programs.hh"
|
2021-12-19 10:37:27 +00:00
|
|
|
#include "folding.hh"
|
|
|
|
#include "gddebug.hh"
|
|
|
|
#include "gestures.hh"
|
2023-05-30 06:31:07 +00:00
|
|
|
#include "globalbroadcaster.hh"
|
|
|
|
#include "speechclient.hh"
|
2021-12-19 10:37:27 +00:00
|
|
|
#include "utils.hh"
|
|
|
|
#include "webmultimediadownload.hh"
|
|
|
|
#include "wildcard.hh"
|
|
|
|
#include "wstring_qt.hh"
|
2023-05-30 06:31:07 +00:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QClipboard>
|
2021-12-19 10:37:27 +00:00
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QDebug>
|
2009-02-01 00:08:08 +00:00
|
|
|
#include <QDesktopServices>
|
2021-12-19 10:37:27 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QRegularExpression>
|
2023-03-17 22:42:11 +00:00
|
|
|
#include <QVariant>
|
2021-12-19 10:37:27 +00:00
|
|
|
#include <QWebChannel>
|
2021-07-06 13:01:50 +00:00
|
|
|
#include <QWebEngineHistory>
|
|
|
|
#include <QWebEngineScript>
|
|
|
|
#include <QWebEngineScriptCollection>
|
2021-12-19 10:37:27 +00:00
|
|
|
#include <QWebEngineSettings>
|
|
|
|
#include <map>
|
2023-06-03 00:29:19 +00:00
|
|
|
#include <QApplication>
|
2023-05-30 06:31:07 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
|
|
|
#include <QWebEngineContextMenuData>
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
|
|
|
#include <QtCore5Compat/QRegExp>
|
|
|
|
#include <QWebEngineContextMenuRequest>
|
2023-06-03 00:29:19 +00:00
|
|
|
#include <QWebEngineFindTextResult>
|
|
|
|
#include <utility>
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2010-11-14 15:38:41 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
2023-07-20 08:02:22 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <QPainter>
|
2010-11-14 15:38:41 +00:00
|
|
|
#endif
|
2012-09-18 23:01:31 +00:00
|
|
|
|
2009-04-12 16:22:42 +00:00
|
|
|
using std::map;
|
2009-03-26 19:00:08 +00:00
|
|
|
using std::list;
|
|
|
|
|
2013-05-29 07:03:37 +00:00
|
|
|
|
2021-06-29 08:59:16 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
char const * const scrollToPrefix = "gdfrom-";
|
|
|
|
|
|
|
|
bool isScrollTo( QString const & id )
|
|
|
|
{
|
|
|
|
return id.startsWith( scrollToPrefix );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString dictionaryIdFromScrollTo( QString const & scrollTo )
|
|
|
|
{
|
|
|
|
Q_ASSERT( isScrollTo( scrollTo ) );
|
2023-06-03 00:29:19 +00:00
|
|
|
constexpr int scrollToPrefixLength = 7;
|
2021-06-29 08:59:16 +00:00
|
|
|
return scrollTo.mid( scrollToPrefixLength );
|
|
|
|
}
|
|
|
|
|
2022-07-02 13:36:19 +00:00
|
|
|
QString searchStatusMessageNoMatches()
|
|
|
|
{
|
|
|
|
return ArticleView::tr( "Phrase not found" );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString searchStatusMessage( int activeMatch, int matchCount )
|
|
|
|
{
|
|
|
|
Q_ASSERT( matchCount > 0 );
|
|
|
|
Q_ASSERT( activeMatch > 0 );
|
|
|
|
Q_ASSERT( activeMatch <= matchCount );
|
|
|
|
return ArticleView::tr( "%1 of %2 matches" ).arg( activeMatch ).arg( matchCount );
|
|
|
|
}
|
|
|
|
|
2021-06-29 08:59:16 +00:00
|
|
|
} // unnamed namespace
|
|
|
|
|
|
|
|
QString ArticleView::scrollToFromDictionaryId( QString const & dictionaryId )
|
|
|
|
{
|
|
|
|
Q_ASSERT( !isScrollTo( dictionaryId ) );
|
|
|
|
return scrollToPrefix + dictionaryId;
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
ArticleView::ArticleView( QWidget * parent,
|
|
|
|
ArticleNetworkAccessManager & nm,
|
|
|
|
AudioPlayerPtr const & audioPlayer_,
|
2009-04-12 16:22:42 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries_,
|
2023-07-20 08:02:22 +00:00
|
|
|
Instances::Groups const & groups_,
|
|
|
|
bool popupView_,
|
|
|
|
Config::Class const & cfg_,
|
2023-03-16 11:55:47 +00:00
|
|
|
QAction & openSearchAction_,
|
|
|
|
QLineEdit const * translateLine_,
|
|
|
|
QAction * dictionaryBarToggled_,
|
2023-07-20 08:02:22 +00:00
|
|
|
GroupComboBox const * groupComboBox_ ):
|
2023-03-17 09:42:44 +00:00
|
|
|
QWidget( parent ),
|
2009-01-28 20:55:45 +00:00
|
|
|
articleNetMgr( nm ),
|
2018-03-21 17:49:34 +00:00
|
|
|
audioPlayer( audioPlayer_ ),
|
2009-04-12 16:22:42 +00:00
|
|
|
allDictionaries( allDictionaries_ ),
|
2009-01-28 20:55:45 +00:00
|
|
|
groups( groups_ ),
|
2009-04-10 21:07:03 +00:00
|
|
|
popupView( popupView_ ),
|
2009-05-12 10:52:11 +00:00
|
|
|
cfg( cfg_ ),
|
2009-05-14 19:27:19 +00:00
|
|
|
pasteAction( this ),
|
2009-05-15 14:11:54 +00:00
|
|
|
articleUpAction( this ),
|
|
|
|
articleDownAction( this ),
|
2009-05-29 22:04:43 +00:00
|
|
|
goBackAction( this ),
|
|
|
|
goForwardAction( this ),
|
2013-01-18 14:37:24 +00:00
|
|
|
selectCurrentArticleAction( this ),
|
2013-05-15 13:52:47 +00:00
|
|
|
copyAsTextAction( this ),
|
2013-05-30 02:18:28 +00:00
|
|
|
inspectAction( this ),
|
2014-04-16 16:18:28 +00:00
|
|
|
openSearchAction( openSearchAction_ ),
|
2009-05-16 11:14:43 +00:00
|
|
|
searchIsOpened( false ),
|
2009-09-23 18:44:38 +00:00
|
|
|
dictionaryBarToggled( dictionaryBarToggled_ ),
|
2014-04-22 13:47:02 +00:00
|
|
|
groupComboBox( groupComboBox_ ),
|
2023-05-13 00:44:17 +00:00
|
|
|
translateLine( translateLine_ )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2023-07-17 00:24:02 +00:00
|
|
|
if ( groupComboBox_ )
|
|
|
|
currentGroupId = groupComboBox_->getCurrentGroup();
|
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
// setup GUI
|
2023-03-20 04:44:28 +00:00
|
|
|
webview = new ArticleWebView( this );
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel = new FtsSearchPanel( this );
|
|
|
|
searchPanel = new SearchPanel( this );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-03-18 06:45:40 +00:00
|
|
|
// Layout
|
2023-03-20 04:44:28 +00:00
|
|
|
auto * mainLayout = new QVBoxLayout( this );
|
|
|
|
mainLayout->addWidget( webview );
|
2023-03-17 09:42:44 +00:00
|
|
|
mainLayout->addWidget( ftsSearchPanel );
|
|
|
|
mainLayout->addWidget( searchPanel );
|
|
|
|
|
|
|
|
webview->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
|
|
|
ftsSearchPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
|
|
|
|
searchPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
|
|
|
|
|
|
|
|
mainLayout->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
|
|
|
|
// end UI setup
|
|
|
|
|
2023-03-17 22:42:11 +00:00
|
|
|
connect( searchPanel->previous, &QPushButton::clicked, this, &ArticleView::on_searchPrevious_clicked );
|
|
|
|
connect( searchPanel->next, &QPushButton::clicked, this, &ArticleView::on_searchNext_clicked );
|
|
|
|
connect( searchPanel->close, &QPushButton::clicked, this, &ArticleView::on_searchCloseButton_clicked );
|
|
|
|
connect( searchPanel->caseSensitive, &QPushButton::clicked, this, &ArticleView::on_searchCaseSensitive_clicked );
|
|
|
|
connect( searchPanel->highlightAll, &QPushButton::clicked, this, &ArticleView::on_highlightAllButton_clicked );
|
|
|
|
connect( searchPanel->lineEdit, &QLineEdit::textEdited, this, &ArticleView::on_searchText_textEdited );
|
|
|
|
connect( searchPanel->lineEdit, &QLineEdit::returnPressed, this, &ArticleView::on_searchText_returnPressed );
|
|
|
|
connect( ftsSearchPanel->next, &QPushButton::clicked, this, &ArticleView::on_ftsSearchNext_clicked );
|
|
|
|
connect( ftsSearchPanel->previous, &QPushButton::clicked, this, &ArticleView::on_ftsSearchPrevious_clicked );
|
2023-03-17 09:42:44 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2023-03-20 04:44:28 +00:00
|
|
|
webview->setUp( const_cast< Config::Class * >( &cfg ) );
|
|
|
|
|
2009-05-29 22:04:43 +00:00
|
|
|
goBackAction.setShortcut( QKeySequence( "Alt+Left" ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( &goBackAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &goBackAction, &QAction::triggered, this, &ArticleView::back );
|
2009-05-15 14:24:37 +00:00
|
|
|
|
2009-05-29 22:04:43 +00:00
|
|
|
goForwardAction.setShortcut( QKeySequence( "Alt+Right" ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( &goForwardAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &goForwardAction, &QAction::triggered, this, &ArticleView::forward );
|
2009-05-15 14:24:37 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->pageAction( QWebEnginePage::Copy )->setShortcut( QKeySequence::Copy );
|
|
|
|
webview->addAction( webview->pageAction( QWebEnginePage::Copy ) );
|
2009-04-03 21:57:23 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
QAction * selectAll = webview->pageAction( QWebEnginePage::SelectAll );
|
2021-08-21 01:41:40 +00:00
|
|
|
selectAll->setShortcut( QKeySequence::SelectAll );
|
|
|
|
selectAll->setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( selectAll );
|
2013-01-18 13:22:24 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->setContextMenuPolicy( Qt::CustomContextMenu );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( webview, &QWebEngineView::loadFinished, this, &ArticleView::loadFinished );
|
2021-12-19 10:37:27 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( webview, &ArticleWebView::linkClicked, this, &ArticleView::linkClicked );
|
2022-01-20 12:34:14 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( webview->page(), &QWebEnginePage::titleChanged, this, &ArticleView::handleTitleChanged );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( webview->page(), &QWebEnginePage::urlChanged, this, &ArticleView::handleUrlChanged );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( webview, &QWidget::customContextMenuRequested, this, &ArticleView::contextMenuRequested );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-06-11 14:31:47 +00:00
|
|
|
connect( webview->page(), &QWebEnginePage::linkHovered, this, &ArticleView::linkHovered );
|
2011-07-02 13:04:49 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( webview, &ArticleWebView::doubleClicked, this, &ArticleView::doubleClicked );
|
2010-04-08 20:37:59 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
pasteAction.setShortcut( QKeySequence::Paste );
|
|
|
|
webview->addAction( &pasteAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &pasteAction, &QAction::triggered, this, &ArticleView::pasteTriggered );
|
2009-05-12 10:52:11 +00:00
|
|
|
|
2009-05-15 14:11:54 +00:00
|
|
|
articleUpAction.setShortcut( QKeySequence( "Alt+Up" ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( &articleUpAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &articleUpAction, &QAction::triggered, this, &ArticleView::moveOneArticleUp );
|
2009-05-15 14:11:54 +00:00
|
|
|
|
|
|
|
articleDownAction.setShortcut( QKeySequence( "Alt+Down" ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( &articleDownAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &articleDownAction, &QAction::triggered, this, &ArticleView::moveOneArticleDown );
|
2009-05-15 14:11:54 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( &openSearchAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &openSearchAction, &QAction::triggered, this, &ArticleView::openSearch );
|
2009-05-16 11:14:43 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
selectCurrentArticleAction.setShortcut( QKeySequence( "Ctrl+Shift+A" ) );
|
2013-01-18 14:37:24 +00:00
|
|
|
selectCurrentArticleAction.setText( tr( "Select Current Article" ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( &selectCurrentArticleAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &selectCurrentArticleAction, &QAction::triggered, this, &ArticleView::selectCurrentArticle );
|
2013-01-18 14:37:24 +00:00
|
|
|
|
2013-05-15 13:52:47 +00:00
|
|
|
copyAsTextAction.setShortcut( QKeySequence( "Ctrl+Shift+C" ) );
|
|
|
|
copyAsTextAction.setText( tr( "Copy as text" ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( ©AsTextAction );
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( ©AsTextAction, &QAction::triggered, this, &ArticleView::copyAsText );
|
2013-05-15 13:52:47 +00:00
|
|
|
|
2013-05-30 02:18:28 +00:00
|
|
|
inspectAction.setShortcut( QKeySequence( Qt::Key_F12 ) );
|
|
|
|
inspectAction.setText( tr( "Inspect" ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->addAction( &inspectAction );
|
2021-11-30 03:40:57 +00:00
|
|
|
|
2022-02-17 17:13:01 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( &inspectAction, &QAction::triggered, this, &ArticleView::inspectElement );
|
2013-05-30 02:18:28 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->installEventFilter( this );
|
|
|
|
searchPanel->installEventFilter( this );
|
|
|
|
ftsSearchPanel->installEventFilter( this );
|
2009-05-12 13:25:18 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
QWebEngineSettings * settings = webview->settings();
|
|
|
|
settings->setUnknownUrlSchemePolicy( QWebEngineSettings::UnknownUrlSchemePolicy::DisallowUnknownUrlSchemes );
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
2022-05-17 13:24:30 +00:00
|
|
|
settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true );
|
|
|
|
settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true );
|
|
|
|
settings->defaultSettings()->setAttribute( QWebEngineSettings::ErrorPageEnabled, false );
|
2023-04-15 01:35:48 +00:00
|
|
|
settings->defaultSettings()->setAttribute( QWebEngineSettings::PluginsEnabled, true );
|
2022-04-26 12:21:45 +00:00
|
|
|
settings->defaultSettings()->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false );
|
|
|
|
settings->defaultSettings()->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true );
|
2022-05-24 13:40:53 +00:00
|
|
|
settings->defaultSettings()->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false );
|
2022-02-27 07:49:29 +00:00
|
|
|
#else
|
2022-05-17 13:24:30 +00:00
|
|
|
settings->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true );
|
|
|
|
settings->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true );
|
|
|
|
settings->setAttribute( QWebEngineSettings::ErrorPageEnabled, false );
|
2023-04-15 01:35:48 +00:00
|
|
|
settings->setAttribute( QWebEngineSettings::PluginsEnabled, true );
|
2022-02-27 07:49:29 +00:00
|
|
|
settings->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false );
|
2022-04-26 12:21:45 +00:00
|
|
|
settings->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true );
|
2022-05-24 13:40:53 +00:00
|
|
|
settings->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false );
|
2022-05-08 08:00:08 +00:00
|
|
|
#endif
|
2012-09-16 10:19:47 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->load( QUrl( "gdlookup://localhost?word=(untitled)&blank=1" ) );
|
2022-08-23 11:09:38 +00:00
|
|
|
|
2012-09-16 10:19:47 +00:00
|
|
|
expandOptionalParts = cfg.preferences.alwaysExpandOptionalParts;
|
2014-02-04 13:35:42 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->grabGesture( Gestures::GDPinchGestureType );
|
|
|
|
webview->grabGesture( Gestures::GDSwipeGestureType );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
|
|
|
// Variable name for store current selection range
|
|
|
|
rangeVarName = QString( "sr_%1" ).arg( QString::number( (quint64)this, 16 ) );
|
2022-01-04 13:01:16 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( const bool fromMainWindow = parent && parent->objectName() == "MainWindow" ) {
|
2023-05-12 02:57:57 +00:00
|
|
|
connect( GlobalBroadcaster::instance(),
|
|
|
|
&GlobalBroadcaster::dictionaryChanges,
|
|
|
|
this,
|
|
|
|
&ArticleView::setActiveDictIds );
|
2022-01-08 06:51:24 +00:00
|
|
|
|
2023-05-12 02:57:57 +00:00
|
|
|
connect( GlobalBroadcaster::instance(), &GlobalBroadcaster::dictionaryClear, this, &ArticleView::dictionaryClear );
|
|
|
|
}
|
2022-07-16 22:54:53 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
channel = new QWebChannel( webview->page() );
|
2023-07-20 08:02:22 +00:00
|
|
|
agent = new ArticleViewAgent( this );
|
2022-01-19 23:29:02 +00:00
|
|
|
attachWebChannelToHtml();
|
2022-05-21 06:03:26 +00:00
|
|
|
ankiConnector = new AnkiConnector( this, cfg );
|
2023-07-20 08:02:22 +00:00
|
|
|
connect( ankiConnector, &AnkiConnector::errorText, this, [ this ]( QString const & errorText ) {
|
|
|
|
emit statusBarMessage( errorText );
|
|
|
|
} );
|
2023-03-22 20:34:05 +00:00
|
|
|
|
|
|
|
// Set up an Anki action if Anki integration is enabled in settings.
|
|
|
|
if ( cfg.preferences.ankiConnectServer.enabled ) {
|
|
|
|
sendToAnkiAction.setShortcut( QKeySequence( "Ctrl+Shift+N" ) );
|
|
|
|
webview->addAction( &sendToAnkiAction );
|
|
|
|
connect( &sendToAnkiAction, &QAction::triggered, this, &ArticleView::handleAnkiAction );
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 20:32:16 +00:00
|
|
|
// explicitly report the minimum size, to avoid
|
|
|
|
// sidebar widgets' improper resize during restore
|
2023-07-20 08:02:22 +00:00
|
|
|
QSize ArticleView::minimumSizeHint() const
|
|
|
|
{
|
|
|
|
return searchPanel->minimumSizeHint();
|
|
|
|
}
|
2012-12-27 20:32:16 +00:00
|
|
|
|
2023-07-17 00:24:02 +00:00
|
|
|
void ArticleView::setCurrentGroupId( unsigned currentGrgId )
|
|
|
|
{
|
|
|
|
currentGroupId = currentGrgId;
|
|
|
|
}
|
|
|
|
unsigned ArticleView::getCurrentGroupId()
|
2009-05-14 19:27:19 +00:00
|
|
|
{
|
2023-07-17 00:24:02 +00:00
|
|
|
return currentGroupId;
|
2009-05-14 19:27:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 15:37:37 +00:00
|
|
|
ArticleView::~ArticleView()
|
|
|
|
{
|
2009-02-08 21:54:19 +00:00
|
|
|
cleanupTemp();
|
2018-03-22 17:07:10 +00:00
|
|
|
audioPlayer->stop();
|
2022-01-23 03:22:40 +00:00
|
|
|
//channel->deregisterObject(this);
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->ungrabGesture( Gestures::GDPinchGestureType );
|
|
|
|
webview->ungrabGesture( Gestures::GDSwipeGestureType );
|
2009-02-06 15:37:37 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::showDefinition( QString const & word,
|
|
|
|
unsigned group,
|
2009-05-29 19:48:50 +00:00
|
|
|
QString const & scrollTo,
|
2015-10-28 19:56:58 +00:00
|
|
|
Contexts const & contexts_ )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2023-07-13 06:49:41 +00:00
|
|
|
GlobalBroadcaster::instance()->pronounce_engine.reset();
|
2023-05-28 16:01:54 +00:00
|
|
|
currentWord = word.trimmed();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( currentWord.isEmpty() )
|
2022-11-04 13:25:55 +00:00
|
|
|
return;
|
2022-11-04 13:23:42 +00:00
|
|
|
historyMode = false;
|
2022-01-08 13:45:10 +00:00
|
|
|
currentActiveDictIds.clear();
|
2013-06-23 09:53:10 +00:00
|
|
|
// first, let's stop the player
|
2018-03-22 17:07:10 +00:00
|
|
|
audioPlayer->stop();
|
2013-06-23 09:53:10 +00:00
|
|
|
|
2013-05-31 04:20:25 +00:00
|
|
|
QUrl req;
|
2015-10-28 19:56:58 +00:00
|
|
|
Contexts contexts( contexts_ );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
req.setScheme( "gdlookup" );
|
|
|
|
req.setHost( "localhost" );
|
2023-05-28 16:01:54 +00:00
|
|
|
Utils::Url::addQueryItem( req, "word", word );
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "group", QString::number( group ) );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( cfg.preferences.ignoreDiacritics )
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "ignore_diacritics", "1" );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-11 19:14:28 +00:00
|
|
|
if ( scrollTo.size() )
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "scrollto", scrollTo );
|
2009-05-29 19:48:50 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( delayedHighlightText.size() ) {
|
2022-06-01 15:11:41 +00:00
|
|
|
Utils::Url::addQueryItem( req, "regexp", delayedHighlightText );
|
2022-06-03 04:32:27 +00:00
|
|
|
delayedHighlightText.clear();
|
|
|
|
}
|
2022-06-01 15:11:41 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( Contexts::Iterator pos = contexts.find( "gdanchor" ); pos != contexts.end() ) {
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "gdanchor", contexts[ "gdanchor" ] );
|
2015-10-28 19:56:58 +00:00
|
|
|
contexts.erase( pos );
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( contexts.size() ) {
|
2009-05-29 19:48:50 +00:00
|
|
|
QBuffer buf;
|
|
|
|
|
|
|
|
buf.open( QIODevice::WriteOnly );
|
|
|
|
|
|
|
|
QDataStream stream( &buf );
|
|
|
|
|
|
|
|
stream << contexts;
|
|
|
|
|
|
|
|
buf.close();
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
Utils::Url::addQueryItem( req, "contexts", QString::fromLatin1( buf.buffer().toBase64() ) );
|
2009-05-29 19:48:50 +00:00
|
|
|
}
|
2009-05-11 19:14:28 +00:00
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
QString mutedDicts = getMutedForGroup( group );
|
|
|
|
|
|
|
|
if ( mutedDicts.size() )
|
2023-07-20 08:02:22 +00:00
|
|
|
Utils::Url::addQueryItem( req, "muted", mutedDicts );
|
2009-09-23 18:44:38 +00:00
|
|
|
|
2022-06-12 11:26:15 +00:00
|
|
|
// Update headwords history
|
2023-05-28 16:01:54 +00:00
|
|
|
emit sendWordToHistory( word );
|
2009-05-11 22:25:22 +00:00
|
|
|
|
2010-04-27 07:49:37 +00:00
|
|
|
// Any search opened is probably irrelevant now
|
|
|
|
closeSearch();
|
|
|
|
|
2022-06-12 11:26:15 +00:00
|
|
|
load( req );
|
2009-05-11 22:25:22 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
//QApplication::setOverrideCursor( Qt::WaitCursor );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->setCursor( Qt::WaitCursor );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::showDefinition( QString const & word,
|
|
|
|
QStringList const & dictIDs,
|
|
|
|
QRegExp const & searchRegExp,
|
|
|
|
unsigned group,
|
2018-04-10 14:49:52 +00:00
|
|
|
bool ignoreDiacritics )
|
2014-04-16 16:18:28 +00:00
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( dictIDs.isEmpty() )
|
2014-04-16 16:18:28 +00:00
|
|
|
return;
|
2022-02-10 12:07:05 +00:00
|
|
|
currentWord = word.trimmed();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( currentWord.isEmpty() )
|
2022-11-04 13:25:55 +00:00
|
|
|
return;
|
2022-11-04 13:23:42 +00:00
|
|
|
historyMode = false;
|
2014-04-16 16:18:28 +00:00
|
|
|
// first, let's stop the player
|
2018-03-22 17:07:10 +00:00
|
|
|
audioPlayer->stop();
|
2014-04-16 16:18:28 +00:00
|
|
|
|
|
|
|
QUrl req;
|
|
|
|
|
|
|
|
req.setScheme( "gdlookup" );
|
|
|
|
req.setHost( "localhost" );
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "word", word );
|
2023-07-20 08:02:22 +00:00
|
|
|
Utils::Url::addQueryItem( req, "dictionaries", dictIDs.join( "," ) );
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "regexp", searchRegExp.pattern() );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchRegExp.caseSensitivity() == Qt::CaseSensitive )
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "matchcase", "1" );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchRegExp.patternSyntax() == QRegExp::WildcardUnix )
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "wildcards", "1" );
|
|
|
|
Utils::Url::addQueryItem( req, "group", QString::number( group ) );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ignoreDiacritics )
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::addQueryItem( req, "ignore_diacritics", "1" );
|
2014-04-16 16:18:28 +00:00
|
|
|
|
2022-06-12 11:26:15 +00:00
|
|
|
// Update headwords history
|
2014-04-16 16:18:28 +00:00
|
|
|
emit sendWordToHistory( word );
|
|
|
|
|
|
|
|
// Any search opened is probably irrelevant now
|
|
|
|
closeSearch();
|
|
|
|
|
|
|
|
// Clear highlight all button selection
|
2023-03-17 22:42:11 +00:00
|
|
|
searchPanel->highlightAll->setChecked( false );
|
2014-04-16 16:18:28 +00:00
|
|
|
|
2022-06-12 11:26:15 +00:00
|
|
|
load( req );
|
2014-04-16 16:18:28 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->setCursor( Qt::WaitCursor );
|
2014-04-16 16:18:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 20:34:05 +00:00
|
|
|
void ArticleView::sendToAnki( QString const & word, QString const & dict_definition, QString const & sentence )
|
|
|
|
{
|
|
|
|
ankiConnector->sendToAnki( word, dict_definition, sentence );
|
2022-05-21 06:03:26 +00:00
|
|
|
}
|
|
|
|
|
2009-02-08 16:50:18 +00:00
|
|
|
void ArticleView::showAnticipation()
|
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->setHtml( "" );
|
|
|
|
webview->setCursor( Qt::WaitCursor );
|
2009-02-08 16:50:18 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::inspectElement()
|
|
|
|
{
|
|
|
|
emit inspectSignal( webview->page() );
|
|
|
|
}
|
2022-02-17 17:13:01 +00:00
|
|
|
|
2022-02-04 13:19:32 +00:00
|
|
|
void ArticleView::loadFinished( bool result )
|
2009-02-08 16:50:18 +00:00
|
|
|
{
|
2022-05-20 09:18:38 +00:00
|
|
|
setZoomFactor( cfg.preferences.zoomFactor );
|
2023-03-17 09:42:44 +00:00
|
|
|
QUrl url = webview->url();
|
2022-07-28 13:23:52 +00:00
|
|
|
qDebug() << "article view loaded url:" << url.url().left( 200 ) << result;
|
2023-07-20 08:02:22 +00:00
|
|
|
|
|
|
|
if ( url.url() == "about:blank" ) {
|
2022-07-28 13:23:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !result ) {
|
|
|
|
qWarning() << "article loaded unsuccessful";
|
2022-07-28 13:23:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( cfg.preferences.autoScrollToTargetArticle ) {
|
2021-11-27 07:17:33 +00:00
|
|
|
QString const scrollTo = Utils::Url::queryItemValue( url, "scrollto" );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( isScrollTo( scrollTo ) ) {
|
2021-06-29 08:59:16 +00:00
|
|
|
setCurrentArticle( scrollTo, true );
|
|
|
|
}
|
2009-05-29 19:48:50 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->unsetCursor();
|
2012-09-16 10:19:47 +00:00
|
|
|
|
2013-06-03 17:14:05 +00:00
|
|
|
// Expand collapsed article if only one loaded
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript( QString( "gdCheckArticlesNumber();" ) );
|
2013-06-03 17:14:05 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !Utils::Url::queryItemValue( url, "gdanchor" ).isEmpty() ) {
|
2023-04-09 03:48:21 +00:00
|
|
|
const QString anchor = QUrl::fromPercentEncoding( Utils::Url::encodedQueryItemValue( url, "gdanchor" ) );
|
2015-10-28 19:56:58 +00:00
|
|
|
|
|
|
|
// Find GD anchor on page
|
2023-04-09 03:21:32 +00:00
|
|
|
url.clear();
|
|
|
|
url.setFragment( anchor );
|
|
|
|
webview->page()->runJavaScript(
|
|
|
|
QString( "window.location.hash = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) );
|
2015-10-28 19:56:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 13:19:32 +00:00
|
|
|
//the click audio url such as gdau://xxxx ,webview also emit a pageLoaded signal but with the result is false.need future investigation.
|
|
|
|
//the audio link click ,no need to emit pageLoaded signal
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( result ) {
|
2022-02-04 13:19:32 +00:00
|
|
|
emit pageLoaded( this );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Utils::Url::hasQueryItem( webview->url(), "regexp" ) )
|
2014-04-22 13:47:02 +00:00
|
|
|
highlightFTSResults();
|
2009-02-08 16:50:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void ArticleView::handleTitleChanged( QString const & title )
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !title.isEmpty() ) // Qt 5.x WebKit raise signal titleChanges(QString()) while navigation within page
|
2016-04-01 13:38:07 +00:00
|
|
|
emit titleChanged( this, title );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::handleUrlChanged( QUrl const & url )
|
|
|
|
{
|
|
|
|
QIcon icon;
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( unsigned group = getGroup( url ) ) {
|
2009-01-28 20:55:45 +00:00
|
|
|
// Find the group's instance corresponding to the fragment value
|
2023-05-13 00:44:17 +00:00
|
|
|
for ( auto const & g : groups ) {
|
|
|
|
if ( g.id == group ) {
|
2009-01-28 20:55:45 +00:00
|
|
|
// Found it
|
2023-05-13 00:44:17 +00:00
|
|
|
icon = g.makeIcon();
|
2010-07-05 19:47:22 +00:00
|
|
|
break;
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
2023-05-13 00:44:17 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit iconChanged( this, icon );
|
|
|
|
}
|
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned ArticleView::getGroup( QUrl const & url )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2021-11-27 07:17:33 +00:00
|
|
|
if ( url.scheme() == "gdlookup" && Utils::Url::hasQueryItem( url, "group" ) )
|
|
|
|
return Utils::Url::queryItemValue( url, "group" ).toUInt();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
return 0;
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-05-11 22:25:22 +00:00
|
|
|
QStringList ArticleView::getArticlesList()
|
2021-12-13 14:45:16 +00:00
|
|
|
{
|
2022-01-08 06:51:24 +00:00
|
|
|
return currentActiveDictIds;
|
2009-05-11 22:25:22 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 12:27:08 +00:00
|
|
|
QString ArticleView::getActiveArticleId()
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
return activeDictId;
|
2022-01-19 12:16:45 +00:00
|
|
|
}
|
2011-07-03 12:27:08 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::setActiveArticleId( QString const & dictId )
|
|
|
|
{
|
|
|
|
this->activeDictId = dictId;
|
2011-07-03 12:27:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-11 19:14:28 +00:00
|
|
|
QString ArticleView::getCurrentArticle()
|
|
|
|
{
|
2023-06-03 00:29:19 +00:00
|
|
|
const QString dictId = getActiveArticleId();
|
2022-01-20 13:59:47 +00:00
|
|
|
return scrollToFromDictionaryId( dictId );
|
2009-05-11 19:14:28 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 16:00:13 +00:00
|
|
|
void ArticleView::jumpToDictionary( QString const & id, bool force )
|
2011-06-05 11:49:50 +00:00
|
|
|
{
|
2011-07-03 12:27:08 +00:00
|
|
|
|
2013-06-28 16:00:13 +00:00
|
|
|
// jump only if neceessary, or when forced
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( const QString targetArticle = scrollToFromDictionaryId( id ); force || targetArticle != getCurrentArticle() ) {
|
2011-07-03 12:27:08 +00:00
|
|
|
setCurrentArticle( targetArticle, true );
|
|
|
|
}
|
2011-06-05 11:49:50 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 11:47:15 +00:00
|
|
|
bool ArticleView::setCurrentArticle( QString const & id, bool moveToIt )
|
2009-05-11 22:25:22 +00:00
|
|
|
{
|
2021-06-29 08:59:16 +00:00
|
|
|
if ( !isScrollTo( id ) )
|
2022-05-24 11:47:15 +00:00
|
|
|
return false; // Incorrect id
|
2009-05-11 22:25:22 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !webview->isVisible() )
|
2022-05-24 11:47:15 +00:00
|
|
|
return false; // No action on background page, scrollIntoView there don't work
|
2014-02-09 15:00:48 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( moveToIt ) {
|
2022-02-25 14:48:43 +00:00
|
|
|
QString dictId = id.mid( 7 );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( dictId.isEmpty() )
|
2022-05-24 23:57:43 +00:00
|
|
|
return false;
|
2023-07-20 08:02:22 +00:00
|
|
|
QString script = QString(
|
|
|
|
"var elem=document.getElementById('%1'); "
|
|
|
|
"if(elem!=undefined){elem.scrollIntoView(true);} gdMakeArticleActive('%2',true);" )
|
2022-02-25 14:48:43 +00:00
|
|
|
.arg( id, dictId );
|
|
|
|
onJsActiveArticleChanged( id );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript( script );
|
2022-02-25 14:48:43 +00:00
|
|
|
setActiveArticleId( dictId );
|
2021-10-05 01:23:30 +00:00
|
|
|
}
|
2022-05-24 11:47:15 +00:00
|
|
|
return true;
|
2009-05-11 22:25:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 14:37:24 +00:00
|
|
|
void ArticleView::selectCurrentArticle()
|
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript(
|
|
|
|
QString(
|
|
|
|
"gdSelectArticle( '%1' );var elem=document.getElementById('%2'); if(elem!=undefined){elem.scrollIntoView(true);}" )
|
|
|
|
.arg( getActiveArticleId(), getCurrentArticle() ) );
|
2013-01-18 14:37:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 15:08:24 +00:00
|
|
|
void ArticleView::isFramedArticle( QString const & ca, const std::function< void( bool ) > & callback )
|
2009-05-29 19:48:50 +00:00
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ca.isEmpty() )
|
2022-03-30 15:08:24 +00:00
|
|
|
callback( false );
|
2009-05-29 19:48:50 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript( QString( "!!document.getElementById('gdexpandframe-%1');" ).arg( ca.mid( 7 ) ),
|
|
|
|
[ callback ]( const QVariant & res ) {
|
|
|
|
callback( res.toBool() );
|
|
|
|
} );
|
2009-05-29 19:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ArticleView::isExternalLink( QUrl const & url )
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
return Utils::isExternalLink( url );
|
2009-05-29 19:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts )
|
|
|
|
{
|
2010-05-29 11:33:04 +00:00
|
|
|
// Don't try mangling audio urls, even if they are from the framed websites
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ( url.scheme() == "http" || url.scheme() == "https" )
|
|
|
|
&& !Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
2009-05-29 19:48:50 +00:00
|
|
|
// Maybe a link inside a website was clicked?
|
|
|
|
|
|
|
|
QString ca = getCurrentArticle();
|
2023-07-20 08:02:22 +00:00
|
|
|
isFramedArticle( ca, []( bool framed ) {} );
|
2009-05-29 19:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::load( QUrl const & url )
|
|
|
|
{
|
|
|
|
webview->load( url );
|
|
|
|
}
|
2022-06-12 11:26:15 +00:00
|
|
|
|
2009-02-08 21:54:19 +00:00
|
|
|
void ArticleView::cleanupTemp()
|
|
|
|
{
|
2023-05-13 00:44:17 +00:00
|
|
|
auto it = desktopOpenedTempFiles.begin();
|
2023-07-20 08:02:22 +00:00
|
|
|
while ( it != desktopOpenedTempFiles.end() ) {
|
|
|
|
if ( QFile::remove( *it ) )
|
2017-03-13 14:38:27 +00:00
|
|
|
it = desktopOpenedTempFiles.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
2010-09-16 18:53:39 +00:00
|
|
|
}
|
2009-02-08 21:54:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 18:36:45 +00:00
|
|
|
bool ArticleView::handleF3( QObject * /*obj*/, QEvent * ev )
|
2009-05-12 13:25:18 +00:00
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ev->type() == QEvent::ShortcutOverride || ev->type() == QEvent::KeyPress ) {
|
|
|
|
QKeyEvent * ke = static_cast< QKeyEvent * >( ev );
|
2013-01-23 18:36:45 +00:00
|
|
|
if ( ke->key() == Qt::Key_F3 && isSearchOpened() ) {
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !ke->modifiers() ) {
|
|
|
|
if ( ev->type() == QEvent::KeyPress )
|
2014-04-23 13:46:48 +00:00
|
|
|
on_searchNext_clicked();
|
|
|
|
|
2013-01-23 18:36:45 +00:00
|
|
|
ev->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ke->modifiers() == Qt::ShiftModifier ) {
|
|
|
|
if ( ev->type() == QEvent::KeyPress )
|
2014-04-23 13:46:48 +00:00
|
|
|
on_searchPrevious_clicked();
|
|
|
|
|
2013-01-23 18:36:45 +00:00
|
|
|
ev->accept();
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-22 21:04:45 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ke->key() == Qt::Key_F3 && ftsSearchIsOpened ) {
|
|
|
|
if ( !ke->modifiers() ) {
|
|
|
|
if ( ev->type() == QEvent::KeyPress )
|
2014-04-23 13:46:48 +00:00
|
|
|
on_ftsSearchNext_clicked();
|
|
|
|
|
2014-04-22 13:47:02 +00:00
|
|
|
ev->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ke->modifiers() == Qt::ShiftModifier ) {
|
|
|
|
if ( ev->type() == QEvent::KeyPress )
|
2014-04-23 13:46:48 +00:00
|
|
|
on_ftsSearchPrevious_clicked();
|
|
|
|
|
2013-01-23 18:36:45 +00:00
|
|
|
ev->accept();
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-22 21:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 18:36:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
|
|
|
|
{
|
2022-03-27 15:05:45 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2022-03-27 14:22:42 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ev->type() == QEvent::NativeGesture ) {
|
2022-03-30 15:10:37 +00:00
|
|
|
qDebug() << "it's a Native Gesture!";
|
|
|
|
// handle Qt::ZoomNativeGesture Qt::SmartZoomNativeGesture here
|
|
|
|
// ignore swipe left/right.
|
|
|
|
// QWebEngine can handle Qt::SmartZoomNativeGesture.
|
|
|
|
}
|
2022-03-27 15:05:45 +00:00
|
|
|
|
|
|
|
#else
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ev->type() == QEvent::Gesture ) {
|
2014-02-04 13:35:42 +00:00
|
|
|
Gestures::GestureResult result;
|
|
|
|
QPoint pt;
|
|
|
|
|
|
|
|
bool handled = Gestures::handleGestureEvent( obj, ev, result, pt );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( handled ) {
|
|
|
|
if ( result == Gestures::ZOOM_IN )
|
2023-04-17 15:19:29 +00:00
|
|
|
emit zoomIn();
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == Gestures::ZOOM_OUT )
|
2023-04-17 15:19:29 +00:00
|
|
|
emit zoomOut();
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == Gestures::SWIPE_LEFT )
|
2014-02-04 13:35:42 +00:00
|
|
|
back();
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == Gestures::SWIPE_RIGHT )
|
2014-02-04 13:35:42 +00:00
|
|
|
forward();
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == Gestures::SWIPE_UP || result == Gestures::SWIPE_DOWN ) {
|
|
|
|
int delta = result == Gestures::SWIPE_UP ? -120 : 120;
|
|
|
|
QWidget * widget = static_cast< QWidget * >( obj );
|
2014-02-04 13:35:42 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
QPoint angleDelta( 0, delta );
|
2022-01-08 13:16:22 +00:00
|
|
|
QPoint pixelDetal;
|
2023-07-20 08:02:22 +00:00
|
|
|
QWidget * child = widget->childAt( widget->mapFromGlobal( pt ) );
|
|
|
|
if ( child ) {
|
|
|
|
QWheelEvent whev( child->mapFromGlobal( pt ),
|
|
|
|
pt,
|
|
|
|
pixelDetal,
|
|
|
|
angleDelta,
|
|
|
|
Qt::NoButton,
|
|
|
|
Qt::NoModifier,
|
|
|
|
Qt::NoScrollPhase,
|
|
|
|
false );
|
2014-02-04 13:35:42 +00:00
|
|
|
qApp->sendEvent( child, &whev );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
|
|
|
QWheelEvent whev( widget->mapFromGlobal( pt ),
|
|
|
|
pt,
|
|
|
|
pixelDetal,
|
|
|
|
angleDelta,
|
|
|
|
Qt::NoButton,
|
|
|
|
Qt::NoModifier,
|
|
|
|
Qt::NoScrollPhase,
|
|
|
|
false );
|
2014-02-04 13:35:42 +00:00
|
|
|
qApp->sendEvent( widget, &whev );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
2022-03-27 15:05:45 +00:00
|
|
|
#endif
|
2014-02-04 13:35:42 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ev->type() == QEvent::MouseMove ) {
|
|
|
|
if ( Gestures::isFewTouchPointsPresented() ) {
|
2014-02-04 13:35:42 +00:00
|
|
|
ev->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-01-23 18:36:45 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( handleF3( obj, ev ) ) {
|
2013-01-23 18:36:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( obj == webview ) {
|
|
|
|
if ( ev->type() == QEvent::MouseButtonPress ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
auto event = static_cast< QMouseEvent * >( ev );
|
2011-06-07 08:26:49 +00:00
|
|
|
if ( event->button() == Qt::XButton1 ) {
|
|
|
|
back();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ( event->button() == Qt::XButton2 ) {
|
|
|
|
forward();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( ev->type() == QEvent::KeyPress ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
auto keyEvent = static_cast< QKeyEvent * >( ev );
|
2009-05-12 13:25:18 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( keyEvent->modifiers() & ( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
|
2009-05-14 20:43:32 +00:00
|
|
|
return false; // A non-typing modifier is pressed
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Utils::ignoreKeyEvent( keyEvent ) || keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter )
|
2009-05-12 15:54:37 +00:00
|
|
|
return false; // Those key have other uses than to start typing
|
|
|
|
|
2009-05-12 13:25:18 +00:00
|
|
|
QString text = keyEvent->text();
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( text.size() ) {
|
2009-05-12 13:25:18 +00:00
|
|
|
emit typingEvent( text );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( ev->type() == QEvent::Wheel ) {
|
2022-02-17 16:39:24 +00:00
|
|
|
QWheelEvent * pe = static_cast< QWheelEvent * >( ev );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( pe->modifiers().testFlag( Qt::ControlModifier ) ) {
|
|
|
|
if ( pe->angleDelta().y() > 0 ) {
|
2022-02-17 16:39:24 +00:00
|
|
|
zoomIn();
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2022-02-17 16:39:24 +00:00
|
|
|
zoomOut();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-12 13:25:18 +00:00
|
|
|
}
|
|
|
|
else
|
2023-03-17 09:42:44 +00:00
|
|
|
return QWidget::eventFilter( obj, ev );
|
2009-05-12 13:25:18 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
QString ArticleView::getMutedForGroup( unsigned group )
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( dictionaryBarToggled && dictionaryBarToggled->isChecked() ) {
|
2009-09-23 18:44:38 +00:00
|
|
|
// Dictionary bar is active -- mute the muted dictionaries
|
|
|
|
Instances::Group const * groupInstance = groups.findGroup( group );
|
|
|
|
|
2012-09-26 13:13:47 +00:00
|
|
|
// Find muted dictionaries for current group
|
|
|
|
Config::Group const * grp = cfg.getGroup( group );
|
|
|
|
Config::MutedDictionaries const * mutedDictionaries;
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( group == Instances::Group::AllGroupId )
|
2012-09-26 13:13:47 +00:00
|
|
|
mutedDictionaries = popupView ? &cfg.popupMutedDictionaries : &cfg.mutedDictionaries;
|
|
|
|
else
|
2023-07-20 08:02:22 +00:00
|
|
|
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
|
|
|
|
if ( !mutedDictionaries )
|
2012-09-26 13:13:47 +00:00
|
|
|
return QString();
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
QStringList mutedDicts;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( groupInstance ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
for ( const auto & dictionarie : groupInstance->dictionaries ) {
|
|
|
|
QString id = QString::fromStdString( dictionarie->getId() );
|
2009-09-23 18:44:38 +00:00
|
|
|
|
2010-03-30 20:15:55 +00:00
|
|
|
if ( mutedDictionaries->contains( id ) )
|
2009-09-23 18:44:38 +00:00
|
|
|
mutedDicts.append( id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( !mutedDicts.empty() )
|
2009-09-23 18:44:38 +00:00
|
|
|
return mutedDicts.join( "," );
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
QStringList ArticleView::getMutedDictionaries( unsigned group )
|
|
|
|
{
|
|
|
|
if ( dictionaryBarToggled && dictionaryBarToggled->isChecked() ) {
|
2022-01-01 10:19:11 +00:00
|
|
|
// Dictionary bar is active -- mute the muted dictionaries
|
2023-07-20 08:02:22 +00:00
|
|
|
Instances::Group const * groupInstance = groups.findGroup( group );
|
2022-01-01 10:19:11 +00:00
|
|
|
|
|
|
|
// Find muted dictionaries for current group
|
2023-07-20 08:02:22 +00:00
|
|
|
Config::Group const * grp = cfg.getGroup( group );
|
|
|
|
Config::MutedDictionaries const * mutedDictionaries;
|
|
|
|
if ( group == Instances::Group::AllGroupId )
|
2022-01-01 10:19:11 +00:00
|
|
|
mutedDictionaries = popupView ? &cfg.popupMutedDictionaries : &cfg.mutedDictionaries;
|
|
|
|
else
|
2023-07-20 08:02:22 +00:00
|
|
|
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
|
|
|
|
if ( !mutedDictionaries )
|
2022-01-01 10:19:11 +00:00
|
|
|
return QStringList();
|
|
|
|
|
|
|
|
QStringList mutedDicts;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( groupInstance ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
for ( const auto & dictionarie : groupInstance->dictionaries ) {
|
|
|
|
QString id = QString::fromStdString( dictionarie->getId() );
|
2022-01-01 10:19:11 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( mutedDictionaries->contains( id ) )
|
|
|
|
mutedDicts.append( id );
|
2022-01-01 10:19:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mutedDicts;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QStringList();
|
2021-10-03 11:28:26 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::linkHovered( const QString & link )
|
2011-07-02 13:04:49 +00:00
|
|
|
{
|
|
|
|
QString msg;
|
2023-07-20 08:02:22 +00:00
|
|
|
QUrl url( link );
|
2011-07-02 13:04:49 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( url.scheme() == "bres" ) {
|
2011-07-02 13:04:49 +00:00
|
|
|
msg = tr( "Resource" );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdau" || Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
2011-07-02 13:04:49 +00:00
|
|
|
msg = tr( "Audio" );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdtts" ) {
|
2013-04-24 16:01:44 +00:00
|
|
|
msg = tr( "TTS Voice" );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdpicture" ) {
|
2012-12-07 11:59:29 +00:00
|
|
|
msg = tr( "Picture" );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdvideo" ) {
|
|
|
|
if ( url.path().isEmpty() ) {
|
2013-06-22 16:36:25 +00:00
|
|
|
msg = tr( "Video" );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2013-06-22 16:36:25 +00:00
|
|
|
QString path = url.path();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( path.startsWith( '/' ) ) {
|
2013-06-22 16:36:25 +00:00
|
|
|
path = path.mid( 1 );
|
|
|
|
}
|
|
|
|
msg = tr( "Video: %1" ).arg( path );
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdlookup" || url.scheme().compare( "bword" ) == 0 ) {
|
2011-07-02 13:04:49 +00:00
|
|
|
QString def = url.path();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( def.startsWith( "/" ) ) {
|
2011-07-02 13:04:49 +00:00
|
|
|
def = def.mid( 1 );
|
|
|
|
}
|
2012-11-26 13:13:56 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Utils::Url::hasQueryItem( url, "dict" ) ) {
|
2012-11-26 13:13:56 +00:00
|
|
|
// Link to other dictionary
|
2021-11-27 07:17:33 +00:00
|
|
|
QString dictName( Utils::Url::queryItemValue( url, "dict" ) );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !dictName.isEmpty() )
|
|
|
|
msg = tr( "Definition from dictionary \"%1\": %2" ).arg( dictName, def );
|
2012-11-26 13:13:56 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( msg.isEmpty() ) {
|
|
|
|
if ( def.isEmpty() && url.hasFragment() )
|
2018-02-21 10:48:11 +00:00
|
|
|
msg = '#' + url.fragment(); // this must be a citation, footnote or backlink
|
|
|
|
else
|
2023-07-20 08:02:22 +00:00
|
|
|
msg = tr( "Definition: %1" ).arg( def );
|
2018-02-21 10:48:11 +00:00
|
|
|
}
|
2011-07-02 13:04:49 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2011-07-02 13:04:49 +00:00
|
|
|
msg = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit statusBarMessage( msg );
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::attachWebChannelToHtml()
|
|
|
|
{
|
2021-12-19 10:37:27 +00:00
|
|
|
// set the web channel to be used by the page
|
|
|
|
// see http://doc.qt.io/qt-5/qwebenginepage.html#setWebChannel
|
2023-07-20 08:02:22 +00:00
|
|
|
webview->page()->setWebChannel( channel, QWebEngineScript::MainWorld );
|
2021-07-06 13:01:50 +00:00
|
|
|
|
2021-12-19 10:37:27 +00:00
|
|
|
// register QObjects to be exposed to JavaScript
|
2023-07-20 08:02:22 +00:00
|
|
|
channel->registerObject( QStringLiteral( "articleview" ), agent );
|
2011-07-03 12:27:08 +00:00
|
|
|
}
|
2011-07-02 13:04:49 +00:00
|
|
|
|
2009-05-29 19:48:50 +00:00
|
|
|
void ArticleView::linkClicked( QUrl const & url_ )
|
2009-02-08 15:49:17 +00:00
|
|
|
{
|
2017-03-14 14:47:38 +00:00
|
|
|
Qt::KeyboardModifiers kmod = QApplication::keyboardModifiers();
|
|
|
|
|
|
|
|
// Lock jump on links while Alt key is pressed
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( kmod & Qt::AltModifier )
|
2017-03-14 14:47:38 +00:00
|
|
|
return;
|
|
|
|
|
2013-05-31 04:20:25 +00:00
|
|
|
QUrl url( url_ );
|
2009-05-29 19:48:50 +00:00
|
|
|
Contexts contexts;
|
|
|
|
|
|
|
|
tryMangleWebsiteClickedUrl( url, contexts );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !popupView && ( webview->isMidButtonPressed() || ( kmod & ( Qt::ControlModifier | Qt::ShiftModifier ) ) )
|
|
|
|
&& !isAudioLink( url ) ) {
|
2011-07-06 06:53:42 +00:00
|
|
|
// Mid button or Control/Shift is currently pressed - open the link in new tab
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->resetMidButtonPressed();
|
|
|
|
emit openLinkInNewTab( url, webview->url(), getCurrentArticle(), contexts );
|
2009-10-22 11:38:11 +00:00
|
|
|
}
|
|
|
|
else
|
2023-03-17 09:42:44 +00:00
|
|
|
openLink( url, webview->url(), getCurrentArticle(), contexts );
|
2009-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 00:19:49 +00:00
|
|
|
void ArticleView::linkClickedInHtml( QUrl const & url_ )
|
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
emit webview->linkClickedInHtml( url_ );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !url_.isEmpty() ) {
|
2022-03-16 14:29:04 +00:00
|
|
|
linkClicked( url_ );
|
|
|
|
}
|
2022-01-14 00:19:49 +00:00
|
|
|
}
|
2023-03-22 20:34:05 +00:00
|
|
|
|
|
|
|
void ArticleView::makeAnkiCardFromArticle( QString const & article_id )
|
|
|
|
{
|
|
|
|
auto const js_code = QString( R"EOF(document.getElementById("gdarticlefrom-%1").innerText)EOF" ).arg( article_id );
|
|
|
|
webview->page()->runJavaScript( js_code, [ this ]( const QVariant & article_text ) {
|
|
|
|
sendToAnki( webview->title(), article_text.toString(), translateLine->text() );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const & scrollTo, Contexts const & contexts_ )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2022-02-04 13:19:32 +00:00
|
|
|
audioPlayer->stop();
|
2021-12-29 15:28:26 +00:00
|
|
|
qDebug() << "open link url:" << url;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
auto [ valid, word ] = Utils::Url::getQueryWord( url );
|
|
|
|
if ( valid && word.isEmpty() ) {
|
2023-04-09 03:21:32 +00:00
|
|
|
//if valid=true and word is empty,the url must be a invalid gdlookup url.
|
|
|
|
//else if valid=false,the url should be external urls.
|
2022-05-27 15:10:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-28 19:56:58 +00:00
|
|
|
Contexts contexts( contexts_ );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( url.scheme().compare( "gdpicture" ) == 0 )
|
2022-06-12 11:26:15 +00:00
|
|
|
load( url );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme().compare( "ankisearch" ) == 0 ) {
|
2023-03-22 02:04:54 +00:00
|
|
|
ankiConnector->ankiSearch( url.path() );
|
2023-03-22 20:34:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ( url.scheme().compare( "ankicard" ) == 0 ) {
|
|
|
|
// If article id is set in path and selection is empty, use text from the current article.
|
|
|
|
// Otherwise, grab currently selected text and use it as the definition.
|
|
|
|
if ( !url.path().isEmpty() && webview->selectedText().isEmpty() ) {
|
|
|
|
makeAnkiCardFromArticle( url.path() );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendToAnki( webview->title(), webview->selectedText(), translateLine->text() );
|
|
|
|
}
|
|
|
|
qDebug() << "requested to make Anki card.";
|
|
|
|
return;
|
2023-03-22 02:04:54 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme().compare( "bword" ) == 0 || url.scheme().compare( "entry" ) == 0 ) {
|
|
|
|
if ( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) {
|
|
|
|
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2022-05-27 15:10:50 +00:00
|
|
|
showDefinition( word, dictsList, QRegExp(), getGroup( ref ), false );
|
2014-04-21 16:20:24 +00:00
|
|
|
}
|
|
|
|
else
|
2023-07-20 08:02:22 +00:00
|
|
|
showDefinition( word, getGroup( ref ), scrollTo, contexts );
|
2009-08-31 14:27:19 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdlookup" ) // Plain html links inherit gdlookup scheme
|
2009-03-26 19:00:08 +00:00
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( url.hasFragment() ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript(
|
2009-03-26 19:00:08 +00:00
|
|
|
QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) );
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
|
|
|
if ( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) {
|
2014-04-21 16:20:24 +00:00
|
|
|
// Specific dictionary group from full-text search
|
2023-07-20 08:02:22 +00:00
|
|
|
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2018-04-10 14:49:52 +00:00
|
|
|
showDefinition( url.path().mid( 1 ), dictsList, QRegExp(), getGroup( ref ), false );
|
2014-04-21 16:20:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-24 20:30:32 +00:00
|
|
|
QString newScrollTo( scrollTo );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Utils::Url::hasQueryItem( url, "dict" ) ) {
|
2012-11-24 20:30:32 +00:00
|
|
|
// Link to other dictionary
|
2021-11-27 07:17:33 +00:00
|
|
|
QString dictName( Utils::Url::queryItemValue( url, "dict" ) );
|
2023-06-03 00:29:19 +00:00
|
|
|
for ( const auto & allDictionarie : allDictionaries ) {
|
|
|
|
if ( dictName.compare( QString::fromUtf8( allDictionarie->getName().c_str() ) ) == 0 ) {
|
|
|
|
newScrollTo = scrollToFromDictionaryId( QString::fromUtf8( allDictionarie->getId().c_str() ) );
|
2012-11-24 20:30:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-28 19:56:58 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Utils::Url::hasQueryItem( url, "gdanchor" ) )
|
2021-11-27 07:17:33 +00:00
|
|
|
contexts[ "gdanchor" ] = Utils::Url::queryItemValue( url, "gdanchor" );
|
2015-10-28 19:56:58 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
showDefinition( word, getGroup( ref ), newScrollTo, contexts );
|
2012-11-12 13:52:54 +00:00
|
|
|
}
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gdvideo"
|
|
|
|
|| Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
2009-02-06 16:19:05 +00:00
|
|
|
// Download it
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
// Clear any pending ones
|
|
|
|
|
|
|
|
resourceDownloadRequests.clear();
|
2009-02-06 16:19:05 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
resourceDownloadUrl = url;
|
2009-02-06 16:19:05 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
|
|
|
sptr< Dictionary::DataRequest > req = std::make_shared< Dictionary::WebMultimediaDownload >( url, articleNetMgr );
|
2010-05-29 11:33:04 +00:00
|
|
|
|
|
|
|
resourceDownloadRequests.push_back( req );
|
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( req.get(), &Dictionary::Request::finished, this, &ArticleView::resourceDownloadFinished );
|
2010-05-29 11:33:04 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdau" && url.host() == "search" ) {
|
2009-02-06 16:19:05 +00:00
|
|
|
// Since searches should be limited to current group, we just do them
|
|
|
|
// here ourselves since otherwise we'd need to pass group id to netmgr
|
|
|
|
// and it should've been having knowledge of the current groups, too.
|
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned currentGroup = getGroup( ref );
|
2009-02-06 16:19:05 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const * activeDicts = nullptr;
|
2009-04-25 21:04:49 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( groups.size() ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
for ( const auto & group : groups )
|
|
|
|
if ( group.id == currentGroup ) {
|
|
|
|
activeDicts = &( group.dictionaries );
|
2009-04-25 21:04:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
activeDicts = &allDictionaries;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( activeDicts ) {
|
2017-07-09 17:15:35 +00:00
|
|
|
unsigned preferred = UINT_MAX;
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( url.hasFragment() ) {
|
2017-07-09 17:15:35 +00:00
|
|
|
// Find sound in the preferred dictionary
|
2021-11-27 07:17:33 +00:00
|
|
|
QString preferredName = Utils::Url::fragment( url );
|
2023-07-20 08:02:22 +00:00
|
|
|
try {
|
|
|
|
for ( unsigned x = 0; x < activeDicts->size(); ++x ) {
|
|
|
|
if ( preferredName.compare( QString::fromUtf8( ( *activeDicts )[ x ]->getName().c_str() ) ) == 0 ) {
|
2017-07-09 17:15:35 +00:00
|
|
|
preferred = x;
|
|
|
|
sptr< Dictionary::DataRequest > req =
|
2023-07-20 08:02:22 +00:00
|
|
|
( *activeDicts )[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() );
|
2017-07-09 17:15:35 +00:00
|
|
|
|
|
|
|
resourceDownloadRequests.push_back( req );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !req->isFinished() ) {
|
2017-07-09 17:15:35 +00:00
|
|
|
// Queued loading
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( req.get(), &Dictionary::Request::finished, this, &ArticleView::resourceDownloadFinished );
|
2017-07-09 17:15:35 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2017-07-09 17:15:35 +00:00
|
|
|
// Immediate loading
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( req->dataSize() > 0 ) {
|
2017-07-09 17:15:35 +00:00
|
|
|
// Resource already found, stop next search
|
|
|
|
resourceDownloadFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
catch ( std::exception & e ) {
|
|
|
|
emit statusBarMessage( tr( "ERROR: %1" ).arg( e.what() ), 10000, QPixmap( ":/icons/error.svg" ) );
|
2017-07-09 17:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
for ( unsigned x = 0; x < activeDicts->size(); ++x ) {
|
|
|
|
try {
|
|
|
|
if ( x == preferred )
|
2017-07-09 17:15:35 +00:00
|
|
|
continue;
|
|
|
|
|
2013-10-18 12:50:29 +00:00
|
|
|
sptr< Dictionary::DataRequest > req =
|
2023-07-20 08:02:22 +00:00
|
|
|
( *activeDicts )[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() );
|
2013-10-18 12:50:29 +00:00
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
resourceDownloadRequests.push_back( req );
|
2013-10-18 12:50:29 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !req->isFinished() ) {
|
2017-04-28 12:25:45 +00:00
|
|
|
// Queued loading
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( req.get(), &Dictionary::Request::finished, this, &ArticleView::resourceDownloadFinished );
|
2013-10-18 12:50:29 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2017-04-28 12:25:45 +00:00
|
|
|
// Immediate loading
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( req->dataSize() > 0 ) {
|
2017-04-28 12:25:45 +00:00
|
|
|
// Resource already found, stop next search
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-04-25 21:04:49 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
catch ( std::exception & e ) {
|
|
|
|
emit statusBarMessage( tr( "ERROR: %1" ).arg( e.what() ), 10000, QPixmap( ":/icons/error.svg" ) );
|
2009-02-06 16:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-27 20:55:53 +00:00
|
|
|
}
|
2009-02-06 16:19:05 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2009-03-26 19:00:08 +00:00
|
|
|
// Normal resource download
|
|
|
|
QString contentType;
|
2009-02-08 14:40:26 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
sptr< Dictionary::DataRequest > req = articleNetMgr.getResource( url, contentType );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !req.get() ) {
|
2009-04-25 21:04:49 +00:00
|
|
|
// Request failed, fail
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( req->isFinished() && req->dataSize() >= 0 ) {
|
2009-03-26 19:00:08 +00:00
|
|
|
// Have data ready, handle it
|
|
|
|
resourceDownloadRequests.push_back( req );
|
|
|
|
resourceDownloadFinished();
|
2009-02-08 14:40:26 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
return;
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( !req->isFinished() ) {
|
2009-03-26 19:00:08 +00:00
|
|
|
// Queue to be handled when done
|
2009-02-08 14:40:26 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
resourceDownloadRequests.push_back( req );
|
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( req.get(), &Dictionary::Request::finished, this, &ArticleView::resourceDownloadFinished );
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
2009-02-08 14:40:26 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
if ( resourceDownloadRequests.empty() ) // No requests were queued
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2013-02-01 12:36:01 +00:00
|
|
|
QMessageBox::critical( this, "GoldenDict", tr( "The referenced resource doesn't exist." ) );
|
2009-03-26 19:00:08 +00:00
|
|
|
return;
|
2009-02-08 21:54:19 +00:00
|
|
|
}
|
2009-04-25 21:04:49 +00:00
|
|
|
else
|
|
|
|
resourceDownloadFinished(); // Check any requests finished already
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdprg" ) {
|
2011-05-29 05:08:37 +00:00
|
|
|
// Program. Run it.
|
|
|
|
QString id( url.host() );
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
for ( const auto & program : cfg.programs ) {
|
|
|
|
if ( program.id == id ) {
|
2011-05-29 05:08:37 +00:00
|
|
|
// Found the corresponding program.
|
2011-06-04 21:35:09 +00:00
|
|
|
Programs::RunInstance * req = new Programs::RunInstance;
|
2011-05-29 05:08:37 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( req, &Programs::RunInstance::finished, req, &QObject::deleteLater );
|
2011-05-29 05:08:37 +00:00
|
|
|
|
2011-06-04 21:35:09 +00:00
|
|
|
QString error;
|
|
|
|
|
|
|
|
// Delete the request if it fails to start
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( !req->start( program, url.path().mid( 1 ), error ) ) {
|
2011-05-29 05:08:37 +00:00
|
|
|
delete req;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
QMessageBox::critical( this, "GoldenDict", error );
|
2011-06-04 21:35:09 +00:00
|
|
|
}
|
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still here? No such program exists.
|
2023-07-20 08:02:22 +00:00
|
|
|
QMessageBox::critical( this, "GoldenDict", tr( "The referenced audio program doesn't exist." ) );
|
2011-05-29 05:08:37 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( url.scheme() == "gdtts" ) {
|
2013-04-24 14:52:04 +00:00
|
|
|
// Text to speech
|
2021-11-27 07:17:33 +00:00
|
|
|
QString md5Id = Utils::Url::queryItemValue( url, "engine" );
|
2013-04-24 14:52:04 +00:00
|
|
|
QString text( url.path().mid( 1 ) );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
for ( const auto & voiceEngine : cfg.voiceEngines ) {
|
2022-07-31 01:19:50 +00:00
|
|
|
QString itemMd5Id =
|
|
|
|
QString( QCryptographicHash::hash( voiceEngine.name.toUtf8(), QCryptographicHash::Md5 ).toHex() );
|
2013-04-24 14:52:04 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( itemMd5Id == md5Id ) {
|
2022-07-31 01:19:50 +00:00
|
|
|
SpeechClient * speechClient = new SpeechClient( voiceEngine, this );
|
2013-04-24 14:52:04 +00:00
|
|
|
connect( speechClient, SIGNAL( finished() ), speechClient, SLOT( deleteLater() ) );
|
2013-04-24 16:01:44 +00:00
|
|
|
speechClient->tell( text );
|
2013-04-24 14:52:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( isExternalLink( url ) ) {
|
2010-06-30 16:43:08 +00:00
|
|
|
// Use the system handler for the conventional external links
|
2009-02-01 00:08:08 +00:00
|
|
|
QDesktopServices::openUrl( url );
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
ResourceToSaveHandler * ArticleView::saveResource( const QUrl & url, const QString & fileName )
|
2013-02-22 12:44:23 +00:00
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
return saveResource( url, webview->url(), fileName );
|
2013-05-27 11:18:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
ResourceToSaveHandler * ArticleView::saveResource( const QUrl & url, const QUrl & ref, const QString & fileName )
|
2013-05-27 11:18:13 +00:00
|
|
|
{
|
2017-04-27 20:55:53 +00:00
|
|
|
ResourceToSaveHandler * handler = new ResourceToSaveHandler( this, fileName );
|
2013-02-22 12:44:23 +00:00
|
|
|
sptr< Dictionary::DataRequest > req;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( url.scheme() == "bres" || url.scheme() == "gico" || url.scheme() == "gdau" || url.scheme() == "gdvideo" ) {
|
|
|
|
if ( url.host() == "search" ) {
|
2013-02-22 12:44:23 +00:00
|
|
|
// Since searches should be limited to current group, we just do them
|
|
|
|
// here ourselves since otherwise we'd need to pass group id to netmgr
|
|
|
|
// and it should've been having knowledge of the current groups, too.
|
|
|
|
|
|
|
|
unsigned currentGroup = getGroup( ref );
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const * activeDicts = nullptr;
|
2013-02-22 12:44:23 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( groups.size() ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
for ( const auto & group : groups )
|
|
|
|
if ( group.id == currentGroup ) {
|
|
|
|
activeDicts = &( group.dictionaries );
|
2013-02-22 12:44:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
activeDicts = &allDictionaries;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( activeDicts ) {
|
2019-06-27 15:09:00 +00:00
|
|
|
unsigned preferred = UINT_MAX;
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( url.hasFragment() && url.scheme() == "gdau" ) {
|
2019-06-27 15:09:00 +00:00
|
|
|
// Find sound in the preferred dictionary
|
2021-11-27 07:17:33 +00:00
|
|
|
QString preferredName = Utils::Url::fragment( url );
|
2023-07-20 08:02:22 +00:00
|
|
|
for ( unsigned x = 0; x < activeDicts->size(); ++x ) {
|
|
|
|
try {
|
|
|
|
if ( preferredName.compare( QString::fromUtf8( ( *activeDicts )[ x ]->getName().c_str() ) ) == 0 ) {
|
2019-06-27 15:09:00 +00:00
|
|
|
preferred = x;
|
2023-06-03 00:29:19 +00:00
|
|
|
sptr< Dictionary::DataRequest > data_request =
|
|
|
|
( *activeDicts )[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() );
|
2019-06-27 15:09:00 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
handler->addRequest( data_request );
|
2019-06-27 15:09:00 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( data_request->isFinished() && data_request->dataSize() > 0 ) {
|
2019-06-27 15:09:00 +00:00
|
|
|
handler->downloadFinished();
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
catch ( std::exception & e ) {
|
|
|
|
gdWarning( "getResource request error (%s) in \"%s\"\n",
|
|
|
|
e.what(),
|
|
|
|
( *activeDicts )[ x ]->getName().c_str() );
|
2019-06-27 15:09:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
for ( unsigned x = 0; x < activeDicts->size(); ++x ) {
|
|
|
|
try {
|
|
|
|
if ( x == preferred )
|
2019-06-27 15:09:00 +00:00
|
|
|
continue;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
req = ( *activeDicts )[ x ]->getResource( Utils::Url::path( url ).mid( 1 ).toUtf8().data() );
|
2013-02-22 12:44:23 +00:00
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
handler->addRequest( req );
|
2017-04-28 12:25:45 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( req->isFinished() && req->dataSize() > 0 ) {
|
2017-04-28 12:25:45 +00:00
|
|
|
// Resource already found, stop next search
|
|
|
|
break;
|
|
|
|
}
|
2013-10-18 12:50:29 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
catch ( std::exception & e ) {
|
|
|
|
gdWarning( "getResource request error (%s) in \"%s\"\n",
|
|
|
|
e.what(),
|
|
|
|
( *activeDicts )[ x ]->getName().c_str() );
|
2013-10-18 12:50:29 +00:00
|
|
|
}
|
2013-02-22 12:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2013-02-22 12:44:23 +00:00
|
|
|
// Normal resource download
|
|
|
|
QString contentType;
|
|
|
|
req = articleNetMgr.getResource( url, contentType );
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( req.get() ) {
|
2017-04-27 20:55:53 +00:00
|
|
|
handler->addRequest( req );
|
2013-10-18 14:32:58 +00:00
|
|
|
}
|
2013-02-22 12:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
|
|
|
req = std::make_shared< Dictionary::WebMultimediaDownload >( url, articleNetMgr );
|
2013-02-22 12:44:23 +00:00
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
handler->addRequest( req );
|
2013-02-22 12:44:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
if ( handler->isEmpty() ) // No requests were queued
|
2013-02-22 12:44:23 +00:00
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
emit statusBarMessage( tr( "ERROR: %1" ).arg( tr( "The referenced resource doesn't exist." ) ),
|
|
|
|
10000,
|
|
|
|
QPixmap( ":/icons/error.svg" ) );
|
2013-02-22 12:44:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
// Check already finished downloads
|
|
|
|
handler->downloadFinished();
|
|
|
|
|
|
|
|
return handler;
|
2013-02-22 12:44:23 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
void ArticleView::updateMutedContents()
|
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
QUrl currentUrl = webview->url();
|
2009-09-23 18:44:38 +00:00
|
|
|
|
|
|
|
if ( currentUrl.scheme() != "gdlookup" )
|
|
|
|
return; // Weird url -- do nothing
|
|
|
|
|
|
|
|
unsigned group = getGroup( currentUrl );
|
|
|
|
|
|
|
|
if ( !group )
|
|
|
|
return; // No group in url -- do nothing
|
|
|
|
|
|
|
|
QString mutedDicts = getMutedForGroup( group );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Utils::Url::queryItemValue( currentUrl, "muted" ) != mutedDicts ) {
|
2009-09-23 18:44:38 +00:00
|
|
|
// The list has changed -- update the url
|
|
|
|
|
2021-11-27 07:17:33 +00:00
|
|
|
Utils::Url::removeQueryItem( currentUrl, "muted" );
|
2009-09-23 18:44:38 +00:00
|
|
|
|
|
|
|
if ( mutedDicts.size() )
|
2023-07-20 08:02:22 +00:00
|
|
|
Utils::Url::addQueryItem( currentUrl, "muted", mutedDicts );
|
2009-09-23 18:44:38 +00:00
|
|
|
|
2022-06-12 11:26:15 +00:00
|
|
|
load( currentUrl );
|
2009-09-23 18:44:38 +00:00
|
|
|
|
|
|
|
//QApplication::setOverrideCursor( Qt::WaitCursor );
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->setCursor( Qt::WaitCursor );
|
2009-09-23 18:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-07 11:27:19 +00:00
|
|
|
bool ArticleView::canGoBack()
|
|
|
|
{
|
|
|
|
// First entry in a history is always an empty page,
|
|
|
|
// so we skip it.
|
2023-03-17 09:42:44 +00:00
|
|
|
return webview->history()->currentItemIndex() > 1;
|
2011-06-07 11:27:19 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
bool ArticleView::canGoForward()
|
|
|
|
{
|
|
|
|
return webview->history()->canGoForward();
|
|
|
|
}
|
2011-06-07 11:27:19 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::setSelectionBySingleClick( bool set )
|
|
|
|
{
|
|
|
|
webview->setSelectionBySingleClick( set );
|
|
|
|
}
|
2012-09-26 13:59:48 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::setDelayedHighlightText( QString const & text )
|
2022-06-01 15:11:41 +00:00
|
|
|
{
|
|
|
|
delayedHighlightText = text;
|
|
|
|
}
|
|
|
|
|
2011-06-07 07:57:25 +00:00
|
|
|
void ArticleView::back()
|
|
|
|
{
|
|
|
|
// Don't allow navigating back to page 0, which is usually the initial
|
|
|
|
// empty page
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( canGoBack() ) {
|
2022-11-04 13:23:42 +00:00
|
|
|
currentActiveDictIds.clear();
|
|
|
|
historyMode = true;
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->back();
|
2011-06-07 07:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::forward()
|
|
|
|
{
|
2022-11-04 13:23:42 +00:00
|
|
|
currentActiveDictIds.clear();
|
|
|
|
historyMode = true;
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->forward();
|
2011-06-07 07:57:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 20:34:05 +00:00
|
|
|
void ArticleView::handleAnkiAction()
|
|
|
|
{
|
|
|
|
// React to the "send *word* to anki" action.
|
|
|
|
// If selected text is empty, use the whole article as the definition.
|
|
|
|
if ( webview->selectedText().isEmpty() ) {
|
|
|
|
makeAnkiCardFromArticle( getActiveArticleId() );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendToAnki( webview->title(), webview->selectedText(), translateLine->text() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::reload()
|
|
|
|
{
|
|
|
|
webview->reload();
|
|
|
|
}
|
2022-06-11 17:57:52 +00:00
|
|
|
|
2022-03-30 15:08:24 +00:00
|
|
|
void ArticleView::hasSound( const std::function< void( bool ) > & callback )
|
2009-04-10 21:07:03 +00:00
|
|
|
{
|
2023-07-13 06:49:41 +00:00
|
|
|
webview->page()->runJavaScript( R"(if(typeof(gdAudioLinks)!="undefined") gdAudioLinks.first)",
|
2023-03-17 09:42:44 +00:00
|
|
|
[ callback ]( const QVariant & v ) {
|
|
|
|
bool has = false;
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( v.type() == QVariant::String )
|
2023-03-17 09:42:44 +00:00
|
|
|
has = !v.toString().isEmpty();
|
|
|
|
callback( has );
|
|
|
|
} );
|
2009-04-10 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 14:45:16 +00:00
|
|
|
//use webengine javascript to playsound
|
2009-04-10 21:07:03 +00:00
|
|
|
void ArticleView::playSound()
|
|
|
|
{
|
2023-07-13 06:49:41 +00:00
|
|
|
QString variable = R"( (function(){ var link=gdAudioMap.get(gdAudioLinks.current);
|
|
|
|
if(link==undefined){
|
|
|
|
link=gdAudioLinks.first;
|
|
|
|
}
|
|
|
|
return link;})(); )";
|
2022-01-31 00:42:36 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript( variable, [ this ]( const QVariant & result ) {
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( result.type() == QVariant::String ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
QString soundScript = result.toString();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !soundScript.isEmpty() )
|
2023-03-17 09:42:44 +00:00
|
|
|
openLink( QUrl::fromEncoded( soundScript.toUtf8() ), webview->url() );
|
|
|
|
}
|
|
|
|
} );
|
2009-04-10 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 15:08:24 +00:00
|
|
|
void ArticleView::toHtml( const std::function< void( QString & ) > & callback )
|
2009-05-01 11:17:29 +00:00
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->toHtml( [ = ]( const QString & content ) {
|
|
|
|
QString html = content;
|
|
|
|
callback( html );
|
|
|
|
} );
|
2009-05-01 11:17:29 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
void ArticleView::setHtml( const QString & content, const QUrl & baseUrl )
|
|
|
|
{
|
|
|
|
webview->page()->setHtml( content, baseUrl );
|
2021-08-21 01:41:40 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
void ArticleView::setContent( const QByteArray & data, const QString & mimeType, const QUrl & baseUrl )
|
2009-05-01 11:17:29 +00:00
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->setContent( data, mimeType, baseUrl );
|
2009-05-01 11:17:29 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
QString ArticleView::getTitle()
|
|
|
|
{
|
|
|
|
return webview->page()->title();
|
|
|
|
}
|
2023-03-17 09:42:44 +00:00
|
|
|
|
2023-05-28 16:01:54 +00:00
|
|
|
QString ArticleView::getWord() const
|
2021-06-10 16:13:11 +00:00
|
|
|
{
|
2023-05-28 16:01:54 +00:00
|
|
|
return currentWord;
|
2021-06-10 16:13:11 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 12:20:33 +00:00
|
|
|
void ArticleView::print( QPrinter * printer ) const
|
|
|
|
{
|
2022-03-12 10:12:17 +00:00
|
|
|
QEventLoop loop;
|
|
|
|
bool result;
|
2023-07-20 08:02:22 +00:00
|
|
|
auto printPreview = [ & ]( bool success ) {
|
2022-03-12 10:12:17 +00:00
|
|
|
result = success;
|
|
|
|
loop.quit();
|
|
|
|
};
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->print( printer, std::move( printPreview ) );
|
2022-03-29 12:34:41 +00:00
|
|
|
#else
|
2023-03-17 09:42:44 +00:00
|
|
|
connect( webview, &QWebEngineView::printFinished, &loop, std::move( printPreview ) );
|
|
|
|
webview->print( printer );
|
2022-03-29 12:34:41 +00:00
|
|
|
#endif
|
2022-03-12 10:12:17 +00:00
|
|
|
loop.exec();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !result ) {
|
2022-03-12 10:12:17 +00:00
|
|
|
qDebug() << "print failed";
|
|
|
|
}
|
2009-05-01 12:20:33 +00:00
|
|
|
}
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void ArticleView::contextMenuRequested( QPoint const & pos )
|
|
|
|
{
|
|
|
|
// Is that a link? Is there a selection?
|
2023-03-17 09:42:44 +00:00
|
|
|
QWebEnginePage * r = webview->page();
|
2009-01-28 20:55:45 +00:00
|
|
|
QMenu menu( this );
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
QAction * followLink = nullptr;
|
|
|
|
QAction * followLinkExternal = nullptr;
|
|
|
|
QAction * followLinkNewTab = nullptr;
|
|
|
|
QAction * lookupSelection = nullptr;
|
|
|
|
QAction * lookupSelectionGr = nullptr;
|
|
|
|
QAction * lookupSelectionNewTab = nullptr;
|
|
|
|
QAction * lookupSelectionNewTabGr = nullptr;
|
|
|
|
QAction * maxDictionaryRefsAction = nullptr;
|
|
|
|
QAction * addWordToHistoryAction = nullptr;
|
|
|
|
QAction * addHeaderToHistoryAction = nullptr;
|
|
|
|
QAction * sendWordToInputLineAction = nullptr;
|
|
|
|
QAction * saveImageAction = nullptr;
|
|
|
|
QAction * saveSoundAction = nullptr;
|
|
|
|
QAction * saveBookmark = nullptr;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
|
|
|
const QWebEngineContextMenuData * menuData = &( r->contextMenuData() );
|
2022-02-27 05:17:37 +00:00
|
|
|
#else
|
2023-03-17 09:42:44 +00:00
|
|
|
QWebEngineContextMenuRequest * menuData = webview->lastContextMenuRequest();
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2023-07-20 08:02:22 +00:00
|
|
|
QUrl targetUrl( menuData->linkUrl() );
|
2009-05-29 19:48:50 +00:00
|
|
|
Contexts contexts;
|
|
|
|
|
|
|
|
tryMangleWebsiteClickedUrl( targetUrl, contexts );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !targetUrl.isEmpty() ) {
|
|
|
|
if ( !isExternalLink( targetUrl ) ) {
|
2022-12-27 09:54:03 +00:00
|
|
|
followLink = new QAction( tr( "Op&en Link" ), &menu );
|
2009-05-29 19:48:50 +00:00
|
|
|
menu.addAction( followLink );
|
2009-04-03 21:57:23 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !popupView && !isAudioLink( targetUrl ) ) {
|
|
|
|
followLinkNewTab = new QAction( QIcon( ":/icons/addtab.svg" ), tr( "Open Link in New &Tab" ), &menu );
|
2009-05-29 19:48:50 +00:00
|
|
|
menu.addAction( followLinkNewTab );
|
|
|
|
}
|
|
|
|
}
|
2009-04-03 21:57:23 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( isExternalLink( targetUrl ) ) {
|
2009-05-29 19:48:50 +00:00
|
|
|
followLinkExternal = new QAction( tr( "Open Link in &External Browser" ), &menu );
|
|
|
|
menu.addAction( followLinkExternal );
|
2023-03-17 09:42:44 +00:00
|
|
|
menu.addAction( webview->pageAction( QWebEnginePage::CopyLinkToClipboard ) );
|
2009-05-29 19:48:50 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 08:30:16 +00:00
|
|
|
QUrl imageUrl;
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
|
|
|
if ( !popupView && menuData->mediaType() == QWebEngineContextMenuData::MediaTypeImage )
|
2022-02-27 05:17:37 +00:00
|
|
|
#else
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !popupView && menuData->mediaType() == QWebEngineContextMenuRequest::MediaType::MediaTypeImage )
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2022-01-02 08:30:16 +00:00
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
imageUrl = menuData->mediaUrl();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !imageUrl.isEmpty() ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
menu.addAction( webview->pageAction( QWebEnginePage::CopyImageToClipboard ) );
|
|
|
|
saveImageAction = new QAction( tr( "Save &image..." ), &menu );
|
|
|
|
menu.addAction( saveImageAction );
|
|
|
|
}
|
2022-01-02 08:30:16 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !popupView && isAudioLink( targetUrl ) ) {
|
|
|
|
saveSoundAction = new QAction( tr( "Save s&ound..." ), &menu );
|
|
|
|
menu.addAction( saveSoundAction );
|
2022-01-02 08:30:16 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 20:34:05 +00:00
|
|
|
QString const selectedText = webview->selectedText();
|
2023-07-20 08:02:22 +00:00
|
|
|
QString text = Utils::trimNonChar( selectedText );
|
2009-09-08 20:31:31 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( text.size() && text.size() < 60 ) {
|
2009-09-08 20:31:31 +00:00
|
|
|
// We don't prompt for selections larger or equal to 60 chars, since
|
|
|
|
// it ruins the menu and it's hardly a single word anyway.
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
lookupSelection = new QAction( tr( "&Look up \"%1\"" ).arg( text ), &menu );
|
2009-01-28 20:55:45 +00:00
|
|
|
menu.addAction( lookupSelection );
|
2010-09-16 18:53:39 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !popupView ) {
|
|
|
|
lookupSelectionNewTab =
|
|
|
|
new QAction( QIcon( ":/icons/addtab.svg" ), tr( "Look up \"%1\" in &New Tab" ).arg( text ), &menu );
|
2009-02-08 15:49:17 +00:00
|
|
|
menu.addAction( lookupSelectionNewTab );
|
2012-11-26 13:13:13 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
sendWordToInputLineAction = new QAction( tr( "Send \"%1\" to input line" ).arg( text ), &menu );
|
2012-11-26 13:13:13 +00:00
|
|
|
menu.addAction( sendWordToInputLineAction );
|
2009-02-08 15:49:17 +00:00
|
|
|
}
|
2009-04-03 21:57:23 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
addWordToHistoryAction = new QAction( tr( "&Add \"%1\" to history" ).arg( text ), &menu );
|
2012-09-16 10:30:14 +00:00
|
|
|
menu.addAction( addWordToHistoryAction );
|
|
|
|
|
2009-05-14 19:27:19 +00:00
|
|
|
Instances::Group const * altGroup =
|
2023-07-17 00:24:02 +00:00
|
|
|
( currentGroupId != getGroup( webview->url() ) ) ? groups.findGroup( currentGroupId ) : nullptr;
|
2009-05-14 19:27:19 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( altGroup ) {
|
|
|
|
QIcon icon = altGroup->icon.size() ? QIcon( ":/flags/" + altGroup->icon ) : QIcon();
|
2009-05-14 19:27:19 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
lookupSelectionGr = new QAction( icon, tr( "Look up \"%1\" in %2" ).arg( text ).arg( altGroup->name ), &menu );
|
2009-05-14 19:27:19 +00:00
|
|
|
menu.addAction( lookupSelectionGr );
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !popupView ) {
|
|
|
|
lookupSelectionNewTabGr =
|
|
|
|
new QAction( QIcon( ":/icons/addtab.svg" ),
|
|
|
|
tr( "Look up \"%1\" in %2 in &New Tab" ).arg( text ).arg( altGroup->name ),
|
|
|
|
&menu );
|
2009-05-14 19:27:19 +00:00
|
|
|
menu.addAction( lookupSelectionNewTabGr );
|
|
|
|
}
|
|
|
|
}
|
2009-09-08 20:31:31 +00:00
|
|
|
}
|
2009-05-14 19:27:19 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( text.size() ) {
|
2022-06-01 15:40:00 +00:00
|
|
|
// avoid too long in the menu ,use left 30 characters.
|
|
|
|
saveBookmark = new QAction( tr( "Save &Bookmark \"%1...\"" ).arg( text.left( 30 ) ), &menu );
|
2022-06-01 15:11:41 +00:00
|
|
|
menu.addAction( saveBookmark );
|
|
|
|
}
|
|
|
|
|
2023-03-22 20:34:05 +00:00
|
|
|
// Add anki menu (if enabled)
|
|
|
|
// If there is no selected text, it will extract text from the current article.
|
|
|
|
if ( cfg.preferences.ankiConnectServer.enabled ) {
|
|
|
|
menu.addAction( &sendToAnkiAction );
|
|
|
|
sendToAnkiAction.setText( webview->selectedText().isEmpty() ? tr( "&Send Current Article to Anki" ) :
|
|
|
|
tr( "&Send selected text to Anki" ) );
|
2022-05-21 06:03:26 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( text.isEmpty() && !cfg.preferences.storeHistory ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
QString txt = webview->title();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( txt.size() > 60 )
|
2015-10-14 15:18:11 +00:00
|
|
|
txt = txt.left( 60 ) + "...";
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
addHeaderToHistoryAction = new QAction( tr( "&Add \"%1\" to history" ).arg( txt ), &menu );
|
2015-10-14 15:18:11 +00:00
|
|
|
menu.addAction( addHeaderToHistoryAction );
|
2013-01-17 18:38:49 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( selectedText.size() ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
menu.addAction( webview->pageAction( QWebEnginePage::Copy ) );
|
2013-05-15 13:52:47 +00:00
|
|
|
menu.addAction( ©AsTextAction );
|
2013-01-18 13:22:24 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2013-01-18 14:37:24 +00:00
|
|
|
menu.addAction( &selectCurrentArticleAction );
|
2023-03-17 09:42:44 +00:00
|
|
|
menu.addAction( webview->pageAction( QWebEnginePage::SelectAll ) );
|
2013-01-18 13:22:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-12 16:22:42 +00:00
|
|
|
map< QAction *, QString > tableOfContents;
|
2010-09-16 18:53:39 +00:00
|
|
|
|
2009-04-12 16:22:42 +00:00
|
|
|
// Add table of contents
|
2009-05-11 22:25:22 +00:00
|
|
|
QStringList ids = getArticlesList();
|
2009-04-12 16:22:42 +00:00
|
|
|
|
|
|
|
if ( !menu.isEmpty() && ids.size() )
|
|
|
|
menu.addSeparator();
|
2009-04-14 18:35:27 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
unsigned refsAdded = 0;
|
2011-07-31 00:11:07 +00:00
|
|
|
bool maxDictionaryRefsReached = false;
|
2009-04-14 18:35:27 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
for ( QStringList::const_iterator i = ids.constBegin(); i != ids.constEnd(); ++i, ++refsAdded ) {
|
2009-04-12 16:22:42 +00:00
|
|
|
// Find this dictionary
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
for ( unsigned x = allDictionaries.size(); x--; ) {
|
|
|
|
if ( allDictionaries[ x ]->getId() == i->toUtf8().data() ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
QAction * action = nullptr;
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( refsAdded == cfg.preferences.maxDictionaryRefsInContextMenu ) {
|
2011-07-31 00:11:07 +00:00
|
|
|
// Enough! Or the menu would become too large.
|
2023-07-20 08:02:22 +00:00
|
|
|
maxDictionaryRefsAction = new QAction( ".........", &menu );
|
|
|
|
action = maxDictionaryRefsAction;
|
2011-07-31 00:11:07 +00:00
|
|
|
maxDictionaryRefsReached = true;
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
|
|
|
action = new QAction( allDictionaries[ x ]->getIcon(),
|
|
|
|
QString::fromUtf8( allDictionaries[ x ]->getName().c_str() ),
|
|
|
|
&menu );
|
2018-07-07 09:33:15 +00:00
|
|
|
// Force icons in menu on all platforms,
|
2011-07-31 00:11:07 +00:00
|
|
|
// since without them it will be much harder
|
|
|
|
// to find things.
|
|
|
|
action->setIconVisibleInMenu( true );
|
|
|
|
}
|
2009-04-12 16:22:42 +00:00
|
|
|
menu.addAction( action );
|
|
|
|
|
|
|
|
tableOfContents[ action ] = *i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( maxDictionaryRefsReached )
|
2011-07-31 00:11:07 +00:00
|
|
|
break;
|
2009-04-12 16:22:42 +00:00
|
|
|
}
|
2010-09-16 18:53:39 +00:00
|
|
|
|
2013-05-30 02:18:28 +00:00
|
|
|
menu.addSeparator();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !popupView || cfg.pinPopupWindow )
|
2022-09-08 13:11:25 +00:00
|
|
|
menu.addAction( &inspectAction );
|
2013-05-30 02:18:28 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !menu.isEmpty() ) {
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( this, &ArticleView::closePopupMenu, &menu, &QWidget::close );
|
2023-03-17 09:42:44 +00:00
|
|
|
QAction * result = menu.exec( webview->mapToGlobal( pos ) );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-29 19:48:50 +00:00
|
|
|
if ( !result )
|
|
|
|
return;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( result == followLink )
|
2023-03-17 09:42:44 +00:00
|
|
|
openLink( targetUrl, webview->url(), getCurrentArticle(), contexts );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == followLinkExternal )
|
2021-12-29 12:09:29 +00:00
|
|
|
QDesktopServices::openUrl( targetUrl );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == lookupSelection )
|
2023-03-17 09:42:44 +00:00
|
|
|
showDefinition( text, getGroup( webview->url() ), getCurrentArticle() );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == saveBookmark ) {
|
2022-06-01 15:40:00 +00:00
|
|
|
emit saveBookmarkSignal( text.left( 60 ) );
|
2022-06-01 15:11:41 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == &sendToAnkiAction ) {
|
2023-03-22 20:34:05 +00:00
|
|
|
// This action is handled by a slot.
|
|
|
|
return;
|
2022-05-21 06:03:26 +00:00
|
|
|
}
|
2023-07-17 00:24:02 +00:00
|
|
|
else if ( result == lookupSelectionGr && currentGroupId )
|
|
|
|
showDefinition( selectedText, currentGroupId, QString() );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == addWordToHistoryAction )
|
2012-09-12 14:11:30 +00:00
|
|
|
emit forceAddWordToHistory( selectedText );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( result == addHeaderToHistoryAction )
|
2023-03-17 09:42:44 +00:00
|
|
|
emit forceAddWordToHistory( webview->title() );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == sendWordToInputLineAction )
|
2012-11-26 13:13:13 +00:00
|
|
|
emit sendWordToInputLine( selectedText );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( !popupView && result == followLinkNewTab )
|
2023-03-17 09:42:44 +00:00
|
|
|
emit openLinkInNewTab( targetUrl, webview->url(), getCurrentArticle(), contexts );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( !popupView && result == lookupSelectionNewTab )
|
2023-03-17 09:42:44 +00:00
|
|
|
emit showDefinitionInNewTab( selectedText, getGroup( webview->url() ), getCurrentArticle(), Contexts() );
|
2023-07-17 00:24:02 +00:00
|
|
|
else if ( !popupView && result == lookupSelectionNewTabGr && currentGroupId )
|
|
|
|
emit showDefinitionInNewTab( selectedText, currentGroupId, QString(), Contexts() );
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( result == saveImageAction || result == saveSoundAction ) {
|
2022-01-09 14:18:53 +00:00
|
|
|
QUrl url = ( result == saveImageAction ) ? imageUrl : targetUrl;
|
2013-05-27 11:18:13 +00:00
|
|
|
QString savePath;
|
|
|
|
QString fileName;
|
|
|
|
|
|
|
|
if ( cfg.resourceSavePath.isEmpty() )
|
|
|
|
savePath = QDir::homePath();
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2013-05-27 11:18:13 +00:00
|
|
|
savePath = QDir::fromNativeSeparators( cfg.resourceSavePath );
|
|
|
|
if ( !QDir( savePath ).exists() )
|
|
|
|
savePath = QDir::homePath();
|
|
|
|
}
|
|
|
|
|
2021-11-27 07:17:33 +00:00
|
|
|
QString name = Utils::Url::path( url ).section( '/', -1 );
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( result == saveSoundAction ) {
|
2013-05-27 11:18:13 +00:00
|
|
|
// Audio data
|
2023-07-20 08:02:22 +00:00
|
|
|
// if ( name.indexOf( '.' ) < 0 )
|
|
|
|
// name += ".wav";
|
2013-05-27 11:18:13 +00:00
|
|
|
|
|
|
|
fileName = savePath + "/" + name;
|
2023-07-20 08:02:22 +00:00
|
|
|
fileName = QFileDialog::getSaveFileName(
|
|
|
|
parentWidget(),
|
|
|
|
tr( "Save sound" ),
|
|
|
|
fileName,
|
|
|
|
tr(
|
|
|
|
"Sound files (*.wav *.opus *.ogg *.oga *.mp3 *.mp4 *.aac *.flac *.mid *.wv *.ape *.spx);;All files (*.*)" ) );
|
2013-05-27 11:18:13 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2013-05-27 11:18:13 +00:00
|
|
|
// Image data
|
|
|
|
|
|
|
|
// Check for babylon image name
|
|
|
|
if ( name[ 0 ] == '\x1E' )
|
|
|
|
name.remove( 0, 1 );
|
|
|
|
if ( name.length() && name[ name.length() - 1 ] == '\x1F' )
|
|
|
|
name.chop( 1 );
|
|
|
|
|
|
|
|
fileName = savePath + "/" + name;
|
2023-07-20 08:02:22 +00:00
|
|
|
fileName = QFileDialog::getSaveFileName( parentWidget(),
|
|
|
|
tr( "Save image" ),
|
2013-05-27 11:18:13 +00:00
|
|
|
fileName,
|
|
|
|
tr( "Image files (*.bmp *.jpg *.png *.tif);;All files (*.*)" ) );
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !fileName.isEmpty() ) {
|
2013-05-27 11:18:13 +00:00
|
|
|
QFileInfo fileInfo( fileName );
|
|
|
|
emit storeResourceSavePath( QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
saveResource( url, webview->url(), fileName );
|
2013-05-27 11:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2011-07-31 00:11:07 +00:00
|
|
|
if ( !popupView && result == maxDictionaryRefsAction )
|
|
|
|
emit showDictsPane();
|
|
|
|
|
2009-04-12 16:22:42 +00:00
|
|
|
// Match against table of contents
|
|
|
|
QString id = tableOfContents[ result ];
|
|
|
|
|
|
|
|
if ( id.size() )
|
2021-06-29 08:59:16 +00:00
|
|
|
setCurrentArticle( scrollToFromDictionaryId( id ), true );
|
2009-02-08 15:49:17 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
qDebug() << "title = " << r->title();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void ArticleView::resourceDownloadFinished()
|
|
|
|
{
|
|
|
|
if ( resourceDownloadRequests.empty() )
|
|
|
|
return; // Stray signal
|
|
|
|
|
|
|
|
// Find any finished resources
|
2023-07-20 08:02:22 +00:00
|
|
|
for ( list< sptr< Dictionary::DataRequest > >::iterator i = resourceDownloadRequests.begin();
|
|
|
|
i != resourceDownloadRequests.end(); ) {
|
|
|
|
if ( ( *i )->isFinished() ) {
|
|
|
|
if ( ( *i )->dataSize() >= 0 ) {
|
2009-03-26 19:00:08 +00:00
|
|
|
// Ok, got one finished, all others are irrelevant now
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
vector< char > const & data = ( *i )->getFullData();
|
2009-03-26 19:00:08 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( resourceDownloadUrl.scheme() == "gdau"
|
|
|
|
|| Dictionary::WebMultimediaDownload::isAudioUrl( resourceDownloadUrl ) ) {
|
2010-01-02 18:16:22 +00:00
|
|
|
// Audio data
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( audioPlayer.data(),
|
2023-07-20 08:02:22 +00:00
|
|
|
&AudioPlayerInterface::error,
|
|
|
|
this,
|
|
|
|
&ArticleView::audioPlayerError,
|
|
|
|
Qt::UniqueConnection );
|
2018-03-22 17:07:10 +00:00
|
|
|
QString errorMessage = audioPlayer->play( data.data(), data.size() );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !errorMessage.isEmpty() )
|
2018-03-22 17:07:10 +00:00
|
|
|
QMessageBox::critical( this, "GoldenDict", tr( "Failed to play sound file: %1" ).arg( errorMessage ) );
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2009-03-26 19:00:08 +00:00
|
|
|
// Create a temporary file
|
2017-03-13 14:38:27 +00:00
|
|
|
// Remove the ones previously used, if any
|
2009-03-26 19:00:08 +00:00
|
|
|
cleanupTemp();
|
2017-03-13 14:38:27 +00:00
|
|
|
QString fileName;
|
2010-09-16 18:53:39 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
QTemporaryFile tmp( QDir::temp().filePath( "XXXXXX-" + resourceDownloadUrl.path().section( '/', -1 ) ),
|
|
|
|
this );
|
2009-03-26 19:00:08 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !tmp.open() || (size_t)tmp.write( &data.front(), data.size() ) != data.size() ) {
|
2013-02-01 12:36:01 +00:00
|
|
|
QMessageBox::critical( this, "GoldenDict", tr( "Failed to create temporary file." ) );
|
2009-03-26 19:00:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-09-16 18:53:39 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
tmp.setAutoRemove( false );
|
2010-09-16 18:53:39 +00:00
|
|
|
|
2017-03-13 14:38:27 +00:00
|
|
|
desktopOpenedTempFiles.insert( fileName = tmp.fileName() );
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
2010-09-16 18:53:39 +00:00
|
|
|
|
2017-03-13 14:38:27 +00:00
|
|
|
if ( !QDesktopServices::openUrl( QUrl::fromLocalFile( fileName ) ) )
|
2023-07-20 08:02:22 +00:00
|
|
|
QMessageBox::critical(
|
|
|
|
this,
|
|
|
|
"GoldenDict",
|
|
|
|
tr( "Failed to auto-open resource file, try opening manually: %1." ).arg( fileName ) );
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ok, whatever it was, it's finished. Remove this and any other
|
|
|
|
// requests and finish.
|
|
|
|
|
|
|
|
resourceDownloadRequests.clear();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2011-05-29 05:08:37 +00:00
|
|
|
// This one had no data. Erase it.
|
2009-03-26 19:00:08 +00:00
|
|
|
resourceDownloadRequests.erase( i++ );
|
|
|
|
}
|
|
|
|
}
|
2017-04-27 20:55:53 +00:00
|
|
|
else // Unfinished, wait.
|
|
|
|
break;
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( resourceDownloadRequests.empty() ) {
|
2022-12-11 11:15:30 +00:00
|
|
|
// emit statusBarMessage(
|
|
|
|
// tr("WARNING: %1").arg(tr("The referenced resource failed to download.")),
|
|
|
|
// 10000, QPixmap(":/icons/error.svg"));
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-05 10:22:12 +00:00
|
|
|
void ArticleView::audioPlayerError( QString const & message )
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
emit statusBarMessage( tr( "WARNING: Audio Player: %1" ).arg( message ), 10000, QPixmap( ":/icons/error.svg" ) );
|
2013-05-05 10:22:12 +00:00
|
|
|
}
|
|
|
|
|
2009-05-12 10:52:11 +00:00
|
|
|
void ArticleView::pasteTriggered()
|
|
|
|
{
|
2023-05-28 16:01:54 +00:00
|
|
|
QString word = cfg.preferences.sanitizeInputPhrase( QApplication::clipboard()->text() );
|
2009-05-12 10:52:11 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !word.isEmpty() ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
unsigned groupId = getGroup( webview->url() );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( groupId == 0 ) {
|
2013-08-22 16:05:39 +00:00
|
|
|
// We couldn't figure out the group out of the URL,
|
|
|
|
// so let's try the currently selected group.
|
2023-07-17 00:24:02 +00:00
|
|
|
groupId = currentGroupId;
|
2013-08-22 16:05:39 +00:00
|
|
|
}
|
2023-05-28 16:01:54 +00:00
|
|
|
showDefinition( word, groupId, getCurrentArticle() );
|
2013-08-22 16:05:39 +00:00
|
|
|
}
|
2009-05-12 10:52:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 02:57:57 +00:00
|
|
|
unsigned ArticleView::getCurrentGroup()
|
|
|
|
{
|
|
|
|
return groupComboBox->getCurrentGroup();
|
|
|
|
}
|
|
|
|
|
2009-05-15 14:11:54 +00:00
|
|
|
void ArticleView::moveOneArticleUp()
|
|
|
|
{
|
|
|
|
QString current = getCurrentArticle();
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( current.size() ) {
|
2009-05-15 14:11:54 +00:00
|
|
|
QStringList lst = getArticlesList();
|
|
|
|
|
2021-06-29 08:59:16 +00:00
|
|
|
int idx = lst.indexOf( dictionaryIdFromScrollTo( current ) );
|
2009-05-15 14:11:54 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( idx != -1 ) {
|
2009-05-15 14:11:54 +00:00
|
|
|
--idx;
|
|
|
|
|
|
|
|
if ( idx < 0 )
|
|
|
|
idx = lst.size() - 1;
|
|
|
|
|
2021-06-29 08:59:16 +00:00
|
|
|
setCurrentArticle( scrollToFromDictionaryId( lst[ idx ] ), true );
|
2009-05-15 14:11:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::moveOneArticleDown()
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
QString current = getCurrentArticle();
|
2022-02-22 16:27:30 +00:00
|
|
|
QString currentDictId = dictionaryIdFromScrollTo( current );
|
|
|
|
QStringList lst = getArticlesList();
|
|
|
|
// if current article is empty .use the first as default.
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( currentDictId.isEmpty() && !lst.isEmpty() ) {
|
2022-02-22 16:27:30 +00:00
|
|
|
currentDictId = lst[ 0 ];
|
|
|
|
}
|
2009-05-15 14:11:54 +00:00
|
|
|
|
2022-02-22 16:27:30 +00:00
|
|
|
int idx = lst.indexOf( currentDictId );
|
2009-05-15 14:11:54 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( idx != -1 ) {
|
2022-02-22 16:27:30 +00:00
|
|
|
idx = ( idx + 1 ) % lst.size();
|
2009-05-15 14:11:54 +00:00
|
|
|
|
2022-02-22 16:27:30 +00:00
|
|
|
setCurrentArticle( scrollToFromDictionaryId( lst[ idx ] ), true );
|
2009-05-15 14:11:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 11:14:43 +00:00
|
|
|
void ArticleView::openSearch()
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !isVisible() )
|
2014-04-16 16:18:28 +00:00
|
|
|
return;
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ftsSearchIsOpened )
|
2014-04-22 13:47:02 +00:00
|
|
|
closeSearch();
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !searchIsOpened ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
searchPanel->show();
|
2023-03-17 22:42:11 +00:00
|
|
|
searchPanel->lineEdit->setText( getTitle() );
|
2009-05-16 11:14:43 +00:00
|
|
|
searchIsOpened = true;
|
|
|
|
}
|
|
|
|
|
2023-03-17 22:42:11 +00:00
|
|
|
searchPanel->lineEdit->setFocus();
|
|
|
|
searchPanel->lineEdit->selectAll();
|
2009-05-16 11:14:43 +00:00
|
|
|
|
|
|
|
// Clear any current selection
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( webview->selectedText().size() ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" );
|
2009-05-16 11:14:43 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchPanel->lineEdit->property( "noResults" ).toBool() ) {
|
2023-03-17 22:42:11 +00:00
|
|
|
searchPanel->lineEdit->setProperty( "noResults", false );
|
2009-05-16 18:04:21 +00:00
|
|
|
|
2023-03-22 01:01:22 +00:00
|
|
|
Utils::Widget::setNoResultColor( searchPanel->lineEdit, false );
|
2009-05-16 11:14:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_searchPrevious_clicked()
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchIsOpened )
|
2013-01-22 21:04:45 +00:00
|
|
|
performFindOperation( false, true );
|
2009-05-16 11:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_searchNext_clicked()
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchIsOpened )
|
2013-01-22 21:04:45 +00:00
|
|
|
performFindOperation( false, false );
|
2009-05-16 11:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_searchText_textEdited()
|
|
|
|
{
|
|
|
|
performFindOperation( true, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_searchText_returnPressed()
|
|
|
|
{
|
|
|
|
on_searchNext_clicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_searchCloseButton_clicked()
|
|
|
|
{
|
|
|
|
closeSearch();
|
|
|
|
}
|
|
|
|
|
2011-06-12 23:59:35 +00:00
|
|
|
void ArticleView::on_searchCaseSensitive_clicked()
|
|
|
|
{
|
2022-06-16 18:13:56 +00:00
|
|
|
performFindOperation( true, false );
|
2011-06-12 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_highlightAllButton_clicked()
|
|
|
|
{
|
|
|
|
performFindOperation( false, false, true );
|
|
|
|
}
|
|
|
|
|
2022-01-18 15:04:27 +00:00
|
|
|
//the id start with "gdform-"
|
2023-07-20 08:02:22 +00:00
|
|
|
void ArticleView::onJsActiveArticleChanged( QString const & id )
|
2011-07-03 12:27:08 +00:00
|
|
|
{
|
2021-06-29 08:59:16 +00:00
|
|
|
if ( !isScrollTo( id ) )
|
2011-07-03 12:27:08 +00:00
|
|
|
return; // Incorrect id
|
|
|
|
|
2022-02-25 14:48:43 +00:00
|
|
|
QString dictId = dictionaryIdFromScrollTo( id );
|
|
|
|
setActiveArticleId( dictId );
|
|
|
|
emit activeArticleChanged( this, dictId );
|
2011-07-03 12:27:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-13 14:38:27 +00:00
|
|
|
void ArticleView::doubleClicked( QPoint pos )
|
2010-04-08 20:37:59 +00:00
|
|
|
{
|
|
|
|
// We might want to initiate translation of the selected word
|
2022-02-25 15:33:34 +00:00
|
|
|
audioPlayer->stop();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( cfg.preferences.doubleClickTranslates ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
QString selectedText = webview->selectedText();
|
2022-05-08 13:02:23 +00:00
|
|
|
|
|
|
|
// ignore empty word;
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( selectedText.isEmpty() )
|
2022-05-08 13:02:23 +00:00
|
|
|
return;
|
|
|
|
|
2022-03-30 07:21:16 +00:00
|
|
|
emit sendWordToInputLine( selectedText );
|
2010-04-08 20:37:59 +00:00
|
|
|
// Do some checks to make sure there's a sensible selection indeed
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Folding::applyWhitespaceOnly( gd::toWString( selectedText ) ).size() && selectedText.size() < 60 ) {
|
2010-04-08 20:37:59 +00:00
|
|
|
// Initiate translation
|
2010-09-16 18:53:39 +00:00
|
|
|
Qt::KeyboardModifiers kmod = QApplication::keyboardModifiers();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( kmod & ( Qt::ControlModifier | Qt::ShiftModifier ) ) { // open in new tab
|
2023-03-17 09:42:44 +00:00
|
|
|
emit showDefinitionInNewTab( selectedText, getGroup( webview->url() ), getCurrentArticle(), Contexts() );
|
2010-09-16 18:53:39 +00:00
|
|
|
}
|
2023-03-17 09:42:44 +00:00
|
|
|
else {
|
|
|
|
QUrl const & ref = webview->url();
|
2014-04-22 18:45:42 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) {
|
|
|
|
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
|
2018-04-10 14:49:52 +00:00
|
|
|
showDefinition( selectedText, dictsList, QRegExp(), getGroup( ref ), false );
|
2014-04-22 18:45:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
showDefinition( selectedText, getGroup( ref ), getCurrentArticle() );
|
|
|
|
}
|
2010-04-08 20:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-12 23:59:35 +00:00
|
|
|
void ArticleView::performFindOperation( bool restart, bool backwards, bool checkHighlight )
|
2009-05-16 11:14:43 +00:00
|
|
|
{
|
2023-03-17 22:42:11 +00:00
|
|
|
QString text = searchPanel->lineEdit->text();
|
2009-05-16 11:14:43 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( restart || checkHighlight ) {
|
|
|
|
if ( restart ) {
|
2011-06-12 23:59:35 +00:00
|
|
|
// Anyone knows how we reset the search position?
|
|
|
|
// For now we resort to this hack:
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( webview->selectedText().size() ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" );
|
2011-06-12 23:59:35 +00:00
|
|
|
}
|
2009-05-16 11:14:43 +00:00
|
|
|
}
|
2011-06-12 23:59:35 +00:00
|
|
|
|
2021-07-06 13:01:50 +00:00
|
|
|
QWebEnginePage::FindFlags f( 0 );
|
2011-06-12 23:59:35 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchPanel->caseSensitive->isChecked() )
|
2021-07-06 13:01:50 +00:00
|
|
|
f |= QWebEnginePage::FindCaseSensitively;
|
2011-06-12 23:59:35 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->findText( "", f );
|
2011-06-12 23:59:35 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchPanel->highlightAll->isChecked() )
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->findText( text, f );
|
2011-06-12 23:59:35 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( checkHighlight )
|
2011-06-12 23:59:35 +00:00
|
|
|
return;
|
2009-05-16 11:14:43 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 13:01:50 +00:00
|
|
|
QWebEnginePage::FindFlags f( 0 );
|
2009-05-16 11:14:43 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchPanel->caseSensitive->isChecked() )
|
2021-07-06 13:01:50 +00:00
|
|
|
f |= QWebEnginePage::FindCaseSensitively;
|
2009-05-16 11:14:43 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( backwards )
|
2021-07-06 13:01:50 +00:00
|
|
|
f |= QWebEnginePage::FindBackward;
|
2009-05-16 11:14:43 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
findText( text, f, [ text, this ]( bool match ) {
|
|
|
|
bool setMark = !text.isEmpty() && !match;
|
2009-05-16 11:14:43 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchPanel->lineEdit->property( "noResults" ).toBool() != setMark ) {
|
|
|
|
searchPanel->lineEdit->setProperty( "noResults", setMark );
|
2009-05-16 18:04:21 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
Utils::Widget::setNoResultColor( searchPanel->lineEdit, setMark );
|
|
|
|
}
|
|
|
|
} );
|
2010-11-15 15:22:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 15:11:41 +00:00
|
|
|
void ArticleView::findText( QString & text,
|
|
|
|
const QWebEnginePage::FindFlags & f,
|
|
|
|
const std::function< void( bool match ) > & callback )
|
2021-07-06 13:01:50 +00:00
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->findText( text, f, [ callback ]( const QWebEngineFindTextResult & result ) {
|
|
|
|
auto r = result.numberOfMatches() > 0;
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( callback )
|
2023-03-17 09:42:44 +00:00
|
|
|
callback( r );
|
|
|
|
} );
|
2022-02-27 05:17:37 +00:00
|
|
|
#else
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->findText( text, f, [ callback ]( bool result ) {
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( callback )
|
2023-03-17 09:42:44 +00:00
|
|
|
callback( result );
|
|
|
|
} );
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2021-07-06 13:01:50 +00:00
|
|
|
}
|
|
|
|
|
2009-05-16 11:14:43 +00:00
|
|
|
bool ArticleView::closeSearch()
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( searchIsOpened ) {
|
2023-03-17 09:42:44 +00:00
|
|
|
searchPanel->hide();
|
|
|
|
webview->setFocus();
|
2009-05-16 11:14:43 +00:00
|
|
|
searchIsOpened = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else if ( ftsSearchIsOpened ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
firstAvailableText.clear();
|
2014-04-22 13:47:02 +00:00
|
|
|
uniqueMatches.clear();
|
2023-07-20 08:02:22 +00:00
|
|
|
ftsPosition = 0;
|
2014-04-22 13:47:02 +00:00
|
|
|
ftsSearchIsOpened = false;
|
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
ftsSearchPanel->hide();
|
|
|
|
webview->setFocus();
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
QWebEnginePage::FindFlags flags( 0 );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->findText( "", flags );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-16 11:14:43 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
bool ArticleView::isSearchOpened()
|
|
|
|
{
|
|
|
|
return searchIsOpened;
|
|
|
|
}
|
2011-06-29 19:12:46 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void ArticleView::showEvent( QShowEvent * ev )
|
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
QWidget::showEvent( ev );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !searchIsOpened )
|
2023-03-17 09:42:44 +00:00
|
|
|
searchPanel->hide();
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !ftsSearchIsOpened )
|
2023-03-17 09:42:44 +00:00
|
|
|
ftsSearchPanel->hide();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
2012-09-16 10:19:47 +00:00
|
|
|
|
2013-05-15 13:52:47 +00:00
|
|
|
void ArticleView::copyAsText()
|
|
|
|
{
|
2023-03-17 09:42:44 +00:00
|
|
|
QString text = webview->selectedText();
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !text.isEmpty() )
|
2013-05-15 13:52:47 +00:00
|
|
|
QApplication::clipboard()->setText( text );
|
|
|
|
}
|
|
|
|
|
2014-04-22 13:47:02 +00:00
|
|
|
void ArticleView::highlightFTSResults()
|
|
|
|
{
|
|
|
|
closeSearch();
|
|
|
|
// Clear any current selection
|
2023-06-03 00:29:19 +00:00
|
|
|
webview->findText( "" );
|
|
|
|
QString regString = Utils::Url::queryItemValue( webview->url(), "regexp" );
|
|
|
|
if ( regString.isEmpty() )
|
|
|
|
return;
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
//<div><i>watch</i>out</div> to plainText will return "watchout".
|
|
|
|
//if application goes here,that means the article text must contains the search text.
|
|
|
|
//whole word match regString will contain \b . can not match the above senario.
|
|
|
|
//workaround ,remove \b from the regstring="(\bwatch\b)"
|
2023-07-01 14:39:43 +00:00
|
|
|
regString.remove( QRegularExpression( R"(\b)" ) );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-07-01 14:39:43 +00:00
|
|
|
//make it simple ,and do not support too much complex cases. such as wildcard etc.
|
|
|
|
firstAvailableText = regString;
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( firstAvailableText.isEmpty() ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
//remove possible wildcard character.
|
2023-07-09 05:51:16 +00:00
|
|
|
auto cleaned =
|
|
|
|
firstAvailableText.split( QRegularExpression( "\\p{P}", QRegularExpression::UseUnicodePropertiesOption ) );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( cleaned.empty() )
|
|
|
|
return;
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
firstAvailableText = cleaned.at( 0 );
|
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
|
|
|
webview->findText( firstAvailableText,
|
|
|
|
QWebEnginePage::FindBackward,
|
|
|
|
[ & ]( const QWebEngineFindTextResult & result ) {
|
|
|
|
qInfo() << result.activeMatch() << "of" << result.numberOfMatches() << "matches";
|
|
|
|
|
|
|
|
if ( result.numberOfMatches() == 0 ) {
|
|
|
|
ftsSearchPanel->statusLabel->setText( searchStatusMessageNoMatches() );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ftsSearchPanel->statusLabel->setText(
|
|
|
|
searchStatusMessage( result.activeMatch(), result.numberOfMatches() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
ftsSearchPanel->show();
|
|
|
|
ftsSearchPanel->previous->setEnabled( result.numberOfMatches() > 1 );
|
|
|
|
ftsSearchPanel->next->setEnabled( result.numberOfMatches() > 1 );
|
|
|
|
|
|
|
|
ftsSearchIsOpened = true;
|
|
|
|
} );
|
|
|
|
#else
|
|
|
|
webview->findText( firstAvailableText, QWebEnginePage::FindBackward, [ this ]( bool res ) {
|
|
|
|
ftsSearchPanel->previous->setEnabled( res );
|
|
|
|
if ( !ftsSearchPanel->next->isEnabled() )
|
|
|
|
ftsSearchPanel->next->setEnabled( res );
|
|
|
|
} );
|
|
|
|
#endif
|
2021-07-06 13:01:50 +00:00
|
|
|
}
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
void ArticleView::setActiveDictIds( const ActiveDictIds & ad )
|
2022-05-22 19:12:30 +00:00
|
|
|
{
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( ( ad.word == currentWord && ad.groupId == getCurrentGroup() ) || historyMode ) {
|
|
|
|
// ignore all other signals.
|
|
|
|
qDebug() << "receive dicts, current word:" << currentWord << ad.word << ":" << ad.dictIds;
|
|
|
|
currentActiveDictIds << ad.dictIds;
|
|
|
|
currentActiveDictIds.removeDuplicates();
|
|
|
|
emit updateFoundInDictsList();
|
2022-05-22 19:21:00 +00:00
|
|
|
}
|
2022-01-08 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
void ArticleView::dictionaryClear( const ActiveDictIds & ad )
|
2022-07-16 22:54:53 +00:00
|
|
|
{
|
|
|
|
// ignore all other signals.
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( ad.word == currentWord && ad.groupId == getCurrentGroup() ) {
|
2022-07-16 22:54:53 +00:00
|
|
|
qDebug() << "clear current dictionaries:" << currentWord;
|
|
|
|
currentActiveDictIds.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-22 13:47:02 +00:00
|
|
|
void ArticleView::performFtsFindOperation( bool backwards )
|
|
|
|
{
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !ftsSearchIsOpened )
|
2014-04-22 13:47:02 +00:00
|
|
|
return;
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( firstAvailableText.isEmpty() ) {
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->statusLabel->setText( searchStatusMessageNoMatches() );
|
|
|
|
ftsSearchPanel->next->setEnabled( false );
|
|
|
|
ftsSearchPanel->previous->setEnabled( false );
|
2014-04-22 13:47:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-06 13:01:50 +00:00
|
|
|
QWebEnginePage::FindFlags flags( 0 );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( ftsSearchMatchCase )
|
2021-07-06 13:01:50 +00:00
|
|
|
flags |= QWebEnginePage::FindCaseSensitively;
|
2014-04-22 13:47:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Restore saved highlighted selection
|
2023-03-17 09:42:44 +00:00
|
|
|
webview->page()->runJavaScript(
|
|
|
|
QString( "var sel=window.getSelection();sel.removeAllRanges();sel.addRange(%1);_=0;" ).arg( rangeVarName ) );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( backwards ) {
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
2023-06-03 00:29:19 +00:00
|
|
|
webview->findText( firstAvailableText,
|
2023-03-17 09:42:44 +00:00
|
|
|
flags | QWebEnginePage::FindBackward,
|
|
|
|
[ this ]( const QWebEngineFindTextResult & result ) {
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( result.numberOfMatches() == 0 )
|
2023-03-17 09:42:44 +00:00
|
|
|
return;
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->previous->setEnabled( true );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !ftsSearchPanel->next->isEnabled() )
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->next->setEnabled( true );
|
2023-06-03 00:29:19 +00:00
|
|
|
|
|
|
|
ftsSearchPanel->statusLabel->setText(
|
|
|
|
searchStatusMessage( result.activeMatch(), result.numberOfMatches() ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
} );
|
2022-02-27 05:17:37 +00:00
|
|
|
#else
|
2023-06-03 00:29:19 +00:00
|
|
|
webview->findText( firstAvailableText, flags | QWebEnginePage::FindBackward, [ this ]( bool res ) {
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->previous->setEnabled( res );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !ftsSearchPanel->next->isEnabled() )
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->next->setEnabled( res );
|
2023-03-17 09:42:44 +00:00
|
|
|
} );
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2023-03-17 09:42:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-07-20 08:02:22 +00:00
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
2023-06-03 00:29:19 +00:00
|
|
|
webview->findText( firstAvailableText, flags, [ this ]( const QWebEngineFindTextResult & result ) {
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( result.numberOfMatches() == 0 )
|
2023-03-17 09:42:44 +00:00
|
|
|
return;
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->next->setEnabled( true );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !ftsSearchPanel->previous->isEnabled() )
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->previous->setEnabled( true );
|
2023-06-03 00:29:19 +00:00
|
|
|
|
|
|
|
ftsSearchPanel->statusLabel->setText( searchStatusMessage( result.activeMatch(), result.numberOfMatches() ) );
|
2023-03-17 09:42:44 +00:00
|
|
|
} );
|
2022-02-27 05:17:37 +00:00
|
|
|
#else
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
webview->findText( firstAvailableText, flags, [ this ]( bool res ) {
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->next->setEnabled( res );
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( !ftsSearchPanel->previous->isEnabled() )
|
2023-03-17 22:42:11 +00:00
|
|
|
ftsSearchPanel->previous->setEnabled( res );
|
2023-03-17 09:42:44 +00:00
|
|
|
} );
|
2014-04-22 13:47:02 +00:00
|
|
|
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2023-06-03 00:29:19 +00:00
|
|
|
}
|
2014-04-22 13:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_ftsSearchPrevious_clicked()
|
|
|
|
{
|
|
|
|
performFtsFindOperation( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArticleView::on_ftsSearchNext_clicked()
|
|
|
|
{
|
|
|
|
performFtsFindOperation( false );
|
|
|
|
}
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
ResourceToSaveHandler::ResourceToSaveHandler( ArticleView * view, QString fileName ):
|
2013-05-27 11:18:13 +00:00
|
|
|
QObject( view ),
|
2023-06-03 00:29:19 +00:00
|
|
|
fileName( std::move( fileName ) ),
|
2017-04-27 20:55:53 +00:00
|
|
|
alreadyDone( false )
|
2013-05-27 11:18:13 +00:00
|
|
|
{
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( this, &ResourceToSaveHandler::statusBarMessage, view, &ArticleView::statusBarMessage );
|
2017-04-27 20:55:53 +00:00
|
|
|
}
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
void ResourceToSaveHandler::addRequest( const sptr< Dictionary::DataRequest > & req )
|
2017-04-27 20:55:53 +00:00
|
|
|
{
|
2023-06-03 00:29:19 +00:00
|
|
|
if ( !alreadyDone ) {
|
2017-04-27 20:55:53 +00:00
|
|
|
downloadRequests.push_back( req );
|
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( req.get(), &Dictionary::Request::finished, this, &ResourceToSaveHandler::downloadFinished );
|
2013-05-27 11:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceToSaveHandler::downloadFinished()
|
|
|
|
{
|
2017-04-27 20:55:53 +00:00
|
|
|
if ( downloadRequests.empty() )
|
|
|
|
return; // Stray signal
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
// Find any finished resources
|
2023-06-03 00:29:19 +00:00
|
|
|
for ( auto i = downloadRequests.begin(); i != downloadRequests.end(); ) {
|
|
|
|
if ( ( *i )->isFinished() ) {
|
|
|
|
if ( ( *i )->dataSize() >= 0 && !alreadyDone ) {
|
2017-04-27 20:55:53 +00:00
|
|
|
QByteArray resourceData;
|
2023-06-03 00:29:19 +00:00
|
|
|
vector< char > const & data = ( *i )->getFullData();
|
|
|
|
resourceData = QByteArray( data.data(), data.size() );
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
// Write data to file
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( !fileName.isEmpty() ) {
|
2023-06-03 00:29:19 +00:00
|
|
|
const QFileInfo fileInfo( fileName );
|
2017-04-27 20:55:53 +00:00
|
|
|
QDir().mkpath( fileInfo.absoluteDir().absolutePath() );
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2017-04-27 20:55:53 +00:00
|
|
|
QFile file( fileName );
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( file.open( QFile::WriteOnly ) ) {
|
2017-04-27 20:55:53 +00:00
|
|
|
file.write( resourceData.data(), resourceData.size() );
|
|
|
|
file.close();
|
|
|
|
}
|
2013-05-27 11:18:13 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( file.error() ) {
|
|
|
|
emit statusBarMessage( tr( "ERROR: %1" ).arg( tr( "Resource saving error: " ) + file.errorString() ),
|
|
|
|
10000,
|
|
|
|
QPixmap( ":/icons/error.svg" ) );
|
2017-04-27 20:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
alreadyDone = true;
|
|
|
|
|
|
|
|
// Clear other requests
|
|
|
|
|
|
|
|
downloadRequests.clear();
|
|
|
|
break;
|
|
|
|
}
|
2023-07-20 08:02:22 +00:00
|
|
|
else {
|
2017-04-27 20:55:53 +00:00
|
|
|
// This one had no data. Erase it.
|
|
|
|
downloadRequests.erase( i++ );
|
|
|
|
}
|
2013-05-27 11:18:13 +00:00
|
|
|
}
|
2017-04-27 20:55:53 +00:00
|
|
|
else // Unfinished, wait.
|
|
|
|
break;
|
2013-05-27 11:18:13 +00:00
|
|
|
}
|
2017-04-27 20:55:53 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
if ( downloadRequests.empty() ) {
|
|
|
|
if ( !alreadyDone ) {
|
|
|
|
emit statusBarMessage( tr( "WARNING: %1" ).arg( tr( "The referenced resource failed to download." ) ),
|
|
|
|
10000,
|
|
|
|
QPixmap( ":/icons/error.svg" ) );
|
2017-04-27 15:04:26 +00:00
|
|
|
}
|
2017-04-27 20:55:53 +00:00
|
|
|
emit done();
|
|
|
|
deleteLater();
|
2013-05-27 11:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-19 23:29:02 +00:00
|
|
|
|
2023-07-20 08:02:22 +00:00
|
|
|
ArticleViewAgent::ArticleViewAgent( ArticleView * articleView ):
|
|
|
|
QObject( articleView ),
|
|
|
|
articleView( articleView )
|
2022-01-19 23:29:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-19 12:37:11 +00:00
|
|
|
void ArticleViewAgent::onJsActiveArticleChanged( QString const & id )
|
|
|
|
{
|
|
|
|
articleView->onJsActiveArticleChanged( id );
|
2022-01-19 23:29:02 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 12:37:11 +00:00
|
|
|
void ArticleViewAgent::linkClickedInHtml( QUrl const & url )
|
|
|
|
{
|
|
|
|
articleView->linkClickedInHtml( url );
|
2022-01-19 23:29:02 +00:00
|
|
|
}
|
2023-04-15 02:48:12 +00:00
|
|
|
|
2023-04-15 11:10:15 +00:00
|
|
|
void ArticleViewAgent::collapseInHtml( QString const & dictId, bool on ) const
|
2023-04-15 02:48:12 +00:00
|
|
|
{
|
|
|
|
if ( GlobalBroadcaster::instance()->getPreference()->sessionCollapse ) {
|
|
|
|
if ( on ) {
|
|
|
|
GlobalBroadcaster::instance()->collapsedDicts.insert( dictId );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GlobalBroadcaster::instance()->collapsedDicts.remove( dictId );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|