Commit graph

2562 commits

Author SHA1 Message Date
Abs62 c5f0f536fa DSL: Fix links with multiple spaces 2022-09-05 18:38:03 +03:00
Igor Kushnir 8f41079069 Make saving complete article work in Qt 5.15
The old code works correctly in Qt 4.8.7. But in Qt 5.15.5
selectedFilter is never equal to either element of filters. So HTML Only
is saved no matter which option the user selects.
2022-09-04 12:09:42 +03:00
Abs62 1064880450 Fix favorities indication when new tabs open in background 2022-07-29 18:48:04 +03:00
Abs62 aa02fdcc25 A little more Ctrl+Tab/Ctrl+Shift+Tab handling 2022-07-14 18:14:28 +03:00
Abs62 5c3b3b8718 Update Aymara translation (by Amos Batto) 2022-07-13 21:51:31 +03:00
Abs62 f640643672 Disable focus acquiring by tabs menu button 2022-07-13 17:32:41 +03:00
Abs62 896bd350be Handle Ctrl+Tab/Ctrl+Shift+Tab in translate line as tabs switch 2022-07-13 17:31:57 +03:00
cha147 21c94bb7dd fix typo in readme 2022-07-12 18:14:32 +03:00
Abs62 b73687b586 Lupdate all translations, update Russian translation 2022-07-07 18:12:55 +03:00
Igor Kushnir 7db10b6664 Show current match and match count during FTS result navigation
This information is going to be especially useful in the upcoming Qt
WebEngine version of GoldenDict. In the Qt WebEngine version only the
words equal to the last found result can be highlighted, not all FTS
matches as in the Qt WebKit version.
2022-07-02 18:54:03 +03:00
Abs62 440380a763 Linux-specific: Add OpenSSL libraries to .Appimage 2022-07-02 16:18:59 +03:00
Igor Kushnir d8d3002329 Revert "Replace a fruitless check with an assertion"
The assertion failure can be triggered by full-text-searching for a
common word, selecting a result with many large articles and quickly
selecting text in the first article while the page is still loading.

This reverts commit c936d03fa0.
2022-07-02 12:21:34 +03:00
Igor Kushnir 1e43bdf18c highlightFTSResults: return earlier if the regexp is empty
A default-constructed QRegExp is passed to ArticleView::showDefinition()
when a user navigates from an FTS-result page by clicking a link or
double-clicking a word. QRegExp().pattern() returns an empty string,
which is stored in the "regexp" query item of an URL. When this URL is
loaded, ArticleView::loadFinished() calls highlightFTSResults(), which
then calls closeSearch(), performs multiple string and regular
expression operations and early-returns because the regular expression
pattern is empty. Returning earlier skips useless work in this case.

An alternative optimization is not calling highlightFTSResults() at all
when the regular expression is empty, but that would skip the
closeSearch() call and keep the FTS search frame visible on a page with
an empty regexp.
2022-07-01 19:48:42 +03:00
Igor Kushnir c936d03fa0 Replace a fruitless check with an assertion
This reduces CPU time waste and simplifies adding Qt WebEngine support.
2022-07-01 18:43:43 +03:00
Abs62 5d51f183d6 DSL: A little more fix resource loading in some cases 2022-06-27 17:43:32 +03:00
Igor Kushnir 7fa7ad6e52 FFmpeg 5.0 player: stop reading raw data at EOF
Since the update to FFmpeg 5.0, when FFmpeg+libao internal player is
selected, most sounds fail to be pronounced. Furthermore, each failed
pronunciation attempt increases GoldenDict's CPU usage. Finally,
GoldenDict continues to hang and utilize the CPU cores when the user
attempts to exit it.

The reason for the issue is: GoldenDict's readAudioData() returns 0 at
EOF but FFmpeg expects the callback to return AVERROR_EOF. As a result,
internal player's threads are busy calling readAudioData() indefinitely.

