Commit graph

2601 commits

Author SHA1 Message Date
Abs62 661dd4d140 XDXF: Add support for draft revision 034 (issue #1600) 2023-01-19 17:57:47 +03:00
Abs62 1921771bbd Remove 0xAD symbol (soft hyphen) for popup window search 2023-01-18 20:50:03 +03:00
Abs62 46a34e805c Zim: One more check for Zim header 2023-01-17 20:59:13 +03:00
Abs62 9a5e1e8910 Fix links decoding broken by #be22bb 2022-12-23 01:12:28 +03:00
Abs62 3bcd9cfe37 Websites: Fix some redirects 2022-12-22 21:41:49 +03:00
Abs62 79f05a23c8 Websites: Fix loading some CSS (from url with query) 2022-12-22 21:40:18 +03:00
Abs62 cd57031d44 Handle some media links without scheme in offline wikipedia/wiktionary via ArticleNetworkAccessManager 2022-12-22 17:57:43 +03:00
Igor Kushnir 02c02829f7 Qt 5.14+: don't use deprecated QString::SkipEmptyParts
This change fixes the following GCC warnings:
warning: ‘QString::SkipEmptyParts’ is deprecated [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(const QString&, SplitBehavior, Qt::CaseSensitivity) const’ is deprecated: Use split(const QString &sep, Qt::SplitBehavior ...) variant instead [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(QChar, SplitBehavior, Qt::CaseSensitivity) const’ is deprecated: Use split(QChar sep, Qt::SplitBehavior ...) variant instead [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(const QRegExp&, SplitBehavior) const’ is deprecated: Use split(const QRegularExpression &, Qt::SplitBehavior) variant instead [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(const QRegularExpression&, SplitBehavior) const’ is deprecated: Use split(const QRegularExpression &, Qt::SplitBehavior) variant instead [-Wdeprecated-declarations]
2022-11-26 20:41:19 +03:00
Igor Kushnir 5034348c1a Allow silencing failed-loading-resource warnings
When a referenced audio resource is not found in a DSL or XDXF
dictionary, GoldenDict searches for this resource by filename in all
other dictionaries within the current group. Naturally, the file is
absent from most dictionaries (see #970). Therefore a "Failed loading
resource" warning is printed for almost every dictionary in the current
group.

These warnings are by far the most frequent on my system. And in the
scenario described above there is nothing wrong at all. So the user may
want to silence these warnings to help notice less frequent and more
important messages. Implement categorized logging to enable this
customization. These warnings can now be disabled by adding the
following line in the [Rules] section of a logging configuration file
(e.g. ~/.config/QtProject/qtlogging.ini on GNU/Linux):
    goldendict.dictionary.resource.warning=false
See also https://doc.qt.io/qt-5/qloggingcategory.html#logging-rules
2022-11-25 22:48:38 +03:00
Igor Kushnir a61b203de7 Extract TO_LOG_MESSAGE() 2022-11-25 22:48:38 +03:00
Igor Kushnir be22bb9ffd Prevent using temporary codec-for-locale UTF8 replacement
Utf8CodecForLocaleReplacer's temporary codec-for-locale replacements
cause race conditions in unrelated code that calls
QTextCodec::codecForLocale(). Implement and use a wrapper function that
calls QTextCodec::codecForLocale() while holding
Utf8CodecForLocaleReplacer's mutex lock to fix it.

f0b66f7507 and this commit fix #1587.

Combine several chained QString::arg() calls into one in
EpwingBook::setErrorString(). A single call is more efficient and
prevents unintended replacement inside previous argument substitutions.
2022-11-25 22:48:38 +03:00
Igor Kushnir 0ae3fdf2bd Extract Utf8CodecForLocaleReplacer 2022-11-25 22:48:38 +03:00
Igor Kushnir a020ebc4b8 Make loggingMutex nonrecursive
A recursive mutex is less efficient and clearly not needed here.
2022-11-25 17:08:01 +03:00
Abs62 d1ff165a65 Slob: Fix handling of a links with anchor 2022-11-24 17:46:20 +03:00
Abs62 f0b66f7507 Use mutex in gdWarning/gdDebug when logging to file is enabled (issue #1587) 2022-11-24 17:44:57 +03:00
Igor Kushnir 3aaaf15e0a Save&restore the geometry of Print Preview dialog
Calling dialog.showMaximized() before dialog.exec() doesn't work as
intended under KDE Plasma and Xfce. In both desktop environments the
Print Preview dialog ends up modeless - the user can interact with the
main window while the dialog is visible. Such a behavior is surprising
to developers, because QDialog::exec() should show the dialog as modal.
In addition, under Xfce the dialog is not maximized, but very small and
also frameless => neither movable nor resizable.

b13b808edf inserted the line
`dialog.showMaximized();` to work around tiny print preview window,
which confirms that the side effects described above are unintentional.

These maximizing issues could be fixed by passing
Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint
as window flags to QPrintPreviewDialog's constructor and replacing the
line `dialog.showMaximized();` with
`dialog.setWindowState( dialog.windowState() | Qt::WindowMaximized );`.
However, saving and restoring the dialog's geometry allows customization
and thus improves usability. This is how more frequently used dialogs
behave in GoldenDict.

Customize the dialog's window flags to show a maximize button.
Maximizing could be useful on a small screen. This also makes restoring
the old appearance on systems, where it worked correctly, easy to the
user: maximize the dialog once and it appears maximized henceforth
(until the user unmaximizes it back). Use the same window flags as in
EditDictionaries dialog - I haven't noticed any complaints since they
were introduced more than a year ago.
2022-11-17 18:36:58 +03:00
Igor Kushnir 83d71daf03 Don't reset FTS Ignore* options on Preferences change
Accepting changes in Preferences dialog no longer disables two options
"Ignore words order" and "Ignore diacritics", which are configurable in
Full-text search dialog.
2022-11-16 18:51:26 +03:00
Igor Kushnir c087d60165 Set article background to white while printing
cb6b00d85e set .gdarticle background to
`#fefdeb` in article-style.css, but failed to override it in
article-style-print.css.

Set html background to white as well in order to prevent a thin border
around articles' contents if non-printing article styles set html
background to a color other than white.

Printing color background makes little sense and is wasteful. Users who
prefer the old behavior can override the background color in
<Configuration Folder>/article-style-print.css.

Use `background` rather than `background-color` CSS property in order to
overwrite any background image set by non-printing article styles.
2022-11-16 18:51:01 +03:00
Igor Kushnir 5e8cab6d54 Show translateBoxWidget automatically when Words Zoom level decreases
When Search Pane is hidden, Words Zoom level is large and GoldenDict
main window's width is small, translateBoxWidget does not fit into the
toolbar and is hidden behind the toolbar extension button » on the right
side. Reducing Words Zoom level does not automatically make
translateBoxWidget visible until the user presses the toolbar extension
button or types text to be translated.

I haven't noticed any effect of the existing line of code that activates
groupList parent widget's layout whether Search Pane is visible or
hidden. This line was introduced in the commit that implemented
TranslateBox - da13998518. In this initial
implementation navToolbar was the parent of groupList, and
translateBoxWidget did not yet exist. I think that the introduction of
translateBoxWidget in 404a16442b obsoleted
this line of code, and so remove it here.

I have verified that this fix works as intended in the Qt 4 and the Qt 5
version both under KDE Plasma and Xfce.
2022-11-14 19:56:29 +02:00
Igor Kushnir f708c5068c Qt5: give focus to article view after last tab is closed
When the last tab is closed while the article view in it has focus,
Results Navigation Pane acquires focus in the Qt 4 version. This is OK,
because typed text is sent to the translate line and all shortcuts work.
In the Qt 5 version, depending on the value of the "Hide single tab"
option, either no widget has focus or the tab bar acquires focus in this
situation. This leads to issues described in the added comment.
2022-11-12 14:10:06 +03:00
Igor Kushnir 5f96f1f26e Linux-specific: don't force X11 focus unnecessarily
Focus is already transferred to GoldenDict in toggleMainWindow() only
the first time the main window is shown. At all subsequent requests to
show the main window, focus has to be forced with the workaround.
Checking focus asynchronously allows to resort to the workaround less
often.

Under Xfce: the timeout of 0 ms is almost always sufficient in the Qt 5
version, but is never enough in the Qt 4 version. The timeout of 4 ms is
always sufficient in both versions.

Under KDE Plasma: the timeout of 0 ms is rarely sufficient in the Qt 5
version. Unfortunately, with any timeout other than 0 ms, the Qt 5
version does not always get focus, which would be a serious regression,
so no other timeout can be used. The Qt 4 version does not always get
focus both with and without the timeout.
2022-11-05 22:03:51 +03:00
Igor Kushnir a321593ed1 Linux-specific: check correct X11 window ID
translateLine->internalWinId() always equals 0. When the show/hide main
window hotkey is triggered right after GoldenDict starts to system tray,
`wh` equals MainWindow::internalWinId(). A few more experiments confirm
that XGetInputFocus()'s output parameter `focus_return` is an ID of a
top-level window, not of an embedded widget child.
2022-11-05 22:03:51 +03:00
Igor Kushnir fdcd6a3773 Demote input phrase limit message from warning to debug
Limiting input phrase length is disabled by default. The default length
limit value is 1000. The user has to enable the option and lower the
length limit in order to be surprised by missing translation. By making
such configuration changes, the user should become aware of this feature
and its effect.

As the person who has implemented this feature and uses 100 as the
length limit, I am never surprised or disappointed by missing
translation. The only annoyance is this warning that floods my systemd
journal. Apparently I accidentally select overly long phrases way too
often.
2022-11-05 17:38:10 +03:00
Igor Kushnir 38f5fa6c90 Don't warn about unclosed DSL [mN] tags
According to DSL documentation, closing the [mN] tags is optional:
unclosed [mN] tags affect formatting until the end of a card.

As many dictionaries don't close the [mN] tags, GoldenDict printed
multiple unclosed-tag warnings during each word lookup.
2022-11-05 17:37:43 +03:00
Igor Kushnir 7c0c586418 Extract is_mN() and isAnyM() 2022-11-05 17:37:43 +03:00
Igor Kushnir d6696b0800 Expand unclosed tag DSL warning message
The dictionary name, article and the tag name help to locate the issue.

GD_FDPRINTF() => gdWarning() to improve flexibility and user options.
2022-11-05 17:37:43 +03:00
Igor Kushnir fc9a48a113 Demote missing favorites file message from warning to debug
This file is never created if the Favorites feature is not used.

Fix a typo along the way: "favorities" => "favorites".
2022-11-04 21:03:48 +03:00
Igor Kushnir 1d6b5efeac Disable GD_DPRINTF() output in Release builds on all systems
Messages printed with GD_DPRINTF() are clearly debug messages. They
flood GoldenDict's output with lines like these:
    some body finished
    one finished.
    erasing..
    erase done..
    one not finished.
    ====reading 16384 bytes

Messages printed to stderr with GD_FDPRINTF() are more important and
less frequent => leave them in Release builds.
2022-11-04 21:01:52 +03:00
Igor Kushnir 98b37feac2 Print debug output with gdDebug() instead of av_log()
Users can enable or disable av_log() output only by inserting a call to
av_log_set_level() and recompiling GoldenDict. Blink browser engine
shipped with Qt WebEngine sets the log level to AV_LOG_QUIET in
chromium/media/base/media.cc and thus disables all output. So
GoldenDict's custom AV_LOG_INFO messages are always printed in the Qt
WebKit version and never in the Qt WebEngine version.

In contrast, users have many ways to enable or disable QDebug output
without recompilation since Qt 5. Furthermore, GoldenDict's command line
option --log-to-file allows to redirect gdDebug() output to a log file.

The two messages printed via av_log() are clearly debug messages,
because they are printed each time a word or a phrase is pronounced.
2022-11-04 19:52:39 +03:00
Igor Kushnir a27a29aca3 Linux-specific: don't open File menu after showing main window
Unfortunately the X11 focus workaround that opens the File menu cannot
be simply removed. Without this workaround, when KDE Plasma's Focus
stealing prevention level is set to Low (which is the default) or
higher, launching a second GoldenDict instance doesn't give focus to the
already running instance unless that instance's main window is currently
hidden into system tray or minimized. A workaround of hiding then
showing the main window makes the window flicker. Suggesting GoldenDict
users to set the focus stealing prevention level to None is not right,
because this setting is global and affects all applications.

Emulate a left mouse button click at position (0, 0) instead of (1, 1)
in order to waste 1 rather than 2 pixels to the left of the menu bar.

Introduce a new macro X11_MAIN_WINDOW_FOCUS_WORKAROUNDS to link the X11
focus workaround to the File menu workaround introduced in this commit.
This simplifies disabling all related workarounds at once. When the
focus workaround is replaced with a proper solution, the developer won't
forget to remove all obsolete workarounds if they are linked together.

Fixes #781.
2022-11-03 19:25:32 +03:00
Igor Kushnir 6dc74a7c7b Assign correct values to XButtonEvent::[xy]_root
The signature is: QPoint QWidget::mapToGlobal(const QPoint &) const;
2022-11-03 19:25:32 +03:00
Igor Kushnir 307fe2ba16 Download and open an image double-clicked in scan popup
Now double-clicking an image has the same effect in the main window and
in the scan popup. This consistency in no way prevents or hinders using
the popup window as designed (for fast lookup in a small group of
dictionaries), because a user is unlikely to double-click an image
accidentally.

Without this commit, when "Double-click translates the word clicked"
option is on, double-clicking an image in the scan popup translates
currently selected text if the selection is not empty.

Fixes #1279.
2022-11-02 22:22:59 +03:00
Igor Kushnir cf84f57632 Don't append duplicates to openedInspectors
There is no benefit in storing the same pointer multiple times in
openedInspectors. This occurred when an article inspector window was
closed then shown again. When the tab corresponding to the duplicated
article inspector pointer was closed, ArticleInspector::beforeClosed()
erased only one pointer from openedInspectors. This left dangling
duplicate pointer(s) in the list and eventually caused a crash when
another inspector's showEvent() accessed a dangling pointer at
openedInspectors.front().
2022-11-02 22:22:16 +03:00
Igor Kushnir 9330c89e4b Don't attempt to translate empty or whitespace-only text
Silently ignore empty or whitespace-only translation requests. It should
be clear to most users why GoldenDict ignores them.

The translated word ends up as the "word" URL query item value, which is
trimmed in ArticleNetworkAccessManager::getResource(). So the added
trimming in MainWindow::translateInputFinished() should be fine.

When a trimmed translated word was empty, InputPhrase::isValid()
returned false, ArticleNetworkAccessManager::getResource() returned a
null pointer and ArticleNetworkAccessManager::createRequest() fell back
to QNetworkAccessManager::createRequest(), which:
* failed silently in the Qt 4 version;
* displayed the
    Protocol "gdlookup" is unknown
    Failed to load URL gdlookup://localhost?word= &group=4.
    QtNetwork Error 301
error page in the Qt 5 version.

Fixes #1179.
2022-11-02 19:16:33 +03:00
Igor Kushnir c7c8b6f632 git clone URL in README: git:// => https:// scheme
An attempt to clone the git:// URL fails on my Manjaro GNU/Linux system
and produces the following output:
    $ git clone git://github.com/goldendict/goldendict.git
    Cloning into 'goldendict'...
    fatal: unable to connect to github.com:
    github.com[0: 140.82.121.4]: errno=Connection timed out

    128✗

The GitHub UI offers the replacement https:// URL when the green Code
button in the GoldenDict repository is clicked.

Fixes #1561.
2022-11-02 18:05:24 +03:00
Igor Kushnir 927566244f Don't percent-encode local file names while saving an article
This commit fixes broken links in complete saved articles to files whose
names contain reserved characters. An HTML parser decodes a
percent-encoded URL before looking for the referenced file on disk. So
a file with a percent-encoded name cannot be found. Percent-encode only
the URL to fix the bug.
2022-09-21 20:33:54 +03:00
Abs62 fb224043a2 Full-text search: Optimize data transfer to articles list 2022-09-08 18:14:31 +03:00
Abs62 3b2df81b3d Full-text search: Reduce max thread count 2022-09-07 19:46:01 +03:00
Abs62 e333a03d7c Full-text search: Use separate thread pool for search requests 2022-09-06 17:40:22 +03:00
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