Commit graph

340 commits

Author SHA1 Message Date
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 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 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
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 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
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
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
xiaoyifang c329430a7b fix:warning qt-style-st-lingoes.css the file was missing 2022-02-13 17:01:17 +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
Igor Kushnir baff02a14b Make MainWindow::setTranslateBoxTextAnd*() harder to misuse
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.
2021-06-30 20:01:40 +03:00
Igor Kushnir 9ff28e226f Translate box: add missing wildcard symbol (un)escaping
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.
2021-06-30 20:01:40 +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 fdf0464628 Save&restore the geometry of Dictionaries dialog
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.
2021-06-23 09:53:42 +03:00
Abs62 e1c9a0d6de Fix compilation without C++11 support 2021-06-18 21:33:24 +03:00
Igor Kushnir 99ddb7686e Don't add the same phrase to history twice in a row
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.
2021-06-17 12:06:36 +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
proletarius101 38d7193f49 Rename id in metadata and desktop entry to org.goldendict.GoldenDict
https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-id-generic

https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#file-naming
2021-02-27 20:04:28 +08:00
Igor Kushnir 193aa4e31d Set up network disk cache for articleNetMgr
When a Wikipedia article is already cached, this change reduces the
amount of sent and received network data almost tenfold.

Setting up a network disk cache in the same way for dictNetMgr does not
noticeably impact the amount of network traffic. Either this network
access manager sends and receives very little data or the data is never
the same. So dictNetMgr does not need a disk cache.

Use QNetworkDiskCache's default maximum size of 50 MiB as the default
network cache size. This size is large enough to accommodate tens of
huge MediaWiki articles. It is also small enough that the user is
unlikely to run out of disk space because of the cache.

Clear network cache on exit by default because most users probably
don't load the same online articles after restarting GoldenDict. Plus
storing the network cache on disk indefinitely by default would be a new
and unexpected to the users privacy risk.