a606f27f4c
documented the expected return value of the read_packet callback.
252500a78f
removed the code that handled the deprecated 0 return value gracefully.

The relevant deprecation warning
"Invalid return value 0 for stream protocol" had been flooding
GoldenDict's output for years

Fixes #1489.
2022-06-21 17:53:23 +03:00
Igor Kushnir 39abe4f1a6 Restart search when case sensitivity changes
One issue with the current implementation is that a wrong-cased match
remains selected when the user checks the Case Sensitive checkbox.
Another issue is that the noResults property of searchText is not
updated right away, which means that searchText's background color
remains wrong until next search.

Handle toggling case sensitivity in the same way as editing the searched
text: restart search from the beginning of the page. This improves the
Search-in-page UI consistency.
2022-06-20 19:18:57 +03:00
Igor Kushnir 9b5756d5e1 Don't update pages history in ArticleView::setCurrentArticle()
The current article is saved to pages history user data before any
navigation to another page and before reloading the current page.
Therefore saving it each time the user activates an article is
redundant. This redundancy is not consistent, because when a user
activates an article by clicking on it, the current article changes in
the UI, but is not immediately saved in history as setCurrentArticle()
is not called. The inconsistent redundancy is a waste of CPU time and
can hide bugs.
2022-06-12 21:26:09 +03:00
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 0173251b22 Jump to the first article too after expanding optional parts
When the first article in the list is current, expanding or collapsing
optional parts results in:
1) uncontrolled jumps due to the content height changes if the scroll
   position is not (0, 0);
2) current article change if a non-first article is saved in history
   user data (e.g. if a mouse click had made the first article active).

Treat the first current article in the same way as non-first ones.

This change also affects the case when the current article is not
present in the article list. If the current article is simply empty,
then there is no behavior change. If the current article is not empty,
it *must* be in the list, unless something else went wrong.
2022-06-12 20:14:22 +03:00
Igor Kushnir de69036e9e ArticleView: deduplicate expand-optional-parts code 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 ca0209faff Save current article and window position before loading DSL picture
Without the added saveHistoryUserData() call, returning back from the
enlarged picture page ("gdpicture") restores the current article and the
window position that were last saved. At this commit the "gdpicture"
behavior is consistent with regular links: returning back from the
enlarged picture page sets the article with the picture as current and
restores the window position at the time of the click on the picture.
2022-06-12 20:13:54 +03:00
Igor Kushnir 10d0d8193b setCurrentArticle(): return false if the article doesn't exist
201f11e656 missed this possibility and may
have inadvertently changed the application behavior in a corner case.
2022-06-08 19:05:02 +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 aa33b8bebc Disable assert macro checks in Release builds 2022-06-01 18:40:35 +03:00
Igor Kushnir 8acec2e062 Reduce build log verbosity
The default qmake build output is overly verbose. Adding the "silent"
switch to CONFIG makes it much more concise, comparable to default CMake
output. This way warnings and errors are much easier to find.

