|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
|
|
#include <QAction> |
|
|
#include <QMap> |
|
|
#include <QSet> |
|
|
#include <list> |
|
|
#include "article_netmgr.hh" |
|
|
#include "audio/audioplayerinterface.hh" |
|
|
#include "instances.hh" |
|
|
#include "groupcombobox.hh" |
|
|
#include "globalbroadcaster.hh" |
|
|
#include "article_inspect.hh" |
|
|
#include "ankiconnector.hh" |
|
|
#include "webmultimediadownload.hh" |
|
|
#include "base_type.hh" |
|
|
#include "articlewebview.hh" |
|
|
#include "ui/searchpanel.hh" |
|
|
#include "ui/ftssearchpanel.hh" |
|
|
#include "dictionary_group.hh" |
|
|
|
|
|
class ResourceToSaveHandler; |
|
|
class ArticleViewAgent; |
|
|
|
|
|
|
|
|
|
|
|
class ArticleView: public QWidget |
|
|
{ |
|
|
Q_OBJECT |
|
|
|
|
|
ArticleNetworkAccessManager & articleNetMgr; |
|
|
const AudioPlayerPtr & audioPlayer; |
|
|
std::unique_ptr< DictionaryGroup > dictionaryGroup; |
|
|
bool popupView; |
|
|
QString customTitle; |
|
|
const Config::Class & cfg; |
|
|
QWebChannel * channel; |
|
|
ArticleViewAgent * agent; |
|
|
|
|
|
AnkiConnector * ankiConnector; |
|
|
|
|
|
QAction pasteAction, articleUpAction, articleDownAction, goBackAction, goForwardAction, selectCurrentArticleAction, |
|
|
copyAsTextAction, inspectAction; |
|
|
|
|
|
bool expandOptionalParts; |
|
|
|
|
|
|
|
|
QAction sendToAnkiAction{ tr( "&Create Anki note" ), this }; |
|
|
|
|
|
|
|
|
QSet< QString > desktopOpenedTempFiles; |
|
|
|
|
|
|
|
|
QSet< QString > audioTempFiles; |
|
|
|
|
|
QAction * dictionaryBarToggled; |
|
|
|
|
|
unsigned currentGroupId; |
|
|
const QLineEdit * translateLine; |
|
|
|
|
|
|
|
|
QString currentWord; |
|
|
|
|
|
|
|
|
QStringList currentActiveDictIds; |
|
|
|
|
|
bool historyMode = false; |
|
|
|
|
|
|
|
|
QString activeDictId; |
|
|
|
|
|
QString audioLink_; |
|
|
|
|
|
|
|
|
QString firstAvailableText; |
|
|
QStringList uniqueMatches; |
|
|
|
|
|
QString delayedHighlightText; |
|
|
|
|
|
|
|
|
bool isWebsiteView = false; |
|
|
|
|
|
|
|
|
QString websiteHost; |
|
|
|
|
|
void highlightFTSResults(); |
|
|
void performFtsFindOperation( bool backwards ); |
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
ArticleView( QWidget * parent, |
|
|
ArticleNetworkAccessManager &, |
|
|
bool popupView, |
|
|
const Config::Class & cfg, |
|
|
const QLineEdit * translateLine, |
|
|
QAction * dictionaryBarToggled = nullptr, |
|
|
unsigned currentGroupId = 0 ); |
|
|
|
|
|
void setCurrentGroupId( unsigned currengGrgId ); |
|
|
unsigned getCurrentGroupId(); |
|
|
|
|
|
void setAudioLink( QString audioLink ); |
|
|
QString getAudioLink() const; |
|
|
|
|
|
QSize minimumSizeHint() const override; |
|
|
void clearContent(); |
|
|
|
|
|
~ArticleView(); |
|
|
|
|
|
|
|
|
void load( const QUrl & url, const QString & customTitle = {} ); |
|
|
|
|
|
void load( QString url, const QString & customTitle = {} ); |
|
|
|
|
|
void setCustomTitle( const QString & customTitle ); |
|
|
|
|
|
|
|
|
static QString scrollToFromDictionaryId( const QString & dictionaryId ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void showDefinition( const QString & word, |
|
|
unsigned group, |
|
|
const QString & scrollTo = QString(), |
|
|
const Contexts & contexts = Contexts() ); |
|
|
|
|
|
void showDefinition( const QString & word, |
|
|
const QStringList & dictIDs, |
|
|
const QRegularExpression & searchRegExp, |
|
|
unsigned group, |
|
|
bool ignoreDiacritics ); |
|
|
void showDefinition( const QString & word, const QStringList & dictIDs, unsigned group, bool ignoreDiacritics ); |
|
|
|
|
|
void sendToAnki( const QString & word, const QString & text, const QString & sentence ); |
|
|
|
|
|
|
|
|
void showAnticipation(); |
|
|
|
|
|
|
|
|
|
|
|
void makeAnkiCardFromArticle( const QString & article_id ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void openLink( const QUrl & url, |
|
|
const QUrl & referrer, |
|
|
const QString & scrollTo = QString(), |
|
|
const Contexts & contexts = Contexts() ); |
|
|
void playAudio( const QUrl & url ); |
|
|
void audioDownloadFinished( const sptr< Dictionary::DataRequest > & req ); |
|
|
|
|
|
|
|
|
|
|
|
void updateMutedContents(); |
|
|
|
|
|
bool canGoBack(); |
|
|
bool canGoForward(); |
|
|
|
|
|
|
|
|
void setSelectionBySingleClick( bool set ); |
|
|
|
|
|
void setDelayedHighlightText( const QString & text ); |
|
|
|
|
|
|
|
|
void syncBackgroundColorWithCfgDarkReader() const; |
|
|
|
|
|
QString getCurrentWord(); |
|
|
|
|
|
|
|
|
bool isInternalPage() const |
|
|
{ |
|
|
return webview->url().scheme() == "gdinternal"; |
|
|
} |
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
ArticleWebView * webview; |
|
|
SearchPanel * searchPanel; |
|
|
FtsSearchPanel * ftsSearchPanel; |
|
|
|
|
|
public slots: |
|
|
|
|
|
|
|
|
void back(); |
|
|
|
|
|
|
|
|
void forward(); |
|
|
|
|
|
|
|
|
void focus() |
|
|
{ |
|
|
webview->setFocus(); |
|
|
} |
|
|
|
|
|
|
|
|
void handleAnkiAction(); |
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
void reload(); |
|
|
|
|
|
void stopSound(); |
|
|
|
|
|
|
|
|
void hasSound( const std::function< void( bool has ) > & callback ); |
|
|
|
|
|
|
|
|
void playSound(); |
|
|
|
|
|
void setZoomFactor( qreal factor ) |
|
|
{ |
|
|
qreal existedFactor = webview->zoomFactor(); |
|
|
if ( !qFuzzyCompare( existedFactor, factor ) ) { |
|
|
qDebug() << "zoom factor ,existed:" << existedFactor << "set:" << factor; |
|
|
webview->setZoomFactor( factor ); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool isWebsite() const |
|
|
{ |
|
|
return isWebsiteView; |
|
|
} |
|
|
|
|
|
|
|
|
void setWebsite( bool website ) |
|
|
{ |
|
|
isWebsiteView = website; |
|
|
} |
|
|
|
|
|
|
|
|
QString getWebsiteHost() const |
|
|
{ |
|
|
return websiteHost; |
|
|
} |
|
|
|
|
|
|
|
|
void setWebsiteHost( const QString & host ); |
|
|
|
|
|
|
|
|
void toHtml( const std::function< void( QString & ) > & callback ); |
|
|
|
|
|
void setHtml( const QString & content, const QUrl & baseUrl ); |
|
|
QWebEnginePage * page(); |
|
|
void setContent( const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl() ); |
|
|
|
|
|
|
|
|
QString getTitle(); |
|
|
|
|
|
|
|
|
QString getWord() const; |
|
|
|
|
|
|
|
|
void print( QPrinter * ) const; |
|
|
|
|
|
|
|
|
|
|
|
bool closeSearch(); |
|
|
|
|
|
bool isSearchOpened(); |
|
|
|
|
|
|
|
|
|
|
|
void jumpToDictionary( const QString &, bool force ); |
|
|
|
|
|
|
|
|
|
|
|
QStringList getArticlesList(); |
|
|
|
|
|
|
|
|
QString getActiveArticleId(); |
|
|
void setActiveArticleId( const QString & ); |
|
|
|
|
|
ResourceToSaveHandler * saveResource( const QUrl & url, const QString & fileName ); |
|
|
|
|
|
void findText( QString & text, |
|
|
const QWebEnginePage::FindFlags & f, |
|
|
const std::function< void( bool match ) > & callback = nullptr ); |
|
|
|
|
|
signals: |
|
|
|
|
|
void titleChanged( ArticleView *, const QString & title ); |
|
|
|
|
|
void pageLoaded( ArticleView * ); |
|
|
|
|
|
|
|
|
void openLinkInNewTab( const QUrl &, const QUrl & referrer, const QString & fromArticle, const Contexts & contexts ); |
|
|
|
|
|
void showDefinitionInNewTab( const QString & word, |
|
|
unsigned group, |
|
|
const QString & fromArticle, |
|
|
const Contexts & contexts ); |
|
|
|
|
|
|
|
|
void sendWordToHistory( const QString & word ); |
|
|
|
|
|
|
|
|
|
|
|
void typingEvent( const QString & text ); |
|
|
|
|
|
void statusBarMessage( const QString & message, int timeout = 0, const QPixmap & pixmap = QPixmap() ); |
|
|
|
|
|
|
|
|
void showDictsPane(); |
|
|
|
|
|
void updateFoundInDictsList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void activeArticleChanged( const ArticleView *, const QString & id ); |
|
|
|
|
|
|
|
|
void forceAddWordToHistory( const QString & word ); |
|
|
|
|
|
|
|
|
void closePopupMenu(); |
|
|
|
|
|
void sendWordToInputLine( const QString & word ); |
|
|
|
|
|
void storeResourceSavePath( const QString & ); |
|
|
|
|
|
void zoomIn(); |
|
|
void zoomOut(); |
|
|
|
|
|
|
|
|
void notifyJavascriptFinished(); |
|
|
|
|
|
void inspectSignal( QWebEnginePage * page ); |
|
|
|
|
|
void saveBookmarkSignal( const QString & bookmark ); |
|
|
|
|
|
public slots: |
|
|
|
|
|
|
|
|
void openSearch(); |
|
|
|
|
|
void on_searchPrevious_clicked(); |
|
|
void on_searchNext_clicked(); |
|
|
|
|
|
void onJsActiveArticleChanged( const QString & id ); |
|
|
|
|
|
|
|
|
bool handleF3( QObject * obj, QEvent * ev ); |
|
|
|
|
|
|
|
|
void selectCurrentArticle(); |
|
|
|
|
|
void linkClicked( const QUrl & ); |
|
|
|
|
|
Q_INVOKABLE void linkClickedInHtml( const QUrl & ); |
|
|
private slots: |
|
|
void inspectElement(); |
|
|
void loadFinished( bool ok ); |
|
|
void handleTitleChanged( const QString & title ); |
|
|
void attachWebChannelToHtml(); |
|
|
|
|
|
void linkHovered( const QString & link ); |
|
|
void contextMenuRequested( const QPoint & ); |
|
|
|
|
|
bool isAudioLink( QUrl & targetUrl ) |
|
|
{ |
|
|
return ( targetUrl.scheme() == "gdau" || Utils::Url::isAudioUrl( targetUrl ) ); |
|
|
} |
|
|
|
|
|
void resourceDownloadFinished( const sptr< Dictionary::DataRequest > & req, const QUrl & resourceDownloadUrl ); |
|
|
|
|
|
|
|
|
void pasteTriggered(); |
|
|
|
|
|
unsigned getCurrentGroup(); |
|
|
|
|
|
|
|
|
void moveOneArticleUp(); |
|
|
|
|
|
|
|
|
void moveOneArticleDown(); |
|
|
|
|
|
void on_searchText_textEdited(); |
|
|
void on_searchText_returnPressed(); |
|
|
void on_searchCloseButton_clicked(); |
|
|
void on_searchCaseSensitive_clicked( bool ); |
|
|
|
|
|
void on_ftsSearchPrevious_clicked(); |
|
|
void on_ftsSearchNext_clicked(); |
|
|
|
|
|
|
|
|
void doubleClicked( QPoint pos ); |
|
|
|
|
|
|
|
|
void audioPlayerError( const QString & message ); |
|
|
|
|
|
|
|
|
void copyAsText(); |
|
|
void copyResourceToClipboard( const QUrl & url ); |
|
|
|
|
|
void setActiveDictIds( const ActiveDictIds & ad ); |
|
|
|
|
|
void dictionaryClear( const ActiveDictIds & ad ); |
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
unsigned getGroup( const QUrl & ); |
|
|
|
|
|
|
|
|
QString getCurrentArticle(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool setCurrentArticle( const QString &, bool moveToIt = false ); |
|
|
|
|
|
|
|
|
|
|
|
void isFramedArticle( const QString & article, const std::function< void( bool framed ) > & callback ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts ); |
|
|
|
|
|
|
|
|
void injectDarkModeJavaScript(); |
|
|
|
|
|
|
|
|
void injectWebsiteConfigScript(); |
|
|
|
|
|
bool isDarkModeEnabled() const; |
|
|
|
|
|
|
|
|
|
|
|
void cleanupTemp(); |
|
|
|
|
|
bool eventFilter( QObject * obj, QEvent * ev ) override; |
|
|
|
|
|
void performFindOperation( bool backwards ); |
|
|
|
|
|
|
|
|
|
|
|
QString getMutedForGroup( unsigned group ); |
|
|
|
|
|
QStringList getMutedDictionaries( unsigned group ); |
|
|
}; |
|
|
|
|
|
class ResourceToSaveHandler: public QObject |
|
|
{ |
|
|
Q_OBJECT |
|
|
|
|
|
public: |
|
|
explicit ResourceToSaveHandler( ArticleView * view, QString fileName ); |
|
|
void addRequest( const sptr< Dictionary::DataRequest > & req ); |
|
|
bool isEmpty() |
|
|
{ |
|
|
return downloadRequests.empty(); |
|
|
} |
|
|
|
|
|
signals: |
|
|
void done(); |
|
|
void statusBarMessage( const QString & message, int timeout = 0, const QPixmap & pixmap = QPixmap() ); |
|
|
|
|
|
public slots: |
|
|
void downloadFinished(); |
|
|
|
|
|
private: |
|
|
std::list< sptr< Dictionary::DataRequest > > downloadRequests; |
|
|
QString fileName; |
|
|
bool alreadyDone; |
|
|
}; |
|
|
|
|
|
class ArticleViewAgent: public QObject |
|
|
{ |
|
|
Q_OBJECT |
|
|
ArticleView * articleView; |
|
|
|
|
|
public: |
|
|
explicit ArticleViewAgent( ArticleView * articleView ); |
|
|
|
|
|
|
|
|
public slots: |
|
|
Q_INVOKABLE void onJsActiveArticleChanged( const QString & id ); |
|
|
Q_INVOKABLE void linkClickedInHtml( const QUrl & ); |
|
|
Q_INVOKABLE void collapseInHtml( const QString & dictId, bool on = true ) const; |
|
|
}; |
|
|
|