Nikita Moor came up with the idea and wrote an initial network disk
cache implementation in #1310.
2020-11-18 19:04:28 +02:00
Abs62 9fb33d10bd Disable focus acquiring by "New tab" button 2020-10-22 20:41:37 +03:00
Abs62 1cef1a8733 Qt5-specific: Fix crash after Ctrl+Tab when tabs navigation in MRU order is turned on in preferences 2019-11-16 16:01:13 +03:00
Abs62 df92b38ea8 Mac-specific: Fix save/restore main window configuration with Qt 5.12 2019-09-30 19:57:30 +03:00
Abs62 c53fe1c640 Windows: Fix crashes when all global hotkeys are disabled (issue #1184) 2019-08-07 22:54:49 +03:00
Abs62 05bfc353a8 Allow dictionaries groups combobox standard hotkeys from FTS and Headwords dialogs 2019-07-09 18:00:23 +03:00
coozoo 09a7d4db33 Fix empty menu if program compiled with qt5
Fixed by not adding dummy system tray under X env
Tested for:
Mate 1.22.1
XFCE4 4.12
KDE 5.14.5 (damn it's so ugly now)
GNOME (with topicons-plus extension)

This commit fixes #907, fixes #1097 and fixes #1155
2019-05-27 18:58:27 +03:00
Igor Kushnir 13a321190f Don't construct scan popup twice at startup
abcabb77fa added a makeScanPopup() call
after applyQtStyleSheet() in MainWindow constructor to apply Qt style
sheets to the scan popup. This call destroys the scan popup created
earlier in the MainWindow constructor and creates a new instance.

Let us remove the first, now redundant invocation of makeScanPopup()
from MainWindow::makeDictionaries() to improve startup performance.
makeDictionaries() is currently called only once, so modifying it is not
a problem. If makeDictionaries() is used elsewhere in the future,
the added assertion will remind to reconstruct the scan popup.
2019-05-15 11:09:20 +03:00
Abs62 abcabb77fa Initialize scanPopup window after setting of Qt style sheets (issue #1144) 2019-05-13 18:17:27 +03:00
Abs62 c3ff15f4d8 Fix one more crash under Qt 5.12 2019-04-22 19:50:06 +03:00
Abs62 5fb4ff183e Fix some more possibly crashes with Qt 5.12 2019-03-22 17:10:26 +03:00
Abs62 465f90a315 Set Qt style sheets immediately before main window show 2019-03-19 17:37:51 +03:00
Igor Kushnir 503de6474f Qt5: improve repeated zooming performance
For example, looking up "United States" in my local dictionaries, then
pressing Ctrl++ to increase zoom factor from 1 to 5 takes 4 seconds with
this change and 25 seconds without it. The same scaling takes 6 seconds
with this change and 45 seconds without when I enable English Wikipedia,
which has a particularly large "United States" article.

There is a workaround that speeds up zooming: look up a nonexistent
word, scale to the desired level, then go back to the large articles.
But this is tedious if large articles are open in scan popup or
in case of many tabs in the main window.
2019-02-02 15:31:16 +02:00
Abs62 7abaf07bbd Fix build under Linux/MacOS 2019-02-01 16:59:41 +03:00
Abs62 68fc27b7d7 Win-specific: Add global hotkeys handling via low-level keyboard hook 2019-01-31 17:59:24 +03:00
Igor Kushnir ebfeb37f56 Undef common words defined in X11 headers
* #undef Bool with Qt4 as well as with Qt5.
* #undef min, #undef max from <X11/Xlibint.h>.
* #include <fixx11h.h> just after hotkeywrapper.hh. Unfortunately this
  header can not be included in hotkeywrapper.hh directly because
  some of the undef-ed words are actually used in hotkeywrapper.cc.
* #include <fixx11h.h> after <X11/Xlib.h> in mainwindow.cc just in case
  hotkeywrapper.hh stops including this Xlib.h header in the future.

These changes should make future compilation errors less likely.

For example, without "#undef min" in hotkeywrapper.hh, including
<iomanip> in mainwindow.cc after the mainwindow.hh include resulted in
the following GCC 8 compilation error:
 /usr/include/c++/8.2.1/bits/locale_facets_nonio.tcc:945:22:
  error: expected unqualified-id before ‘(’ token
      __minlen = std::min(__minlen,
                      ^~~
2019-01-28 15:58:14 +02:00
Abs62 92e8c85eec Fix behavior while words list font resizing (issue #1109) 2019-01-26 22:11:27 +03:00
Abs62 06c6c63ddc Handle %GDWORD% template while calling external editor 2018-07-18 19:14:24 +03:00
Boyuan Yang 5d5432dbad
Fix typos found by codespell 2018-07-07 17:33:15 +08:00
Igor Kushnir d83586d3e4 Improve X11 autostart behavior
* Run the freedesktop.org-specific code only on X11 (not on Mac).
* Use a (hopefully) unique destination .desktop file name to prevent
  clashes with a goldendict.desktop file possibly created and customized
  manually or by a system preferences tool.
* Allow different executable and .desktop file names because there is
  no real dependency between them.
* Improve performance slightly with an early return.
2018-05-06 15:43:08 +03:00
fixes a4e98b2f11
Fix autostart bug 2018-05-05 15:03:23 +04:00
Igor Kushnir eec796c6e3 Eliminate a redundant makeScanPopup() call
Destroying and creating a scan popup instance twice in
MainWindow::editPreferences() is wasteful.

2b9dd55804 added the unconditional second
makeScanPopup() call below but didn't remove the existing call,
probably by mistake.
2018-04-19 09:42:18 +03:00
Mohammadreza Abdollahzadeh eea6f686f6
add possibility to use icon from system theme for tray icon 2018-04-17 11:58:20 +04:30
Abs62 5fa5cc123f Full-text search: Allow ignore diacritics while search 2018-04-10 17:49:52 +03:00
Abs62 6a77c23986 Implement "inactive dictionaries" feature for all groups (issue #984) 2018-03-28 17:21:32 +03:00
Abs62 d65a1f7869 Save popup window configuration without it destroying 2018-03-27 21:23:48 +03:00
Abs62 2ff7e4e6d0 Refactor quit/end-of-session handling 2018-03-27 17:46:03 +03:00
Abs62 3cf4561802 Save Favorites inside commitData() 2018-03-26 17:35:49 +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