Commit graph

65 commits

Author SHA1 Message Date
Igor Kushnir 7df106c68c Refactor: get rid of ArticleView::articleToJump
This variable overrides history user data, which makes the current
article and position restoring code in ArticleView::loadFinished()
difficult to understand.

Encode the same logic in the history user data instead. This should make
the code more straightforward and less brittle in the face of changes.
2022-06-12 20:14:22 +03:00
Igor Kushnir 40dd01755e Always jump to current article before reloading
MainWindow calls ArticleView::reload() when the group list is updated.
This updating may add/remove/reorder dictionaries in the active group.

MainWindow also calls ArticleView::reload() when the display or addon
style changes.

In both of the above scenarios uncontrolled jumps and current article
change can occur (see also the parent commit message).

Move setting articleToJump from above the only ArticleView's reload()
call into ArticleView::reload() itself.
2022-06-12 20:14:22 +03:00
Igor Kushnir e8a1358bce Refactor: extract ArticleView::load()
This way it is clearer that the pages history is updated just before
each navigation to a different page.

The call to ArticleView::saveHistoryUserData() now occurs slightly later
in ArticleView::showDefinition(). I don't think the intervening code can
affect the current article or window position. So the reordering most
likely does not affect application behavior.
2022-06-12 20:13:54 +03:00
Igor Kushnir 99982a1c11 ArticleView: expose only minimal API to JavaScript
https://doc.qt.io/archives/qt-5.5/qtwebkit-bridge.html#internet-security
Qt WebKit Bridge documentation recommends:
  When exposing native objects to an open web environment, it is
  important to understand the security implications. Think whether the
  exposed object enables the web environment access things that
  shouldn't be open, and whether the web content loaded by that web page
  comes from a trusted source.

The author of Qt WebChannel has said the following in a talk that
introduced this Qt module (WebKit Bridge replacement for Qt WebEngine):
  My suggestion here is to write dedicated QObjects with a slim, minimal
  API that only have the signals and methods that you deem safe to be
  used from the outside.
- see a comment under https://redirect.invidious.io/watch?v=KnvnTi6XafA
2022-06-02 13:51:13 +03:00
Igor Kushnir 201f11e656 Set current article at most once in loadFinished()
When the current article is set and the user expands or collapses
optional parts (e.g. via the Ctrl+* shortcut),
ArticleView::setCurrentArticle() is called twice from
ArticleView::loadFinished(). Furthermore, the window scroll position is
restored before the second jump. This is wasteful. Move the
higher-priority setCurrentArticle() call up and, if it succeeds, skip
the other call and the scrolling.

I have measured the time spent running the affected code fragment on my
GNU/Linux system before and at this commit. When the loaded articles are
not very large, the performance gain of this commit is only about 1 ms.
However, when one of the displayed articles was huge (the
"United States" English Wikipedia article), the time went from 120 ms to
5 ms.
2022-05-24 21:02:20 +03:00
Igor Kushnir bd5b36cac7 Extract ArticleView::highlightAllFtsOccurences()
Extracting this function allows to simplify the code and facilitates
optimizing it in the next commit.

Remove `#if QT_VERSION >= 0x040600` along the way as GoldenDict does not
support Qt versions older than 4.6 for several years now.
2022-05-23 16:02:01 +03:00
Igor Kushnir 9f5788ee11 Remove unused declaration showFindButtons()
c2cdf9b177 declared this member function
but it was never defined.
2022-05-23 16:01:58 +03:00
Igor Kushnir f919685797 Extract duplicated "gdfrom-" string manipulation into functions
Such helper functions facilitate understanding of the code and simplify
implementing new features.
2021-06-29 13:31:09 +03:00
Igor Kushnir 60bc05218f Add input phrase's punctuation suffix to alts
Preferences::sanitizeInputPhrase() transforms an input phrase by
removing its whitespace/punctuation prefix and suffix. Translating a
phrase from X11 primary selection or from clipboard, via mouse-over or
from the command line results in such sanitization. This is useful when
a punctuation mark or a space is selected accidentally alongside a word.
This sanitization can be undesirable, however, when an abbreviated word
is selected. For example: "etc.", "e.g.", "i.e.".