Adding CONFIG-=silent to the qmake command line doesn't restore the
verbosity because it is applied before the "CONFIG += silent" line in
goldendict.pro. Add a new CONFIG switch "verbose_build_output" to allow
increasing build log verbosity without editing goldendict.pro.
2022-06-01 18:00:45 +03:00
Abs62 f9652487b9 Zim: A little more support for new format features 2022-06-01 17:51:56 +03:00
Abs62 55122eb739 Zim: Handle new namespace (issue #1502) 2022-05-31 21:08:47 +03:00
wisherhxl 0cea62699d Linux-specific: workaround of clipboard issue with Ctrl+C+C
Closes #1420, closes #650, closes #858.
2022-05-25 21:01:33 +03:00
Igor Kushnir c770e9688e Don't update state prematurely in showTranslationFor()
MainWindow::showTranslationFor() overloads disable the "Pronounce Word"
action, then call ArticleView::showDefinition(). And then immediately
update pronounce availability, Found in Dictionaries list, Back and
Forward buttons. Since ArticleView::showDefinition() loads the requested
page asynchronously, the previous page is still current. Therefore the
"Pronounce Word" action is immediately re-enabled (if the still-current
article has sounds), the other state updates have no effect whatsoever.
Once the new page is loaded, the state is updated again in
MainWindow::pageLoaded() - this time with the desired effect.

So the only effect of the state updates in
MainWindow::showTranslationFor() is to revert the intentional disabling
of the "Pronounce Word" action. Plus waste some CPU time. The
pronunciation-disabling behavior looks better to me and is consistent
with the scan popup's behavior (which immediately hides the
"Pronounce Word" button).
2022-05-25 18:27:18 +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
Xiao YiFang efb4a84da2 fix: duplicated entries in epwing dictionary 2022-05-24 20:32:23 +03:00
Abs62 f07ba75a5c Epwing: Fix full-text search for some CJK dictionaries (issue #1490) 2022-05-23 20:43:58 +03:00
Igor Kushnir b87b023db0 Optimize highlighting FTS matches in articles
The wall time of calls to ArticleView::highlightAllFtsOccurences() on my
GNU/Linux system before and at this commit:
allMatches.size()   uniqueMatches.size()    before(ms)  at(ms)
79                  1                       277         4
98                  1                       380         4
267                 1                       16803       65
2022-05-23 16:05:36 +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
Abs62 f810c6bd72 Zips: Expand headwords while indexing 2022-05-10 18:34:42 +03:00
Abs62 06188dfe1f Win-specific: Remove submodule "winlibs/lib/msvc" 2022-04-30 14:22:46 +03:00
Abs62 f5fdb2ae51 DSL: Fix escaped brackets handling in inside card headwords 2022-04-30 12:56:37 +03:00
Liao Junxuan 8acb288c9e add support for ffmpeg 5.0 2022-02-20 12:28:05 +08:00
yifang 22f72faa03 optimize:fix resource leak Fixes #20 2022-02-18 18:28:44 +03:00
xiaoyifang 570c75e920 performance: Prefer prefix ++/-- operators for non-primitive types.
more detail check https://hownot2code.com/2016/06/30/use-a-prefix-increment-operator-i-in-iterators-instead-of-a-postfix-i-operator/
2022-02-16 22:08:32 +08:00
Jose Riha 1131cc6b1e Update Slovak translation 2022-02-15 00:38:32 +01:00
xiaoyifang c329430a7b fix:warning qt-style-st-lingoes.css the file was missing 2022-02-13 17:01:17 +03:00
Jose Riha a35f9a14d0 Update Slovak translation 2022-02-06 16:38:37 +01:00
Abs62 0e888db874 Win-specific: Compile FFMpeg libraries with speex codec support 2021-12-29 17:50:28 +03:00
Igor Kushnir 8260ac87ba Linux-specific: Don't ignore main window close event
If GoldenDict's option "Close to system tray" is checked and
GoldenDict's main window is visible when the user logs out, the logout
is canceled in latest stable versions of KDE Plasma and Xfce desktop
environments (probably in other GNU/Linux desktop environments too, but
they weren't tested). The cause of this unintended and pointless logout
cancellation is ignoring the close event.

Close events are accepted by default. main() calls
`app.setQuitOnLastWindowClosed( false );`. Thus, if the close event is
not touched, the main window is hidden as before this change.
GoldenDict's configuration, history and favorites are still committed
and saved in both KDE Plasma and Xfce when logging out first
closes/hides the main window, then quits GoldenDict.

The change is limited to GNU/Linux because @Abs62 pointed out that
closing the main window breaks global hotkeys on Windows. I have
verified that closing the main window does not break global hotkeys on
GNU/Linux with Qt5 or Qt4. No one has volunteered to test whether the
change is needed on macOS, so it is safer not to apply it there.

Closes #1421.
2021-11-29 11:25:39 +02:00
Abs62 b10cdf685c MDict: A little support for video 2021-11-12 21:26:46 +03:00