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.
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).
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.
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
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.
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.
Separate data directory is only used if history file isn't already
present in the configuration directory.
This commit together with two previous ones allows to switch to
layout described in XDG Base Directory specification. Data is not
migrated automatically and old ~/.goldendict home dir has precedence.
If you wish to use standards-compliant locations, move files and
directories manually:
```
CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/goldendict"
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/goldendict"
DATA="${XDG_DATA_HOME:-$HOME/.local/share}/goldendict"
mkdir -p "${CACHE}"
mkdir -p "${DATA}"
mv ~/.goldendict/index "${CACHE}"
mv ~/.goldendict/history "${DATA}"
mv ~/.goldendict/ "${CONFIG}"
```
Please note that this effectively discards network cache stored in
"${XDG_CACHE_HOME:-$HOME/.cache}/GoldenDict/network". You can safely
delete the obsolete cache directory. If you wish to preserve and
keep using the existing network cache, move it into the new location
manually:
```
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}"
mkdir -p "${CACHE}/goldendict"
mv "${CACHE}/GoldenDict/network" "${CACHE}/goldendict"
rmdir "${CACHE}/GoldenDict"
```
If GoldenDict with this change has been already used, new cache dir
will already have "${CACHE}/goldendict/network", and mv will refuse to
merge directories. In such case, you will need to manually remove it
before moving directory with old cache.
Most callers of these member functions should escape wildcard symbols in
the `text` argument. Yet nothing in the functions' signatures suggested
such escaping. With the added enum WildcardPolicy argument, the callers
are forced to decide whether or not the wildcards should be escaped.
When not-escaped wildcard symbols are placed in the translate box/line,
word completion can occupy the CPU for seconds. So it is safer to err on
the side of escaping than the other way around.
The missed unescaping in ScanPopup::translateInputFinished() was
inconsistent with the main window. It made escaping in the scan popup's
translate box unusable by attempting to translate e.g. "\*" verbatim.
This dialog can make use of extra horizontal space when there are many
groups, extra vertical space - when there are many dictionaries. Thus
maximizing Dictionaries dialog can be useful.
Currently Dictionaries dialog features the following window buttons in
the top right corner:
* Close button under Xfce on GNU/Linux;
* Context help, Minimize, Maximize and Close buttons under KDE Plasma on
GNU/Linux;
* Help, Close buttons on Windows (according to Internet screenshots).
With this commit the top-right corner window buttons become:
* Maximize and Close buttons under Xfce on GNU/Linux;
* Minimize, Maximize and Close buttons under KDE Plasma on GNU/Linux;
* disabled Minimize button; Maximize and Close buttons on Windows
(thanks to @nonwill for checking this).
I don't think that Minimize button is useful in this dialog. But it does
no harm, so I won't go out of my way to remove it on all platforms.
Interestingly, the Minimize button won't show up under Xfce even if
Qt::WindowMinimizeButtonHint is on. It is difficult if at all possible
to remove this button under KDE Plasma. Fortunately, the Minimize button
works well in this desktop environment: minimizing hides both the dialog
and the main window, unminimizing shows both windows.
@nonwill found that this button doesn't work well on Windows: minimizing
the dialog hides it, but keeps the main window visible with its input
still blocked by the hidden dialog. Therefore it is just as well that
the Minimize button is disabled on Windows.
I couldn't find a UI element in the Dictionaries dialog that features
context help. Therefore the Context help/Help (question mark) button
must be useless. So removing it is an extra benefit of this commit.
I cannot check which window buttons are visible with this commit on
macOS, but I expect them to include Maximize, Close buttons and be
acceptable overall.
Closes #1359.
The geometries of many GoldenDict's dialogs and windows are already
stored in config. Dictionaries dialog can make use of extra horizontal
space when there are many groups, extra vertical space - when there are
many dictionaries. A user can now resize this dialog to her liking once.
Duplicate articles can be shown when the alts collection is not empty
and a MediaWiki site redirects multiple words to a single page. The
alts collection can be populated when:
* option Preferences=>Advanced=>"Extra search via synonyms" is enabled;
* a Morphology dictionary is active;
* a translation of a phrase is requested in a way that makes GoldenDict
pass the input phrase to Preferences::sanitizeInputPhrase().
Steps to reproduce 1:
1. Create and switch to a dictionary group with (1) "English Wikipedia"
and (2) "English (US) Morphology" dictionaries in it.
2. Request a translation of the word "plays" (without quotes).
Steps to reproduce 2:
1. Create a dictionary group with "English Wiktionary" dictionary in it;
switch to this group in the scan popup window (or in the main window
if the Preferences=>Scan Popup=>"Send translated word to main window"
option is enabled).
2. Select the word "i.e." (without quotes) and press Ctrl+C+C (or
whatever hotkey is configured to translate a word from clipboard).
Each of the 3 removed history addition requests follows a call to
ArticleView::showDefinition() with the same phrase/word as an argument.
Each showDefinition() overload adds its phrase/word argument to history.
These duplicate history additions weren't noticeable because
History::addItem() searches for and removes its argument from items to
avoid duplicate history entries. But the extra function calls, signal
emissions, linear searches and QList manipulation wasted processor time.
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.
For example, the first audio link in "The United States" English
Wikipedia article - "The Star-Spangled Banner" - ends with ".oga".
Without this commit the audio link is not recognized by GoldenDict:
* it is not pronounced when a Preferences=>Audio=>"Auto-pronounce..."
option is enabled;
* clicking on the link opens it in the default browser instead of
playing inside GoldenDict.