This commit implements searching for the input word with the punctuation
suffix preserved as an alternative form of the sanitized word to show
articles for both. For example, when the word "etc." is translated from
the clipboard, both "ETC" and "etc." articles are displayed.

The punctuation suffix is preserved when the word is passed from the
scan popup to the main window and when the translate line text is
refreshed (e.g. when the current group is changed). The suffix is not
stored in history and favorites (doing so would require file format
changes and possibly substantial code changes, this can be implemented
later if need be).

Trim the input phrase once in ArticleNetworkAccessManager::getResource()
instead of verbose trimming in multiple places in
ArticleMaker::makeDefinitionFor().

Closes #1350.
2021-06-17 12:06:36 +03:00
Igor Kushnir 3bf7aad1f7 Add a shortcut to focus scan popup's article view
The article view focus is necessary to navigate a word definition via
keyboard rather than mouse. The shortcut - Ctrl+N - is the same as
the one in the main window for the corresponding action.
2018-05-16 14:54:20 +03:00
Abs62 5fa5cc123f Full-text search: Allow ignore diacritics while search 2018-04-10 17:49:52 +03:00
Igor Kushnir e5045860ef Make adding new audio player implementations easy
* add a new interface class AudioPlayerInterface;
* inherit a new proxy class Ffmpeg::AudioPlayer from it;
* partially switch ArlticleView to using the interface;
* expose MainWindow's AudioPlayerInterface instance to all ArticleView
  instances;
* add a new AudioPlayerFactory class responsible for creating instances
  of concrete classes derived from AudioPlayerInterface depending on
  relevant Config::Preferences values;
* increase minimum supported Qt version from 4.5 to 4.6 in README
  in order to use QScopedPointer introduced in Qt 4.6.
2018-03-24 21:31:48 +02:00
Abs62 747dc0aaaf Refactor resource downloading 2017-04-28 00:13:25 +03:00
Abs62 2085314eb9 1. Don't show "failed to download" error message while saving resources like "gdau://search/..."
2. Stop search if resource is found
2017-04-27 18:04:26 +03:00
Abs62 9511494c2b Send image to external viewer by double click 2017-03-13 17:38:27 +03:00
Abs62 10532279b1 Merge branch 'Original' into Qt4x5
Conflicts:
	article_netmgr.cc
	mainwindow.cc
2014-04-23 18:16:06 +04:00
Abs62 503650d617 Full-text search: Set group for ArticleView::showDefinition() when view article 2014-04-23 00:08:21 +04:00
Abs62 c2cdf9b177 Full-text search: Highlight of the search results 2014-04-22 22:29:58 +04:00
Abs62 9ad0d5f985 Implement full-text search 2014-04-16 20:18:28 +04:00
Abs62 0fa4087b38 Merge branch 'Original' into Qt4x5
Conflicts:
	goldendict.pro
	mainwindow.cc
	zim.cc
	zipsounds.cc
2014-02-11 23:39:31 +04:00
Abs62 dabceff223 Don't jump to dictionary when new page opens in background 2014-02-09 19:15:41 +04:00
Abs62 97c4697a80 Handle some touch screen gestures in article view window 2014-02-04 22:38:50 +04:00
Timon Wong 01ef08a709 Merge branch 'master' into qt4x5 2013-07-05 17:03:57 +08:00
Tvangeste 23f94c584f Jump to article when double-clicking on dictinary in "Found in Dictionaries"
This forces the jump even when the dictionary is already a current/active dictionary.
This is convenient for the following use-cases:

1. User manually scrolls far away from the current dictionary and would like to return.
2. User jumps far away from the current dictionary when doing search (Ctrl+F).
3. User scrolls a huge article and would like to get back to the beginning of it.
2013-06-28 18:00:13 +02:00
Timon Wong 4b412f360c Merge branch 'master' into qt4x5 2013-05-31 12:20:33 +08:00
Timon Wong f30c41dbf6 Remove Url::Class, add Qt4x5::Url::ensureLeadingSlash() and fix all related 2013-05-31 12:20:25 +08:00
Timon Wong d5c236f183 Fix pronunciation for active article (if not avaialbe, fallback to the first one) 2013-05-31 11:29:04 +08:00
Timon Wong ad4394d02b #212: Workaround for Qt5 changed behavior in QUrl::setPath() 2013-05-30 23:05:41 +08:00
Timon Wong 329aa02f93 Add "Inspect" action to context menu
* The "Inspect" action will bring up web inspector from WebKit.
* Restorable inspector window geometry.
2013-05-30 10:18:28 +08:00
Timon Wong 1ba03a326d Add an option to enable saving resource files with articles (#321) 2013-05-27 19:18:13 +08:00
Abs62 1f5270c619 Add "Copy as text" feature (issue #311) 2013-05-15 17:52:47 +04:00
Timon Wong c4752eb14c Add internal audio player(ffmpeg/libav + libao).
* phonon, bass, playsound are removed.
2013-05-05 18:22:12 +08:00
Abs62 0ac060576d Save images and sounds via context menu (issue #223) 2013-02-22 16:44:23 +04:00
Tvangeste 48801fc7a8 Fixed #186: F3 and Shift+F3 shortcuts are no longer global in the main window. 2013-01-23 19:36:45 +01:00
Tvangeste bb3a35e7ff Fixed Issue #184: F3 and Shift-F3 shortcuts don't work in a scan popup window when Search is activated
Also fixed  #185: Dictionaries menu uses hardcoded shortcut value in its text.
2013-01-22 22:16:54 +01:00
Tvangeste 0ee62530c2 Select an enire text of the current article (Ctrl+Shift+A).
Plus a context menu for that as well.
2013-01-18 15:37:24 +01:00
Tvangeste 8b61a8f995 Fixed a bug with incorrect restored sizes of sidebars. 2012-12-27 21:32:16 +01:00
Abs62 0dcbfd849f Send word to input line via context menu 2012-11-26 17:13:13 +04:00
Abs62 259efae81c Update history when clicking links on page (issue #120) 2012-11-12 17:52:54 +04:00
Abs62 8cc13b98b9 "Sound" button on toolbar always play first obtained sound 2012-09-29 14:11:06 +04:00
Abs62 ad8ddc8daf Add option for word selection by single mouse click 2012-09-26 17:59:48 +04:00
Abs62 3c2990bf23 Own muted dictionaries list for each group 2012-09-26 17:13:47 +04:00
Abs62 4c5e79c2b2 Add "Dictionary info" item to dictionary bar context menu 2012-09-25 17:13:35 +04:00
Abs62 3de1e09663 Win-specific: Scan popup now work in GoldenDict article tabs 2012-09-19 03:01:31 +04:00
Abs62 305c9ed1b8 Show/hide optional parts of articles (DSL dictionaries only) 2012-09-16 14:19:47 +04:00
Abs62 e00415e4d2 Close popup menus when ScanPopup window closes 2012-09-12 18:18:16 +04:00
Abs62 ea442909ae Add word to history through context menu 2012-09-12 18:11:30 +04:00
Abs62 535fe0d3e0 Update year in copyright notices. 2012-02-21 01:47:14 +04:00
Julian Depetris Chauvin a7cb431c72 Clicking on "...." in the article view's context menu opens the Results Navigation Pane (if closed and is not popup window), focuses on the next dictionary entry on it and scrolls to the next dictionary in the article view. If user is using the popup window it just scrolls to the next dictionary. 2011-07-30 21:11:07 -03:00
Julian Depetris Chauvin 778a288297 Fix sync between currently active article and the "found in dictionaries" pane for web dictionaries. 2011-07-30 17:28:24 -03:00